Rigid Body Dynamics Library
Kinematics.h
Go to the documentation of this file.
1/*
2 * RBDL - Rigid Body Dynamics Library
3 * Copyright (c) 2011-2018 Martin Felis <martin@fysx.org>
4 *
5 * Licensed under the zlib license. See LICENSE for more details.
6 */
7
8#ifndef RBDL_KINEMATICS_H
9#define RBDL_KINEMATICS_H
10
11#include "rbdl/rbdl_math.h"
12#include <assert.h>
13#include <iostream>
14#include "rbdl/Logging.h"
15
16namespace RigidBodyDynamics {
17
42RBDL_DLLAPI void UpdateKinematics (Model &model,
43 const Math::VectorNd &Q,
44 const Math::VectorNd &QDot,
45 const Math::VectorNd &QDDot
46 );
47
62RBDL_DLLAPI void UpdateKinematicsCustom (Model &model,
63 const Math::VectorNd *Q,
64 const Math::VectorNd *QDot,
65 const Math::VectorNd *QDDot
66 );
67
80 Model &model,
81 const Math::VectorNd &Q,
82 unsigned int body_id,
83 const Math::Vector3d &body_point_position,
84 bool update_kinematics = true);
85
98 Model &model,
99 const Math::VectorNd &Q,
100 unsigned int body_id,
101 const Math::Vector3d &base_point_position,
102 bool update_kinematics = true);
103
116 Model &model,
117 const Math::VectorNd &Q,
118 const unsigned int body_id,
119 bool update_kinematics = true);
120
141RBDL_DLLAPI void CalcPointJacobian (Model &model,
142 const Math::VectorNd &Q,
143 unsigned int body_id,
144 const Math::Vector3d &point_position,
146 bool update_kinematics = true
147 );
148
169RBDL_DLLAPI void CalcPointJacobian6D (Model &model,
170 const Math::VectorNd &Q,
171 unsigned int body_id,
172 const Math::Vector3d &point_position,
174 bool update_kinematics = true
175 );
176
197RBDL_DLLAPI void CalcBodySpatialJacobian (
198 Model &model,
199 const Math::VectorNd &Q,
200 unsigned int body_id,
202 bool update_kinematics = true
203 );
204
217 Model &model,
218 const Math::VectorNd &Q,
219 const Math::VectorNd &QDot,
220 unsigned int body_id,
221 const Math::Vector3d &point_position,
222 bool update_kinematics = true
223 );
224
238RBDL_DLLAPI
240 Model &model,
241 const Math::VectorNd &Q,
242 const Math::VectorNd &QDot,
243 unsigned int body_id,
244 const Math::Vector3d &point_position,
245 bool update_kinematics = true
246 );
247
269RBDL_DLLAPI
271 Model &model,
272 const Math::VectorNd &Q,
273 const Math::VectorNd &QDot,
274 const Math::VectorNd &QDDot,
275 unsigned int body_id,
276 const Math::Vector3d &point_position,
277 bool update_kinematics = true
278 );
279
303RBDL_DLLAPI
305 Model &model,
306 const Math::VectorNd &Q,
307 const Math::VectorNd &QDot,
308 const Math::VectorNd &QDDot,
309 unsigned int body_id,
310 const Math::Vector3d &point_position,
311 bool update_kinematics = true
312 );
313
314#ifndef RBDL_USE_CASADI_MATH
346RBDL_DLLAPI
347 bool InverseKinematics (
348 Model &model,
349 const Math::VectorNd &Qinit,
350 const std::vector<unsigned int>& body_id,
351 const std::vector<Math::Vector3d>& body_point,
352 const std::vector<Math::Vector3d>& target_pos,
353 Math::VectorNd &Qres,
354 double step_tol = 1.0e-12,
355 double lambda = 0.01,
356 unsigned int max_iter = 55
357 );
358
360 const Math::Matrix3d &RotMat);
361
364 ConstraintTypePosition = 0,
369 ConstraintTypePositionCoMXY
370 };
371
373
377
378 unsigned int num_constraints; //size of all constraints
379 double lambda;
380 unsigned int num_steps; // The number of iterations performed
381 unsigned int max_steps; // Maximum number of steps (default 300), abort if more steps are performed.
382 double step_tol; // Step tolerance (default = 1.0e-12). If the computed step length is smaller than this value the algorithm terminates successfully (i.e. returns true). If error_norm is still larger than constraint_tol then this usually means that the target is unreachable.
383 double constraint_tol; // Constraint tolerance (default = 1.0e-12). If error_norm is smaller than this value the algorithm terminates successfully, i.e. all constraints are satisfied.
384 double error_norm; // Norm of the constraint residual vector.
385 double delta_q_norm; //Norm of the change in generalized coordinates
386
387 // everything to define a IKin constraint
388 std::vector<ConstraintType> constraint_type;
389 std::vector<unsigned int> body_ids;
390 std::vector<Math::Vector3d> body_points;
391 std::vector<Math::Vector3d> target_positions;
392 std::vector<Math::Matrix3d> target_orientations;
393 std::vector<unsigned int> constraint_row_index;
394 std::vector<float> constraint_weight;
395
396 // Adds a point constraint that tries to get a body point close to a
397 // point described in base coordinates.
398 unsigned int AddPointConstraint (unsigned int body_id, const Math::Vector3d &body_point, const Math::Vector3d &target_pos, float weight = 1.);
399 // Adds an orientation constraint that tries to align a body to the
400 // orientation specified as a rotation matrix expressed in base
401 // coordinates.
402 unsigned int AddOrientationConstraint (unsigned int body_id, const Math::Matrix3d &target_orientation, float weight = 1.);
403 // Adds a constraint on both location and orientation of a body.
404 unsigned int AddFullConstraint (unsigned int body_id, const Math::Vector3d &body_point, const Math::Vector3d &target_pos, const Math::Matrix3d &target_orientation, float weight = 1.);
405 // Clears all entries of the constraint setting
406 unsigned int ClearConstraints();
407
408 unsigned int AddPointConstraintXY (unsigned int body_id, const Math::Vector3d &body_point, const Math::Vector3d &target_pos, float weight = 1.);
409 unsigned int AddPointConstraintZ (unsigned int body_id, const Math::Vector3d &body_point, const Math::Vector3d &target_pos, float weight = 1.);
410 unsigned int AddPointConstraintCoMXY (unsigned int body_id, const Math::Vector3d &target_pos, float weight = 1.);
411
412};
413
414RBDL_DLLAPI bool InverseKinematics (
415 Model &model,
416 const Math::VectorNd &Qinit,
418 Math::VectorNd &Qres
419 );
420#endif
421
424}
425
426/* RBDL_KINEMATICS_H */
427#endif
RBDL_DLLAPI Matrix3d CalcBodyWorldOrientation(Model &model, const VectorNd &Q, const unsigned int body_id, bool update_kinematics)
Returns the orientation of a given body as 3x3 matrix.
Definition: Kinematics.cc:222
RBDL_DLLAPI void UpdateKinematics(Model &model, const VectorNd &Q, const VectorNd &QDot, const VectorNd &QDDot)
Updates and computes velocities and accelerations of the bodies.
Definition: Kinematics.cc:25
RBDL_DLLAPI Vector3d CalcAngularVelocityfromMatrix(const Matrix3d &RotMat)
Definition: Kinematics.cc:699
RBDL_DLLAPI void CalcBodySpatialJacobian(Model &model, const VectorNd &Q, unsigned int body_id, MatrixNd &G, bool update_kinematics)
Computes the spatial jacobian for a body.
Definition: Kinematics.cc:370
RBDL_DLLAPI void CalcPointJacobian6D(Model &model, const VectorNd &Q, unsigned int body_id, const Vector3d &point_position, MatrixNd &G, bool update_kinematics)
Computes a 6-D Jacobian for a point on a body.
Definition: Kinematics.cc:308
RBDL_DLLAPI Vector3d CalcBodyToBaseCoordinates(Model &model, const VectorNd &Q, unsigned int body_id, const Vector3d &point_body_coordinates, bool update_kinematics)
Returns the base coordinates of a point given in body coordinates.
Definition: Kinematics.cc:157
RBDL_DLLAPI SpatialVector CalcPointAcceleration6D(Model &model, const VectorNd &Q, const VectorNd &QDot, const VectorNd &QDDot, unsigned int body_id, const Vector3d &point_position, bool update_kinematics)
Computes linear and angular acceleration of a point on a body.
Definition: Kinematics.cc:562
RBDL_DLLAPI void UpdateKinematicsCustom(Model &model, const VectorNd *Q, const VectorNd *QDot, const VectorNd *QDDot)
Selectively updates model internal states of body positions, velocities and/or accelerations.
Definition: Kinematics.cc:78
RBDL_DLLAPI void CalcPointJacobian(Model &model, const VectorNd &Q, unsigned int body_id, const Vector3d &point_position, MatrixNd &G, bool update_kinematics)
Computes the point jacobian for a point on a body.
Definition: Kinematics.cc:244
RBDL_DLLAPI Vector3d CalcBaseToBodyCoordinates(Model &model, const VectorNd &Q, unsigned int body_id, const Vector3d &point_base_coordinates, bool update_kinematics)
Returns the body coordinates of a point given in base coordinates.
Definition: Kinematics.cc:190
RBDL_DLLAPI Vector3d CalcPointVelocity(Model &model, const VectorNd &Q, const VectorNd &QDot, unsigned int body_id, const Vector3d &point_position, bool update_kinematics)
Computes the velocity of a point on a body.
Definition: Kinematics.cc:434
RBDL_DLLAPI bool InverseKinematics(Model &model, const VectorNd &Qinit, const std::vector< unsigned int > &body_id, const std::vector< Vector3d > &body_point, const std::vector< Vector3d > &target_pos, VectorNd &Qres, double step_tol, double lambda, unsigned int max_iter)
Computes the inverse kinematics iteratively using a damped Levenberg-Marquardt method (also known as ...
Definition: Kinematics.cc:605
RBDL_DLLAPI Math::SpatialVector CalcPointVelocity6D(Model &model, const Math::VectorNd &Q, const Math::VectorNd &QDot, unsigned int body_id, const Math::Vector3d &point_position, bool update_kinematics)
Computes angular and linear velocity of a point that is fixed on a body.
Definition: Kinematics.cc:478
RBDL_DLLAPI Vector3d CalcPointAcceleration(Model &model, const VectorNd &Q, const VectorNd &QDot, const VectorNd &QDDot, unsigned int body_id, const Vector3d &point_position, bool update_kinematics)
Computes the linear acceleration of a point on a body.
Definition: Kinematics.cc:515
SpatialVector_t SpatialVector
Definition: rbdl_math.h:61
std::vector< Math::Vector3d > target_positions
Definition: Kinematics.h:391
Math::MatrixNd G
the Jacobian of all constraints
Definition: Kinematics.h:375
unsigned int num_constraints
Vector with all the constraint residuals.
Definition: Kinematics.h:378
std::vector< Math::Vector3d > body_points
Definition: Kinematics.h:390
unsigned int num_steps
Damping factor, the default value of 1.0e-6 is reasonable for most problems.
Definition: Kinematics.h:380
std::vector< unsigned int > constraint_row_index
Definition: Kinematics.h:393
std::vector< Math::Matrix3d > target_orientations
Definition: Kinematics.h:392
Math::VectorNd e
temporary storage of a single body Jacobian
Definition: Kinematics.h:376
std::vector< ConstraintType > constraint_type
Definition: Kinematics.h:388