blob: dc1cf3bc7f07da70f79c50fb28f007b6113202c3 [file] [log] [blame]
Brian Silverman26e4e522015-12-17 01:56:40 -05001/*----------------------------------------------------------------------------*/
2/* Copyright (c) FIRST 2008. All Rights Reserved.
3 */
4/* Open Source Software - may be modified and shared by FRC teams. The code */
5/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
6/*----------------------------------------------------------------------------*/
7
8#include "Talon.h"
9
10#include "LiveWindow/LiveWindow.h"
11
12/**
13 * Constructor for a Talon (original or Talon SR)
14 * @param channel The PWM channel number that the Talon is attached to. 0-9 are
15 * on-board, 10-19 are on the MXP port
16 */
17Talon::Talon(uint32_t 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 * 2.037ms = full "forward"
26 * 1.539ms = the "high end" of the deadband range
27 * 1.513ms = center of the deadband range (off)
28 * 1.487ms = the "low end" of the deadband range
29 * 0.989ms = full "reverse"
30 */
31 SetBounds(2.037, 1.539, 1.513, 1.487, .989);
32 SetPeriodMultiplier(kPeriodMultiplier_1X);
33 SetRaw(m_centerPwm);
34 SetZeroLatch();
35
36 HALReport(HALUsageReporting::kResourceType_Talon, GetChannel());
37 LiveWindow::GetInstance()->AddActuator("Talon", GetChannel(), this);
38}
39
40/**
41 * Set the PWM value.
42 *
43 * The PWM value is set using a range of -1.0 to 1.0, appropriately
44 * scaling the value for the FPGA.
45 *
46 * @param speed The speed value between -1.0 and 1.0 to set.
47 * @param syncGroup Unused interface.
48 */
49void Talon::Set(float speed, uint8_t syncGroup) {
50 SetSpeed(m_isInverted ? -speed : speed);
51}
52
53/**
54 * Get the recently set value of the PWM.
55 *
56 * @return The most recently set value for the PWM between -1.0 and 1.0.
57 */
58float Talon::Get() const { return GetSpeed(); }
59
60/**
61 * Common interface for disabling a motor.
62 */
63void Talon::Disable() { SetRaw(kPwmDisabled); }
64
65/**
66* common interface for inverting direction of a speed controller
67* @param isInverted The state of inversion true is inverted
68*/
69void Talon::SetInverted(bool isInverted) { m_isInverted = isInverted; }
70
71/**
72 * Common interface for the inverting direction of a speed controller.
73 *
74 * @return isInverted The state of inversion, true is inverted.
75 *
76 */
77bool Talon::GetInverted() const { return m_isInverted; }
78
79/**
80 * Write out the PID value as seen in the PIDOutput base object.
81 *
82 * @param output Write out the PWM value as was found in the PIDController
83 */
84void Talon::PIDWrite(float output) { Set(output); }