2013-12-15 18:30:16 -05:00
|
|
|
/*----------------------------------------------------------------------------*/
|
2017-08-23 22:06:13 -07:00
|
|
|
/* Copyright (c) 2008-2017 FIRST. All Rights Reserved. */
|
2013-12-15 18:30:16 -05:00
|
|
|
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
2016-01-02 03:02:34 -08:00
|
|
|
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
|
|
|
|
/* the project. */
|
2013-12-15 18:30:16 -05:00
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
#include "Encoder.h"
|
2016-09-25 16:50:13 -07:00
|
|
|
|
2017-08-27 00:11:52 -07:00
|
|
|
#include <HAL/HAL.h>
|
|
|
|
|
|
2013-12-15 18:30:16 -05:00
|
|
|
#include "DigitalInput.h"
|
2016-05-20 17:30:37 -07:00
|
|
|
#include "LiveWindow/LiveWindow.h"
|
2013-12-15 18:30:16 -05:00
|
|
|
#include "WPIErrors.h"
|
|
|
|
|
|
2016-11-01 22:33:12 -07:00
|
|
|
using namespace frc;
|
|
|
|
|
|
2013-12-15 18:30:16 -05:00
|
|
|
/**
|
|
|
|
|
* Common initialization code for Encoders.
|
2016-05-20 17:30:37 -07:00
|
|
|
*
|
2013-12-15 18:30:16 -05:00
|
|
|
* This code allocates resources for Encoders and is common to all constructors.
|
2014-07-29 09:58:15 -07:00
|
|
|
*
|
|
|
|
|
* The counter will start counting immediately.
|
|
|
|
|
*
|
2015-06-25 15:07:55 -04:00
|
|
|
* @param reverseDirection If true, counts down instead of up (this is all
|
2016-05-20 17:30:37 -07:00
|
|
|
* relative)
|
|
|
|
|
* @param encodingType either k1X, k2X, or k4X to indicate 1X, 2X or 4X
|
|
|
|
|
* decoding. If 4X is selected, then an encoder FPGA
|
|
|
|
|
* object is used and the returned counts will be 4x
|
|
|
|
|
* the encoder spec'd value since all rising and
|
|
|
|
|
* falling edges are counted. If 1X or 2X are selected
|
|
|
|
|
* then a counter object will be used and the returned
|
|
|
|
|
* value will either exactly match the spec'd count or
|
|
|
|
|
* be double (2x) the spec'd count.
|
2013-12-15 18:30:16 -05:00
|
|
|
*/
|
2015-06-25 15:07:55 -04:00
|
|
|
void Encoder::InitEncoder(bool reverseDirection, EncodingType encodingType) {
|
2016-07-03 15:22:22 -07:00
|
|
|
int32_t status = 0;
|
2016-07-09 00:24:26 -07:00
|
|
|
m_encoder = HAL_InitializeEncoder(
|
|
|
|
|
m_aSource->GetPortHandleForRouting(),
|
|
|
|
|
(HAL_AnalogTriggerType)m_aSource->GetAnalogTriggerTypeForRouting(),
|
|
|
|
|
m_bSource->GetPortHandleForRouting(),
|
|
|
|
|
(HAL_AnalogTriggerType)m_bSource->GetAnalogTriggerTypeForRouting(),
|
|
|
|
|
reverseDirection, (HAL_EncoderEncodingType)encodingType, &status);
|
|
|
|
|
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
|
|
|
|
|
|
|
|
|
|
HAL_Report(HALUsageReporting::kResourceType_Encoder, GetFPGAIndex(),
|
|
|
|
|
encodingType);
|
2016-07-07 21:43:55 -07:00
|
|
|
LiveWindow::GetInstance()->AddSensor("Encoder", m_aSource->GetChannel(),
|
|
|
|
|
this);
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Encoder constructor.
|
2016-05-20 17:30:37 -07:00
|
|
|
*
|
2014-06-13 17:45:10 -04:00
|
|
|
* Construct a Encoder given a and b channels.
|
2014-07-29 09:58:15 -07:00
|
|
|
*
|
|
|
|
|
* The counter will start counting immediately.
|
|
|
|
|
*
|
2016-05-20 17:30:37 -07:00
|
|
|
* @param aChannel The a channel DIO channel. 0-9 are on-board, 10-25
|
|
|
|
|
* are on the MXP port
|
|
|
|
|
* @param bChannel The b channel DIO channel. 0-9 are on-board, 10-25
|
|
|
|
|
* are on the MXP port
|
|
|
|
|
* @param reverseDirection represents the orientation of the encoder and
|
|
|
|
|
* inverts the output values if necessary so forward
|
|
|
|
|
* represents positive values.
|
|
|
|
|
* @param encodingType either k1X, k2X, or k4X to indicate 1X, 2X or 4X
|
|
|
|
|
* decoding. If 4X is selected, then an encoder FPGA
|
|
|
|
|
* object is used and the returned counts will be 4x
|
|
|
|
|
* the encoder spec'd value since all rising and
|
|
|
|
|
* falling edges are counted. If 1X or 2X are selected
|
|
|
|
|
* then a counter object will be used and the returned
|
|
|
|
|
* value will either exactly match the spec'd count or
|
|
|
|
|
* be double (2x) the spec'd count.
|
2013-12-15 18:30:16 -05:00
|
|
|
*/
|
2016-09-06 00:01:45 -07:00
|
|
|
Encoder::Encoder(int aChannel, int bChannel, bool reverseDirection,
|
2015-06-24 01:06:29 -07:00
|
|
|
EncodingType encodingType) {
|
2015-07-29 16:48:04 -04:00
|
|
|
m_aSource = std::make_shared<DigitalInput>(aChannel);
|
|
|
|
|
m_bSource = std::make_shared<DigitalInput>(bChannel);
|
2015-06-25 15:07:55 -04:00
|
|
|
InitEncoder(reverseDirection, encodingType);
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Encoder constructor.
|
2016-05-20 17:30:37 -07:00
|
|
|
*
|
2015-06-25 15:07:55 -04:00
|
|
|
* Construct a Encoder given a and b channels as digital inputs. This is used in
|
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
|
|
|
* the case where the digital inputs are shared. The Encoder class will not
|
|
|
|
|
* allocate the digital inputs and assume that they already are counted.
|
2016-05-20 17:30:37 -07:00
|
|
|
*
|
2014-07-29 09:58:15 -07:00
|
|
|
* The counter will start counting immediately.
|
|
|
|
|
*
|
2016-05-20 17:30:37 -07:00
|
|
|
* @param aSource The source that should be used for the a channel.
|
|
|
|
|
* @param bSource the source that should be used for the b channel.
|
|
|
|
|
* @param reverseDirection represents the orientation of the encoder and
|
|
|
|
|
* inverts the output values if necessary so forward
|
|
|
|
|
* represents positive values.
|
|
|
|
|
* @param encodingType either k1X, k2X, or k4X to indicate 1X, 2X or 4X
|
|
|
|
|
* decoding. If 4X is selected, then an encoder FPGA
|
|
|
|
|
* object is used and the returned counts will be 4x
|
|
|
|
|
* the encoder spec'd value since all rising and
|
|
|
|
|
* falling edges are counted. If 1X or 2X are selected
|
|
|
|
|
* then a counter object will be used and the returned
|
|
|
|
|
* value will either exactly match the spec'd count or
|
|
|
|
|
* be double (2x) the spec'd count.
|
2013-12-15 18:30:16 -05:00
|
|
|
*/
|
2016-05-20 17:30:37 -07:00
|
|
|
Encoder::Encoder(DigitalSource* aSource, DigitalSource* bSource,
|
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
|
|
|
bool reverseDirection, EncodingType encodingType)
|
|
|
|
|
: m_aSource(aSource, NullDeleter<DigitalSource>()),
|
|
|
|
|
m_bSource(bSource, NullDeleter<DigitalSource>()) {
|
|
|
|
|
if (m_aSource == nullptr || m_bSource == nullptr)
|
|
|
|
|
wpi_setWPIError(NullParameter);
|
|
|
|
|
else
|
|
|
|
|
InitEncoder(reverseDirection, encodingType);
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-29 16:48:04 -04:00
|
|
|
Encoder::Encoder(std::shared_ptr<DigitalSource> aSource,
|
2016-05-20 17:30:37 -07:00
|
|
|
std::shared_ptr<DigitalSource> bSource, bool reverseDirection,
|
|
|
|
|
EncodingType encodingType)
|
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
|
|
|
: m_aSource(aSource), m_bSource(bSource) {
|
2015-06-23 04:49:51 -07:00
|
|
|
if (m_aSource == nullptr || m_bSource == nullptr)
|
2015-06-25 15:07:55 -04:00
|
|
|
wpi_setWPIError(NullParameter);
|
|
|
|
|
else
|
|
|
|
|
InitEncoder(reverseDirection, encodingType);
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Encoder constructor.
|
2016-05-20 17:30:37 -07:00
|
|
|
*
|
2015-06-25 15:07:55 -04:00
|
|
|
* Construct a Encoder given a and b channels as digital inputs. This is used in
|
2016-05-20 17:30:37 -07:00
|
|
|
* the case where the digital inputs are shared. The Encoder class will not
|
|
|
|
|
* allocate the digital inputs and assume that they already are counted.
|
2014-07-29 09:58:15 -07:00
|
|
|
*
|
|
|
|
|
* The counter will start counting immediately.
|
|
|
|
|
*
|
2016-05-20 17:30:37 -07:00
|
|
|
* @param aSource The source that should be used for the a channel.
|
|
|
|
|
* @param bSource the source that should be used for the b channel.
|
|
|
|
|
* @param reverseDirection represents the orientation of the encoder and
|
|
|
|
|
* inverts the output values if necessary so forward
|
|
|
|
|
* represents positive values.
|
|
|
|
|
* @param encodingType either k1X, k2X, or k4X to indicate 1X, 2X or 4X
|
|
|
|
|
* decoding. If 4X is selected, then an encoder FPGA
|
|
|
|
|
* object is used and the returned counts will be 4x
|
|
|
|
|
* the encoder spec'd value since all rising and
|
|
|
|
|
* falling edges are counted. If 1X or 2X are selected
|
|
|
|
|
* then a counter object will be used and the returned
|
|
|
|
|
* value will either exactly match the spec'd count or
|
|
|
|
|
* be double (2x) the spec'd count.
|
2013-12-15 18:30:16 -05:00
|
|
|
*/
|
2016-05-20 17:30:37 -07:00
|
|
|
Encoder::Encoder(DigitalSource& aSource, DigitalSource& bSource,
|
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
|
|
|
bool reverseDirection, EncodingType encodingType)
|
|
|
|
|
: m_aSource(&aSource, NullDeleter<DigitalSource>()),
|
2016-05-20 17:30:37 -07:00
|
|
|
m_bSource(&bSource, NullDeleter<DigitalSource>()) {
|
2015-06-25 15:07:55 -04:00
|
|
|
InitEncoder(reverseDirection, encodingType);
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Free the resources for an Encoder.
|
2016-05-20 17:30:37 -07:00
|
|
|
*
|
2013-12-15 18:30:16 -05:00
|
|
|
* Frees the FPGA resources associated with an Encoder.
|
|
|
|
|
*/
|
2015-06-25 15:07:55 -04:00
|
|
|
Encoder::~Encoder() {
|
2016-07-03 15:22:22 -07:00
|
|
|
int32_t status = 0;
|
2016-07-09 00:24:26 -07:00
|
|
|
HAL_FreeEncoder(m_encoder, &status);
|
|
|
|
|
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
2014-12-30 17:36:12 -05:00
|
|
|
/**
|
|
|
|
|
* The encoding scale factor 1x, 2x, or 4x, per the requested encodingType.
|
2016-05-20 17:30:37 -07:00
|
|
|
*
|
2014-12-30 17:36:12 -05:00
|
|
|
* Used to divide raw edge counts down to spec'd counts.
|
|
|
|
|
*/
|
2016-09-06 00:01:45 -07:00
|
|
|
int Encoder::GetEncodingScale() const {
|
2016-07-03 15:22:22 -07:00
|
|
|
int32_t status = 0;
|
2016-09-06 00:01:45 -07:00
|
|
|
int val = HAL_GetEncoderEncodingScale(m_encoder, &status);
|
2016-07-09 00:24:26 -07:00
|
|
|
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
|
2016-07-03 15:22:22 -07:00
|
|
|
return val;
|
|
|
|
|
}
|
2014-12-30 17:36:12 -05:00
|
|
|
|
2013-12-15 18:30:16 -05:00
|
|
|
/**
|
|
|
|
|
* Gets the raw value from the encoder.
|
2016-05-20 17:30:37 -07:00
|
|
|
*
|
2013-12-15 18:30:16 -05:00
|
|
|
* The raw value is the actual count unscaled by the 1x, 2x, or 4x scale
|
|
|
|
|
* factor.
|
2016-05-20 17:30:37 -07:00
|
|
|
*
|
2013-12-15 18:30:16 -05:00
|
|
|
* @return Current raw count from the encoder
|
|
|
|
|
*/
|
2016-09-06 00:01:45 -07:00
|
|
|
int Encoder::GetRaw() const {
|
2015-06-25 15:07:55 -04:00
|
|
|
if (StatusIsFatal()) return 0;
|
2016-07-03 15:22:22 -07:00
|
|
|
int32_t status = 0;
|
2016-09-06 00:01:45 -07:00
|
|
|
int value = HAL_GetEncoderRaw(m_encoder, &status);
|
2016-07-09 00:24:26 -07:00
|
|
|
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
|
2015-06-25 15:07:55 -04:00
|
|
|
return value;
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Gets the current count.
|
2016-05-20 17:30:37 -07:00
|
|
|
*
|
|
|
|
|
* Returns the current count on the Encoder. This method compensates for the
|
|
|
|
|
* decoding type.
|
2014-06-13 17:45:10 -04:00
|
|
|
*
|
2015-06-25 15:07:55 -04:00
|
|
|
* @return Current count from the Encoder adjusted for the 1x, 2x, or 4x scale
|
2016-05-20 17:30:37 -07:00
|
|
|
* factor.
|
2013-12-15 18:30:16 -05:00
|
|
|
*/
|
2016-09-06 00:01:45 -07:00
|
|
|
int Encoder::Get() const {
|
2015-06-25 15:07:55 -04:00
|
|
|
if (StatusIsFatal()) return 0;
|
2016-07-03 15:22:22 -07:00
|
|
|
int32_t status = 0;
|
2016-09-06 00:01:45 -07:00
|
|
|
int value = HAL_GetEncoder(m_encoder, &status);
|
2016-07-09 00:24:26 -07:00
|
|
|
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
|
2016-07-03 15:22:22 -07:00
|
|
|
return value;
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Reset the Encoder distance to zero.
|
2016-05-20 17:30:37 -07:00
|
|
|
*
|
2013-12-15 18:30:16 -05:00
|
|
|
* Resets the current count to zero on the encoder.
|
|
|
|
|
*/
|
2015-06-25 15:07:55 -04:00
|
|
|
void Encoder::Reset() {
|
|
|
|
|
if (StatusIsFatal()) return;
|
2016-07-03 15:22:22 -07:00
|
|
|
int32_t status = 0;
|
2016-07-09 00:24:26 -07:00
|
|
|
HAL_ResetEncoder(m_encoder, &status);
|
|
|
|
|
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the period of the most recent pulse.
|
2016-05-20 17:30:37 -07:00
|
|
|
*
|
2017-07-01 01:05:33 -04:00
|
|
|
* Returns the period of the most recent Encoder pulse in seconds. This method
|
|
|
|
|
* compensates for the decoding type.
|
2014-06-13 17:45:10 -04:00
|
|
|
*
|
2017-07-01 01:05:33 -04:00
|
|
|
* Warning: This returns unscaled periods. Use GetRate() for rates that are
|
|
|
|
|
* scaled using the value from SetDistancePerPulse().
|
2013-12-15 18:30:16 -05:00
|
|
|
*
|
|
|
|
|
* @return Period in seconds of the most recent pulse.
|
|
|
|
|
*/
|
2015-06-25 15:07:55 -04:00
|
|
|
double Encoder::GetPeriod() const {
|
|
|
|
|
if (StatusIsFatal()) return 0.0;
|
2016-07-03 15:22:22 -07:00
|
|
|
int32_t status = 0;
|
2016-07-09 00:24:26 -07:00
|
|
|
double value = HAL_GetEncoderPeriod(m_encoder, &status);
|
|
|
|
|
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
|
2016-07-03 15:22:22 -07:00
|
|
|
return value;
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Sets the maximum period for stopped detection.
|
2016-05-20 17:30:37 -07:00
|
|
|
*
|
2015-06-25 15:07:55 -04:00
|
|
|
* Sets the value that represents the maximum period of the Encoder before it
|
2016-05-20 17:30:37 -07:00
|
|
|
* will assume that the attached device is stopped. This timeout allows users
|
|
|
|
|
* to determine if the wheels or other shaft has stopped rotating.
|
2013-12-15 18:30:16 -05:00
|
|
|
* This method compensates for the decoding type.
|
2014-06-13 17:45:10 -04:00
|
|
|
*
|
2015-06-25 15:07:55 -04:00
|
|
|
* @deprecated Use SetMinRate() in favor of this method. This takes unscaled
|
2016-05-20 17:30:37 -07:00
|
|
|
* periods and SetMinRate() scales using value from
|
|
|
|
|
* SetDistancePerPulse().
|
2014-06-13 17:45:10 -04:00
|
|
|
*
|
2016-05-20 17:30:37 -07:00
|
|
|
* @param maxPeriod The maximum time between rising and falling edges before
|
|
|
|
|
* the FPGA will report the device stopped. This is expressed
|
|
|
|
|
* in seconds.
|
2013-12-15 18:30:16 -05:00
|
|
|
*/
|
2015-06-25 15:07:55 -04:00
|
|
|
void Encoder::SetMaxPeriod(double maxPeriod) {
|
|
|
|
|
if (StatusIsFatal()) return;
|
2016-07-03 15:22:22 -07:00
|
|
|
int32_t status = 0;
|
2016-07-09 00:24:26 -07:00
|
|
|
HAL_SetEncoderMaxPeriod(m_encoder, maxPeriod, &status);
|
|
|
|
|
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Determine if the encoder is stopped.
|
2016-05-20 17:30:37 -07:00
|
|
|
*
|
2015-06-25 15:07:55 -04:00
|
|
|
* Using the MaxPeriod value, a boolean is returned that is true if the encoder
|
2016-05-20 17:30:37 -07:00
|
|
|
* is considered stopped and false if it is still moving. A stopped encoder is
|
|
|
|
|
* one where the most recent pulse width exceeds the MaxPeriod.
|
|
|
|
|
*
|
2013-12-15 18:30:16 -05:00
|
|
|
* @return True if the encoder is considered stopped.
|
|
|
|
|
*/
|
2015-06-25 15:07:55 -04:00
|
|
|
bool Encoder::GetStopped() const {
|
|
|
|
|
if (StatusIsFatal()) return true;
|
2016-07-03 15:22:22 -07:00
|
|
|
int32_t status = 0;
|
2016-07-09 00:24:26 -07:00
|
|
|
bool value = HAL_GetEncoderStopped(m_encoder, &status);
|
|
|
|
|
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
|
2016-07-03 15:22:22 -07:00
|
|
|
return value;
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The last direction the encoder value changed.
|
2016-05-20 17:30:37 -07:00
|
|
|
*
|
2013-12-15 18:30:16 -05:00
|
|
|
* @return The last direction the encoder value changed.
|
|
|
|
|
*/
|
2015-06-25 15:07:55 -04:00
|
|
|
bool Encoder::GetDirection() const {
|
|
|
|
|
if (StatusIsFatal()) return false;
|
2016-07-03 15:22:22 -07:00
|
|
|
int32_t status = 0;
|
2016-07-09 00:24:26 -07:00
|
|
|
bool value = HAL_GetEncoderDirection(m_encoder, &status);
|
|
|
|
|
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
|
2016-07-03 15:22:22 -07:00
|
|
|
return value;
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2015-06-25 15:07:55 -04:00
|
|
|
* The scale needed to convert a raw counter value into a number of encoder
|
|
|
|
|
* pulses.
|
2013-12-15 18:30:16 -05:00
|
|
|
*/
|
2016-11-20 07:25:03 -08:00
|
|
|
double Encoder::DecodingScaleFactor() const {
|
2015-06-25 15:07:55 -04:00
|
|
|
if (StatusIsFatal()) return 0.0;
|
2016-07-03 15:22:22 -07:00
|
|
|
int32_t status = 0;
|
2016-11-20 07:25:03 -08:00
|
|
|
double val = HAL_GetEncoderDecodingScaleFactor(m_encoder, &status);
|
2016-07-09 00:24:26 -07:00
|
|
|
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
|
2016-07-03 15:22:22 -07:00
|
|
|
return val;
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the distance the robot has driven since the last reset.
|
2014-06-13 17:45:10 -04:00
|
|
|
*
|
2015-06-25 15:07:55 -04:00
|
|
|
* @return The distance driven since the last reset as scaled by the value from
|
2016-05-20 17:30:37 -07:00
|
|
|
* SetDistancePerPulse().
|
2013-12-15 18:30:16 -05:00
|
|
|
*/
|
2016-11-20 07:25:03 -08:00
|
|
|
double Encoder::GetDistance() const {
|
2015-06-25 15:07:55 -04:00
|
|
|
if (StatusIsFatal()) return 0.0;
|
2016-07-03 15:22:22 -07:00
|
|
|
int32_t status = 0;
|
2016-11-20 07:25:03 -08:00
|
|
|
double value = HAL_GetEncoderDistance(m_encoder, &status);
|
2016-07-09 00:24:26 -07:00
|
|
|
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
|
2016-07-03 15:22:22 -07:00
|
|
|
return value;
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the current rate of the encoder.
|
2016-05-20 17:30:37 -07:00
|
|
|
*
|
2015-06-25 15:07:55 -04:00
|
|
|
* Units are distance per second as scaled by the value from
|
|
|
|
|
* SetDistancePerPulse().
|
2014-06-13 17:45:10 -04:00
|
|
|
*
|
2013-12-15 18:30:16 -05:00
|
|
|
* @return The current rate of the encoder.
|
|
|
|
|
*/
|
2016-11-20 07:25:03 -08:00
|
|
|
double Encoder::GetRate() const {
|
2015-06-25 15:07:55 -04:00
|
|
|
if (StatusIsFatal()) return 0.0;
|
2016-07-03 15:22:22 -07:00
|
|
|
int32_t status = 0;
|
2016-11-20 07:25:03 -08:00
|
|
|
double value = HAL_GetEncoderRate(m_encoder, &status);
|
2016-07-09 00:24:26 -07:00
|
|
|
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
|
2016-07-03 15:22:22 -07:00
|
|
|
return value;
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set the minimum rate of the device before the hardware reports it stopped.
|
2014-06-13 17:45:10 -04:00
|
|
|
*
|
2015-06-25 15:07:55 -04:00
|
|
|
* @param minRate The minimum rate. The units are in distance per second as
|
2016-05-20 17:30:37 -07:00
|
|
|
* scaled by the value from SetDistancePerPulse().
|
2013-12-15 18:30:16 -05:00
|
|
|
*/
|
2016-11-20 07:25:03 -08:00
|
|
|
void Encoder::SetMinRate(double minRate) {
|
2015-06-25 15:07:55 -04:00
|
|
|
if (StatusIsFatal()) return;
|
2016-07-03 15:22:22 -07:00
|
|
|
int32_t status = 0;
|
2016-07-09 00:24:26 -07:00
|
|
|
HAL_SetEncoderMinRate(m_encoder, minRate, &status);
|
|
|
|
|
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set the distance per pulse for this encoder.
|
2016-05-20 17:30:37 -07:00
|
|
|
*
|
2015-06-25 15:07:55 -04:00
|
|
|
* This sets the multiplier used to determine the distance driven based on the
|
2016-05-20 17:30:37 -07:00
|
|
|
* count value from the encoder.
|
|
|
|
|
*
|
2015-06-25 15:07:55 -04:00
|
|
|
* Do not include the decoding type in this scale. The library already
|
|
|
|
|
* compensates for the decoding type.
|
2016-05-20 17:30:37 -07:00
|
|
|
*
|
2013-12-15 18:30:16 -05:00
|
|
|
* Set this value based on the encoder's rated Pulses per Revolution and
|
|
|
|
|
* factor in gearing reductions following the encoder shaft.
|
2016-05-20 17:30:37 -07:00
|
|
|
*
|
2013-12-15 18:30:16 -05:00
|
|
|
* This distance can be in any units you like, linear or angular.
|
2014-06-13 17:45:10 -04:00
|
|
|
*
|
2015-06-25 15:07:55 -04:00
|
|
|
* @param distancePerPulse The scale factor that will be used to convert pulses
|
2016-05-20 17:30:37 -07:00
|
|
|
* to useful units.
|
2013-12-15 18:30:16 -05:00
|
|
|
*/
|
2016-11-20 07:25:03 -08:00
|
|
|
void Encoder::SetDistancePerPulse(double distancePerPulse) {
|
2015-06-25 15:07:55 -04:00
|
|
|
if (StatusIsFatal()) return;
|
2016-07-03 15:22:22 -07:00
|
|
|
int32_t status = 0;
|
2016-07-09 00:24:26 -07:00
|
|
|
HAL_SetEncoderDistancePerPulse(m_encoder, distancePerPulse, &status);
|
|
|
|
|
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set the direction sensing for this encoder.
|
2016-05-20 17:30:37 -07:00
|
|
|
*
|
2015-06-25 15:07:55 -04:00
|
|
|
* This sets the direction sensing on the encoder so that it could count in the
|
2016-05-20 17:30:37 -07:00
|
|
|
* correct software direction regardless of the mounting.
|
|
|
|
|
*
|
2013-12-15 18:30:16 -05:00
|
|
|
* @param reverseDirection true if the encoder direction should be reversed
|
|
|
|
|
*/
|
2015-06-25 15:07:55 -04:00
|
|
|
void Encoder::SetReverseDirection(bool reverseDirection) {
|
|
|
|
|
if (StatusIsFatal()) return;
|
2016-07-03 15:22:22 -07:00
|
|
|
int32_t status = 0;
|
2016-07-09 00:24:26 -07:00
|
|
|
HAL_SetEncoderReverseDirection(m_encoder, reverseDirection, &status);
|
|
|
|
|
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2015-06-25 15:07:55 -04:00
|
|
|
* Set the Samples to Average which specifies the number of samples of the timer
|
2016-05-20 17:30:37 -07:00
|
|
|
* to average when calculating the period.
|
|
|
|
|
*
|
|
|
|
|
* Perform averaging to account for mechanical imperfections or as oversampling
|
|
|
|
|
* to increase resolution.
|
|
|
|
|
*
|
2013-12-15 18:30:16 -05:00
|
|
|
* @param samplesToAverage The number of samples to average from 1 to 127.
|
|
|
|
|
*/
|
2015-06-25 15:07:55 -04:00
|
|
|
void Encoder::SetSamplesToAverage(int samplesToAverage) {
|
|
|
|
|
if (samplesToAverage < 1 || samplesToAverage > 127) {
|
|
|
|
|
wpi_setWPIErrorWithContext(
|
|
|
|
|
ParameterOutOfRange,
|
|
|
|
|
"Average counter values must be between 1 and 127");
|
2016-07-03 15:22:22 -07:00
|
|
|
return;
|
2015-06-25 15:07:55 -04:00
|
|
|
}
|
|
|
|
|
int32_t status = 0;
|
2016-07-09 00:24:26 -07:00
|
|
|
HAL_SetEncoderSamplesToAverage(m_encoder, samplesToAverage, &status);
|
|
|
|
|
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
2014-06-13 17:45:10 -04:00
|
|
|
|
2013-12-15 18:30:16 -05:00
|
|
|
/**
|
2015-06-25 15:07:55 -04:00
|
|
|
* Get the Samples to Average which specifies the number of samples of the timer
|
2016-05-20 17:30:37 -07:00
|
|
|
* to average when calculating the period.
|
|
|
|
|
*
|
|
|
|
|
* Perform averaging to account for mechanical imperfections or as oversampling
|
|
|
|
|
* to increase resolution.
|
|
|
|
|
*
|
|
|
|
|
* @return The number of samples being averaged (from 1 to 127)
|
2013-12-15 18:30:16 -05:00
|
|
|
*/
|
2015-06-25 15:07:55 -04:00
|
|
|
int Encoder::GetSamplesToAverage() const {
|
|
|
|
|
int32_t status = 0;
|
2016-07-09 00:24:26 -07:00
|
|
|
int result = HAL_GetEncoderSamplesToAverage(m_encoder, &status);
|
|
|
|
|
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
|
2015-06-25 15:07:55 -04:00
|
|
|
return result;
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Implement the PIDSource interface.
|
2014-06-13 17:45:10 -04:00
|
|
|
*
|
2013-12-15 18:30:16 -05:00
|
|
|
* @return The current value of the selected source parameter.
|
|
|
|
|
*/
|
Revert changes preventing old user code from compiling.
I'm not 100% sure whether we want these, but they are a quick
find and replace to do.
Basically, there are two primary things that we have done
this summer that break existing user code:
-Changing GetInstance() calls to return references instead
of pointers. This forces users to change from doing something
like LiveWindow::GetInstance()->AddSensor() to LiveWindow::GetInstance().AddSensor().
-Making PIDGet() and related calls const, forcing users to change
the function signatures wherever they override them.
The GetInstance() calls don't really matter to me either way,
especially since there are no real ownership issues going on there,
unlike the rest of the smart pointer-related changes.
For the const stuff, it is certainly more correct to mandate that
user PIDGet() functions be const and the such, but at the same time,
I'm not sure that there is any strong need for it, and the errors
generated are not the most helpful. While this wouldn't necessarily
be an issue for more experienced teams or completely new teams (who
don't have any old code to be reusing), it may cause issues for more
average teams who aren't familiar with the intricacies of C++ anything.
Change-Id: I6e7007982069292ea70e6d0fc8ca40203340df1b
2015-07-24 19:19:40 -04:00
|
|
|
double Encoder::PIDGet() {
|
2015-06-25 15:07:55 -04:00
|
|
|
if (StatusIsFatal()) return 0.0;
|
2015-07-14 20:37:52 -07:00
|
|
|
switch (GetPIDSourceType()) {
|
|
|
|
|
case PIDSourceType::kDisplacement:
|
2015-06-25 15:07:55 -04:00
|
|
|
return GetDistance();
|
2015-07-14 20:37:52 -07:00
|
|
|
case PIDSourceType::kRate:
|
2015-06-25 15:07:55 -04:00
|
|
|
return GetRate();
|
|
|
|
|
default:
|
|
|
|
|
return 0.0;
|
|
|
|
|
}
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
2015-01-06 16:39:24 -05:00
|
|
|
/**
|
2016-05-20 17:30:37 -07:00
|
|
|
* Set the index source for the encoder.
|
|
|
|
|
*
|
|
|
|
|
* When this source is activated, the encoder count automatically resets.
|
2015-01-06 16:39:24 -05:00
|
|
|
*
|
|
|
|
|
* @param channel A DIO channel to set as the encoder index
|
2016-05-20 17:30:37 -07:00
|
|
|
* @param type The state that will cause the encoder to reset
|
2015-01-06 16:39:24 -05:00
|
|
|
*/
|
2016-09-06 00:01:45 -07:00
|
|
|
void Encoder::SetIndexSource(int channel, Encoder::IndexingType type) {
|
2016-07-07 21:43:55 -07:00
|
|
|
// Force digital input if just given an index
|
|
|
|
|
m_indexSource = std::make_unique<DigitalInput>(channel);
|
2017-07-01 01:05:33 -04:00
|
|
|
SetIndexSource(*m_indexSource.get(), type);
|
2015-01-06 16:39:24 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2016-05-20 17:30:37 -07:00
|
|
|
* Set the index source for the encoder.
|
|
|
|
|
*
|
|
|
|
|
* When this source is activated, the encoder count automatically resets.
|
2015-01-06 16:39:24 -05:00
|
|
|
*
|
|
|
|
|
* @param channel A digital source to set as the encoder index
|
2016-05-20 17:30:37 -07:00
|
|
|
* @param type The state that will cause the encoder to reset
|
2015-01-06 16:39:24 -05:00
|
|
|
*/
|
2016-05-20 17:30:37 -07:00
|
|
|
void Encoder::SetIndexSource(const DigitalSource& source,
|
2015-06-25 15:07:55 -04:00
|
|
|
Encoder::IndexingType type) {
|
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
|
|
|
int32_t status = 0;
|
2016-07-09 00:24:26 -07:00
|
|
|
HAL_SetEncoderIndexSource(
|
|
|
|
|
m_encoder, source.GetPortHandleForRouting(),
|
|
|
|
|
(HAL_AnalogTriggerType)source.GetAnalogTriggerTypeForRouting(),
|
|
|
|
|
(HAL_EncoderIndexingType)type, &status);
|
|
|
|
|
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
|
2016-07-03 15:22:22 -07:00
|
|
|
}
|
|
|
|
|
|
2016-09-06 00:01:45 -07:00
|
|
|
int Encoder::GetFPGAIndex() const {
|
2016-07-03 15:22:22 -07:00
|
|
|
int32_t status = 0;
|
2016-09-06 00:01:45 -07:00
|
|
|
int val = HAL_GetEncoderFPGAIndex(m_encoder, &status);
|
2016-07-09 00:24:26 -07:00
|
|
|
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
|
2016-07-03 15:22:22 -07:00
|
|
|
return val;
|
2015-01-06 16:39:24 -05:00
|
|
|
}
|
|
|
|
|
|
2013-12-15 18:30:16 -05:00
|
|
|
void Encoder::UpdateTable() {
|
2015-06-23 04:49:51 -07:00
|
|
|
if (m_table != nullptr) {
|
2015-06-25 15:07:55 -04:00
|
|
|
m_table->PutNumber("Speed", GetRate());
|
|
|
|
|
m_table->PutNumber("Distance", GetDistance());
|
2016-07-03 15:22:22 -07:00
|
|
|
int32_t status = 0;
|
2016-07-09 00:24:26 -07:00
|
|
|
double distancePerPulse =
|
|
|
|
|
HAL_GetEncoderDistancePerPulse(m_encoder, &status);
|
|
|
|
|
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
|
2016-07-03 15:22:22 -07:00
|
|
|
m_table->PutNumber("Distance per Tick", distancePerPulse);
|
2015-06-25 15:07:55 -04:00
|
|
|
}
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
void Encoder::StartLiveWindowMode() {}
|
2014-06-13 17:45:10 -04:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
void Encoder::StopLiveWindowMode() {}
|
2013-12-15 18:30:16 -05:00
|
|
|
|
2015-06-19 17:23:54 -07:00
|
|
|
std::string Encoder::GetSmartDashboardType() const {
|
2016-07-03 15:22:22 -07:00
|
|
|
int32_t status = 0;
|
2016-07-09 00:24:26 -07:00
|
|
|
HAL_EncoderEncodingType type = HAL_GetEncoderEncodingType(m_encoder, &status);
|
|
|
|
|
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
|
|
|
|
|
if (type == HAL_EncoderEncodingType::HAL_Encoder_k4X)
|
2015-06-25 15:07:55 -04:00
|
|
|
return "Quadrature Encoder";
|
|
|
|
|
else
|
|
|
|
|
return "Encoder";
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
2015-07-29 16:48:04 -04:00
|
|
|
void Encoder::InitTable(std::shared_ptr<ITable> subTable) {
|
2015-06-25 15:07:55 -04:00
|
|
|
m_table = subTable;
|
|
|
|
|
UpdateTable();
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
2015-07-29 16:48:04 -04:00
|
|
|
std::shared_ptr<ITable> Encoder::GetTable() const { return m_table; }
|