ModelState.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 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 
18 #ifndef GAZEBO_PHYSICS_MODELSTATE_HH_
19 #define GAZEBO_PHYSICS_MODELSTATE_HH_
20 
21 #include <vector>
22 #include <string>
23 #include <boost/regex.hpp>
24 
25 #include <ignition/math/Pose3.hh>
26 #include <ignition/math/Vector3.hh>
27 #include "gazebo/math/Pose.hh"
28 
29 #include "gazebo/physics/State.hh"
32 #include "gazebo/util/system.hh"
33 
34 namespace gazebo
35 {
36  namespace physics
37  {
40 
49  class GZ_PHYSICS_VISIBLE ModelState : public State
50  {
52  public: ModelState();
53 
62  public: ModelState(const ModelPtr _model, const common::Time &_realTime,
63  const common::Time &_simTime, const uint64_t _iterations);
64 
70  public: explicit ModelState(const ModelPtr _model);
71 
76  public: explicit ModelState(const sdf::ElementPtr _sdf);
77 
79  public: virtual ~ModelState();
80 
89  public: void Load(const ModelPtr _model, const common::Time &_realTime,
90  const common::Time &_simTime, const uint64_t _iterations);
91 
96  public: virtual void Load(const sdf::ElementPtr _elem);
97 
101  public: const math::Pose GetPose() const GAZEBO_DEPRECATED(8.0);
102 
105  public: const ignition::math::Pose3d &Pose() const;
106 
109  public: const ignition::math::Vector3d &Scale() const;
110 
113  public: bool IsZero() const;
114 
119  public: unsigned int GetLinkStateCount() const;
120 
125  public: LinkState_M GetLinkStates(const boost::regex &_regex) const;
126 
131  public: JointState_M GetJointStates(const boost::regex &_regex) const;
132 
140  public: LinkState GetLinkState(const std::string &_linkName) const;
141 
145  public: bool HasLinkState(const std::string &_linkName) const;
146 
149  public: const LinkState_M &GetLinkStates() const;
150 
155  public: unsigned int GetJointStateCount() const;
156 
164  public: JointState GetJointState(unsigned int _index) const;
165 
173  public: JointState GetJointState(const std::string &_jointName) const;
174 
177  public: const JointState_M &GetJointStates() const;
178 
182  public: bool HasJointState(const std::string &_jointName) const;
183 
188  public: unsigned int NestedModelStateCount() const;
189 
197  public: ModelState NestedModelState(const std::string &_modelName) const;
198 
202  public: bool HasNestedModelState(const std::string &_modelName) const;
203 
206  public: const ModelState_M &NestedModelStates() const;
207 
210  public: void FillSDF(sdf::ElementPtr _sdf);
211 
215  public: virtual void SetWallTime(const common::Time &_time);
216 
219  public: virtual void SetRealTime(const common::Time &_time);
220 
223  public: virtual void SetSimTime(const common::Time &_time);
224 
228  public: virtual void SetIterations(const uint64_t _iterations);
229 
233  public: ModelState &operator=(const ModelState &_state);
234 
238  public: ModelState operator-(const ModelState &_state) const;
239 
243  public: ModelState operator+(const ModelState &_state) const;
244 
249  public: inline friend std::ostream &operator<<(std::ostream &_out,
250  const gazebo::physics::ModelState &_state)
251  {
252  ignition::math::Vector3d euler(_state.pose.Rot().Euler());
253  _out << std::fixed <<std::setprecision(3)
254  << "<model name='" << _state.GetName() << "'>"
255  << "<pose>"
256  << _state.pose.Pos().X() << " "
257  << _state.pose.Pos().Y() << " "
258  << _state.pose.Pos().Z() << " "
259  << euler.X() << " "
260  << euler.Y() << " "
261  << euler.Z() << " "
262  << "</pose>"
263  << "<scale>"
264  << _state.scale
265  << "</scale>";
266 
267  for (LinkState_M::const_iterator iter =
268  _state.linkStates.begin(); iter != _state.linkStates.end();
269  ++iter)
270  {
271  _out << iter->second;
272  }
273 
274  for (const auto &ms : _state.modelStates)
275  {
276  _out << ms.second;
277  }
278 
279  // Output the joint information
280  // for (JointState_M::const_iterator iter =
281  // _state.jointStates.begin(); iter != _state.jointStates.end();
282  // ++iter)
283  // {
284  // _out << iter->second;
285  // }
286 
287  _out << "</model>";
288 
289  return _out;
290  }
291 
293  private: ignition::math::Pose3d pose;
294 
296  private: ignition::math::Vector3d scale;
297 
299  private: LinkState_M linkStates;
300 
302  private: JointState_M jointStates;
303 
305  private: ModelState_M modelStates;
306  };
308  }
309 }
310 #endif
Forward declarations for the common classes.
Definition: Animation.hh:33
std::map< std::string, ModelState > ModelState_M
Definition: PhysicsTypes.hh:233
std::string GetName() const
Get the name associated with this State.
Encapsulates a position and rotation in three space.
Definition: Pose.hh:42
std::map< std::string, JointState > JointState_M
Definition: PhysicsTypes.hh:245
State of an entity.
Definition: State.hh:49
keeps track of state of a physics::Joint
Definition: JointState.hh:43
#define GAZEBO_DEPRECATED(version)
Definition: system.hh:302
friend std::ostream & operator<<(std::ostream &_out, const gazebo::physics::ModelState &_state)
Stream insertion operator.
Definition: ModelState.hh:249
boost::shared_ptr< Model > ModelPtr
Definition: PhysicsTypes.hh:93
std::map< std::string, LinkState > LinkState_M
Definition: PhysicsTypes.hh:241
Store state information of a physics::Model object.
Definition: ModelState.hh:49
Store state information of a physics::Link object.
Definition: LinkState.hh:46
A Time class, can be used to hold wall- or sim-time.
Definition: Time.hh:44