implement AFServoMotor

This commit is contained in:
Leonetienne
2025-12-14 15:02:55 +01:00
parent a1c1cf0c40
commit d339f5b297
5 changed files with 203 additions and 1 deletions
+39
View File
@@ -0,0 +1,39 @@
#pragma once
#include <Arduino.h>
#include "RangedMotor.hpp"
#include "AdafruitPWMBoard.hpp"
class AdafruitServoMotor : public RangedMotor
{
public:
AdafruitServoMotor(
AdafruitPWMBoard& driver,
const uint8_t motorIndex,
const float gearboxRatio,
const float scaleCalibration,
const float zeroOffset,
const float minSafeAngle,
const float maxSafeAngle,
const float specRangeDeg, // 180 for a 180-deg-servo, 270 for a 270-deg-servo, etc ...
const uint16_t minPulseLength = 125,
const uint16_t maxPulseLength = 125,
const float initialPosition = 0
) noexcept;
// Returns true if the motion is accepted, false if it is outside of safe bounds.
bool moveTo(const float target) noexcept override;
float getPosition() const noexcept override { return hardwareAngleToVirtualAngle(currentHardwarePosition); };
// Will apply the current position immediately, no matter how small the move might be.
void commitMoveImmediately() noexcept;
protected:
uint16_t hardwareAngleToPulse(const float hardwareAngle) const noexcept;
AdafruitPWMBoard& driver;
const uint8_t motorIndex;
float currentHardwarePosition = 0;
float lastCommittedHardwarePosition = 0;
float specRangeDeg;
const uint8_t minPulseLength;
const uint8_t maxPulseLength;
};