Supporting classes

Inheritance diagram of bdsim.components

BDSim class

This class describes the run-time environment for executing a block diagram.

class bdsim.BDSim(packages=None, **kwargs)[source]

Bases: object

__init__(packages=None, **kwargs)[source]
Parameters
  • sysargs (bool, optional) – process options from sys.argv, defaults to True

  • graphics (bool, optional) – enable graphics, defaults to True

  • animation (bool, optional) – enable animation, defaults to False

  • progress (bool, optional) – enable progress bar, defaults to True

  • debug (str, optional) – debug options, defaults to None

  • backend (str, optional) – matplotlib backend, defaults to ‘Qt5Agg’’

  • tiles (str, optional) – figure tile layout on monitor, defaults to ‘3x4’

Raises

ImportError – syntax error in block

Returns

parent object for blockdiagram simulation

Return type

BDSim

If sysargs is True, process command line arguments and passed options. Command line arguments have precedence.

Command line switch

Argument

Default

Behaviour

++nographics, +g

graphics

True

enable graphical display

++animation, +a

animation

True

update graphics at each time step

–nographics, -g

graphics

True

disable graphical display

–animation, -a

animation

True

don’t update graphics at each time step

–noprogress, -p

progress

True

do not display simulation progress bar

–backend BE

backend

‘Qt5Agg’

matplotlib backend

–tiles RxC, -t RxC

tiles

‘3x4’

arrangement of figure tiles on the display

–shape WxH

shape

None

window size, default matplotlib size

–altscreen

altscreen

True

use secondary monitor if it exists

–verbose, -v

verbose

False

be verbose

–debug F, -d F

debug

‘’

debug flag string

Note

