blob: a43476975edb68219fc821d6eadc50950caa780b [file] [log] [blame]
jerrymf1579332013-02-07 01:56:28 +00001/*----------------------------------------------------------------------------*/
2/* Copyright (c) FIRST 2008. 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 $(WIND_BASE)/WPILib. */
5/*----------------------------------------------------------------------------*/
6
7#include "Victor.h"
8
9#include "DigitalModule.h"
10#include "NetworkCommunication/UsageReporting.h"
11#include "LiveWindow/LiveWindow.h"
12
13/**
14 * Common initialization code called by all constructors.
15 *
16 * Note that the Victor uses the following bounds for PWM values. These values were determined
17 * empirically and optimized for the Victor 888. These values should work reasonably well for
18 * Victor 884 controllers as well but if users experience issues such as asymmetric behavior around
19 * the deadband or inability to saturate the controller in either direction, calibration is recommended.
20 * The calibration procedure can be found in the Victor 884 User Manual available from IFI.
21 *
22 * - 206 = full "forward"
23 * - 131 = the "high end" of the deadband range
24 * - 128 = center of the deadband range (off)
25 * - 125 = the "low end" of the deadband range
26 * - 56 = full "reverse"
27 */
28void Victor::InitVictor() {
29 // TODO: compute the appropriate values based on digital loop timing
30 SetBounds(206, 131, 128, 125, 56);
31 SetPeriodMultiplier(kPeriodMultiplier_2X);
32 SetRaw(m_centerPwm);
33
34 LiveWindow::GetInstance()->AddActuator("Victor", GetModuleNumber(), GetChannel(), this);
35 nUsageReporting::report(nUsageReporting::kResourceType_Victor, GetChannel(), GetModuleNumber() - 1);
36}
37
38/**
39 * Constructor that assumes the default digital module.
40 *
41 * @param channel The PWM channel on the digital module that the Victor is attached to.
42 */
43Victor::Victor(UINT32 channel) : SafePWM(channel)
44{
45 InitVictor();
46}
47
48/**
49 * Constructor that specifies the digital module.
50 *
51 * @param moduleNumber The digital module (1 or 2).
52 * @param channel The PWM channel on the digital module that the Victor is attached to (1..10).
53 */
54Victor::Victor(UINT8 moduleNumber, UINT32 channel) : SafePWM(moduleNumber, channel)
55{
56 InitVictor();
57}
58
59Victor::~Victor()
60{
61}
62
63/**
64 * Set the PWM value.
65 *
66 * The PWM value is set using a range of -1.0 to 1.0, appropriately
67 * scaling the value for the FPGA.
68 *
69 * @param speed The speed value between -1.0 and 1.0 to set.
70 * @param syncGroup Unused interface.
71 */
72void Victor::Set(float speed, UINT8 syncGroup)
73{
74 SetSpeed(speed);
75}
76
77/**
78 * Get the recently set value of the PWM.
79 *
80 * @return The most recently set value for the PWM between -1.0 and 1.0.
81 */
82float Victor::Get()
83{
84 return GetSpeed();
85}
86
87/**
88 * Common interface for disabling a motor.
89 */
90void Victor::Disable()
91{
92 SetRaw(kPwmDisabled);
93}
94
95/**
96 * Write out the PID value as seen in the PIDOutput base object.
97 *
98 * @param output Write out the PWM value as was found in the PIDController
99 */
100void Victor::PIDWrite(float output)
101{
102 Set(output);
103}
104