Brian Silverman | f7f267a | 2017-02-04 16:16:08 -0800 | [diff] [blame^] | 1 | /*----------------------------------------------------------------------------*/ |
| 2 | /* Copyright (c) FIRST 2008-2017. 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 "Talon.h" |
| 9 | |
| 10 | #include "LiveWindow/LiveWindow.h" |
| 11 | |
| 12 | using namespace frc; |
| 13 | |
| 14 | /** |
| 15 | * @param channel The PWM channel that the Talon is attached to. |
| 16 | */ |
| 17 | Talon::Talon(int channel) : SafePWM(channel) { |
| 18 | /* Note that the Talon uses the following bounds for PWM values. These values |
| 19 | * should work reasonably well for most controllers, but if users experience |
| 20 | * issues such as asymmetric behavior around the deadband or inability to |
| 21 | * saturate the controller in either direction, calibration is recommended. |
| 22 | * The calibration procedure can be found in the Talon User Manual available |
| 23 | * from CTRE. |
| 24 | * |
| 25 | * - 211 = full "forward" |
| 26 | * - 133 = the "high end" of the deadband range |
| 27 | * - 129 = center of the deadband range (off) |
| 28 | * - 125 = the "low end" of the deadband range |
| 29 | * - 49 = full "reverse" |
| 30 | */ |
| 31 | SetBounds(2.037, 1.539, 1.513, 1.487, .989); |
| 32 | SetPeriodMultiplier(kPeriodMultiplier_2X); |
| 33 | SetRaw(m_centerPwm); |
| 34 | |
| 35 | LiveWindow::GetInstance()->AddActuator("Talon", GetChannel(), this); |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * Set the PWM value. |
| 40 | * |
| 41 | * The PWM value is set using a range of -1.0 to 1.0, appropriately |
| 42 | * scaling the value for the FPGA. |
| 43 | * |
| 44 | * @param speed The speed value between -1.0 and 1.0 to set. |
| 45 | */ |
| 46 | void Talon::Set(double speed) { SetSpeed(speed); } |
| 47 | |
| 48 | /** |
| 49 | * Get the recently set value of the PWM. |
| 50 | * |
| 51 | * @return The most recently set value for the PWM between -1.0 and 1.0. |
| 52 | */ |
| 53 | double Talon::Get() const { return GetSpeed(); } |
| 54 | |
| 55 | /** |
| 56 | * Common interface for disabling a motor. |
| 57 | */ |
| 58 | void Talon::Disable() { SetRaw(kPwmDisabled); } |
| 59 | |
| 60 | /** |
| 61 | * Write out the PID value as seen in the PIDOutput base object. |
| 62 | * |
| 63 | * @param output Write out the PWM value as was found in the PIDController |
| 64 | */ |
| 65 | void Talon::PIDWrite(double output) { Set(output); } |