animation and graphics options are coupled. If graphics=False, all graphics is suppressed. If graphics=True then graphics are shown and the behaviour depends on animation. animation=False shows graphs at the end of the simulation, while ``animation=True` will animate the graphs during simulation.

Seealso

set_options()

blockdiagram(name='main')[source]

Instantiate a new block diagram object.

Parameters

name (str, optional) – diagram name, defaults to ‘main’

Returns

parent object for blockdiagram

Return type

BlockDiagram

This object describes the connectivity of a set of blocks and wires.

It is an instantiation of the BlockDiagram class with a factory method for every dynamically loaded block which returns an instance of the block. These factory methods have names which are all upper case, for example, the method .GAIN invokes the constructor for the Gain class.

Seealso

BlockDiagram()

blocks()[source]

List all loaded blocks.

Example:

73  blocks loaded
bdsim.blocks.functions..................: Sum Prod Gain Clip Function Interpolate 
bdsim.blocks.sources....................: Constant Time WaveForm Piecewise Step Ramp 
bdsim.blocks.sinks......................: Print Stop Null Watch 
bdsim.blocks.transfers..................: Integrator PoseIntegrator LTI_SS LTI_SISO 
bdsim.blocks.discrete...................: ZOH DIntegrator DPoseIntegrator 
bdsim.blocks.linalg.....................: Inverse Transpose Norm Flatten Slice2 Slice1 Det Cond 
bdsim.blocks.displays...................: Scope ScopeXY ScopeXY1 
bdsim.blocks.connections................: Item Dict Mux DeMux Index SubSystem InPort OutPort 
roboticstoolbox.blocks.arm..............: FKine IKine Jacobian Tr2Delta Delta2Tr Point2Tr TR2T FDyn IDyn Gravload 
........................................: Inertia Inertia_X FDyn_X ArmPlot Traj JTraj LSPB CTraj CirclePath 
roboticstoolbox.blocks.mobile...........: Bicycle Unicycle DiffSteer VehiclePlot 
roboticstoolbox.blocks.uav..............: MultiRotor MultiRotorMixer MultiRotorPlot 
machinevisiontoolbox.blocks.camera......: Camera Visjac_p EstPose_p ImagePlane 
closefigs()[source]
done(bd, **kwargs)[source]
get_options(sysargs=True, **kwargs)[source]
load_blocks(verbose=True)[source]

Dynamically load all block definitions.

Raises

ImportError – module could not be imported

Returns

dictionary of block metadata

Return type

dict of dict

Reads blocks from .py files found in bdsim/bdsim/blocks, folders given by colon separated list in envariable BDSIMPATH, and the command line option packages.

The result is a dict indexed by the upper-case block name with elements: - path to the folder holding the Python file defining the block - classname - blockname, upper case version of classname - url of online documentation for the block - package containing the block - doc is the docstring from the class constructor

options = None
progress(t=None)[source]

Update progress bar

Parameters

t (float, optional) – current simulation time, defaults to None

Update progress bar as a percentage of the maximum simulation time, given as an argument to run.

Seealso

run() progress_done()

progress_done()[source]

Clean up progress bar

run(bd, T=10.0, dt=0.1, solver='RK45', solver_args={}, debug='', block=False, checkfinite=True, minstepsize=1e-12, watch=[])[source]

Run the block diagram

Parameters
  • T (float, optional) – maximum integration time, defaults to 10.0

  • dt (float, optional) – maximum time step, defaults to 0.1

  • solver (str, optional) – integration method, defaults to RK45

  • block (bool) – matplotlib block at end of run, default False

  • checkfinite (bool) – error if inf or nan on any wire, default True

  • minstepsize (float) – minimum step length, default 1e-6

  • watch (list) – list of input ports to log

  • solver_args (dict) – arguments passed to scipy.integrate

Returns

time history of signals and states

Return type

Sim class

Assumes that the network has been compiled.

Results are returned in a class with attributes:

  • t the time vector: ndarray, shape=(M,)

  • x is the state vector: ndarray, shape=(M,N)

  • xnames is a list of the names of the states corresponding to columns of x, eg. “plant.x0”,

    defined for the block using the snames argument

  • yN for a watched input where N is the index of the port mentioned in the watch argument

  • ynames is a list of the names of the input ports being watched, same order as in watch argument

If there are no dynamic elements in the diagram, ie. no states, then x and xnames are not present.

The watch argument is a list of one or more input ports whose value during simulation will be recorded. The elements of the list can be:

  • a Block reference, which is interpretted as input port 0

  • a Plug reference, ie. a block with an index or attribute

  • a string of the form “block[i]” which is port i of the block named block.

The debug string comprises single letter flags:

  • ‘p’ debug network value propagation

  • ‘s’ debug state vector

  • ‘d’ debug state derivative

Note

Simulation stops if the step time falls below minsteplength which typically indicates that the solver is struggling with a very harsh non-linearity.

run_interval(bd, t0, T, x0, state)[source]

Integrate system over interval

Parameters
  • bd (BlockDiagram) – the system blockdiagram

  • t0 (float) – initial time

  • tf (float) – final time

  • x0 (ndarray(n)) – initial state vector

  • simstate (SimState) – simulation state object

Returns

final state vector xf

Return type

ndarray(n)

The system is integrated from from x0 to xf over the interval t0 to tf.

savefig(block, filename=None, format='pdf', **kwargs)[source]
savefigs(bd, format='pdf', **kwargs)[source]
set_options(**options)[source]

Set simulation options at run time

The options are the same as those for the constructor.

Example:

sim = bdsim.BDsim()
sim.set_options(graphics=False)
Seealso

__init__()

showgraph(bd, **kwargs)[source]
class bdsim.Struct(name='Struct', **kwargs)[source]

Bases: collections.UserDict

A dict like object that allows items to be added by attribute or by key.

For example:

>>> d = Struct('thing')
>>> d.a = 1
>>> d['b'] = 2
>>> d.a
1
>>> d['a']
1
>>> d.b
2
>>> str(d)
"thing {'a': 1, 'b': 2}"
__init__(name='Struct', **kwargs)[source]

Initialize self. See help(type(self)) for accurate signature.

add(name, value)[source]
class bdsim.BDSimState[source]

Bases: object

Variables
  • x (np.ndarray) – state vector

  • T (float) – maximum simulation time (seconds)

  • t (float) – current simulation time (seconds)

  • fignum (int) – number of next matplotlib figure to create

  • stop (Block subclass) – reference to block wanting to stop simulation, else None

  • checkfinite (bool) – halt simulation if any wire has inf or nan

  • graphics (bool) – enable graphics

__init__()[source]

Initialize self. See help(type(self)) for accurate signature.

declare_event(block, t)[source]

BlockDiagram class

This class describes a block diagram, a collection of blocks and wires that can be “executed”.

bdsim.blockdiagram

alias of bdsim.blockdiagram

Components

Wire

class bdsim.Wire(start=None, end=None, name=None)[source]

Bases: object

Create a wire.

Parameters
  • start (Plug, optional) – Plug at the start of a wire, defaults to None

  • end (Plug, optional) – Plug at the end of a wire, defaults to None

  • name (str, optional) – Name of wire, defaults to None

Returns

A wire object

Return type

Wire

A Wire object connects two block ports. A Wire has a reference to the start and end ports.

A wire records all the connections defined by the user. At compile time wires are used to build inter-block references.

Between two blocks, a wire can connect one or more ports, ie. it can connect a set of output ports on one block to a same sized set of input ports on another block.

property fullname

Display wire connection details.

Returns

Wire name

Return type

str

String format:

d2goal[0] --> Kv[0]
property info

Interactive display of wire properties.

Displays all attributes of the wire for debugging purposes.

send(value, sinks=True)[source]

Send a value to the port at end of this wire.

Parameters

value (float, numpy.ndarray, etc.) – A port value

The value is sent to the input port connected to the end of this wire.

Plug

class bdsim.Plug(block, port=0, type=None)[source]

Bases: object

Create a plug.

Parameters
  • block (Block) – The block being plugged into

  • port (int, optional) – The port on the block, defaults to 0

  • type (str, optional) – ‘start’ or ‘end’, defaults to None

Returns

Plug object

Return type

Plug

Plugs are the interface between a wire and block and have information about port number and wire end. Plugs are on the end of each wire, and connect a Wire to a specific port on a Block.

The type argument indicates if the Plug is at:
  • the start of a wire, ie. the port is an output port

  • the end of a wire, ie. the port is an input port

A plug can specify a set of ports on a block.

__add__(other)[source]

Overloaded + operator for implicit block creation.

Parameters
  • self (Plug) – A signal (plug) to be added

  • other (Block or Plug) – A signal (block or plug) to be added

Returns

SUM block

Return type

Block subclass

This method is implicitly invoked by the + operator when the left operand is a Plug and the right operand is a Plug, Block or constant:

result = X[i] + Y
result = X[i] + Y[j]
result = X[i] + C

where X and Y are blocks and C is a Python or NumPy constant.

Create a SUM("++") block named _sum.N whose inputs are the left and right operands. For the third case, a new CONSTANT(C) block named _const.N is also created.

Seealso

Plug.__radd__() Block.__add__()

__init__(block, port=0, type=None)[source]

Initialize self. See help(type(self)) for accurate signature.

__mul__(other)[source]

Overloaded * operator for implicit block creation.

Parameters
  • self (Plug) – A signal (plug) to be multiplied

  • other (Block or Plug) – A signal (block or plug) to be multiplied

Returns

PROD or GAIN block

Return type

Block subclass

This method is implicitly invoked by the * operator when the left operand is a Plug and the right operand is a Plug, Block or constant:

result = X[i] * Y
result = X[i] * Y[j]
result = X[i] * C

where X and Y are blocks and C is a Python or NumPy constant.

Create a PROD("**") block named _prod.N whose inputs are the left and right operands.

For the third case, create a GAIN(C) block named _gain.N.

Note

Signals are assumed to be scalars, but if C is a NumPy array then the option matrix is set to True.

Seealso

Plug.__rmul__() Block.__mul__()

__neg__()[source]

Overloaded unary minus operator for implicit block creation.

Parameters

self (Plug) – A signal (plug) to be negated

Returns

GAIN block

Return type

Block subclass

This method is implicitly invoked by the - operator for unary minus when the operand is a Plug:

result = -X[i]

where X is a block.

Create a GAIN(-1) block named _gain.N whose input is the operand.

Seealso

Block.__neg__()

__radd__(other)[source]

Overloaded + operator for implicit block creation.

Parameters
  • self (Plug) – A signal (plug) to be added

  • other (Block or Plug) – A signal (block or plug) to be added

Returns

SUM block

Return type

Block subclass

This method is implicitly invoked by the + operator when the right operand is a Plug and the left operand is a Plug, Block or constant:

result = X + Y[j]
result = X[i] + Y[j]
result = C + Y[j]

where X and Y are blocks and C is a Python or NumPy constant.

Create a SUM("++") block named ``_sum.N whose inputs are the left and right operands. For the third case, a new CONSTANT(C) block named _const.N is also created.

Note

The inputs to the summing junction are reversed: right then left operand.

Seealso

Plug.__add__() Block.__radd__()

__repr__()[source]

Display plug details.

Returns

Plug description

Return type

str

String format:

bicycle.0[1]
__rmul__(other)[source]

Overloaded * operator for implicit block creation.

Parameters
  • self (Plug) – A signal (plug) to be multiplied

  • other (Block or Plug) – A signal (block or plug) to be multiplied

Returns

PROD or GAIN block

Return type

Block subclass

This method is implicitly invoked by the * operator when the right operand is a Plug and the left operand is a Plug, Block or constant:

result = X * Y[j]
result = X[i] * Y[j]
result = C * Y[j]

where X and Y are blocks and C is a Python or NumPy constant.

For the first two cases, a PROD("**") block named _prod.N whose inputs are the left and right operands.

For the third case, create a GAIN(C) block named _gain.N.

Note

Signals are assumed to be scalars, but if C is a NumPy array then the option matrix is set to True.

Seealso

Plug.__mul__() Block.__rmul__()

__rshift__(right)[source]

Overloaded >> operator for implicit wiring.

Parameters
  • left (Plug) – A plug to be wired from

  • right (Block or Plug) – A block or plug to be wired to

Returns

right

Return type

Block or Plug

Implements implicit wiring, where the left-hand operator is a Plug, for example:

a = bike[2] >> bd.GAIN(3)

will connect port 2 of bike to the input of the GAIN block.

Note that:

a = bike[2] >> func[1]

will connect port 2 of bike to port 1 of func, and port 1 of func will be assigned to a. To specify a different outport port on func we need to use parentheses:

a = (bike[2] >> func[1])[0]

which will connect port 2 of bike to port 1 of func, and port 0 of func will be assigned to a.

Seealso

Block.__mul__

__rsub__(other)[source]

Overloaded - operator for implicit block creation.

Parameters
  • self (Plug) – A signal (plug) to be added (minuend)

  • other (Block or Plug) – A signal (block or plug) to be subtracted (subtrahend)

Returns

SUM block

Return type

Block subclass

This method is implicitly invoked by the - operator when the left operand is a Plug and the right operand is a Plug, Block or constant:

result = X - Y[j]
result = X[i] - Y[j]
result = C - Y[j]

where X and Y are blocks and C is a Python or NumPy constant.

Create a SUM("+-") block named _sum.N whose inputs are the left and right operands. For the third case, a new CONSTANT(C) block named _const.N is also created.

Note

The inputs to the summing junction are reversed: right then left operand.

Seealso

Plug.__sub__() Block.__rsub__()

__rtruediv__(other)[source]

Overloaded / operator for implicit block creation.

Parameters
  • self (Plug) – A signal (plug) to be multiplied (dividend)

  • other (Block or Plug) – A signal (block or plug) to be divided (divisor)

Returns

PROD block

Return type

Block subclass

This method is implicitly invoked by the / operator when the right operand is a Plug and the left operand is a Plug, Block or constant:

result = X / Y[j]
result = X[i] / Y[j]
result = C / Y[j]

where X and Y are blocks and C is a Python or NumPy constant.

For the first two cases, a PROD("*/") block named _prod.N whose inputs are the left and right operands. For the third case, a new CONSTANT block named _const.N is also created.

Note

Signals are assumed to be scalars, but if C is a NumPy array then the option matrix is set to True.

Seealso

Plug.__truediv__() Block.__rtruediv__()

__sub__(other)[source]

Overloaded - operator for implicit block creation.

Parameters
  • self (Plug) – A signal (plug) to be added (minuend)

  • other (Block or Plug) – A signal (block or plug) to be subtracted (subtrahend)

Returns

SUM block

Return type

Block subclass

This method is implicitly invoked by the - operator when the left operand is a Plug and the right operand is a Plug, Block or constant:

result = X[i] - Y
result = X[i] - Y[j]
result = X[i] - C

where X and Y are blocks and C is a Python or NumPy constant.

Create a SUM("+-") block named _sum.N whose inputs are the left and right operands. For the third case, a new CONSTANT(C) block named _const.N is also created.

Seealso

Plug.__rsub__() Block.__sub__()

__truediv__(other)[source]

Overloaded / operator for implicit block creation.

Parameters
  • self (Plug) – A signal (plug) to be multiplied (dividend)

  • other (Block or Plug) – A signal (block or plug) to be divided (divisor)

Returns

PROD or GAIN block

Return type

Block subclass

This method is implicitly invoked by the / operator when the left operand is a Plug and the right operand is a Plug, Block or constant:

result = X[i] / Y
result = X[i] / Y[j]
result = X[i] / C

where X and Y are blocks and C is a Python or NumPy constant.

Create a PROD("**") block named _prod.N whose inputs are the left and right operands.

For the third case, create a GAIN(1/C) block named _gain.N.

Note

Signals are assumed to be scalars, but if C is a NumPy array then the option matrix is set to True.

Seealso

Plug.__rtruediv__() Block.__truediv__()

property isslice

Test if port number is a slice.

Returns

Whether the port is a slice

Return type

bool

Returns True if the port is a slice, eg. [0:3], and False for a simple index, eg. [2].

property portlist

Return port numbers.

Returns

Port numbers

Return type

list of int

If the port is a simple index, eg. [2] returns [2].

If the port is a slice, eg. [0:3], returns [0, 1, 2]. For the case [2:] the upper bound is the maximum number of input or output ports of the block.

property width

Return number of ports connected.

Returns

Number of ports

Return type

int

If the port is a simple index, eg. [2] returns 1.

If the port is a slice, eg. [0:3], returns 3.

Blocks

class bdsim.Block(*args, bd=None, **kwargs)[source]

Bases: object

__add__(other)[source]

Overloaded + operator for implicit block creation.

Parameters
  • self (Block) – A signal (block) to be added

  • other (Block or Plug) – A signal (block or plug) to be added

Returns

SUM block

Return type

Block subclass

This method is implicitly invoked by the + operator when the right operand is a Block and the left operand is a Plug, Block or constant:

result = X + Y
result = X + Y[j]
result = X + C

where X and Y are blocks and C is a Python or NumPy constant.

Creates a SUM("++") block named ``_sum.N whose inputs are the left and right operands. For the third case, a new CONSTANT(C) block named _const.N is also created.

Note

The inputs to the summing junction are reversed: right then left operand.

Seealso

Block.__radd__() Plug.__add__()

__getitem__(port)[source]

Convert a block slice reference to a plug.

Parameters

port (int) – Port number

Returns

A port plug

Return type

Plug

Invoked whenever a block is referenced as a slice, for example:

c = bd.CONSTANT(1)

bd.connect(x, c[0])
bd.connect(c[0], x)

In both cases c[0] is converted to a Plug by this method.

__init__(name=None, nin=None, nout=None, inputs=None, type=None, inames=None, onames=None, snames=None, pos=None, bd=None, blockclass=None, verbose=False, **kwargs)[source]

Construct a new block object.

Parameters
  • name (str, optional) – Name of the block, defaults to None

  • nin (int, optional) – Number of inputs, defaults to None

  • nout (int, optional) – Number of outputs, defaults to None

  • inputs (Block, Plug or list of Block or Plug) – Optional incoming connections

  • inames (list of str, optional) – Names of input ports, defaults to None

  • onames (list of str, optional) – Names of output ports, defaults to None

  • snames (list of str, optional) – Names of states, defaults to None

  • pos (2-element tuple or list, optional) – Position of block on the canvas, defaults to None

  • bd (BlockDiagram, optional) – Parent block diagram, defaults to None

  • verbose (bool, optional) – enable diagnostic prints, defaults to False

  • kwargs (dict) – Unused arguments

Returns

A Block superclass

Return type

Block

A block object is the superclass of all blocks in the simulation environment.

This is the top-level initializer, and handles most options passed to the superclass initializer for each block in the library.

__mul__(other)[source]

Overloaded * operator for implicit block creation.

Parameters
  • self (Block) – A signal (block) to be multiplied

  • other (Block or Plug) – A signal (block or plug) to be multiplied

Returns

PROD or GAIN block

Return type

Block subclass

This method is implicitly invoked by the * operator when the left operand is a Block and the right operand is a Plug, Block or constant:

result = X * Y
result = X * Y[j]
result = X * C

where X and Y are blocks and C is a Python or NumPy constant.

Create a PROD("**") block named _prod.N whose inputs are the left and right operands.

For the third case, create a GAIN(C) block named _gain.N.

Note

Signals are assumed to be scalars, but if C is a NumPy array then the option matrix is set to True.

Seealso

Block.__rmul__() Plug.__mul__()

__neg__()[source]

Overloaded unary minus operator for implicit block creation.

Parameters

self (Block) – A signal (block) to be negated

Returns

GAIN block

Return type

Block subclass

This method is implicitly invoked by the - operator for unary minus when the operand is a Block:

result = -X

where X is a block.

Creates a GAIN(-1) block named _gain.N whose input is the operand.

Seealso

Plug.__neg__()

static __new__(cls, *args, bd=None, **kwargs)[source]

Construct a new Block object.

Parameters
  • cls (class type) – The class to construct

  • *args

    positional args passed to constructor

  • **kwargs

    keyword args passed to constructor

Returns

new Block instance

Return type

Block instance

__radd__(other)[source]

Overloaded + operator for implicit block creation.

Parameters
  • self (Block) – A signal (block) to be added

  • other (Block or Plug) – A signal (block or plug) to be added

Returns

SUM block

Return type

Block subclass

This method is implicitly invoked by the + operator when the right operand is a Block and the left operand is a Plug, Block or constant:

result = X + Y[j]
result = X[i] + Y[j]
result = C + Y[j]

where X and Y are blocks and C is a Python or NumPy constant.

Creates a SUM("++") block named ``_sum.N whose inputs are the left and right operands. For the third case, a new CONSTANT(C) block named _const.N is also created.

Note

The inputs to the summing junction are reversed: right then left operand.

Seealso

Block.__add__() Plug._r_add__()

__repr__()[source]

Return repr(self).

__rmul__(other)[source]

Overloaded * operator for implicit block creation.

Parameters
  • self (Block) – A signal (block) to be multiplied

  • other (Block or Plug) – A signal (block or plug) to be multiplied

Returns

PROD or GAIN block

Return type

Block subclass

This method is implicitly invoked by the * operator when the right operand is a Block and the left operand is a Plug, Block or constant:

result = X * Y
result = X[i] * Y
result = C * Y

where X and Y are blocks and C is a Python or NumPy constant.

For the first two cases, a PROD("**") block named _prod.N whose inputs are the left and right operands.

For the third case, create a GAIN(C) block named _gain.N.

Note

Signals are assumed to be scalars, but if C is a NumPy array then the option matrix is set to True.

Seealso

Block.__mul__() Plug.__rmul__()

__rshift__(right)[source]

Operator for implicit wiring.

Parameters
  • left (Block) – A block to be wired from

  • right (Block or Plug) – A block or plugto be wired to

Returns

right

Return type

Block or Plug

Implements implicit wiring, for example:

a = bd.CONSTANT(1) >> bd.GAIN(2)

will connect the output of the CONSTANT block to the input of the GAIN block. The result will be GAIN block, whose output in this case will be assigned to a.

Note that:

a = bd.CONSTANT(1) >> func[1]

will connect port 0 of CONSTANT to port 1 of func, and port 1 of func will be assigned to a. To specify a different outport port on func we need to use parentheses:

a = (bd.CONSTANT(1) >> func[1])[0]

which will connect port 0 of CONSTANT ` to port 1 of func, and port 0 of func will be assigned to a.

