Supporting classes¶

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
If
sysargsis 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
animationandgraphicsoptions are coupled. Ifgraphics=False, all graphics is suppressed. Ifgraphics=Truethen graphics are shown and the behaviour depends onanimation.animation=Falseshows graphs at the end of the simulation, while ``animation=True` will animate the graphs during simulation.- Seealso
-
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
BlockDiagramclass 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.GAINinvokes the constructor for theGainclass.- 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
-
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: -
pathto the folder holding the Python file defining the block -classname-blockname, upper case version ofclassname-urlof online documentation for the block -packagecontaining 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(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
RK45block (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:
tthe time vector: ndarray, shape=(M,)xis the state vector: ndarray, shape=(M,N)xnamesis a list of the names of the states corresponding to columns of x, eg. “plant.x0”,defined for the block using the
snamesargument
yNfor a watched input where N is the index of the port mentioned in thewatchargumentynamesis a list of the names of the input ports being watched, same order as inwatchargument
If there are no dynamic elements in the diagram, ie. no states, then
xandxnamesare not present.The
watchargument is a list of one or more input ports whose value during simulation will be recorded. The elements of the list can be:a
Blockreference, which is interpretted as input port 0a
Plugreference, ie. a block with an index or attributea 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
minsteplengthwhich 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
x0toxfover the intervalt0totf.
-
-
class
bdsim.Struct(name='Struct', **kwargs)[source]¶ Bases:
collections.UserDictA 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}"
-
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
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:
objectCreate a wire.
- Parameters
- Returns
A wire object
- Return type
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.
Plug¶
-
class
bdsim.Plug(block, port=0, type=None)[source]¶ Bases:
objectCreate 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
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
typeargument indicates if thePlugis 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
- Returns
SUM block
- Return type
Block subclass
This method is implicitly invoked by the + operator when the left operand is a
Plugand the right operand is aPlug,Blockor constant:result = X[i] + Y result = X[i] + Y[j] result = X[i] + C
where
XandYare blocks andCis a Python or NumPy constant.Create a
SUM("++")block named_sum.Nwhose inputs are the left and right operands. For the third case, a newCONSTANT(C)block named_const.Nis also created.- Seealso
-
__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
- Returns
PROD or GAIN block
- Return type
Block subclass
This method is implicitly invoked by the * operator when the left operand is a
Plugand the right operand is aPlug,Blockor constant:result = X[i] * Y result = X[i] * Y[j] result = X[i] * C
where
XandYare blocks andCis a Python or NumPy constant.Create a
PROD("**")block named_prod.Nwhose 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
Cis a NumPy array then the optionmatrixis set to True.- Seealso
-
__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
Xis a block.Create a
GAIN(-1)block named_gain.Nwhose input is the operand.- Seealso
-
__radd__(other)[source]¶ Overloaded + operator for implicit block creation.
- Parameters
- Returns
SUM block
- Return type
Block subclass
This method is implicitly invoked by the + operator when the right operand is a
Plugand the left operand is aPlug,Blockor constant:result = X + Y[j] result = X[i] + Y[j] result = C + Y[j]
where
XandYare blocks andCis a Python or NumPy constant.Create a
SUM("++") block named ``_sum.Nwhose inputs are the left and right operands. For the third case, a newCONSTANT(C)block named_const.Nis also created.Note
The inputs to the summing junction are reversed: right then left operand.
- Seealso
-
__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
- Returns
PROD or GAIN block
- Return type
Block subclass
This method is implicitly invoked by the * operator when the right operand is a
Plugand the left operand is aPlug,Blockor constant:result = X * Y[j] result = X[i] * Y[j] result = C * Y[j]
where
XandYare blocks andCis a Python or NumPy constant.For the first two cases, a
PROD("**")block named_prod.Nwhose 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
Cis a NumPy array then the optionmatrixis set to True.- Seealso
-
__rshift__(right)[source]¶ Overloaded >> operator for implicit wiring.
- Parameters
- Returns
right- Return type
Implements implicit wiring, where the left-hand operator is a Plug, for example:
a = bike[2] >> bd.GAIN(3)
will connect port 2 of
biketo the input of the GAIN block.Note that:
a = bike[2] >> func[1]
will connect port 2 of
biketo port 1 offunc, and port 1 offuncwill be assigned toa. To specify a different outport port onfuncwe need to use parentheses:a = (bike[2] >> func[1])[0]
which will connect port 2 of
biketo port 1 offunc, and port 0 offuncwill be assigned toa.- Seealso
Block.__mul__
-
__rsub__(other)[source]¶ Overloaded - operator for implicit block creation.
- Parameters
- Returns
SUM block
- Return type
Block subclass
This method is implicitly invoked by the - operator when the left operand is a
Plugand the right operand is aPlug,Blockor constant:result = X - Y[j] result = X[i] - Y[j] result = C - Y[j]
where
XandYare blocks andCis a Python or NumPy constant.Create a
SUM("+-")block named_sum.Nwhose inputs are the left and right operands. For the third case, a newCONSTANT(C)block named_const.Nis also created.Note
The inputs to the summing junction are reversed: right then left operand.
- Seealso
-
__rtruediv__(other)[source]¶ Overloaded / operator for implicit block creation.
- Parameters
- Returns
PROD block
- Return type
Block subclass
This method is implicitly invoked by the / operator when the right operand is a
Plugand the left operand is aPlug,Blockor constant:result = X / Y[j] result = X[i] / Y[j] result = C / Y[j]
where
XandYare blocks andCis a Python or NumPy constant.For the first two cases, a
PROD("*/")block named_prod.Nwhose inputs are the left and right operands. For the third case, a new CONSTANT block named_const.Nis also created.Note
Signals are assumed to be scalars, but if
Cis a NumPy array then the optionmatrixis set to True.
-
__sub__(other)[source]¶ Overloaded - operator for implicit block creation.
- Parameters
- Returns
SUM block
- Return type
Block subclass
This method is implicitly invoked by the - operator when the left operand is a
Plugand the right operand is aPlug,Blockor constant:result = X[i] - Y result = X[i] - Y[j] result = X[i] - C
where
XandYare blocks andCis a Python or NumPy constant.Create a
SUM("+-")block named_sum.Nwhose inputs are the left and right operands. For the third case, a newCONSTANT(C)block named_const.Nis also created.- Seealso
-
__truediv__(other)[source]¶ Overloaded / operator for implicit block creation.
- Parameters
- Returns
PROD or GAIN block
- Return type
Block subclass
This method is implicitly invoked by the / operator when the left operand is a
Plugand the right operand is aPlug,Blockor constant:result = X[i] / Y result = X[i] / Y[j] result = X[i] / C
where
XandYare blocks andCis a Python or NumPy constant.Create a
PROD("**")block named_prod.Nwhose 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
Cis a NumPy array then the optionmatrixis set to True.
-
property
isslice¶ Test if port number is a slice.
- Returns
Whether the port is a slice
- Return type
bool
Returns
Trueif the port is a slice, eg.[0:3], andFalsefor 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
- Returns
SUM block
- Return type
Block subclass
This method is implicitly invoked by the + operator when the right operand is a
Blockand the left operand is aPlug,Blockor constant:result = X + Y result = X + Y[j] result = X + C
where
XandYare blocks andCis a Python or NumPy constant.Creates a
SUM("++") block named ``_sum.Nwhose inputs are the left and right operands. For the third case, a newCONSTANT(C)block named_const.Nis also created.Note
The inputs to the summing junction are reversed: right then left operand.
- Seealso
-
__getitem__(port)[source]¶ Convert a block slice reference to a plug.
- Parameters
port (int) – Port number
- Returns
A port plug
- Return type
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 aPlugby 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
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
- Returns
PROD or GAIN block
- Return type
Block subclass
This method is implicitly invoked by the * operator when the left operand is a
Blockand the right operand is aPlug,Blockor constant:result = X * Y result = X * Y[j] result = X * C
where
XandYare blocks andCis a Python or NumPy constant.Create a
PROD("**")block named_prod.Nwhose 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
Cis a NumPy array then the optionmatrixis set to True.- Seealso
-
__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
Xis a block.Creates a
GAIN(-1)block named_gain.Nwhose input is the operand.- Seealso
-
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
- Returns
SUM block
- Return type
Block subclass
This method is implicitly invoked by the + operator when the right operand is a
Blockand the left operand is aPlug,Blockor constant:result = X + Y[j] result = X[i] + Y[j] result = C + Y[j]
where
XandYare blocks andCis a Python or NumPy constant.Creates a
SUM("++") block named ``_sum.Nwhose inputs are the left and right operands. For the third case, a newCONSTANT(C)block named_const.Nis also created.Note
The inputs to the summing junction are reversed: right then left operand.
- Seealso
Block.__add__()Plug._r_add__()
-
__rmul__(other)[source]¶ Overloaded * operator for implicit block creation.
- Parameters
- Returns
PROD or GAIN block
- Return type
Block subclass
This method is implicitly invoked by the * operator when the right operand is a
Blockand the left operand is aPlug,Blockor constant:result = X * Y result = X[i] * Y result = C * Y
where
XandYare blocks andCis a Python or NumPy constant.For the first two cases, a
PROD("**")block named_prod.Nwhose 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
Cis a NumPy array then the optionmatrixis set to True.- Seealso
-
__rshift__(right)[source]¶ Operator for implicit wiring.
- Parameters
- Returns
right- Return type
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 offuncwill be assigned toa. To specify a different outport port onfuncwe 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 offuncwill be assigned toa.- Seealso
Plug.__rshift__
-
__rsub__(other)[source]¶ Overloaded - operator for implicit block creation.
- Parameters
- Returns
SUM block
- Return type
Block subclass
This method is implicitly invoked by the - operator when the left operand is a
Blockand the right operand is aPlug,Blockor constant:result = X - Y result = X[i] - Y result = C - Y
where
XandYare blocks andCis a Python or NumPy constant.Creates a
SUM("+-")block named_sum.Nwhose inputs are the left and right operands. For the third case, a newCONSTANT(C)block named_const.Nis also created.Note
The inputs to the summing junction are reversed: right then left operand.
- Seealso
-
__rtruediv__(other)[source]¶ Overloaded / operator for implicit block creation.
- Parameters
- Returns
PROD block
- Return type
Block subclass
This method is implicitly invoked by the / operator when the right operand is a
Blockand the left operand is aPlug,Blockor constant:result = X / Y result = X[i] / Y result = C / Y
where
XandYare blocks andCis a Python or NumPy constant.For the first two cases, a
PROD("*/")block named_prod.Nwhose inputs are the left and right operands. For the third case, a new CONSTANT block named_const.Nis also created.Note
Signals are assumed to be scalars, but if
Cis a NumPy array then the optionmatrixis set to True.
-
__setattr__(name, value)[source]¶ Convert a LHS block name reference to a wire.
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
xto port ‘u’ of the constant blockc.Notes:
this overloaded method handles all instances of
setattrand implements normal functionality as well, only creating a wire ifnameis a known port name.
-
__setitem__(port, src)[source]¶ Convert a LHS block slice reference to a wire.
Used to create a wired connection by assignment, for example:
X[0] = Y
where
XandYare blocks. This method is implicitly invoked and creates a wire fromYto input port 0 ofX.Note
The square brackets on the left-hand-side is critical, and
X = Ywill simply overwrite the reference toX.
-
__sub__(other)[source]¶ Overloaded - operator for implicit block creation.
- Parameters
- Returns
SUM block
- Return type
Block subclass
This method is implicitly invoked by the - operator when the left operand is a
Blockand the right operand is aPlug,Blockor constant:result = X - Y result = X - Y[j] result = X - C
where
XandYare blocks andCis a Python or NumPy constant.Creates a
SUM("+-")block named_sum.Nwhose inputs are the left and right operands. For the third case, a newCONSTANT(C)block named_const.Nis also created.- Seealso
-
__truediv__(other)[source]¶ Overloaded / operator for implicit block creation.
- Parameters
- Returns
PROD or GAIN block
- Return type
Block subclass
This method is implicitly invoked by the / operator when the left operand is a
Blockand the right operand is aPlug,Blockor constant:result = X / Y result = X / Y[j] result = X / C
where
XandYare blocks andCis a Python or NumPy constant.Create a
PROD("**")block named_prod.Nwhose 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
Cis a NumPy array then the optionmatrixis set to True.
-
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
inamesargument 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
onamesargument 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.
-
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
-
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
namekeyword, otherwise a systematic default name.
- Seealso
outport_names
-
varinputs= False¶
-
varoutputs= False¶
-
Source block¶
-
class
bdsim.SourceBlock(*args, bd=None, **kwargs)[source]¶ Bases:
bdsim.components.BlockA 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
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.BlockA 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
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.BlockA 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
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.BlockA 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
This is the parent class of all transfer function blocks.
-
__module__= 'bdsim.components'¶
-
blockclass= 'transfer'¶
-
Subsystem block¶
-
class
bdsim.SubsystemBlock(*args, bd=None, **kwargs)[source]¶ Bases:
bdsim.components.BlockA 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
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.SinkBlockA 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
This is the parent class of all graphic display blocks.
-
__module__= 'bdsim.graphics'¶
-
blockclass= 'graphics'¶
-
Discrete-time systems¶
-
class
bdsim.ClockedBlock(*args, bd=None, **kwargs)[source]¶ Bases:
bdsim.components.BlockA 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
This is the parent class of all clocked blocks.
-
blockclass= 'clocked'¶
-