Skip to main content

dynamics_rs/
lib.rs

1//! # **`dynamics`**: A Rust library for Rigid Body Dynamics
2//!
3//! `dynamics` is a Rust library for rigid body dynamics computations, allowing
4//! users to model and simulate the motion of articulated rigid body systems such
5//! as robots. It provides efficient algorithms for computing kinematics, dynamics,
6//! and other related quantities.
7//!
8//! On top of Rust API, Python bindings are provided for easy integration into Python projects.
9//! The Python package [`rdynamics-py`](https://pypi.org/project/rdynamics-py/) can be installed via `pip`.
10//!
11//! This library has two inspiration sources:
12//! - Roy Featherstone's book ["Rigid Body Dynamics Algorithms"](https://link.springer.com/book/10.1007/978-1-4899-7560-7), which provides the theoretical
13//!   foundation for many of the algorithms implemented in this library.
14//! - The C++ library [Pinocchio](https://github.com/stack-of-tasks/pinocchio/), a widely-used
15//!   library for rigid body dynamics in robotics, which served as a reference for the API design
16//!   and implementation details.
17//!
18//! ## Features
19//! - Representation of rigid body systems using articulated body models.
20//! - Parsing of model files in the folowing formats:
21//!   * URDF (Unified Robot Description Format)
22//!   * *SDF (Simulation Description Format)* (WIP)
23//! - The following algorithms:
24//!   * Forward kinematics
25//!   * Inverse dynamics (RNEA)
26//!   * *Jacobians computation* (WIP)
27//!   * *Forward dynamics (ABA)* (WIP)
28//!
29//! ## Example
30//! The following example demonstrates how to load a robot model from a URDF file,
31//! compute its forward kinematics for a random configuration, and print the placement
32//! of a specific joint and frame.
33//!
34//! ```no_run
35//! use dynamics_rs::prelude::*;
36//!
37//! fn main() {
38//!     let urdf_path = "./examples/descriptions/ur5/ur5_robot.urdf"; // Path to the URDF file
39//!     let mesh_path = "./examples/descriptions/ur5/"; // Optional mesh path
40//!
41//!     // Build models from the URDF file
42//!     let (model, _coll_model, _viz_model) =
43//!         build_models_from_urdf(urdf_path, Some(mesh_path)).expect("Failed to parse URDF file");
44//!
45//!     // Generate a random configuration
46//!     let q = random_configuration(&model);
47//!     println!("Random configuration q: {}", q);
48//!
49//!     // Create data structure for the model
50//!     let mut data = model.create_data();
51//!
52//!     // Compute forward kinematics
53//!     forward_kinematics(&model, &mut data, &q, None, None)
54//!         .expect("Failed to compute forward kinematics");
55//!
56//!     // Print the placement of the joint 'wrist_3_joint'
57//!     let id = model.get_joint_id("wrist_3_joint").unwrap();
58//!     let placement = &data.joint_placements[id];
59//!     println!("Placement of 'wrist_3_joint':\n{}", placement);
60//!
61//!     // Compute the frame placements
62//!     update_frame_placements(&model, &mut data);
63//!
64//!     // Print the placement of the frame 'tool0'
65//!     let frame_id = model.get_frame_id("tool0", None).unwrap();
66//!     // we don't specify a frame type (None) as there is only one frame with this name
67//!     let frame_placement = &data.frame_placements[frame_id];
68//!     println!("Placement of frame 'tool0':\n{}", frame_placement);
69//! }
70//! ```
71//!
72//! ## Crates
73//! The `dynamics` library is organized into several crates, each focusing on a specific aspect
74//! of rigid body dynamics:
75//! - [`dynamics-rs`](https://docs.rs/crate/dynamics-rs/latest): the main crate that provides high-level functionalities and interfaces.
76//! - [`dynamics-spatial`](https://docs.rs/crate/dynamics-spatial/latest): implements spatial algebra used in rigid body dynamics, such as spatial vectors and transformations.
77//! - [`dynamics-model`](https://docs.rs/crate/dynamics-model/latest): contains model and data structures for rigid body systems, as well as the main algorithms for kinematics and dynamics computations.
78//! - [`dynamics-joint`](https://docs.rs/crate/dynamics-joint/latest): implements various joint types and their properties.
79//! - [`dynamics-inertia`](https://docs.rs/crate/dynamics-inertia/latest): provides inertia-related computations and data structures.
80//! - [`dynamics-parse`](https://docs.rs/crate/dynamics-parse/latest): utilities for parsing model files and configurations.
81//!
82//! For collision checking functionalities, the [`collider-rs`](https://docs.rs/crate/collider-rs/latest) crate is used.
83
84pub use collider_rs as collider;
85pub use dynamics_inertia as inertia;
86pub use dynamics_joint as joint;
87pub use dynamics_model as model;
88pub use dynamics_parse as parse;
89pub use dynamics_spatial as spatial;
90
91pub mod prelude;