Inertial.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012-2016 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 _INERTIAL_HH_
18 #define _INERTIAL_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 <string>
27 
28 #include <sdf/sdf.hh>
29 
30 #include "gazebo/msgs/msgs.hh"
32 #include "gazebo/math/Vector3.hh"
33 #include "gazebo/math/Matrix3.hh"
34 #include "gazebo/util/system.hh"
35 
36 namespace gazebo
37 {
38  namespace physics
39  {
42 
45  class GZ_PHYSICS_VISIBLE Inertial
46  {
48  public: Inertial();
49 
52  public: explicit Inertial(double _mass);
53 
56  public: Inertial(const Inertial &_inertial);
57 
59  public: virtual ~Inertial();
60 
63  public: void Load(sdf::ElementPtr _sdf);
64 
67  public: void UpdateParameters(sdf::ElementPtr _sdf);
68 
70  public: void Reset();
71 
73  public: void SetMass(double m);
74 
76  public: double GetMass() const;
77 
85  public: void SetInertiaMatrix(double _ixx, double _iyy, double _izz,
86  double _ixy, double _ixz, double iyz);
87 
92  public: void SetCoG(double _cx, double _cy, double _cz);
93 
96  public: void SetCoG(const math::Vector3 &_center);
97 
106  public: void SetCoG(double _cx, double _cy, double _cz,
107  double _rx, double _ry, double _rz);
108 
111  public: void SetCoG(const math::Pose &_c);
112 
115  public: inline const math::Vector3 &GetCoG() const
116  {
117  return this->cog.pos;
118  }
119 
123  public: inline const math::Pose GetPose() const
124  {
125  return math::Pose(this->cog);
126  }
127 
130  public: math::Vector3 GetPrincipalMoments() const;
131 
134  public: math::Vector3 GetProductsofInertia() const;
135 
138  public: double GetIXX() const;
139 
142  public: double GetIYY() const;
143 
146  public: double GetIZZ() const;
147 
150  public: double GetIXY() const;
151 
154  public: double GetIXZ() const;
155 
158  public: double GetIYZ() const;
159 
162  public: void SetIXX(double _v);
163 
166  public: void SetIYY(double _v);
167 
170  public: void SetIZZ(double _v);
171 
174  public: void SetIXY(double _v);
175 
178  public: void SetIXZ(double _v);
179 
182  public: void SetIYZ(double _v);
183 
186  public: void Rotate(const math::Quaternion &_rot);
187 
191  public: Inertial &operator=(const Inertial &_inertial);
192 
200  public: Inertial operator+(const Inertial &_inertial) const;
201 
205  public: const Inertial &operator+=(const Inertial &_inertial);
206 
209  public: void ProcessMsg(const msgs::Inertial &_msg);
210 
219  public: math::Matrix3 GetMOI(const math::Pose &_pose)
220  const;
221 
227  public: Inertial GetInertial(const math::Pose &_frameOffset) const;
228 
232  public: friend std::ostream &operator<<(std::ostream &_out,
233  const gazebo::physics::Inertial &_inertial)
234  {
235  _out << "Mass[" << _inertial.mass << "] CoG["
236  << _inertial.cog << "]\n";
237  _out << "IXX[" << _inertial.principals.x << "] "
238  << "IYY[" << _inertial.principals.y << "] "
239  << "IZZ[" << _inertial.principals.z << "]\n";
240  _out << "IXY[" << _inertial.products.x << "] "
241  << "IXZ[" << _inertial.products.y << "] "
242  << "IYZ[" << _inertial.products.z << "]\n";
243  return _out;
244  }
245 
248  public: math::Matrix3 GetMOI() const;
249 
252  public: void SetMOI(const math::Matrix3 &_moi);
253 
255  private: double mass;
256 
259  private: math::Pose cog;
260 
263  private: math::Vector3 principals;
264 
268  private: math::Vector3 products;
269 
271  private: sdf::ElementPtr sdf;
272 
275  private: static sdf::ElementPtr sdfInertial;
276  };
278  }
279 }
280 #endif
double x
X location.
Definition: Vector3.hh:311
double y
Y location.
Definition: Vector3.hh:314
const math::Vector3 & GetCoG() const
Get the center of gravity.
Definition: Inertial.hh:115
Encapsulates a position and rotation in three space.
Definition: Pose.hh:37
The Vector3 class represents the generic vector containing 3 elements.
Definition: Vector3.hh:39
const math::Pose GetPose() const
Get the pose about which the mass and inertia matrix is specified in the Link frame.
Definition: Inertial.hh:123
double z
Z location.
Definition: Vector3.hh:317
A 3x3 matrix class.
Definition: Matrix3.hh:34
A class for inertial information about a link.
Definition: Inertial.hh:45
friend std::ostream & operator<<(std::ostream &_out, const gazebo::physics::Inertial &_inertial)
Output operator.
Definition: Inertial.hh:232
A quaternion class.
Definition: Quaternion.hh:42