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 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 /* 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(unsigned int _index) const
130  GAZEBO_DEPRECATED(1.7);
131 
139  public: LinkState GetLinkState(const std::string &_linkName) const;
140 
144  public: bool HasLinkState(const std::string &_linkName) const;
145 
148  public: const LinkState_M &GetLinkStates() const;
149 
154  public: unsigned int GetJointStateCount() const;
155 
163  public: JointState GetJointState(unsigned int _index) const;
164 
172  public: JointState GetJointState(const std::string &_jointName) const;
173 
176  public: const JointState_M &GetJointStates() const;
177 
181  public: bool HasJointState(const std::string &_jointName) const;
182 
185  public: void FillSDF(sdf::ElementPtr _sdf);
186 
190  public: virtual void SetWallTime(const common::Time &_time);
191 
194  public: virtual void SetRealTime(const common::Time &_time);
195 
198  public: virtual void SetSimTime(const common::Time &_time);
199 
203  public: ModelState &operator=(const ModelState &_state);
204 
208  public: ModelState operator-(const ModelState &_state) const;
209 
213  public: ModelState operator+(const ModelState &_state) const;
214 
219  public: inline friend std::ostream &operator<<(std::ostream &_out,
220  const gazebo::physics::ModelState &_state)
221  {
222  math::Vector3 q(_state.pose.rot.GetAsEuler());
223  _out << std::fixed <<std::setprecision(3)
224  << "<model name='" << _state.GetName() << "'>"
225  << "<pose>"
226  << _state.pose.pos.x << " "
227  << _state.pose.pos.y << " "
228  << _state.pose.pos.z << " "
229  << q.x << " "
230  << q.y << " "
231  << q.z << " "
232  << "</pose>";
233 
234  for (LinkState_M::const_iterator iter =
235  _state.linkStates.begin(); iter != _state.linkStates.end();
236  ++iter)
237  {
238  _out << iter->second;
239  }
240 
241  // Output the joint information
242  // for (JointState_M::const_iterator iter =
243  // _state.jointStates.begin(); iter != _state.jointStates.end();
244  // ++iter)
245  // {
246  // _out << iter->second;
247  // }
248 
249  _out << "</model>";
250 
251  return _out;
252  }
253 
255  private: math::Pose pose;
256 
258  private: LinkState_M linkStates;
259 
261  private: JointState_M jointStates;
262  };
264  }
265 }
266 #endif