mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-02 02:51:42 +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
@@ -32,7 +32,7 @@ class PIDCommand : public Command, public PIDOutput, public PIDSource {
|
||||
void SetSetpointRelative(double deltaSetpoint);
|
||||
|
||||
// PIDOutput interface
|
||||
virtual void PIDWrite(float output);
|
||||
virtual void PIDWrite(double output);
|
||||
|
||||
// PIDSource interface
|
||||
virtual double PIDGet();
|
||||
|
||||
@@ -42,20 +42,20 @@ class PIDSubsystem : public Subsystem, public PIDOutput, public PIDSource {
|
||||
void Disable();
|
||||
|
||||
// PIDOutput interface
|
||||
virtual void PIDWrite(float output);
|
||||
virtual void PIDWrite(double output);
|
||||
|
||||
// PIDSource interface
|
||||
virtual double PIDGet();
|
||||
void SetSetpoint(double setpoint);
|
||||
void SetSetpointRelative(double deltaSetpoint);
|
||||
void SetInputRange(float minimumInput, float maximumInput);
|
||||
void SetOutputRange(float minimumOutput, float maximumOutput);
|
||||
void SetInputRange(double minimumInput, double maximumInput);
|
||||
void SetOutputRange(double minimumOutput, double maximumOutput);
|
||||
double GetSetpoint();
|
||||
double GetPosition();
|
||||
double GetRate();
|
||||
|
||||
virtual void SetAbsoluteTolerance(float absValue);
|
||||
virtual void SetPercentTolerance(float percent);
|
||||
virtual void SetAbsoluteTolerance(double absValue);
|
||||
virtual void SetPercentTolerance(double percent);
|
||||
virtual bool OnTarget() const;
|
||||
|
||||
protected:
|
||||
|
||||
@@ -47,9 +47,9 @@ class GenericHID {
|
||||
explicit GenericHID(int port);
|
||||
virtual ~GenericHID() = default;
|
||||
|
||||
virtual float GetX(JoystickHand hand = kRightHand) const = 0;
|
||||
virtual float GetY(JoystickHand hand = kRightHand) const = 0;
|
||||
virtual float GetRawAxis(int axis) const;
|
||||
virtual double GetX(JoystickHand hand = kRightHand) const = 0;
|
||||
virtual double GetY(JoystickHand hand = kRightHand) const = 0;
|
||||
virtual double GetRawAxis(int axis) const;
|
||||
|
||||
bool GetRawButton(int button) const;
|
||||
|
||||
|
||||
@@ -58,21 +58,21 @@ class Joystick : public JoystickBase, public ErrorBase {
|
||||
int GetAxisChannel(AxisType axis) const;
|
||||
void SetAxisChannel(AxisType axis, int channel);
|
||||
|
||||
float GetX(JoystickHand hand = kRightHand) const override;
|
||||
float GetY(JoystickHand hand = kRightHand) const override;
|
||||
float GetZ(JoystickHand hand = kRightHand) const override;
|
||||
float GetTwist() const override;
|
||||
float GetThrottle() const override;
|
||||
virtual float GetAxis(AxisType axis) const;
|
||||
double GetX(JoystickHand hand = kRightHand) const override;
|
||||
double GetY(JoystickHand hand = kRightHand) const override;
|
||||
double GetZ(JoystickHand hand = kRightHand) const override;
|
||||
double GetTwist() const override;
|
||||
double GetThrottle() const override;
|
||||
virtual double GetAxis(AxisType axis) const;
|
||||
|
||||
bool GetTrigger(JoystickHand hand = kRightHand) const override;
|
||||
bool GetTop(JoystickHand hand = kRightHand) const override;
|
||||
bool GetButton(ButtonType button) const;
|
||||
static Joystick* GetStickForPort(int port);
|
||||
|
||||
virtual float GetMagnitude() const;
|
||||
virtual float GetDirectionRadians() const;
|
||||
virtual float GetDirectionDegrees() const;
|
||||
virtual double GetMagnitude() const;
|
||||
virtual double GetDirectionRadians() const;
|
||||
virtual double GetDirectionDegrees() const;
|
||||
|
||||
int GetAxisType(int axis) const;
|
||||
|
||||
|
||||
@@ -19,9 +19,9 @@ class JoystickBase : public GenericHID {
|
||||
explicit JoystickBase(int port);
|
||||
virtual ~JoystickBase() = default;
|
||||
|
||||
virtual float GetZ(JoystickHand hand = kRightHand) const = 0;
|
||||
virtual float GetTwist() const = 0;
|
||||
virtual float GetThrottle() const = 0;
|
||||
virtual double GetZ(JoystickHand hand = kRightHand) const = 0;
|
||||
virtual double GetTwist() const = 0;
|
||||
virtual double GetThrottle() const = 0;
|
||||
|
||||
virtual bool GetTrigger(JoystickHand hand = kRightHand) const = 0;
|
||||
virtual bool GetTop(JoystickHand hand = kRightHand) const = 0;
|
||||
|
||||
@@ -39,19 +39,19 @@ class PIDController : public LiveWindowSendable,
|
||||
public PIDInterface,
|
||||
public ITableListener {
|
||||
public:
|
||||
PIDController(float p, float i, float d, PIDSource* source, PIDOutput* output,
|
||||
float period = 0.05);
|
||||
PIDController(float p, float i, float d, float f, PIDSource* source,
|
||||
PIDOutput* output, float period = 0.05);
|
||||
PIDController(double p, double i, double d, PIDSource* source,
|
||||
PIDOutput* output, double period = 0.05);
|
||||
PIDController(double p, double i, double d, double f, PIDSource* source,
|
||||
PIDOutput* output, double period = 0.05);
|
||||
virtual ~PIDController();
|
||||
|
||||
PIDController(const PIDController&) = delete;
|
||||
PIDController& operator=(const PIDController) = delete;
|
||||
|
||||
virtual float Get() const;
|
||||
virtual double Get() const;
|
||||
virtual void SetContinuous(bool continuous = true);
|
||||
virtual void SetInputRange(float minimumInput, float maximumInput);
|
||||
virtual void SetOutputRange(float minimumOutput, float maximumOutput);
|
||||
virtual void SetInputRange(double minimumInput, double maximumInput);
|
||||
virtual void SetOutputRange(double minimumOutput, double maximumOutput);
|
||||
void SetPID(double p, double i, double d) override;
|
||||
virtual void SetPID(double p, double i, double d, double f);
|
||||
double GetP() const override;
|
||||
@@ -59,19 +59,19 @@ class PIDController : public LiveWindowSendable,
|
||||
double GetD() const override;
|
||||
virtual double GetF() const;
|
||||
|
||||
void SetSetpoint(float setpoint) override;
|
||||
void SetSetpoint(double setpoint) override;
|
||||
double GetSetpoint() const override;
|
||||
double GetDeltaSetpoint() const;
|
||||
|
||||
virtual float GetError() const;
|
||||
virtual float GetAvgError() const;
|
||||
virtual double GetError() const;
|
||||
virtual double GetAvgError() const;
|
||||
|
||||
virtual void SetPIDSourceType(PIDSourceType pidSource);
|
||||
virtual PIDSourceType GetPIDSourceType() const;
|
||||
|
||||
virtual void SetTolerance(float percent);
|
||||
virtual void SetAbsoluteTolerance(float absValue);
|
||||
virtual void SetPercentTolerance(float percentValue);
|
||||
virtual void SetTolerance(double percent);
|
||||
virtual void SetAbsoluteTolerance(double absValue);
|
||||
virtual void SetPercentTolerance(double percentValue);
|
||||
virtual void SetToleranceBuffer(int buf = 1);
|
||||
virtual bool OnTarget() const;
|
||||
|
||||
@@ -94,27 +94,27 @@ class PIDController : public LiveWindowSendable,
|
||||
|
||||
private:
|
||||
// factor for "proportional" control
|
||||
float m_P;
|
||||
double m_P;
|
||||
// factor for "integral" control
|
||||
float m_I;
|
||||
double m_I;
|
||||
// factor for "derivative" control
|
||||
float m_D;
|
||||
double m_D;
|
||||
// factor for "feed forward" control
|
||||
float m_F;
|
||||
double m_F;
|
||||
// |maximum output|
|
||||
float m_maximumOutput = 1.0;
|
||||
double m_maximumOutput = 1.0;
|
||||
// |minimum output|
|
||||
float m_minimumOutput = -1.0;
|
||||
double m_minimumOutput = -1.0;
|
||||
// maximum input - limit setpoint to this
|
||||
float m_maximumInput = 0;
|
||||
double m_maximumInput = 0;
|
||||
// minimum input - limit setpoint to this
|
||||
float m_minimumInput = 0;
|
||||
double m_minimumInput = 0;
|
||||
// do the endpoints wrap around? eg. Absolute encoder
|
||||
bool m_continuous = false;
|
||||
// is the pid controller enabled
|
||||
bool m_enabled = false;
|
||||
// the prior error (used to compute velocity)
|
||||
float m_prevError = 0;
|
||||
double m_prevError = 0;
|
||||
// the sum of the errors for use in the integral calc
|
||||
double m_totalError = 0;
|
||||
enum {
|
||||
@@ -124,12 +124,12 @@ class PIDController : public LiveWindowSendable,
|
||||
} m_toleranceType = kNoTolerance;
|
||||
|
||||
// the percetage or absolute error that is considered on target.
|
||||
float m_tolerance = 0.05;
|
||||
float m_setpoint = 0;
|
||||
float m_prevSetpoint = 0;
|
||||
float m_error = 0;
|
||||
float m_result = 0;
|
||||
float m_period;
|
||||
double m_tolerance = 0.05;
|
||||
double m_setpoint = 0;
|
||||
double m_prevSetpoint = 0;
|
||||
double m_error = 0;
|
||||
double m_result = 0;
|
||||
double m_period;
|
||||
|
||||
// Length of buffer for averaging for tolerances.
|
||||
std::atomic<unsigned> m_bufLength{1};
|
||||
|
||||
@@ -19,7 +19,7 @@ class PIDInterface : public Controller {
|
||||
virtual double GetI() const = 0;
|
||||
virtual double GetD() const = 0;
|
||||
|
||||
virtual void SetSetpoint(float setpoint) = 0;
|
||||
virtual void SetSetpoint(double setpoint) = 0;
|
||||
virtual double GetSetpoint() const = 0;
|
||||
|
||||
virtual void Enable() = 0;
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace frc {
|
||||
*/
|
||||
class PIDOutput {
|
||||
public:
|
||||
virtual void PIDWrite(float output) = 0;
|
||||
virtual void PIDWrite(double output) = 0;
|
||||
};
|
||||
|
||||
} // namespace frc
|
||||
|
||||
@@ -31,13 +31,13 @@ class XboxController : public GamepadBase, public ErrorBase {
|
||||
XboxController(const XboxController&) = delete;
|
||||
XboxController& operator=(const XboxController&) = delete;
|
||||
|
||||
float GetX(JoystickHand hand) const override;
|
||||
float GetY(JoystickHand hand) const override;
|
||||
double GetX(JoystickHand hand) const override;
|
||||
double GetY(JoystickHand hand) const override;
|
||||
|
||||
bool GetBumper(JoystickHand hand) const override;
|
||||
bool GetStickButton(JoystickHand hand) const override;
|
||||
|
||||
virtual float GetTriggerAxis(JoystickHand hand) const;
|
||||
virtual double GetTriggerAxis(JoystickHand hand) const;
|
||||
|
||||
bool GetAButton() const;
|
||||
bool GetBButton() const;
|
||||
|
||||
@@ -45,7 +45,7 @@ class Gyro {
|
||||
* @return the current heading of the robot in degrees. This heading is based
|
||||
* on integration of the returned rate from the gyro.
|
||||
*/
|
||||
virtual float GetAngle() const = 0;
|
||||
virtual double GetAngle() const = 0;
|
||||
|
||||
/**
|
||||
* Return the rate of rotation of the gyro
|
||||
|
||||
Reference in New Issue
Block a user