Skip to content

Conversation

@jimsynz
Copy link
Contributor

@jimsynz jimsynz commented Dec 27, 2025

Summary

  • Add runtime simulation mode via start_link(simulation: :kinematic) allowing robots to run without physical hardware
  • Actuators are replaced with BB.Sim.Actuator which publishes BeginMotion messages with timing based on joint velocity limits
  • Controllers and bridges support per-component simulation DSL option (:omit, :mock, :start)
  • Safety system works normally in simulation - must arm before commands
  • OpenLoopPositionEstimator works unchanged for position feedback

Usage

# Start in simulation mode
MyRobot.start_link(simulation: :kinematic)

# Check simulation mode at runtime
BB.Robot.Runtime.simulation_mode(MyRobot)  # => :kinematic

# Per-controller/bridge simulation behaviour in DSL
controllers do
  controller :pca9685, {BB.Servo.PCA9685.Controller, bus: "i2c-1"},
    simulation: :omit  # :omit (default), :mock, or :start
end

parameters do
  bridge :mavlink, {BBMavLink.ParameterBridge, conn: "/dev/ttyACM0"},
    simulation: :omit
end

Test plan

  • Robot starts in simulation mode with simulation: :kinematic
  • Robot starts in hardware mode by default
  • Simulated actuator publishes BeginMotion on position command
  • Simulated actuator clamps position to joint limits
  • Synchronous position command returns acknowledgement
  • Controller with simulation: :omit is not started in simulation mode
  • Controller with simulation: :omit is started in hardware mode
  • Controller with simulation: :mock starts mock controller
  • Controller with simulation: :start starts real controller
  • Bridge with simulation: :omit is not started in simulation mode
  • Bridge with simulation: :omit is started in hardware mode
  • Bridge with simulation: :mock starts mock bridge
  • Bridge with simulation: :start starts real bridge
  • All 555 tests pass
  • Dialyzer, credo, formatter all pass

@jimsynz jimsynz merged commit 9c3090f into main Dec 28, 2025
14 checks passed
Add runtime simulation mode via `start_link(simulation: :kinematic)`.
A single robot definition now works for both hardware and simulation.

Changes:
- Runtime option to start robots in kinematic simulation mode
- Actuators are replaced with `BB.Sim.Actuator` which publishes
  `BeginMotion` messages with timing based on joint velocity limits
- Controllers and bridges support per-component `simulation` option:
  - `:omit` (default) - don't start in simulation
  - `:mock` - start a no-op mock
  - `:start` - start the real component
- `BB.Robot.Runtime.simulation_mode/1` to check current mode
- Safety system works normally (must arm before commands)
- `OpenLoopPositionEstimator` works unchanged for position feedback

New modules:
- `BB.Sim.Actuator` - kinematic simulation actuator
- `BB.Sim.Controller` - no-op mock controller
- `BB.Sim.Bridge` - no-op mock bridge

Documentation:
- New tutorial: `10-simulation.md`
- Updated AGENTS.md with simulation mode info
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants