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. */
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2018-07-20 00:03:45 -07:00
|
|
|
#include "frc/SafePWM.h"
|
|
|
|
|
#include "frc/SpeedController.h"
|
2016-02-05 13:38:21 -08:00
|
|
|
|
2016-11-01 22:33:12 -07:00
|
|
|
namespace frc {
|
|
|
|
|
|
2016-02-05 13:38:21 -08:00
|
|
|
/**
|
2017-11-16 00:33:51 -08:00
|
|
|
* Common base class for all PWM Speed Controllers.
|
2016-02-05 13:38:21 -08:00
|
|
|
*/
|
|
|
|
|
class PWMSpeedController : public SafePWM, public SpeedController {
|
|
|
|
|
public:
|
2018-05-31 20:47:15 -07: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.
|
|
|
|
|
*
|
|
|
|
|
* @param speed The speed value between -1.0 and 1.0 to set.
|
|
|
|
|
*/
|
2016-11-20 07:25:03 -08:00
|
|
|
void Set(double value) override;
|
2018-05-31 20:47:15 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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 Get() const override;
|
2018-05-31 20:47:15 -07:00
|
|
|
|
2017-07-09 22:43:56 -04:00
|
|
|
void SetInverted(bool isInverted) override;
|
2018-05-31 20:47:15 -07:00
|
|
|
|
2017-07-09 22:43:56 -04:00
|
|
|
bool GetInverted() const override;
|
2018-05-31 20:47:15 -07:00
|
|
|
|
2016-07-10 17:47:44 -07:00
|
|
|
void Disable() override;
|
2018-05-31 20:47:15 -07:00
|
|
|
|
2016-07-10 17:47:44 -07:00
|
|
|
void StopMotor() override;
|
2016-02-05 13:38:21 -08:00
|
|
|
|
2018-05-31 20:47:15 -07: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 PIDWrite(double output) override;
|
2016-02-05 13:38:21 -08:00
|
|
|
|
|
|
|
|
protected:
|
2018-05-31 20:47:15 -07:00
|
|
|
/**
|
|
|
|
|
* Constructor for a PWM Speed Controller connected via PWM.
|
|
|
|
|
*
|
|
|
|
|
* @param channel The PWM channel that the controller is attached to. 0-9 are
|
|
|
|
|
* on-board, 10-19 are on the MXP port
|
|
|
|
|
*/
|
2016-09-06 00:01:45 -07:00
|
|
|
explicit PWMSpeedController(int channel);
|
2018-05-31 20:47:15 -07:00
|
|
|
|
2018-03-03 21:36:25 -08:00
|
|
|
void InitSendable(SendableBuilder& builder) override;
|
2016-05-20 17:30:37 -07:00
|
|
|
|
2016-02-05 13:38:21 -08:00
|
|
|
private:
|
|
|
|
|
bool m_isInverted = false;
|
2016-05-23 20:42:58 -07:00
|
|
|
};
|
2016-11-01 22:33:12 -07:00
|
|
|
|
|
|
|
|
} // namespace frc
|