Stepdance Software Library
Loading...
Searching...
No Matches
channels.hpp
1#include "arm_math.h"
2#include <sys/_stdint.h>
3#include "output_ports.hpp"
4#include "core.hpp"
5
6/*
7Channels Module of the StepDance Control System
8
9[More Details to be Added]
10
11A part of the Mixing Metaphors Project
12(c) 2025 Ilan Moyer, Jennifer Jacobs, Devon Frost, Emilie Yu
13*/
14
15#ifndef channels_h //prevent importing twice
16#define channels_h
17
18#define MAX_NUM_CHANNELS 10 //just to start with, until we need more.
19
20void run_all_registered_channels(); //drives all registered channels to their target positions
21void activate_channels(); //adds channels to the frame interrupt routine
22
23
33
34class Channel : public Plugin{
35 public:
36 // Public State
40 DecimalPosition target_position; //primary target position, in pulses.
44 DecimalPosition current_position; //tracks the current position, in pulses.
48 DecimalPosition filtered_target_position; // filtered target position
52 bool filtering_on = false;
53
58 DecimalPosition target_position_2; // secondary target position, used for coordinate transforms.
59 float32_t num_averaging_samples = 20; //samples in the averaging window
60 // BlockPorts
61 BlockPort input_target_position;
62 BlockPort input_target_position_2;
63
64 void push_deep();
65
67
68 // Public Methods
69 Channel();
74 void begin(); //channel with no output port
75
81 void begin(OutputPort* target_output_port, uint8_t output_signal);
86 void set_max_pulse_rate(float max_pulses_per_sec);
92 void set_ratio(float input_units, float channel_units = 1.0); //sets the transmission ratio for all target transmissions
97 void set_upper_limit(DecimalPosition upper_limit_input_units); //sets the upper limit, using input (world) units.
102 void set_lower_limit(DecimalPosition lower_limit_input_units); //sets the lower limit, using input (world) units.
117 inline void disable_limits(){
120 }
121
124 void disable();
128 void enable();
133 void enable_filtering(uint16_t num_samples = 20);
154 void invert_output(bool invert);
155
156
161 void enroll(RPC *rpc, const String& instance_name);
162 void run(); //Drives the current position to the target position by one pulse, and generates a signal
164
165
166 private:
167 // Constants
168 const uint32_t ACCUMULATOR_THRESHOLD = 1000000;
169 const uint32_t PULSE_MAX_RATE = 1000000 / CORE_FRAME_PERIOD_US;
170
171 // Configuration
172 int has_output = 0; //1 if channel has an output port, otherwise 0.
173 OutputPort* target_output_port; //stores the target output port
174 uint8_t output_signal = SIGNAL_X; //default to signal X
175 uint8_t output_inverted = 0; //if 1, will invert the output direction of the channel
176
177 // Private State
178 volatile float accumulator;
179 volatile float accumulator_velocity;
180 volatile int last_direction;
181 DecimalPosition upper_limit;
182 DecimalPosition lower_limit;
183 bool upper_limit_enabled = false;
184 bool lower_limit_enabled = false;
185 bool enabled = true;
186
187 // Private Methods
188 void initialize_state(); // initializes all state variables
189 void register_channel(); // registers channel with the signal generator loop
190 void pulse(int8_t direction); // generates a step pulse and releases a signal on the output port
191
192};
193
194#endif
BlockPorts provide a unified interface for mapping inputs and outputs of different StepDance componen...
Definition core.hpp:148
void disable_limits()
Disables the channel.
Definition channels.hpp:117
void disable_lower_limit()
Disables the lower position limit.
bool filtering_on
Flag indicating whether filtering is enabled for the channel.
Definition channels.hpp:52
void begin()
Initialize the Channel with no output port. Not for normal use.
DecimalPosition current_position
Current position of the channel in pulses. Current position is where the channel is currently at.
Definition channels.hpp:44
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,...
void disable()
Disables the channel.
int8_t is_outside_limits()
Checks if the current channel position is outside the set limits.
DecimalPosition target_position
Target position of the channel in pulses. Target positon is what the channel is driving toward.
Definition channels.hpp:40
void disable_upper_limit()
Disables the upper position limit.
void begin(OutputPort *target_output_port, uint8_t output_signal)
Initialize the Channel with a target OutputPort and output signal.
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 mo...
void invert_output(bool invert)
Inverts the channel output direction. Useful for reversing motor direction without changing wiring.
void invert_output()
Inverts the channel output direction.
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_lower_limit(DecimalPosition lower_limit_input_units)
Sets the lower position limit for the channel. Useful if you want the channel to stop transmitting mo...
void disable_filtering()
Disables the moving average filter.
DecimalPosition filtered_target_position
Filtered target position of the channel in pulses. This is used when the enableFiltering() method is ...
Definition channels.hpp:48
OutputPorts are modules that convert internal step commands into a frame of pulse signals on the phys...
Definition output_ports.hpp:108
RPC class for handling remote procedure calls over serial streams.
Definition rpc.hpp:35