Site upgrade: my notes, papers and tutorials are back, and so are my book recommendations

Take a look

bdsim

bdsim simulates dynamic systems expressed as block diagrams, much like Simulink®, except that the diagram is written as Python code rather than drawn. It handles continuous-time, discrete-time and hybrid systems, and the wires between blocks can carry any Python type: scalars, NumPy arrays, dictionaries, or objects such as the SE3 poses from the Spatial Maths Toolbox.

The first two editions of Robotics, Vision & Control, and the MATLAB version of the third, make extensive use of Simulink® models. There was no equivalent in the Python world, so I wrote bdsim for the Python version of the third edition, where it runs all the block-diagram models. Some of the thinking behind it is in this LinkedIn article.

An example

We first sketch the system we want to simulate, here a simple first-order plant under proportional control:

Hand-drawn block diagram: a step demand, summing junction, gain of 10 and first-order plant, with a scope showing demand and output

and then write it down, block by block and wire by wire:

import bdsim
sim = bdsim.BDSim()
bd = sim.blockdiagram()
# define the blocks
demand = bd.STEP(T=1, name="demand")
sum = bd.SUM("+-")
gain = bd.GAIN(10)
plant = bd.LTI_SISO(0.5, [2, 1])
scope = bd.SCOPE(styles=["k", "r--"])
# connect the blocks
bd.connect(demand, sum[0], scope[1])
bd.connect(plant, sum[1])
bd.connect(sum, gain)
bd.connect(gain, plant)
bd.connect(plant, scope[0])
bd.compile()
out = sim.run(bd, T=5)

Because the model is code, it can be kept in git, compared with diff, generated by a program, tested, and run in batches on a server. There is also a graphical editor, bdedit, for drawing diagrams.

Try it

The graphical editor is built with Qt and runs on the desktop. The layout is saved as a JSON file with .bd extension. When this is loaded it creates the objects and wires to form an executable block diagram object.

It’s not Simulink but it’s pretty handy.

Learn more