Use Angle16 for servo angles

This commit is contained in:
Pascal Serrarens 2024-08-02 09:10:42 +02:00
parent 4b362fffa8
commit f3e2656502
3 changed files with 9 additions and 8 deletions

View File

@ -9,7 +9,7 @@ class AbsoluteEncoder {
public: public:
AbsoluteEncoder() {} AbsoluteEncoder() {}
virtual Angle GetActualAngle() = 0; virtual Angle16 GetActualAngle() = 0;
virtual float GetActualVelocity() = 0; virtual float GetActualVelocity() = 0;
}; };

View File

@ -10,7 +10,7 @@ ServoMotor::ServoMotor()
this->hasTargetAngle = false; this->hasTargetAngle = false;
} }
void ServoMotor::SetTargetAngle(Angle angle) { void ServoMotor::SetTargetAngle(Angle16 angle) {
angle = Float::Clamp(angle, minAngle, maxAngle); angle = Float::Clamp(angle, minAngle, maxAngle);
if (maxVelocity == 0.0F || hasTargetAngle == false) { if (maxVelocity == 0.0F || hasTargetAngle == false) {
@ -23,7 +23,7 @@ void ServoMotor::SetTargetAngle(Angle angle) {
this->hasTargetAngle = true; this->hasTargetAngle = true;
} }
Angle ServoMotor::GetTargetAngle() { Angle16 ServoMotor::GetTargetAngle() {
return this->targetAngle; return this->targetAngle;
} }

View File

@ -1,6 +1,7 @@
#pragma once #pragma once
#include "ControlledMotor.h" #include "ControlledMotor.h"
#include "LinearAlgebra/Angle16.h"
namespace Passer { namespace Passer {
namespace RoboidContol { namespace RoboidContol {
@ -16,8 +17,8 @@ class ServoMotor : public Thing {
enum ControlMode { Position, Velocity }; enum ControlMode { Position, Velocity };
ControlMode controlMode = ControlMode::Position; ControlMode controlMode = ControlMode::Position;
virtual void SetTargetAngle(Angle angle); virtual void SetTargetAngle(Angle16 angle);
virtual Angle GetTargetAngle(); virtual Angle16 GetTargetAngle();
virtual void SetMaximumVelocity(float maxVelocity); virtual void SetMaximumVelocity(float maxVelocity);
@ -28,16 +29,16 @@ class ServoMotor : public Thing {
protected: protected:
bool hasTargetAngle = false; bool hasTargetAngle = false;
Angle targetAngle = 0.0F; Angle16 targetAngle = 0.0F;
float maxVelocity = 0.0F; float maxVelocity = 0.0F;
float targetVelocity = 0.0F; float targetVelocity = 0.0F;
Angle limitedTargetAngle = 0.0F; Angle16 limitedTargetAngle = 0.0F;
float lastUpdateTimeMs = 0.0F; float lastUpdateTimeMs = 0.0F;
virtual void SetAngle(Angle angle) = 0; virtual void SetAngle(Angle16 angle) = 0;
}; };
} // namespace RoboidContol } // namespace RoboidContol