Files
hexapod-robot/2026-current/robot/ServoDriver.h
T

26 lines
1.4 KiB
C++
Raw Normal View History

#pragma once
#include "Kinematics.h"
class ServoDriver {
public:
void begin(); // set up the PWM pins (no pulses yet)
void relaxAll(); // stop all pulses - call when disarming
void writeLeg(int leg_index, const JointAngles& angles);
// Joint angle -> pulse through that servo's calibration (Config.h SERVOS)
// plus its centre trim.
static int degToMicros(int leg, int joint, float deg);
// ---- 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
};