2026-09-28 15:36:37 +02:00
|
|
|
#pragma once
|
|
|
|
|
#include "Kinematics.h"
|
|
|
|
|
|
|
|
|
|
class ServoDriver {
|
|
|
|
|
public:
|
2026-10-01 15:53:55 +02:00
|
|
|
void begin(); // set up the PWM pins (no pulses yet)
|
|
|
|
|
void relaxAll(); // stop all pulses - call when disarming
|
2026-09-28 15:36:37 +02:00
|
|
|
void writeLeg(int leg_index, const JointAngles& angles);
|
2026-10-01 15:53:55 +02:00
|
|
|
|
2026-11-17 14:42:37 +01:00
|
|
|
// Joint angle -> pulse through that servo's calibration (Config.h SERVOS)
|
|
|
|
|
// plus its centre trim.
|
2026-10-01 15:53:55 +02:00
|
|
|
static int degToMicros(int leg, int joint, float deg);
|
2026-11-17 14:42:37 +01:00
|
|
|
|
|
|
|
|
// ---- Servo centre calibration (remote's CAL page, CmdPacket.cal_*) ----
|
|
|
|
|
// Each servo has a centre trim in us on top of Config.h SERVOS, kept in
|
|
|
|
|
// EEPROM. Trims shift the whole pulse range, like the old sketch's
|
|
|
|
|
// servoCallibration[].
|
|
|
|
|
static void loadTrims(); // from EEPROM; all 0 if none stored. Call in setup()
|
|
|
|
|
static int16_t trim(int servo); // servo = leg * 3 + joint
|
|
|
|
|
static bool trimsDirty(); // changed since the last load/save
|
|
|
|
|
static bool trimsStored(); // the EEPROM holds a trim record
|
|
|
|
|
// Applies one calibration command (CAL_* in HexapodProtocol.h) and holds
|
|
|
|
|
// every servo at the centre pose. Call every loop while in SERVO_CAL.
|
|
|
|
|
void calibrate(uint8_t cal_cmd, uint8_t servo, int16_t value_us);
|
|
|
|
|
static const JointAngles CAL_POSE; // coxa 0, femur 0, tibia -90
|
2026-09-28 15:36:37 +02:00
|
|
|
};
|