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

Used for generating output signals based on upper and lower thresholds. More...

#include <generators.hpp>

Inheritance diagram for ThresholdGenerator:

Public Member Functions

 ThresholdGenerator ()
 Default constructor for ThresholdGenerator. Does not initialize board hardware. Call begin() to set up the generator.
void begin ()
 Initialize the ThresholdGenerator.
void debugPrint ()
 Print debug information about the ThresholdGenerator to the Serial console.
void enable ()
 Enable the ThresholdGenerator.
void disable ()
 Disable the ThresholdGenerator.
void setLowerCallback (void(*callback_function)())
 Set the callback function to be called when the input crosses the lower threshold.
void setUpperCallback (void(*callback_function)())
 Set the callback function to be called when the input crosses the upper threshold.
void setUpperThreshold (float64_t upper_threshold, bool clamp_to_upper=false)
 Set the upper threshold value and optionally enable clamping to the upper threshold. This must be called to activate the upper threshold.
void setLowerThreshold (float64_t lower_threshold, bool clamp_to_lower=false)
 Set the lower threshold value and optionally enable clamping to the lower threshold. This must be called to activate the lower threshold.
void clearUpperThreshold ()
 Clear the upper threshold, disabling its effect.
void clearLowerThreshold ()
 Clear the lower threshold, disabling its effect.

Public Attributes

BlockPort input
 Input BlockPort for the ThresholdGenerator. This is what you map to with an upstream component.
BlockPort output
 Output BlockPort for the ThresholdGenerator. This is what you map from to a downstream component. If clamping is enabled, the output will be clamped to the threshold values.

Protected Member Functions

void run ()

Detailed Description

Used for generating output signals based on upper and lower thresholds.

The ThresholdGenerator monitors an input signal and triggers callbacks or clamps output when the input crosses specified upper or lower thresholds. It can be used to restrict a motion signal within defined bounds and/or to trigger events when those bounds are exceeded.
Here's an example of how to instantiate and configure a ThresholdGenerator:

#define module_driver
#include "stepdance.hpp"
ThresholdGenerator threshold_gen;
InputPort input_a;
Channel channel_a;
OutputPort output_a;
void setup() {
// Initialize OutputPort A
output_a.begin(OUTPUT_A);
// Enable the output drivers
enable_drivers();
// Initialize InputPort A
input_a.begin(INPUT_A);
input_a.output_x.map(threshold_gen.input); // Map SIGNAL_X to ThresholdGenerator input
// Configure ThresholdGenerator
threshold_gen.setLowerThreshold(10.0, true); // Set lower threshold at 10.0 with clamping
threshold_gen.setUpperThreshold(90.0, true); // Set upper threshold at 90.0 with clamping
threshold_gen.setLowerCallback(&onLowerThresholdCrossed); // Set callback for lower threshold crossing
threshold_gen.setUpperCallback(&onUpperThresholdCrossed); // Set callback for upper threshold crossing
// Map ThresholdGenerator output to Channel A's target position
threshold_gen.output.map(channel_a.input_target_position);
threshold_gen.begin();
// Initialize Channel A
channel_a.begin(&output_a, SIGNAL_E); // Connect Channel A to OutputPort A's SIGNAL_E
dance_start();
}
void onLowerThresholdCrossed() {
Serial.println("Lower threshold crossed!");
// Additional actions can be added here
}
void onUpperThresholdCrossed() {
Serial.println("Upper threshold crossed!");
// Additional actions can be added here
}
void loop(){
dance_loop();
}

Member Function Documentation

◆ setLowerCallback()

void ThresholdGenerator::setLowerCallback ( void(* callback_function )())

Set the callback function to be called when the input crosses the lower threshold.

Parameters
callback_functionPointer to the callback function.

◆ setLowerThreshold()

void ThresholdGenerator::setLowerThreshold ( float64_t lower_threshold,
bool clamp_to_lower = false )

Set the lower threshold value and optionally enable clamping to the lower threshold. This must be called to activate the lower threshold.

Parameters
lower_thresholdThe lower threshold value.
clamp_to_lowerIf true, output will be clamped to the lower threshold when exceeded.

◆ setUpperCallback()

void ThresholdGenerator::setUpperCallback ( void(* callback_function )())

Set the callback function to be called when the input crosses the upper threshold.

Parameters
callback_functionPointer to the callback function.

◆ setUpperThreshold()

void ThresholdGenerator::setUpperThreshold ( float64_t upper_threshold,
bool clamp_to_upper = false )

Set the upper threshold value and optionally enable clamping to the upper threshold. This must be called to activate the upper threshold.

Parameters
upper_thresholdThe upper threshold value.
clamp_to_upperIf true, output will be clamped to the upper threshold when exceeded.

Member Data Documentation

◆ input

BlockPort ThresholdGenerator::input

Input BlockPort for the ThresholdGenerator. This is what you map to with an upstream component.

input_a.output_x.map(threshold_gen.input); // Map SIGNAL_X to ThresholdGenerator input

◆ output

BlockPort ThresholdGenerator::output

Output BlockPort for the ThresholdGenerator. This is what you map from to a downstream component. If clamping is enabled, the output will be clamped to the threshold values.

threshold_gen.output.map(channelX.input_target_position); // Map ThresholdGenerator output to ChannelX target position

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