Seealso

Plug.__rshift__

__rsub__(other)[source]

Overloaded - operator for implicit block creation.

Parameters
  • self (Block) – A signal (block) to be added (minuend)

  • other (Block or Plug) – A signal (block or plug) to be subtracted (subtrahend)

Returns

SUM block

Return type

Block subclass

This method is implicitly invoked by the - operator when the left operand is a Block and the right operand is a Plug, Block or constant:

result = X - Y
result = X[i] - Y
result = C - Y

where X and Y are blocks and C is a Python or NumPy constant.

Creates a SUM("+-") block named _sum.N whose inputs are the left and right operands. For the third case, a new CONSTANT(C) block named _const.N is also created.

Note

The inputs to the summing junction are reversed: right then left operand.

Seealso

Block.__sub__() Plug.__rsub__()

__rtruediv__(other)[source]

Overloaded / operator for implicit block creation.

Parameters
  • self (Block) – A signal (block) to be multiplied (dividend)

  • other (Block or Plug) – A signal (block or plug) to be divided (divisor)

Returns

PROD block

Return type

Block subclass

This method is implicitly invoked by the / operator when the right operand is a Block and the left operand is a Plug, Block or constant:

result = X / Y
result = X[i] / Y
result = C / Y

where X and Y are blocks and C is a Python or NumPy constant.

