blob: 81c863c1ea319140779888bbffd737ca1d0b8971 [file] [log] [blame]
Brian Silverman26e4e522015-12-17 01:56:40 -05001/*----------------------------------------------------------------------------*/
Brian Silverman1a675112016-02-20 20:42:49 -05002/* Copyright (c) FIRST 2008-2016. All Rights Reserved. */
Brian Silverman26e4e522015-12-17 01:56:40 -05003/* Open Source Software - may be modified and shared by FRC teams. The code */
Brian Silverman1a675112016-02-20 20:42:49 -05004/* must be accompanied by the FIRST BSD license file in the root directory of */
5/* the project. */
Brian Silverman26e4e522015-12-17 01:56:40 -05006/*----------------------------------------------------------------------------*/
7
8#include "Victor.h"
9
10#include "LiveWindow/LiveWindow.h"
11
12/**
13 * Constructor for a Victor
14 * @param channel The PWM channel number that the Victor is attached to. 0-9 are
15 * on-board, 10-19 are on the MXP port
16 */
17Victor::Victor(uint32_t channel) : SafePWM(channel) {
18 /* Note that the Victor uses the following bounds for PWM values. These
19 * values were determined empirically and optimized for the Victor 888. These
20 * values should work reasonably well for Victor 884 controllers as well but
21 * if users experience issues such as asymmetric behaviour around the deadband
22 * or inability to saturate the controller in either direction, calibration is
23 * recommended. The calibration procedure can be found in the Victor 884 User
24 * Manual available from IFI.
25 *
26 * 2.027ms = full "forward"
27 * 1.525ms = the "high end" of the deadband range
28 * 1.507ms = center of the deadband range (off)
29 * 1.49ms = the "low end" of the deadband range
30 * 1.026ms = full "reverse"
31 */
32 SetBounds(2.027, 1.525, 1.507, 1.49, 1.026);
33 SetPeriodMultiplier(kPeriodMultiplier_2X);
34 SetRaw(m_centerPwm);
35 SetZeroLatch();
36
37 LiveWindow::GetInstance()->AddActuator("Victor", GetChannel(), this);
38 HALReport(HALUsageReporting::kResourceType_Victor, GetChannel());
39}
40
41/**
42 * Set the PWM value.
43 *
44 * The PWM value is set using a range of -1.0 to 1.0, appropriately
45 * scaling the value for the FPGA.
46 *
47 * @param speed The speed value between -1.0 and 1.0 to set.
48 * @param syncGroup Unused interface.
49 */
50void Victor::Set(float speed, uint8_t syncGroup) {
51 SetSpeed(m_isInverted ? -speed : speed);
52}
53
54/**
55 * Get the recently set value of the PWM.
56 *
57 * @return The most recently set value for the PWM between -1.0 and 1.0.
58 */
59float Victor::Get() const { return GetSpeed(); }
60
61/**
62 * Common interface for disabling a motor.
63 */
64void Victor::Disable() { SetRaw(kPwmDisabled); }
65/**
66* Common interface for inverting direction of a speed controller.
67* @param isInverted The state of inversion, true is inverted.
68*/
69void Victor::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 Victor::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 Victor::PIDWrite(float output) { Set(output); }
Brian Silverman1a675112016-02-20 20:42:49 -050085
86/**
87 * Common interface to stop the motor until Set is called again.
88 */
89void Victor::StopMotor() { this->SafePWM::StopMotor(); }