Skip to main content

MechanicsDSL Logo

mechanicsdsl-ros2

Compile MechanicsDSL physical systems directly to complete ROS2 packages.

Active ROS2 MIT License Core Package

Overview

mechanicsdsl-ros2 provides a dedicated ROS2 integration layer for MechanicsDSL. Physical systems defined in DSL notation compile to complete, buildable ROS2 packages, no manual C++ required for the physics layer.


Package: mechanicsdsl_pendulum

The first generated package, currently including:

Nodes

Node System Rate Topics
pendulum_node Simple pendulum 250 Hz /mechanicsdsl/pendulum/state, /mechanicsdsl/pendulum/energy
double_pendulum_node Double pendulum 200 Hz /double_pendulum/state

Messages

Message Fields
PendulumState header, theta, omega, energy, energy_drift, sim_time
SystemState header, q[], q_dot[], q_ddot[], lambda[], energy, energy_drift, conserved_quantities[], sim_time

Launch Files

ros2 launch mechanicsdsl_pendulum pendulum.launch.py
ros2 launch mechanicsdsl_pendulum pendulum.launch.py l_m:=0.5 theta0_rad:=0.8
ros2 launch mechanicsdsl_pendulum double_pendulum.launch.py theta1_0:=0.3 theta2_0:=0.2

Repository Structure

mechanicsdsl-ros2/
├── mechanicsdsl_pendulum/
│   ├── package.xml, CMakeLists.txt
│   ├── msg/  PendulumState.msg, SystemState.msg
│   ├── src/  pendulum_node.cpp, double_pendulum_node.cpp
│   ├── include/mechanicsdsl_pendulum/  pendulum_dynamics.hpp
│   ├── launch/  pendulum.launch.py, double_pendulum.launch.py
│   ├── config/  pendulum_params.yaml
│   └── test/  test_pendulum_eom.cpp, test_pendulum_integration.py
├── docker/  Dockerfile (ROS2 Jazzy + MechanicsDSL)
├── scripts/  build.sh, monitor.sh
└── docs/  getting_started.md, architecture.md, adding_systems.md

Quick Start

# Clone into ROS2 workspace
mkdir -p ~/ros2_ws/src && cd ~/ros2_ws/src
git clone https://github.com/MechanicsDSL/mechanicsdsl-ros2.git

# Build
cd ~/ros2_ws
rosdep install --from-paths src --ignore-src -r -y
colcon build --packages-select mechanicsdsl_pendulum
source install/setup.bash

# Run
ros2 launch mechanicsdsl_pendulum pendulum.launch.py

Docker:

docker build -t mechanicsdsl-ros2:jazzy docker/
docker run --rm -it mechanicsdsl-ros2:jazzy

Monitoring

ros2 topic echo /mechanicsdsl/pendulum/state
ros2 topic hz  /mechanicsdsl/pendulum/state   # should be ~250 Hz

# Reset
ros2 topic pub --once /pendulum/reset std_msgs/msg/Bool "data: true"

Testing

colcon test --packages-select mechanicsdsl_pendulum
colcon test-result --verbose

GTests cover EOM correctness, energy conservation, equilibrium stability, and small-angle period accuracy.


Generate a package from any DSL spec

pip install mechanicsdsl-ros2
mechanicsdsl-ros2 scaffold double_pendulum -o ~/ros2_ws/src                 # ament_cmake + rclcpp
mechanicsdsl-ros2 scaffold double_pendulum --lang python -o ~/ros2_ws/src   # ament_python + rclpy
mechanicsdsl-ros2 scaffold my_system.msl --rate 500 -o ~/ros2_ws/src
mechanicsdsl-ros2 header double_pendulum -o include/                        # header-only C++17 dynamics
mechanicsdsl-ros2 inspect double_pendulum

Then:

cd ~/ros2_ws && colcon build --packages-select mechanicsdsl_double_pendulum
ros2 launch mechanicsdsl_double_pendulum double_pendulum.launch.py

Every generated node:

Interface Name Type
state (C++ only) <system>/state SystemState: names, q, q_dot, q_ddot, energy, energy_drift, sim_time
joint states <system>/joint_states sensor_msgs/JointState (RViz / robot_state_publisher ready)
energy (Python only) <system>/energy std_msgs/Float64
reset <system>/reset std_srvs/Trigger
parameters every physical parameter, rate_hz, substeps, paused live-updatable with ros2 param set

The launch file loads config/<system>_params.yaml (keyed /**, so it applies under any node name or namespace). C++ packages include a gtest that checks the dynamics stay finite and, for conservative systems, conserve energy.

How generated code is checked

The dynamics headers for six presets are compiled together in one translation unit with g++ -std=c++17 -Wall -Wextra -Wpedantic -Werror and compared with a Python RK4 reference to 1e-12. The Python package's dynamics.py is imported and run against the same reference. The rclcpp and rclpy nodes themselves are not built in this repository's CI (that needs a ROS2 install); build them with colcon as above.


Architecture

See docs/architecture.md for the full node/message/layer diagram.

Adding New Systems

See docs/adding_systems.md.

Contributing

See CONTRIBUTING.md.

License

MIT License; see LICENSE.

Metadata

Release files for mechanicsdsl-ros2 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mechanicsdsl-ros2 0.2.0
File Size Uploaded Provenance Actions
mechanicsdsl_ros2-0.2.0.tar.gz 42.8 kB With provenance Details for mechanicsdsl_ros2-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for mechanicsdsl-ros2 0.2.0
File Interpreter ABI Platform Actions
mechanicsdsl_ros2-0.2.0-py3-none-any.whl Python 3 none any Details for mechanicsdsl_ros2-0.2.0-py3-none-any.whl

Total release size: 67.6 kB

Release files / mechanicsdsl_ros2-0.2.0.tar.gz

Download URL mechanicsdsl_ros2-0.2.0.tar.gz
Size 42.8 kB
Tags Source
SHA-256 checksum
How to use checksums
3501c1a12ca3a6fa80faab9a18b46554ae0600777445c24daddcfb3c6f946bc7
BLAKE2b-256 checksum
How to use checksums
b64657e78ce623583e15f6c3611be688f27409a5f95aa4c96670b8bbdb21e228
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 14, 2026.

Transparency log

Release files / mechanicsdsl_ros2-0.2.0-py3-none-any.whl

Download URL mechanicsdsl_ros2-0.2.0-py3-none-any.whl
Size 24.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
396299af92a5b079bc01f2dc66f9c688d6660cb405d75818eface29e562414ff
BLAKE2b-256 checksum
How to use checksums
6e18d49770fc551921eef5e039fe71b265a65efa7163ef155ecab0b54d5ed659
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 14, 2026.

Transparency log

Security for mechanicsdsl-ros2 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for mechanicsdsl_ros2-0.2.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 14, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page