Joint.h
Go to the documentation of this file.
1 /*
2  * Original Copyright (c) 2011-2016 Martin Felis <martin.felis@iwr.uni-heidelberg.de>
3  *
4  *
5  * RDL - Robot Dynamics Library
6  * Modifications Copyright (c) 2017 Jordan Lack <jlack1987@gmail.com>
7  *
8  * Licensed under the zlib license. See LICENSE for more details.
9  */
10 
11 #ifndef __RDL_JOINT_H__
12 #define __RDL_JOINT_H__
13 
19 #include <assert.h>
20 #include <iostream>
22 
23 namespace RobotDynamics
24 {
25 struct Model;
26 
188 {
196  // angular velocity for joint velocity variables.
198  // multi DoF joints).
200  // multi DoF joints).
202  // multi DoF joints).
206  // the parent body.
214 };
215 
228 struct Joint
229 {
231  {
232  }
233 
234  explicit Joint(JointType type) : mJointAxes(nullptr), mJointType(type), mDoFCount(0), q_index(0), custom_joint_index(-1)
235  {
236  if (type == JointTypeRevoluteX)
237  {
238  mDoFCount = 1;
240  mJointAxes[0] = Math::SpatialVector(1., 0., 0., 0., 0., 0.);
241  }
242  else if (type == JointTypeRevoluteY)
243  {
244  mDoFCount = 1;
246  mJointAxes[0] = Math::SpatialVector(0., 1., 0., 0., 0., 0.);
247  }
248  else if (type == JointTypeRevoluteZ)
249  {
250  mDoFCount = 1;
252  mJointAxes[0] = Math::SpatialVector(0., 0., 1., 0., 0., 0.);
253  }
254  else if (type == JointTypeSpherical)
255  {
256  mDoFCount = 3;
257 
259 
260  mJointAxes[0] = Math::SpatialVector(0., 0., 1., 0., 0., 0.);
261  mJointAxes[1] = Math::SpatialVector(0., 1., 0., 0., 0., 0.);
262  mJointAxes[2] = Math::SpatialVector(1., 0., 0., 0., 0., 0.);
263  }
264  else if (type == JointTypeEulerZYX)
265  {
266  mDoFCount = 3;
267 
269 
270  mJointAxes[0] = Math::SpatialVector(0., 0., 1., 0., 0., 0.);
271  mJointAxes[1] = Math::SpatialVector(0., 1., 0., 0., 0., 0.);
272  mJointAxes[2] = Math::SpatialVector(1., 0., 0., 0., 0., 0.);
273  }
274  else if (type == JointTypeEulerXYZ)
275  {
276  mDoFCount = 3;
277 
279 
280  mJointAxes[0] = Math::SpatialVector(1., 0., 0., 0., 0., 0.);
281  mJointAxes[1] = Math::SpatialVector(0., 1., 0., 0., 0., 0.);
282  mJointAxes[2] = Math::SpatialVector(0., 0., 1., 0., 0., 0.);
283  }
284  else if (type == JointTypeEulerYXZ)
285  {
286  mDoFCount = 3;
287 
289 
290  mJointAxes[0] = Math::SpatialVector(0., 1., 0., 0., 0., 0.);
291  mJointAxes[1] = Math::SpatialVector(1., 0., 0., 0., 0., 0.);
292  mJointAxes[2] = Math::SpatialVector(0., 0., 1., 0., 0., 0.);
293  }
294  else if (type == JointTypeTranslationXYZ)
295  {
296  mDoFCount = 3;
297 
299 
300  mJointAxes[0] = Math::SpatialVector(0., 0., 0., 1., 0., 0.);
301  mJointAxes[1] = Math::SpatialVector(0., 0., 0., 0., 1., 0.);
302  mJointAxes[2] = Math::SpatialVector(0., 0., 0., 0., 0., 1.);
303  }
304  else if ((type >= JointType1DoF) && (type <= JointType6DoF))
305  {
306  // create a joint and allocate memory for it.
307  // Warning: the memory does not get initialized by this function!
308  mDoFCount = type - JointType1DoF + 1;
310  }
311  else if (type == JointTypeCustom)
312  {
313  // This constructor cannot be used for a JointTypeCustom because
314  // we have no idea what mDoFCount is.
315  throw RdlException("Error: Invalid use of Joint constructor Joint(JointType type). Only allowed when type != JointTypeCustom");
316  }
317  else if ((type != JointTypeFixed) && (type != JointTypeFloatingBase))
318  {
319  throw RdlException("Error: Invalid use of Joint constructor Joint(JointType type).");
320  }
321  }
322 
323  Joint(JointType type, int degreesOfFreedom) : mJointAxes(nullptr), mJointType(type), mDoFCount(0), q_index(0), custom_joint_index(-1)
324  {
325  if (type == JointTypeCustom)
326  {
327  mDoFCount = degreesOfFreedom;
329 
330  for (unsigned int i = 0; i < mDoFCount; ++i)
331  {
332  mJointAxes[i] = Math::SpatialVector(0., 0., 0., 0., 0., 0.);
333  }
334  }
335  else
336  {
337  throw RdlException("Error: Invalid use of Joint constructor Joint(JointType type, int degreesOfFreedom). Only allowed when type == JointTypeCustom.");
338  }
339  }
340 
342  {
344 
345  for (unsigned int i = 0; i < mDoFCount; i++)
346  {
347  mJointAxes[i] = joint.mJointAxes[i];
348  }
349  }
350 
351  Joint& operator=(const Joint& joint)
352  {
353  if (this != &joint)
354  {
355  if (mDoFCount > 0)
356  {
357  assert(mJointAxes);
358  delete[] mJointAxes;
359  }
360  mJointType = joint.mJointType;
361  mDoFCount = joint.mDoFCount;
364 
365  for (unsigned int i = 0; i < mDoFCount; i++)
366  {
367  mJointAxes[i] = joint.mJointAxes[i];
368  }
369 
370  q_index = joint.q_index;
371  }
372  return *this;
373  }
374 
376  {
377  if (mJointAxes)
378  {
379  assert(mJointAxes);
380  delete[] mJointAxes;
381  mJointAxes = nullptr;
382  mDoFCount = 0;
383  custom_joint_index = -1;
384  }
385  }
386 
395  Joint(const JointType joint_type, const Math::Vector3d& joint_axis) : mDoFCount(1), q_index(0), custom_joint_index(-1)
396  {
398 
399  // Some assertions, as we concentrate on simple cases
400 
401  // Only rotation around the Z-axis
402  assert(joint_type == JointTypeRevolute || joint_type == JointTypePrismatic);
403 
404  mJointType = joint_type;
405 
406  if (joint_type == JointTypeRevolute)
407  {
408  // make sure we have a unit axis
409  mJointAxes[0].set(joint_axis[0], joint_axis[1], joint_axis[2], 0., 0., 0.);
410  }
411  else if (joint_type == JointTypePrismatic)
412  {
413  // make sure we have a unit axis
414  assert(joint_axis.squaredNorm() == 1.);
415 
416  mJointAxes[0].set(0., 0., 0., joint_axis[0], joint_axis[1], joint_axis[2]);
417  }
418  }
419 
429  explicit Joint(const Math::SpatialVector& axis_0) : mDoFCount(1), q_index(0), custom_joint_index(-1)
430  {
432  mJointAxes[0] = Math::SpatialVector(axis_0);
433 
434  if (axis_0 == Math::SpatialVector(1., 0., 0., 0., 0., 0.))
435  {
437  }
438  else if (axis_0 == Math::SpatialVector(0., 1., 0., 0., 0., 0.))
439  {
441  }
442  else if (axis_0 == Math::SpatialVector(0., 0., 1., 0., 0., 0.))
443  {
445  }
446  else
447  {
449  }
451  }
452 
464  {
466  mJointAxes[0] = axis_0;
467  mJointAxes[1] = axis_1;
468 
471  }
472 
484  Joint(const Math::SpatialVector& axis_0, const Math::SpatialVector& axis_1, const Math::SpatialVector& axis_2)
486  {
488 
489  mJointAxes[0] = axis_0;
490  mJointAxes[1] = axis_1;
491  mJointAxes[2] = axis_2;
492 
496  }
497 
510  Joint(const Math::SpatialVector& axis_0, const Math::SpatialVector& axis_1, const Math::SpatialVector& axis_2, const Math::SpatialVector& axis_3)
512  {
514 
515  mJointAxes[0] = axis_0;
516  mJointAxes[1] = axis_1;
517  mJointAxes[2] = axis_2;
518  mJointAxes[3] = axis_3;
519 
524  }
525 
539  Joint(const Math::SpatialVector& axis_0, const Math::SpatialVector& axis_1, const Math::SpatialVector& axis_2, const Math::SpatialVector& axis_3,
540  const Math::SpatialVector& axis_4)
542  {
544 
545  mJointAxes[0] = axis_0;
546  mJointAxes[1] = axis_1;
547  mJointAxes[2] = axis_2;
548  mJointAxes[3] = axis_3;
549  mJointAxes[4] = axis_4;
550 
556  }
557 
572  Joint(const Math::SpatialVector& axis_0, const Math::SpatialVector& axis_1, const Math::SpatialVector& axis_2, const Math::SpatialVector& axis_3,
573  const Math::SpatialVector& axis_4, const Math::SpatialVector& axis_5)
575  {
577 
578  mJointAxes[0] = axis_0;
579  mJointAxes[1] = axis_1;
580  mJointAxes[2] = axis_2;
581  mJointAxes[3] = axis_3;
582  mJointAxes[4] = axis_4;
583  mJointAxes[5] = axis_5;
584 
591  }
592 
599  {
600  if (fabs(axis.norm() - 1.0) > 1.0e-8)
601  {
602  std::cerr << "Warning: joint axis is not unit!" << std::endl;
603  }
604 
605  bool axis_rotational = false;
606  bool axis_translational = false;
607 
608  Math::Vector3d rotation(axis[0], axis[1], axis[2]);
609  Math::Vector3d translation(axis[3], axis[4], axis[5]);
610 
611  if (fabs(translation.norm()) < 1.0e-8)
612  {
613  axis_rotational = true;
614  }
615 
616  if (fabs(rotation.norm()) < 1.0e-8)
617  {
618  axis_translational = true;
619  }
620 
621  return axis_rotational || axis_translational;
622  }
623 
626 
629 
631  // have here a value of 0 and their actual numbers of degrees of freedom
632  // can be obtained using the CustomJoint structure.
633  unsigned int mDoFCount;
634  unsigned int q_index;
635  unsigned int custom_joint_index;
636 };
637 
650 void jcalc(Model& model, unsigned int joint_id, const Math::VectorNd& q, const Math::VectorNd& qdot);
651 
652 Math::SpatialTransform jcalc_XJ(Model& model, unsigned int joint_id, const Math::VectorNd& q);
653 
654 void jcalc_X_lambda_S(Model& model, unsigned int joint_id, const Math::VectorNd& q);
655 
663 {
668  {
669  }
670 
674  virtual ~CustomJoint()
675  {
676  }
677 
684  virtual void jcalc(Model& model, unsigned int joint_id, const Math::VectorNd& q, const Math::VectorNd& qdot) = 0;
685 
686  virtual void jcalc_X_lambda_S(Model& model, unsigned int joint_id, const Math::VectorNd& q) = 0;
687 
688  unsigned int mDoFCount;
697 };
698 } // namespace RobotDynamics
699 
700 /* RDL_JOINT_H */
701 #endif // ifndef __RDL_JOINT_H__
unsigned int mDoFCount
Definition: Joint.h:688
EIGEN_STRONG_INLINE void set(const double &v0, const double &v1, const double &v2, const double &v3, const double &v4, const double &v5)
Emulated 3 DoF joint.
Definition: Joint.h:209
3 DoF joint that uses Euler ZYX convention (faster than emulated
Definition: Joint.h:197
Math::MatrixNd Dinv
Definition: Joint.h:693
Joint(const Math::SpatialVector &axis_0)
Constructs a 1 DoF joint with the given motion subspaces.
Definition: Joint.h:429
Joint & operator=(const Joint &joint)
Definition: Joint.h:351
User defined joints of varying size.
Definition: Joint.h:213
Math::VectorNd ndof0_vec
Definition: Joint.h:696
CustomJoint is a struct used to create a joint with user defined parameters. This is accomplished by ...
Definition: Joint.h:662
CustomJoint()
Constructor.
Definition: Joint.h:667
Math::VectorNd d_u
Definition: Joint.h:695
Joint(JointType type, int degreesOfFreedom)
Definition: Joint.h:323
unsigned int q_index
Definition: Joint.h:634
Fixed joint which causes the inertial properties to be merged with.
Definition: Joint.h:205
void jcalc(Model &model, unsigned int joint_id, const Math::VectorNd &q, const Math::VectorNd &qdot)
Computes all variables for a joint model and updates the body frame as well as the body&#39;s center of m...
Definition: Joint.cc:23
Joint(const Math::SpatialVector &axis_0, const Math::SpatialVector &axis_1)
Constructs a 2 DoF joint with the given motion subspaces.
Definition: Joint.h:463
Joint(const Joint &joint)
Definition: Joint.h:341
Joint(JointType type)
Definition: Joint.h:234
bool validate_spatial_axis(Math::SpatialVector &axis)
Checks whether we have pure rotational or translational axis.
Definition: Joint.h:598
Math::SpatialTransform XJ
Definition: Joint.h:689
Compact representation of spatial transformations.
Emulated 4 DoF joint.
Definition: Joint.h:210
Joint(const Math::SpatialVector &axis_0, const Math::SpatialVector &axis_1, const Math::SpatialVector &axis_2)
Constructs a 3 DoF joint with the given motion subspaces.
Definition: Joint.h:484
Math::VectorNd u
Definition: Joint.h:694
unsigned int custom_joint_index
Definition: Joint.h:635
Emulated 6 DoF joint.
Definition: Joint.h:212
Math::MatrixNd S_o
Definition: Joint.h:691
Describes a joint relative to the predecessor body.
Definition: Joint.h:228
3 DoF joint that uses Euler XYZ convention (faster than emulated
Definition: Joint.h:199
Emulated 5 DoF joint.
Definition: Joint.h:211
Math::SpatialTransform jcalc_XJ(Model &model, unsigned int joint_id, const Math::VectorNd &q)
Definition: Joint.cc:215
Eigen::VectorXd VectorNd
Definition: rdl_eigenmath.h:25
virtual ~CustomJoint()
Destructor.
Definition: Joint.h:674
Joint(const Math::SpatialVector &axis_0, const Math::SpatialVector &axis_1, const Math::SpatialVector &axis_2, const Math::SpatialVector &axis_3, const Math::SpatialVector &axis_4)
Constructs a 5 DoF joint with the given motion subspaces.
Definition: Joint.h:539
JointType
General types of joints.
Definition: Joint.h:187
unsigned int mDoFCount
Number of degrees of freedom of the joint. Note: CustomJoints.
Definition: Joint.h:633
Math::SpatialVector * mJointAxes
The spatial axes of the joint.
Definition: Joint.h:625
Contains all information about the rigid body model.
Definition: Model.h:121
A 6-DoF joint for floating-base (or freeflyer) systems.
Definition: Joint.h:204
void jcalc_X_lambda_S(Model &model, unsigned int joint_id, const Math::VectorNd &q)
Definition: Joint.cc:242
Eigen::MatrixXd MatrixNd
Definition: rdl_eigenmath.h:26
Emulated 2 DoF joint.
Definition: Joint.h:208
Joint(const Math::SpatialVector &axis_0, const Math::SpatialVector &axis_1, const Math::SpatialVector &axis_2, const Math::SpatialVector &axis_3)
Constructs a 4 DoF joint with the given motion subspaces.
Definition: Joint.h:510
Math::MatrixNd S
Definition: Joint.h:690
Joint(const Math::SpatialVector &axis_0, const Math::SpatialVector &axis_1, const Math::SpatialVector &axis_2, const Math::SpatialVector &axis_3, const Math::SpatialVector &axis_4, const Math::SpatialVector &axis_5)
Constructs a 6 DoF joint with the given motion subspaces.
Definition: Joint.h:572
A custom exception.
3 DoF joint using Quaternions for joint positional variables and
Definition: Joint.h:195
Joint(const JointType joint_type, const Math::Vector3d &joint_axis)
Constructs a joint from the given cartesian parameters.
Definition: Joint.h:395
JointType mJointType
Type of joint.
Definition: Joint.h:628
Namespace for all structures of the RobotDynamics library.
Definition: Body.h:21
Math::MatrixNd U
Definition: Joint.h:692
3 DoF joint that uses Euler YXZ convention (faster than emulated
Definition: Joint.h:201


rdl_dynamics
Author(s):
autogenerated on Tue Apr 20 2021 02:25:27