Skip to content

Real time control

Peter Corke edited this page May 25, 2026 · 3 revisions

Major update: May 2026

bdsim supports soft real-time control of sampled systems via BDRealTime. The same block/wire programming model is used as simulation mode, but runtime evaluation is aligned to wall clock ticks from one or more CLOCK blocks.

Quick start

from bdsim.realtime import BDRealTime

rt = BDRealTime(io_provider="rpi", toolboxes=False)
bd = rt.blockdiagram()

clock = bd.clock(0.02, name="clock")
u = bd.WAVEFORM(wave="square", freq=0.25, min=0.25, max=0.75)
y = bd.PWMOUT(clock, channel=18, freq=10_000)
bd.connect(u, y)

bd.compile()
out = rt.run(bd, tf=30)

What is the same as simulation mode

  • familiar block diagram factory object
  • you can use all the arithmetic and function blocks like GAIN, SUM, FUNCTION, MUX, DICT etc.
  • you can use all the sampled-data blocks like INTEGRATOR_S, DERIV_S, PID_S, LTI_SISO_S etc.

What is different from simulation mode

  • Use BDRealTime rather than BDSim.
  • Diagram execution is sampled and clocked; no continuous-state integration (no blocks like INTEGRATOR, DERIV, PID, LTI_SISO)
  • Use I/O blocks bind to a runtime-selected provider (rpi, serial, mock, ...).
  • No local plotting using SCOPE blocks

Realtime I/O blocks

  • ANALOGIN input from an analog-to-digital converter (ADC) (int or float)
  • ANALOGOUT command output from a digital-to-analog converter (DAC) (int or float)
  • DIGITALIN input from a digital line (bool)
  • DIGITALOUT output to a digital line (bool)
  • PWMOUT output to a pulse-width-modulated output, more common on low-end hardware than a DAC (int or float)
  • TELEMETRY stream signals via UDP/JSONL to a telemetry_client running on a desktop or laptop for real-time dispay

These I/O blocks are hardware agnostic, the mapping to hardware happens in the I/O provider, see below.

Timer backends

BDRealTime.run(..., backend=...) supports:

  • auto (default): choose platform backend
  • gcd: macOS Grand Central Dispatch timers
  • thread: portable thread timers
  • posix: scaffold only (not implemented yet)

Provider status

Current practical status:

  • rpi provider is the currently used/working hardware path.
  • serial provider framework exists; TCLab driver is implemented but not yet hardware-validated in this repo.
  • firmata and arduio providers are scaffolds/prototypes.

For setup, wiring, and troubleshooting by provider, use:

Telemetry client

Use TELEMETRY in your diagram and run:

telemetry-client --listen 0.0.0.0:5001

Clone this wiki locally