Initial commit: add stepper controller firmware
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
#pragma once
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <AccelStepper.h>
|
||||
#include "config/ConfigManager.h"
|
||||
|
||||
enum class MotorState {
|
||||
Idle,
|
||||
Moving,
|
||||
Continuous,
|
||||
LimitLeft,
|
||||
LimitRight,
|
||||
Error
|
||||
};
|
||||
|
||||
class StepperController {
|
||||
public:
|
||||
StepperController();
|
||||
void begin(const MotorConfig& config);
|
||||
void update();
|
||||
void moveLeftRotations(float rotations);
|
||||
void moveRightRotations(float rotations);
|
||||
void continuousLeft();
|
||||
void continuousRight();
|
||||
void stop();
|
||||
void emergencyStop();
|
||||
void setSpeed(float maxSpeed);
|
||||
void setAcceleration(float acceleration);
|
||||
void setLimits(bool enabled, bool leftTriggered, bool rightTriggered);
|
||||
bool isMoving() const;
|
||||
long position();
|
||||
MotorState state() const;
|
||||
const char* stateName() const;
|
||||
|
||||
private:
|
||||
bool directionAllowed(int direction) const;
|
||||
void applyLimitState();
|
||||
long rotationsToSteps(float rotations) const;
|
||||
|
||||
AccelStepper stepper_;
|
||||
long stepsPerRevolution_ = 4096;
|
||||
float maxSpeed_ = 500.0f;
|
||||
bool reverseDirection_ = false;
|
||||
bool holdPosition_ = false;
|
||||
bool limitsEnabled_ = false;
|
||||
bool leftLimit_ = false;
|
||||
bool rightLimit_ = false;
|
||||
MotorState state_ = MotorState::Idle;
|
||||
};
|
||||
Reference in New Issue
Block a user