| 1 | // Copyright (C) 2009 Ruben Smits <ruben dot smits at mech dot kuleuven dot be> |
| 2 | |
| 3 | // Version: 1.0 |
| 4 | // Author: Ruben Smits <ruben dot smits at mech dot kuleuven dot be> |
| 5 | // Maintainer: Ruben Smits <ruben dot smits at mech dot kuleuven dot be> |
| 6 | // URL: http://www.orocos.org/kdl |
| 7 | |
| 8 | // This library is free software; you can redistribute it and/or |
| 9 | // modify it under the terms of the GNU Lesser General Public |
| 10 | // License as published by the Free Software Foundation; either |
| 11 | // version 2.1 of the License, or (at your option) any later version. |
| 12 | |
| 13 | // This library is distributed in the hope that it will be useful, |
| 14 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 | // Lesser General Public License for more details. |
| 17 | |
| 18 | // You should have received a copy of the GNU Lesser General Public |
| 19 | // License along with this library; if not, write to the Free Software |
| 20 | // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 21 | |
| 22 | #ifndef KDL_RIGIDBODYINERTIA_HPP |
| 23 | #define KDL_RIGIDBODYINERTIA_HPP |
| 24 | |
| 25 | #include "frames.hpp" |
| 26 | |
| 27 | #include "rotationalinertia.hpp" |
| 28 | |
| 29 | namespace KDL { |
| 30 | |
| 31 | /** |
| 32 | * \brief 6D Inertia of a rigid body |
| 33 | * |
| 34 | * The inertia is defined in a certain reference point and a certain reference base. |
| 35 | * The reference point does not have to coincide with the origin of the reference frame. |
| 36 | */ |
| 37 | class RigidBodyInertia{ |
| 38 | public: |
| 39 | |
| 40 | /** |
| 41 | * This constructor creates a cartesian space inertia matrix, |
| 42 | * the arguments are the mass, the vector from the reference point to cog and the rotational inertia in the cog. |
| 43 | */ |
| 44 | explicit RigidBodyInertia(double m=0, const Vector& oc=Vector::Zero(), const RotationalInertia& Ic=RotationalInertia::Zero()); |
| 45 | |
| 46 | /** |
| 47 | * Creates an inertia with zero mass, and zero RotationalInertia |
| 48 | */ |
| 49 | static inline RigidBodyInertia Zero(){ |
| 50 | return RigidBodyInertia(0.0,Vector::Zero(),RotationalInertia::Zero()); |
| 51 | }; |
| 52 | |
| 53 | |
| 54 | ~RigidBodyInertia(){}; |
| 55 | |
| 56 | friend RigidBodyInertia operator*(double a,const RigidBodyInertia& I); |
| 57 | friend RigidBodyInertia operator+(const RigidBodyInertia& Ia,const RigidBodyInertia& Ib); |
| 58 | friend Wrench operator*(const RigidBodyInertia& I,const Twist& t); |
| 59 | friend RigidBodyInertia operator*(const Frame& T,const RigidBodyInertia& I); |
| 60 | friend RigidBodyInertia operator*(const Rotation& R,const RigidBodyInertia& I); |
| 61 | |
| 62 | /** |
| 63 | * Reference point change with v the vector from the old to |
| 64 | * the new point expressed in the current reference frame |
| 65 | */ |
| 66 | RigidBodyInertia RefPoint(const Vector& p); |
| 67 | |
| 68 | /** |
| 69 | * Get the mass of the rigid body |
| 70 | */ |
| 71 | double getMass() const{ |
| 72 | return m; |
| 73 | }; |
| 74 | |
| 75 | /** |
| 76 | * Get the center of gravity of the rigid body |
| 77 | */ |
| 78 | Vector getCOG() const{ |
| 79 | if(m==0) return Vector::Zero(); |
| 80 | else return h/m; |
| 81 | }; |
| 82 | |
| 83 | /** |
| 84 | * Get the rotational inertia expressed in the reference frame (not the cog) |
| 85 | */ |
| 86 | RotationalInertia getRotationalInertia() const{ |
| 87 | return I; |
| 88 | }; |
| 89 | |
| 90 | private: |
| 91 | RigidBodyInertia(double m,const Vector& h,const RotationalInertia& I,bool mhi); |
| 92 | double m; |
| 93 | Vector h; |
| 94 | RotationalInertia I; |
| 95 | |
| 96 | friend class ArticulatedBodyInertia; |
| 97 | |
| 98 | }; |
| 99 | |
| 100 | /** |
| 101 | * Scalar product: I_new = double * I_old |
| 102 | */ |
| 103 | RigidBodyInertia operator*(double a,const RigidBodyInertia& I); |
| 104 | /** |
| 105 | * addition I: I_new = I_old1 + I_old2, make sure that I_old1 |
| 106 | * and I_old2 are expressed in the same reference frame/point, |
| 107 | * otherwise the result is worth nothing |
| 108 | */ |
| 109 | RigidBodyInertia operator+(const RigidBodyInertia& Ia,const RigidBodyInertia& Ib); |
| 110 | |
| 111 | /** |
| 112 | * calculate spatial momentum: h = I*v |
| 113 | * make sure that the twist v and the inertia are expressed in the same reference frame/point |
| 114 | */ |
| 115 | Wrench operator*(const RigidBodyInertia& I,const Twist& t); |
| 116 | |
| 117 | /** |
| 118 | * Coordinate system transform Ia = T_a_b*Ib with T_a_b the frame from a to b. |
| 119 | */ |
| 120 | RigidBodyInertia operator*(const Frame& T,const RigidBodyInertia& I); |
| 121 | /** |
| 122 | * Reference frame orientation change Ia = R_a_b*Ib with R_a_b |
| 123 | * the rotation of b expressed in a |
| 124 | */ |
| 125 | RigidBodyInertia operator*(const Rotation& R,const RigidBodyInertia& I); |
| 126 | |
| 127 | |
| 128 | |
| 129 | }//namespace |
| 130 | |
| 131 | |
| 132 | #endif |