[hal, wpilib] PWM Rewrite (#7845)

The HAL will only contain the output period and the raw microseconds. Higher level things such as SimDevice can handle everything else.
This commit is contained in:
Thad House
2025-03-20 19:23:22 -07:00
committed by GitHub
parent 2e21a41f87
commit e2cc9e0059
96 changed files with 1037 additions and 2453 deletions

View File

@@ -4,20 +4,27 @@
#pragma once
#include <hal/SimDevice.h>
#include <units/angle.h>
#include "frc/PWM.h"
namespace frc {
namespace sim {
class ServoSim;
} // namespace sim
/**
* Standard hobby style servo.
*
* The range parameters default to the appropriate values for the Hitec HS-322HD
* servo provided in the FIRST Kit of Parts in 2008.
*/
class Servo : public PWM {
class Servo : public wpi::Sendable, public wpi::SendableHelper<Servo> {
public:
friend class frc::sim::ServoSim;
/**
* Constructor.
*
@@ -42,13 +49,6 @@ class Servo : public PWM {
*/
void Set(double value);
/**
* Set the servo to offline.
*
* Set the servo raw value to 0 (undriven)
*/
void SetOffline();
/**
* Get the servo position.
*
@@ -86,30 +86,27 @@ class Servo : public PWM {
*/
double GetAngle() const;
/**
* Get the maximum angle of the servo.
*
* @return The maximum angle of the servo in degrees.
*/
double GetMaxAngle() const;
/**
* Get the minimum angle of the servo.
*
* @return The minimum angle of the servo in degrees.
*/
double GetMinAngle() const;
int GetChannel() const;
void InitSendable(wpi::SendableBuilder& builder) override;
private:
double GetServoAngleRange() const;
static double GetServoAngleRange();
units::microsecond_t GetFullRangeScaleFactor() const;
static constexpr double kMaxServoAngle = 180.;
static constexpr double kMaxServoAngle = 180.0;
static constexpr double kMinServoAngle = 0.0;
static constexpr units::millisecond_t kDefaultMaxServoPWM = 2.4_ms;
static constexpr units::millisecond_t kDefaultMinServoPWM = 0.6_ms;
units::millisecond_t m_maxPwm = kDefaultMaxServoPWM;
units::millisecond_t m_minPwm = kDefaultMinServoPWM;
hal::SimDevice m_simDevice;
hal::SimDouble m_simPosition;
PWM m_pwm;
};
} // namespace frc