For the first two cases, a PROD("*/") block named _prod.N whose inputs are the left and right operands. For the third case, a new CONSTANT block named _const.N is also created.

Note

Signals are assumed to be scalars, but if C is a NumPy array then the option matrix is set to True.

Seealso

Block.__truediv__() Plug.__rtruediv__()

__setattr__(name, value)[source]

Convert a LHS block name reference to a wire.

Parameters
  • name – Port name

  • value (Block or Plug) – the RHS

Used to create a wired connection by assignment, for example:

c = bd.CONSTANT(1, inames=['u'])

c.u = x

Ths method is invoked to create a wire from x to port ‘u’ of the constant block c.

Notes:

  • this overloaded method handles all instances of setattr and implements normal functionality as well, only creating a wire if name is a known port name.

__setitem__(port, src)[source]

Convert a LHS block slice reference to a wire.

Parameters
  • port (int) – Port number

  • src (Block or Plug) – the RHS

Used to create a wired connection by assignment, for example:

X[0] = Y

where X and Y are blocks. This method is implicitly invoked and creates a wire from Y to input port 0 of X.

Note

The square brackets on the left-hand-side is critical, and X = Y will simply overwrite the reference to X.

__str__()[source]

Return str(self).

__sub__(other)[source]

Overloaded - operator for implicit block creation.

