Stepper Component

API Reference

Stepper

class Stepper

Subclassed by stepper::A4988

Public Functions

void set_target(int32_t steps)
void report_position(int32_t steps)
void set_acceleration(float acceleration)
void set_deceleration(float deceleration)
void set_max_speed(float max_speed)
bool has_reached_target()
template <typename T>
SetTargetAction<T> *make_set_target_action()
template <typename T>
ReportPositionAction<T> *make_report_position_action()

Public Members

int32_t current_position = {0}
int32_t target_position = {0}

Protected Functions

void calculate_speed_(uint32_t now)
int32_t should_step_()

Protected Attributes

float acceleration_ = {1e6f}
float deceleration_ = {1e6f}
float current_speed_ = {0.0f}
float max_speed_ = {1e6f}
uint32_t last_calculation_ = {0}
uint32_t last_step_ = {0}
template <typename T>
class SetTargetAction : public Action<T>

Public Functions

SetTargetAction(Stepper *parent)
void set_target(std::function<int32_t(T)> target)
void set_target(int32_t target)
void play(T x)

Protected Attributes

Stepper *parent_
TemplatableValue<int32_t, T> target_
template <typename T>
class ReportPositionAction : public Action<T>

Public Functions

ReportPositionAction(Stepper *parent)
void set_position(std::function<int32_t(T)> pos)
void set_position(int32_t pos)
void play(T x)

Protected Attributes

Stepper *parent_
TemplatableValue<int32_t, T> pos_

A4988

class A4988 : public stepper::Stepper, public Component

Public Functions

A4988(GPIOPin *step_pin, GPIOPin *dir_pin)
void set_sleep_pin(const GPIOOutputPin &sleep_pin)
void setup()

Where the component’s initialization should happen.

Analogous to Arduino’s setup(). This method is guaranteed to only be called once. Defaults to doing nothing.

void dump_config()
void loop()

This method will be called repeatedly.

Analogous to Arduino’s loop(). setup() is guaranteed to be called before this. Defaults to doing nothing.

float get_setup_priority() const

priority of setup().

higher -> executed earlier

Defaults to 0.

Return
The setup priority of this component

Protected Attributes

GPIOPin *step_pin_
GPIOPin *dir_pin_
GPIOPin *sleep_pin_ = {nullptr}