multibody_dynamics
multibody_dynamics is a Rust crate for rigid multibody dynamics with
spatial-vector style algorithms for kinematics, Jacobians, mass matrices,
inverse dynamics, and forward dynamics.
The crate is built around fixed-size const generics:
NUM_BODIES: number of bodies/joints in the model.NUM_DOFS: total generalized coordinate dimension.
NUM_DOFS must equal the sum of joint dimensions. Revolute and prismatic
joints each contribute 1 DOF; SixDOF joints contribute 6 DOFs.
Installation
Add the crate to your Cargo.toml:
[]
= "0.4.2"
For local development from this repository:
[]
= { = "." }
Example
use ;
use ;
let cfg = ;
let model = from_config.unwrap;
let no_six_dof_joints: = Vecnew;
let q = zeros;
let conf = model.minimal_to_homogeneous_configuration;
let mass_matrix = model.compute_mass_matrix;
Topology Conventions
The parent vector uses one-based indexing:
parent[i] == 0: bodyiis a root.parent[i] == k: bodyihas parent bodyk - 1.
Non-root parents must reference an earlier body. This keeps traversal order well-defined and prevents cycles.
Link Properties
You can provide either:
- a full spatial mass matrix with
mass6, or - scalar
mass,r_com, andinertia3.
When mass6 is provided, the crate derives scalar mass and center of mass from
the spatial mass matrix unless explicit mass or r_com values are also
provided. Buoyancy uses volume and r_cob when present.
Checked APIs
The crate provides checked variants for input-sensitive operations:
MultiBody::from_configtry_minimal_to_homogeneous_configurationtry_compute_regressor_matrixtry_step_dynamics
The unchecked compatibility methods panic with clear messages when the checked variant would return an error.
Integration Helpers
MultiBody::step_dynamics and MultiBody::try_step_dynamics provide
convenience stepping around forward_dynamics_ab. They support
semi-implicit Euler and RK4 through IntegrationOptions.
For SixDOF joints, generalized velocities are interpreted as body-frame
twists ordered [linear; angular], matching the crate's spatial-vector
conventions. The RK4 mode uses a fourth-order generalized-velocity update and
ordered SE(3) stage composition for SixDOF poses.
Development
Run the main verification commands before publishing changes:
Run benchmarks with:
License
This project is licensed under GPL-3.0. See LICENSE.txt.