Skip to content

Adding blocks

Peter Corke edited this page Apr 13, 2022 · 8 revisions

The first step is to create a Simulation object instance

import bdsim

bd = bdsim.BDSim()

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 GainFunctionBlockBlock.

Blocks belong to one of four main subclasses:

Standard blocks

Sources

Source blocks (subclass of SourceBlockBlock) 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

Sinks

Sink blocks (subclass of SinkBlockBlock) have inputs, but no outputs.

Name Description
NULL discards all data
PRINT Print value to console
STOP Stop simulation when condition is true
WATCH Add input to the watch list
SCOPE Plot signals as function of time
SCOPEXY Plot one signal against another
VEHICLE 2D animation of ground vehicle motion
MULTIROTORPLOT 3D animation of multi-rotor motion

Functions

Function blocks (subclass of FunctionBlockBlock) 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
PROD multiplication and division of signals
SUM addition and subtraction of signals

Linear algebra

Linear algebra blocks (subclass of FunctionBlockBlock) 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

Transfers

Transfer blocks (subclass of TransferBlockBlock) have inputs and outputs and state and represent differential equations.

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
POSEINTEGRATOR integrate spatial velocity to pose

Discrete-time transfers

Transfer blocks (subclass of TransferBlockBlock) have inputs and outputs and state and represent continuous-time differential equations.

Name Description
DINTEGRATOR integration of input signals
DPOSEINTEGRATOR integrate spatial velocity to pose
ZOH zero-order hold

Connections

Connection blocks (subclass of FunctionBlockBlock) manipulate vector and dict signals.

Name Description
MUX concatenate signals into a vector signal
DEMUX split a vector signal to individual signals
DICT convert input signals to a dict of signals
ITEM select specific item from a dict signal

Subsystem blocks (subclass of SubsystemBlockBlock) 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.

External block sets

Robotics

Robot models

Robot blocks.

Name Description
ARMPLOT Animate robot arm using Matplotlib
CTRAJ Cartesian trajectory
CIRCLEPATH circular trajectory
DELTA2TR spatial displacement to SE(3)
FDYN manipulator forward dynamics
FDYN_X manipulator forward dynamics in task space
FKINE manipulator forward kinematics trajectory
GRAVLOAD manipulator forward kinematics trajectory
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

Machine Vision