Stepdance Software Library
Loading...
Searching...
No Matches
BlockPort Class Reference

BlockPorts provide a unified interface for mapping inputs and outputs of different StepDance components (E.g. Channels, Kinematics, Generators, etc) More...

#include <core.hpp>

Public Member Functions

 BlockPort ()
 Default constructor for BlockPort. Initializes a BlockPort instance. You do not need to call this directly; BlockPorts are typically members of other components and are automatically initialized when the component is initialized.
void set_ratio (float world_units, float block_units=1.0)
 Sets the ratio between world units and block units for this BlockPort for automatic conversion. Default is 1:1. For example if ou want the BlockPort to transmit data in millimeters corresponding to a single step, you would set the ratio to 0.01 world units to 1 block_units (i.e. 1 step = 0.01mm).
void map (BlockPort *map_target, uint8_t mode)
 Maps this BlockPort to a target BlockPort with a specified mode (INCREMENTAL or ABSOLUTE).
void map (BlockPort *map_target)
float64_t read (uint8_t mode)
 Returns the position value of the BlockPort in world units. Reading in INCREMENTAL mode returns the change to the position since the last read or update; reading in ABSOLUTE mode returns the absolute position value.
float64_t read_absolute ()
 Returns the absolute position value of the BlockPort in world units.

Detailed Description

BlockPorts provide a unified interface for mapping inputs and outputs of different StepDance components (E.g. Channels, Kinematics, Generators, etc)

BlockPorts manage push and pull of data between components automatically through the map() method, which when called assigns a target to the BlockPort. Each BlockPort has an internal position value. On each interrupt frame a component reads its input BlockPorts' position, performs internal calculations specific to the component, and then stores the result in its output BlockPorts' position. The component then calls BlockPort.push() for each output BlockPort which transmits the position value to the mapped target BlockPort. However BlockPorts can only have one target of their map function. To get around this you can also have BlockPort Inputs pull from multiple other BlockPorts by mapping an input BlockPort to either an input or an output. The Component will first call BlockPort.pull() on its input BlockPorts to retrieve the latest values from all mapped BlockPorts, then perform its internal calculations, and finally call BlockPort.push() on its output BlockPorts to transmit the results.

Typical mapping patterns of BlockPorts. Components (A-E) each have one BlockPort Input and one BlockPort Output. Multiple BlockPort Outputs can map to a single Input (e.g. A.output and C.output are both mapped to B.input). Inputs can map to multiple inputs or outputs (e.g. D.input is mapped to C.output)

You will never instantiate a BlockPort directly; instead, you can access the BlockPorts that are members of different components. The example below shows how to access and map an InputPort's BlockPort to a Channel's input target position BlockPort.

#define module_driver
#include "stepdance.hpp"
InputPort inputA;
Channel channelX;
OutputPort outputA;
void setup() {
// -- Configure and start the output port --
outputA.begin(OUTPUT_A); // Initialize OutputPort A
// Enable the output drivers
enable_drivers();
// -- Configure and start the channel --
channelX.begin(&outputA, SIGNAL_X); // Connect Channel X to OutputPort A
// -- Configure and start the input port --
inputA.begin(INPUT_A); // Initialize InputPort A
inputA.output_x.map(channelX.input_target_position); // Map SIGNAL_X to Channel X's input target position
}
void loop(){
dance_loop();
}

Member Function Documentation

◆ map()

void BlockPort::map ( BlockPort * map_target,
uint8_t mode )

Maps this BlockPort to a target BlockPort with a specified mode (INCREMENTAL or ABSOLUTE).

Parameters
map_targetPointer to the target BlockPort to map to.
modeMode of operation: INCREMENTAL or ABSOLUTE.

◆ read()

float64_t BlockPort::read ( uint8_t mode)

Returns the position value of the BlockPort in world units. Reading in INCREMENTAL mode returns the change to the position since the last read or update; reading in ABSOLUTE mode returns the absolute position value.

Parameters
modeMode of operation: INCREMENTAL or ABSOLUTE.

◆ set_ratio()

void BlockPort::set_ratio ( float world_units,
float block_units = 1.0 )

Sets the ratio between world units and block units for this BlockPort for automatic conversion. Default is 1:1. For example if ou want the BlockPort to transmit data in millimeters corresponding to a single step, you would set the ratio to 0.01 world units to 1 block_units (i.e. 1 step = 0.01mm).

Parameters
world_unitsNumber of world units.
block_unitsNumber of block units. Default is 1.

The documentation for this class was generated from the following file: