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

Used for generating position signals based on a target position and maximum velocity. More...

#include <generators.hpp>

Inheritance diagram for PositionGenerator:

Public Member Functions

 PositionGenerator ()
 Default constructor for PositionGenerator. Does not initialize the Generator. Call begin() to set up the generator.
void begin ()
 Initialize the PositionGenerator. Must be called to set up the generator.
void set_speed (ControlParameter speed)
 Set the speed (maximum velocity) for the PositionGenerator.
void go (float64_t distance_or_position, uint8_t mode)
 Command the PositionGenerator to move to a specified distance or position.
void go (float64_t distance_or_position, uint8_t mode, ControlParameter speed)
 Command the PositionGenerator to move to a specified distance or position with a specified speed.

Public Attributes

volatile ControlParameter speed_units_per_sec = 0
 ControlParameter that determines the speed of the PositionGenerator. Will not be used if speed is provided in the go() command.
BlockPort output
 Output BlockPort for the PositionGenerator. This is what you map from to a downstream component.

Protected Member Functions

void run ()

Detailed Description

Used for generating position signals based on a target position and maximum velocity.

A PositionGenerator maintains an internal position state and incrementally drives an output to reach a specified target position under the constraints of a maximum velocity. It is useful for generating smooth trajectories to an absolute or relative position. Position generators do not require an input signal, as they generate motion based on internal state and commands. Here's an example of how to instantiate and configure a PositionGenerator:

// Will move a channel to a target position at a specified maximum velocity when a button is pressed.
#define module_driver
#include "stepdance.hpp"
Channel channel_a;
OutputPort output_a;
Button start_button;
void setup() {
// Initialize OutputPort A
output_a.begin(OUTPUT_A);
// Enable the output drivers
enable_drivers();
// Map PositionGenerator output to Channel A's target position
pos_gen.output.map(channel_a.input_target_position);
pos_gen.begin();
// Initialize Channel A
channel_a.begin(&output_a, SIGNAL_E); // Connect Channel A to OutputPort A's SIGNAL_E
// Set speed for PositionGenerator
pos_gen.set_speed(50.0); // Set velocity to 50 units per second
start_button.begin(IO_D1); // Initialize button on physical input port IO_D1
start_button.set_callback_on_release(&onButtonRelease); // Set callback function for button press event
dance_start();
}
void onButtonRelease() {
// Command PositionGenerator to move to target position when button is released
pos_gen.go(100.0, ABSOLUTE); // Move to absolute position of 100.0 units
}
void loop(){
dance_loop();
}

Member Function Documentation

◆ go() [1/2]

void PositionGenerator::go ( float64_t distance_or_position,
uint8_t mode )

Command the PositionGenerator to move to a specified distance or position.

Parameters
distance_or_positionThe target distance (incremental) or position (absolute).
modeThe mode of operation: INCREMENTAL or ABSOLUTE.

◆ go() [2/2]

void PositionGenerator::go ( float64_t distance_or_position,
uint8_t mode,
ControlParameter speed )

Command the PositionGenerator to move to a specified distance or position with a specified speed.

Parameters
distance_or_positionThe target distance (incremental) or position (absolute).
modeThe mode of operation: INCREMENTAL, ABSOLUTE, or GLOBAL
speedThe speed in units per second.

◆ set_speed()

void PositionGenerator::set_speed ( ControlParameter speed)

Set the speed (maximum velocity) for the PositionGenerator.

Parameters
speedThe speed in units per second.

Member Data Documentation

◆ output

BlockPort PositionGenerator::output

Output BlockPort for the PositionGenerator. This is what you map from to a downstream component.

position_gen.output.map(channelX.input_target_position); // Map PositionGenerator output to ChannelX target position

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