ModelState.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012-2015 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 
63  public: ModelState(const ModelPtr _model, const common::Time &_realTime,
64  const common::Time &_simTime, const uint64_t _iterations);
65 
71  public: explicit ModelState(const ModelPtr _model);
72 
77  public: explicit ModelState(const sdf::ElementPtr _sdf);
78 
80  public: virtual ~ModelState();
81 
90  public: void Load(const ModelPtr _model, const common::Time &_realTime,
91  const common::Time &_simTime, const uint64_t _iterations);
92 
97  public: virtual void Load(const sdf::ElementPtr _elem);
98 
101  public: const math::Pose &GetPose() const;
102 
105  public: bool IsZero() const;
106 
111  public: unsigned int GetLinkStateCount() const;
112 
117  public: LinkState_M GetLinkStates(const boost::regex &_regex) const;
118 
123  public: JointState_M GetJointStates(const boost::regex &_regex) const;
124 
132  public: LinkState GetLinkState(const std::string &_linkName) const;
133 
137  public: bool HasLinkState(const std::string &_linkName) const;
138 
141  public: const LinkState_M &GetLinkStates() const;
142 
147  public: unsigned int GetJointStateCount() const;
148 
156  public: JointState GetJointState(unsigned int _index) const;
157 
165  public: JointState GetJointState(const std::string &_jointName) const;
166 
169  public: const JointState_M &GetJointStates() const;
170 
174  public: bool HasJointState(const std::string &_jointName) const;
175 
178  public: void FillSDF(sdf::ElementPtr _sdf);
179 
183  public: virtual void SetWallTime(const common::Time &_time);
184 
187  public: virtual void SetRealTime(const common::Time &_time);
188 
191  public: virtual void SetSimTime(const common::Time &_time);
192 
196  public: virtual void SetIterations(const uint64_t _iterations);
197 
201  public: ModelState &operator=(const ModelState &_state);
202 
206  public: ModelState operator-(const ModelState &_state) const;
207 
211  public: ModelState operator+(const ModelState &_state) const;
212 
217  public: inline friend std::ostream &operator<<(std::ostream &_out,
218  const gazebo::physics::ModelState &_state)
219  {
220  math::Vector3 q(_state.pose.rot.GetAsEuler());
221  _out << std::fixed <<std::setprecision(3)
222  << "<model name='" << _state.GetName() << "'>"
223  << "<pose>"
224  << _state.pose.pos.x << " "
225  << _state.pose.pos.y << " "
226  << _state.pose.pos.z << " "
227  << q.x << " "
228  << q.y << " "
229  << q.z << " "
230  << "</pose>";
231 
232  for (LinkState_M::const_iterator iter =
233  _state.linkStates.begin(); iter != _state.linkStates.end();
234  ++iter)
235  {
236  _out << iter->second;
237  }
238 
239  // Output the joint information
240  // for (JointState_M::const_iterator iter =
241  // _state.jointStates.begin(); iter != _state.jointStates.end();
242  // ++iter)
243  // {
244  // _out << iter->second;
245  // }
246 
247  _out << "</model>";
248 
249  return _out;
250  }
251 
253  private: math::Pose pose;
254 
256  private: LinkState_M linkStates;
257 
259  private: JointState_M jointStates;
260  };
262  }
263 }
264 #endif
std::string GetName() const
Get the name associated with this State.
boost::shared_ptr< Model > ModelPtr
Definition: PhysicsTypes.hh:84
#define GZ_PHYSICS_VISIBLE
Definition: system.hh:318
Encapsulates a position and rotation in three space.
Definition: Pose.hh:37
The Vector3 class represents the generic vector containing 3 elements.
Definition: Vector3.hh:39
std::map< std::string, JointState > JointState_M
Definition: PhysicsTypes.hh:212
double x
X location.
Definition: Vector3.hh:311
double z
Z location.
Definition: Vector3.hh:317
State of an entity.
Definition: State.hh:49
Vector3 pos
The position.
Definition: Pose.hh:252
keeps track of state of a physics::Joint
Definition: JointState.hh:46
Quaternion rot
The rotation.
Definition: Pose.hh:255
friend std::ostream & operator<<(std::ostream &_out, const gazebo::physics::ModelState &_state)
Stream insertion operator.
Definition: ModelState.hh:217
Store state information of a physics::Model object.
Definition: ModelState.hh:50
std::map< std::string, LinkState > LinkState_M
Definition: PhysicsTypes.hh:208
Store state information of a physics::Link object.
Definition: LinkState.hh:49
double y
Y location.
Definition: Vector3.hh:314
A Time class, can be used to hold wall- or sim-time.
Definition: Time.hh:39
Vector3 GetAsEuler() const
Return the rotation in Euler angles.