Stepdance Software Library
Loading...
Searching...
No Matches
generators.hpp
1#include <stdint.h>
2#include <sys/types.h>
3#include "arm_math.h"
4/*
5Generators Module of the StepDance Control System
6
7This module contains an assortment of motion stream generators
8
9[More Details to be Added]
10
11A part of the Mixing Metaphors Project
12(c) 2025 Ilan Moyer, Jennifer Jacobs, Devon Frost
13
14*/
15#include "core.hpp"
16
17#ifndef generators_h //prevent importing twice
18#define generators_h
19
20
29class ThresholdGenerator : public Plugin{
30 public:
38 void begin();
42 void debugPrint();
46 void enable();
50 void disable();
55 void setLowerCallback(void (*callback_function)());
60 void setUpperCallback(void (*callback_function)());
66 void setUpperThreshold(float64_t upper_threshold, bool clamp_to_upper = false);
72 void setLowerThreshold(float64_t lower_threshold, bool clamp_to_lower = false);
81
100 void enroll(RPC *rpc, const String& instance_name);
102 private:
103 DecimalPosition input_position;
104 DecimalPosition output_position;
105 volatile ControlParameter _lower_threshold = 0;
106 volatile ControlParameter _upper_threshold = 0;
107 void (*callback_on_lower_threshold)() = nullptr;
108 void (*callback_on_upper_threshold)() = nullptr;
109 bool clamp_lower = false;
110 bool clamp_upper = false;
111 bool upper_set = false;
112 bool lower_set = false;
113
114
115
116 protected:
117 void run();
118
119
120};
121
130class WaveGenerator1D : public Plugin{
131 public:
139 volatile ControlParameter amplitude = 0;
143 volatile ControlParameter phase = 0.0;
147 volatile ControlParameter frequency = 8;
151 void begin();
163 void enable();
167 void disable();
186 void enroll(RPC *rpc, const String& instance_name);
188
189 private:
190
191 private:
192 DecimalPosition input_position;
193 DecimalPosition output_position;
194 bool no_input = false; //if set to true uses the frame value to update the output
195
196
197 protected:
198 volatile float64_t current_angle_rad = 0;
199 volatile float64_t delta = 0;
200
201 void run();
202};
203
204//removing because it's currently not needed with WaveGenerator1D
205/*class WaveGenerator2D : public Plugin{
206 public:
207 WaveGenerator2D();
208 volatile ControlParameter amplitude = 1.0;
209 volatile ControlParameter phase = 0.0;
210 volatile ControlParameter frequency = 6;
211 volatile bool no_input = false; //if set to true uses the frame value to update the output
212
213 void begin();
214 void setNoInput();
215
216 void debugPrint();
217
218 BlockPort input;
219 BlockPort output_x;
220 BlockPort output_y;
221
222 private:
223 DecimalPosition input_position;
224 DecimalPosition output_x_position;
225 DecimalPosition output_y_position;
226
227 protected:
228 volatile float64_t current_angle_rad = 0;
229 volatile float64_t delta = 0;
230
231 void run();
232};*/
233
244class CircleGenerator : public Plugin{
245 public:
246 CircleGenerator();
250 volatile ControlParameter radius = 1.0;
255 volatile ControlParameter rotational_speed_rev_per_sec = 6; //starts off
259 void begin();
272 void enroll(RPC *rpc, const String& instance_name);
295
296 private:
297 DecimalPosition input_position;
298 DecimalPosition output_x_position;
299 DecimalPosition output_y_position;
300 bool no_input = false; //if set to true uses the frame value to update the output
301
302
303 protected:
304 volatile float64_t current_angle_rad = 0;
305 volatile float64_t delta = 0;
306
307 void run();
308};
309
319class VelocityGenerator : public Plugin{
320 public:
321 VelocityGenerator();
326 volatile ControlParameter speed_units_per_sec = 0; // generation velocity
330 void begin();
335 void enroll(RPC *rpc, const String& instance_name);
348 DecimalPosition target_position = 0;
350
351 protected:
352 void run();
353};
354
363class PositionGenerator : public Plugin{
364 // This position generator maintains its own internal state, and will incrementally drive an output transmission to achieve
365 // a particular value of its internal position state under the constraints of a maximum velocity.
366
367 public:
375 void begin();
380 void set_speed(ControlParameter speed);
386 void go(float64_t distance_or_position, uint8_t mode);
393 void go(float64_t distance_or_position, uint8_t mode, ControlParameter speed);
397 volatile ControlParameter speed_units_per_sec = 0; // generation velocity. This will be used if not explicitly provided by the call to go()
398
399 // BlockPorts
411 void enroll(RPC *rpc, const String& instance_name);
413
414 private:
415 DecimalPosition target_position = 0;
416 DecimalPosition current_position = 0;
417
418 protected:
419 void run();
420};
421
432class PathLengthGenerator2D : public Plugin{
433 // Generates an output signal in proportion to the linear distance traversed by two inputs.
434
435 public:
436 PathLengthGenerator2D();
440 void begin();
445 void set_ratio(ControlParameter ratio);
446 inline void set_ratio(ControlParameter output_distance, ControlParameter input_distance){
447 set_ratio(output_distance / input_distance);
448 }
460 void set_ratio_for_circle(ControlParameter circle_radius, ControlParameter output_per_revolution);
465 void enroll(RPC *rpc, const String& instance_name);
470 ControlParameter ratio = 1.0; // output / input
471 // BlockPorts
487
488 DecimalPosition input_1_position;
489 DecimalPosition input_2_position;
490 DecimalPosition output_position;
491
492 private:
493
494
495 protected:
496 void run();
497};
498
508class PathLengthGenerator3D : public Plugin{
509 // Generates an output signal in proportion to the linear distance traversed by three inputs.
510
511 public:
512 PathLengthGenerator3D();
516 void begin();
521 void set_ratio(ControlParameter ratio);
522 inline void set_ratio(ControlParameter output_distance, ControlParameter input_distance){
523 set_ratio(output_distance / input_distance);
524 }
529 void enroll(RPC *rpc, const String& instance_name);
534 ControlParameter ratio = 1.0; // output / input
535 // BlockPorts
552
553 private:
554 DecimalPosition input_1_position;
555 DecimalPosition input_2_position;
556 DecimalPosition input_3_position;
557 DecimalPosition output_position;
558
559 protected:
560 void run();
561};
562
563#endif //generators_h
BlockPorts provide a unified interface for mapping inputs and outputs of different StepDance componen...
Definition core.hpp:148
void debugPrint()
Print debug information about the CircleGenerator to the Serial console.
void setNoInput()
Use internal frame count for phase instead of an input signal. This will allow the circle generator t...
volatile ControlParameter radius
ControlParameter for the circle radius. You can set it directly or map an input to it.
Definition generators.hpp:250
BlockPort output_y
Output BlockPort for Y component of the circular path.
Definition generators.hpp:294
BlockPort input
Optional input BlockPort (phase). If setNoInput() is called, this input is ignored.
Definition generators.hpp:280
void begin()
Initialize the CircleGenerator. Must be called to set up the generator.
volatile ControlParameter rotational_speed_rev_per_sec
ControlParameter for the rotational speed, in revolutions per second. You can set it directly or map ...
Definition generators.hpp:255
BlockPort output_x
Output BlockPort for X component of the circular path.
Definition generators.hpp:287
void set_ratio_for_circle(ControlParameter circle_radius, ControlParameter output_per_revolution)
Configure the generator for circular motion (e.g., from CircleGenerator). Sets the ratio so that the ...
void begin()
Initialize the PathLengthGenerator2D. Must be called to set up the generator.
BlockPort output
Output BlockPort proportional to 2D path length.
Definition generators.hpp:486
ControlParameter ratio
ControlParameter scaling output relative to input path length (output/input).
Definition generators.hpp:470
BlockPort input_2
Second input BlockPort (e.g., Y position).
Definition generators.hpp:479
void set_ratio(ControlParameter ratio)
Set the ratio between output distance and input path length.
BlockPort input_1
First input BlockPort (e.g., X position).
Definition generators.hpp:475
void set_ratio(ControlParameter ratio)
Set the ratio between output distance and input path length.
BlockPort input_2
Second input BlockPort (e.g., Y position).
Definition generators.hpp:543
BlockPort input_1
First input BlockPort (e.g., X position).
Definition generators.hpp:539
ControlParameter ratio
ControlParameter scaling output relative to input path length (output/input).
Definition generators.hpp:534
void begin()
Initialize the PathLengthGenerator3D. Must be called to set up the generator.
BlockPort input_3
Third input BlockPort (e.g., Z position).
Definition generators.hpp:547
BlockPort output
Output BlockPort proportional to 3D path length.
Definition generators.hpp:551
void go(float64_t distance_or_position, uint8_t mode)
Command the PositionGenerator to move to a specified distance or position.
PositionGenerator()
Default constructor for PositionGenerator. Does not initialize the Generator. Call begin() to set up ...
void set_speed(ControlParameter speed)
Set the speed (maximum velocity) for the PositionGenerator.
volatile ControlParameter speed_units_per_sec
ControlParameter that determines the speed of the PositionGenerator. Will not be used if speed is pro...
Definition generators.hpp:397
BlockPort output
Output BlockPort for the PositionGenerator. This is what you map from to a downstream component.
Definition generators.hpp:406
void begin()
Initialize the PositionGenerator. Must be called to set up the generator.
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.
RPC class for handling remote procedure calls over serial streams.
Definition rpc.hpp:35
void setUpperThreshold(float64_t upper_threshold, bool clamp_to_upper=false)
Set the upper threshold value and optionally enable clamping to the upper threshold....
void begin()
Initialize the ThresholdGenerator.
void setUpperCallback(void(*callback_function)())
Set the callback function to be called when the input crosses 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....
void clearLowerThreshold()
Clear the lower threshold, disabling its effect.
void clearUpperThreshold()
Clear the upper threshold, disabling its effect.
void enable()
Enable the ThresholdGenerator.
BlockPort output
Output BlockPort for the ThresholdGenerator. This is what you map from to a downstream component....
Definition generators.hpp:95
void setLowerCallback(void(*callback_function)())
Set the callback function to be called when the input crosses the lower threshold.
void disable()
Disable the ThresholdGenerator.
void debugPrint()
Print debug information about the ThresholdGenerator to the Serial console.
ThresholdGenerator()
Default constructor for ThresholdGenerator. Does not initialize board hardware. Call begin() to set u...
BlockPort input
Input BlockPort for the ThresholdGenerator. This is what you map to with an upstream component.
Definition generators.hpp:88
void begin()
Initialize the VelocityGenerator. Must be called to set up the generator.
BlockPort output
Output BlockPort for the generated position signal.
Definition generators.hpp:343
volatile ControlParameter speed_units_per_sec
ControlParameter specifying the generation speed in units per second. You can set it directly or map ...
Definition generators.hpp:326
BlockPort input
Input BlockPort for the WaveGenerator1D. This is what you map to with an upstream component....
Definition generators.hpp:174
void enable()
Enable the WaveGenerator1D.
volatile ControlParameter frequency
ControlParameter for the frequency of the waveform in revolutions per second (e.g....
Definition generators.hpp:147
volatile ControlParameter phase
ControlParameter for the phase of the waveform in radians. Phase is the offset of the waveform from i...
Definition generators.hpp:143
void debugPrint()
Print debug information about the WaveGenerator1D to the Serial console.
volatile ControlParameter amplitude
ControlParameter for the amplitude of the waveform- the distance from the center line of the wave for...
Definition generators.hpp:139
WaveGenerator1D()
Default constructor for WaveGenerator1D. Does not initialize board hardware. Call begin() to set up t...
void setNoInput()
Set the generator to use internal frame count for waveform generation instead of an input signal....
void begin()
Initialize the WaveGenerator1D. Must be called to set up the generator.
BlockPort output
Output BlockPort for the WaveGenerator1D. This is what you map from to a downstream component.
Definition generators.hpp:181
void disable()
Disable the WaveGenerator1D.