JointState.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 #ifndef GAZEBO_PHYSICS_JOINTSTATE_HH_
18 #define GAZEBO_PHYSICS_JOINTSTATE_HH_
19 
20 #ifdef _WIN32
21  // Ensure that Winsock2.h is included before Windows.h, which can get
22  // pulled in by anybody (e.g., Boost).
23  #include <Winsock2.h>
24 #endif
25 
26 #include <vector>
27 #include <string>
28 #include <ignition/math/Angle.hh>
29 
30 #include "gazebo/physics/State.hh"
31 #include "gazebo/math/Angle.hh"
32 #include "gazebo/util/system.hh"
33 
34 namespace gazebo
35 {
36  namespace physics
37  {
40 
43  class GZ_PHYSICS_VISIBLE JointState : public State
44  {
46  public: JointState();
47 
53  public: JointState(JointPtr _joint, const common::Time &_realTime,
54  const common::Time &_simTime, const uint64_t _iterations);
55 
58  public: explicit JointState(JointPtr _joint);
59 
64  public: explicit JointState(const sdf::ElementPtr _sdf);
65 
67  public: virtual ~JointState();
68 
73  public: void Load(JointPtr _joint, const common::Time &_realTime,
74  const common::Time &_simTime);
75 
78  public: virtual void Load(const sdf::ElementPtr _elem);
79 
82  public: unsigned int GetAngleCount() const;
83 
89  public: math::Angle GetAngle(unsigned int _axis) const
90  GAZEBO_DEPRECATED(8.0);
91 
103  public: double Position(const unsigned int _axis = 0) const;
104 
108  public: const std::vector<math::Angle> GetAngles() const
109  GAZEBO_DEPRECATED(8.0);
110 
117  public: const std::vector<double> &Positions() const;
118 
121  public: bool IsZero() const;
122 
125  public: void FillSDF(sdf::ElementPtr _sdf);
126 
130  public: JointState &operator=(const JointState &_state);
131 
135  public: JointState operator-(const JointState &_state) const;
136 
140  public: JointState operator+(const JointState &_state) const;
141 
146  public: inline friend std::ostream &operator<<(std::ostream &_out,
147  const gazebo::physics::JointState &_state)
148  {
149  _out << "<joint name='" << _state.GetName() << "'>";
150 
151  int i = 0;
152  for (std::vector<double>::const_iterator iter =
153  _state.positions.begin(); iter != _state.positions.end(); ++iter)
154  {
155  _out << "<angle axis='" << i << "'>" << (*iter) << "</angle>";
156  }
157 
158  _out << "</joint>";
159 
160  return _out;
161  }
162 
163  private: std::vector<double> positions;
164  };
166  }
167 }
168 #endif
std::string GetName() const
Get the name associated with this State.
boost::shared_ptr< Joint > JointPtr
Definition: PhysicsTypes.hh:117
State of an entity.
Definition: State.hh:49
friend std::ostream & operator<<(std::ostream &_out, const gazebo::physics::JointState &_state)
Stream insertion operator.
Definition: JointState.hh:146
keeps track of state of a physics::Joint
Definition: JointState.hh:43
#define GAZEBO_DEPRECATED(version)
Definition: system.hh:302
An angle and related functions.
Definition: Angle.hh:53
A Time class, can be used to hold wall- or sim-time.
Definition: Time.hh:44