-
Notifications
You must be signed in to change notification settings - Fork 37
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.
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)- familiar block diagram factory object
- you can use all the arithmetic and function blocks like
GAIN,SUM,FUNCTION,MUX,DICTetc. - you can use all the sampled-data blocks like
INTEGRATOR_S,DERIV_S,PID_S,LTI_SISO_Setc.
- Use
BDRealTimerather thanBDSim. - 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
SCOPEblocks
-
ANALOGINinput from an analog-to-digital converter (ADC) (int or float) -
ANALOGOUTcommand output from a digital-to-analog converter (DAC) (int or float) -
DIGITALINinput from a digital line (bool) -
DIGITALOUToutput to a digital line (bool) -
PWMOUToutput to a pulse-width-modulated output, more common on low-end hardware than a DAC (int or float) -
TELEMETRYstream signals via UDP/JSONL to atelemetry_clientrunning 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.
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)
Current practical status:
-
rpiprovider is the currently used/working hardware path. -
serialprovider framework exists; TCLab driver is implemented but not yet hardware-validated in this repo. -
firmataandarduioproviders are scaffolds/prototypes.
For setup, wiring, and troubleshooting by provider, use:
Use TELEMETRY in your diagram and run:
telemetry-client --listen 0.0.0.0:5001Copyright (c) Peter Corke 2020-
- Home
- Control Systems Magazine article
- FAQ
- Changes
- Adding blocks
- Block path
- Connecting blocks
- Subsystems
- Compiling
- Running
- Runtime options
- Discrete-time blocks
- Figures
- Notebook animation
- PID control
- Coding patterns
- Block methods and attributes
- Event handling
- Discrete-time dynamics
- Blocks, wires and plug
- Discrete-time blocks
- Evaluation
- Runtimes and simulator state
- Creating a new block
- Future & related work
Under development on feat/realtime branch