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

Channels are modules that store the machine's positional state. More...

#include <channels.hpp>

Inheritance diagram for Channel:

Public Member Functions

void begin ()
 Initialize the Channel with no output port. Not for normal use.
void begin (OutputPort *target_output_port, uint8_t output_signal)
 Initialize the Channel with a target OutputPort and output signal.
void set_max_pulse_rate (float max_pulses_per_sec)
 Sets the maxium allowable pulse rate for the channel.
void set_ratio (float input_units, float channel_units=1.0)
 Sets the transmission ratio for all target transmissions.
void set_upper_limit (DecimalPosition upper_limit_input_units)
 Sets the upper position limit for the channel. Useful if you want the channel to stop transmitting motion streams at a certain upper threshold.
void set_lower_limit (DecimalPosition lower_limit_input_units)
 Sets the lower position limit for the channel. Useful if you want the channel to stop transmitting motion streams at a certain lower threshold.
void disable_upper_limit ()
 Disables the upper position limit.
void disable_lower_limit ()
 Disables the lower position limit.
void disable_limits ()
 Disables the channel.
void disable ()
 Disables the channel.
void enable ()
 Enables the channel.
void enable_filtering (uint16_t num_samples=20)
 Enables a moving average filter with a specified sample window. The bigger the window, the smoother the output but the less responsive the motion.
void disable_filtering ()
 Disables the moving average filter.
int8_t is_outside_limits ()
 Checks if the current channel position is outside the set limits.
void invert_output ()
 Inverts the channel output direction.
void invert_output (bool invert)
 Inverts the channel output direction. Useful for reversing motor direction without changing wiring.

Public Attributes

DecimalPosition target_position
 Target position of the channel in pulses. Target positon is what the channel is driving toward.
DecimalPosition current_position
 Current position of the channel in pulses. Current position is where the channel is currently at.
DecimalPosition filtered_target_position
 Filtered target position of the channel in pulses. This is used when the enableFiltering() method is used to smooth out motion.
bool filtering_on = false
 Flag indicating whether filtering is enabled for the channel.

Detailed Description

Channels are modules that store the machine's positional state.

A Channel directly interfaces with an OutputPort by mapping to a particular signal flag (e.g. "X").Channels contain a target position variable that can be modified by upstream components such as motion generators. They also contain a variable representing their current position. Each interrupt frame, the channel increments or decrements the current position when needed to drive |target-current| < 0.5, and correspondingly sets step and direction flags on its mapped OutputPort. Any number of channels can be instantiated, often corresponding to axes of the machine machine. Basic Modules may contain multiple channels that map to distinct flags on the same OutputPort. Driver Modules typically have multiple channels that each map to a unique OutputPort, that then generate step/direction signals for a motor drive module. Here's an example of how to instantiate and configure a Channel and map it to an OutputPort:

#define module_driver
#include "stepdance.hpp"
Channel channel_x;
OutputPort output_x;
void setup() {
// -- Configure and start the output port --
output_x.begin(OUTPUT_A); // "OUTPUT_A" specifies the physical port on the PCB for the output.
// -- Configure and start the channels --
channel_x.begin(&output_x, SIGNAL_X); // Connects the channel to the "X" signal on "output_x".
// We choose the "X" signal because it results in a step pulse of 2us,
// which is more than long enough for the driver IC
channel_x.set_ratio(40, 3200); // Sets the input/output transmission ratio for the channel.
}
void loop(){
dance_loop();
}

Member Function Documentation

◆ begin()

void Channel::begin ( OutputPort * target_output_port,
uint8_t output_signal )

Initialize the Channel with a target OutputPort and output signal.

Parameters
target_output_portPointer to the target OutputPort.
output_signalIndex of the output signal (SIGNAL_X, SIGNAL_Y, etc.).

◆ disable_limits()

void Channel::disable_limits ( )
inline

Disables the channel.

Disables all position limits.

◆ enable_filtering()

void Channel::enable_filtering ( uint16_t num_samples = 20)

Enables a moving average filter with a specified sample window. The bigger the window, the smoother the output but the less responsive the motion.

Parameters
num_samplesNumber of samples for filtering. Default is 20.

◆ invert_output() [1/2]

void Channel::invert_output ( )

Inverts the channel output direction.

Inverts the channel output direction. Useful for reversing motor direction without changing wiring.

◆ invert_output() [2/2]

void Channel::invert_output ( bool invert)

Inverts the channel output direction. Useful for reversing motor direction without changing wiring.

Parameters
invertIf true, inverts the output direction; if false, restores the normal direction.

◆ is_outside_limits()

int8_t Channel::is_outside_limits ( )

Checks if the current channel position is outside the set limits.

Returns
int8_t Returns 0 if inside limits, 1 if outside upper limit, or -1 if outside lower limit.

◆ set_lower_limit()

void Channel::set_lower_limit ( DecimalPosition lower_limit_input_units)

Sets the lower position limit for the channel. Useful if you want the channel to stop transmitting motion streams at a certain lower threshold.

Parameters
lower_limit_input_unitsLower limit in input (world) units.

◆ set_max_pulse_rate()

void Channel::set_max_pulse_rate ( float max_pulses_per_sec)

Sets the maxium allowable pulse rate for the channel.

Parameters
max_pulses_per_secMaximum allowable pulse rate in pulses per second.

◆ set_ratio()

void Channel::set_ratio ( float input_units,
float channel_units = 1.0 )

Sets the transmission ratio for all target transmissions.

Parameters
input_unitsNumber of input units corresponding to channel_units.
channel_unitsNumber of channel units corresponding to input_units. Default is 1.0.

◆ set_upper_limit()

void Channel::set_upper_limit ( DecimalPosition upper_limit_input_units)

Sets the upper position limit for the channel. Useful if you want the channel to stop transmitting motion streams at a certain upper threshold.

Parameters
upper_limit_input_unitsUpper limit in input (world) units.

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