All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ModelState.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012-2014 Open Source Robotics Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16 */
17 /* Desc: A model state
18  * Author: Nate Koenig
19  */
20 
21 #ifndef _MODELSTATE_HH_
22 #define _MODELSTATE_HH_
23 
24 #include <vector>
25 #include <string>
26 #include <boost/regex.hpp>
27 
28 #include "gazebo/math/Pose.hh"
29 
30 #include "gazebo/physics/State.hh"
33 
34 namespace gazebo
35 {
36  namespace physics
37  {
40 
49  class ModelState : public State
50  {
52  public: ModelState();
53 
61  public: ModelState(const ModelPtr _model, const common::Time &_realTime,
62  const common::Time &_simTime);
63 
69  public: explicit ModelState(const ModelPtr _model);
70 
75  public: explicit ModelState(const sdf::ElementPtr _sdf);
76 
78  public: virtual ~ModelState();
79 
87  public: void Load(const ModelPtr _model, const common::Time &_realTime,
88  const common::Time &_simTime);
89 
94  public: virtual void Load(const sdf::ElementPtr _elem);
95 
98  public: const math::Pose &GetPose() const;
99 
102  public: bool IsZero() const;
103 
108  public: unsigned int GetLinkStateCount() const;
109 
114  public: LinkState_M GetLinkStates(const boost::regex &_regex) const;
115 
120  public: JointState_M GetJointStates(const boost::regex &_regex) const;
121 
129  public: LinkState GetLinkState(const std::string &_linkName) const;
130 
134  public: bool HasLinkState(const std::string &_linkName) const;
135 
138  public: const LinkState_M &GetLinkStates() const;
139 
144  public: unsigned int GetJointStateCount() const;
145 
153  public: JointState GetJointState(unsigned int _index) const;
154 
162  public: JointState GetJointState(const std::string &_jointName) const;
163 
166  public: const JointState_M &GetJointStates() const;
167 
171  public: bool HasJointState(const std::string &_jointName) const;
172 
175  public: void FillSDF(sdf::ElementPtr _sdf);
176 
180  public: virtual void SetWallTime(const common::Time &_time);
181 
184  public: virtual void SetRealTime(const common::Time &_time);
185 
188  public: virtual void SetSimTime(const common::Time &_time);
189 
193  public: ModelState &operator=(const ModelState &_state);
194 
198  public: ModelState operator-(const ModelState &_state) const;
199 
203  public: ModelState operator+(const ModelState &_state) const;
204 
209  public: inline friend std::ostream &operator<<(std::ostream &_out,
210  const gazebo::physics::ModelState &_state)
211  {
212  math::Vector3 q(_state.pose.rot.GetAsEuler());
213  _out << std::fixed <<std::setprecision(3)
214  << "<model name='" << _state.GetName() << "'>"
215  << "<pose>"
216  << _state.pose.pos.x << " "
217  << _state.pose.pos.y << " "
218  << _state.pose.pos.z << " "
219  << q.x << " "
220  << q.y << " "
221  << q.z << " "
222  << "</pose>";
223 
224  for (LinkState_M::const_iterator iter =
225  _state.linkStates.begin(); iter != _state.linkStates.end();
226  ++iter)
227  {
228  _out << iter->second;
229  }
230 
231  // Output the joint information
232  // for (JointState_M::const_iterator iter =
233  // _state.jointStates.begin(); iter != _state.jointStates.end();
234  // ++iter)
235  // {
236  // _out << iter->second;
237  // }
238 
239  _out << "</model>";
240 
241  return _out;
242  }
243 
245  private: math::Pose pose;
246 
248  private: LinkState_M linkStates;
249 
251  private: JointState_M jointStates;
252  };
254  }
255 }
256 #endif