mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-26 01:51:41 +00:00
Replaced floats with doubles (#355)
This makes our APIs more consistent. With optimizations enabled, doubles are just as efficient as floats on ARMv7, so we should take advantage of the extra precision.
This commit is contained in:
committed by
Peter Johnson
parent
7bcd243ec3
commit
69422dc063
@@ -11,11 +11,11 @@
|
||||
|
||||
using namespace frc;
|
||||
|
||||
constexpr float Servo::kMaxServoAngle;
|
||||
constexpr float Servo::kMinServoAngle;
|
||||
constexpr double Servo::kMaxServoAngle;
|
||||
constexpr double Servo::kMinServoAngle;
|
||||
|
||||
constexpr float Servo::kDefaultMaxServoPWM;
|
||||
constexpr float Servo::kDefaultMinServoPWM;
|
||||
constexpr double Servo::kDefaultMaxServoPWM;
|
||||
constexpr double Servo::kDefaultMinServoPWM;
|
||||
|
||||
/**
|
||||
* @param channel The PWM channel to which the servo is attached. 0-9 are
|
||||
@@ -45,7 +45,7 @@ Servo::~Servo() {
|
||||
*
|
||||
* @param value Position from 0.0 to 1.0.
|
||||
*/
|
||||
void Servo::Set(float value) { SetPosition(value); }
|
||||
void Servo::Set(double value) { SetPosition(value); }
|
||||
|
||||
/**
|
||||
* Set the servo to offline.
|
||||
@@ -62,7 +62,7 @@ void Servo::SetOffline() { SetRaw(0); }
|
||||
*
|
||||
* @return Position from 0.0 to 1.0.
|
||||
*/
|
||||
float Servo::Get() const { return GetPosition(); }
|
||||
double Servo::Get() const { return GetPosition(); }
|
||||
|
||||
/**
|
||||
* Set the servo angle.
|
||||
@@ -78,15 +78,14 @@ float Servo::Get() const { return GetPosition(); }
|
||||
*
|
||||
* @param degrees The angle in degrees to set the servo.
|
||||
*/
|
||||
void Servo::SetAngle(float degrees) {
|
||||
void Servo::SetAngle(double degrees) {
|
||||
if (degrees < kMinServoAngle) {
|
||||
degrees = kMinServoAngle;
|
||||
} else if (degrees > kMaxServoAngle) {
|
||||
degrees = kMaxServoAngle;
|
||||
}
|
||||
|
||||
SetPosition(static_cast<float>(degrees - kMinServoAngle) /
|
||||
GetServoAngleRange());
|
||||
SetPosition((degrees - kMinServoAngle) / GetServoAngleRange());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -97,9 +96,8 @@ void Servo::SetAngle(float degrees) {
|
||||
*
|
||||
* @return The angle in degrees to which the servo is set.
|
||||
*/
|
||||
float Servo::GetAngle() const {
|
||||
return static_cast<float>(GetPosition()) * GetServoAngleRange() +
|
||||
kMinServoAngle;
|
||||
double Servo::GetAngle() const {
|
||||
return GetPosition() * GetServoAngleRange() + kMinServoAngle;
|
||||
}
|
||||
|
||||
void Servo::ValueChanged(ITable* source, llvm::StringRef key,
|
||||
|
||||
Reference in New Issue
Block a user