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 Nate Koenig
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 
109  public: const std::vector<LinkState> &GetLinkStates() const;
110 
115  public: unsigned int GetJointStateCount() const;
116 
124  public: JointState GetJointState(unsigned int _index) const;
125 
133  public: JointState GetJointState(const std::string &_jointName) const;
134 
137  public: const std::vector<JointState> &GetJointStates() const;
138 
142  public: ModelState &operator=(const ModelState &_state);
143 
147  public: ModelState operator-(const ModelState &_state) const;
148 
152  public: ModelState operator+(const ModelState &_state) const;
153 
158  public: friend std::ostream &operator<<(std::ostream &_out,
159  const gazebo::physics::ModelState &_state)
160  {
161  _out << "<model name='" << _state.GetName() << "'>\n";
162  _out << "<pose>" << _state.pose << "</pose>\n";
163 
164  // for (std::vector<LinkState>::const_iterator iter =
165  // _state.linkStates.begin(); iter != _state.linkStates.end();
166  // ++iter)
167  // {
168  // _out << *iter;
169  // }
170 
171  // Output the joint information
172  for (std::vector<JointState>::const_iterator iter =
173  _state.jointStates.begin(); iter != _state.jointStates.end();
174  ++iter)
175  {
176  _out << *iter;
177  }
178 
179  _out << "</model>\n";
180 
181  return _out;
182  }
183 
185  private: math::Pose pose;
186 
188  private: std::vector<LinkState> linkStates;
189 
191  private: std::vector<JointState> jointStates;
192  };
194  }
195 }
196 #endif