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 
27 #include "gazebo/math/Pose.hh"
28 
29 #include "gazebo/physics/State.hh"
32 
33 namespace gazebo
34 {
35  namespace physics
36  {
39 
48  class ModelState : public State
49  {
51  public: ModelState();
52 
58  public: explicit ModelState(const ModelPtr _model);
59 
64  public: explicit ModelState(const sdf::ElementPtr _sdf);
65 
67  public: virtual ~ModelState();
68 
73  public: virtual void Load(const sdf::ElementPtr _elem);
74 
77  public: const math::Pose &GetPose() const;
78 
81  public: bool IsZero() const;
82 
87  public: unsigned int GetLinkStateCount() const;
88 
96  public: LinkState GetLinkState(unsigned int _index) const;
97 
105  public: LinkState GetLinkState(const std::string &_linkName) const;
106 
110  public: bool HasLinkState(const std::string &_linkName) const;
111 
114  public: const std::vector<LinkState> &GetLinkStates() const;
115 
120  public: unsigned int GetJointStateCount() const;
121 
129  public: JointState GetJointState(unsigned int _index) const;
130 
138  public: JointState GetJointState(const std::string &_jointName) const;
139 
142  public: const std::vector<JointState> &GetJointStates() const;
143 
147  public: bool HasJointState(const std::string &_jointName) const;
148 
151  public: void FillSDF(sdf::ElementPtr _sdf);
152 
156  public: ModelState &operator=(const ModelState &_state);
157 
161  public: ModelState operator-(const ModelState &_state) const;
162 
166  public: ModelState operator+(const ModelState &_state) const;
167 
172  public: friend std::ostream &operator<<(std::ostream &_out,
173  const gazebo::physics::ModelState &_state)
174  {
175  _out << " <model name='" << _state.GetName() << "'>\n";
176  _out << " <pose>" << _state.pose << "</pose>\n";
177 
178  for (std::vector<LinkState>::const_iterator iter =
179  _state.linkStates.begin(); iter != _state.linkStates.end();
180  ++iter)
181  {
182  _out << *iter;
183  }
184 
185  // Output the joint information
186  for (std::vector<JointState>::const_iterator iter =
187  _state.jointStates.begin(); iter != _state.jointStates.end();
188  ++iter)
189  {
190  _out << *iter;
191  }
192 
193  _out << " </model>\n";
194 
195  return _out;
196  }
197 
199  private: math::Pose pose;
200 
202  private: std::vector<LinkState> linkStates;
203 
205  private: std::vector<JointState> jointStates;
206  };
208  }
209 }
210 #endif