2014-12-05 09:19:27 -08:00
|
|
|
/*----------------------------------------------------------------------------*/
|
2015-06-25 15:07:55 -04:00
|
|
|
/* Copyright (c) FIRST 2008. All Rights Reserved.
|
|
|
|
|
*/
|
2014-12-05 09:19:27 -08:00
|
|
|
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
|
|
|
|
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
#include "VictorSP.h"
|
|
|
|
|
|
2014-12-12 18:01:24 -05:00
|
|
|
//#include "NetworkCommunication/UsageReporting.h"
|
|
|
|
|
#include "LiveWindow/LiveWindow.h"
|
2014-12-05 09:19:27 -08:00
|
|
|
|
2014-12-12 18:01:24 -05:00
|
|
|
/**
|
2015-06-25 15:07:55 -04:00
|
|
|
* Note that the VictorSP uses the following bounds for PWM values. These values
|
|
|
|
|
* should work reasonably well for
|
|
|
|
|
* most controllers, but if users experience issues such as asymmetric behavior
|
|
|
|
|
* around
|
|
|
|
|
* the deadband or inability to saturate the controller in either direction,
|
|
|
|
|
* calibration is recommended.
|
|
|
|
|
* The calibration procedure can be found in the VictorSP User Manual available
|
|
|
|
|
* from Vex.
|
2014-12-12 18:01:24 -05:00
|
|
|
*
|
2014-12-29 14:09:37 -05:00
|
|
|
* 2.004ms = full "forward"
|
|
|
|
|
* 1.52ms = the "high end" of the deadband range
|
|
|
|
|
* 1.50ms = center of the deadband range (off)
|
|
|
|
|
* 1.48ms = the "low end" of the deadband range
|
|
|
|
|
* 0.997ms = full "reverse"
|
2014-12-12 18:01:24 -05:00
|
|
|
*/
|
2015-06-29 02:43:44 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Constructor for a VictorSP
|
|
|
|
|
* @param channel The PWM channel that the VictorSP is attached to. 0-9 are
|
|
|
|
|
* on-board, 10-19 are on the MXP port
|
|
|
|
|
*/
|
|
|
|
|
VictorSP::VictorSP(uint32_t channel) : SafePWM(channel) {
|
2015-06-25 15:07:55 -04:00
|
|
|
SetBounds(2.004, 1.52, 1.50, 1.48, .997);
|
|
|
|
|
SetPeriodMultiplier(kPeriodMultiplier_1X);
|
|
|
|
|
SetRaw(m_centerPwm);
|
|
|
|
|
SetZeroLatch();
|
2014-12-12 18:01:24 -05:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
HALReport(HALUsageReporting::kResourceType_VictorSP, GetChannel());
|
artf4154: Get rid of raw pointers in C++.
This deals with the majority of the user-facing code
in wpilibC++Devices and a substantial portion of it in
wpilibC++. wpilibC++Sim and wpilibC++IntegrationTests
are untouched except where it is necessary to make them
work with the rest of the libraries.
There is still a lot to do in the following areas:
-The HAL (which we may not want to touch at all).
-The I2C, Serial, and SPI interfaces in wpilibC++Devices,
which I haven't gotten around to doing yet.
-Most wpilibC++Devices classes have void* pointers
for interacting with the HAL.
-InterruptableSensorBase passes a void *params for
the interrupt handler.
-I haven't converted all the const char* to std::strings.
-There are plenty of other cases of raw pointers still
existing.
-This doesn't fall directly under raw pointer stuff,
but move syntax and rvalue references could be introduced
in many places.
-I haven't touched vision code.
-The Resource classes conflict (one is in the hal, the other
in wpilibC++). Someone should figure out a more
permanent fix (eg, just renaming them), then doing
what I did (making a new namespace for one of them,
essentially the same as renaming it).
A few other things:
-I created a NullDeleter class which is marked as deprecated.
What this does is it can be passed as the deleter to a
std::shared_ptr so that when you are converting raw pointers
to shared_ptrs the shared_ptr doesn't do any deletion if
someone else owns the raw pointer. This should only be
used in making old raw pointer UIs.
-I had to alter the build.gradle so that it did not
emit errors when deprecated functions called deprecated
functions. Unfortunately, gradle doesn't appear to be
actually printing out gcc warnigns for some reason.
The best way I have found to fix this is to patch
the toolchains (https://bitbucket.org/byteit101/toolchain-builder/pull-request/5/make-gcc-not-throw-warnings-for-nested/diff)
so that a deprecated function calling a deprecated
function is fine but a non-deprecated function calling
a deprecated function will throw a warning (which we
then elevate with -Werror). I believe that clang
deals with this properly, although I have not
tried it myself.
Change-Id: Ib8090c66893576fe73654f4e9d268f9d37be06a2
2015-06-30 15:01:20 -04:00
|
|
|
LiveWindow::GetInstance().AddActuator("VictorSP", GetChannel(), this);
|
2014-12-12 18:01:24 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set the PWM value.
|
|
|
|
|
*
|
|
|
|
|
* The PWM value is set using a range of -1.0 to 1.0, appropriately
|
|
|
|
|
* scaling the value for the FPGA.
|
|
|
|
|
*
|
|
|
|
|
* @param speed The speed value between -1.0 and 1.0 to set.
|
|
|
|
|
* @param syncGroup Unused interface.
|
|
|
|
|
*/
|
2015-06-25 15:07:55 -04:00
|
|
|
void VictorSP::Set(float speed, uint8_t syncGroup) {
|
|
|
|
|
SetSpeed(m_isInverted ? -speed : speed);
|
2014-12-05 09:19:27 -08:00
|
|
|
}
|
|
|
|
|
|
2014-12-12 18:01:24 -05:00
|
|
|
/**
|
|
|
|
|
* Get the recently set value of the PWM.
|
|
|
|
|
*
|
|
|
|
|
* @return The most recently set value for the PWM between -1.0 and 1.0.
|
|
|
|
|
*/
|
2015-06-25 15:07:55 -04:00
|
|
|
float VictorSP::Get() const { return GetSpeed(); }
|
2015-06-15 15:32:47 -04:00
|
|
|
|
2015-03-24 15:01:17 -04:00
|
|
|
/**
|
2015-06-15 15:32:47 -04:00
|
|
|
* Common interface for inverting direction of a speed controller.
|
|
|
|
|
* @param isInverted The state of inversion, true is inverted.
|
|
|
|
|
*/
|
2015-06-25 15:07:55 -04:00
|
|
|
void VictorSP::SetInverted(bool isInverted) { m_isInverted = isInverted; }
|
2015-06-15 15:32:47 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Common interface for the inverting direction of a speed controller.
|
|
|
|
|
*
|
|
|
|
|
* @return isInverted The state of inversion, true is inverted.
|
|
|
|
|
*
|
|
|
|
|
*/
|
2015-06-25 15:07:55 -04:00
|
|
|
bool VictorSP::GetInverted() const { return m_isInverted; }
|
2015-06-15 15:32:47 -04:00
|
|
|
|
2014-12-12 18:01:24 -05:00
|
|
|
/**
|
|
|
|
|
* Common interface for disabling a motor.
|
|
|
|
|
*/
|
2015-06-25 15:07:55 -04:00
|
|
|
void VictorSP::Disable() { SetRaw(kPwmDisabled); }
|
2014-12-12 18:01:24 -05:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Write out the PID value as seen in the PIDOutput base object.
|
|
|
|
|
*
|
|
|
|
|
* @param output Write out the PWM value as was found in the PIDController
|
|
|
|
|
*/
|
2015-06-25 15:07:55 -04:00
|
|
|
void VictorSP::PIDWrite(float output) { Set(output); }
|