Stepdance Software Library
Loading...
Searching...
No Matches
encoders.hpp
1#include <stdint.h>
2/*
3Encoders Module of the StepDance Control System
4
5This module interfaces with encoder inputs
6
7[More Details to be Added]
8
9A part of the Mixing Metaphors Project
10(c) 2025 Ilan Moyer, Jennifer Jacobs, Devon Frost
11
12*/
13#include "core.hpp"
14#include <QuadEncoder.h>
15
16#ifndef encoders_h //prevent importing twice
17#define encoders_h
18
19#define MAX_NUM_ENCODERS 3 //this is the most we can get out of a stepdance board (ENC1, ENC2, and INPUT_A)
20#define ENCODER_1 0
21#define ENCODER_2 1
22#define ENCODER_A 2 //the A stepdance input can double as a third encoder input
27struct encoder_info_struct{
28 uint8_t CHANNEL_A_TEENSY_PIN;
29 uint8_t CHANNEL_B_TEENSY_PIN;
30};
40class Encoder : public Plugin{
41 public:
42 Encoder();
47 void begin(uint8_t encoder_index);
51 void invert();
56 DecimalPosition read(); //returns the last read encoder value, in realworld units. This is a shortcut for output.read(ABSOLUTE).
60 void reset(); //resets the encoder value to zero
65 void set(DecimalPosition value); //resets the encoder value to a provided value, in world units
71 void set_latch(DecimalPosition value_world_units, uint8_t min_or_max);
72 void set_ratio(float output_units, float encoder_units = 1.0);
73
74 // BlockPorts
75 BlockPort output;
76
77 bool min_latch_enabled = false; //enables latching in the negative direction (encoder units)
78 bool max_latch_enabled = false; //enables latching in the positive direction
79 int32_t min_latch_value = 0; //encoder units
80 int32_t max_latch_value = 0;
81
82 void enroll(RPC *rpc, const String& instance_name);
83
84 private:
85 static const struct encoder_info_struct encoder_info[]; //stores configuration for all available encoder ports
86 static QuadEncoder* all_encoders[MAX_NUM_ENCODERS];
87 void QuadEncoder_configure(uint8_t encoder_index); //applies the configuration stored in encoder_info[encoder_index] to the QuadEncoder object.
88 QuadEncoder* quad_encoder; //pointer to the active quad encoder for this instance
89 uint8_t invert_flag = 0;
90 DecimalPosition encoder_value; //stores the encoder position as a DecimalPosition. This gets updated at the beginning of each call to run();
91
92 protected:
93 void run();
94};
95
96
97#endif //encoders_h
BlockPorts provide a unified interface for mapping inputs and outputs of different StepDance componen...
Definition core.hpp:148
void set(DecimalPosition value)
Sets the encoder position to a specified value in world units.
void set_latch(DecimalPosition value_world_units, uint8_t min_or_max)
Sets latching behavior for the encoder at specified world unit values.
void reset()
Resets the encoder position to zero.
void begin(uint8_t encoder_index)
Initializes the Encoder with the specified encoder index.
DecimalPosition read()
Returns the current position of the encoder in world units.
void invert()
Inverts the encoder direction. Useful for changing the direction without rewiring.
RPC class for handling remote procedure calls over serial streams.
Definition rpc.hpp:35