blob: b2bd57aacb82a6ff953a9caa7f4136d4ca1a79ae [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 "Jaguar.h"
9#include "LiveWindow/LiveWindow.h"
10
11/**
12 * Constructor for a Jaguar connected via PWM
13 * @param channel The PWM channel that the Jaguar is attached to. 0-9 are
14 * on-board, 10-19 are on the MXP port
15 */
16Jaguar::Jaguar(uint32_t channel) : SafePWM(channel) {
17 /**
18 * Input profile defined by Luminary Micro.
19 *
20 * Full reverse ranges from 0.671325ms to 0.6972211ms
21 * Proportional reverse ranges from 0.6972211ms to 1.4482078ms
22 * Neutral ranges from 1.4482078ms to 1.5517922ms
23 * Proportional forward ranges from 1.5517922ms to 2.3027789ms
24 * Full forward ranges from 2.3027789ms to 2.328675ms
25 */
26 SetBounds(2.31, 1.55, 1.507, 1.454, .697);
27 SetPeriodMultiplier(kPeriodMultiplier_1X);
28 SetRaw(m_centerPwm);
29 SetZeroLatch();
30
31 HALReport(HALUsageReporting::kResourceType_Jaguar, GetChannel());
32 LiveWindow::GetInstance()->AddActuator("Jaguar", GetChannel(), this);
33}
34
35/**
36 * Set the PWM value.
37 *
38 * The PWM value is set using a range of -1.0 to 1.0, appropriately
39 * scaling the value for the FPGA.
40 *
41 * @param speed The speed value between -1.0 and 1.0 to set.
42 * @param syncGroup Unused interface.
43 */
44void Jaguar::Set(float speed, uint8_t syncGroup) {
45 SetSpeed(m_isInverted ? -speed : speed);
46}
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 */
53float Jaguar::Get() const { return GetSpeed(); }
54
55/**
56 * Common interface for disabling a motor.
57 */
58void Jaguar::Disable() { SetRaw(kPwmDisabled); }
59
60/**
61* Common interface for inverting direction of a speed controller.
62* @param isInverted The state of inversion, true is inverted.
63*/
64void Jaguar::SetInverted(bool isInverted) { m_isInverted = isInverted; }
65
66/**
67 * Common interface for the inverting direction of a speed controller.
68 *
69 * @return isInverted The state of inversion, true is inverted.
70 *
71 */
72bool Jaguar::GetInverted() const { return m_isInverted; }
73
74/**
75 * Write out the PID value as seen in the PIDOutput base object.
76 *
77 * @param output Write out the PWM value as was found in the PIDController
78 */
79void Jaguar::PIDWrite(float output) { Set(output); }
Brian Silverman1a675112016-02-20 20:42:49 -050080
81/**
82 * Common interface to stop the motor until Set is called again.
83 */
84void Jaguar::StopMotor() { this->SafePWM::StopMotor(); }