New/fixing derivs no benchmarks#100
Conversation
DVolpi256
commented
May 26, 2026
- Implemented a new algorithm called firstOrderInverseDynamicsDerivatives in ClusterTreeDynamics.cpp that computes the first-order derivatives of rigid-body dynamics for closed-chain kinematic systems.
- Two new unit tests were added to validate the new algorithm: testInverseDynamicsDerivativesSimple validates the algorithm against a first-order finite difference to an accuracy on the order of 10^-8 and testInverseDynamicsDerivativesComplexStep validates the algorithm against a complex step derivative to an accuracy on the order of 10^-14 (i.e., machine precision).
- New terms were added to handle the new algorithm. This is especially apparent in GenericJoint.h and GenericJoint.cpp, where new CasADi functions to handle the presence of a configuration-dependent joint motion subspace matrix S.
- A new model of Agility Robotics' Cassie and model variants of the Tello robot were added to evaluate the algorithm's handling of closed-chain kinematic systems. A model of the KUKA LWR 4+ robot was also added to test a real robot arm.
Has temporary variables for the backward pass as well. Comments are made for new functions that need to be implemented.
…ded some efficiencies after review.
… two unit test files and fixed the resulting type issues.
Need Casadi to add additional terms
Merging to add support for Ubuntu 24 instead of 18
…tives function in testRBDAlgos
… 456 of ClusterTreeDyamics.cpp. The error pertains to a segmentation fault that I believe is related to the usage of the Psi_dot_ term.
…h a finite difference for fixed-base robots.
…finite difference and the other does a complex step. They work well for the double pendulum case. The three link and four link serial chains and Mini Cheetah have larger errors.
…s derivatives tests now pass.
… Cheetah. Examining how to get the complex step working and whether testRigidBodyDynamicsAlgosDerivatives is now broken.
…aking the existing unit tests.
- Reverted src/Dynamics/ClusterTreeDynamics.cpp to e1bf655 - Reverted include/grbda/Utils/OrientationTools.h to e1bf655 - Reverted src/Dynamics/ClusterJoints/FreeJoint.cpp to e1bf655 - Reverted src/Robots/MiniCheetah.cpp to e1bf655 - Reverted UnitTests/testHelpers.hpp to e1bf655 - Modified UnitTests/testInverseDynamicsDerivativesSimple.cpp: - Updated conf_add to use [pos(3), quat(4)] ordering - Use h=1e-6 for floating base (instead of 1e-8) - Use tolerance 1e-5 for floating base tests - Joint.h remains with [pos(3), quat(4)] ordering (e1bf655 baseline) Results: - testInverseDynamicsDerivativesSimple: 4/4 PASSED (including MiniCheetahQuaternion) - testRigidBodyDynamicsAlgosDerivatives: 14/14 PASSED
| const DMat<Scalar> &S_j = cluster_j->S(); | ||
|
|
||
| // dtau_dq(ii, jj) = t1^T * Psi_ddot_j + t4^T * Psi_dot_j | ||
| dtau_dq.block(ii, jj, num_vel_i, num_vel_j)= |
|
|
||
| if (j < i) | ||
| { | ||
| dtau_dq.block(jj, ii, num_vel_j, num_vel_i)= S_j.transpose() * t3; |
| } | ||
| } | ||
|
|
||
| dtau_dq_dot.block(jj, ii, num_vel_j, num_vel_i)= S_j.transpose() * t2; |
|
|
||
| dtau_dq_dot.block(jj, ii, num_vel_j, num_vel_i)= S_j.transpose() * t2; | ||
| dtau_dq_dot.block(ii, jj, num_vel_i, num_vel_j)= | ||
| t1.transpose() * cluster_j->Upsilon_dot_ + t4.transpose() * S_j; |
| const DMat<Scalar> &S_j = cluster_j->S(); | ||
|
|
||
| dtau_dq.block(ii, jj, num_vel_i, num_vel_j)= | ||
| t1.transpose() * cluster_j->Psi_ddot_ + t4.transpose() * cluster_j->Psi_dot_; |
|
|
||
| if (j < i) | ||
| { | ||
| dtau_dq.block(jj, ii, num_vel_j, num_vel_i)= S_j.transpose() * t3; |
| } | ||
| } | ||
|
|
||
| dtau_dq_dot.block(jj, ii, num_vel_j, num_vel_i)= S_j.transpose() * t2; |
|
|
||
| dtau_dq_dot.block(jj, ii, num_vel_j, num_vel_i)= S_j.transpose() * t2; | ||
| dtau_dq_dot.block(ii, jj, num_vel_i, num_vel_j)= | ||
| t1.transpose() * cluster_j->Upsilon_dot_ + t4.transpose() * S_j; |
| const D6Mat<Scalar> F4_b = BC0_b.transpose() * S0_b; | ||
|
|
||
| // Diagonal blocks: accumulate over all bodies | ||
| dtau_dq_dot.block(ii, ii, num_vel_i, num_vel_i)+= |
| // Diagonal blocks: accumulate over all bodies | ||
| dtau_dq_dot.block(ii, ii, num_vel_i, num_vel_i)+= | ||
| F1_b.transpose() * Upd0_b + F4_b.transpose() * S0_b; | ||
| dtau_dq.block(ii, ii, num_vel_i, num_vel_i)+= |
| const D6Mat<Scalar> &Psidblock = cluster_nodes_[parent]->Psid0_[parent_subindex]; | ||
| const D6Mat<Scalar> &Psiddblock = cluster_nodes_[parent]->Psidd0_[parent_subindex]; | ||
|
|
||
| // Off-diagonal blocks |
…ties to avoid dynamic allocation
|
|
||
| // Diagonal blocks: accumulate over all bodies | ||
| dtau_dq_dot.block(ii, ii, num_vel_i, num_vel_i)+= | ||
| F1_b.transpose() * Upd0_b + F4_b.transpose() * S0_b; |
There was a problem hiding this comment.
Rather than using F1 and F4, we have a different formula in the draft (using one matrix multiply instead of two). Can you confirm that the unit test will still pass with that modification?
(This came up when I was using the code to write up the world frame version of the algo, and there was an inconsistency in the formula for the diagonal blocks)
| dtau_dq_dot.block(ii, ii, num_vel_i, num_vel_i)+= | ||
| F1_b.transpose() * Upd0_b + F4_b.transpose() * S0_b; | ||
| dtau_dq.block(ii, ii, num_vel_i, num_vel_i)+= | ||
| F1_b.transpose() * Psidd0_b + F4_b.transpose() * Psid0_b; |
There was a problem hiding this comment.
Rather than using F1 and F4, we have a different formula in the draft (using one matrix multiply instead of two). Can you confirm that the unit test will still pass with that modification?
(This came up when I was using the code to write up the world frame version of the algo, and there was an inconsistency in the formula for the diagonal blocks)
…opArm accordingly. Comments were added to document how it should eventually be transformed to GenericJoint.
…atial.h dead code
… some conditionals.