Skip to content

New/fixing derivs no benchmarks#100

Open
DVolpi256 wants to merge 175 commits into
mainfrom
new/fixing_derivs_no_benchmarks
Open

New/fixing derivs no benchmarks#100
DVolpi256 wants to merge 175 commits into
mainfrom
new/fixing_derivs_no_benchmarks

Conversation

@DVolpi256

Copy link
Copy Markdown
  • 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.

DVolpi256 and others added 30 commits October 23, 2025 13:28
Has temporary variables for the backward pass as well. Comments are made for new functions that need to be implemented.
… 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
… 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.
… Cheetah. Examining how to get the complex step working and whether testRigidBodyDynamicsAlgosDerivatives is now broken.
- 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
Comment thread include/grbda/Dynamics/Nodes/ClusterTreeNode.h
Comment thread include/grbda/Utils/Spatial.h Outdated
Comment thread include/grbda/Utils/SpatialTransforms.h Outdated
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)=

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

noalias


if (j < i)
{
dtau_dq.block(jj, ii, num_vel_j, num_vel_i)= S_j.transpose() * t3;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

noalias

}
}

dtau_dq_dot.block(jj, ii, num_vel_j, num_vel_i)= S_j.transpose() * t2;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

noalias


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;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

noalias

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_;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

noalias


if (j < i)
{
dtau_dq.block(jj, ii, num_vel_j, num_vel_i)= S_j.transpose() * t3;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

noalias

}
}

dtau_dq_dot.block(jj, ii, num_vel_j, num_vel_i)= S_j.transpose() * t2;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

noalias


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;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

noalias

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)+=

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

noalias

// 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)+=

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

noalias

const D6Mat<Scalar> &Psidblock = cluster_nodes_[parent]->Psid0_[parent_subindex];
const D6Mat<Scalar> &Psiddblock = cluster_nodes_[parent]->Psidd0_[parent_subindex];

// Off-diagonal blocks

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

noalias for these next four

Comment thread src/Dynamics/ClusterJoints/GenericJoint.cpp Outdated
Comment thread src/Dynamics/ClusterJoints/GenericJoint.cpp
Comment thread src/Dynamics/ClusterJoints/GenericJoint.cpp
Comment thread src/Dynamics/ClusterJoints/GenericJoint.cpp
Comment thread src/Dynamics/ClusterJoints/GenericJoint.cpp Outdated

// 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;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
A
 Please enter the commit message for your changes. Lines starting
Added an alias for std::vector<Mat6, ...> for improved readability
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants