Skip to content

Blocks, Wires and Plugs

Peter Corke edited this page Jun 8, 2021 · 10 revisions

plugs and wires

Blocks, Wires and Plugs

The key elements in bdsim are blocks, plugs and wires. They are metaphors for physical plug-board wiring as shown below.

plugs and wires

The top wire has a single 'conductor'. The bottom wire is a bundle with two 'conductors', it actually gets turned into two single conductor wires.

Blocks

Blocks are created by factory methods of a BlockDiagram object, for example

bike = bd.BICYCLE(x0=[5, 2, 0])

represents a dynamic model of a vehicle with bicycle kinematics. bike an instance of a Bicycle class which is a subclass of Transfer (transfer function or stateful block) which is a subclass of Block.

This particular block has two input ports and two output ports. Blocks have many attributes but key ones are:

  • blockclass either 'sink', 'source', 'function', 'transfer', or 'subsystem'
  • type the block type, eg. 'bicycle' or 'constant'
  • nin number of input ports, would be 0 for a source
  • nout number of output ports, would be 0 for a sink
  • nstates number of states, 0 for everything except a Transfer subclass block
  • name the name optionally assigned by the user
  • x the state vector, for Transfer subclass only, as a numpy array
  • bd a reference to the Simulation instance in which this block was instantiated

Plugs

bike[1] is an instance of a Plug object which represents a block and a specific port. It is neither an input or output port, that depends on the context and is determined later. The Plug has attributes:

  • block the block it refers to
  • port the port on the block
  • type has the values 'start', 'end' or None (not yet determined),

Wires

A wire connects two plugs, or a wire has a plug on each end. Wires don't directly reference blocks, it is always via a plug. A reference like bike is actually turned into the plug block[0] when it used in a wiring expression, and whether it is a start or end plug depends on the context.

A wire has attributes:

  • start the plug that connects to an output, the start of the wire
  • end the plug that connects to an input, the end of the wire

Data structures

plugs and wires

The top half shows the relevant data structures after a wire is established between two blocks. The wire object has references to a pair of plugs, and they each reference a block and contain the port number.

The bottom half shows the relevant data structures after compilation. Output values are propagated from one block to another following the red reference links, via Wire and Plug objects. inports is a list (of len(nin)) of back references (black dashed line) from the receiving block to the wire that feeds it, and from there back to the source block. outports is a list (of length len(not)) of lists, one per output port, of references to all outgoing wires.