[wpilib] Remove Servo Classes (#8270)

SystemCore doesn't directly support Servos. It would be possible to still use a Servo Power Module, but those are fairly rare, and we should probably use a different class for that case, so users don't attempt to hook a servo directly up to systemcore. That will depend on what happens with the rules in 2027.

Rev Servo Hubs are a current working replacement for systemcore users.
This commit is contained in:
Thad House
2025-10-02 22:39:55 -07:00
committed by GitHub
parent c46b54a523
commit e369c721ca
8 changed files with 0 additions and 553 deletions

View File

@@ -1,84 +0,0 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#include "frc/Servo.h"
#include <hal/UsageReporting.h>
#include <wpi/sendable/SendableBuilder.h>
#include <wpi/sendable/SendableRegistry.h>
using namespace frc;
Servo::Servo(int channel) : m_pwm(channel, false) {
wpi::SendableRegistry::Add(this, "Servo", channel);
// Assign defaults for period multiplier for the servo PWM control signal
m_pwm.SetOutputPeriod(PWM::kOutputPeriod_20Ms);
HAL_ReportUsage("IO", channel, "Servo");
wpi::SendableRegistry::SetName(this, "Servo", channel);
m_simDevice = hal::SimDevice{"Servo", channel};
if (m_simDevice) {
m_simPosition = m_simDevice.CreateDouble("Position", true, 0.0);
m_pwm.SetSimDevice(m_simDevice);
}
}
void Servo::Set(double value) {
value = std::clamp(value, 0.0, 1.0);
if (m_simPosition) {
m_simPosition.Set(value);
}
units::microsecond_t rawValue =
(value * GetFullRangeScaleFactor()) + m_minPwm;
m_pwm.SetPulseTime(rawValue);
}
double Servo::Get() const {
units::microsecond_t rawValue = m_pwm.GetPulseTime();
if (rawValue < m_minPwm) {
return 0.0;
} else if (rawValue > m_maxPwm) {
return 1.0;
}
return (rawValue - m_minPwm).to<double>() /
GetFullRangeScaleFactor().to<double>();
}
void Servo::SetAngle(double degrees) {
if (degrees < kMinServoAngle) {
degrees = kMinServoAngle;
} else if (degrees > kMaxServoAngle) {
degrees = kMaxServoAngle;
}
Set((degrees - kMinServoAngle) / GetServoAngleRange());
}
double Servo::GetAngle() const {
return Get() * GetServoAngleRange() + kMinServoAngle;
}
void Servo::InitSendable(wpi::SendableBuilder& builder) {
builder.SetSmartDashboardType("Servo");
builder.AddDoubleProperty(
"Value", [=, this] { return Get(); },
[=, this](double value) { Set(value); });
}
double Servo::GetServoAngleRange() {
return kMaxServoAngle - kMinServoAngle;
}
units::microsecond_t Servo::GetFullRangeScaleFactor() const {
return m_maxPwm - m_minPwm;
}
int Servo::GetChannel() const {
return m_pwm.GetChannel();
}

View File

@@ -1,28 +0,0 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#include "frc/simulation/ServoSim.h"
#include <hal/SimDevice.h>
#include <units/length.h>
#include "frc/simulation/SimDeviceSim.h"
using namespace frc;
using namespace frc::sim;
ServoSim::ServoSim(const Servo& servo) : ServoSim(servo.GetChannel()) {}
ServoSim::ServoSim(int channel) {
frc::sim::SimDeviceSim deviceSim{"Servo", channel};
m_simPosition = deviceSim.GetDouble("Position");
}
double ServoSim::GetPosition() const {
return m_simPosition.Get();
}
double ServoSim::GetAngle() const {
return GetPosition() * Servo::GetServoAngleRange() + Servo::kMinServoAngle;
}

View File

@@ -1,112 +0,0 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#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 wpi::Sendable, public wpi::SendableHelper<Servo> {
public:
friend class frc::sim::ServoSim;
/**
* Constructor.
*
* By default, 2.4 ms is used as the max PWM value and 0.6 ms is used as the
* min PWM value.
*
* @param channel The PWM channel to which the servo is attached. 0-9 are
* on-board, 10-19 are on the MXP port
*/
explicit Servo(int channel);
Servo(Servo&&) = default;
Servo& operator=(Servo&&) = default;
/**
* Set the servo position.
*
* Servo values range from 0.0 to 1.0 corresponding to the range of full left
* to full right.
*
* @param value Position from 0.0 to 1.0.
*/
void Set(double value);
/**
* Get the servo position.
*
* Servo values range from 0.0 to 1.0 corresponding to the range of full left
* to full right. This returns the commanded position, not the position that
* the servo is actually at, as the servo does not report its own position.
*
* @return Position from 0.0 to 1.0.
*/
double Get() const;
/**
* Set the servo angle.
*
* The angles are based on the HS-322HD Servo, and have a range of 0 to 180
* degrees.
*
* Servo angles that are out of the supported range of the servo simply
* "saturate" in that direction. In other words, if the servo has a range of
* (X degrees to Y degrees) than angles of less than X result in an angle of
* X being set and angles of more than Y degrees result in an angle of Y being
* set.
*
* @param angle The angle in degrees to set the servo.
*/
void SetAngle(double angle);
/**
* Get the servo angle.
*
* This returns the commanded angle, not the angle that the servo is actually
* at, as the servo does not report its own angle.
*
* @return The angle in degrees to which the servo is set.
*/
double GetAngle() const;
int GetChannel() const;
void InitSendable(wpi::SendableBuilder& builder) override;
private:
static double GetServoAngleRange();
units::microsecond_t GetFullRangeScaleFactor() const;
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

View File

@@ -1,31 +0,0 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#pragma once
#include <hal/SimDevice.h>
#include <units/length.h>
#include "frc/Servo.h"
namespace frc {
class Servo;
namespace sim {
class ServoSim {
public:
explicit ServoSim(const Servo& servo);
explicit ServoSim(int channel);
double GetPosition() const;
double GetAngle() const;
private:
hal::SimDouble m_simPosition;
};
} // namespace sim
} // namespace frc