Parameters
  • self (Block) – A signal (block) to be added (minuend)

  • other (Block or Plug) – A signal (block or plug) to be subtracted (subtrahend)

Returns

SUM block

Return type

Block subclass

This method is implicitly invoked by the - operator when the left operand is a Block and the right operand is a Plug, Block or constant:

result = X - Y
result = X - Y[j]
result = X - C

where X and Y are blocks and C is a Python or NumPy constant.

Creates a SUM("+-") block named _sum.N whose inputs are the left and right operands. For the third case, a new CONSTANT(C) block named _const.N is also created.

Seealso

Block.__rsub__() Plug.__sub__()

__truediv__(other)[source]

Overloaded / operator for implicit block creation.

Parameters
  • self (Block) – A signal (block) to be multiplied (dividend)

  • other (Block or Plug) – A signal (block or plug) to be divided (divisor)

Returns

PROD or GAIN block

Return type

Block subclass

This method is implicitly invoked by the / operator when the left operand is a Block and the right operand is a Plug, Block or constant:

result = X / Y
result = X / Y[j]
result = X / C

where X and Y are blocks and C is a Python or NumPy constant.

Create a PROD("**") block named _prod.N whose inputs are the left and right operands.

For the third case, create a GAIN(1/C) block named _gain.N.

