All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties 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 #include "gazebo/util/system.hh"
34 
35 namespace gazebo
36 {
37  namespace physics
38  {
41 
51  {
53  public: ModelState();
54 
62  public: ModelState(const ModelPtr _model, const common::Time &_realTime,
63  const common::Time &_simTime);
64 
70  public: explicit ModelState(const ModelPtr _model);
71 
76  public: explicit ModelState(const sdf::ElementPtr _sdf);
77 
79  public: virtual ~ModelState();
80 
88  public: void Load(const ModelPtr _model, const common::Time &_realTime,
89  const common::Time &_simTime);
90 
95  public: virtual void Load(const sdf::ElementPtr _elem);
96 
99  public: const math::Pose &GetPose() const;
100 
103  public: bool IsZero() const;
104 
109  public: unsigned int GetLinkStateCount() const;
110 
115  public: LinkState_M GetLinkStates(const boost::regex &_regex) const;
116 
121  public: JointState_M GetJointStates(const boost::regex &_regex) const;
122 
130  public: LinkState GetLinkState(const std::string &_linkName) const;
131 
135  public: bool HasLinkState(const std::string &_linkName) const;
136 
139  public: const LinkState_M &GetLinkStates() const;
140 
145  public: unsigned int GetJointStateCount() const;
146 
154  public: JointState GetJointState(unsigned int _index) const;
155 
163  public: JointState GetJointState(const std::string &_jointName) const;
164 
167  public: const JointState_M &GetJointStates() const;
168 
172  public: bool HasJointState(const std::string &_jointName) const;
173 
176  public: void FillSDF(sdf::ElementPtr _sdf);
177 
181  public: virtual void SetWallTime(const common::Time &_time);
182 
185  public: virtual void SetRealTime(const common::Time &_time);
186 
189  public: virtual void SetSimTime(const common::Time &_time);
190 
194  public: ModelState &operator=(const ModelState &_state);
195 
199  public: ModelState operator-(const ModelState &_state) const;
200 
204  public: ModelState operator+(const ModelState &_state) const;
205 
210  public: inline friend std::ostream &operator<<(std::ostream &_out,
211  const gazebo::physics::ModelState &_state)
212  {
213  math::Vector3 q(_state.pose.rot.GetAsEuler());
214  _out << std::fixed <<std::setprecision(3)
215  << "<model name='" << _state.GetName() << "'>"
216  << "<pose>"
217  << _state.pose.pos.x << " "
218  << _state.pose.pos.y << " "
219  << _state.pose.pos.z << " "
220  << q.x << " "
221  << q.y << " "
222  << q.z << " "
223  << "</pose>";
224 
225  for (LinkState_M::const_iterator iter =
226  _state.linkStates.begin(); iter != _state.linkStates.end();
227  ++iter)
228  {
229  _out << iter->second;
230  }
231 
232  // Output the joint information
233  // for (JointState_M::const_iterator iter =
234  // _state.jointStates.begin(); iter != _state.jointStates.end();
235  // ++iter)
236  // {
237  // _out << iter->second;
238  // }
239 
240  _out << "</model>";
241 
242  return _out;
243  }
244 
246  private: math::Pose pose;
247 
249  private: LinkState_M linkStates;
250 
252  private: JointState_M jointStates;
253  };
255  }
256 }
257 #endif
std::string GetName() const
Get the name associated with this State.
boost::shared_ptr< Model > ModelPtr
Definition: PhysicsTypes.hh:82
Encapsulates a position and rotation in three space.
Definition: Pose.hh:40
The Vector3 class represents the generic vector containing 3 elements.
Definition: Vector3.hh:43
std::map< std::string, JointState > JointState_M
Definition: PhysicsTypes.hh:198
double x
X location.
Definition: Vector3.hh:302
double z
Z location.
Definition: Vector3.hh:308
State of an entity.
Definition: State.hh:43
Vector3 pos
The position.
Definition: Pose.hh:243
keeps track of state of a physics::Joint
Definition: JointState.hh:40
Quaternion rot
The rotation.
Definition: Pose.hh:246
friend std::ostream & operator<<(std::ostream &_out, const gazebo::physics::ModelState &_state)
Stream insertion operator.
Definition: ModelState.hh:210
Store state information of a physics::Model object.
Definition: ModelState.hh:50
std::map< std::string, LinkState > LinkState_M
Definition: PhysicsTypes.hh:194
Store state information of a physics::Link object.
Definition: LinkState.hh:49
#define GAZEBO_VISIBLE
Use to represent "symbol visible" if supported.
Definition: system.hh:48
double y
Y location.
Definition: Vector3.hh:305
A Time class, can be used to hold wall- or sim-time.
Definition: Time.hh:43
Vector3 GetAsEuler() const
Return the rotation in Euler angles.