-
-
Notifications
You must be signed in to change notification settings - Fork 40
Adding blocks to your model
The first step is to create a Simulation object instance
import bdsim
sim = bdsim.BDSim()
bd = sim.blockdiagram()
which loads blocks from a number of modules in the bdsim/blocks folder.
We create blocks using this object's factory methods. For example
gain = bd.GAIN(4)
is a gain block represented by an instance of the class Gain
>>> type(gain)
<class 'bdsim.blocks.functions.Gain'>
which has the class hierarchy Gain → FunctionBlock → Block.
Block-catalog shows how to obtain a list of all available blocks.
Blocks belong to several main subclasses:
Source blocks (subclass of SourceBlock → Block) have an output, but no inputs.
| Name | Description |
|---|---|
| CONSTANT | A constant of any type |
| PIECEWISE | a piecewise constant function of time |
| RAMP | a linear ramp with a start time |
| STEP | a step (Heaviside) function of time |
| TIME | time since start of simulation |
| WAVEFORM | sine, square or triangle function of time |
Sink blocks (subclass of SinkBlock → Block) have inputs, but no outputs.
| Name | Description |
|---|---|
| EVENT | trigger an event when condition becomes true |
| NULL | discards all data |
| Print value to console | |
| STOP | Stop simulation when condition is true |
| WATCH | Add input to the watch list |
Display blocks (subclass of GraphicsBlock → SinkBlock → Block) are graphical sinks.
| Name | Description |
|---|---|
| ANIMATION | Create an animation from user-defined setup/update functions |
| SCOPE | Plot signals as function of time |
| SCOPEXY | Plot one signal against another |
| SCOPEXY1 | Plot one signal against another with optional clipping |
Function blocks (subclass of FunctionBlock → Block) have inputs and outputs and perform some linear or non-linear operation.
| Name | Description |
|---|---|
| CLIP | limit signal values |
| FUNCTION | apply Python function to inputs |
| GAIN | multiply input by constant, any of input or constant can be numpy arrays |
| INTERPOLATE | 1D interpolation of data |
| POW | raise input signal to a power |
| PROD | multiplication and division of signals |
| SUM | addition and subtraction of signals |
Linear algebra blocks (subclass of FunctionBlock → Block) have inputs and outputs.
| Name | Description |
|---|---|
| COND | matrix condition number |
| DET | matrix determinant |
| FLATTEN | flatten matrix to 1D array |
| INVERSE | matrix inverse |
| NORM | vector norm |
| SLICE1 | slice of 1D array |
| SLICE2 | slice of 2D array |
| TRANSPOSE | matrix transpose |
Continuous blocks (subclass of ContinuousBlock → Block) have inputs and outputs and state and represent differential equations. TransferBlock, seen in older code, is a deprecated alias for ContinuousBlock — it's a subclass of ContinuousBlock, not the other way round.
| Name | Description |
|---|---|
| INTEGRATOR | integration of input signals |
| LTI_SISO | dynamic system described in transfer-function form |
| LTI_SS | dynamic system described in state-space form |
| DERIV2 | derivative with second-order smoothing |
Two more blocks are commonly used alongside these but aren't literally ContinuousBlock subclasses — they're SubsystemBlocks composed internally from simpler blocks:
| Name | Description |
|---|---|
| DERIV | derivative with first-order smoothing |
| PID | PID control subsystem |
Sampled blocks (subclass of SampledBlock → Block) have inputs and outputs and state and represent sampled-data dynamics. ClockedBlock, seen in older code, is a deprecated alias for SampledBlock.
| Name | Description |
|---|---|
| DERIV_S | derivative, first order difference |
| INTEGRATOR_S | integration of input signals |
| LTI_SISO_S | dynamic system described in transfer-function form |
| LTI_SS_S | dynamic system described in state-space form |
| ZOH | zero-order hold |
DINTEGRATOR is a deprecated alias for INTEGRATOR_S, not a separate block.
As with DERIV/PID above, PID_S is a SubsystemBlock rather than a literal SampledBlock subclass:
| Name | Description |
|---|---|
| PID_S | PID control subsystem |
Connection blocks (subclass of FunctionBlock → Block) manipulate vector and dict signals.
| Name | Description |
|---|---|
| DICT | convert input signals to a dict of signals |
| DEMUX | split a vector signal to individual signals |
| INDEX | index/slice selection for vectors, arrays, lists, tuples, strings, or dicts |
| ITEM | select specific item from a dict signal |
| MUX | concatenate signals into a vector signal |
Subsystem blocks (subclass of SubsystemBlock → Block) connect a block diagram subsystem to a parent block diagram.
| Name | Description |
|---|---|
| INPORT | Inputs to the subsystem, like a SourceBlock
|
| OUTPORT | Outputs from the subsystem, like a SinkBlock
|
| SUBSYSTEM | Represents the subsystem in the parent block diagram, like a FunctionBlock
|
The inputs to a SUBSYSTEM block are the outputs of that subsystem's INPORT, and the inputs to the subsystem's OUTPORT are the outputs of the SUBSYSTEM block.
Unlike Simulink, there is only one input or output block per subsystem, but they can have multiple inputs each.
Hardware I/O blocks (ANALOGIN, ANALOGOUT, DIGITALIN, DIGITALOUT, PWMOUT, TELEMETRY) are source/sink
blocks that bind to a runtime I/O provider. They currently live on the unmerged feat/realtime branch, not
main — see Real-time overview.
Spatial blocks mostly operate on SO2/SO3/SE2/SE3 types when spatialmath is installed (subclass of FunctionBlock → Block), except for the two pose integrators which are stateful (ContinuousBlock/SampledBlock subclasses).
| Name | Description |
|---|---|
| POSE_INVERSE | inverse of pose input |
| POSE_POSTMUL | post-multiply input pose by a constant pose |
| POSE_PREMUL | pre-multiply input pose by a constant pose |
| TRANSFORM_VECTOR | transform Euclidean vector by pose input |
| POSEINTEGRATOR | integrate spatial velocity to pose (continuous-time) |
| DPOSEINTEGRATOR | integrate spatial velocity to pose (sampled-data) |
vision.py is currently a placeholder module; there are no registered vision blocks at this time.
When toolboxes=True (the default), bdsim also loads block sets contributed by
robotics-toolbox-python (RTB) and machinevision-toolbox-python (MVTB). These packages own and
document their own blocks in full; the tables below are a quick-reference index of what's currently
registered (sim.blocks(), see Block path), not a substitute for their own docs.
| Module | Blocks |
|---|---|
roboticstoolbox.blocks.arm |
FKINE, IKINE, JACOBIAN, ARMPLOT, JTRAJ, CTRAJ, CIRCLEPATH, TRAPEZOIDAL, TRAJ, IDYN, GRAVLOAD_X, INERTIA, INERTIA_X, FDYN, FDYN_X |
roboticstoolbox.blocks.mobile |
BICYCLE, UNICYCLE, DIFFSTEER, VEHICLEPLOT |
roboticstoolbox.blocks.spatial |
TR2DELTA, DELTA2TR, POINT2TR, TR2T |
roboticstoolbox.blocks.uav |
MULTIROTOR, MULTIROTORMIXER, MULTIROTORPLOT |
A few worth calling out directly since they appear elsewhere in this wiki:
| Name | Description |
|---|---|
| ARMPLOT | Animate robot arm using Matplotlib |
| VEHICLEPLOT | Animate a wheeled vehicle's pose using Matplotlib |
| BICYCLE | Bicycle kinematics as for a car-like vehicle |
| UNICYCLE | Unicycle kinematics |
| DIFFSTEER | Differential-steer kinematics with wheel speed inputs |
| MULTIROTOR | Dynamics of a multi-rotor drone |
| Module | Blocks |
|---|---|
machinevisiontoolbox.blocks.camera |
CAMERA, VISJAC_P, ESTPOSE_P, IMAGEPLANE |
Copyright (c) Peter Corke 2020-
- Home
- API reference (Sphinx)
- Block catalog
- Control Systems Magazine article
- Adding blocks to your model
- Block path
- Connecting blocks
- Compiling
- Running
- Watching a simulation variable
- Simulation results
- Runtime options
- Environment variables
- Discrete-time blocks
- Subsystems
- Figures
- Notebook animation
- Animation and movies
- PID control
- Coding patterns
- Block methods and attributes
- Time stepping: integration, animation & events
- Blocks, wires and plugs
- Graphics blocks
- Evaluation
- Runtimes and simulator state
- Creating a new block
- Related packages
Under development on feat/realtime branch, planned for release before end of 2026.