Python bindings for YAMS (Yet Another Mechanism System), built with Semi-wrap, pybind11 and Meson.
This project exposes the real YAMS C++ mechanism library to Python. It is not a Python reimplementation: Semi-wrap parses the upstream headers, generates pybind11 wrappers, and Meson compiles those wrappers together with the upstream YAMS sources and the WPILib static libraries into a single extension module.
import yams
motor_config = (
yams.SmartMotorControllerConfig()
.with_motor_gearing(10.0)
.with_subsystem(yams.SimSubsystem("arm"))
.with_starting_position(0.0)
)
motor = yams.SimMotorController(motor_config)
arm = yams.Arm(
yams.ArmConfig()
.with_arm_length(1.0)
.with_min_angle(-90.0)
.with_max_angle(90.0),
motor,
)
motor.set_duty_cycle(0.5)
for _ in range(10):
arm.sim_iterate()
print(arm.get_angle()) # degreesThe package is not currently published on PyPI. Build a wheel from this repository (see below), or install a wheel produced by the CI workflow.
- Mechanisms:
Arm,Elevator,Pivot,FlyWheel, plus theSmartMechanismhierarchy. - Motor-control configuration and simulation:
SmartMotorControllerConfig,SimMotorController,SimSubsystem, simulation suppliers. - Gearing and math:
GearBox,Sprocket,MechanismGearing,SmartMath,LQRConfig,LQRController,DerivativeTimeFilter,EasyCRT. - Configuration value types, enums, telemetry fields, and YAMS exceptions.
Vendor motor-controller wrappers (CTRE TalonFX/TalonFXS, REV Spark Max,
ThriftyLib Nova) are intentionally not included because they require
non-redistributable vendor libraries. Use SimMotorController for hardware-free
development, testing and simulation.
| Platform | Status |
|---|---|
| Linux x86-64 | Built and tested locally and in CI |
| Linux aarch64 | Not built or verified |
| macOS (Apple Silicon) | Covered by CI; not verified locally |
| Windows x86-64 | Covered by CI; not verified locally |
The native archives are pinned and verified for Linux x86-64/arm64, macOS, and
Windows x86-64. The link arguments are selected per platform in meson.build:
GNU ld archives are grouped on Linux, the Mach-O archives are listed on macOS,
and the MSVC import libraries are linked by path on Windows. The macOS archives
are universal; CI exercises the arm64 runner and does not build the Intel slice
separately.
The build requires a C++23 compiler (GCC 14+, Clang 17+ with a standard
library providing <print>, or current MSVC), Meson, Ninja, and network access
to the WPILib Maven repository the first time native dependencies are fetched.
CPython 3.12 or newer is required; the wheel and tests have been verified with
CPython 3.14 locally, and CI targets CPython 3.12, 3.13, and 3.14.
pip install yams-0.1.0-cp314-cp314-linux_x86_64.whlWheels built on this Nix host require that host's glibc. For distribution, use
a wheel produced by CI and repaired with auditwheel (see
docs/development.md).
python -m venv .venv
. .venv/bin/activate
python -m pip install --upgrade pip build
python -m build --wheel
pip install dist/*.whlpython -m build installs the pinned build requirements in an isolated
environment. To use the active environment instead:
python -m pip install build "semiwrap==0.8.1" "hatch-meson>=0.1.3" \
"hatchling>=1.33.0" "patchelf; sys_platform == 'linux'" \
pybind11 "pybind11-stubgen~=2.5.1" meson ninja
python -m build --wheel --no-isolationThe custom build hook downloads the pinned WPILib headers and static
libraries with SHA-256 verification. See
docs/installation.md for system requirements and a
clean-environment verification recipe.
python -m pip install -e . --no-build-isolation
pytestAlternatively compile with Meson directly:
python tools/fetch_native_deps.py --prefix native
meson setup builddir
ninja -C builddir
ln -sf "$PWD/builddir/semiwrap/modules/_yams"*.so yams/
PYTHONPATH=. python -c "import yams"vendor/YAMS C++ headers + sources
│
├── semiwrap/*.yml ──> generated pybind11 wrappers, trampolines, Meson
│
cpp/ (adapters, type casters, module entry point)
│
└── Meson + Ninja ──> yams._yams extension ──> yams package ──> wheel
pyproject.tomlconfigures hatchling with three hooks:custom(hatch_build.py) fetches WPILib and polishes the wheel,semiwrapgenerates the bindings, andmesoncompiles the extension.semiwrap/*.ymlis the source of truth for the exposed API.cpp/contains only binding glue: theSimMotorControlleradapter,SimSubsystem, unit type casters, and thestd::initializer_listhelper.vendor/YAMSis pinned tov2026.10.19(48085344887361058a25661aea57031cedea0d21);vendor/semiwrapis pinned to0.7.2(b3cccdb82882bf0dffc6862fb60d939bc89547fa).
More detail: docs/development.md.
C++ std::initializer_list methods accept Python sequences:
gearbox = yams.GearBox.from_reduction_stages([10.0, 2.0])
gearbox = yams.GearBox.from_stages(["10:1", "2:1"])
gearbox = yams.GearBox.from_teeth([12, 36, 12, 36])
sprocket = yams.Sprocket.from_stages(["10:1", "2:1"])Unit types are exposed as Python float values. The unit is part of each
method's documented meaning, not its Python type. See
docs/api.md for the full API and unit conventions.
Mechanisms drive the simulated motor controller. Advance simulation with
mechanism.sim_iterate(); calling smc.sim_iterate() alone does not move the
mechanism. Closed-loop commands need configured gains and feedback. See
examples/simulated_arm.py.
All YAMS exceptions derive from yams.YamsException, which derives from
Python's Exception:
try:
yams.SmartMath.gear_box([])
except yams.NoStagesGivenException:
....venv/bin/python -m pytest -qThe suite exercises the compiled extension: imports, configuration builders, gearing and type conversion, enum values, simulated mechanisms, exceptions, encoder state, and absolute-encoder solving. Tests do not use hardware or vendor libraries.
docs/installation.md— platforms, prerequisites, source builds, clean-environment wheel verification.docs/development.md— submodules, Semi-wrap YAML workflow, Meson integration, custom bindings, stub generation.docs/api.md— exported classes, methods, units, ownership, and limitations.docs/troubleshooting.md— build, linker, RPATH, auditwheel, import, and simulation problems.examples/simulated_arm.py— verified hardware-free example.
- Vendor hardware controllers are not bound.
- Linux aarch64 (RoboRIO/SystemCore class targets) is not built or tested.
to_robot_attitudetakes a WPILibRotation3d, which this project does not bind, so it is only usable with a value produced by another extension.SmartMotorControllerTelemetryConfigis not bound because it is non-copyable and libstdc++ incorrectly reports it as copy-constructible.- Unit overloads that differ only by unit cannot be distinguished from Python and resolve in declaration order.
- Semi-wrap's built-in stub step is disabled; the hatch build generates stubs
separately with a permissive
pybind11-stubgeninvocation.
The bindings are distributed under LGPL-3.0-or-later, matching YAMS. See
LICENSE and THIRD_PARTY_NOTICES.md for
WPILib, pybind11, and Semi-wrap attribution.