Block library¶
The block diagrams comprise blocks which belong to one of a number of different categories. These come from
the package bdsim.blocks, roboticstoolbox.blocks, machinevisiontoolbox.blocks.
Icons, if shown to the left of the black header bar, are as used with bdedit.

Source blocks¶
Source blocks:
have outputs but no inputs
have no state variables
are a subclass of
SourceBlock→Block
-
class
bdsim.blocks.sources.Constant(*args, bd=None, **kwargs)[source]¶ Bases:
bdsim.components.SourceBlockCONSTANT
inputs
outputs
states
0
1
0
float, A(N,)
-
__init__(value=None, **blockargs)[source]¶ Constant value.
- Parameters
value (any, optional) – the constant, defaults to None
blockargs – common Block options
- Returns
a CONSTANT block
- Return type
Constant instance
This block has only one output port, but the value can be any Python type, for example float, list or Numpy ndarray.
-
-
class
bdsim.blocks.sources.Piecewise(*args, bd=None, **kwargs)[source]¶ Bases:
bdsim.components.SourceBlockPIECEWISE
inputs
outputs
states
0
1
0
float
-
__init__(*seq, **blockargs)[source]¶ Piecewise constant signal.
- Parameters
seq (list of 2-tuples) – sequence of time, value pairs
blockargs (dict) – common Block options
- Returns
a PIECEWISE block
- Return type
Piecewise instance
Outputs a piecewise constant function of time. This is described as a series of 2-tuples (time, value). The output value is taken from the active tuple, that is, the latest one in the list whose time is no greater than simulation time.
Note
The tuples must be order by monotonically increasing time.
There is no default initial value, the list should contain a tuple with time zero otherwise the output will be undefined.
Note
The block declares an event for the start of each segment.
- Seealso
declare_events()
-
-
class
bdsim.blocks.sources.Ramp(*args, bd=None, **kwargs)[source]¶ Bases:
bdsim.components.SourceBlockRAMP
inputs
outputs
states
0
1
0
float
-
__init__(T=1, off=0, slope=1, **blockargs)[source]¶ Ramp signal.
- Parameters
T (float, optional) – time of ramp start, defaults to 1
off (float, optional) – initial value, defaults to 0
slope (float, optional) – gradient of slope, defaults to 1
blockargs (dict) – common Block options
- Returns
a RAMP block
- Return type
Output a ramp signal that starts increasing from the value
offwhen time equalsTlinearly with time, with a gradient ofslope.Note
The block declares an event for the ramp start time.
- Seealso
-
-
class
bdsim.blocks.sources.Step(*args, bd=None, **kwargs)[source]¶ Bases:
bdsim.components.SourceBlockSTEP
inputs
outputs
states
0
1
0
float
-
__init__(T=1, off=0, on=1, **blockargs)[source]¶ Step signal.
- Parameters
T (float, optional) – time of step, defaults to 1
off (float, optional) – initial value, defaults to 0
on (float, optional) – final value, defaults to 1
blockargs (dict) – common Block options
- Returns
a STEP block
- Return type
Output a step signal that transitions from the value
offtoonwhen time equalsT.Note
The block declares an event for the step time.
- Seealso
declare_events()
-
-
class
bdsim.blocks.sources.Time(*args, bd=None, **kwargs)[source]¶ Bases:
bdsim.components.SourceBlockTIME
inputs
outputs
states
0
1
0
float
-
__init__(value=None, **blockargs)[source]¶ Simulation time.
- Parameters
blockargs (dict) – common Block options
- Returns
a TIME block
- Return type
Time instance
The block has only one output port which is the current simulation time.
-
-
class
bdsim.blocks.sources.WaveForm(*args, bd=None, **kwargs)[source]¶ Bases:
bdsim.components.SourceBlockWAVEFORM
inputs
outputs
states
0
1
0
float
-
__init__(wave='square', freq=1, unit='Hz', phase=0, amplitude=1, offset=0, min=None, max=None, duty=0.5, **blockargs)[source]¶ Waveform as function of time.
- Parameters
wave (str, optional) – type of waveform to generate, one of: ‘sine’, ‘square’, ‘triangle’, defaults to ‘square’
freq (float, optional) – frequency, defaults to 1
unit (str, optional) – frequency unit, one of: ‘rad/s’, ‘Hz’, defaults to ‘Hz’
amplitude (float, optional) – amplitude, defaults to 1
offset (float, optional) – signal offset, defaults to 0
phase (float, optional) – Initial phase of signal in the range [0,1], defaults to 0
min (float, optional) – minimum value, defaults to 0
max (float, optional) – maximum value, defaults to 1
duty (float, optional) – duty cycle for square wave in range [0,1], defaults to 0.5
blockargs (dict) – common Block options
- Returns
a WAVEFORM block
- Return type
WaveForm instance
Create a waveform generator block.
Examples:
WAVEFORM(wave='sine', freq=2) # 2Hz sine wave varying from -1 to 1 WAVEFORM(wave='square', freq=2, unit='rad/s') # 2rad/s square wave varying from -1 to 1
The minimum and maximum values of the waveform are given by default in terms of amplitude and offset. The signals are symmetric about the offset value. For example:
WAVEFORM(wave='sine') varies between -1 and +1 WAVEFORM(wave='sine', amplitude=2) varies between -2 and +2 WAVEFORM(wave='sine', offset=1) varies between 0 and +2 WAVEFORM(wave='sine', amplitude=2, offset=1) varies between -1 and +3
Alternatively we can specify the minimum and maximum values which override amplitude and offset:
WAVEFORM(wave='triangle', min=0, max=5) varies between 0 and +5
At time 0 the sine and triangle wave are zero and increasing, and the square wave has its first rise. We can specify a phase shift with a number in the range [0,1] where 1 corresponds to one cycle.
Note
For discontinuous signals (square, triangle) the block declares events for every discontinuity.
:seealso
declare_events()
-
Sink blocks¶
Sink blocks:
have inputs but no outputs
have no state variables
are a subclass of
SinkBlock→Blockthat perform graphics are a subclass of
GraphicsBlock→SinkBlock→Block
-
class
bdsim.blocks.sinks.Null(*args, bd=None, **kwargs)[source]¶ Bases:
bdsim.components.SinkBlockNULL
inputs
outputs
states
N
0
0
any
-
__init__(nin=1, **blockargs)[source]¶ Discard signal.
- Parameters
nin (int, optional) – number of input ports, defaults to 1
blockargs (dict) – common Block options
- Returns
A NULL block
- Return type
Null instance
Create a sink block with arbitrary number of input ports that discards all data. Useful for testing.
-
-
class
bdsim.blocks.sinks.Print(*args, bd=None, **kwargs)[source]¶ Bases:
bdsim.components.SinkBlockPRINT
inputs
outputs
states
1
0
0
any
-
__init__(fmt=None, file=None, **blockargs)[source]¶ Print signal.
- Parameters
fmt (str, optional) – Format string, defaults to None
file (file object, optional) – file to write data to, defaults to None
blockargs (dict) – common Block options
- Returns
A PRINT block
- Return type
Print instance
Creates a console print block which displays the value of a signal at each simulation time step. The display format is like:
PRINT(print.0 @ t=0.100) [-1.0 0.2]
and includes the block name, time, and the formatted value.
The numerical formatting of the signal is controlled by
fmt:if not provided,
str()is used to format the signal- if provided:
a scalar is formatted by the
fmt.format()a NumPy array is formatted by
fmt.format()applied to every element
Examples:
pr = bd.PRINT() # create PRINT block bd.connect(x, inputs=pr) # its input comes from x bd.PRINT(x) # create PRINT block with input from x bd.PRINT(x, name='X') # block name appears in the printed text bd.PRINT(x, fmt="{:.1f}") # print with explicit format
Note
By default writes to stdout
The output is cleaner if progress bar printing is disabled.
-
-
class
bdsim.blocks.sinks.Stop(*args, bd=None, **kwargs)[source]¶ Bases:
bdsim.components.SinkBlockSTOP
inputs
outputs
states
1
0
0
any
-
__init__(func=None, **blockargs)[source]¶ Conditional simulation stop.
- Parameters
func (callable, optional) – evaluate stop condition, defaults to None
blockargs (dict) – common Block options
- Returns
A STOP block
- Return type
Stop instance
Conditionally stop the simulation if the input is:
bool type and True
numeric type and > 0
If
funcis provided, then it is applied to the block input and if it returns True the simulation is stopped.
-
-
class
bdsim.blocks.sinks.Watch(*args, bd=None, **kwargs)[source]¶ Bases:
bdsim.components.SinkBlockWATCH
inputs
outputs
states
N
0
0
1
-
__init__(**blockargs)[source]¶ Watch a signal.
- Parameters
blockargs (dict) – common Block options
- Returns
A NULL block
- Return type
Null instance
Causes the input signal to be logged during the simulation run. Equivalent to adding it as the
watch=argument tobdsim.run.- Seealso
-
Function blocks¶
Function blocks:
have inputs and outputs
have no state variables
are a subclass of
FunctionBlock→Block
-
class
bdsim.blocks.functions.Clip(*args, bd=None, **kwargs)[source]¶ Bases:
bdsim.components.FunctionBlockCLIP
inputs
outputs
states
1
1
0
float, A(N,)
float, A(N,)
-
__init__(min=- inf, max=inf, **blockargs)[source]¶ Signal clipping.
- Parameters
min (float or array_like, optional) – Minimum value, defaults to -math.inf
max (float or array_like, optional) – Maximum value, defaults to math.inf
blockargs (dict) – common Block options
- Returns
A CLIP block
- Return type
Clip instance
The input signal is clipped to the range from
minimumtomaximuminclusive.The signal can be a 1D-array in which case each element is clipped. The minimum and maximum values can be:
a scalar, in which case the same value applies to every element of the input vector , or
a 1D-array, of the same shape as the input vector that applies elementwise to the input vector.
For example:
clip = bd.CLIP()
-
-
class
bdsim.blocks.functions.Function(*args, bd=None, **kwargs)[source]¶ Bases:
bdsim.components.FunctionBlockFUNCTION
inputs
outputs
states
nin
nout
0
any
any
-
__init__(func=None, nin=1, nout=1, persistent=False, args=None, kwargs=None, **blockargs)[source]¶ Python function.
- Parameters
func (callable or sequence of callables, optional) – A function or lambda, or list thereof, defaults to None
nin (int, optional) – number of inputs, defaults to 1
nout (int, optional) – number of outputs, defaults to 1
persistent (bool, optional) – pass in a reference to a dictionary instance to hold persistent state, defaults to False
args (list, optional) – extra positional arguments passed to the function, defaults to []
kwargs (dict, optional) – extra keyword arguments passed to the function, defaults to {}
blockargs (dict, optional) – common Block options
- Returns
A FUNCTION block
- Return type
A Function instance
Inputs to the block are passed as separate arguments to the function. Programmatic ositional or keyword arguments can also be passed to the function.
A block with one output port that sums its two input ports is:
FUNCTION(lambda u1, u2: u1+u2, nin=2)
A block with a function that takes two inputs and has two additional arguments:
def myfun(u1, u2, param1, param2): pass FUNCTION(myfun, nin=2, args=(p1,p2))
If we need access to persistent (static) data, to keep some state:
def myfun(u1, u2, param1, param2, state): pass FUNCTION(myfun, nin=2, args=(p1,p2), persistent=True)
where a dictionary is passed in as the last argument and which is kept from call to call.
A block with a function that takes two inputs and additional keyword arguments:
def myfun(u1, u2, param1=1, param2=2, param3=3, param4=4): pass FUNCTION(myfun, nin=2, kwargs=dict(param2=7, param3=8))
A block with two inputs and two outputs, the outputs are defined by two lambda functions with the same inputs:
FUNCTION( [ lambda x, y: x_t, lambda x, y: x* y])
A block with two inputs and two outputs, the outputs are defined by a single function which returns a list:
def myfun(u1, u2): return [ u1+u2, u1*u2 ] FUNCTION( myfun, nin=2, nout=2)
For example:
func = bd.FUNCTION(myfun, args)
If inputs are specified then connections are automatically made and are assigned to sequential input ports:
func = bd.FUNCTION(myfun, block1, block2, args)
is equivalent to:
func = bd.FUNCTION(myfun, args) bd.connect(block1, func[0]) bd.connect(block2, func[1])
-
-
class
bdsim.blocks.functions.Gain(*args, bd=None, **kwargs)[source]¶ Bases:
bdsim.components.FunctionBlockGAIN
inputs
outputs
states
1
1
0
float, A(N,), A(N,M)
float, A(N,), A(N,M)
-
__init__(K=1, premul=False, **blockargs)[source]¶ Gain block.
- Parameters
K (array_like) – The gain value, defaults to 1
premul (bool, optional) – premultiply by constant, default is postmultiply, defaults to False
blockargs (dict) – common Block options
- Returns
A GAIN block
- Return type
Gain instance
Scale the input signal. If the input is \(u\) the output is \(u K\).
Either or both the input and gain can be Numpy arrays and Numpy will compute the appropriate product \(u K\).
If \(u\) and
Kare both NumPy arrays the@operator is used and \(u\) is postmultiplied by the gain. To premultiply by the gain, to compute \(K u\) use thepremuloption.For example:
gain = bd.GAIN(constant)
-
-
class
bdsim.blocks.functions.Interpolate(*args, bd=None, **kwargs)[source]¶ Bases:
bdsim.components.FunctionBlockINTERPOLATE
inputs
outputs
states
0 or 1
1
0
float
any
-
__init__(x=None, y=None, xy=None, time=False, kind='linear', **blockargs)[source]¶ Interpolate signal.
- Parameters
x (array_like, shape (N,) optional) – x-values of function, defaults to None
y (array_like, optional) – y-values of function, defaults to None
xy (array_like, optional) – combined x- and y-values of function, defaults to None
time (bool, optional) – x new is simulation time, defaults to False
kind (str, optional) – interpolation method, defaults to ‘linear’
blockargs (dict) – common Block options
- Returns
An INTERPOLATE block
- Return type
An Interpolate instance
Interpolate the input signal using to a piecewise function.
A simple triangle function with domain [0,10] and range [0,1] can be defined by:
INTERPOLATE(x=(0,5,10), y=(0,1,0))
We might also express this as a list of 2D-coordinats:
INTERPOLATE(xy=[(0,0), (5,1), (10,0)])
The data can also be expressed as Numpy arrays. If that is the case, the interpolation function can be vector valued.
xhas a shape of (N,1) andyhas a shape of (N,M). Alternativelyxyhas a shape of (N,M+1) and the first column is the x-data.The input to the interpolator comes from:
Input port 0
Simulation time, if
time=True. In this case the block has no input ports and is aSourcenot aFunction.
-
-
class
bdsim.blocks.functions.Prod(*args, bd=None, **kwargs)[source]¶ Bases:
bdsim.components.FunctionBlockPROD
inputs
outputs
states
len(ops)
1
0
float, A(N,), A(N,M)
float, A(N,), A(N,M)
-
__init__(ops='**', matrix=False, **blockargs)[source]¶ Product junction.
- Parameters
ops (str, optional) – operations associated with input ports, accepted characters: * or /, defaults to ‘**’
matrix (bool, optional) – Arguments are matrices, defaults to False
blockargs (dict) – common Block options
- Returns
A PROD block
- Return type
Prod instance
Multiply or divide input signals according to the ops string. The number of input ports is the length of this string.
For example:
prod = PROD('*/*')
is a 3-input product junction which computes port0 / port 1 * port2.
Implicit PROD blocks are created by:
sum = block1 block2
which will create a summation block named “_prod.N”.
Note
The inputs can be scalars or NumPy arrays.
By default the
*and/operators are used.The option
matrixwill instead use@and@ np.linalg.inv(). - the shapes of matrices must conform. - only square matrices are supported.
-
-
class
bdsim.blocks.functions.Sum(*args, bd=None, **kwargs)[source]¶ Bases:
bdsim.components.FunctionBlockSUM
inputs
outputs
states
len(signs)
1
0
float, A(N,), A(N,M)
float, A(N,), A(N,M)
-
__init__(signs='++', angles=False, **blockargs)[source]¶ Summing junction.
- Parameters
signs (str, optional) – signs associated with input ports, accepted characters: + or -, defaults to ‘++’
angles (bool, optional) – the signals are angles, wraps to [-pi,pi], defaults to False
blockargs (dict) – common `Block options <https://petercorke.github.io/bdsim/bdsim.html?highlight=block.__init__#bdsim.components.Block.__init__`_
- Returns
A SUM block
- Return type
Sum instance
Add or subtract input signals according to the signs string. The number of input ports is the length of this string.
For example:
sum = bd.SUM('+-+')
is a 3-input summing junction which computes port0 - port1 + port2.
Implicit SUM blocks are created by:
sum = block1 + block2
which will create a summation block named “_sum.N”.
Note
The signals must be compatible, all scalars, or all arrays of the same shape.
-
Transfer blocks¶
Transfer blocks:
have inputs and outputs
have state variables
are a subclass of
TransferBlock→Block
-
class
bdsim.blocks.transfers.Integrator(*args, bd=None, **kwargs)[source]¶ Bases:
bdsim.components.TransferBlockINTEGRATOR
inputs
outputs
states
1
1
N
float, A(N,)
float, A(N,)
-
__init__(x0=0, min=None, max=None, **blockargs)[source]¶ Integrator.
- Parameters
x0 (array_like, optional) – Initial state, defaults to 0
min (float or array_like, optional) – Minimum value of state, defaults to None
max (float or array_like, optional) – Maximum value of state, defaults to None
blockargs (dict) – common Block options
- Returns
an INTEGRATOR block
- Return type
Integrator instance
Output is the time integral of the input. The state can be a scalar or a vector. The initial state, and type, is given by
x0. The shape of the input signal must matchx0.The minimum and maximum values can be:
a scalar, in which case the same value applies to every element of the state vector, or
a vector, of the same shape as
x0that applies elementwise to the state.
-
-
class
bdsim.blocks.transfers.LTI_SISO(*args, bd=None, **kwargs)[source]¶ Bases:
bdsim.blocks.transfers.LTI_SSLTI_SISO
inputs
outputs
states
1
1
n
float
float
-
__init__(N=1, D=[1, 1], x0=None, **blockargs)[source]¶ SISO LTI dynamics.
- Parameters
N (array_like, optional) – numerator coefficients, defaults to 1
D (array_like, optional) – denominator coefficients, defaults to [1,1]
x0 (array_like, optional) – initial states, defaults to None
blockargs (dict) – common Block options
- Returns
A SCOPE block
- Return type
LTI_SISO instance
Implements the dynamics of a single-input single-output (SISO) linear time invariant (LTI) system described by numerator and denominator polynomial coefficients.
Coefficients are given in the order from highest order to zeroth order, ie. \(2s^2 - 4s +3\) is
[2, -4, 3].Only proper transfer functions, where order of numerator is less than denominator are allowed.
The order of the states in
x0is consistent with controller canonical form.Examples:
LTI_SISO(N=[1, 2], D=[2, 3, -4])
is the transfer function \(\frac{s+2}{2s^2+3s-4}\).
-
-
class
bdsim.blocks.transfers.LTI_SS(*args, bd=None, **kwargs)[source]¶ Bases:
bdsim.components.TransferBlockLTI_SS
inputs
outputs
states
1
1
nc
float, A(nb,)
float, A(nc,)
-
__init__(A=None, B=None, C=None, x0=None, **blockargs)[source]¶ State-space LTI dynamics.
- Parameters
N (array_like, optional) – numerator coefficients, defaults to 1
D (array_like, optional) – denominator coefficients, defaults to [1,1]
x0 (array_like, optional) – initial states, defaults to None
blockargs (dict) – common Block options
- Returns
A SCOPE block
- Return type
LTI_SISO instance
Implements the dynamics of a single-input single-output (SISO) linear time invariant (LTI) system described by numerator and denominator polynomial coefficients.
Coefficients are given in the order from highest order to zeroth order, ie. \(2s^2 - 4s +3\) is
[2, -4, 3].Only proper transfer functions, where order of numerator is less than denominator are allowed.
The order of the states in
x0is consistent with controller canonical form.Examples:
LTI_SISO(N=[1,2], D=[2, 3, -4])
is the transfer function \(\frac{s+2}{2s^2+3s-4}\).
-
-
class
bdsim.blocks.transfers.PoseIntegrator(*args, bd=None, **kwargs)[source]¶ Bases:
bdsim.components.TransferBlockPOSEINTEGRATOR
inputs
outputs
states
1
1
N
A(N,)
A(N,)
-
__init__(x0=None, **blockargs)[source]¶ Pose integrator
- Parameters
x0 (SE3, optional) – Initial pose, defaults to null
blockargs (dict) – common Block options
- Returns
an INTEGRATOR block
- Return type
Integrator instance
This block integrates spatial velocity over time. The block input is a spatial velocity as a 6-vector \((v_x, v_y, v_z, \omega_x, \omega_y, \omega_z)\) and the output is pose as an
SE3instance.Note
State is a velocity twist.
Warning
NOT WORKING YET
-
Discrete-time blocks¶
Transfer blocks:
have inputs and outputs
have state variables
are a subclass of
TransferBlock→Block
-
class
bdsim.blocks.discrete.DIntegrator(*args, bd=None, **kwargs)[source]¶ Bases:
bdsim.components.ClockedBlockDINTEGRATOR
inputs
outputs
states
1
1
N
float, A(N,)
float, A(N,)
-
__init__(clock, x0=0, gain=1.0, min=None, max=None, **blockargs)[source]¶ Discrete-time integrator.
- Parameters
clock (Clock) – clock source
x0 (array_like, optional) – Initial state, defaults to 0
min (float or array_like, optional) – Minimum value of state, defaults to None
max (float or array_like, optional) – Maximum value of state, defaults to None
blockargs (dict) – common Block options
- Returns
an INTEGRATOR block
- Return type
Integrator instance
Create a discrete-time integrator block.
Output is the time integral of the input. The state can be a scalar or a vector, this is given by the type of
x0.The minimum and maximum values can be:
a scalar, in which case the same value applies to every element of the state vector, or
a vector, of the same shape as
x0that applies elementwise to the state.
-
-
class
bdsim.blocks.discrete.DPoseIntegrator(*args, bd=None, **kwargs)[source]¶ Bases:
bdsim.components.ClockedBlockDPOSEINTEGRATOR
inputs
outputs
states
1
1
N
A(6,)
SE3
-
__init__(clock, x0=None, **blockargs)[source]¶ Discrete-time spatial velocity integrator.
- Parameters
clock (Clock) – clock source
x0 (SE3, optional) – Initial pose, defaults to null
blockargs (dict) – common Block options
- Returns
an DPOSEINTEGRATOR block
- Return type
Integrator instance
This block integrates spatial velocity over time. The block input is a spatial velocity as a 6-vector \((v_x, v_y, v_z, \omega_x, \omega_y, \omega_z)\) and the output is pose as an
SE3instance.Note
State is a velocity twist.
-
-
class
bdsim.blocks.discrete.ZOH(*args, bd=None, **kwargs)[source]¶ Bases:
bdsim.components.ClockedBlockZOH
inputs
outputs
states
1
1
N
float, A(N,)
float, A(N,)
-
__init__(clock, x0=0, **blockargs)[source]¶ Zero-order hold.
- Parameters
clock (Clock) – clock source
x0 (array_like, optional) – Initial value of the hold, defaults to 0
blockargs (dict) – common Block options
- Returns
a ZOH block
- Return type
Integrator instance
Output is the input at the previous clock time. The state can be a scalar or a vector, this is given by the type of
x0.Note
If input is not a scalar,
x0must have the shape of the input signal.
-
Linear algebra blocks¶
Linear algebra blocks:
have inputs and outputs
have no state variables
are a subclass of
FunctionBlock→Block
-
class
bdsim.blocks.linalg.Cond(*args, bd=None, **kwargs)[source]¶ Bases:
bdsim.components.FunctionBlockCOND
inputs
outputs
states
1
1
0
A(N,M)
float
-
__init__(**blockargs)[source]¶ Compute the matrix condition number.
- Parameters
blockargs (dict) – common Block options
- Returns
A COND block
- Return type
Cond instance
- Seealso
numpy.linalg.cond()
-
-
class
bdsim.blocks.linalg.Det(*args, bd=None, **kwargs)[source]¶ Bases:
bdsim.components.FunctionBlockDET
inputs
outputs
states
1
1
0
A(N,N)
float
-
__init__(**blockargs)[source]¶ Matrix determinant
- Parameters
blockargs (dict) – common Block options
- Returns
A DET block
- Return type
Det instance
Compute the matrix determinant.
- Seealso
numpy.linalg.inv()
-
-
class
bdsim.blocks.linalg.Flatten(*args, bd=None, **kwargs)[source]¶ Bases:
bdsim.components.FunctionBlockFLATTEN
inputs
outputs
states
1
1
0
A(N,M )
A(NM,)
-
__init__(order='C', **blockargs)[source]¶ Flatten a multi-dimensional array.
- Parameters
order (str) – flattening order, either “C” or “F”, defaults to “C”
blockargs (dict) – common Block options
- Returns
A FLATTEN block
- Return type
Flatten instance
Flattens the incoming array in either row major (‘C’) or column major (‘F’) order.
- Seealso
numpy.flatten()
-
-
class
bdsim.blocks.linalg.Inverse(*args, bd=None, **kwargs)[source]¶ Bases:
bdsim.components.FunctionBlockINVERSE
inputs
outputs
states
1
2
0
A(M,N)
A(N,M) float
-
__init__(pinv=False, **blockargs)[source]¶ Matrix inverse.
- Parameters
pinv (bool, optional) – force pseudo inverse, defaults to False
blockargs (dict) – common Block options
- Returns
An INVERSE block
- Return type
Inverse instance
Compute inverse of the 2D-array input signal. If the matrix is square the inverse is computed unless the
pinvflag is True. For a non-square matrix the pseudo-inverse is used. The condition number is output on the second port.- Seealso
numpy.linalg.inv()numpy.linalg.pinv()numpy.linalg.cond()
-
onames= ('inv', 'cond')¶
-
-
class
bdsim.blocks.linalg.Norm(*args, bd=None, **kwargs)[source]¶ Bases:
bdsim.components.FunctionBlockNORM
inputs
outputs
states
1
1
0
A(N,) A(N,M)
float
-
__init__(ord=None, axis=None, **blockargs)[source]¶ Array norm.
- Parameters
axis (int, optional) – specifies the axis along which to compute the vector norms, defaults to None.
ord (int or str) – Order of the norm, default to None.
blockargs (dict) – common Block options
- Returns
A NORM block
- Return type
Norm instance
Computes the specified norm for a 1D- or 2D-array.
- Seealso
numpy.linalg.norm()
-
-
class
bdsim.blocks.linalg.Slice1(*args, bd=None, **kwargs)[source]¶ Bases:
bdsim.components.FunctionBlockSLICE1
inputs
outputs
states
1
1
0
A(N)
A(M)
-
__init__(index, **blockargs)[source]¶ Slice out subarray of 1D-array.
- Parameters
index (tuple(3)) – slice, defaults to None
blockargs (dict) – common Block options
- Returns
A SLICE1 block
- Return type
Slice1 instance
Compute a 1D slice of input 1D array.
If
indexisNoneit means all elements.If
indexis a list, perform NumPy fancy indexing, returning the specified elementsExample:
SLICE1(index=[2,3]) # return elements 2 and 3 as a 1D array SLICE1(index=[2]) # return element 2 as a 1D array SLICE1(index=2) # return element 2 as a NumPy scalar
If
indexis a tuple, it must have three elements. It describes a Python slice(start, stop, step)where any element can beNonestart=Nonemeans start at first elementstop=Nonemeans finish at last elementstep=Nonemeans step by one
rows=Noneis equivalent torows=(None, None, None).Example:
SLICE1(index=(None,None,2)) # return every second element SLICE1(index=(None,None,-1)) # reverse the elements
- Seealso
-
-
class
bdsim.blocks.linalg.Slice2(*args, bd=None, **kwargs)[source]¶ Bases:
bdsim.components.FunctionBlockSLICE2
inputs
outputs
states
1
1
0
A(N,M)
A(K,L)
-
__init__(rows=None, cols=None, **blockargs)[source]¶ Slice out subarray of 2D-array.
- Parameters
rows (tuple(3) or list) – row selection, defaults to None
cols (tuple(3) or list) – column selection, defaults to None
blockargs (dict) – common Block options
- Returns
A SLICE2 block
- Return type
Slice2 instance
Compute a 2D slice of input 2D array.
If
rowsorcolsisNoneit means all rows or columns respectively.If
rowsorcolsis a list, perform NumPy fancy indexing, returning the specified rows or columnsExample:
SLICE2(rows=[2,3]) # return rows 2 and 3, all columns SLICE2(cols=[4,1]) # return columns 4 and 1, all rows SLICE2(rows=[2,3], cols=[4,1]) # return elements [2,4] and [3,1] as a 1D array
If a single row or column is selected, the result will be a 1D array
If
rowsorcolsis a tuple, it must have three elements. It describes a Python slice(start, stop, step)where any element can beNonestart=Nonemeans start at first elementstop=Nonemeans finish at last elementstep=Nonemeans step by one
rows=Noneis equivalent torows=(None, None, None).Example:
SLICE2(rows=(None,None,2)) # return every second row SLICE2(cols=(None,None,-1)) # reverse the columns
The list and tuple notation can be mixed, for example, one for rows and one for columns.
- Seealso
Slice1Index
-
-
class
bdsim.blocks.linalg.Transpose(*args, bd=None, **kwargs)[source]¶ Bases:
bdsim.components.FunctionBlockTRANSPOSE
inputs
outputs
states
1
1
0
A(M,N)
A(N,M)
-
__init__(**blockargs)[source]¶ Matrix transpose.
- Parameters
blockargs (dict) – common Block options
- Returns
A TRANSPOSE block
- Return type
Transpose instance
Compute transpose of the 2D-array input signal.
Note
An input 1D-array of shape (N,) is turned into a 2D-array column vector with shape (N,1).
An input 2D-array column vector of shape (N,1) becomes a 2D-array
row vector with shape (1,N).
- Seealso
numpy.transpose()
-
Connection blocks¶
Connection blocks are in two categories:
- Signal manipulation:
have inputs and outputs
have no state variables
are a subclass of
FunctionBlock→Block
- Subsystem support
have inputs or outputs
have no state variables
are a subclass of
SubsysytemBlock→Block
-
class
bdsim.blocks.connections.DeMux(*args, bd=None, **kwargs)[source]¶ Bases:
bdsim.components.FunctionBlockDEMUX
inputs
outputs
states
1
nout
0
float, A(nout,)
float
-
__init__(nout=1, **kwargs)[source]¶ Demultiplex signals.
- Parameters
nout (int, optional) – number of outputs, defaults to 1
kwargs (dict) – common Block options
- Returns
A DEMUX block
- Return type
DeMux instance
This block has a single input port and
noutoutput ports. A 1D-array input signal (withnoutelements) is routed element-wise to individual scalar output ports.
-
-
class
bdsim.blocks.connections.Dict(*args, bd=None, **kwargs)[source]¶ Bases:
bdsim.components.FunctionBlockDICT
inputs
outputs
states
N
1
0
any
dict
-
__init__(item, **kwargs)[source]¶ Create a dictionary signal.
- Parameters
keys (list) – list of dictionary keys
kwargs (dict) – common Block options
- Returns
A DICT block
- Return type
Dict instance
Inputs are assigned to a dictionary signal, using the corresponding names from
keys. For example:DICT(['x', 'xd', 'xdd'])
expects three inputs and assigns them to dictionary items
x,xd,xddof the output dictionary respectively.A dictionary signal can serve a similar purpose to a “bus” in Simulink(R).
This is somewhat like a multiplexer
Muxbut allows for named heterogeneous data.
-
-
class
bdsim.blocks.connections.InPort(*args, bd=None, **kwargs)[source]¶ Bases:
bdsim.components.SubsystemBlockINPORT
inputs
outputs
states
0
nout
0
any
-
__init__(nout=1, **kwargs)[source]¶ Input ports for a subsystem.
- Parameters
nout (int, optional) – Number of output ports, defaults to 1
kwargs (dict) – common Block options
- Returns
An INPORT block
- Return type
InPort instance
This block connects a subsystem to a parent block diagram. Inputs to the parent-level
SubSystemblock appear as the outputs of this block.Note
Only one
INPORTblock can appear in a block diagram but it can have multiple ports. This is different to Simulink(R) which would require multiple single-port input blocks.
-
-
class
bdsim.blocks.connections.Index(*args, bd=None, **kwargs)[source]¶ Bases:
bdsim.components.FunctionBlockINDEX
inputs
outputs
states
1
1
0
ndarray
ndarray
-
__init__(index=[], **kwargs)[source]¶ Index an iterable signal.
- Parameters
index (list, slice or str, optional) – elements of input array, defaults to []
kwargs (dict) – common Block options
- Returns
An INDEX block
- Return type
Index instance
The specified element(s) of the input iterable (list, string, etc.) are output. The index can be an integer, sequence of integers, a Python slice object, or a string with Python slice notation, eg.
"::-1".- Seealso
Slice1Slice2
-
-
class
bdsim.blocks.connections.Item(*args, bd=None, **kwargs)[source]¶ Bases:
bdsim.components.FunctionBlockITEM
inputs
outputs
states
1
1
0
dict
any
-
__init__(item, **kwargs)[source]¶ Selector item from a dictionary signal.
- Parameters
item (str) – name of dictionary item
kwargs (dict) – common Block options
- Returns
An ITEM block
- Return type
Item instance
For a dictionary type input signal, select one item as the output signal. For example:
ITEM('xd')
selects the
xditem from the dictionary signal input to the block.A dictionary signal can serve a similar purpose to a “bus” in Simulink(R).
This is somewhat like a demultiplexer
DeMuxbut allows for named heterogeneous data.- Seealso
-
-
class
bdsim.blocks.connections.Mux(*args, bd=None, **kwargs)[source]¶ Bases:
bdsim.components.FunctionBlockMUX
inputs
outputs
states
nin
1
0
float, A(N,)
A(M,) A(M,)
-
__init__(nin=1, **kwargs)[source]¶ Multiplex signals.
- Parameters
nin (int, optional) – Number of input ports, defaults to 1
kwargs (dict) – common Block options
- Returns
A MUX block
- Return type
Mux instance
This block takes a number of scalar or 1D-array signals and concatenates them into a single 1-D array signal. For example:
MUX(2, inputs=(func1[2], sum3))
multiplexes the outputs of blocks
func1(port 2) andsum3into a single output vector as a 1D-array.- Seealso
-
-
class
bdsim.blocks.connections.OutPort(*args, bd=None, **kwargs)[source]¶ Bases:
bdsim.components.SubsystemBlockOUTPORT
inputs
outputs
states
nin
0
0
any
-
__init__(nin=1, **kwargs)[source]¶ Output ports for a subsystem.
- Parameters
nin (int, optional) – Number of input ports, defaults to 1
kwargs (dict) – common Block options
- Returns
A OUTPORT block
- Return type
OutPort instance
This block connects a subsystem to a parent block diagram. The the inputs of this block become the outputs of the parent-level
SubSystemblock.Note
Only one
OUTPORTblock can appear in a block diagram but it can have multiple ports. This is different to Simulink(R) which would require multiple single-port output blocks.
-
-
class
bdsim.blocks.connections.SubSystem(*args, bd=None, **kwargs)[source]¶ Bases:
bdsim.components.SubsystemBlockSUBSYSTEM
inputs
outputs
states
ss.in.nout
ss.out.nin
0
any
any
-
__init__(subsys, nin=1, nout=1, **kwargs)[source]¶ Instantiate a subsystem.
- Parameters
subsys (str or BlockDiagram) – Subsystem as either a filename or a
BlockDiagraminstancenin (int, optional) – Number of input ports, defaults to 1
nout (int, optional) – Number of output ports, defaults to 1
kwargs (dict) – common Block options
- Raises
ImportError – DESCRIPTION
ValueError – DESCRIPTION
- Returns
A SUBSYSTEM block
- Return type
SubSystem instance
This block represents a subsystem in a block diagram. The definition of the subsystem can be:
the name of a module which is imported and must contain only only
BlockDiagraminstance, ora
BlockDiagraminstance
The referenced block diagram must contain one or both of:
one
InPortblock, which has outputs but no inputs. These outputs are connected to the inputs to the enclosingSubSystemblock.one
OutPortblock, which has inputs but no outputs. These inputs are connected to the outputs to the enclosingSubSystemblock.
The referenced block diagram is treated like a macro and copied into the parent block diagram at compile time. The
SubSystem,InPortandOutPortblocks are eliminated, that is, all hierarchical structure is lost.- The same subsystem can be used multiple times, its blocks and wires
will be cloned. Subsystems can also include subsystems.
The number of input and output ports is not specified, they are computed from the number of ports on the
InPortandOutPortblocks within the subsystem.
-
External Toolbox blocksets¶
These blocks are defined within external Toolboxes or packages.
Robot blocks¶
These blocks are defined within the Robotics Toolbox for Python.
Arm robots¶
-
class
roboticstoolbox.blocks.arm.ArmPlot(*args, bd=None, **kwargs)[source]¶ Bases:
bdsim.graphics.GraphicsBlockARMPLOT
inputs
outputs
states
1
0
0
ndarray
-
__init__(robot=None, *inputs, q0=None, backend=None, **blockargs)[source]¶ - Parameters
robot (Robot subclass) – Robot model
backend (str, optional) – RTB backend name, defaults to ‘pyplot’
blockargs (dict) – common Block options
- Returns
An ARMPLOT block
- Return type
ArmPlot instance
Create a robot animation.
Notes:
Uses RTB
plotmethod
Example of vehicle display (animated). The label at the top is the block name.
-
-
class
roboticstoolbox.blocks.arm.CTraj(*args, bd=None, **kwargs)[source]¶ Bases:
bdsim.components.SourceBlockCTRAJ
inputs
outputs
states
0
1
0
float
-
__init__(T1, T2, T, lspb=True, **blockargs)[source]¶ [summary]
- Parameters
T1 (SE3) – initial pose
T2 (SE3) – final pose
T (float) – motion time
lspb (bool) – Use LSPB motion profile along the path
blockargs (dict) – common Block options
- Returns
CTRAJ block
- Return type
CTraj instance
Create a Cartesian motion block.
The block outputs a pose that varies smoothly from
T1toT2over the course ofTseconds.If
Tis not given it defaults to the simulation time.If
lspbis True then an LSPB motion profile is used along the path to provide initial acceleration and final deceleration. Otherwise, motion is at constant velocity.- Seealso
-
-
class
roboticstoolbox.blocks.arm.CirclePath(*args, bd=None, **kwargs)[source]¶ Bases:
bdsim.components.SourceBlockCIRCLEPATH
inputs
outputs
states
0 or 1
1
0
float
float
-
__init__(radius=1, centre=0, 0, 0, pose=None, frequency=1, unit='rps', phase=0, **blockargs)[source]¶ - Parameters
radius (float) – radius of circle, defaults to 1
centre (array_like(3)) – center of circle, defaults to [0,0,0]
pose (SE3) – SE3 pose of output, defaults to None
frequency (float) – rotational frequency, defaults to 1
unit (str) – unit for frequency, one of: ‘rps’ [default], ‘rad’
phase (float) – phase
blockargs (dict) – common Block options
- Returns
TRAJ block
- Return type
Traj instance
Create a circular motion block.
The block outputs the coordinates of a point moving in a circle of radius
rcentred atcentreand parallel to the xy-plane.By default the output is a 3-vector \((x, y, z)\) but if
poseis anSE3instance the output is a copy of that pose with its translation set to the coordinate of the moving point. This is the motion of a frame with fixed orientation following a circular path.
-
-
class
roboticstoolbox.blocks.arm.Delta2Tr(*args, bd=None, **kwargs)[source]¶ Bases:
bdsim.components.FunctionBlockDELTA2TR
inputs
outputs
states
1
1
0
ndarray(6)
SE3
-
__init__(**blockargs)[source]¶ - Parameters
blockargs (dict) – common Block options
- Returns
a DELTA2TR block
- Return type
Delta2Tr instance
Delta to SE(3)
The block has one input port:
delta as an ndarray(6,n)
and one output port:
T as an SE3
- Seealso
spatialmath.base.delta2tr()
-
-
class
roboticstoolbox.blocks.arm.FDyn(*args, bd=None, **kwargs)[source]¶ Bases:
bdsim.components.TransferBlockFDYN
inputs
outputs
states
1
3
0
ndarray
ndarray, ndarray, ndarray
-
__init__(robot, q0=None, **blockargs)[source]¶ - Parameters
robot (Robot subclass) – Robot model
q0 (array_like(n)) – Initial joint configuration
blockargs (dict) – common Block options
- Returns
a FORWARD_DYNAMICS block
- Return type
Foward_Dynamics instance
Robot arm forward dynamics model.
The block has one input port:
Joint force/torque as an ndarray.
and three output ports:
joint configuration
joint velocity
joint acceleration
-
-
class
roboticstoolbox.blocks.arm.FDyn_X(*args, bd=None, **kwargs)[source]¶ Bases:
bdsim.components.TransferBlockFDYN_X
inputs
outputs
states
1
3
0
ndarray
ndarray, ndarray, ndarray
-
__init__(robot, q0=None, gravcomp=False, velcomp=False, representation='rpy/xyz', **blockargs)[source]¶ - Parameters
robot (Robot subclass) – Robot model
end (Link or str) – Link to compute pose of, defaults to end-effector
blockargs (dict) – common Block options
- Returns
a FDYN_X block
- Return type
FDyn_X instance
Robot arm forward dynamics model.
The block has one input port:
Applied end-effector wrench as an ndarray.
and three output ports:
task space pose
task space velocity
task space acceleration
-
-
class
roboticstoolbox.blocks.arm.FKine(*args, bd=None, **kwargs)[source]¶ Bases:
bdsim.components.FunctionBlockFKINE
inputs
outputs
states
1
1
0
ndarray
SE3
-
__init__(robot=None, args={}, **blockargs)[source]¶ - Parameters
robot (Robot subclass, optional) – Robot model, defaults to None
args (dict, optional) – Options for fkine, defaults to {}
blockargs (dict) – common Block options
- Returns
a FORWARD_KINEMATICS block
- Return type
Foward_Kinematics instance
Robot arm forward kinematic model.
Block ports
- input q
Joint configuration vector as an ndarray.
- output T
End-effector pose as an SE(3) object
-
-
class
roboticstoolbox.blocks.arm.Gravload(*args, bd=None, **kwargs)[source]¶ Bases:
bdsim.components.FunctionBlockGRAVLOAD
inputs
outputs
states
1
1
0
ndarray
ndarray
-
__init__(robot, gravity=None, **blockargs)[source]¶ - Parameters
robot (Robot subclass) – Robot model
gravity (float) – gravitational acceleration
blockargs (dict) – common Block options
- Returns
a GRAVLOAD block
- Return type
Gravload instance
Robot arm gravity torque.
The block has one input port:
Joint configuration vector as an ndarray.
and one output port:
joint torque/force due to gravity
-
-
class
roboticstoolbox.blocks.arm.Gravload_X(*args, bd=None, **kwargs)[source]¶ Bases:
bdsim.components.FunctionBlockGRAVLOAD_X
inputs
outputs
states
1
1
0
ndarray
ndarray
-
__init__(robot, gravity=None, **blockargs)[source]¶ - Parameters
robot (Robot subclass) – Robot model
gravity (float) – gravitational acceleration
blockargs (dict) – common Block options
- Returns
a GRAVLOAD block
- Return type
Gravload instance
Robot arm gravity torque.
The block has one input port:
Joint configuration vector as an ndarray.
and one output port:
joint torque/force due to gravity
-
-
class
roboticstoolbox.blocks.arm.IDyn(*args, bd=None, **kwargs)[source]¶ Bases:
bdsim.components.FunctionBlockIDYN
inputs
outputs
states
3
1
0
ndarray, ndarray, ndarray
ndarray
-
__init__(robot, gravity=None, **blockargs)[source]¶ - Parameters
robot (Robot subclass) – Robot model
gravity (float) – gravitational acceleration
blockargs (dict) – common Block options
- Returns
an INVERSE_DYNAMICS block
- Return type
Inverse_Dynamics instance
Robot arm forward dynamics model.
The block has three input port:
Joint configuration vector as an ndarray.
Joint velocity vector as an ndarray.
Joint acceleration vector as an ndarray.
and one output port:
joint torque/force
-
-
class
roboticstoolbox.blocks.arm.IKine(*args, bd=None, **kwargs)[source]¶ Bases:
bdsim.components.FunctionBlockIKINE
inputs
outputs
states
1
1
0
SE3
ndarray
-
__init__(robot=None, q0=None, useprevious=True, ik=None, **blockargs)[source]¶ - Parameters
robot (Robot subclass, optional) – Robot model, defaults to None
q0 (array_like(n), optional) – Initial joint angles, defaults to None
useprevious (bool, optional) – Use previous IK solution as q0, defaults to True
ik (callable f(T)) – Specify an IK function, defaults to ‘ikine_LM’
blockargs (dict) – common Block options
- Returns
an INVERSE_KINEMATICS block
- Return type
Inverse_Kinematics instance
Robot arm inverse kinematic model.
The block has one input port:
End-effector pose as an SE(3) object
and one output port:
Joint configuration vector as an ndarray.
-
-
class
roboticstoolbox.blocks.arm.Inertia(*args, bd=None, **kwargs)[source]¶ Bases:
bdsim.components.FunctionBlockINERTIA
inputs
outputs
states
1
1
0
ndarray
ndarray
-
__init__(robot, gravity=None, **blockargs)[source]¶ - Parameters
robot (Robot subclass) – Robot model
blockargs (dict) – common Block options
- Returns
an INERTIA block
- Return type
Inertia instance
Robot arm inertia matrix.
The block has one input port:
Joint configuration vector as an ndarray.
and one output port:
Joint-space inertia matrix \(\mat{M}(q)\)
-
-
class
roboticstoolbox.blocks.arm.Inertia_X(*args, bd=None, **kwargs)[source]¶ Bases:
bdsim.components.FunctionBlockINERTIA_X
inputs
outputs
states
1
1
0
ndarray
ndarray
-
__init__(robot, representation=None, pinv=False, **blockargs)[source]¶ - Parameters
robot (Robot subclass) – Robot model
blockargs (dict) – common Block options
- Returns
an INERTIA_X block
- Return type
Inertia_X instance
Robot arm task-space inertia matrix.
The block has one input port:
Joint configuration vector as an ndarray.
and one output port:
Task-space inertia matrix \(\mat{M}_x(q)\)
-
-
class
roboticstoolbox.blocks.arm.JTraj(*args, bd=None, **kwargs)[source]¶ Bases:
bdsim.components.SourceBlockJTRAJ
inputs
outputs
states
0
3
0
ndarray(n)
-
__init__(q0, qf, qd0=None, qdf=None, T=None, **blockargs)[source]¶ Compute a joint-space trajectory
- Parameters
q0 (array_like(n)) – initial joint coordinate
qf (array_like(n)) – final joint coordinate
T (array_like or int, optional) – time vector or number of steps, defaults to None
qd0 (array_like(n), optional) – initial velocity, defaults to None
qdf (array_like(n), optional) – final velocity, defaults to None
blockargs (dict) – common Block options
- Returns
TRAJ block
- Return type
Traj instance
tg = jtraj(q0, qf, N)is a joint space trajectory where the joint
coordinates vary from
q0(M) toqf(M). A quintic (5th order) polynomial is used with default zero boundary conditions for velocity and acceleration. Time is assumed to vary from 0 to 1 inNsteps.tg = jtraj(q0, qf, t)as above buttis a uniformly-spaced time
vector
The return value is an object that contains position, velocity and acceleration data.
Notes:
The time vector, if given, scales the velocity and acceleration outputs
assuming that the time vector starts at zero and increases linearly.
- Seealso
ctraj(),qplot(),jtraj()
-
-
class
roboticstoolbox.blocks.arm.Jacobian(*args, bd=None, **kwargs)[source]¶ Bases:
bdsim.components.FunctionBlockJACOBIAN
inputs
outputs
states
1
1
0
ndarray
ndarray
-
__init__(robot, frame='0', inverse=False, pinv=False, transpose=False, **blockargs)[source]¶ - Parameters
robot (Robot subclass) – Robot model
frame (str, optional) – Frame to compute Jacobian for, one of: ‘0’ [default], ‘e’
inverse (bool, optional) – output inverse of Jacobian, defaults to False
pinv (bool, optional) – output pseudo-inverse of Jacobian, defaults to False
transpose (bool, optional) – output transpose of Jacobian, defaults to False
blockargs (dict) – common Block options
- Returns
a JACOBIAN block
- Return type
Jacobian instance
Robot arm Jacobian.
The block has one input port:
Joint configuration vector as an ndarray.
and one output port:
Jacobian matrix as an ndarray(6,n)
-
-
class
roboticstoolbox.blocks.arm.LSPB(*args, bd=None, **kwargs)[source]¶ Bases:
bdsim.components.SourceBlockLSPB
inputs
outputs
states
0
3
0
float
-
__init__(q0, qf, V=None, T=None, **blockargs)[source]¶ Compute a joint-space trajectory
- Parameters
q0 (array_like(n)) – initial joint coordinate
qf (array_like(n)) – final joint coordinate
T (array_like or int, optional) – time vector or number of steps, defaults to None
blockargs (dict) – common Block options
- Returns
LSPB block
- Return type
LSPB instance
tg = jtraj(q0, qf, N)is a joint space trajectory where the joint
coordinates vary from
q0(M) toqf(M). A quintic (5th order) polynomial is used with default zero boundary conditions for velocity and acceleration. Time is assumed to vary from 0 to 1 inNsteps.tg = jtraj(q0, qf, t)as above buttis a uniformly-spaced time
vector
The return value is an object that contains position, velocity and acceleration data.
Notes:
The time vector, if given, scales the velocity and acceleration outputs
assuming that the time vector starts at zero and increases linearly.
- Seealso
ctraj(),qplot(),jtraj()
-
-
class
roboticstoolbox.blocks.arm.Point2Tr(*args, bd=None, **kwargs)[source]¶ Bases:
bdsim.components.FunctionBlockPOINT2TR
inputs
outputs
states
1
1
0
ndarray(3)
SE3
-
__init__(T, **blockargs)[source]¶ - Parameters
T (SE3) – the transform
blockargs (dict) – common Block options
- Returns
a POINT2TR block
- Return type
Point2Tr instance
The block has one input port:
a 3D point as an ndarray(3)
and one output port:
T as an SE3 with its position part replaced by the input
- Seealso
spatialmath.base.delta2tr()
-
-
class
roboticstoolbox.blocks.arm.TR2T(*args, bd=None, **kwargs)[source]¶ Bases:
bdsim.components.FunctionBlockTR2T
inputs
outputs
states
1
3
0
SE3
float
-
__init__(**blockargs)[source]¶ - Parameters
T (SE3) – the transform
blockargs (dict) – common Block options
- Returns
a POINT2TR block
- Return type
Point2Tr instance
The block has one input port:
a 3D point as an ndarray(3)
and one output port:
T as an SE3 with its position part replaced by the input
- Seealso
spatialmath.base.delta2tr()
-
-
class
roboticstoolbox.blocks.arm.Tr2Delta(*args, bd=None, **kwargs)[source]¶ Bases:
bdsim.components.FunctionBlockTR2DELTA
inputs
outputs
states
2
1
0
SE3, SE3
ndarray(6)
-
__init__(**blockargs)[source]¶ - Parameters
blockargs (dict) – common Block options
- Returns
a TR2DELTA block
- Return type
Tr2Delta instance
Difference between T1 and T2 as a 6-vector
The block has two input port:
T1 as an SE3.
T2 as an SE3.
and one output port:
delta as an ndarray(6,n)
- Seealso
spatialmath.base.tr2delta()
-
-
class
roboticstoolbox.blocks.arm.Traj(*args, bd=None, **kwargs)[source]¶ Bases:
bdsim.components.FunctionBlockTRAJ
inputs
outputs
states
0 or 1
1
0
float
float
-
__init__(y0=0, yf=1, T=None, time=False, traj='lspb', **blockargs)[source]¶ - Parameters
y0 (array_like(m), optional) – initial value, defaults to 0
yf (array_like(m), optional) – final value, defaults to 1
T (array_like or int, optional) – time vector or number of steps, defaults to None
time (bool, optional) – x is simulation time, defaults to False
traj (str, optional) – trajectory type, one of: ‘lspb’ [default], ‘tpoly’
blockargs (dict) – common Block options
- Returns
TRAJ block
- Return type
Traj instance
Create a trajectory block.
A block that generates a trajectory using a trapezoidal or quintic polynomial profile.
-
Mobile robots¶
-
class
roboticstoolbox.blocks.mobile.Bicycle(*args, bd=None, **kwargs)[source]¶ Bases:
bdsim.components.TransferBlockBICYCLE
inputs
outputs
states
2
1
3
float
ndarray(3)
-
__init__(L=1, speed_max=inf, accel_max=inf, steer_max=1.413716694115407, x0=None, **blockargs)[source]¶ Create a vehicle model with Bicycle kinematics.
- Parameters
L (float, optional) – Wheelbase, defaults to 1
speed_max (float, optional) – Velocity limit, defaults to 1
accel_max (float, optional) – maximum acceleration, defaults to math.inf
steer_max (float, optional) – maximum steering angle, defaults to math.pi*0.45
x0 (array_like, optional) – Inital state, defaults to None
blockargs (dict) – common Block options
- Returns
a BICYCLE block
- Return type
Bicycle instance
Bicycle kinematic model with state \([x, y, \theta]\).
Block ports
- input v
Vehicle speed (metres/sec). The velocity limit
vlimis applied to the magnitude of this input.- input γ
Steering wheel angle (radians). The steering limit
slimis applied to the magnitude of this input.- output q
configuration (x, y, θ)
- Seealso
mobile.BicycleDiffSteer
-
-
class
roboticstoolbox.blocks.mobile.DiffSteer(*args, bd=None, **kwargs)[source]¶ Bases:
bdsim.components.TransferBlockDIFFSTEER
inputs
outputs
states
2
3
3
float
float
-
__init__(w=1, R=1, speed_max=inf, accel_max=inf, steer_max=None, a=0, x0=None, **blockargs)[source]¶ Create a differential steer vehicle model
- Parameters
w (float, optional) – vehicle width, defaults to 1
R (float, optional) – Wheel radius, defaults to 1
speed_max (float, optional) – Velocity limit, defaults to 1
accel_max (float, optional) – maximum acceleration, defaults to math.inf
steer_max (float, optional) – maximum steering rate, defaults to 1
x0 (array_like, optional) – Inital state, defaults to None
blockargs (dict :return: a DIFFSTEER block) – common Block options
- Return type
DifSteer instance
Unicycle kinematic model with state \([x, y, heta]\), with with inputs given as wheel angular velocity.
Block ports
- input ωL
Left-wheel angular velocity (radians/sec).
- input ωR
Right-wheel angular velocity (radians/sec).
- output q
configuration (x, y, θ)
Note
Wheel velocity is defined such that if both are positive the vehicle moves forward.
-
-
class
roboticstoolbox.blocks.mobile.Unicycle(*args, bd=None, **kwargs)[source]¶ Bases:
bdsim.components.TransferBlockUNICYCLE
inputs
outputs
states
2
1
3
float
float
-
__init__(w=1, speed_max=inf, accel_max=inf, steer_max=None, a=0, x0=None, **blockargs)[source]¶ Create a vehicle model with Unicycle kinematics.
- Parameters
w (float, optional) – vehicle width, defaults to 1
speed_max (float, optional) – Velocity limit, defaults to 1
accel_max (float, optional) – maximum acceleration, defaults to math.inf
steer_max (float, optional) – maximum steering rate, defaults to 1
x0 (array_like, optional) – Inital state, defaults to None
blockargs (dict :return: a UNICYCLE block) – common Block options
- Return type
Unicycle instance
Unicycle kinematic model with state \([x, y, \theta]\).
Block ports
- input v
Vehicle speed (metres/sec). The velocity limit
vlimis applied to the magnitude of this input.- input ω
Angular velocity (radians/sec). The steering limit
slimis applied to the magnitude of this input.- output q
configuration (x, y, θ)
-
-
class
roboticstoolbox.blocks.mobile.VehiclePlot(*args, bd=None, **kwargs)[source]¶ Bases:
bdsim.graphics.GraphicsBlockVEHICLEPLOT
inputs
outputs
states
1
0
0
ndarray
-
__init__(animation=None, path=None, labels=['X', 'Y'], square=True, init=None, scale=True, **blockargs)[source]¶ Create a vehicle animation
- Parameters
animation (VehicleAnimation subclass, optional) – Graphical animation of vehicle, defaults to None
path (str or dict, optional) – linestyle to plot path taken by vehicle, defaults to None
labels (array_like(2) or list) – axis labels (xlabel, ylabel), defaults to [“X”,”Y”]
square (bool, optional) – Set aspect ratio to 1, defaults to True
init (callable, optional) – initialize graphics, defaults to None
blockargs (dict :return: A VEHICLEPLOT block) – common Block options
- Return type
VehiclePlot instance
Create a vehicle animation similar to the figure below.
Block ports
- input q
configuration (x, y, θ)
Notes:
The
initfunction is called after the axes are initialized and can be used to draw application specific detail on the plot. In the example below, this is the dot and star.A dynamic trail, showing path to date can be animated if the option
pathis set to a linestyle.
Example of vehicle display (animated). The label at the top is the block name.¶
-
Multi rotor flying robots¶
-
class
roboticstoolbox.blocks.uav.MultiRotor(*args, bd=None, **kwargs)[source]¶ Bases:
bdsim.components.TransferBlockMULTIROTOR
inputs
outputs
states
1
1
16
A(4,)
dict
-
__init__(model, groundcheck=True, speedcheck=True, x0=None, **blockargs)[source]¶ Create a a multi-rotor dynamic model block.
- Parameters
model (dict) – Vehicle geometric and inertial parameters
groundcheck (bool) – Prevent vehicle moving below ground, defaults to True
speedcheck (bool) – Check for zero rotor speed, defaults to True
x0 (float, optional) – Initial state, defaults to None
blockargs (dict) – common Block options
- Returns
a MULTIROTOR block
- Return type
MultiRotor instance
Block ports
- input ω
a vector of input rotor speeds in (radians/sec). These are, looking down, clockwise from the front rotor which lies on the x-axis.
- output x
a dictionary signal with the following items:
xpose in the world frame as \([x, y, z, \theta_Y, \theta_P, \theta_R]\)vbtranslational velocity in the world frame (metres/sec)wangular rates in the world frame as yaw-pitch-roll rates (radians/second)a1slongitudinal flapping angles (radians)b1slateral flapping angles (radians)
Based on MATLAB code developed by Pauline Pounds 2004.
-
-
class
roboticstoolbox.blocks.uav.MultiRotorMixer(*args, bd=None, **kwargs)[source]¶ Bases:
bdsim.components.FunctionBlockMULTIROTORMIXER
inputs
outputs
states
4
1
0
float
-
__init__(maxw=1000, minw=5, **blockargs)[source]¶ Create a block that displays/animates a multi-rotor flying vehicle.
- Parameters
maxw (float) – maximum rotor speed in rad/s, defaults to 1000
minw (float) – minimum rotor speed in rad/s, defaults to 5
blockargs (dict) – common Block options
- Returns
a MULTIROTORMIXER block
- Return type
MultiRotorMixer instance
Block ports
- input 𝛕r
roll torque
- input 𝛕p
pitch torque
- input 𝛕y
yaw torque
- input T
total thrust
- output ω
1D array of rotor speeds
Derived from Simulink model by Pauline Pounds 2004
-
-
class
roboticstoolbox.blocks.uav.MultiRotorPlot(*args, bd=None, **kwargs)[source]¶ Bases:
bdsim.graphics.GraphicsBlockMULTIROTORPLOT
inputs
outputs
states
1
0
0
dict
-
__init__(model, scale=[- 2, 2, - 2, 2, 10], flapscale=1, projection='ortho', **blockargs)[source]¶ Create a block that displays/animates a multi-rotor flying vehicle.
- Parameters
model (dict) – A dictionary of vehicle geometric and inertial properties
scale (array_like, optional) – dimensions of workspace: xmin, xmax, ymin, ymax, zmin, zmax, defaults to [-2,2,-2,2,10]
flapscale (float) – exagerate flapping angle by this factor, defaults to 1
projection (str) – 3D projection, one of: ‘ortho’ [default], ‘perspective’
blockargs (dict) – common Block options
- Returns
a MULTIROTORPLOT block
- Return type
MultiRotorPlot instance
Block ports
- input y
a dictionary signal that includes the item:
xpose in the world frame as \([x, y, z, heta_Y, heta_P, heta_R]\)Xpose in the world frame as \([x, y, z, heta_Y, heta_P, heta_R]\)a1sb1s
Example of quad-rotor display.¶
Written by Pauline Pounds 2004
-
Vision blocks¶
These blocks are defined within the Machine Vision Toolbox for Python.