mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-03 03:01:44 +00:00
[hal,wpilib] Rename Encoder constants to all caps
This commit is contained in:
@@ -18,19 +18,19 @@
|
||||
* The type of index pulse for the encoder.
|
||||
*/
|
||||
HAL_ENUM(HAL_EncoderIndexingType) {
|
||||
HAL_kResetWhileHigh,
|
||||
HAL_kResetWhileLow,
|
||||
HAL_kResetOnFallingEdge,
|
||||
HAL_kResetOnRisingEdge
|
||||
HAL_ENCODER_INDEX_RESET_WHILE_HIGH,
|
||||
HAL_ENCODER_INDEX_RESET_WHILE_LOW,
|
||||
HAL_ENCODER_INDEX_RESET_ON_FALLING_EDGE,
|
||||
HAL_ENCODER_INDEX_RESET_ON_RISING_EDGE
|
||||
};
|
||||
|
||||
/**
|
||||
* The encoding scaling of the encoder.
|
||||
*/
|
||||
HAL_ENUM(HAL_EncoderEncodingType) {
|
||||
HAL_Encoder_k1X,
|
||||
HAL_Encoder_k2X,
|
||||
HAL_Encoder_k4X
|
||||
HAL_ENCODER_1X_ENCODING,
|
||||
HAL_ENCODER_2X_ENCODING,
|
||||
HAL_ENCODER_4X_ENCODING
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@@ -72,7 +72,7 @@ HAL_EncoderHandle HAL_InitializeEncoder(int32_t aChannel, int32_t bChannel,
|
||||
int32_t* status) {
|
||||
wpi::hal::init::CheckInit();
|
||||
HAL_Handle nativeHandle = HAL_kInvalidHandle;
|
||||
if (encodingType == HAL_EncoderEncodingType::HAL_Encoder_k4X) {
|
||||
if (encodingType == HAL_EncoderEncodingType::HAL_ENCODER_4X_ENCODING) {
|
||||
// k4x, allocate encoder
|
||||
nativeHandle = fpgaEncoderHandles->Allocate();
|
||||
} else {
|
||||
@@ -104,7 +104,7 @@ HAL_EncoderHandle HAL_InitializeEncoder(int32_t aChannel, int32_t bChannel,
|
||||
encoder->nativeHandle = nativeHandle;
|
||||
encoder->encodingType = encodingType;
|
||||
encoder->distancePerPulse = 1.0;
|
||||
if (encodingType == HAL_EncoderEncodingType::HAL_Encoder_k4X) {
|
||||
if (encodingType == HAL_EncoderEncodingType::HAL_ENCODER_4X_ENCODING) {
|
||||
encoder->fpgaHandle = nativeHandle;
|
||||
encoder->counterHandle = HAL_kInvalidHandle;
|
||||
} else {
|
||||
@@ -139,11 +139,11 @@ void HAL_SetEncoderSimDevice(HAL_EncoderHandle handle,
|
||||
|
||||
static inline int EncodingScaleFactor(Encoder* encoder) {
|
||||
switch (encoder->encodingType) {
|
||||
case HAL_Encoder_k1X:
|
||||
case HAL_ENCODER_1X_ENCODING:
|
||||
return 1;
|
||||
case HAL_Encoder_k2X:
|
||||
case HAL_ENCODER_2X_ENCODING:
|
||||
return 2;
|
||||
case HAL_Encoder_k4X:
|
||||
case HAL_ENCODER_4X_ENCODING:
|
||||
return 4;
|
||||
default:
|
||||
return 0;
|
||||
@@ -152,11 +152,11 @@ static inline int EncodingScaleFactor(Encoder* encoder) {
|
||||
|
||||
static inline double DecodingScaleFactor(Encoder* encoder) {
|
||||
switch (encoder->encodingType) {
|
||||
case HAL_Encoder_k1X:
|
||||
case HAL_ENCODER_1X_ENCODING:
|
||||
return 1.0;
|
||||
case HAL_Encoder_k2X:
|
||||
case HAL_ENCODER_2X_ENCODING:
|
||||
return 0.5;
|
||||
case HAL_Encoder_k4X:
|
||||
case HAL_ENCODER_4X_ENCODING:
|
||||
return 0.25;
|
||||
default:
|
||||
return 0.0;
|
||||
@@ -365,7 +365,7 @@ HAL_EncoderEncodingType HAL_GetEncoderEncodingType(
|
||||
auto encoder = encoderHandles->Get(encoderHandle);
|
||||
if (encoder == nullptr) {
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return HAL_Encoder_k4X; // default to k4x
|
||||
return HAL_ENCODER_4X_ENCODING; // default to k4x
|
||||
}
|
||||
|
||||
return encoder->encodingType;
|
||||
|
||||
@@ -131,7 +131,7 @@ double HAL_GetEncoderDistancePerPulse(HAL_EncoderHandle encoderHandle,
|
||||
HAL_EncoderEncodingType HAL_GetEncoderEncodingType(
|
||||
HAL_EncoderHandle encoderHandle, int32_t* status) {
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return HAL_Encoder_k4X;
|
||||
return HAL_ENCODER_4X_ENCODING;
|
||||
}
|
||||
|
||||
int32_t HAL_GetEncoderFPGAIndex(HAL_EncoderHandle encoderHandle,
|
||||
|
||||
@@ -28,7 +28,7 @@ class MyRobot(wpilib.TimedRobot):
|
||||
"""Robot initialization function"""
|
||||
super().__init__()
|
||||
|
||||
self.encoder = wpilib.Encoder(1, 2, False, wpilib.Encoder.EncodingType.k4X)
|
||||
self.encoder = wpilib.Encoder(1, 2, False, wpilib.Encoder.EncodingType.X4)
|
||||
|
||||
# Defines the number of samples to average when determining the rate.
|
||||
# On a quadrature encoder, values range from 1-255;
|
||||
|
||||
@@ -144,7 +144,7 @@ void Encoder::InitSendable(wpi::util::SendableBuilder& builder) {
|
||||
int32_t status = 0;
|
||||
HAL_EncoderEncodingType type = HAL_GetEncoderEncodingType(m_encoder, &status);
|
||||
WPILIB_CheckErrorStatus(status, "GetEncodingType");
|
||||
if (type == HAL_EncoderEncodingType::HAL_Encoder_k4X) {
|
||||
if (type == HAL_EncoderEncodingType::HAL_ENCODER_4X_ENCODING) {
|
||||
builder.SetSmartDashboardType("Quadrature Encoder");
|
||||
} else {
|
||||
builder.SetSmartDashboardType("Encoder");
|
||||
@@ -169,13 +169,13 @@ void Encoder::InitEncoder(int aChannel, int bChannel, bool reverseDirection,
|
||||
|
||||
const char* type = "Encoder";
|
||||
switch (encodingType) {
|
||||
case k1X:
|
||||
case EncodingType::X1:
|
||||
type = "Encoder:1x";
|
||||
break;
|
||||
case k2X:
|
||||
case EncodingType::X2:
|
||||
type = "Encoder:2x";
|
||||
break;
|
||||
case k4X:
|
||||
case EncodingType::X4:
|
||||
type = "Encoder:4x";
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -19,7 +19,8 @@ namespace wpi {
|
||||
*/
|
||||
class CounterBase {
|
||||
public:
|
||||
enum EncodingType { k1X, k2X, k4X };
|
||||
/** The number of edges for the CounterBase to increment or decrement on. */
|
||||
enum class EncodingType { X1, X2, X4 };
|
||||
|
||||
CounterBase() = default;
|
||||
virtual ~CounterBase() = default;
|
||||
|
||||
@@ -44,7 +44,7 @@ class Encoder : public CounterBase,
|
||||
* @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
|
||||
* @param encodingType either X1, X2, or X4 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
|
||||
@@ -54,7 +54,7 @@ class Encoder : public CounterBase,
|
||||
* be double (2x) the spec'd count.
|
||||
*/
|
||||
Encoder(int aChannel, int bChannel, bool reverseDirection = false,
|
||||
EncodingType encodingType = k4X);
|
||||
EncodingType encodingType = EncodingType::X4);
|
||||
|
||||
Encoder(Encoder&&) = default;
|
||||
Encoder& operator=(Encoder&&) = default;
|
||||
@@ -256,7 +256,7 @@ class Encoder : public CounterBase,
|
||||
* @param bChannel The b channel.
|
||||
* @param reverseDirection If true, counts down instead of up (this is all
|
||||
* relative)
|
||||
* @param encodingType either k1X, k2X, or k4X to indicate 1X, 2X or 4X
|
||||
* @param encodingType either X1, X2, or X4 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
|
||||
|
||||
@@ -13,7 +13,7 @@ classes:
|
||||
int, int, bool, EncodingType:
|
||||
param_override:
|
||||
encodingType:
|
||||
default: wpi::Encoder::EncodingType::k4X
|
||||
default: wpi::Encoder::EncodingType::X4
|
||||
DigitalSource*, DigitalSource*, bool, EncodingType:
|
||||
ignore: true
|
||||
DigitalSource&, DigitalSource&, bool, EncodingType:
|
||||
@@ -21,7 +21,7 @@ classes:
|
||||
std::shared_ptr<DigitalSource>, std::shared_ptr<DigitalSource>, bool, EncodingType:
|
||||
param_override:
|
||||
encodingType:
|
||||
default: wpi::Encoder::EncodingType::k4X
|
||||
default: wpi::Encoder::EncodingType::X4
|
||||
Get:
|
||||
Reset:
|
||||
GetPeriod:
|
||||
|
||||
@@ -72,11 +72,11 @@ class Robot : public wpi::TimedRobot {
|
||||
* set this parameter to true, the direction of the encoder will be reversed,
|
||||
* in case it makes more sense mechanically.
|
||||
*
|
||||
* The final (optional) parameter specifies encoding rate (k1X, k2X, or k4X)
|
||||
* and defaults to k4X. Faster (k4X) encoding gives greater positional
|
||||
* The final (optional) parameter specifies encoding rate (X1, X2, or X4)
|
||||
* and defaults to X4. Faster (X4) encoding gives greater positional
|
||||
* precision but more noise in the rate.
|
||||
*/
|
||||
wpi::Encoder m_encoder{1, 2, false, wpi::Encoder::k4X};
|
||||
wpi::Encoder m_encoder{1, 2, false, wpi::Encoder::EncodingType::X4};
|
||||
};
|
||||
|
||||
#ifndef RUNNING_WPILIB_TESTS
|
||||
|
||||
@@ -56,7 +56,7 @@ class Robot : public wpi::TimedRobot {
|
||||
|
||||
// Initializes an encoder on DIO pins 0 and 1
|
||||
// 2X encoding and non-inverted
|
||||
wpi::Encoder m_encoder2x{0, 1, false, wpi::Encoder::EncodingType::k2X};
|
||||
wpi::Encoder m_encoder2x{0, 1, false, wpi::Encoder::EncodingType::X2};
|
||||
};
|
||||
|
||||
#ifndef RUNNING_WPILIB_TESTS
|
||||
|
||||
@@ -16,11 +16,11 @@ public interface CounterBase {
|
||||
/** The number of edges for the CounterBase to increment or decrement on. */
|
||||
enum EncodingType {
|
||||
/** Count only the rising edge. */
|
||||
k1X(0),
|
||||
X1(0),
|
||||
/** Count both the rising and falling edge. */
|
||||
k2X(1),
|
||||
X2(1),
|
||||
/** Count rising and falling on both channels. */
|
||||
k4X(2);
|
||||
X4(2);
|
||||
|
||||
/** EncodingType value. */
|
||||
public final int value;
|
||||
|
||||
@@ -48,9 +48,9 @@ public class Encoder implements CounterBase, Sendable, AutoCloseable {
|
||||
|
||||
String typeStr =
|
||||
switch (type) {
|
||||
case k1X -> "Encoder:1x";
|
||||
case k2X -> "Encoder:2x";
|
||||
case k4X -> "Encoder:4x";
|
||||
case X1 -> "Encoder:1x";
|
||||
case X2 -> "Encoder:2x";
|
||||
case X4 -> "Encoder:4x";
|
||||
default -> "Encoder";
|
||||
};
|
||||
HAL.reportUsage("IO[" + aChannel + "," + bChannel + "]", typeStr);
|
||||
@@ -70,7 +70,7 @@ public class Encoder implements CounterBase, Sendable, AutoCloseable {
|
||||
* if necessary so forward represents positive values.
|
||||
*/
|
||||
public Encoder(final int channelA, final int channelB, boolean reverseDirection) {
|
||||
this(channelA, channelB, reverseDirection, EncodingType.k4X);
|
||||
this(channelA, channelB, reverseDirection, EncodingType.X4);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -337,15 +337,15 @@ public class Encoder implements CounterBase, Sendable, AutoCloseable {
|
||||
*/
|
||||
public double getDecodingScaleFactor() {
|
||||
return switch (m_encodingType) {
|
||||
case k1X -> 1.0;
|
||||
case k2X -> 0.5;
|
||||
case k4X -> 0.25;
|
||||
case X1 -> 1.0;
|
||||
case X2 -> 0.5;
|
||||
case X4 -> 0.25;
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initSendable(SendableBuilder builder) {
|
||||
if (EncoderJNI.getEncoderEncodingType(m_encoder) == EncodingType.k4X.value) {
|
||||
if (EncoderJNI.getEncoderEncodingType(m_encoder) == EncodingType.X4.value) {
|
||||
builder.setSmartDashboardType("Quadrature Encoder");
|
||||
} else {
|
||||
builder.setSmartDashboardType("Encoder");
|
||||
|
||||
@@ -32,7 +32,7 @@ public class Robot extends TimedRobot {
|
||||
* defaults to k4X. Faster (k4X) encoding gives greater positional precision but more noise in the
|
||||
* rate.
|
||||
*/
|
||||
private final Encoder m_encoder = new Encoder(1, 2, false, CounterBase.EncodingType.k4X);
|
||||
private final Encoder m_encoder = new Encoder(1, 2, false, CounterBase.EncodingType.X4);
|
||||
|
||||
/** Called once at the beginning of the robot program. */
|
||||
public Robot() {
|
||||
|
||||
@@ -19,7 +19,7 @@ public class Robot extends TimedRobot {
|
||||
|
||||
// Initializes an encoder on DIO pins 0 and 1
|
||||
// 2X encoding and non-inverted
|
||||
Encoder m_encoder2x = new Encoder(0, 1, false, Encoder.EncodingType.k2X);
|
||||
Encoder m_encoder2x = new Encoder(0, 1, false, Encoder.EncodingType.X2);
|
||||
|
||||
/** Called once at the beginning of the robot program. */
|
||||
public Robot() {
|
||||
|
||||
Reference in New Issue
Block a user