Skip to content

.bd files

Peter Corke edited this page Aug 6, 2024 · 3 revisions

bdsim supports models expressed in JSON format text files, which have the extension .bd. These contain a full description of the model including all block and wire parameters as well as visual information which is used by bdedit.

A .bd file is ASCII text and can be easily modified using any text editor.

Importing a .bd file

A block diagram instance can be created by

from bdsim import bdload, BDSim

sim = BDSim(animation=True)
bd = sim.blockdiagram()

bd = bdload(bd, "eg1.bd")

Note that the parameters of the blocks in the JSON file can only be simple types such as ints, floats, strings or lists of these simple types. For more complex parameters such as objects (robots, cameras, poses etc.) or functions they are referenced in the file as a string prefixed by an equal sign, which is a reference to a local variable. For example the parameter '=myparam' is a reference to a local variable myparam that must exist before the model is loaded.

from bdsim import bdload, BDSim
from spatialmath import SE3

sim = BDSim(animation=True)
bd = sim.blockdiagram()

myparam = SE.Tx(1.2)

bd = bdload(bd, model, globalvars=globals())

Creating a .bd file

The interactive editing tool bdedit is the easiest way to create such a file.