Note

Signals are assumed to be scalars, but if C is a NumPy array then the option matrix is set to True.

Seealso

Block.__rtruediv__() Plug.__truediv__()

add_inport(w)[source]
add_outport(w)[source]
add_param(param, handler=None)[source]
check()[source]
done(**kwargs)[source]
property info

Interactive display of block properties.

Displays all attributes of the block for debugging purposes.

inport_names(names)[source]

Set the names of block input ports.

Parameters

names (list of str) – List of port names

Invoked by the inames argument to the Block constructor.

The names can include LaTeX math markup. The LaTeX version is used where appropriate, but the port names are a de-LaTeXd version of the given string with backslash, caret, braces and dollar signs removed.

property isclocked
property isgraphics
outport_names(names)[source]

Set the names of block output ports.

Parameters

names (list of str) – List of port names

Invoked by the onames argument to the Block constructor.

The names can include LaTeX math markup. The LaTeX version is used where appropriate, but the port names are a de-LaTeXd version of the given string with backslash, caret, braces and dollar signs removed.

reset()[source]
savefig(*pos, **kwargs)[source]
set_param(name, newvalue)[source]
setinput(port, value)[source]

Receive input from a wire

Parameters
  • self – Block to be updated

  • port (int) – Input port to be updated

  • value – Input value

