2025-12-31 15:44:48 -06:00
|
|
|
#ifndef SERVO_H
|
|
|
|
|
#define SERVO_H
|
|
|
|
|
#include <atomic>
|
|
|
|
|
#include "calibration.hpp"
|
|
|
|
|
#include "encoder.hpp"
|
|
|
|
|
|
|
|
|
|
#define CCW 1
|
|
|
|
|
#define CW 0
|
|
|
|
|
#define server 1
|
|
|
|
|
#define manual 0
|
|
|
|
|
|
2026-01-03 22:59:36 -06:00
|
|
|
// Command structures for servo control
|
|
|
|
|
typedef enum {
|
|
|
|
|
SERVO_CMD_STOP,
|
|
|
|
|
SERVO_CMD_MOVE_CCW,
|
|
|
|
|
SERVO_CMD_MOVE_CW,
|
|
|
|
|
SERVO_CMD_MOVE_TO_POSITION
|
|
|
|
|
} servo_command_t;
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
|
servo_command_t command;
|
|
|
|
|
uint8_t target_position; // For MOVE_TO_POSITION
|
|
|
|
|
bool is_manual; // vs server-initiated
|
|
|
|
|
} servo_cmd_msg_t;
|
|
|
|
|
|
2025-12-31 15:44:48 -06:00
|
|
|
extern std::atomic<bool> calibListen;
|
|
|
|
|
extern std::atomic<bool> clearCalibFlag;
|
|
|
|
|
extern std::atomic<bool> savePosFlag;
|
|
|
|
|
|
2025-12-31 17:23:44 -06:00
|
|
|
extern Encoder* topEnc;
|
|
|
|
|
extern Encoder* bottomEnc;
|
2025-12-31 15:44:48 -06:00
|
|
|
|
2025-12-31 17:23:44 -06:00
|
|
|
void servoInit();
|
2025-12-31 15:44:48 -06:00
|
|
|
void servoOn(uint8_t dir, uint8_t manOrServer);
|
|
|
|
|
void servoOff();
|
|
|
|
|
void servoMainSwitch(uint8_t onOff);
|
|
|
|
|
void servoSavePos();
|
|
|
|
|
void servoCalibListen();
|
|
|
|
|
bool servoInitCalib();
|
|
|
|
|
bool servoBeginDownwardCalib();
|
|
|
|
|
bool servoCompleteCalib();
|
|
|
|
|
|
|
|
|
|
void initMainLoop();
|
|
|
|
|
void watchdogCallback(void* arg);
|
|
|
|
|
void servoSavePos();
|
|
|
|
|
int32_t servoReadPos();
|
|
|
|
|
void stopServerRun();
|
|
|
|
|
void servoWandListen();
|
2025-12-31 17:23:44 -06:00
|
|
|
void servoServerListen();
|
2025-12-31 15:44:48 -06:00
|
|
|
void runToAppPos(uint8_t appPos);
|
|
|
|
|
|
2026-01-03 22:59:36 -06:00
|
|
|
// Servo control task
|
|
|
|
|
void servoControlTask(void* arg);
|
|
|
|
|
|
2025-12-31 15:44:48 -06:00
|
|
|
#endif
|