# rbdl / include / rbdl / Kinematics.h

  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 /* * RBDL - Rigid Body Dynamics Library * Copyright (c) 2011-2012 Martin Felis * * Licensed under the zlib license. See LICENSE for more details. */ #ifndef _KINEMATICS_H #define _KINEMATICS_H #include #include #include #include "rbdl/Logging.h" namespace RigidBodyDynamics { /** \defgroup kinematics_group Kinematics * @{ * * \note Please note that in the Rigid %Body Dynamics Library all angles * are specified in radians. * */ /** \brief Updates and computes velocities and accelerations of the bodies * * This function updates the kinematic variables such as body velocities * and accelerations in the model to reflect the variables passed to this function. * * \param model the model * \param Q the positional variables of the model * \param QDot the generalized velocities of the joints * \param QDDot the generalized accelerations of the joints */ void UpdateKinematics (Model &model, const Math::VectorNd &Q, const Math::VectorNd &QDot, const Math::VectorNd &QDDot ); /** \brief Selectively updates model internal states of body positions, velocities and/or accelerations. * * This function updates the kinematic variables such as body velocities and * accelerations in the model to reflect the variables passed to this function. * * In contrast to UpdateKinematics() this function allows to update the model * state with values one is interested and thus reduce computations (e.g. only * positions, only positions + accelerations, only velocities, etc.). * \param model the model * \param Q the positional variables of the model * \param QDot the generalized velocities of the joints * \param QDDot the generalized accelerations of the joints */ void UpdateKinematicsCustom (Model &model, const Math::VectorNd *Q, const Math::VectorNd *QDot, const Math::VectorNd *QDDot ); /** \brief Returns the base coordinates of a point given in body coordinates. * * \param model the rigid body model * \param Q the curent genereralized positions * \param body_id id of the body for which the point coordinates are expressed * \param point_body_coordinates coordinates of the point in body coordinates * \param update_kinematics whether UpdateKinematics() should be called * or not (default: true) * * \returns a 3-D vector with coordinates of the point in base coordinates */ Math::Vector3d CalcBodyToBaseCoordinates ( Model &model, const Math::VectorNd &Q, unsigned int body_id, const Math::Vector3d &body_point_position, bool update_kinematics = true); /** \brief Returns the body coordinates of a point given in base coordinates. * * \param model the rigid body model * \param Q the curent genereralized positions * \param body_id id of the body for which the point coordinates are expressed * \param point_base_coordinates coordinates of the point in base coordinates * \param update_kinematics whether UpdateKinematics() should be called or not * (default: true). * * \returns a 3-D vector with coordinates of the point in body coordinates */ Math::Vector3d CalcBaseToBodyCoordinates ( Model &model, const Math::VectorNd &Q, unsigned int body_id, const Math::Vector3d &base_point_position, bool update_kinematics = true); /** \brief Returns the orientation of a given body as 3x3 matrix * * \param model the rigid body model * \param Q the curent genereralized positions * \param body_id id of the body for which the point coordinates are expressed * \param update_kinematics whether UpdateKinematics() should be called or not * (default: true). * * \returns An orthonormal 3x3 matrix that rotates vectors from base coordinates * to body coordinates. */ Math::Matrix3d CalcBodyWorldOrientation ( Model &model, const Math::VectorNd &Q, const unsigned int body_id, bool update_kinematics = true); /** \brief Computes the point jacobian for a point on a body * * If a position of a point is computed by a function \f$g(q(t))\f$ for which its * time derivative is \f$\frac{d}{dt} g(q(t)) = G(q)\dot{q}\f$ then this * function computes the jacobian matrix \f$G(q)\f$. * * \param model rigid body model * \param Q state vector of the internal joints * \param body_id the id of the body * \param point_position the position of the point in body-local data * \param G a matrix where the result will be stored in * \param update_kinematics whether UpdateKinematics() should be called or not (default: true) * * \returns A 3 x \#dof_count matrix of the point jacobian */ void CalcPointJacobian (Model &model, const Math::VectorNd &Q, unsigned int body_id, const Math::Vector3d &point_position, Math::MatrixNd &G, bool update_kinematics = true ); /** \brief Computes the point jacobian for a point on a body (added by G.J.) * * Calculates J_\omega for the point in the specified body * * \param model rigid body model * \param Q state vector of the internal joints * \param body_id the id of the body * \param point_position the position of the point in body-local data * \param G a matrix where the result will be stored in * \param update_kinematics whether UpdateKinematics() should be called or not (default: true) * * \returns A 3 x \#dof_count J_\omega */ void CalcPointJacobianW (Model &model, const Math::VectorNd &Q, unsigned int body_id, const Math::Vector3d &point_position, Math::MatrixNd &G, bool update_kinematics = true ); /** \brief Computes the velocity of a point on a body * * \param model rigid body model * \param Q state vector of the internal joints * \param QDot velocity vector of the internal joints * \param body_id the id of the body * \param point_position the position of the point in body-local data * \param update_kinematics whether UpdateKinematics() should be called or not (default: true) * * \returns The cartesian velocity of the point in global frame (output) */ Math::Vector3d CalcPointVelocity ( Model &model, const Math::VectorNd &Q, const Math::VectorNd &QDot, unsigned int body_id, const Math::Vector3d &point_position, bool update_kinematics = true ); /** \brief Computes the acceleration of a point on a body * * \param model rigid body model * \param Q state vector of the internal joints * \param QDot velocity vector of the internal joints * \param QDDot velocity vector of the internal joints * \param body_id the id of the body * \param point_position the position of the point in body-local data * \param update_kinematics whether UpdateKinematics() should be called or not (default: true) * * \returns The cartesian acceleration of the point in global frame (output) * * The kinematic state of the model has to be updated before valid * values can be obtained. This can either be done by calling * UpdateKinematics() or setting the last parameter update_kinematics to * true (default). * * \note During the execution of ForwardDynamics() the acceleration * is only applied on the root body and propagated form there. Therefore * in the internal state the accelerations of the bodies only represent * the relative accelerations without any gravitational effects. * * \warning If this function is called after ForwardDynamics() without * an update of the kinematic state one has to add the gravity * acceleration has to be added to the result. */ Math::Vector3d CalcPointAcceleration ( Model &model, const Math::VectorNd &Q, const Math::VectorNd &QDot, const Math::VectorNd &QDDot, unsigned int body_id, const Math::Vector3d &point_position, bool update_kinematics = true ); /** \brief Computes the inverse kinematics iteratively using a damped Levenberg-Marquardt method * * \param model rigid body model * \param Qinit initial guess for the state * \param body_id a vector of all bodies for which we we have kinematic target positions * \param body_point a vector of points in body local coordinates that are * to be matched to target positions * \param target_pos a vector of target positions * \param Qres output of the computed inverse kinematics * \param step_tol tolerance used for convergence detection * \param lambda damping factor for the least squares function * \param max_iter maximum number of steps that should be performed * \returns true on success, false otherwise * * This function repeatedly computes * \f[ Qres = Qres + \Delta \theta\f] * \f[ \Delta \theta = G^T (G^T G + \lambda^2 I)^{-1} e \f] * where \f$G = G(q) = \frac{d}{dt} g(q(t))\f$ and \f$e\f$ is the * correction of the body points so that they coincide with the target * positions. The function returns true when \f$||\Delta \theta||_2 \le\f$ * step_tol or if the error between body points and target gets smaller * than step_tol. Otherwise it returns false. * * The parameter \f$\lambda\f$ is the damping factor that has to * be chosen carefully. In case of unreachable positions higher values (e.g * 0.9) can be helpful. Otherwise values of 0.0001, 0.001, 0.01, 0.1 might * yield good results. See the literature for best practices. * * \warning The actual accuracy might be rather low (~1.0e-2)! Use this function with a * grain of suspicion. */ bool InverseKinematics ( Model &model, const Math::VectorNd &Qinit, const std::vector& body_id, const std::vector& body_point, const std::vector& target_pos, Math::VectorNd &Qres, double step_tol = 1.0e-12, double lambda = 0.01, unsigned int max_iter = 50 ); /** @} */ } #endif /* _KINEMATICS_H */