setinputs(*pos)[source]
sourcename(port)[source]

Get the name of output port driving this input port.

Parameters

port (int) – Input port

Returns

Port name

Return type

str

Return the name of the output port that drives the specified input port. The name can be:

  • a LaTeX string if provided

  • block name with port number given in square brackets. The block name will the one optionally assigned by the user using the name keyword, otherwise a systematic default name.

Seealso

outport_names

start(**kwargs)[source]
state_names(names)[source]
step(**kwargs)[source]
varinputs = False
varoutputs = False

Source block

class bdsim.SourceBlock(*args, bd=None, **kwargs)[source]

Bases: bdsim.components.Block

A SourceBlock is a subclass of Block that represents a block that has outputs but no inputs. Its output is a function of parameters and time.

__init__(**blockargs)[source]

Create a source block.

Parameters

blockargs (dict) – common Block options

Returns

source block base class

Return type

SourceBlock

This is the parent class of all source blocks.

__module__ = 'bdsim.components'
blockclass = 'source'

Sink block

class bdsim.SinkBlock(*args, bd=None, **kwargs)[source]

Bases: bdsim.components.Block

A SinkBlock is a subclass of Block that represents a block that has inputs but no outputs. Typically used to save data to a variable, file or graphics.

__init__(**blockargs)[source]

