Skip to main content

MechanicsDSL Logo

mechanicsdsl-embedded

Deploy MechanicsDSL simulations to Arduino, Raspberry Pi, and ARM edge devices.

Active Targets MIT License Core Package

Overview

mechanicsdsl-embedded provides deployment infrastructure and examples for running MechanicsDSL-generated simulations on embedded and edge platforms. Write your physical system once in DSL notation; generate optimized, dependency-free C++ or no_std Rust ready to flash or deploy.

All examples originate from MechanicsDSL DSL specifications, the originating spec is included as a comment in every generated source file.


Examples

Arduino

Example System Rate Hardware
arduino_pendulum/ Simple pendulum + MPU6050 IMU 250 Hz Arduino Uno
arduino_double_pendulum/ Double pendulum (chaotic) 200 Hz Arduino Mega 2560

Raspberry Pi

Example System Rate Features
raspberry_pi_pendulum/ Simple pendulum 250 Hz pigpio, POSIX RT scheduling, NEON, GPIO energy alert
raspberry_pi_double_pendulum/ Double pendulum 200 Hz pigpio, POSIX RT scheduling, GPIO energy alert

Repository Structure

mechanicsdsl-embedded/
├── examples/
│   ├── arduino_pendulum/          .ino + README
│   ├── arduino_double_pendulum/   .ino + README
│   ├── raspberry_pi_pendulum/     .cpp + README
│   └── raspberry_pi_double_pendulum/ .cpp + README
├── cmake/
│   └── arm-toolchain.cmake        ARM cross-compilation toolchain
├── docker/
│   ├── Dockerfile                 ARM cross-compilation environment
│   └── docker-compose.yml
├── scripts/
│   ├── cross_compile_arm.sh       One-command ARM build via Docker
│   └── monitor_serial.py          Real-time serial CSV plotter
├── docs/
│   ├── getting_started.md
│   └── hardware_guide.md          Wiring, platform support, performance notes
└── tests/
    └── test_eom.py                Physics correctness via SciPy reference

Quick Start

Arduino

  1. Open examples/arduino_pendulum/pendulum_realtime.ino in Arduino IDE
  2. Select board and port → Upload
  3. Open Serial Monitor at 115200 baud

Raspberry Pi

sudo apt-get install pigpio libpigpio-dev cmake g++
mkdir build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
make -j$(nproc)
sudo ./pendulum_rpi

ARM Cross-Compilation (from x86 host)

./scripts/cross_compile_arm.sh
scp build_arm/pendulum_rpi pi@<ip>:~/
ssh pi@<ip> "sudo ~/pendulum_rpi"

Real-Time Serial Monitor

pip install pyserial matplotlib numpy
python scripts/monitor_serial.py --port /dev/ttyUSB0

Testing (no hardware required)

pip install pytest numpy scipy
pytest tests/ -v

Physics correctness is validated against SciPy reference integrations, period accuracy, energy conservation, equilibrium stability.


Code Generation

mechanicsdsl-embed compiles any .msl spec (or core preset) through mechanicsdsl-core and emits source for the chosen target:

pip install mechanicsdsl-embedded
mechanicsdsl-embed targets
mechanicsdsl-embed generate pendulum --target arduino -o build/
mechanicsdsl-embed generate pendulum --target raspberry_pi -o build/
mechanicsdsl-embed generate my_system.msl --target c_header --precision float -o build/
mechanicsdsl-embed generate double_pendulum --target rust_no_std -o crates/
Target Output Notes
arduino .ino sketch core ArduinoGenerator, serial plotter output
raspberry_pi .cpp core ARMGenerator, NEON
arm_bare .cpp core ARMGenerator, Cortex-M, no OS
c_header single .h portable C99, float or double, RK4 + energy, CSE-optimised; works on any MCU
rust_no_std Cargo crate #![no_std], no allocator, libm only; Cortex-M / RISC-V

Before you flash: inspect, budget, verify

mechanicsdsl-embed inspect double_pendulum                      # coordinates, parameters, EOM, energy
mechanicsdsl-embed budget double_pendulum --rate 1000 --mflops 20   # ops/step, MFLOP/s needed, RAM
mechanicsdsl-embed verify double_pendulum --dt 0.001 --duration 10  # RK4 energy drift at your dt

budget counts floating-point operations after common-subexpression elimination, which is what the generated code actually executes. verify integrates with the same fixed-step RK4 the generated code uses and fails (exit code 4) if energy drift exceeds --tolerance, so you can choose a timestep on the desktop instead of on the bench.

How generated code is checked

The test suite compiles every c_header output with gcc -std=c99 -Wall -Wextra -Werror -pedantic, runs 1000 RK4 steps, and compares the state with a Python RK4 reference (double precision to 1e-12, float to 1e-4). Rust expressions are evaluated numerically against SymPy, and the crate is built with cargo test in CI where a Rust toolchain exists.


Contributing

See CONTRIBUTING.md. Hardware validation on new platforms especially welcome.

License

MIT License; see LICENSE.

Metadata

Release files for mechanicsdsl-embedded 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-embedded 0.2.0
File Size Uploaded Provenance Actions
mechanicsdsl_embedded-0.2.0.tar.gz 40.8 kB With provenance Details for mechanicsdsl_embedded-0.2.0.tar.gz

Built distribution (wheel)

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

Total release size: 62.9 kB

Release files / mechanicsdsl_embedded-0.2.0.tar.gz

Download URL mechanicsdsl_embedded-0.2.0.tar.gz
Size 40.8 kB
Tags Source
SHA-256 checksum
How to use checksums
35364f2cc85d2c3e64a7479d10ebfb5279e7ddfe8fd50efe6f46c6e7e7b2339b
BLAKE2b-256 checksum
How to use checksums
9471d25ac9c3dd951b02f580909b47a63e834c34e7e546dff191f2c38e52463c
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_embedded-0.2.0-py3-none-any.whl

Download URL mechanicsdsl_embedded-0.2.0-py3-none-any.whl
Size 22.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8bb14c4e3702c4509c7314a5955ae40118fa0c654f6de72e77ef6afd0093446e
BLAKE2b-256 checksum
How to use checksums
5018bb1ba7a84076a095be43cf3eb19e0d8e16ae486c3dfd6df9dc079f592b59
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-embedded 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_embedded-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