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

Encoder components read quadrature encoder inputs. More...

#include <encoders.hpp>

Inheritance diagram for Encoder:

Public Member Functions

void begin (uint8_t encoder_index)
 Initializes the Encoder with the specified encoder index.
void invert ()
 Inverts the encoder direction. Useful for changing the direction without rewiring.
DecimalPosition read ()
 Returns the current position of the encoder in world units.
void reset ()
 Resets the encoder position to zero.
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 set_ratio (float output_units, float encoder_units=1.0)
void enroll (RPC *rpc, const String &instance_name)

Public Attributes

BlockPort output
bool min_latch_enabled = false
bool max_latch_enabled = false
int32_t min_latch_value = 0
int32_t max_latch_value = 0

Protected Member Functions

void run ()

Detailed Description

Encoder components read quadrature encoder inputs.

The Encoder class interfaces with quadrature encoders connected to the StepDance controller and allows mapping the encoder signals to Stepdance components. Here's an example of how to instantiate and configure an Encoder:

#define module_driver
#include "stepdance.hpp"
Encoder encoder;
Channel channel_a;
OutputPort output_a;
void setup(){
// Initialize OutputPort and enable drivers
output_a.begin(OUTPUT_A);
enable_drivers();
channel_a.begin(&output_a, SIGNAL_E); // Initialize Channel A on Output A
// Initialize Encoder and map to output
encoder.begin(ENCODER_1);
encoder.set_ratio(24, 2400); // 24mm per revolution, where 1 rev == 2400 encoder pulses
encoder.output.map(output_a.input_position);
dance_start();
}
void loop(){
dance_loop();
}

Member Function Documentation

◆ begin()

void Encoder::begin ( uint8_t encoder_index)

Initializes the Encoder with the specified encoder index.

Parameters
encoder_indexIndex of the encoder to initialize (e.g., ENCODER_1, ENCODER_2, ENCODER_A).

◆ read()

DecimalPosition Encoder::read ( )

Returns the current position of the encoder in world units.

Returns
DecimalPosition Current position in world units.

◆ set()

void Encoder::set ( DecimalPosition value)

Sets the encoder position to a specified value in world units.

Parameters
valuePosition value to set in world units.

◆ set_latch()

void Encoder::set_latch ( DecimalPosition value_world_units,
uint8_t min_or_max )

Sets latching behavior for the encoder at specified world unit values.

Parameters
value_world_unitsThe world unit value at which to set the latch.
min_or_maxSpecify whether this is a minimum (0) or maximum (1) latch.

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