40 lines
1.5 KiB
C++
40 lines
1.5 KiB
C++
#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;
|
|
};
|