Create a sink block.

Parameters

blockargs (dict) – common Block options

Returns

sink block base class

Return type

SinkBlock

This is the parent class of all sink blocks.

__module__ = 'bdsim.components'
blockclass = 'sink'

Function block

class bdsim.FunctionBlock(*args, bd=None, **kwargs)[source]

Bases: bdsim.components.Block

A FunctionBlock is a subclass of Block that represents a block that has inputs and outputs but no state variables. Typically used to describe operations such as gain, summation or various mappings.

__init__(**blockargs)[source]

Create a function block.

Parameters

blockargs (dict) – common Block options

Returns

function block base class

Return type

FunctionBlock

This is the parent class of all function blocks.

__module__ = 'bdsim.components'
blockclass = 'function'

Transfer function block

class bdsim.TransferBlock(*args, bd=None, **kwargs)[source]

Bases: bdsim.components.Block

A TransferBlock is a subclass of Block that represents a block with inputs outputs and states. Typically used to describe a continuous time dynamic system, either linear or nonlinear.

__init__(nstates=1, **blockargs)[source]

Create a transfer function block.

Parameters

blockargs (dict) – common Block options

Returns

transfer function block base class

Return type

TransferBlock

This is the parent class of all transfer function blocks.

__module__ = 'bdsim.components'
blockclass = 'transfer'
check()[source]
getstate0()[source]
reset()[source]
setstate(x)[source]

Subsystem block

class bdsim.SubsystemBlock(*args, bd=None, **kwargs)[source]

Bases: bdsim.components.Block

A SubSystem s a subclass of Block that represents a block that has inputs and outputs but no state variables. Typically used to describe operations such as gain, summation or various mappings.

__init__(**blockargs)[source]

Create a subsystem block.

Parameters

blockargs (dict) – common Block options

Returns

subsystem block base class

Return type

SubsystemBlock

This is the parent class of all subsystem blocks.

__module__ = 'bdsim.components'
blockclass = 'subsystem'

Graphics block

class bdsim.GraphicsBlock(*args, bd=None, **kwargs)[source]

Bases: bdsim.components.SinkBlock

A GraphicsBlock is a subclass of SinkBlock that represents a block that has inputs but no outputs and creates/updates a graphical display.

__init__(movie=None, **blockargs)[source]

Create a graphical display block.

Parameters
  • movie (str, optional) – Save animation in this file in MP4 format, defaults to None

  • blockargs (dict) – common Block options

Returns

transfer function block base class

Return type

TransferBlock

This is the parent class of all graphic display blocks.

__module__ = 'bdsim.graphics'
blockclass = 'graphics'
create_figure(state)[source]
done(state=None, block=False, **kwargs)[source]
savefig(filename=None, format='pdf', **kwargs)[source]

Save the figure as an image file

Parameters
  • fname (str) – Name of file to save graphics to

  • **kwargs – Options passed to savefig

The file format is taken from the file extension and can be jpeg, png or pdf.

start()[source]
step(state=None)[source]

Discrete-time systems

class bdsim.ClockedBlock(*args, bd=None, **kwargs)[source]

Bases: bdsim.components.Block

A ClockedBlock is a subclass of Block that represents a block with inputs outputs and discrete states. Typically used to describe a discrete time dynamic system, either linear or nonlinear.

__init__(clock=None, **blockargs)[source]

Create a clocked block.

Parameters

blockargs (dict) – common Block options

Returns

clocked block base class

Return type

ClockedBlock

This is the parent class of all clocked blocks.

blockclass = 'clocked'
check()[source]
getstate0()[source]
reset()[source]
setstate(x)[source]
class bdsim.Clock(arg, unit='s', offset=0, name=None)[source]

Bases: object

__init__(arg, unit='s', offset=0, name=None)[source]

Initialize self. See help(type(self)) for accurate signature.

add_block(block)[source]
getstate()[source]
getstate0()[source]
next_event(state=None)[source]
savestate(t)[source]
setstate()[source]
start(state=None)[source]
time(i)[source]
class bdsim.PriorityQ[source]

Bases: object

__init__()[source]

Initialize self. See help(type(self)) for accurate signature.

pop(dt=0)[source]
pop_until(t)[source]
push(value)[source]