2013-12-15 18:30:16 -05:00
|
|
|
/*----------------------------------------------------------------------------*/
|
2015-06-25 15:07:55 -04:00
|
|
|
/* Copyright (c) FIRST 2008. All Rights Reserved.
|
|
|
|
|
*/
|
2013-12-15 18:30:16 -05:00
|
|
|
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
|
|
|
|
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
#include "Talon.h"
|
|
|
|
|
|
2014-01-06 10:12:21 -05:00
|
|
|
//#include "NetworkCommunication/UsageReporting.h"
|
2013-12-15 18:30:16 -05:00
|
|
|
#include "LiveWindow/LiveWindow.h"
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Common initialization code called by all constructors.
|
|
|
|
|
*
|
2015-06-25 15:07:55 -04:00
|
|
|
* Note that the Talon uses the following bounds for PWM values. These values
|
|
|
|
|
* should work reasonably well for
|
|
|
|
|
* most controllers, but if users experience issues such as asymmetric behavior
|
|
|
|
|
* around
|
|
|
|
|
* the deadband or inability to saturate the controller in either direction,
|
|
|
|
|
* calibration is recommended.
|
|
|
|
|
* The calibration procedure can be found in the Talon User Manual available
|
|
|
|
|
* from CTRE.
|
2014-06-13 17:45:10 -04:00
|
|
|
*
|
2014-12-29 14:09:37 -05:00
|
|
|
* 2.037ms = full "forward"
|
|
|
|
|
* 1.539ms = the "high end" of the deadband range
|
|
|
|
|
* 1.513ms = center of the deadband range (off)
|
|
|
|
|
* 1.487ms = the "low end" of the deadband range
|
|
|
|
|
* 0.989ms = full "reverse"
|
2013-12-15 18:30:16 -05:00
|
|
|
*/
|
|
|
|
|
void Talon::InitTalon() {
|
2015-06-25 15:07:55 -04:00
|
|
|
SetBounds(2.037, 1.539, 1.513, 1.487, .989);
|
|
|
|
|
SetPeriodMultiplier(kPeriodMultiplier_1X);
|
|
|
|
|
SetRaw(m_centerPwm);
|
|
|
|
|
SetZeroLatch();
|
2013-12-15 18:30:16 -05:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
HALReport(HALUsageReporting::kResourceType_Talon, GetChannel());
|
|
|
|
|
LiveWindow::GetInstance()->AddActuator("Talon", GetChannel(), this);
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2014-12-29 14:09:37 -05:00
|
|
|
* Constructor for a Talon (original or Talon SR)
|
2015-06-25 15:07:55 -04:00
|
|
|
* @param channel The PWM channel number that the Talon is attached to. 0-9 are
|
|
|
|
|
* on-board, 10-19 are on the MXP port
|
2013-12-15 18:30:16 -05:00
|
|
|
*/
|
2015-06-25 15:07:55 -04:00
|
|
|
Talon::Talon(uint32_t channel) : SafePWM(channel) { InitTalon(); }
|
2013-12-15 18:30:16 -05:00
|
|
|
|
|
|
|
|
/**
|
2014-06-13 17:45:10 -04:00
|
|
|
* Set the PWM value.
|
|
|
|
|
*
|
2013-12-15 18:30:16 -05:00
|
|
|
* The PWM value is set using a range of -1.0 to 1.0, appropriately
|
|
|
|
|
* scaling the value for the FPGA.
|
2014-06-13 17:45:10 -04:00
|
|
|
*
|
2013-12-15 18:30:16 -05:00
|
|
|
* @param speed The speed value between -1.0 and 1.0 to set.
|
|
|
|
|
* @param syncGroup Unused interface.
|
|
|
|
|
*/
|
2015-06-25 15:07:55 -04:00
|
|
|
void Talon::Set(float speed, uint8_t syncGroup) {
|
|
|
|
|
SetSpeed(m_isInverted ? -speed : speed);
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the recently set value of the PWM.
|
2014-06-13 17:45:10 -04:00
|
|
|
*
|
2013-12-15 18:30:16 -05:00
|
|
|
* @return The most recently set value for the PWM between -1.0 and 1.0.
|
|
|
|
|
*/
|
2015-06-25 15:07:55 -04:00
|
|
|
float Talon::Get() const { return GetSpeed(); }
|
2013-12-15 18:30:16 -05:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Common interface for disabling a motor.
|
|
|
|
|
*/
|
2015-06-25 15:07:55 -04:00
|
|
|
void Talon::Disable() { SetRaw(kPwmDisabled); }
|
2015-06-15 15:32:47 -04:00
|
|
|
|
2015-03-24 15:01:17 -04:00
|
|
|
/**
|
|
|
|
|
* common interface for inverting direction of a speed controller
|
|
|
|
|
* @param isInverted The state of inversion true is inverted
|
|
|
|
|
*/
|
2015-06-25 15:07:55 -04:00
|
|
|
void Talon::SetInverted(bool isInverted) { m_isInverted = isInverted; }
|
2015-06-15 15:32:47 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Common interface for the inverting direction of a speed controller.
|
|
|
|
|
*
|
|
|
|
|
* @return isInverted The state of inversion, true is inverted.
|
|
|
|
|
*
|
|
|
|
|
*/
|
2015-06-25 15:07:55 -04:00
|
|
|
bool Talon::GetInverted() const { return m_isInverted; }
|
2015-06-15 15:32:47 -04:00
|
|
|
|
2013-12-15 18:30:16 -05:00
|
|
|
/**
|
|
|
|
|
* Write out the PID value as seen in the PIDOutput base object.
|
2014-06-13 17:45:10 -04:00
|
|
|
*
|
2013-12-15 18:30:16 -05:00
|
|
|
* @param output Write out the PWM value as was found in the PIDController
|
|
|
|
|
*/
|
2015-06-25 15:07:55 -04:00
|
|
|
void Talon::PIDWrite(float output) { Set(output); }
|