[wpilib] PWMSpeedController: Use PWM by composition (#3248)

This cleans up the user experience by removing lower-level functions from the
interface.

Also remove MotorSafety from "raw" PWM.
This commit is contained in:
Peter Johnson
2021-03-21 11:12:49 -07:00
committed by GitHub
parent 160fb740f4
commit 9550777b9d
32 changed files with 242 additions and 252 deletions

View File

@@ -19,7 +19,7 @@
using namespace frc;
PWM::PWM(int channel) {
PWM::PWM(int channel, bool registerSendable) {
if (!SensorUtil::CheckPWMChannel(channel)) {
wpi_setWPIErrorWithContext(ChannelIndexOutOfRange,
"PWM Channel " + wpi::Twine(channel));
@@ -44,9 +44,9 @@ PWM::PWM(int channel) {
wpi_setHALError(status);
HAL_Report(HALUsageReporting::kResourceType_PWM, channel + 1);
SendableRegistry::GetInstance().AddLW(this, "PWM", channel);
SetSafetyEnabled(false);
if (registerSendable) {
SendableRegistry::GetInstance().AddLW(this, "PWM", channel);
}
}
PWM::~PWM() {
@@ -59,14 +59,6 @@ PWM::~PWM() {
wpi_setHALError(status);
}
void PWM::StopMotor() {
SetDisabled();
}
void PWM::GetDescription(wpi::raw_ostream& desc) const {
desc << "PWM " << GetChannel();
}
void PWM::SetRaw(uint16_t value) {
if (StatusIsFatal()) {
return;
@@ -115,8 +107,6 @@ void PWM::SetSpeed(double speed) {
int32_t status = 0;
HAL_SetPWMSpeed(m_handle, speed, &status);
wpi_setHALError(status);
Feed();
}
double PWM::GetSpeed() const {
@@ -223,8 +213,7 @@ int PWM::GetChannel() const {
void PWM::InitSendable(SendableBuilder& builder) {
builder.SetSmartDashboardType("PWM");
builder.SetActuator(true);
builder.SetSafeState([=]() { SetDisabled(); });
builder.SetSafeState([=] { SetDisabled(); });
builder.AddDoubleProperty(
"Value", [=]() { return GetRaw(); },
[=](double value) { SetRaw(value); });
"Value", [=] { return GetRaw(); }, [=](double value) { SetRaw(value); });
}