Skip to content

Blocks, Wires and Plugs

Peter Corke edited this page Aug 20, 2026 · 15 revisions

plugs and wires

ENIAC (1946) being programmed with plugs and wires by Betty Jennings and Frances Bilas. (credit U.S. Army Research Laboratory)

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 ContinuousBlock (a stateful block, in this case describing continuous-time dynamics) which is a subclass of Block. (Older code may reference TransferBlock — that's now a deprecated alias for ContinuousBlock, not a separate class in between.)

This particular block has two input ports and one output port — its output is a single 3-element array (x, y, θ), not three separate ports. Blocks have many attributes but key ones are:

  • blockclass either 'sink', 'source', 'function', 'continuous', 'sampled', 'subsystem' or 'graphics'
  • 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 ContinuousBlock or SampledBlock subclass
  • name the name optionally assigned by the user
  • bd a reference to the Simulation instance in which this block was instantiated

There's no public x/state attribute — a stateful block's state lives in internal, underscore-prefixed attributes (_x0 for the initial state, _x_view for the live value during a run) that aren't meant for direct external access; see Evaluation for how state is actually threaded through during a run.

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 connects two blocks. The wire object has references to a pair of plugs, and they each reference a block and contain the port number.

Clone this wiki locally