2020-12-26 14:12:05 -08:00
|
|
|
// 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.
|
2016-02-05 13:38:21 -08:00
|
|
|
|
2018-07-20 00:03:45 -07:00
|
|
|
#include "frc/PWMSpeedController.h"
|
2016-02-05 13:38:21 -08:00
|
|
|
|
2018-07-20 00:03:45 -07:00
|
|
|
#include "frc/smartdashboard/SendableBuilder.h"
|
2018-03-03 21:36:25 -08:00
|
|
|
|
2016-11-01 22:33:12 -07:00
|
|
|
using namespace frc;
|
|
|
|
|
|
2016-11-20 07:25:03 -08:00
|
|
|
void PWMSpeedController::Set(double speed) {
|
2016-02-05 13:38:21 -08:00
|
|
|
SetSpeed(m_isInverted ? -speed : speed);
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-28 12:58:06 -08:00
|
|
|
double PWMSpeedController::Get() const {
|
|
|
|
|
return GetSpeed();
|
|
|
|
|
}
|
2016-02-05 13:38:21 -08:00
|
|
|
|
2016-05-20 17:30:37 -07:00
|
|
|
void PWMSpeedController::SetInverted(bool isInverted) {
|
|
|
|
|
m_isInverted = isInverted;
|
|
|
|
|
}
|
2016-02-05 13:38:21 -08:00
|
|
|
|
2020-12-28 12:58:06 -08:00
|
|
|
bool PWMSpeedController::GetInverted() const {
|
|
|
|
|
return m_isInverted;
|
|
|
|
|
}
|
2016-02-05 13:38:21 -08:00
|
|
|
|
2020-12-28 12:58:06 -08:00
|
|
|
void PWMSpeedController::Disable() {
|
|
|
|
|
SetDisabled();
|
|
|
|
|
}
|
2017-07-09 22:43:56 -04:00
|
|
|
|
2020-12-28 12:58:06 -08:00
|
|
|
void PWMSpeedController::StopMotor() {
|
|
|
|
|
PWM::StopMotor();
|
|
|
|
|
}
|
2017-07-09 22:43:56 -04:00
|
|
|
|
2020-12-28 12:58:06 -08:00
|
|
|
void PWMSpeedController::PIDWrite(double output) {
|
|
|
|
|
Set(output);
|
|
|
|
|
}
|
2018-03-03 21:36:25 -08:00
|
|
|
|
2018-11-22 21:15:26 -08:00
|
|
|
PWMSpeedController::PWMSpeedController(int channel) : PWM(channel) {}
|
2018-05-31 20:47:15 -07:00
|
|
|
|
2018-03-03 21:36:25 -08:00
|
|
|
void PWMSpeedController::InitSendable(SendableBuilder& builder) {
|
|
|
|
|
builder.SetSmartDashboardType("Speed Controller");
|
2018-07-28 14:04:46 -07:00
|
|
|
builder.SetActuator(true);
|
2018-03-03 21:36:25 -08:00
|
|
|
builder.SetSafeState([=]() { SetDisabled(); });
|
2020-06-27 20:39:00 -07:00
|
|
|
builder.AddDoubleProperty(
|
|
|
|
|
"Value", [=]() { return GetSpeed(); },
|
|
|
|
|
[=](double value) { SetSpeed(value); });
|
2018-03-03 21:36:25 -08:00
|
|
|
}
|