2016-02-05 13:38:21 -08:00
|
|
|
/*----------------------------------------------------------------------------*/
|
2018-01-02 09:20:21 -08:00
|
|
|
/* Copyright (c) 2008-2018 FIRST. All Rights Reserved. */
|
2016-02-05 13:38:21 -08:00
|
|
|
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
|
|
|
|
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
|
|
|
|
/* the project. */
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
#include "PWMSpeedController.h"
|
|
|
|
|
|
2018-03-03 21:36:25 -08:00
|
|
|
#include "SmartDashboard/SendableBuilder.h"
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-20 07:25:03 -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
|
|
|
|
|
|
|
|
bool PWMSpeedController::GetInverted() const { return m_isInverted; }
|
|
|
|
|
|
2017-07-09 22:43:56 -04:00
|
|
|
void PWMSpeedController::Disable() { SetDisabled(); }
|
|
|
|
|
|
|
|
|
|
void PWMSpeedController::StopMotor() { SafePWM::StopMotor(); }
|
|
|
|
|
|
2016-11-20 07:25:03 -08:00
|
|
|
void PWMSpeedController::PIDWrite(double output) { Set(output); }
|
2018-03-03 21:36:25 -08:00
|
|
|
|
2018-05-31 20:47:15 -07:00
|
|
|
PWMSpeedController::PWMSpeedController(int channel) : SafePWM(channel) {}
|
|
|
|
|
|
2018-03-03 21:36:25 -08:00
|
|
|
void PWMSpeedController::InitSendable(SendableBuilder& builder) {
|
|
|
|
|
builder.SetSmartDashboardType("Speed Controller");
|
|
|
|
|
builder.SetSafeState([=]() { SetDisabled(); });
|
|
|
|
|
builder.AddDoubleProperty("Value", [=]() { return GetSpeed(); },
|
|
|
|
|
[=](double value) { SetSpeed(value); });
|
|
|
|
|
}
|