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-02-05 13:38:21 -08:00
|
|
|
/**
|
2016-05-20 17:30:37 -07:00
|
|
|
* Constructor for a PWM Speed Controller connected via PWM.
|
|
|
|
|
*
|
2016-02-05 13:38:21 -08:00
|
|
|
* @param channel The PWM channel that the controller is attached to. 0-9 are
|
2016-05-20 17:30:37 -07:00
|
|
|
* on-board, 10-19 are on the MXP port
|
2016-02-05 13:38:21 -08:00
|
|
|
*/
|
2016-09-06 00:01:45 -07:00
|
|
|
PWMSpeedController::PWMSpeedController(int channel) : SafePWM(channel) {}
|
2016-02-05 13:38:21 -08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set the PWM value.
|
|
|
|
|
*
|
|
|
|
|
* The PWM value is set using a range of -1.0 to 1.0, appropriately
|
|
|
|
|
* scaling the value for the FPGA.
|
|
|
|
|
*
|
2016-05-23 20:42:58 -07:00
|
|
|
* @param speed The speed value between -1.0 and 1.0 to set.
|
2016-02-05 13:38:21 -08:00
|
|
|
*/
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the recently set value of the PWM.
|
|
|
|
|
*
|
|
|
|
|
* @return The most recently set value for the PWM between -1.0 and 1.0.
|
|
|
|
|
*/
|
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-02-05 13:38:21 -08:00
|
|
|
/**
|
|
|
|
|
* Write out the PID value as seen in the PIDOutput base object.
|
|
|
|
|
*
|
|
|
|
|
* @param output Write out the PWM value as was found in the PIDController
|
|
|
|
|
*/
|
2016-11-20 07:25:03 -08:00
|
|
|
void PWMSpeedController::PIDWrite(double output) { Set(output); }
|
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); });
|
|
|
|
|
}
|