Brian Silverman | 41cdd3e | 2019-01-19 19:48:58 -0800 | [diff] [blame] | 1 | /*----------------------------------------------------------------------------*/ |
| 2 | /* Copyright (c) 2008-2018 FIRST. All Rights Reserved. */ |
| 3 | /* Open Source Software - may be modified and shared by FRC teams. The code */ |
| 4 | /* must be accompanied by the FIRST BSD license file in the root directory of */ |
| 5 | /* the project. */ |
| 6 | /*----------------------------------------------------------------------------*/ |
| 7 | |
| 8 | #include "frc/PWMSpeedController.h" |
| 9 | |
| 10 | #include "frc/smartdashboard/SendableBuilder.h" |
| 11 | |
| 12 | using namespace frc; |
| 13 | |
| 14 | void PWMSpeedController::Set(double speed) { |
| 15 | SetSpeed(m_isInverted ? -speed : speed); |
| 16 | } |
| 17 | |
| 18 | double PWMSpeedController::Get() const { return GetSpeed(); } |
| 19 | |
| 20 | void PWMSpeedController::SetInverted(bool isInverted) { |
| 21 | m_isInverted = isInverted; |
| 22 | } |
| 23 | |
| 24 | bool PWMSpeedController::GetInverted() const { return m_isInverted; } |
| 25 | |
| 26 | void PWMSpeedController::Disable() { SetDisabled(); } |
| 27 | |
| 28 | void PWMSpeedController::StopMotor() { PWM::StopMotor(); } |
| 29 | |
| 30 | void PWMSpeedController::PIDWrite(double output) { Set(output); } |
| 31 | |
| 32 | PWMSpeedController::PWMSpeedController(int channel) : PWM(channel) {} |
| 33 | |
| 34 | void PWMSpeedController::InitSendable(SendableBuilder& builder) { |
| 35 | builder.SetSmartDashboardType("Speed Controller"); |
| 36 | builder.SetActuator(true); |
| 37 | builder.SetSafeState([=]() { SetDisabled(); }); |
| 38 | builder.AddDoubleProperty("Value", [=]() { return GetSpeed(); }, |
| 39 | [=](double value) { SetSpeed(value); }); |
| 40 | } |