mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-21 01:01:43 +00:00
Add braces to C++ single-line loops and conditionals (NFC) (#2973)
This makes code easier to read and more consistent between C++ and Java. Also update clang-format settings to always add a line break (even if no braces are used).
This commit is contained in:
@@ -38,16 +38,28 @@ void ADXL345_I2C::SetRange(Range range) {
|
||||
kDataFormat_FullRes | static_cast<uint8_t>(range));
|
||||
}
|
||||
|
||||
double ADXL345_I2C::GetX() { return GetAcceleration(kAxis_X); }
|
||||
double ADXL345_I2C::GetX() {
|
||||
return GetAcceleration(kAxis_X);
|
||||
}
|
||||
|
||||
double ADXL345_I2C::GetY() { return GetAcceleration(kAxis_Y); }
|
||||
double ADXL345_I2C::GetY() {
|
||||
return GetAcceleration(kAxis_Y);
|
||||
}
|
||||
|
||||
double ADXL345_I2C::GetZ() { return GetAcceleration(kAxis_Z); }
|
||||
double ADXL345_I2C::GetZ() {
|
||||
return GetAcceleration(kAxis_Z);
|
||||
}
|
||||
|
||||
double ADXL345_I2C::GetAcceleration(ADXL345_I2C::Axes axis) {
|
||||
if (axis == kAxis_X && m_simX) return m_simX.Get();
|
||||
if (axis == kAxis_Y && m_simY) return m_simY.Get();
|
||||
if (axis == kAxis_Z && m_simZ) return m_simZ.Get();
|
||||
if (axis == kAxis_X && m_simX) {
|
||||
return m_simX.Get();
|
||||
}
|
||||
if (axis == kAxis_Y && m_simY) {
|
||||
return m_simY.Get();
|
||||
}
|
||||
if (axis == kAxis_Z && m_simZ) {
|
||||
return m_simZ.Get();
|
||||
}
|
||||
int16_t rawAccel = 0;
|
||||
m_i2c.Read(kDataRegister + static_cast<int>(axis), sizeof(rawAccel),
|
||||
reinterpret_cast<uint8_t*>(&rawAccel));
|
||||
|
||||
@@ -49,19 +49,33 @@ void ADXL345_SPI::SetRange(Range range) {
|
||||
commands[1] = kDataFormat_FullRes | static_cast<uint8_t>(range & 0x03);
|
||||
m_spi.Transaction(commands, commands, 2);
|
||||
|
||||
if (m_simRange) m_simRange.Set(range);
|
||||
if (m_simRange) {
|
||||
m_simRange.Set(range);
|
||||
}
|
||||
}
|
||||
|
||||
double ADXL345_SPI::GetX() { return GetAcceleration(kAxis_X); }
|
||||
double ADXL345_SPI::GetX() {
|
||||
return GetAcceleration(kAxis_X);
|
||||
}
|
||||
|
||||
double ADXL345_SPI::GetY() { return GetAcceleration(kAxis_Y); }
|
||||
double ADXL345_SPI::GetY() {
|
||||
return GetAcceleration(kAxis_Y);
|
||||
}
|
||||
|
||||
double ADXL345_SPI::GetZ() { return GetAcceleration(kAxis_Z); }
|
||||
double ADXL345_SPI::GetZ() {
|
||||
return GetAcceleration(kAxis_Z);
|
||||
}
|
||||
|
||||
double ADXL345_SPI::GetAcceleration(ADXL345_SPI::Axes axis) {
|
||||
if (axis == kAxis_X && m_simX) return m_simX.Get();
|
||||
if (axis == kAxis_Y && m_simY) return m_simY.Get();
|
||||
if (axis == kAxis_Z && m_simZ) return m_simZ.Get();
|
||||
if (axis == kAxis_X && m_simX) {
|
||||
return m_simX.Get();
|
||||
}
|
||||
if (axis == kAxis_Y && m_simY) {
|
||||
return m_simY.Get();
|
||||
}
|
||||
if (axis == kAxis_Z && m_simZ) {
|
||||
return m_simZ.Get();
|
||||
}
|
||||
uint8_t buffer[3];
|
||||
uint8_t command[3] = {0, 0, 0};
|
||||
command[0] = (kAddress_Read | kAddress_MultiByte | kDataRegister) +
|
||||
|
||||
@@ -76,7 +76,9 @@ ADXL362::ADXL362(SPI::Port port, Range range)
|
||||
}
|
||||
|
||||
void ADXL362::SetRange(Range range) {
|
||||
if (m_gsPerLSB == 0.0) return;
|
||||
if (m_gsPerLSB == 0.0) {
|
||||
return;
|
||||
}
|
||||
|
||||
uint8_t commands[3];
|
||||
|
||||
@@ -100,21 +102,37 @@ void ADXL362::SetRange(Range range) {
|
||||
kFilterCtl_ODR_100Hz | static_cast<uint8_t>((range & 0x03) << 6);
|
||||
m_spi.Write(commands, 3);
|
||||
|
||||
if (m_simRange) m_simRange.Set(range);
|
||||
if (m_simRange) {
|
||||
m_simRange.Set(range);
|
||||
}
|
||||
}
|
||||
|
||||
double ADXL362::GetX() { return GetAcceleration(kAxis_X); }
|
||||
double ADXL362::GetX() {
|
||||
return GetAcceleration(kAxis_X);
|
||||
}
|
||||
|
||||
double ADXL362::GetY() { return GetAcceleration(kAxis_Y); }
|
||||
double ADXL362::GetY() {
|
||||
return GetAcceleration(kAxis_Y);
|
||||
}
|
||||
|
||||
double ADXL362::GetZ() { return GetAcceleration(kAxis_Z); }
|
||||
double ADXL362::GetZ() {
|
||||
return GetAcceleration(kAxis_Z);
|
||||
}
|
||||
|
||||
double ADXL362::GetAcceleration(ADXL362::Axes axis) {
|
||||
if (m_gsPerLSB == 0.0) return 0.0;
|
||||
if (m_gsPerLSB == 0.0) {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
if (axis == kAxis_X && m_simX) return m_simX.Get();
|
||||
if (axis == kAxis_Y && m_simY) return m_simY.Get();
|
||||
if (axis == kAxis_Z && m_simZ) return m_simZ.Get();
|
||||
if (axis == kAxis_X && m_simX) {
|
||||
return m_simX.Get();
|
||||
}
|
||||
if (axis == kAxis_Y && m_simY) {
|
||||
return m_simY.Get();
|
||||
}
|
||||
if (axis == kAxis_Z && m_simZ) {
|
||||
return m_simZ.Get();
|
||||
}
|
||||
|
||||
uint8_t buffer[4];
|
||||
uint8_t command[4] = {0, 0, 0, 0};
|
||||
|
||||
@@ -79,7 +79,9 @@ static inline int BytesToIntBE(uint8_t* buf) {
|
||||
|
||||
uint16_t ADXRS450_Gyro::ReadRegister(int reg) {
|
||||
int cmd = 0x80000000 | static_cast<int>(reg) << 17;
|
||||
if (!CalcParity(cmd)) cmd |= 1u;
|
||||
if (!CalcParity(cmd)) {
|
||||
cmd |= 1u;
|
||||
}
|
||||
|
||||
// big endian
|
||||
uint8_t buf[4] = {static_cast<uint8_t>((cmd >> 24) & 0xff),
|
||||
@@ -89,24 +91,34 @@ uint16_t ADXRS450_Gyro::ReadRegister(int reg) {
|
||||
|
||||
m_spi.Write(buf, 4);
|
||||
m_spi.Read(false, buf, 4);
|
||||
if ((buf[0] & 0xe0) == 0) return 0; // error, return 0
|
||||
if ((buf[0] & 0xe0) == 0) {
|
||||
return 0; // error, return 0
|
||||
}
|
||||
return static_cast<uint16_t>((BytesToIntBE(buf) >> 5) & 0xffff);
|
||||
}
|
||||
|
||||
double ADXRS450_Gyro::GetAngle() const {
|
||||
if (m_simAngle) return m_simAngle.Get();
|
||||
if (m_simAngle) {
|
||||
return m_simAngle.Get();
|
||||
}
|
||||
return m_spi.GetAccumulatorIntegratedValue() * kDegreePerSecondPerLSB;
|
||||
}
|
||||
|
||||
double ADXRS450_Gyro::GetRate() const {
|
||||
if (m_simRate) return m_simRate.Get();
|
||||
if (m_simRate) {
|
||||
return m_simRate.Get();
|
||||
}
|
||||
return static_cast<double>(m_spi.GetAccumulatorLastValue()) *
|
||||
kDegreePerSecondPerLSB;
|
||||
}
|
||||
|
||||
void ADXRS450_Gyro::Reset() {
|
||||
if (m_simAngle) m_simAngle.Set(0.0);
|
||||
if (m_simRate) m_simRate.Set(0.0);
|
||||
if (m_simAngle) {
|
||||
m_simAngle.Set(0.0);
|
||||
}
|
||||
if (m_simRate) {
|
||||
m_simRate.Set(0.0);
|
||||
}
|
||||
m_spi.ResetAccumulator();
|
||||
}
|
||||
|
||||
@@ -122,4 +134,6 @@ void ADXRS450_Gyro::Calibrate() {
|
||||
m_spi.ResetAccumulator();
|
||||
}
|
||||
|
||||
int ADXRS450_Gyro::GetPort() const { return m_port; }
|
||||
int ADXRS450_Gyro::GetPort() const {
|
||||
return m_port;
|
||||
}
|
||||
|
||||
@@ -44,9 +44,13 @@ void AnalogAccelerometer::SetSensitivity(double sensitivity) {
|
||||
m_voltsPerG = sensitivity;
|
||||
}
|
||||
|
||||
void AnalogAccelerometer::SetZero(double zero) { m_zeroGVoltage = zero; }
|
||||
void AnalogAccelerometer::SetZero(double zero) {
|
||||
m_zeroGVoltage = zero;
|
||||
}
|
||||
|
||||
double AnalogAccelerometer::PIDGet() { return GetAcceleration(); }
|
||||
double AnalogAccelerometer::PIDGet() {
|
||||
return GetAcceleration();
|
||||
}
|
||||
|
||||
void AnalogAccelerometer::InitSendable(SendableBuilder& builder) {
|
||||
builder.SetSmartDashboardType("Accelerometer");
|
||||
|
||||
@@ -51,7 +51,9 @@ void AnalogEncoder::Init() {
|
||||
}
|
||||
|
||||
units::turn_t AnalogEncoder::Get() const {
|
||||
if (m_simPosition) return units::turn_t{m_simPosition.Get()};
|
||||
if (m_simPosition) {
|
||||
return units::turn_t{m_simPosition.Get()};
|
||||
}
|
||||
|
||||
// As the values are not atomic, keep trying until we get 2 reads of the same
|
||||
// value If we don't within 10 attempts, error
|
||||
@@ -73,7 +75,9 @@ units::turn_t AnalogEncoder::Get() const {
|
||||
return m_lastPosition;
|
||||
}
|
||||
|
||||
double AnalogEncoder::GetPositionOffset() const { return m_positionOffset; }
|
||||
double AnalogEncoder::GetPositionOffset() const {
|
||||
return m_positionOffset;
|
||||
}
|
||||
|
||||
void AnalogEncoder::SetDistancePerRotation(double distancePerRotation) {
|
||||
m_distancePerRotation = distancePerRotation;
|
||||
@@ -92,7 +96,9 @@ void AnalogEncoder::Reset() {
|
||||
m_positionOffset = m_analogInput->GetVoltage();
|
||||
}
|
||||
|
||||
int AnalogEncoder::GetChannel() const { return m_analogInput->GetChannel(); }
|
||||
int AnalogEncoder::GetChannel() const {
|
||||
return m_analogInput->GetChannel();
|
||||
}
|
||||
|
||||
void AnalogEncoder::InitSendable(SendableBuilder& builder) {
|
||||
builder.SetSmartDashboardType("AbsoluteEncoder");
|
||||
|
||||
@@ -62,10 +62,14 @@ AnalogGyro::AnalogGyro(std::shared_ptr<AnalogInput> channel, int center,
|
||||
}
|
||||
}
|
||||
|
||||
AnalogGyro::~AnalogGyro() { HAL_FreeAnalogGyro(m_gyroHandle); }
|
||||
AnalogGyro::~AnalogGyro() {
|
||||
HAL_FreeAnalogGyro(m_gyroHandle);
|
||||
}
|
||||
|
||||
double AnalogGyro::GetAngle() const {
|
||||
if (StatusIsFatal()) return 0.0;
|
||||
if (StatusIsFatal()) {
|
||||
return 0.0;
|
||||
}
|
||||
int32_t status = 0;
|
||||
double value = HAL_GetAnalogGyroAngle(m_gyroHandle, &status);
|
||||
wpi_setHALError(status);
|
||||
@@ -73,7 +77,9 @@ double AnalogGyro::GetAngle() const {
|
||||
}
|
||||
|
||||
double AnalogGyro::GetRate() const {
|
||||
if (StatusIsFatal()) return 0.0;
|
||||
if (StatusIsFatal()) {
|
||||
return 0.0;
|
||||
}
|
||||
int32_t status = 0;
|
||||
double value = HAL_GetAnalogGyroRate(m_gyroHandle, &status);
|
||||
wpi_setHALError(status);
|
||||
@@ -81,7 +87,9 @@ double AnalogGyro::GetRate() const {
|
||||
}
|
||||
|
||||
int AnalogGyro::GetCenter() const {
|
||||
if (StatusIsFatal()) return 0;
|
||||
if (StatusIsFatal()) {
|
||||
return 0;
|
||||
}
|
||||
int32_t status = 0;
|
||||
int value = HAL_GetAnalogGyroCenter(m_gyroHandle, &status);
|
||||
wpi_setHALError(status);
|
||||
@@ -89,7 +97,9 @@ int AnalogGyro::GetCenter() const {
|
||||
}
|
||||
|
||||
double AnalogGyro::GetOffset() const {
|
||||
if (StatusIsFatal()) return 0.0;
|
||||
if (StatusIsFatal()) {
|
||||
return 0.0;
|
||||
}
|
||||
int32_t status = 0;
|
||||
double value = HAL_GetAnalogGyroOffset(m_gyroHandle, &status);
|
||||
wpi_setHALError(status);
|
||||
@@ -104,21 +114,27 @@ void AnalogGyro::SetSensitivity(double voltsPerDegreePerSecond) {
|
||||
}
|
||||
|
||||
void AnalogGyro::SetDeadband(double volts) {
|
||||
if (StatusIsFatal()) return;
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
int32_t status = 0;
|
||||
HAL_SetAnalogGyroDeadband(m_gyroHandle, volts, &status);
|
||||
wpi_setHALError(status);
|
||||
}
|
||||
|
||||
void AnalogGyro::Reset() {
|
||||
if (StatusIsFatal()) return;
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
int32_t status = 0;
|
||||
HAL_ResetAnalogGyro(m_gyroHandle, &status);
|
||||
wpi_setHALError(status);
|
||||
}
|
||||
|
||||
void AnalogGyro::InitGyro() {
|
||||
if (StatusIsFatal()) return;
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
if (m_gyroHandle == HAL_kInvalidHandle) {
|
||||
int32_t status = 0;
|
||||
m_gyroHandle = HAL_InitializeAnalogGyro(m_analog->m_port, &status);
|
||||
@@ -153,7 +169,9 @@ void AnalogGyro::InitGyro() {
|
||||
}
|
||||
|
||||
void AnalogGyro::Calibrate() {
|
||||
if (StatusIsFatal()) return;
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
int32_t status = 0;
|
||||
HAL_CalibrateAnalogGyro(m_gyroHandle, &status);
|
||||
wpi_setHALError(status);
|
||||
|
||||
@@ -42,10 +42,14 @@ AnalogInput::AnalogInput(int channel) {
|
||||
SendableRegistry::GetInstance().AddLW(this, "AnalogInput", channel);
|
||||
}
|
||||
|
||||
AnalogInput::~AnalogInput() { HAL_FreeAnalogInputPort(m_port); }
|
||||
AnalogInput::~AnalogInput() {
|
||||
HAL_FreeAnalogInputPort(m_port);
|
||||
}
|
||||
|
||||
int AnalogInput::GetValue() const {
|
||||
if (StatusIsFatal()) return 0;
|
||||
if (StatusIsFatal()) {
|
||||
return 0;
|
||||
}
|
||||
int32_t status = 0;
|
||||
int value = HAL_GetAnalogValue(m_port, &status);
|
||||
wpi_setHALError(status);
|
||||
@@ -53,7 +57,9 @@ int AnalogInput::GetValue() const {
|
||||
}
|
||||
|
||||
int AnalogInput::GetAverageValue() const {
|
||||
if (StatusIsFatal()) return 0;
|
||||
if (StatusIsFatal()) {
|
||||
return 0;
|
||||
}
|
||||
int32_t status = 0;
|
||||
int value = HAL_GetAnalogAverageValue(m_port, &status);
|
||||
wpi_setHALError(status);
|
||||
@@ -61,7 +67,9 @@ int AnalogInput::GetAverageValue() const {
|
||||
}
|
||||
|
||||
double AnalogInput::GetVoltage() const {
|
||||
if (StatusIsFatal()) return 0.0;
|
||||
if (StatusIsFatal()) {
|
||||
return 0.0;
|
||||
}
|
||||
int32_t status = 0;
|
||||
double voltage = HAL_GetAnalogVoltage(m_port, &status);
|
||||
wpi_setHALError(status);
|
||||
@@ -69,7 +77,9 @@ double AnalogInput::GetVoltage() const {
|
||||
}
|
||||
|
||||
double AnalogInput::GetAverageVoltage() const {
|
||||
if (StatusIsFatal()) return 0.0;
|
||||
if (StatusIsFatal()) {
|
||||
return 0.0;
|
||||
}
|
||||
int32_t status = 0;
|
||||
double voltage = HAL_GetAnalogAverageVoltage(m_port, &status);
|
||||
wpi_setHALError(status);
|
||||
@@ -77,12 +87,16 @@ double AnalogInput::GetAverageVoltage() const {
|
||||
}
|
||||
|
||||
int AnalogInput::GetChannel() const {
|
||||
if (StatusIsFatal()) return 0;
|
||||
if (StatusIsFatal()) {
|
||||
return 0;
|
||||
}
|
||||
return m_channel;
|
||||
}
|
||||
|
||||
void AnalogInput::SetAverageBits(int bits) {
|
||||
if (StatusIsFatal()) return;
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
int32_t status = 0;
|
||||
HAL_SetAnalogAverageBits(m_port, bits, &status);
|
||||
wpi_setHALError(status);
|
||||
@@ -96,14 +110,18 @@ int AnalogInput::GetAverageBits() const {
|
||||
}
|
||||
|
||||
void AnalogInput::SetOversampleBits(int bits) {
|
||||
if (StatusIsFatal()) return;
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
int32_t status = 0;
|
||||
HAL_SetAnalogOversampleBits(m_port, bits, &status);
|
||||
wpi_setHALError(status);
|
||||
}
|
||||
|
||||
int AnalogInput::GetOversampleBits() const {
|
||||
if (StatusIsFatal()) return 0;
|
||||
if (StatusIsFatal()) {
|
||||
return 0;
|
||||
}
|
||||
int32_t status = 0;
|
||||
int oversampleBits = HAL_GetAnalogOversampleBits(m_port, &status);
|
||||
wpi_setHALError(status);
|
||||
@@ -111,7 +129,9 @@ int AnalogInput::GetOversampleBits() const {
|
||||
}
|
||||
|
||||
int AnalogInput::GetLSBWeight() const {
|
||||
if (StatusIsFatal()) return 0;
|
||||
if (StatusIsFatal()) {
|
||||
return 0;
|
||||
}
|
||||
int32_t status = 0;
|
||||
int lsbWeight = HAL_GetAnalogLSBWeight(m_port, &status);
|
||||
wpi_setHALError(status);
|
||||
@@ -119,7 +139,9 @@ int AnalogInput::GetLSBWeight() const {
|
||||
}
|
||||
|
||||
int AnalogInput::GetOffset() const {
|
||||
if (StatusIsFatal()) return 0;
|
||||
if (StatusIsFatal()) {
|
||||
return 0;
|
||||
}
|
||||
int32_t status = 0;
|
||||
int offset = HAL_GetAnalogOffset(m_port, &status);
|
||||
wpi_setHALError(status);
|
||||
@@ -127,7 +149,9 @@ int AnalogInput::GetOffset() const {
|
||||
}
|
||||
|
||||
bool AnalogInput::IsAccumulatorChannel() const {
|
||||
if (StatusIsFatal()) return false;
|
||||
if (StatusIsFatal()) {
|
||||
return false;
|
||||
}
|
||||
int32_t status = 0;
|
||||
bool isAccum = HAL_IsAccumulatorChannel(m_port, &status);
|
||||
wpi_setHALError(status);
|
||||
@@ -135,7 +159,9 @@ bool AnalogInput::IsAccumulatorChannel() const {
|
||||
}
|
||||
|
||||
void AnalogInput::InitAccumulator() {
|
||||
if (StatusIsFatal()) return;
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
m_accumulatorOffset = 0;
|
||||
int32_t status = 0;
|
||||
HAL_InitAccumulator(m_port, &status);
|
||||
@@ -143,12 +169,16 @@ void AnalogInput::InitAccumulator() {
|
||||
}
|
||||
|
||||
void AnalogInput::SetAccumulatorInitialValue(int64_t initialValue) {
|
||||
if (StatusIsFatal()) return;
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
m_accumulatorOffset = initialValue;
|
||||
}
|
||||
|
||||
void AnalogInput::ResetAccumulator() {
|
||||
if (StatusIsFatal()) return;
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
int32_t status = 0;
|
||||
HAL_ResetAccumulator(m_port, &status);
|
||||
wpi_setHALError(status);
|
||||
@@ -164,21 +194,27 @@ void AnalogInput::ResetAccumulator() {
|
||||
}
|
||||
|
||||
void AnalogInput::SetAccumulatorCenter(int center) {
|
||||
if (StatusIsFatal()) return;
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
int32_t status = 0;
|
||||
HAL_SetAccumulatorCenter(m_port, center, &status);
|
||||
wpi_setHALError(status);
|
||||
}
|
||||
|
||||
void AnalogInput::SetAccumulatorDeadband(int deadband) {
|
||||
if (StatusIsFatal()) return;
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
int32_t status = 0;
|
||||
HAL_SetAccumulatorDeadband(m_port, deadband, &status);
|
||||
wpi_setHALError(status);
|
||||
}
|
||||
|
||||
int64_t AnalogInput::GetAccumulatorValue() const {
|
||||
if (StatusIsFatal()) return 0;
|
||||
if (StatusIsFatal()) {
|
||||
return 0;
|
||||
}
|
||||
int32_t status = 0;
|
||||
int64_t value = HAL_GetAccumulatorValue(m_port, &status);
|
||||
wpi_setHALError(status);
|
||||
@@ -186,7 +222,9 @@ int64_t AnalogInput::GetAccumulatorValue() const {
|
||||
}
|
||||
|
||||
int64_t AnalogInput::GetAccumulatorCount() const {
|
||||
if (StatusIsFatal()) return 0;
|
||||
if (StatusIsFatal()) {
|
||||
return 0;
|
||||
}
|
||||
int32_t status = 0;
|
||||
int64_t count = HAL_GetAccumulatorCount(m_port, &status);
|
||||
wpi_setHALError(status);
|
||||
@@ -194,7 +232,9 @@ int64_t AnalogInput::GetAccumulatorCount() const {
|
||||
}
|
||||
|
||||
void AnalogInput::GetAccumulatorOutput(int64_t& value, int64_t& count) const {
|
||||
if (StatusIsFatal()) return;
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
int32_t status = 0;
|
||||
HAL_GetAccumulatorOutput(m_port, &value, &count, &status);
|
||||
wpi_setHALError(status);
|
||||
@@ -215,7 +255,9 @@ double AnalogInput::GetSampleRate() {
|
||||
}
|
||||
|
||||
double AnalogInput::PIDGet() {
|
||||
if (StatusIsFatal()) return 0.0;
|
||||
if (StatusIsFatal()) {
|
||||
return 0.0;
|
||||
}
|
||||
return GetAverageVoltage();
|
||||
}
|
||||
|
||||
|
||||
@@ -44,7 +44,9 @@ AnalogOutput::AnalogOutput(int channel) {
|
||||
SendableRegistry::GetInstance().AddLW(this, "AnalogOutput", m_channel);
|
||||
}
|
||||
|
||||
AnalogOutput::~AnalogOutput() { HAL_FreeAnalogOutputPort(m_port); }
|
||||
AnalogOutput::~AnalogOutput() {
|
||||
HAL_FreeAnalogOutputPort(m_port);
|
||||
}
|
||||
|
||||
void AnalogOutput::SetVoltage(double voltage) {
|
||||
int32_t status = 0;
|
||||
@@ -62,7 +64,9 @@ double AnalogOutput::GetVoltage() const {
|
||||
return voltage;
|
||||
}
|
||||
|
||||
int AnalogOutput::GetChannel() const { return m_channel; }
|
||||
int AnalogOutput::GetChannel() const {
|
||||
return m_channel;
|
||||
}
|
||||
|
||||
void AnalogOutput::InitSendable(SendableBuilder& builder) {
|
||||
builder.SetSmartDashboardType("Analog Output");
|
||||
|
||||
@@ -38,7 +38,9 @@ double AnalogPotentiometer::Get() const {
|
||||
m_offset;
|
||||
}
|
||||
|
||||
double AnalogPotentiometer::PIDGet() { return Get(); }
|
||||
double AnalogPotentiometer::PIDGet() {
|
||||
return Get();
|
||||
}
|
||||
|
||||
void AnalogPotentiometer::InitSendable(SendableBuilder& builder) {
|
||||
builder.SetSmartDashboardType("Analog Input");
|
||||
|
||||
@@ -83,42 +83,54 @@ AnalogTrigger& AnalogTrigger::operator=(AnalogTrigger&& rhs) {
|
||||
}
|
||||
|
||||
void AnalogTrigger::SetLimitsVoltage(double lower, double upper) {
|
||||
if (StatusIsFatal()) return;
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
int32_t status = 0;
|
||||
HAL_SetAnalogTriggerLimitsVoltage(m_trigger, lower, upper, &status);
|
||||
wpi_setHALError(status);
|
||||
}
|
||||
|
||||
void AnalogTrigger::SetLimitsDutyCycle(double lower, double upper) {
|
||||
if (StatusIsFatal()) return;
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
int32_t status = 0;
|
||||
HAL_SetAnalogTriggerLimitsDutyCycle(m_trigger, lower, upper, &status);
|
||||
wpi_setHALError(status);
|
||||
}
|
||||
|
||||
void AnalogTrigger::SetLimitsRaw(int lower, int upper) {
|
||||
if (StatusIsFatal()) return;
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
int32_t status = 0;
|
||||
HAL_SetAnalogTriggerLimitsRaw(m_trigger, lower, upper, &status);
|
||||
wpi_setHALError(status);
|
||||
}
|
||||
|
||||
void AnalogTrigger::SetAveraged(bool useAveragedValue) {
|
||||
if (StatusIsFatal()) return;
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
int32_t status = 0;
|
||||
HAL_SetAnalogTriggerAveraged(m_trigger, useAveragedValue, &status);
|
||||
wpi_setHALError(status);
|
||||
}
|
||||
|
||||
void AnalogTrigger::SetFiltered(bool useFilteredValue) {
|
||||
if (StatusIsFatal()) return;
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
int32_t status = 0;
|
||||
HAL_SetAnalogTriggerFiltered(m_trigger, useFilteredValue, &status);
|
||||
wpi_setHALError(status);
|
||||
}
|
||||
|
||||
int AnalogTrigger::GetIndex() const {
|
||||
if (StatusIsFatal()) return -1;
|
||||
if (StatusIsFatal()) {
|
||||
return -1;
|
||||
}
|
||||
int32_t status = 0;
|
||||
auto ret = HAL_GetAnalogTriggerFPGAIndex(m_trigger, &status);
|
||||
wpi_setHALError(status);
|
||||
@@ -126,7 +138,9 @@ int AnalogTrigger::GetIndex() const {
|
||||
}
|
||||
|
||||
bool AnalogTrigger::GetInWindow() {
|
||||
if (StatusIsFatal()) return false;
|
||||
if (StatusIsFatal()) {
|
||||
return false;
|
||||
}
|
||||
int32_t status = 0;
|
||||
bool result = HAL_GetAnalogTriggerInWindow(m_trigger, &status);
|
||||
wpi_setHALError(status);
|
||||
@@ -134,7 +148,9 @@ bool AnalogTrigger::GetInWindow() {
|
||||
}
|
||||
|
||||
bool AnalogTrigger::GetTriggerState() {
|
||||
if (StatusIsFatal()) return false;
|
||||
if (StatusIsFatal()) {
|
||||
return false;
|
||||
}
|
||||
int32_t status = 0;
|
||||
bool result = HAL_GetAnalogTriggerTriggerState(m_trigger, &status);
|
||||
wpi_setHALError(status);
|
||||
@@ -143,11 +159,15 @@ bool AnalogTrigger::GetTriggerState() {
|
||||
|
||||
std::shared_ptr<AnalogTriggerOutput> AnalogTrigger::CreateOutput(
|
||||
AnalogTriggerType type) const {
|
||||
if (StatusIsFatal()) return nullptr;
|
||||
if (StatusIsFatal()) {
|
||||
return nullptr;
|
||||
}
|
||||
return std::shared_ptr<AnalogTriggerOutput>(
|
||||
new AnalogTriggerOutput(*this, type), NullDeleter<AnalogTriggerOutput>());
|
||||
}
|
||||
|
||||
void AnalogTrigger::InitSendable(SendableBuilder& builder) {
|
||||
if (m_ownsAnalog) m_analogInput->InitSendable(builder);
|
||||
if (m_ownsAnalog) {
|
||||
m_analogInput->InitSendable(builder);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,9 +28,13 @@ AnalogTriggerType AnalogTriggerOutput::GetAnalogTriggerTypeForRouting() const {
|
||||
return m_outputType;
|
||||
}
|
||||
|
||||
bool AnalogTriggerOutput::IsAnalogTrigger() const { return true; }
|
||||
bool AnalogTriggerOutput::IsAnalogTrigger() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
int AnalogTriggerOutput::GetChannel() const { return m_trigger->GetIndex(); }
|
||||
int AnalogTriggerOutput::GetChannel() const {
|
||||
return m_trigger->GetIndex();
|
||||
}
|
||||
|
||||
void AnalogTriggerOutput::InitSendable(SendableBuilder&) {}
|
||||
|
||||
|
||||
@@ -32,11 +32,17 @@ void BuiltInAccelerometer::SetRange(Range range) {
|
||||
HAL_SetAccelerometerActive(true);
|
||||
}
|
||||
|
||||
double BuiltInAccelerometer::GetX() { return HAL_GetAccelerometerX(); }
|
||||
double BuiltInAccelerometer::GetX() {
|
||||
return HAL_GetAccelerometerX();
|
||||
}
|
||||
|
||||
double BuiltInAccelerometer::GetY() { return HAL_GetAccelerometerY(); }
|
||||
double BuiltInAccelerometer::GetY() {
|
||||
return HAL_GetAccelerometerY();
|
||||
}
|
||||
|
||||
double BuiltInAccelerometer::GetZ() { return HAL_GetAccelerometerZ(); }
|
||||
double BuiltInAccelerometer::GetZ() {
|
||||
return HAL_GetAccelerometerZ();
|
||||
}
|
||||
|
||||
void BuiltInAccelerometer::InitSendable(SendableBuilder& builder) {
|
||||
builder.SetSmartDashboardType("3AxisAccelerometer");
|
||||
|
||||
@@ -41,7 +41,9 @@ CAN::CAN(int deviceId, int deviceManufacturer, int deviceType) {
|
||||
}
|
||||
|
||||
CAN::~CAN() {
|
||||
if (StatusIsFatal()) return;
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
if (m_handle != HAL_kInvalidHandle) {
|
||||
HAL_CleanCAN(m_handle);
|
||||
m_handle = HAL_kInvalidHandle;
|
||||
|
||||
@@ -29,17 +29,23 @@ Compressor::Compressor(int pcmID) : m_module(pcmID) {
|
||||
}
|
||||
|
||||
void Compressor::Start() {
|
||||
if (StatusIsFatal()) return;
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
SetClosedLoopControl(true);
|
||||
}
|
||||
|
||||
void Compressor::Stop() {
|
||||
if (StatusIsFatal()) return;
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
SetClosedLoopControl(false);
|
||||
}
|
||||
|
||||
bool Compressor::Enabled() const {
|
||||
if (StatusIsFatal()) return false;
|
||||
if (StatusIsFatal()) {
|
||||
return false;
|
||||
}
|
||||
int32_t status = 0;
|
||||
bool value;
|
||||
|
||||
@@ -53,7 +59,9 @@ bool Compressor::Enabled() const {
|
||||
}
|
||||
|
||||
bool Compressor::GetPressureSwitchValue() const {
|
||||
if (StatusIsFatal()) return false;
|
||||
if (StatusIsFatal()) {
|
||||
return false;
|
||||
}
|
||||
int32_t status = 0;
|
||||
bool value;
|
||||
|
||||
@@ -67,7 +75,9 @@ bool Compressor::GetPressureSwitchValue() const {
|
||||
}
|
||||
|
||||
double Compressor::GetCompressorCurrent() const {
|
||||
if (StatusIsFatal()) return 0;
|
||||
if (StatusIsFatal()) {
|
||||
return 0;
|
||||
}
|
||||
int32_t status = 0;
|
||||
double value;
|
||||
|
||||
@@ -81,7 +91,9 @@ double Compressor::GetCompressorCurrent() const {
|
||||
}
|
||||
|
||||
void Compressor::SetClosedLoopControl(bool on) {
|
||||
if (StatusIsFatal()) return;
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
int32_t status = 0;
|
||||
|
||||
HAL_SetCompressorClosedLoopControl(m_compressorHandle, on, &status);
|
||||
@@ -92,7 +104,9 @@ void Compressor::SetClosedLoopControl(bool on) {
|
||||
}
|
||||
|
||||
bool Compressor::GetClosedLoopControl() const {
|
||||
if (StatusIsFatal()) return false;
|
||||
if (StatusIsFatal()) {
|
||||
return false;
|
||||
}
|
||||
int32_t status = 0;
|
||||
bool value;
|
||||
|
||||
@@ -106,7 +120,9 @@ bool Compressor::GetClosedLoopControl() const {
|
||||
}
|
||||
|
||||
bool Compressor::GetCompressorCurrentTooHighFault() const {
|
||||
if (StatusIsFatal()) return false;
|
||||
if (StatusIsFatal()) {
|
||||
return false;
|
||||
}
|
||||
int32_t status = 0;
|
||||
bool value;
|
||||
|
||||
@@ -120,7 +136,9 @@ bool Compressor::GetCompressorCurrentTooHighFault() const {
|
||||
}
|
||||
|
||||
bool Compressor::GetCompressorCurrentTooHighStickyFault() const {
|
||||
if (StatusIsFatal()) return false;
|
||||
if (StatusIsFatal()) {
|
||||
return false;
|
||||
}
|
||||
int32_t status = 0;
|
||||
bool value;
|
||||
|
||||
@@ -135,7 +153,9 @@ bool Compressor::GetCompressorCurrentTooHighStickyFault() const {
|
||||
}
|
||||
|
||||
bool Compressor::GetCompressorShortedStickyFault() const {
|
||||
if (StatusIsFatal()) return false;
|
||||
if (StatusIsFatal()) {
|
||||
return false;
|
||||
}
|
||||
int32_t status = 0;
|
||||
bool value;
|
||||
|
||||
@@ -149,7 +169,9 @@ bool Compressor::GetCompressorShortedStickyFault() const {
|
||||
}
|
||||
|
||||
bool Compressor::GetCompressorShortedFault() const {
|
||||
if (StatusIsFatal()) return false;
|
||||
if (StatusIsFatal()) {
|
||||
return false;
|
||||
}
|
||||
int32_t status = 0;
|
||||
bool value;
|
||||
|
||||
@@ -163,7 +185,9 @@ bool Compressor::GetCompressorShortedFault() const {
|
||||
}
|
||||
|
||||
bool Compressor::GetCompressorNotConnectedStickyFault() const {
|
||||
if (StatusIsFatal()) return false;
|
||||
if (StatusIsFatal()) {
|
||||
return false;
|
||||
}
|
||||
int32_t status = 0;
|
||||
bool value;
|
||||
|
||||
@@ -177,7 +201,9 @@ bool Compressor::GetCompressorNotConnectedStickyFault() const {
|
||||
}
|
||||
|
||||
bool Compressor::GetCompressorNotConnectedFault() const {
|
||||
if (StatusIsFatal()) return false;
|
||||
if (StatusIsFatal()) {
|
||||
return false;
|
||||
}
|
||||
int32_t status = 0;
|
||||
bool value;
|
||||
|
||||
@@ -191,7 +217,9 @@ bool Compressor::GetCompressorNotConnectedFault() const {
|
||||
}
|
||||
|
||||
void Compressor::ClearAllPCMStickyFaults() {
|
||||
if (StatusIsFatal()) return;
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
int32_t status = 0;
|
||||
|
||||
HAL_ClearAllPCMStickyFaults(m_module, &status);
|
||||
@@ -201,17 +229,20 @@ void Compressor::ClearAllPCMStickyFaults() {
|
||||
}
|
||||
}
|
||||
|
||||
int Compressor::GetModule() const { return m_module; }
|
||||
int Compressor::GetModule() const {
|
||||
return m_module;
|
||||
}
|
||||
|
||||
void Compressor::InitSendable(SendableBuilder& builder) {
|
||||
builder.SetSmartDashboardType("Compressor");
|
||||
builder.AddBooleanProperty(
|
||||
"Enabled", [=]() { return Enabled(); },
|
||||
[=](bool value) {
|
||||
if (value)
|
||||
if (value) {
|
||||
Start();
|
||||
else
|
||||
} else {
|
||||
Stop();
|
||||
}
|
||||
});
|
||||
builder.AddBooleanProperty(
|
||||
"Pressure switch", [=]() { return GetPressureSwitchValue(); }, nullptr);
|
||||
|
||||
@@ -93,7 +93,9 @@ Counter::~Counter() {
|
||||
}
|
||||
|
||||
void Counter::SetUpSource(int channel) {
|
||||
if (StatusIsFatal()) return;
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
SetUpSource(std::make_shared<DigitalInput>(channel));
|
||||
SendableRegistry::GetInstance().AddChild(this, m_upSource.get());
|
||||
}
|
||||
@@ -107,7 +109,9 @@ void Counter::SetUpSource(AnalogTrigger* analogTrigger,
|
||||
|
||||
void Counter::SetUpSource(std::shared_ptr<AnalogTrigger> analogTrigger,
|
||||
AnalogTriggerType triggerType) {
|
||||
if (StatusIsFatal()) return;
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
SetUpSource(analogTrigger->CreateOutput(triggerType));
|
||||
}
|
||||
|
||||
@@ -117,7 +121,9 @@ void Counter::SetUpSource(DigitalSource* source) {
|
||||
}
|
||||
|
||||
void Counter::SetUpSource(std::shared_ptr<DigitalSource> source) {
|
||||
if (StatusIsFatal()) return;
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
m_upSource = source;
|
||||
if (m_upSource->StatusIsFatal()) {
|
||||
CloneError(*m_upSource);
|
||||
@@ -137,7 +143,9 @@ void Counter::SetUpSource(DigitalSource& source) {
|
||||
}
|
||||
|
||||
void Counter::SetUpSourceEdge(bool risingEdge, bool fallingEdge) {
|
||||
if (StatusIsFatal()) return;
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
if (m_upSource == nullptr) {
|
||||
wpi_setWPIErrorWithContext(
|
||||
NullParameter,
|
||||
@@ -149,7 +157,9 @@ void Counter::SetUpSourceEdge(bool risingEdge, bool fallingEdge) {
|
||||
}
|
||||
|
||||
void Counter::ClearUpSource() {
|
||||
if (StatusIsFatal()) return;
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
m_upSource.reset();
|
||||
int32_t status = 0;
|
||||
HAL_ClearCounterUpSource(m_counter, &status);
|
||||
@@ -157,7 +167,9 @@ void Counter::ClearUpSource() {
|
||||
}
|
||||
|
||||
void Counter::SetDownSource(int channel) {
|
||||
if (StatusIsFatal()) return;
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
SetDownSource(std::make_shared<DigitalInput>(channel));
|
||||
SendableRegistry::GetInstance().AddChild(this, m_downSource.get());
|
||||
}
|
||||
@@ -171,7 +183,9 @@ void Counter::SetDownSource(AnalogTrigger* analogTrigger,
|
||||
|
||||
void Counter::SetDownSource(std::shared_ptr<AnalogTrigger> analogTrigger,
|
||||
AnalogTriggerType triggerType) {
|
||||
if (StatusIsFatal()) return;
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
SetDownSource(analogTrigger->CreateOutput(triggerType));
|
||||
}
|
||||
|
||||
@@ -186,7 +200,9 @@ void Counter::SetDownSource(DigitalSource& source) {
|
||||
}
|
||||
|
||||
void Counter::SetDownSource(std::shared_ptr<DigitalSource> source) {
|
||||
if (StatusIsFatal()) return;
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
m_downSource = source;
|
||||
if (m_downSource->StatusIsFatal()) {
|
||||
CloneError(*m_downSource);
|
||||
@@ -201,7 +217,9 @@ void Counter::SetDownSource(std::shared_ptr<DigitalSource> source) {
|
||||
}
|
||||
|
||||
void Counter::SetDownSourceEdge(bool risingEdge, bool fallingEdge) {
|
||||
if (StatusIsFatal()) return;
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
if (m_downSource == nullptr) {
|
||||
wpi_setWPIErrorWithContext(
|
||||
NullParameter,
|
||||
@@ -213,7 +231,9 @@ void Counter::SetDownSourceEdge(bool risingEdge, bool fallingEdge) {
|
||||
}
|
||||
|
||||
void Counter::ClearDownSource() {
|
||||
if (StatusIsFatal()) return;
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
m_downSource.reset();
|
||||
int32_t status = 0;
|
||||
HAL_ClearCounterDownSource(m_counter, &status);
|
||||
@@ -221,35 +241,45 @@ void Counter::ClearDownSource() {
|
||||
}
|
||||
|
||||
void Counter::SetUpDownCounterMode() {
|
||||
if (StatusIsFatal()) return;
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
int32_t status = 0;
|
||||
HAL_SetCounterUpDownMode(m_counter, &status);
|
||||
wpi_setHALError(status);
|
||||
}
|
||||
|
||||
void Counter::SetExternalDirectionMode() {
|
||||
if (StatusIsFatal()) return;
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
int32_t status = 0;
|
||||
HAL_SetCounterExternalDirectionMode(m_counter, &status);
|
||||
wpi_setHALError(status);
|
||||
}
|
||||
|
||||
void Counter::SetSemiPeriodMode(bool highSemiPeriod) {
|
||||
if (StatusIsFatal()) return;
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
int32_t status = 0;
|
||||
HAL_SetCounterSemiPeriodMode(m_counter, highSemiPeriod, &status);
|
||||
wpi_setHALError(status);
|
||||
}
|
||||
|
||||
void Counter::SetPulseLengthMode(double threshold) {
|
||||
if (StatusIsFatal()) return;
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
int32_t status = 0;
|
||||
HAL_SetCounterPulseLengthMode(m_counter, threshold, &status);
|
||||
wpi_setHALError(status);
|
||||
}
|
||||
|
||||
void Counter::SetReverseDirection(bool reverseDirection) {
|
||||
if (StatusIsFatal()) return;
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
int32_t status = 0;
|
||||
HAL_SetCounterReverseDirection(m_counter, reverseDirection, &status);
|
||||
wpi_setHALError(status);
|
||||
@@ -273,10 +303,14 @@ int Counter::GetSamplesToAverage() const {
|
||||
return samples;
|
||||
}
|
||||
|
||||
int Counter::GetFPGAIndex() const { return m_index; }
|
||||
int Counter::GetFPGAIndex() const {
|
||||
return m_index;
|
||||
}
|
||||
|
||||
int Counter::Get() const {
|
||||
if (StatusIsFatal()) return 0;
|
||||
if (StatusIsFatal()) {
|
||||
return 0;
|
||||
}
|
||||
int32_t status = 0;
|
||||
int value = HAL_GetCounter(m_counter, &status);
|
||||
wpi_setHALError(status);
|
||||
@@ -284,14 +318,18 @@ int Counter::Get() const {
|
||||
}
|
||||
|
||||
void Counter::Reset() {
|
||||
if (StatusIsFatal()) return;
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
int32_t status = 0;
|
||||
HAL_ResetCounter(m_counter, &status);
|
||||
wpi_setHALError(status);
|
||||
}
|
||||
|
||||
double Counter::GetPeriod() const {
|
||||
if (StatusIsFatal()) return 0.0;
|
||||
if (StatusIsFatal()) {
|
||||
return 0.0;
|
||||
}
|
||||
int32_t status = 0;
|
||||
double value = HAL_GetCounterPeriod(m_counter, &status);
|
||||
wpi_setHALError(status);
|
||||
@@ -299,21 +337,27 @@ double Counter::GetPeriod() const {
|
||||
}
|
||||
|
||||
void Counter::SetMaxPeriod(double maxPeriod) {
|
||||
if (StatusIsFatal()) return;
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
int32_t status = 0;
|
||||
HAL_SetCounterMaxPeriod(m_counter, maxPeriod, &status);
|
||||
wpi_setHALError(status);
|
||||
}
|
||||
|
||||
void Counter::SetUpdateWhenEmpty(bool enabled) {
|
||||
if (StatusIsFatal()) return;
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
int32_t status = 0;
|
||||
HAL_SetCounterUpdateWhenEmpty(m_counter, enabled, &status);
|
||||
wpi_setHALError(status);
|
||||
}
|
||||
|
||||
bool Counter::GetStopped() const {
|
||||
if (StatusIsFatal()) return false;
|
||||
if (StatusIsFatal()) {
|
||||
return false;
|
||||
}
|
||||
int32_t status = 0;
|
||||
bool value = HAL_GetCounterStopped(m_counter, &status);
|
||||
wpi_setHALError(status);
|
||||
@@ -321,7 +365,9 @@ bool Counter::GetStopped() const {
|
||||
}
|
||||
|
||||
bool Counter::GetDirection() const {
|
||||
if (StatusIsFatal()) return false;
|
||||
if (StatusIsFatal()) {
|
||||
return false;
|
||||
}
|
||||
int32_t status = 0;
|
||||
bool value = HAL_GetCounterDirection(m_counter, &status);
|
||||
wpi_setHALError(status);
|
||||
|
||||
@@ -21,7 +21,9 @@ DMA::DMA() {
|
||||
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
|
||||
}
|
||||
|
||||
DMA::~DMA() { HAL_FreeDMA(dmaHandle); }
|
||||
DMA::~DMA() {
|
||||
HAL_FreeDMA(dmaHandle);
|
||||
}
|
||||
|
||||
void DMA::SetPause(bool pause) {
|
||||
int32_t status = 0;
|
||||
|
||||
@@ -103,7 +103,9 @@ void DigitalGlitchFilter::Add(Counter* input) {
|
||||
Add(input->m_downSource.get());
|
||||
}
|
||||
|
||||
void DigitalGlitchFilter::Remove(DigitalSource* input) { DoAdd(input, 0); }
|
||||
void DigitalGlitchFilter::Remove(DigitalSource* input) {
|
||||
DoAdd(input, 0);
|
||||
}
|
||||
|
||||
void DigitalGlitchFilter::Remove(Encoder* input) {
|
||||
Remove(input->m_aSource.get());
|
||||
|
||||
@@ -41,31 +41,41 @@ DigitalInput::DigitalInput(int channel) {
|
||||
}
|
||||
|
||||
DigitalInput::~DigitalInput() {
|
||||
if (StatusIsFatal()) return;
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
HAL_FreeDIOPort(m_handle);
|
||||
}
|
||||
|
||||
bool DigitalInput::Get() const {
|
||||
if (StatusIsFatal()) return false;
|
||||
if (StatusIsFatal()) {
|
||||
return false;
|
||||
}
|
||||
int32_t status = 0;
|
||||
bool value = HAL_GetDIO(m_handle, &status);
|
||||
wpi_setHALError(status);
|
||||
return value;
|
||||
}
|
||||
|
||||
HAL_Handle DigitalInput::GetPortHandleForRouting() const { return m_handle; }
|
||||
HAL_Handle DigitalInput::GetPortHandleForRouting() const {
|
||||
return m_handle;
|
||||
}
|
||||
|
||||
AnalogTriggerType DigitalInput::GetAnalogTriggerTypeForRouting() const {
|
||||
return (AnalogTriggerType)0;
|
||||
}
|
||||
|
||||
bool DigitalInput::IsAnalogTrigger() const { return false; }
|
||||
bool DigitalInput::IsAnalogTrigger() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
void DigitalInput::SetSimDevice(HAL_SimDeviceHandle device) {
|
||||
HAL_SetDIOSimDevice(m_handle, device);
|
||||
}
|
||||
|
||||
int DigitalInput::GetChannel() const { return m_channel; }
|
||||
int DigitalInput::GetChannel() const {
|
||||
return m_channel;
|
||||
}
|
||||
|
||||
void DigitalInput::InitSendable(SendableBuilder& builder) {
|
||||
builder.SetSmartDashboardType("Digital Input");
|
||||
|
||||
@@ -42,7 +42,9 @@ DigitalOutput::DigitalOutput(int channel) {
|
||||
}
|
||||
|
||||
DigitalOutput::~DigitalOutput() {
|
||||
if (StatusIsFatal()) return;
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
// Disable the PWM in case it was running.
|
||||
DisablePWM();
|
||||
|
||||
@@ -50,7 +52,9 @@ DigitalOutput::~DigitalOutput() {
|
||||
}
|
||||
|
||||
void DigitalOutput::Set(bool value) {
|
||||
if (StatusIsFatal()) return;
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
|
||||
int32_t status = 0;
|
||||
HAL_SetDIO(m_handle, value, &status);
|
||||
@@ -58,7 +62,9 @@ void DigitalOutput::Set(bool value) {
|
||||
}
|
||||
|
||||
bool DigitalOutput::Get() const {
|
||||
if (StatusIsFatal()) return false;
|
||||
if (StatusIsFatal()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int32_t status = 0;
|
||||
bool val = HAL_GetDIO(m_handle, &status);
|
||||
@@ -66,18 +72,26 @@ bool DigitalOutput::Get() const {
|
||||
return val;
|
||||
}
|
||||
|
||||
HAL_Handle DigitalOutput::GetPortHandleForRouting() const { return m_handle; }
|
||||
HAL_Handle DigitalOutput::GetPortHandleForRouting() const {
|
||||
return m_handle;
|
||||
}
|
||||
|
||||
AnalogTriggerType DigitalOutput::GetAnalogTriggerTypeForRouting() const {
|
||||
return (AnalogTriggerType)0;
|
||||
}
|
||||
|
||||
bool DigitalOutput::IsAnalogTrigger() const { return false; }
|
||||
bool DigitalOutput::IsAnalogTrigger() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
int DigitalOutput::GetChannel() const { return m_channel; }
|
||||
int DigitalOutput::GetChannel() const {
|
||||
return m_channel;
|
||||
}
|
||||
|
||||
void DigitalOutput::Pulse(double length) {
|
||||
if (StatusIsFatal()) return;
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
|
||||
int32_t status = 0;
|
||||
HAL_Pulse(m_handle, length, &status);
|
||||
@@ -85,7 +99,9 @@ void DigitalOutput::Pulse(double length) {
|
||||
}
|
||||
|
||||
bool DigitalOutput::IsPulsing() const {
|
||||
if (StatusIsFatal()) return false;
|
||||
if (StatusIsFatal()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int32_t status = 0;
|
||||
bool value = HAL_IsPulsing(m_handle, &status);
|
||||
@@ -94,7 +110,9 @@ bool DigitalOutput::IsPulsing() const {
|
||||
}
|
||||
|
||||
void DigitalOutput::SetPWMRate(double rate) {
|
||||
if (StatusIsFatal()) return;
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
|
||||
int32_t status = 0;
|
||||
HAL_SetDigitalPWMRate(rate, &status);
|
||||
@@ -102,26 +120,38 @@ void DigitalOutput::SetPWMRate(double rate) {
|
||||
}
|
||||
|
||||
void DigitalOutput::EnablePWM(double initialDutyCycle) {
|
||||
if (m_pwmGenerator != HAL_kInvalidHandle) return;
|
||||
if (m_pwmGenerator != HAL_kInvalidHandle) {
|
||||
return;
|
||||
}
|
||||
|
||||
int32_t status = 0;
|
||||
|
||||
if (StatusIsFatal()) return;
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
m_pwmGenerator = HAL_AllocateDigitalPWM(&status);
|
||||
wpi_setHALError(status);
|
||||
|
||||
if (StatusIsFatal()) return;
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
HAL_SetDigitalPWMDutyCycle(m_pwmGenerator, initialDutyCycle, &status);
|
||||
wpi_setHALError(status);
|
||||
|
||||
if (StatusIsFatal()) return;
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
HAL_SetDigitalPWMOutputChannel(m_pwmGenerator, m_channel, &status);
|
||||
wpi_setHALError(status);
|
||||
}
|
||||
|
||||
void DigitalOutput::DisablePWM() {
|
||||
if (StatusIsFatal()) return;
|
||||
if (m_pwmGenerator == HAL_kInvalidHandle) return;
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
if (m_pwmGenerator == HAL_kInvalidHandle) {
|
||||
return;
|
||||
}
|
||||
|
||||
int32_t status = 0;
|
||||
|
||||
@@ -137,7 +167,9 @@ void DigitalOutput::DisablePWM() {
|
||||
}
|
||||
|
||||
void DigitalOutput::UpdateDutyCycle(double dutyCycle) {
|
||||
if (StatusIsFatal()) return;
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
|
||||
int32_t status = 0;
|
||||
HAL_SetDigitalPWMDutyCycle(m_pwmGenerator, dutyCycle, &status);
|
||||
|
||||
@@ -85,7 +85,9 @@ DoubleSolenoid::~DoubleSolenoid() {
|
||||
}
|
||||
|
||||
void DoubleSolenoid::Set(Value value) {
|
||||
if (StatusIsFatal()) return;
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
|
||||
bool forward = false;
|
||||
bool reverse = false;
|
||||
@@ -115,7 +117,9 @@ void DoubleSolenoid::Set(Value value) {
|
||||
}
|
||||
|
||||
DoubleSolenoid::Value DoubleSolenoid::Get() const {
|
||||
if (StatusIsFatal()) return kOff;
|
||||
if (StatusIsFatal()) {
|
||||
return kOff;
|
||||
}
|
||||
|
||||
int fstatus = 0;
|
||||
int rstatus = 0;
|
||||
@@ -172,10 +176,11 @@ void DoubleSolenoid::InitSendable(SendableBuilder& builder) {
|
||||
},
|
||||
[=](wpi::StringRef value) {
|
||||
Value lvalue = kOff;
|
||||
if (value == "Forward")
|
||||
if (value == "Forward") {
|
||||
lvalue = kForward;
|
||||
else if (value == "Reverse")
|
||||
} else if (value == "Reverse") {
|
||||
lvalue = kReverse;
|
||||
}
|
||||
Set(lvalue);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -421,7 +421,9 @@ bool DriverStation::IsNewControlData() const {
|
||||
std::unique_lock lock(m_waitForDataMutex);
|
||||
int& lastCount = GetDSLastCount();
|
||||
int currentCount = m_waitForDataCounter;
|
||||
if (lastCount == currentCount) return false;
|
||||
if (lastCount == currentCount) {
|
||||
return false;
|
||||
}
|
||||
lastCount = currentCount;
|
||||
return true;
|
||||
}
|
||||
@@ -498,7 +500,9 @@ int DriverStation::GetLocation() const {
|
||||
}
|
||||
}
|
||||
|
||||
void DriverStation::WaitForData() { WaitForData(0); }
|
||||
void DriverStation::WaitForData() {
|
||||
WaitForData(0);
|
||||
}
|
||||
|
||||
bool DriverStation::WaitForData(double timeout) {
|
||||
auto timeoutTime =
|
||||
@@ -621,16 +625,26 @@ void DriverStation::Run() {
|
||||
HAL_WaitForDSData();
|
||||
GetData();
|
||||
|
||||
if (IsDisabled()) safetyCounter = 0;
|
||||
if (IsDisabled()) {
|
||||
safetyCounter = 0;
|
||||
}
|
||||
|
||||
if (++safetyCounter >= 4) {
|
||||
MotorSafety::CheckMotors();
|
||||
safetyCounter = 0;
|
||||
}
|
||||
if (m_userInDisabled) HAL_ObserveUserProgramDisabled();
|
||||
if (m_userInAutonomous) HAL_ObserveUserProgramAutonomous();
|
||||
if (m_userInTeleop) HAL_ObserveUserProgramTeleop();
|
||||
if (m_userInTest) HAL_ObserveUserProgramTest();
|
||||
if (m_userInDisabled) {
|
||||
HAL_ObserveUserProgramDisabled();
|
||||
}
|
||||
if (m_userInAutonomous) {
|
||||
HAL_ObserveUserProgramAutonomous();
|
||||
}
|
||||
if (m_userInTeleop) {
|
||||
HAL_ObserveUserProgramTeleop();
|
||||
}
|
||||
if (m_userInTest) {
|
||||
HAL_ObserveUserProgramTest();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -37,7 +37,9 @@ DutyCycle::DutyCycle(std::shared_ptr<DigitalSource> source)
|
||||
}
|
||||
}
|
||||
|
||||
DutyCycle::~DutyCycle() { HAL_FreeDutyCycle(m_handle); }
|
||||
DutyCycle::~DutyCycle() {
|
||||
HAL_FreeDutyCycle(m_handle);
|
||||
}
|
||||
|
||||
void DutyCycle::InitDutyCycle() {
|
||||
int32_t status = 0;
|
||||
@@ -87,7 +89,9 @@ unsigned int DutyCycle::GetOutputScaleFactor() const {
|
||||
return retVal;
|
||||
}
|
||||
|
||||
int DutyCycle::GetSourceChannel() const { return m_source->GetChannel(); }
|
||||
int DutyCycle::GetSourceChannel() const {
|
||||
return m_source->GetChannel();
|
||||
}
|
||||
|
||||
void DutyCycle::InitSendable(SendableBuilder& builder) {
|
||||
builder.SetSmartDashboardType("Duty Cycle");
|
||||
|
||||
@@ -76,7 +76,9 @@ void DutyCycleEncoder::Init() {
|
||||
}
|
||||
|
||||
units::turn_t DutyCycleEncoder::Get() const {
|
||||
if (m_simPosition) return units::turn_t{m_simPosition.Get()};
|
||||
if (m_simPosition) {
|
||||
return units::turn_t{m_simPosition.Get()};
|
||||
}
|
||||
|
||||
// As the values are not atomic, keep trying until we get 2 reads of the same
|
||||
// value If we don't within 10 attempts, error
|
||||
@@ -116,12 +118,16 @@ int DutyCycleEncoder::GetFrequency() const {
|
||||
}
|
||||
|
||||
void DutyCycleEncoder::Reset() {
|
||||
if (m_counter) m_counter->Reset();
|
||||
if (m_counter) {
|
||||
m_counter->Reset();
|
||||
}
|
||||
m_positionOffset = m_dutyCycle->GetOutput();
|
||||
}
|
||||
|
||||
bool DutyCycleEncoder::IsConnected() const {
|
||||
if (m_simIsConnected) return m_simIsConnected.Get();
|
||||
if (m_simIsConnected) {
|
||||
return m_simIsConnected.Get();
|
||||
}
|
||||
return GetFrequency() > m_frequencyThreshold;
|
||||
}
|
||||
|
||||
|
||||
@@ -31,10 +31,11 @@ Encoder::Encoder(DigitalSource* aSource, DigitalSource* bSource,
|
||||
bool reverseDirection, EncodingType encodingType)
|
||||
: m_aSource(aSource, NullDeleter<DigitalSource>()),
|
||||
m_bSource(bSource, NullDeleter<DigitalSource>()) {
|
||||
if (m_aSource == nullptr || m_bSource == nullptr)
|
||||
if (m_aSource == nullptr || m_bSource == nullptr) {
|
||||
wpi_setWPIError(NullParameter);
|
||||
else
|
||||
} else {
|
||||
InitEncoder(reverseDirection, encodingType);
|
||||
}
|
||||
}
|
||||
|
||||
Encoder::Encoder(DigitalSource& aSource, DigitalSource& bSource,
|
||||
@@ -48,10 +49,11 @@ Encoder::Encoder(std::shared_ptr<DigitalSource> aSource,
|
||||
std::shared_ptr<DigitalSource> bSource, bool reverseDirection,
|
||||
EncodingType encodingType)
|
||||
: m_aSource(aSource), m_bSource(bSource) {
|
||||
if (m_aSource == nullptr || m_bSource == nullptr)
|
||||
if (m_aSource == nullptr || m_bSource == nullptr) {
|
||||
wpi_setWPIError(NullParameter);
|
||||
else
|
||||
} else {
|
||||
InitEncoder(reverseDirection, encodingType);
|
||||
}
|
||||
}
|
||||
|
||||
Encoder::~Encoder() {
|
||||
@@ -61,7 +63,9 @@ Encoder::~Encoder() {
|
||||
}
|
||||
|
||||
int Encoder::Get() const {
|
||||
if (StatusIsFatal()) return 0;
|
||||
if (StatusIsFatal()) {
|
||||
return 0;
|
||||
}
|
||||
int32_t status = 0;
|
||||
int value = HAL_GetEncoder(m_encoder, &status);
|
||||
wpi_setHALError(status);
|
||||
@@ -69,14 +73,18 @@ int Encoder::Get() const {
|
||||
}
|
||||
|
||||
void Encoder::Reset() {
|
||||
if (StatusIsFatal()) return;
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
int32_t status = 0;
|
||||
HAL_ResetEncoder(m_encoder, &status);
|
||||
wpi_setHALError(status);
|
||||
}
|
||||
|
||||
double Encoder::GetPeriod() const {
|
||||
if (StatusIsFatal()) return 0.0;
|
||||
if (StatusIsFatal()) {
|
||||
return 0.0;
|
||||
}
|
||||
int32_t status = 0;
|
||||
double value = HAL_GetEncoderPeriod(m_encoder, &status);
|
||||
wpi_setHALError(status);
|
||||
@@ -84,14 +92,18 @@ double Encoder::GetPeriod() const {
|
||||
}
|
||||
|
||||
void Encoder::SetMaxPeriod(double maxPeriod) {
|
||||
if (StatusIsFatal()) return;
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
int32_t status = 0;
|
||||
HAL_SetEncoderMaxPeriod(m_encoder, maxPeriod, &status);
|
||||
wpi_setHALError(status);
|
||||
}
|
||||
|
||||
bool Encoder::GetStopped() const {
|
||||
if (StatusIsFatal()) return true;
|
||||
if (StatusIsFatal()) {
|
||||
return true;
|
||||
}
|
||||
int32_t status = 0;
|
||||
bool value = HAL_GetEncoderStopped(m_encoder, &status);
|
||||
wpi_setHALError(status);
|
||||
@@ -99,7 +111,9 @@ bool Encoder::GetStopped() const {
|
||||
}
|
||||
|
||||
bool Encoder::GetDirection() const {
|
||||
if (StatusIsFatal()) return false;
|
||||
if (StatusIsFatal()) {
|
||||
return false;
|
||||
}
|
||||
int32_t status = 0;
|
||||
bool value = HAL_GetEncoderDirection(m_encoder, &status);
|
||||
wpi_setHALError(status);
|
||||
@@ -107,7 +121,9 @@ bool Encoder::GetDirection() const {
|
||||
}
|
||||
|
||||
int Encoder::GetRaw() const {
|
||||
if (StatusIsFatal()) return 0;
|
||||
if (StatusIsFatal()) {
|
||||
return 0;
|
||||
}
|
||||
int32_t status = 0;
|
||||
int value = HAL_GetEncoderRaw(m_encoder, &status);
|
||||
wpi_setHALError(status);
|
||||
@@ -122,7 +138,9 @@ int Encoder::GetEncodingScale() const {
|
||||
}
|
||||
|
||||
double Encoder::GetDistance() const {
|
||||
if (StatusIsFatal()) return 0.0;
|
||||
if (StatusIsFatal()) {
|
||||
return 0.0;
|
||||
}
|
||||
int32_t status = 0;
|
||||
double value = HAL_GetEncoderDistance(m_encoder, &status);
|
||||
wpi_setHALError(status);
|
||||
@@ -130,7 +148,9 @@ double Encoder::GetDistance() const {
|
||||
}
|
||||
|
||||
double Encoder::GetRate() const {
|
||||
if (StatusIsFatal()) return 0.0;
|
||||
if (StatusIsFatal()) {
|
||||
return 0.0;
|
||||
}
|
||||
int32_t status = 0;
|
||||
double value = HAL_GetEncoderRate(m_encoder, &status);
|
||||
wpi_setHALError(status);
|
||||
@@ -138,21 +158,27 @@ double Encoder::GetRate() const {
|
||||
}
|
||||
|
||||
void Encoder::SetMinRate(double minRate) {
|
||||
if (StatusIsFatal()) return;
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
int32_t status = 0;
|
||||
HAL_SetEncoderMinRate(m_encoder, minRate, &status);
|
||||
wpi_setHALError(status);
|
||||
}
|
||||
|
||||
void Encoder::SetDistancePerPulse(double distancePerPulse) {
|
||||
if (StatusIsFatal()) return;
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
int32_t status = 0;
|
||||
HAL_SetEncoderDistancePerPulse(m_encoder, distancePerPulse, &status);
|
||||
wpi_setHALError(status);
|
||||
}
|
||||
|
||||
double Encoder::GetDistancePerPulse() const {
|
||||
if (StatusIsFatal()) return 0.0;
|
||||
if (StatusIsFatal()) {
|
||||
return 0.0;
|
||||
}
|
||||
int32_t status = 0;
|
||||
double distancePerPulse = HAL_GetEncoderDistancePerPulse(m_encoder, &status);
|
||||
wpi_setHALError(status);
|
||||
@@ -160,7 +186,9 @@ double Encoder::GetDistancePerPulse() const {
|
||||
}
|
||||
|
||||
void Encoder::SetReverseDirection(bool reverseDirection) {
|
||||
if (StatusIsFatal()) return;
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
int32_t status = 0;
|
||||
HAL_SetEncoderReverseDirection(m_encoder, reverseDirection, &status);
|
||||
wpi_setHALError(status);
|
||||
@@ -186,7 +214,9 @@ int Encoder::GetSamplesToAverage() const {
|
||||
}
|
||||
|
||||
double Encoder::PIDGet() {
|
||||
if (StatusIsFatal()) return 0.0;
|
||||
if (StatusIsFatal()) {
|
||||
return 0.0;
|
||||
}
|
||||
switch (GetPIDSourceType()) {
|
||||
case PIDSourceType::kDisplacement:
|
||||
return GetDistance();
|
||||
@@ -229,10 +259,11 @@ void Encoder::InitSendable(SendableBuilder& builder) {
|
||||
int32_t status = 0;
|
||||
HAL_EncoderEncodingType type = HAL_GetEncoderEncodingType(m_encoder, &status);
|
||||
wpi_setHALError(status);
|
||||
if (type == HAL_EncoderEncodingType::HAL_Encoder_k4X)
|
||||
if (type == HAL_EncoderEncodingType::HAL_Encoder_k4X) {
|
||||
builder.SetSmartDashboardType("Quadrature Encoder");
|
||||
else
|
||||
} else {
|
||||
builder.SetSmartDashboardType("Encoder");
|
||||
}
|
||||
|
||||
builder.AddDoubleProperty(
|
||||
"Speed", [=]() { return GetRate(); }, nullptr);
|
||||
@@ -259,7 +290,9 @@ void Encoder::InitEncoder(bool reverseDirection, EncodingType encodingType) {
|
||||
}
|
||||
|
||||
double Encoder::DecodingScaleFactor() const {
|
||||
if (StatusIsFatal()) return 0.0;
|
||||
if (StatusIsFatal()) {
|
||||
return 0.0;
|
||||
}
|
||||
int32_t status = 0;
|
||||
double val = HAL_GetEncoderDecodingScaleFactor(m_encoder, &status);
|
||||
wpi_setHALError(status);
|
||||
|
||||
@@ -39,21 +39,33 @@ bool Error::operator<(const Error& rhs) const {
|
||||
}
|
||||
}
|
||||
|
||||
Error::Code Error::GetCode() const { return m_code; }
|
||||
Error::Code Error::GetCode() const {
|
||||
return m_code;
|
||||
}
|
||||
|
||||
std::string Error::GetMessage() const { return m_message; }
|
||||
std::string Error::GetMessage() const {
|
||||
return m_message;
|
||||
}
|
||||
|
||||
std::string Error::GetFilename() const { return m_filename; }
|
||||
std::string Error::GetFilename() const {
|
||||
return m_filename;
|
||||
}
|
||||
|
||||
std::string Error::GetFunction() const { return m_function; }
|
||||
std::string Error::GetFunction() const {
|
||||
return m_function;
|
||||
}
|
||||
|
||||
int Error::GetLineNumber() const { return m_lineNumber; }
|
||||
int Error::GetLineNumber() const {
|
||||
return m_lineNumber;
|
||||
}
|
||||
|
||||
const ErrorBase* Error::GetOriginatingObject() const {
|
||||
return m_originatingObject;
|
||||
}
|
||||
|
||||
double Error::GetTimestamp() const { return m_timestamp; }
|
||||
double Error::GetTimestamp() const {
|
||||
return m_timestamp;
|
||||
}
|
||||
|
||||
void Error::Set(Code code, const wpi::Twine& contextMessage,
|
||||
wpi::StringRef filename, wpi::StringRef function,
|
||||
|
||||
@@ -48,13 +48,21 @@ void GlobalErrors::Insert(Error&& error) {
|
||||
inst.lastError = &(*inst.errors.insert(std::move(error)).first);
|
||||
}
|
||||
|
||||
ErrorBase::ErrorBase() { HAL_Initialize(500, 0); }
|
||||
ErrorBase::ErrorBase() {
|
||||
HAL_Initialize(500, 0);
|
||||
}
|
||||
|
||||
Error& ErrorBase::GetError() { return m_error; }
|
||||
Error& ErrorBase::GetError() {
|
||||
return m_error;
|
||||
}
|
||||
|
||||
const Error& ErrorBase::GetError() const { return m_error; }
|
||||
const Error& ErrorBase::GetError() const {
|
||||
return m_error;
|
||||
}
|
||||
|
||||
void ErrorBase::ClearError() const { m_error.Clear(); }
|
||||
void ErrorBase::ClearError() const {
|
||||
m_error.Clear();
|
||||
}
|
||||
|
||||
void ErrorBase::SetErrnoError(const wpi::Twine& contextMessage,
|
||||
wpi::StringRef filename, wpi::StringRef function,
|
||||
@@ -139,7 +147,9 @@ void ErrorBase::CloneError(const ErrorBase& rhs) const {
|
||||
m_error = rhs.GetError();
|
||||
}
|
||||
|
||||
bool ErrorBase::StatusIsFatal() const { return m_error.GetCode() < 0; }
|
||||
bool ErrorBase::StatusIsFatal() const {
|
||||
return m_error.GetCode() < 0;
|
||||
}
|
||||
|
||||
void ErrorBase::SetGlobalError(Error::Code code,
|
||||
const wpi::Twine& contextMessage,
|
||||
@@ -164,7 +174,9 @@ void ErrorBase::SetGlobalWPIError(const wpi::Twine& errorMessage,
|
||||
Error ErrorBase::GetGlobalError() {
|
||||
auto& inst = GlobalErrors::GetInstance();
|
||||
std::scoped_lock mutex(inst.mutex);
|
||||
if (!inst.lastError) return Error{};
|
||||
if (!inst.lastError) {
|
||||
return {};
|
||||
}
|
||||
return *inst.lastError;
|
||||
}
|
||||
|
||||
@@ -172,7 +184,9 @@ std::vector<Error> ErrorBase::GetGlobalErrors() {
|
||||
auto& inst = GlobalErrors::GetInstance();
|
||||
std::scoped_lock mutex(inst.mutex);
|
||||
std::vector<Error> rv;
|
||||
for (auto&& error : inst.errors) rv.push_back(error);
|
||||
for (auto&& error : inst.errors) {
|
||||
rv.push_back(error);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
@@ -34,11 +34,17 @@ double GenericHID::GetRawAxis(int axis) const {
|
||||
return m_ds->GetStickAxis(m_port, axis);
|
||||
}
|
||||
|
||||
int GenericHID::GetPOV(int pov) const { return m_ds->GetStickPOV(m_port, pov); }
|
||||
int GenericHID::GetPOV(int pov) const {
|
||||
return m_ds->GetStickPOV(m_port, pov);
|
||||
}
|
||||
|
||||
int GenericHID::GetAxisCount() const { return m_ds->GetStickAxisCount(m_port); }
|
||||
int GenericHID::GetAxisCount() const {
|
||||
return m_ds->GetStickAxisCount(m_port);
|
||||
}
|
||||
|
||||
int GenericHID::GetPOVCount() const { return m_ds->GetStickPOVCount(m_port); }
|
||||
int GenericHID::GetPOVCount() const {
|
||||
return m_ds->GetStickPOVCount(m_port);
|
||||
}
|
||||
|
||||
int GenericHID::GetButtonCount() const {
|
||||
return m_ds->GetStickButtonCount(m_port);
|
||||
@@ -60,7 +66,9 @@ int GenericHID::GetAxisType(int axis) const {
|
||||
return m_ds->GetJoystickAxisType(m_port, axis);
|
||||
}
|
||||
|
||||
int GenericHID::GetPort() const { return m_port; }
|
||||
int GenericHID::GetPort() const {
|
||||
return m_port;
|
||||
}
|
||||
|
||||
void GenericHID::SetOutput(int outputNumber, bool value) {
|
||||
m_outputs =
|
||||
@@ -75,10 +83,11 @@ void GenericHID::SetOutputs(int value) {
|
||||
}
|
||||
|
||||
void GenericHID::SetRumble(RumbleType type, double value) {
|
||||
if (value < 0)
|
||||
if (value < 0) {
|
||||
value = 0;
|
||||
else if (value > 1)
|
||||
} else if (value > 1) {
|
||||
value = 1;
|
||||
}
|
||||
if (type == kLeftRumble) {
|
||||
m_leftRumble = value * 65535;
|
||||
} else {
|
||||
|
||||
@@ -22,7 +22,9 @@ I2C::I2C(Port port, int deviceAddress)
|
||||
HAL_Report(HALUsageReporting::kResourceType_I2C, deviceAddress);
|
||||
}
|
||||
|
||||
I2C::~I2C() { HAL_CloseI2C(m_port); }
|
||||
I2C::~I2C() {
|
||||
HAL_CloseI2C(m_port);
|
||||
}
|
||||
|
||||
bool I2C::Transaction(uint8_t* dataToSend, int sendSize, uint8_t* dataReceived,
|
||||
int receiveSize) {
|
||||
@@ -33,7 +35,9 @@ bool I2C::Transaction(uint8_t* dataToSend, int sendSize, uint8_t* dataReceived,
|
||||
return status < 0;
|
||||
}
|
||||
|
||||
bool I2C::AddressOnly() { return Transaction(nullptr, 0, nullptr, 0); }
|
||||
bool I2C::AddressOnly() {
|
||||
return Transaction(nullptr, 0, nullptr, 0);
|
||||
}
|
||||
|
||||
bool I2C::Write(int registerAddress, uint8_t data) {
|
||||
uint8_t buffer[2];
|
||||
@@ -83,10 +87,14 @@ bool I2C::VerifySensor(int registerAddress, int count,
|
||||
i += 4, curRegisterAddress += 4) {
|
||||
int toRead = count - i < 4 ? count - i : 4;
|
||||
// Read the chunk of data. Return false if the sensor does not respond.
|
||||
if (Read(curRegisterAddress, toRead, deviceData)) return false;
|
||||
if (Read(curRegisterAddress, toRead, deviceData)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int j = 0; j < toRead; j++) {
|
||||
if (deviceData[j] != expected[i + j]) return false;
|
||||
if (deviceData[j] != expected[i + j]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
@@ -10,7 +10,9 @@
|
||||
using namespace frc;
|
||||
|
||||
InterruptableSensorBase::~InterruptableSensorBase() {
|
||||
if (m_interrupt == HAL_kInvalidHandle) return;
|
||||
if (m_interrupt == HAL_kInvalidHandle) {
|
||||
return;
|
||||
}
|
||||
int32_t status = 0;
|
||||
HAL_CleanInterrupts(m_interrupt, &status);
|
||||
// Ignore status, as an invalid handle just needs to be ignored.
|
||||
@@ -18,11 +20,15 @@ InterruptableSensorBase::~InterruptableSensorBase() {
|
||||
|
||||
void InterruptableSensorBase::RequestInterrupts(
|
||||
HAL_InterruptHandlerFunction handler, void* param) {
|
||||
if (StatusIsFatal()) return;
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
|
||||
wpi_assert(m_interrupt == HAL_kInvalidHandle);
|
||||
AllocateInterrupts(false);
|
||||
if (StatusIsFatal()) return; // if allocate failed, out of interrupts
|
||||
if (StatusIsFatal()) {
|
||||
return; // if allocate failed, out of interrupts
|
||||
}
|
||||
|
||||
int32_t status = 0;
|
||||
HAL_RequestInterrupts(
|
||||
@@ -35,11 +41,15 @@ void InterruptableSensorBase::RequestInterrupts(
|
||||
}
|
||||
|
||||
void InterruptableSensorBase::RequestInterrupts(InterruptEventHandler handler) {
|
||||
if (StatusIsFatal()) return;
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
|
||||
wpi_assert(m_interrupt == HAL_kInvalidHandle);
|
||||
AllocateInterrupts(false);
|
||||
if (StatusIsFatal()) return; // if allocate failed, out of interrupts
|
||||
if (StatusIsFatal()) {
|
||||
return; // if allocate failed, out of interrupts
|
||||
}
|
||||
|
||||
m_interruptHandler =
|
||||
std::make_unique<InterruptEventHandler>(std::move(handler));
|
||||
@@ -68,11 +78,15 @@ void InterruptableSensorBase::RequestInterrupts(InterruptEventHandler handler) {
|
||||
}
|
||||
|
||||
void InterruptableSensorBase::RequestInterrupts() {
|
||||
if (StatusIsFatal()) return;
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
|
||||
wpi_assert(m_interrupt == HAL_kInvalidHandle);
|
||||
AllocateInterrupts(true);
|
||||
if (StatusIsFatal()) return; // if allocate failed, out of interrupts
|
||||
if (StatusIsFatal()) {
|
||||
return; // if allocate failed, out of interrupts
|
||||
}
|
||||
|
||||
int32_t status = 0;
|
||||
HAL_RequestInterrupts(
|
||||
@@ -84,7 +98,9 @@ void InterruptableSensorBase::RequestInterrupts() {
|
||||
}
|
||||
|
||||
void InterruptableSensorBase::CancelInterrupts() {
|
||||
if (StatusIsFatal()) return;
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
wpi_assert(m_interrupt != HAL_kInvalidHandle);
|
||||
int32_t status = 0;
|
||||
HAL_CleanInterrupts(m_interrupt, &status);
|
||||
@@ -95,7 +111,9 @@ void InterruptableSensorBase::CancelInterrupts() {
|
||||
|
||||
InterruptableSensorBase::WaitResult InterruptableSensorBase::WaitForInterrupt(
|
||||
double timeout, bool ignorePrevious) {
|
||||
if (StatusIsFatal()) return InterruptableSensorBase::kTimeout;
|
||||
if (StatusIsFatal()) {
|
||||
return InterruptableSensorBase::kTimeout;
|
||||
}
|
||||
wpi_assert(m_interrupt != HAL_kInvalidHandle);
|
||||
int32_t status = 0;
|
||||
int result;
|
||||
@@ -113,7 +131,9 @@ InterruptableSensorBase::WaitResult InterruptableSensorBase::WaitForInterrupt(
|
||||
}
|
||||
|
||||
void InterruptableSensorBase::EnableInterrupts() {
|
||||
if (StatusIsFatal()) return;
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
wpi_assert(m_interrupt != HAL_kInvalidHandle);
|
||||
int32_t status = 0;
|
||||
HAL_EnableInterrupts(m_interrupt, &status);
|
||||
@@ -121,7 +141,9 @@ void InterruptableSensorBase::EnableInterrupts() {
|
||||
}
|
||||
|
||||
void InterruptableSensorBase::DisableInterrupts() {
|
||||
if (StatusIsFatal()) return;
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
wpi_assert(m_interrupt != HAL_kInvalidHandle);
|
||||
int32_t status = 0;
|
||||
HAL_DisableInterrupts(m_interrupt, &status);
|
||||
@@ -129,7 +151,9 @@ void InterruptableSensorBase::DisableInterrupts() {
|
||||
}
|
||||
|
||||
double InterruptableSensorBase::ReadRisingTimestamp() {
|
||||
if (StatusIsFatal()) return 0.0;
|
||||
if (StatusIsFatal()) {
|
||||
return 0.0;
|
||||
}
|
||||
wpi_assert(m_interrupt != HAL_kInvalidHandle);
|
||||
int32_t status = 0;
|
||||
int64_t timestamp = HAL_ReadInterruptRisingTimestamp(m_interrupt, &status);
|
||||
@@ -138,7 +162,9 @@ double InterruptableSensorBase::ReadRisingTimestamp() {
|
||||
}
|
||||
|
||||
double InterruptableSensorBase::ReadFallingTimestamp() {
|
||||
if (StatusIsFatal()) return 0.0;
|
||||
if (StatusIsFatal()) {
|
||||
return 0.0;
|
||||
}
|
||||
wpi_assert(m_interrupt != HAL_kInvalidHandle);
|
||||
int32_t status = 0;
|
||||
int64_t timestamp = HAL_ReadInterruptFallingTimestamp(m_interrupt, &status);
|
||||
@@ -148,7 +174,9 @@ double InterruptableSensorBase::ReadFallingTimestamp() {
|
||||
|
||||
void InterruptableSensorBase::SetUpSourceEdge(bool risingEdge,
|
||||
bool fallingEdge) {
|
||||
if (StatusIsFatal()) return;
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
if (m_interrupt == HAL_kInvalidHandle) {
|
||||
wpi_setWPIErrorWithContext(
|
||||
NullParameter,
|
||||
|
||||
@@ -32,7 +32,9 @@ void IterativeRobot::StartCompetition() {
|
||||
while (true) {
|
||||
// Wait for driver station data so the loop doesn't hog the CPU
|
||||
DriverStation::GetInstance().WaitForData();
|
||||
if (m_exit) break;
|
||||
if (m_exit) {
|
||||
break;
|
||||
}
|
||||
|
||||
LoopFunc();
|
||||
}
|
||||
|
||||
@@ -182,7 +182,9 @@ void IterativeRobotBase::LoopFunc() {
|
||||
m_watchdog.Disable();
|
||||
|
||||
// Flush NetworkTables
|
||||
if (m_ntFlushEnabled) nt::NetworkTableInstance::GetDefault().Flush();
|
||||
if (m_ntFlushEnabled) {
|
||||
nt::NetworkTableInstance::GetDefault().Flush();
|
||||
}
|
||||
|
||||
// Warn on loop time overruns
|
||||
if (m_watchdog.IsExpired()) {
|
||||
|
||||
@@ -21,27 +21,45 @@ Joystick::Joystick(int port) : GenericHID(port) {
|
||||
HAL_Report(HALUsageReporting::kResourceType_Joystick, port + 1);
|
||||
}
|
||||
|
||||
void Joystick::SetXChannel(int channel) { m_axes[Axis::kX] = channel; }
|
||||
void Joystick::SetXChannel(int channel) {
|
||||
m_axes[Axis::kX] = channel;
|
||||
}
|
||||
|
||||
void Joystick::SetYChannel(int channel) { m_axes[Axis::kY] = channel; }
|
||||
void Joystick::SetYChannel(int channel) {
|
||||
m_axes[Axis::kY] = channel;
|
||||
}
|
||||
|
||||
void Joystick::SetZChannel(int channel) { m_axes[Axis::kZ] = channel; }
|
||||
void Joystick::SetZChannel(int channel) {
|
||||
m_axes[Axis::kZ] = channel;
|
||||
}
|
||||
|
||||
void Joystick::SetTwistChannel(int channel) { m_axes[Axis::kTwist] = channel; }
|
||||
void Joystick::SetTwistChannel(int channel) {
|
||||
m_axes[Axis::kTwist] = channel;
|
||||
}
|
||||
|
||||
void Joystick::SetThrottleChannel(int channel) {
|
||||
m_axes[Axis::kThrottle] = channel;
|
||||
}
|
||||
|
||||
int Joystick::GetXChannel() const { return m_axes[Axis::kX]; }
|
||||
int Joystick::GetXChannel() const {
|
||||
return m_axes[Axis::kX];
|
||||
}
|
||||
|
||||
int Joystick::GetYChannel() const { return m_axes[Axis::kY]; }
|
||||
int Joystick::GetYChannel() const {
|
||||
return m_axes[Axis::kY];
|
||||
}
|
||||
|
||||
int Joystick::GetZChannel() const { return m_axes[Axis::kZ]; }
|
||||
int Joystick::GetZChannel() const {
|
||||
return m_axes[Axis::kZ];
|
||||
}
|
||||
|
||||
int Joystick::GetTwistChannel() const { return m_axes[Axis::kTwist]; }
|
||||
int Joystick::GetTwistChannel() const {
|
||||
return m_axes[Axis::kTwist];
|
||||
}
|
||||
|
||||
int Joystick::GetThrottleChannel() const { return m_axes[Axis::kThrottle]; }
|
||||
int Joystick::GetThrottleChannel() const {
|
||||
return m_axes[Axis::kThrottle];
|
||||
}
|
||||
|
||||
double Joystick::GetX(JoystickHand hand) const {
|
||||
return GetRawAxis(m_axes[Axis::kX]);
|
||||
@@ -51,15 +69,21 @@ double Joystick::GetY(JoystickHand hand) const {
|
||||
return GetRawAxis(m_axes[Axis::kY]);
|
||||
}
|
||||
|
||||
double Joystick::GetZ() const { return GetRawAxis(m_axes[Axis::kZ]); }
|
||||
double Joystick::GetZ() const {
|
||||
return GetRawAxis(m_axes[Axis::kZ]);
|
||||
}
|
||||
|
||||
double Joystick::GetTwist() const { return GetRawAxis(m_axes[Axis::kTwist]); }
|
||||
double Joystick::GetTwist() const {
|
||||
return GetRawAxis(m_axes[Axis::kTwist]);
|
||||
}
|
||||
|
||||
double Joystick::GetThrottle() const {
|
||||
return GetRawAxis(m_axes[Axis::kThrottle]);
|
||||
}
|
||||
|
||||
bool Joystick::GetTrigger() const { return GetRawButton(Button::kTrigger); }
|
||||
bool Joystick::GetTrigger() const {
|
||||
return GetRawButton(Button::kTrigger);
|
||||
}
|
||||
|
||||
bool Joystick::GetTriggerPressed() {
|
||||
return GetRawButtonPressed(Button::kTrigger);
|
||||
@@ -69,11 +93,17 @@ bool Joystick::GetTriggerReleased() {
|
||||
return GetRawButtonReleased(Button::kTrigger);
|
||||
}
|
||||
|
||||
bool Joystick::GetTop() const { return GetRawButton(Button::kTop); }
|
||||
bool Joystick::GetTop() const {
|
||||
return GetRawButton(Button::kTop);
|
||||
}
|
||||
|
||||
bool Joystick::GetTopPressed() { return GetRawButtonPressed(Button::kTop); }
|
||||
bool Joystick::GetTopPressed() {
|
||||
return GetRawButtonPressed(Button::kTop);
|
||||
}
|
||||
|
||||
bool Joystick::GetTopReleased() { return GetRawButtonReleased(Button::kTop); }
|
||||
bool Joystick::GetTopReleased() {
|
||||
return GetRawButtonReleased(Button::kTop);
|
||||
}
|
||||
|
||||
double Joystick::GetMagnitude() const {
|
||||
return std::sqrt(std::pow(GetX(), 2) + std::pow(GetY(), 2));
|
||||
|
||||
@@ -36,11 +36,17 @@ void NidecBrushless::Set(double speed) {
|
||||
Feed();
|
||||
}
|
||||
|
||||
double NidecBrushless::Get() const { return m_speed; }
|
||||
double NidecBrushless::Get() const {
|
||||
return m_speed;
|
||||
}
|
||||
|
||||
void NidecBrushless::SetInverted(bool isInverted) { m_isInverted = isInverted; }
|
||||
void NidecBrushless::SetInverted(bool isInverted) {
|
||||
m_isInverted = isInverted;
|
||||
}
|
||||
|
||||
bool NidecBrushless::GetInverted() const { return m_isInverted; }
|
||||
bool NidecBrushless::GetInverted() const {
|
||||
return m_isInverted;
|
||||
}
|
||||
|
||||
void NidecBrushless::Disable() {
|
||||
m_disabled = true;
|
||||
@@ -48,9 +54,13 @@ void NidecBrushless::Disable() {
|
||||
m_pwm.SetDisabled();
|
||||
}
|
||||
|
||||
void NidecBrushless::Enable() { m_disabled = false; }
|
||||
void NidecBrushless::Enable() {
|
||||
m_disabled = false;
|
||||
}
|
||||
|
||||
void NidecBrushless::PIDWrite(double output) { Set(output); }
|
||||
void NidecBrushless::PIDWrite(double output) {
|
||||
Set(output);
|
||||
}
|
||||
|
||||
void NidecBrushless::StopMotor() {
|
||||
m_dio.UpdateDutyCycle(0.5);
|
||||
@@ -61,7 +71,9 @@ void NidecBrushless::GetDescription(wpi::raw_ostream& desc) const {
|
||||
desc << "Nidec " << GetChannel();
|
||||
}
|
||||
|
||||
int NidecBrushless::GetChannel() const { return m_pwm.GetChannel(); }
|
||||
int NidecBrushless::GetChannel() const {
|
||||
return m_pwm.GetChannel();
|
||||
}
|
||||
|
||||
void NidecBrushless::InitSendable(SendableBuilder& builder) {
|
||||
builder.SetSmartDashboardType("Nidec Brushless");
|
||||
|
||||
@@ -18,8 +18,9 @@
|
||||
using namespace frc;
|
||||
|
||||
Notifier::Notifier(std::function<void()> handler) {
|
||||
if (handler == nullptr)
|
||||
if (handler == nullptr) {
|
||||
wpi_setWPIErrorWithContext(NullParameter, "handler must not be nullptr");
|
||||
}
|
||||
m_handler = handler;
|
||||
int32_t status = 0;
|
||||
m_notifier = HAL_InitializeNotifier(&status);
|
||||
@@ -29,9 +30,13 @@ Notifier::Notifier(std::function<void()> handler) {
|
||||
for (;;) {
|
||||
int32_t status = 0;
|
||||
HAL_NotifierHandle notifier = m_notifier.load();
|
||||
if (notifier == 0) break;
|
||||
if (notifier == 0) {
|
||||
break;
|
||||
}
|
||||
uint64_t curTime = HAL_WaitForNotifierAlarm(notifier, &status);
|
||||
if (curTime == 0 || status != 0) break;
|
||||
if (curTime == 0 || status != 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
std::function<void()> handler;
|
||||
{
|
||||
@@ -47,14 +52,17 @@ Notifier::Notifier(std::function<void()> handler) {
|
||||
}
|
||||
|
||||
// call callback
|
||||
if (handler) handler();
|
||||
if (handler) {
|
||||
handler();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Notifier::Notifier(int priority, std::function<void()> handler) {
|
||||
if (handler == nullptr)
|
||||
if (handler == nullptr) {
|
||||
wpi_setWPIErrorWithContext(NullParameter, "handler must not be nullptr");
|
||||
}
|
||||
m_handler = handler;
|
||||
int32_t status = 0;
|
||||
m_notifier = HAL_InitializeNotifier(&status);
|
||||
@@ -65,9 +73,13 @@ Notifier::Notifier(int priority, std::function<void()> handler) {
|
||||
HAL_SetCurrentThreadPriority(true, priority, &status);
|
||||
for (;;) {
|
||||
HAL_NotifierHandle notifier = m_notifier.load();
|
||||
if (notifier == 0) break;
|
||||
if (notifier == 0) {
|
||||
break;
|
||||
}
|
||||
uint64_t curTime = HAL_WaitForNotifierAlarm(notifier, &status);
|
||||
if (curTime == 0 || status != 0) break;
|
||||
if (curTime == 0 || status != 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
std::function<void()> handler;
|
||||
{
|
||||
@@ -83,7 +95,9 @@ Notifier::Notifier(int priority, std::function<void()> handler) {
|
||||
}
|
||||
|
||||
// call callback
|
||||
if (handler) handler();
|
||||
if (handler) {
|
||||
handler();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -96,7 +110,9 @@ Notifier::~Notifier() {
|
||||
wpi_setHALError(status);
|
||||
|
||||
// Join the thread to ensure the handler has exited.
|
||||
if (m_thread.joinable()) m_thread.join();
|
||||
if (m_thread.joinable()) {
|
||||
m_thread.join();
|
||||
}
|
||||
|
||||
HAL_CleanNotifier(handle, &status);
|
||||
}
|
||||
@@ -174,7 +190,9 @@ void Notifier::UpdateAlarm(uint64_t triggerTime) {
|
||||
int32_t status = 0;
|
||||
// Return if we are being destructed, or were not created successfully
|
||||
auto notifier = m_notifier.load();
|
||||
if (notifier == 0) return;
|
||||
if (notifier == 0) {
|
||||
return;
|
||||
}
|
||||
HAL_UpdateNotifierAlarm(notifier, triggerTime, &status);
|
||||
wpi_setHALError(status);
|
||||
}
|
||||
|
||||
@@ -133,12 +133,13 @@ void PIDBase::SetSetpoint(double setpoint) {
|
||||
std::scoped_lock lock(m_thisMutex);
|
||||
|
||||
if (m_maximumInput > m_minimumInput) {
|
||||
if (setpoint > m_maximumInput)
|
||||
if (setpoint > m_maximumInput) {
|
||||
m_setpoint = m_maximumInput;
|
||||
else if (setpoint < m_minimumInput)
|
||||
} else if (setpoint < m_minimumInput) {
|
||||
m_setpoint = m_minimumInput;
|
||||
else
|
||||
} else {
|
||||
m_setpoint = setpoint;
|
||||
}
|
||||
} else {
|
||||
m_setpoint = setpoint;
|
||||
}
|
||||
@@ -163,7 +164,9 @@ double PIDBase::GetError() const {
|
||||
}
|
||||
}
|
||||
|
||||
double PIDBase::GetAvgError() const { return GetError(); }
|
||||
double PIDBase::GetAvgError() const {
|
||||
return GetError();
|
||||
}
|
||||
|
||||
void PIDBase::SetPIDSourceType(PIDSourceType pidSource) {
|
||||
m_pidInput->SetPIDSourceType(pidSource);
|
||||
@@ -221,7 +224,9 @@ void PIDBase::Reset() {
|
||||
m_result = 0;
|
||||
}
|
||||
|
||||
void PIDBase::PIDWrite(double output) { SetSetpoint(output); }
|
||||
void PIDBase::PIDWrite(double output) {
|
||||
SetSetpoint(output);
|
||||
}
|
||||
|
||||
void PIDBase::InitSendable(SendableBuilder& builder) {
|
||||
builder.SetSmartDashboardType("PIDController");
|
||||
@@ -240,7 +245,9 @@ void PIDBase::InitSendable(SendableBuilder& builder) {
|
||||
}
|
||||
|
||||
void PIDBase::Calculate() {
|
||||
if (m_pidInput == nullptr || m_pidOutput == nullptr) return;
|
||||
if (m_pidInput == nullptr || m_pidOutput == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
bool enabled;
|
||||
{
|
||||
|
||||
@@ -10,4 +10,6 @@ void PIDSource::SetPIDSourceType(PIDSourceType pidSource) {
|
||||
m_pidSource = pidSource;
|
||||
}
|
||||
|
||||
PIDSourceType PIDSource::GetPIDSourceType() const { return m_pidSource; }
|
||||
PIDSourceType PIDSource::GetPIDSourceType() const {
|
||||
return m_pidSource;
|
||||
}
|
||||
|
||||
@@ -59,14 +59,18 @@ PWM::~PWM() {
|
||||
wpi_setHALError(status);
|
||||
}
|
||||
|
||||
void PWM::StopMotor() { SetDisabled(); }
|
||||
void PWM::StopMotor() {
|
||||
SetDisabled();
|
||||
}
|
||||
|
||||
void PWM::GetDescription(wpi::raw_ostream& desc) const {
|
||||
desc << "PWM " << GetChannel();
|
||||
}
|
||||
|
||||
void PWM::SetRaw(uint16_t value) {
|
||||
if (StatusIsFatal()) return;
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
|
||||
int32_t status = 0;
|
||||
HAL_SetPWMRaw(m_handle, value, &status);
|
||||
@@ -74,7 +78,9 @@ void PWM::SetRaw(uint16_t value) {
|
||||
}
|
||||
|
||||
uint16_t PWM::GetRaw() const {
|
||||
if (StatusIsFatal()) return 0;
|
||||
if (StatusIsFatal()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t status = 0;
|
||||
uint16_t value = HAL_GetPWMRaw(m_handle, &status);
|
||||
@@ -84,14 +90,18 @@ uint16_t PWM::GetRaw() const {
|
||||
}
|
||||
|
||||
void PWM::SetPosition(double pos) {
|
||||
if (StatusIsFatal()) return;
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
int32_t status = 0;
|
||||
HAL_SetPWMPosition(m_handle, pos, &status);
|
||||
wpi_setHALError(status);
|
||||
}
|
||||
|
||||
double PWM::GetPosition() const {
|
||||
if (StatusIsFatal()) return 0.0;
|
||||
if (StatusIsFatal()) {
|
||||
return 0.0;
|
||||
}
|
||||
int32_t status = 0;
|
||||
double position = HAL_GetPWMPosition(m_handle, &status);
|
||||
wpi_setHALError(status);
|
||||
@@ -99,7 +109,9 @@ double PWM::GetPosition() const {
|
||||
}
|
||||
|
||||
void PWM::SetSpeed(double speed) {
|
||||
if (StatusIsFatal()) return;
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
int32_t status = 0;
|
||||
HAL_SetPWMSpeed(m_handle, speed, &status);
|
||||
wpi_setHALError(status);
|
||||
@@ -108,7 +120,9 @@ void PWM::SetSpeed(double speed) {
|
||||
}
|
||||
|
||||
double PWM::GetSpeed() const {
|
||||
if (StatusIsFatal()) return 0.0;
|
||||
if (StatusIsFatal()) {
|
||||
return 0.0;
|
||||
}
|
||||
int32_t status = 0;
|
||||
double speed = HAL_GetPWMSpeed(m_handle, &status);
|
||||
wpi_setHALError(status);
|
||||
@@ -116,7 +130,9 @@ double PWM::GetSpeed() const {
|
||||
}
|
||||
|
||||
void PWM::SetDisabled() {
|
||||
if (StatusIsFatal()) return;
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
|
||||
int32_t status = 0;
|
||||
|
||||
@@ -125,7 +141,9 @@ void PWM::SetDisabled() {
|
||||
}
|
||||
|
||||
void PWM::SetPeriodMultiplier(PeriodMultiplier mult) {
|
||||
if (StatusIsFatal()) return;
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
|
||||
int32_t status = 0;
|
||||
|
||||
@@ -149,7 +167,9 @@ void PWM::SetPeriodMultiplier(PeriodMultiplier mult) {
|
||||
}
|
||||
|
||||
void PWM::SetZeroLatch() {
|
||||
if (StatusIsFatal()) return;
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
|
||||
int32_t status = 0;
|
||||
|
||||
@@ -158,7 +178,9 @@ void PWM::SetZeroLatch() {
|
||||
}
|
||||
|
||||
void PWM::EnableDeadbandElimination(bool eliminateDeadband) {
|
||||
if (StatusIsFatal()) return;
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
int32_t status = 0;
|
||||
HAL_SetPWMEliminateDeadband(m_handle, eliminateDeadband, &status);
|
||||
wpi_setHALError(status);
|
||||
@@ -166,7 +188,9 @@ void PWM::EnableDeadbandElimination(bool eliminateDeadband) {
|
||||
|
||||
void PWM::SetBounds(double max, double deadbandMax, double center,
|
||||
double deadbandMin, double min) {
|
||||
if (StatusIsFatal()) return;
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
int32_t status = 0;
|
||||
HAL_SetPWMConfig(m_handle, max, deadbandMax, center, deadbandMin, min,
|
||||
&status);
|
||||
@@ -175,7 +199,9 @@ void PWM::SetBounds(double max, double deadbandMax, double center,
|
||||
|
||||
void PWM::SetRawBounds(int max, int deadbandMax, int center, int deadbandMin,
|
||||
int min) {
|
||||
if (StatusIsFatal()) return;
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
int32_t status = 0;
|
||||
HAL_SetPWMConfigRaw(m_handle, max, deadbandMax, center, deadbandMin, min,
|
||||
&status);
|
||||
@@ -190,7 +216,9 @@ void PWM::GetRawBounds(int* max, int* deadbandMax, int* center,
|
||||
wpi_setHALError(status);
|
||||
}
|
||||
|
||||
int PWM::GetChannel() const { return m_channel; }
|
||||
int PWM::GetChannel() const {
|
||||
return m_channel;
|
||||
}
|
||||
|
||||
void PWM::InitSendable(SendableBuilder& builder) {
|
||||
builder.SetSmartDashboardType("PWM");
|
||||
|
||||
@@ -12,19 +12,29 @@ void PWMSpeedController::Set(double speed) {
|
||||
SetSpeed(m_isInverted ? -speed : speed);
|
||||
}
|
||||
|
||||
double PWMSpeedController::Get() const { return GetSpeed(); }
|
||||
double PWMSpeedController::Get() const {
|
||||
return GetSpeed();
|
||||
}
|
||||
|
||||
void PWMSpeedController::SetInverted(bool isInverted) {
|
||||
m_isInverted = isInverted;
|
||||
}
|
||||
|
||||
bool PWMSpeedController::GetInverted() const { return m_isInverted; }
|
||||
bool PWMSpeedController::GetInverted() const {
|
||||
return m_isInverted;
|
||||
}
|
||||
|
||||
void PWMSpeedController::Disable() { SetDisabled(); }
|
||||
void PWMSpeedController::Disable() {
|
||||
SetDisabled();
|
||||
}
|
||||
|
||||
void PWMSpeedController::StopMotor() { PWM::StopMotor(); }
|
||||
void PWMSpeedController::StopMotor() {
|
||||
PWM::StopMotor();
|
||||
}
|
||||
|
||||
void PWMSpeedController::PIDWrite(double output) { Set(output); }
|
||||
void PWMSpeedController::PIDWrite(double output) {
|
||||
Set(output);
|
||||
}
|
||||
|
||||
PWMSpeedController::PWMSpeedController(int channel) : PWM(channel) {}
|
||||
|
||||
|
||||
@@ -133,7 +133,9 @@ void PowerDistributionPanel::ClearStickyFaults() {
|
||||
}
|
||||
}
|
||||
|
||||
int PowerDistributionPanel::GetModule() const { return m_module; }
|
||||
int PowerDistributionPanel::GetModule() const {
|
||||
return m_module;
|
||||
}
|
||||
|
||||
void PowerDistributionPanel::InitSendable(SendableBuilder& builder) {
|
||||
builder.SetSmartDashboardType("PowerDistributionPanel");
|
||||
|
||||
@@ -22,7 +22,9 @@ Preferences* Preferences::GetInstance() {
|
||||
return &instance;
|
||||
}
|
||||
|
||||
std::vector<std::string> Preferences::GetKeys() { return m_table->GetKeys(); }
|
||||
std::vector<std::string> Preferences::GetKeys() {
|
||||
return m_table->GetKeys();
|
||||
}
|
||||
|
||||
std::string Preferences::GetString(wpi::StringRef key,
|
||||
wpi::StringRef defaultValue) {
|
||||
@@ -119,7 +121,9 @@ bool Preferences::ContainsKey(wpi::StringRef key) {
|
||||
return m_table->ContainsKey(key);
|
||||
}
|
||||
|
||||
void Preferences::Remove(wpi::StringRef key) { m_table->Delete(key); }
|
||||
void Preferences::Remove(wpi::StringRef key) {
|
||||
m_table->Delete(key);
|
||||
}
|
||||
|
||||
void Preferences::RemoveAll() {
|
||||
for (auto preference : GetKeys()) {
|
||||
|
||||
@@ -81,12 +81,18 @@ Relay::~Relay() {
|
||||
HAL_SetRelay(m_forwardHandle, false, &status);
|
||||
HAL_SetRelay(m_reverseHandle, false, &status);
|
||||
// ignore errors, as we want to make sure a free happens.
|
||||
if (m_forwardHandle != HAL_kInvalidHandle) HAL_FreeRelayPort(m_forwardHandle);
|
||||
if (m_reverseHandle != HAL_kInvalidHandle) HAL_FreeRelayPort(m_reverseHandle);
|
||||
if (m_forwardHandle != HAL_kInvalidHandle) {
|
||||
HAL_FreeRelayPort(m_forwardHandle);
|
||||
}
|
||||
if (m_reverseHandle != HAL_kInvalidHandle) {
|
||||
HAL_FreeRelayPort(m_reverseHandle);
|
||||
}
|
||||
}
|
||||
|
||||
void Relay::Set(Relay::Value value) {
|
||||
if (StatusIsFatal()) return;
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
|
||||
int32_t status = 0;
|
||||
|
||||
@@ -170,9 +176,13 @@ Relay::Value Relay::Get() const {
|
||||
wpi_setHALError(status);
|
||||
}
|
||||
|
||||
int Relay::GetChannel() const { return m_channel; }
|
||||
int Relay::GetChannel() const {
|
||||
return m_channel;
|
||||
}
|
||||
|
||||
void Relay::StopMotor() { Set(kOff); }
|
||||
void Relay::StopMotor() {
|
||||
Set(kOff);
|
||||
}
|
||||
|
||||
void Relay::GetDescription(wpi::raw_ostream& desc) const {
|
||||
desc << "Relay " << GetChannel();
|
||||
@@ -197,13 +207,14 @@ void Relay::InitSendable(SendableBuilder& builder) {
|
||||
}
|
||||
},
|
||||
[=](wpi::StringRef value) {
|
||||
if (value == "Off")
|
||||
if (value == "Off") {
|
||||
Set(kOff);
|
||||
else if (value == "Forward")
|
||||
} else if (value == "Forward") {
|
||||
Set(kForward);
|
||||
else if (value == "Reverse")
|
||||
} else if (value == "Reverse") {
|
||||
Set(kReverse);
|
||||
else if (value == "On")
|
||||
} else if (value == "On") {
|
||||
Set(kOn);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -51,7 +51,9 @@ uint32_t Resource::Allocate(uint32_t index, const std::string& resourceDesc) {
|
||||
|
||||
void Resource::Free(uint32_t index) {
|
||||
std::unique_lock lock(m_allocateMutex);
|
||||
if (index == std::numeric_limits<uint32_t>::max()) return;
|
||||
if (index == std::numeric_limits<uint32_t>::max()) {
|
||||
return;
|
||||
}
|
||||
if (index >= m_isAllocated.size()) {
|
||||
wpi_setWPIError(NotAllocated);
|
||||
return;
|
||||
|
||||
@@ -125,13 +125,17 @@ void RobotDrive::Drive(double outputMagnitude, double curve) {
|
||||
if (curve < 0) {
|
||||
double value = std::log(-curve);
|
||||
double ratio = (value - m_sensitivity) / (value + m_sensitivity);
|
||||
if (ratio == 0) ratio = 0.0000000001;
|
||||
if (ratio == 0) {
|
||||
ratio = 0.0000000001;
|
||||
}
|
||||
leftOutput = outputMagnitude / ratio;
|
||||
rightOutput = outputMagnitude;
|
||||
} else if (curve > 0) {
|
||||
double value = std::log(curve);
|
||||
double ratio = (value - m_sensitivity) / (value + m_sensitivity);
|
||||
if (ratio == 0) ratio = 0.0000000001;
|
||||
if (ratio == 0) {
|
||||
ratio = 0.0000000001;
|
||||
}
|
||||
leftOutput = outputMagnitude;
|
||||
rightOutput = outputMagnitude / ratio;
|
||||
} else {
|
||||
@@ -339,12 +343,14 @@ void RobotDrive::SetLeftRightMotorOutputs(double leftOutput,
|
||||
double rightOutput) {
|
||||
wpi_assert(m_rearLeftMotor != nullptr && m_rearRightMotor != nullptr);
|
||||
|
||||
if (m_frontLeftMotor != nullptr)
|
||||
if (m_frontLeftMotor != nullptr) {
|
||||
m_frontLeftMotor->Set(Limit(leftOutput) * m_maxOutput);
|
||||
}
|
||||
m_rearLeftMotor->Set(Limit(leftOutput) * m_maxOutput);
|
||||
|
||||
if (m_frontRightMotor != nullptr)
|
||||
if (m_frontRightMotor != nullptr) {
|
||||
m_frontRightMotor->Set(-Limit(rightOutput) * m_maxOutput);
|
||||
}
|
||||
m_rearRightMotor->Set(-Limit(rightOutput) * m_maxOutput);
|
||||
|
||||
Feed();
|
||||
@@ -375,21 +381,33 @@ void RobotDrive::SetSensitivity(double sensitivity) {
|
||||
m_sensitivity = sensitivity;
|
||||
}
|
||||
|
||||
void RobotDrive::SetMaxOutput(double maxOutput) { m_maxOutput = maxOutput; }
|
||||
void RobotDrive::SetMaxOutput(double maxOutput) {
|
||||
m_maxOutput = maxOutput;
|
||||
}
|
||||
|
||||
void RobotDrive::GetDescription(wpi::raw_ostream& desc) const {
|
||||
desc << "RobotDrive";
|
||||
}
|
||||
|
||||
void RobotDrive::StopMotor() {
|
||||
if (m_frontLeftMotor != nullptr) m_frontLeftMotor->StopMotor();
|
||||
if (m_frontRightMotor != nullptr) m_frontRightMotor->StopMotor();
|
||||
if (m_rearLeftMotor != nullptr) m_rearLeftMotor->StopMotor();
|
||||
if (m_rearRightMotor != nullptr) m_rearRightMotor->StopMotor();
|
||||
if (m_frontLeftMotor != nullptr) {
|
||||
m_frontLeftMotor->StopMotor();
|
||||
}
|
||||
if (m_frontRightMotor != nullptr) {
|
||||
m_frontRightMotor->StopMotor();
|
||||
}
|
||||
if (m_rearLeftMotor != nullptr) {
|
||||
m_rearLeftMotor->StopMotor();
|
||||
}
|
||||
if (m_rearRightMotor != nullptr) {
|
||||
m_rearRightMotor->StopMotor();
|
||||
}
|
||||
Feed();
|
||||
}
|
||||
|
||||
void RobotDrive::InitRobotDrive() { SetSafetyEnabled(true); }
|
||||
void RobotDrive::InitRobotDrive() {
|
||||
SetSafetyEnabled(true);
|
||||
}
|
||||
|
||||
double RobotDrive::Limit(double number) {
|
||||
if (number > 1.0) {
|
||||
@@ -405,7 +423,9 @@ void RobotDrive::Normalize(double* wheelSpeeds) {
|
||||
double maxMagnitude = std::fabs(wheelSpeeds[0]);
|
||||
for (int i = 1; i < kMaxNumberOfMotors; i++) {
|
||||
double temp = std::fabs(wheelSpeeds[i]);
|
||||
if (maxMagnitude < temp) maxMagnitude = temp;
|
||||
if (maxMagnitude < temp) {
|
||||
maxMagnitude = temp;
|
||||
}
|
||||
}
|
||||
if (maxMagnitude > 1.0) {
|
||||
for (int i = 0; i < kMaxNumberOfMotors; i++) {
|
||||
|
||||
@@ -28,4 +28,6 @@ bool RobotState::IsAutonomous() {
|
||||
return DriverStation::GetInstance().IsAutonomous();
|
||||
}
|
||||
|
||||
bool RobotState::IsTest() { return DriverStation::GetInstance().IsTest(); }
|
||||
bool RobotState::IsTest() {
|
||||
return DriverStation::GetInstance().IsTest();
|
||||
}
|
||||
|
||||
@@ -76,7 +76,9 @@ void SPI::Accumulator::Update() {
|
||||
// get amount of data available
|
||||
int32_t numToRead =
|
||||
HAL_ReadSPIAutoReceivedData(m_port, m_buf, 0, 0, &status);
|
||||
if (status != 0) return; // error reading
|
||||
if (status != 0) {
|
||||
return; // error reading
|
||||
}
|
||||
|
||||
// only get whole responses; +1 is for timestamp
|
||||
numToRead -= numToRead % m_xferSize;
|
||||
@@ -84,11 +86,15 @@ void SPI::Accumulator::Update() {
|
||||
numToRead = m_xferSize * kAccumulateDepth;
|
||||
done = false;
|
||||
}
|
||||
if (numToRead == 0) return; // no samples
|
||||
if (numToRead == 0) {
|
||||
return; // no samples
|
||||
}
|
||||
|
||||
// read buffered data
|
||||
HAL_ReadSPIAutoReceivedData(m_port, m_buf, numToRead, 0, &status);
|
||||
if (status != 0) return; // error reading
|
||||
if (status != 0) {
|
||||
return; // error reading
|
||||
}
|
||||
|
||||
// loop over all responses
|
||||
for (int32_t off = 0; off < numToRead; off += m_xferSize) {
|
||||
@@ -115,7 +121,9 @@ void SPI::Accumulator::Update() {
|
||||
int32_t data = static_cast<int32_t>(resp >> m_dataShift);
|
||||
data &= m_dataMax - 1;
|
||||
// 2s complement conversion if signed MSB is set
|
||||
if (m_isSigned && (data & m_dataMsbMask) != 0) data -= m_dataMax;
|
||||
if (m_isSigned && (data & m_dataMsbMask) != 0) {
|
||||
data -= m_dataMax;
|
||||
}
|
||||
// center offset
|
||||
int32_t dataNoCenter = data;
|
||||
data -= m_center;
|
||||
@@ -124,18 +132,19 @@ void SPI::Accumulator::Update() {
|
||||
m_value += data;
|
||||
if (m_count != 0) {
|
||||
// timestamps use the 1us FPGA clock; also handle rollover
|
||||
if (timestamp >= m_lastTimestamp)
|
||||
if (timestamp >= m_lastTimestamp) {
|
||||
m_integratedValue +=
|
||||
dataNoCenter *
|
||||
static_cast<int32_t>(timestamp - m_lastTimestamp) * 1e-6 -
|
||||
m_integratedCenter;
|
||||
else
|
||||
} else {
|
||||
m_integratedValue +=
|
||||
dataNoCenter *
|
||||
static_cast<int32_t>((1ULL << 32) - m_lastTimestamp +
|
||||
timestamp) *
|
||||
1e-6 -
|
||||
m_integratedCenter;
|
||||
}
|
||||
}
|
||||
}
|
||||
++m_count;
|
||||
@@ -158,9 +167,13 @@ SPI::SPI(Port port) : m_port(static_cast<HAL_SPIPort>(port)) {
|
||||
static_cast<uint8_t>(port) + 1);
|
||||
}
|
||||
|
||||
SPI::~SPI() { HAL_CloseSPI(m_port); }
|
||||
SPI::~SPI() {
|
||||
HAL_CloseSPI(m_port);
|
||||
}
|
||||
|
||||
void SPI::SetClockRate(int hz) { HAL_SetSPISpeed(m_port, hz); }
|
||||
void SPI::SetClockRate(int hz) {
|
||||
HAL_SetSPISpeed(m_port, hz);
|
||||
}
|
||||
|
||||
void SPI::SetMSBFirst() {
|
||||
m_msbFirst = true;
|
||||
@@ -356,7 +369,9 @@ void SPI::FreeAccumulator() {
|
||||
}
|
||||
|
||||
void SPI::ResetAccumulator() {
|
||||
if (!m_accum) return;
|
||||
if (!m_accum) {
|
||||
return;
|
||||
}
|
||||
std::scoped_lock lock(m_accum->m_mutex);
|
||||
m_accum->m_value = 0;
|
||||
m_accum->m_count = 0;
|
||||
@@ -366,43 +381,57 @@ void SPI::ResetAccumulator() {
|
||||
}
|
||||
|
||||
void SPI::SetAccumulatorCenter(int center) {
|
||||
if (!m_accum) return;
|
||||
if (!m_accum) {
|
||||
return;
|
||||
}
|
||||
std::scoped_lock lock(m_accum->m_mutex);
|
||||
m_accum->m_center = center;
|
||||
}
|
||||
|
||||
void SPI::SetAccumulatorDeadband(int deadband) {
|
||||
if (!m_accum) return;
|
||||
if (!m_accum) {
|
||||
return;
|
||||
}
|
||||
std::scoped_lock lock(m_accum->m_mutex);
|
||||
m_accum->m_deadband = deadband;
|
||||
}
|
||||
|
||||
int SPI::GetAccumulatorLastValue() const {
|
||||
if (!m_accum) return 0;
|
||||
if (!m_accum) {
|
||||
return 0;
|
||||
}
|
||||
std::scoped_lock lock(m_accum->m_mutex);
|
||||
m_accum->Update();
|
||||
return m_accum->m_lastValue;
|
||||
}
|
||||
|
||||
int64_t SPI::GetAccumulatorValue() const {
|
||||
if (!m_accum) return 0;
|
||||
if (!m_accum) {
|
||||
return 0;
|
||||
}
|
||||
std::scoped_lock lock(m_accum->m_mutex);
|
||||
m_accum->Update();
|
||||
return m_accum->m_value;
|
||||
}
|
||||
|
||||
int64_t SPI::GetAccumulatorCount() const {
|
||||
if (!m_accum) return 0;
|
||||
if (!m_accum) {
|
||||
return 0;
|
||||
}
|
||||
std::scoped_lock lock(m_accum->m_mutex);
|
||||
m_accum->Update();
|
||||
return m_accum->m_count;
|
||||
}
|
||||
|
||||
double SPI::GetAccumulatorAverage() const {
|
||||
if (!m_accum) return 0;
|
||||
if (!m_accum) {
|
||||
return 0;
|
||||
}
|
||||
std::scoped_lock lock(m_accum->m_mutex);
|
||||
m_accum->Update();
|
||||
if (m_accum->m_count == 0) return 0.0;
|
||||
if (m_accum->m_count == 0) {
|
||||
return 0.0;
|
||||
}
|
||||
return static_cast<double>(m_accum->m_value) / m_accum->m_count;
|
||||
}
|
||||
|
||||
@@ -419,23 +448,31 @@ void SPI::GetAccumulatorOutput(int64_t& value, int64_t& count) const {
|
||||
}
|
||||
|
||||
void SPI::SetAccumulatorIntegratedCenter(double center) {
|
||||
if (!m_accum) return;
|
||||
if (!m_accum) {
|
||||
return;
|
||||
}
|
||||
std::scoped_lock lock(m_accum->m_mutex);
|
||||
m_accum->m_integratedCenter = center;
|
||||
}
|
||||
|
||||
double SPI::GetAccumulatorIntegratedValue() const {
|
||||
if (!m_accum) return 0;
|
||||
if (!m_accum) {
|
||||
return 0;
|
||||
}
|
||||
std::scoped_lock lock(m_accum->m_mutex);
|
||||
m_accum->Update();
|
||||
return m_accum->m_integratedValue;
|
||||
}
|
||||
|
||||
double SPI::GetAccumulatorIntegratedAverage() const {
|
||||
if (!m_accum) return 0;
|
||||
if (!m_accum) {
|
||||
return 0;
|
||||
}
|
||||
std::scoped_lock lock(m_accum->m_mutex);
|
||||
m_accum->Update();
|
||||
if (m_accum->m_count <= 1) return 0.0;
|
||||
if (m_accum->m_count <= 1) {
|
||||
return 0.0;
|
||||
}
|
||||
// count-1 due to not integrating the first value received
|
||||
return m_accum->m_integratedValue / (m_accum->m_count - 1);
|
||||
}
|
||||
|
||||
@@ -24,7 +24,9 @@ const int SensorUtil::kPwmChannels = HAL_GetNumPWMChannels();
|
||||
const int SensorUtil::kRelayChannels = HAL_GetNumRelayHeaders();
|
||||
const int SensorUtil::kPDPChannels = HAL_GetNumPDPChannels();
|
||||
|
||||
int SensorUtil::GetDefaultSolenoidModule() { return 0; }
|
||||
int SensorUtil::GetDefaultSolenoidModule() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool SensorUtil::CheckSolenoidModule(int moduleNumber) {
|
||||
return HAL_CheckSolenoidModule(moduleNumber);
|
||||
|
||||
@@ -20,7 +20,9 @@ SerialPort::SerialPort(int baudRate, Port port, int dataBits,
|
||||
HAL_InitializeSerialPort(static_cast<HAL_SerialPort>(port), &status);
|
||||
wpi_setHALError(status);
|
||||
// Don't continue if initialization failed
|
||||
if (status < 0) return;
|
||||
if (status < 0) {
|
||||
return;
|
||||
}
|
||||
HAL_SetSerialBaudRate(m_portHandle, baudRate, &status);
|
||||
wpi_setHALError(status);
|
||||
HAL_SetSerialDataBits(m_portHandle, dataBits, &status);
|
||||
@@ -54,7 +56,9 @@ SerialPort::SerialPort(int baudRate, const wpi::Twine& portName, Port port,
|
||||
static_cast<HAL_SerialPort>(port), portNameC, &status);
|
||||
wpi_setHALError(status);
|
||||
// Don't continue if initialization failed
|
||||
if (status < 0) return;
|
||||
if (status < 0) {
|
||||
return;
|
||||
}
|
||||
HAL_SetSerialBaudRate(m_portHandle, baudRate, &status);
|
||||
wpi_setHALError(status);
|
||||
HAL_SetSerialDataBits(m_portHandle, dataBits, &status);
|
||||
|
||||
@@ -28,11 +28,17 @@ Servo::Servo(int channel) : PWM(channel) {
|
||||
SendableRegistry::GetInstance().SetName(this, "Servo", channel);
|
||||
}
|
||||
|
||||
void Servo::Set(double value) { SetPosition(value); }
|
||||
void Servo::Set(double value) {
|
||||
SetPosition(value);
|
||||
}
|
||||
|
||||
void Servo::SetOffline() { SetRaw(0); }
|
||||
void Servo::SetOffline() {
|
||||
SetRaw(0);
|
||||
}
|
||||
|
||||
double Servo::Get() const { return GetPosition(); }
|
||||
double Servo::Get() const {
|
||||
return GetPosition();
|
||||
}
|
||||
|
||||
void Servo::SetAngle(double degrees) {
|
||||
if (degrees < kMinServoAngle) {
|
||||
@@ -48,9 +54,13 @@ double Servo::GetAngle() const {
|
||||
return GetPosition() * GetServoAngleRange() + kMinServoAngle;
|
||||
}
|
||||
|
||||
double Servo::GetMaxAngle() const { return kMaxServoAngle; }
|
||||
double Servo::GetMaxAngle() const {
|
||||
return kMaxServoAngle;
|
||||
}
|
||||
|
||||
double Servo::GetMinAngle() const { return kMinServoAngle; }
|
||||
double Servo::GetMinAngle() const {
|
||||
return kMinServoAngle;
|
||||
}
|
||||
|
||||
void Servo::InitSendable(SendableBuilder& builder) {
|
||||
builder.SetSmartDashboardType("Servo");
|
||||
|
||||
@@ -49,10 +49,14 @@ Solenoid::Solenoid(int moduleNumber, int channel)
|
||||
m_channel);
|
||||
}
|
||||
|
||||
Solenoid::~Solenoid() { HAL_FreeSolenoidPort(m_solenoidHandle); }
|
||||
Solenoid::~Solenoid() {
|
||||
HAL_FreeSolenoidPort(m_solenoidHandle);
|
||||
}
|
||||
|
||||
void Solenoid::Set(bool on) {
|
||||
if (StatusIsFatal()) return;
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
|
||||
int32_t status = 0;
|
||||
HAL_SetSolenoid(m_solenoidHandle, on, &status);
|
||||
@@ -60,7 +64,9 @@ void Solenoid::Set(bool on) {
|
||||
}
|
||||
|
||||
bool Solenoid::Get() const {
|
||||
if (StatusIsFatal()) return false;
|
||||
if (StatusIsFatal()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int32_t status = 0;
|
||||
bool value = HAL_GetSolenoid(m_solenoidHandle, &status);
|
||||
@@ -69,7 +75,9 @@ bool Solenoid::Get() const {
|
||||
return value;
|
||||
}
|
||||
|
||||
void Solenoid::Toggle() { Set(!Get()); }
|
||||
void Solenoid::Toggle() {
|
||||
Set(!Get());
|
||||
}
|
||||
|
||||
bool Solenoid::IsBlackListed() const {
|
||||
int value = GetPCMSolenoidBlackList(m_moduleNumber) & (1 << m_channel);
|
||||
@@ -78,14 +86,18 @@ bool Solenoid::IsBlackListed() const {
|
||||
|
||||
void Solenoid::SetPulseDuration(double durationSeconds) {
|
||||
int32_t durationMS = durationSeconds * 1000;
|
||||
if (StatusIsFatal()) return;
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
int32_t status = 0;
|
||||
HAL_SetOneShotDuration(m_solenoidHandle, durationMS, &status);
|
||||
wpi_setHALError(status);
|
||||
}
|
||||
|
||||
void Solenoid::StartPulse() {
|
||||
if (StatusIsFatal()) return;
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
int32_t status = 0;
|
||||
HAL_FireOneShot(m_solenoidHandle, &status);
|
||||
wpi_setHALError(status);
|
||||
|
||||
@@ -19,8 +19,9 @@ SpeedControllerGroup::SpeedControllerGroup(
|
||||
}
|
||||
|
||||
void SpeedControllerGroup::Initialize() {
|
||||
for (auto& speedController : m_speedControllers)
|
||||
for (auto& speedController : m_speedControllers) {
|
||||
SendableRegistry::GetInstance().AddChild(this, &speedController.get());
|
||||
}
|
||||
static int instances = 0;
|
||||
++instances;
|
||||
SendableRegistry::GetInstance().Add(this, "SpeedControllerGroup", instances);
|
||||
@@ -43,7 +44,9 @@ void SpeedControllerGroup::SetInverted(bool isInverted) {
|
||||
m_isInverted = isInverted;
|
||||
}
|
||||
|
||||
bool SpeedControllerGroup::GetInverted() const { return m_isInverted; }
|
||||
bool SpeedControllerGroup::GetInverted() const {
|
||||
return m_isInverted;
|
||||
}
|
||||
|
||||
void SpeedControllerGroup::Disable() {
|
||||
for (auto speedController : m_speedControllers) {
|
||||
@@ -57,7 +60,9 @@ void SpeedControllerGroup::StopMotor() {
|
||||
}
|
||||
}
|
||||
|
||||
void SpeedControllerGroup::PIDWrite(double output) { Set(output); }
|
||||
void SpeedControllerGroup::PIDWrite(double output) {
|
||||
Set(output);
|
||||
}
|
||||
|
||||
void SpeedControllerGroup::InitSendable(SendableBuilder& builder) {
|
||||
builder.SetSmartDashboardType("Speed Controller");
|
||||
|
||||
@@ -42,7 +42,9 @@ void TimedRobot::StartCompetition() {
|
||||
wpi_setHALError(status);
|
||||
|
||||
uint64_t curTime = HAL_WaitForNotifierAlarm(m_notifier, &status);
|
||||
if (curTime == 0 || status != 0) break;
|
||||
if (curTime == 0 || status != 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
callback.func();
|
||||
|
||||
|
||||
@@ -8,23 +8,37 @@
|
||||
|
||||
namespace frc {
|
||||
|
||||
void Wait(double seconds) { frc2::Wait(units::second_t(seconds)); }
|
||||
void Wait(double seconds) {
|
||||
frc2::Wait(units::second_t(seconds));
|
||||
}
|
||||
|
||||
double GetTime() { return frc2::GetTime().to<double>(); }
|
||||
double GetTime() {
|
||||
return frc2::GetTime().to<double>();
|
||||
}
|
||||
|
||||
} // namespace frc
|
||||
|
||||
using namespace frc;
|
||||
|
||||
Timer::Timer() { Reset(); }
|
||||
Timer::Timer() {
|
||||
Reset();
|
||||
}
|
||||
|
||||
double Timer::Get() const { return m_timer.Get().to<double>(); }
|
||||
double Timer::Get() const {
|
||||
return m_timer.Get().to<double>();
|
||||
}
|
||||
|
||||
void Timer::Reset() { m_timer.Reset(); }
|
||||
void Timer::Reset() {
|
||||
m_timer.Reset();
|
||||
}
|
||||
|
||||
void Timer::Start() { m_timer.Start(); }
|
||||
void Timer::Start() {
|
||||
m_timer.Start();
|
||||
}
|
||||
|
||||
void Timer::Stop() { m_timer.Stop(); }
|
||||
void Timer::Stop() {
|
||||
m_timer.Stop();
|
||||
}
|
||||
|
||||
bool Timer::HasPeriodPassed(double period) {
|
||||
return m_timer.HasPeriodPassed(units::second_t(period));
|
||||
|
||||
@@ -12,9 +12,13 @@
|
||||
|
||||
using namespace frc;
|
||||
|
||||
Tracer::Tracer() { ResetTimer(); }
|
||||
Tracer::Tracer() {
|
||||
ResetTimer();
|
||||
}
|
||||
|
||||
void Tracer::ResetTimer() { m_startTime = hal::fpga_clock::now(); }
|
||||
void Tracer::ResetTimer() {
|
||||
m_startTime = hal::fpga_clock::now();
|
||||
}
|
||||
|
||||
void Tracer::ClearEpochs() {
|
||||
ResetTimer();
|
||||
@@ -31,7 +35,9 @@ void Tracer::PrintEpochs() {
|
||||
wpi::SmallString<128> buf;
|
||||
wpi::raw_svector_ostream os(buf);
|
||||
PrintEpochs(os);
|
||||
if (!buf.empty()) DriverStation::ReportWarning(buf);
|
||||
if (!buf.empty()) {
|
||||
DriverStation::ReportWarning(buf);
|
||||
}
|
||||
}
|
||||
|
||||
void Tracer::PrintEpochs(wpi::raw_ostream& os) {
|
||||
|
||||
@@ -97,12 +97,16 @@ void Ultrasonic::Ping() {
|
||||
}
|
||||
|
||||
bool Ultrasonic::IsRangeValid() const {
|
||||
if (m_simRangeValid) return m_simRangeValid.Get();
|
||||
if (m_simRangeValid) {
|
||||
return m_simRangeValid.Get();
|
||||
}
|
||||
return m_counter.Get() > 1;
|
||||
}
|
||||
|
||||
void Ultrasonic::SetAutomaticMode(bool enabling) {
|
||||
if (enabling == m_automaticEnabled) return; // ignore the case of no change
|
||||
if (enabling == m_automaticEnabled) {
|
||||
return; // ignore the case of no change
|
||||
}
|
||||
|
||||
m_automaticEnabled = enabling;
|
||||
|
||||
@@ -137,20 +141,30 @@ void Ultrasonic::SetAutomaticMode(bool enabling) {
|
||||
|
||||
double Ultrasonic::GetRangeInches() const {
|
||||
if (IsRangeValid()) {
|
||||
if (m_simRange) return m_simRange.Get();
|
||||
if (m_simRange) {
|
||||
return m_simRange.Get();
|
||||
}
|
||||
return m_counter.GetPeriod() * kSpeedOfSoundInchesPerSec / 2.0;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
double Ultrasonic::GetRangeMM() const { return GetRangeInches() * 25.4; }
|
||||
double Ultrasonic::GetRangeMM() const {
|
||||
return GetRangeInches() * 25.4;
|
||||
}
|
||||
|
||||
bool Ultrasonic::IsEnabled() const { return m_enabled; }
|
||||
bool Ultrasonic::IsEnabled() const {
|
||||
return m_enabled;
|
||||
}
|
||||
|
||||
void Ultrasonic::SetEnabled(bool enable) { m_enabled = enable; }
|
||||
void Ultrasonic::SetEnabled(bool enable) {
|
||||
m_enabled = enable;
|
||||
}
|
||||
|
||||
void Ultrasonic::SetDistanceUnits(DistanceUnit units) { m_units = units; }
|
||||
void Ultrasonic::SetDistanceUnits(DistanceUnit units) {
|
||||
m_units = units;
|
||||
}
|
||||
|
||||
Ultrasonic::DistanceUnit Ultrasonic::GetDistanceUnits() const {
|
||||
return m_units;
|
||||
@@ -209,7 +223,9 @@ void Ultrasonic::Initialize() {
|
||||
void Ultrasonic::UltrasonicChecker() {
|
||||
while (m_automaticEnabled) {
|
||||
for (auto& sensor : m_sensors) {
|
||||
if (!m_automaticEnabled) break;
|
||||
if (!m_automaticEnabled) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (sensor->IsEnabled()) {
|
||||
sensor->m_pingChannel->Pulse(kPingTime); // do the ping
|
||||
|
||||
@@ -60,7 +60,9 @@ Watchdog::Impl::~Impl() {
|
||||
wpi_setGlobalHALError(status);
|
||||
|
||||
// Join the thread to ensure the handler has exited.
|
||||
if (m_thread.joinable()) m_thread.join();
|
||||
if (m_thread.joinable()) {
|
||||
m_thread.join();
|
||||
}
|
||||
|
||||
HAL_CleanNotifier(handle, &status);
|
||||
}
|
||||
@@ -69,15 +71,18 @@ void Watchdog::Impl::UpdateAlarm() {
|
||||
int32_t status = 0;
|
||||
// Return if we are being destructed, or were not created successfully
|
||||
auto notifier = m_notifier.load();
|
||||
if (notifier == 0) return;
|
||||
if (m_watchdogs.empty())
|
||||
if (notifier == 0) {
|
||||
return;
|
||||
}
|
||||
if (m_watchdogs.empty()) {
|
||||
HAL_CancelNotifierAlarm(notifier, &status);
|
||||
else
|
||||
} else {
|
||||
HAL_UpdateNotifierAlarm(
|
||||
notifier,
|
||||
static_cast<uint64_t>(m_watchdogs.top()->m_expirationTime.to<double>() *
|
||||
1e6),
|
||||
&status);
|
||||
}
|
||||
wpi_setGlobalHALError(status);
|
||||
}
|
||||
|
||||
@@ -85,13 +90,19 @@ void Watchdog::Impl::Main() {
|
||||
for (;;) {
|
||||
int32_t status = 0;
|
||||
HAL_NotifierHandle notifier = m_notifier.load();
|
||||
if (notifier == 0) break;
|
||||
if (notifier == 0) {
|
||||
break;
|
||||
}
|
||||
uint64_t curTime = HAL_WaitForNotifierAlarm(notifier, &status);
|
||||
if (curTime == 0 || status != 0) break;
|
||||
if (curTime == 0 || status != 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
std::unique_lock lock(m_mutex);
|
||||
|
||||
if (m_watchdogs.empty()) continue;
|
||||
if (m_watchdogs.empty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// If the condition variable timed out, that means a Watchdog timeout
|
||||
// has occurred, so call its timeout function.
|
||||
@@ -128,9 +139,13 @@ Watchdog::Watchdog(double timeout, std::function<void()> callback)
|
||||
Watchdog::Watchdog(units::second_t timeout, std::function<void()> callback)
|
||||
: m_timeout(timeout), m_callback(callback), m_impl(GetImpl()) {}
|
||||
|
||||
Watchdog::~Watchdog() { Disable(); }
|
||||
Watchdog::~Watchdog() {
|
||||
Disable();
|
||||
}
|
||||
|
||||
Watchdog::Watchdog(Watchdog&& rhs) { *this = std::move(rhs); }
|
||||
Watchdog::Watchdog(Watchdog&& rhs) {
|
||||
*this = std::move(rhs);
|
||||
}
|
||||
|
||||
Watchdog& Watchdog::operator=(Watchdog&& rhs) {
|
||||
m_impl = rhs.m_impl;
|
||||
@@ -186,9 +201,13 @@ void Watchdog::AddEpoch(wpi::StringRef epochName) {
|
||||
m_tracer.AddEpoch(epochName);
|
||||
}
|
||||
|
||||
void Watchdog::PrintEpochs() { m_tracer.PrintEpochs(); }
|
||||
void Watchdog::PrintEpochs() {
|
||||
m_tracer.PrintEpochs();
|
||||
}
|
||||
|
||||
void Watchdog::Reset() { Enable(); }
|
||||
void Watchdog::Reset() {
|
||||
Enable();
|
||||
}
|
||||
|
||||
void Watchdog::Enable() {
|
||||
m_startTime = frc2::Timer::GetFPGATimestamp();
|
||||
|
||||
@@ -64,4 +64,6 @@ ChassisSpeeds HolonomicDriveController::Calculate(
|
||||
angleRef);
|
||||
}
|
||||
|
||||
void HolonomicDriveController::SetEnabled(bool enabled) { m_enabled = enabled; }
|
||||
void HolonomicDriveController::SetEnabled(bool enabled) {
|
||||
m_enabled = enabled;
|
||||
}
|
||||
|
||||
@@ -30,25 +30,41 @@ void PIDController::SetPID(double Kp, double Ki, double Kd) {
|
||||
m_Kd = Kd;
|
||||
}
|
||||
|
||||
void PIDController::SetP(double Kp) { m_Kp = Kp; }
|
||||
void PIDController::SetP(double Kp) {
|
||||
m_Kp = Kp;
|
||||
}
|
||||
|
||||
void PIDController::SetI(double Ki) { m_Ki = Ki; }
|
||||
void PIDController::SetI(double Ki) {
|
||||
m_Ki = Ki;
|
||||
}
|
||||
|
||||
void PIDController::SetD(double Kd) { m_Kd = Kd; }
|
||||
void PIDController::SetD(double Kd) {
|
||||
m_Kd = Kd;
|
||||
}
|
||||
|
||||
double PIDController::GetP() const { return m_Kp; }
|
||||
double PIDController::GetP() const {
|
||||
return m_Kp;
|
||||
}
|
||||
|
||||
double PIDController::GetI() const { return m_Ki; }
|
||||
double PIDController::GetI() const {
|
||||
return m_Ki;
|
||||
}
|
||||
|
||||
double PIDController::GetD() const { return m_Kd; }
|
||||
double PIDController::GetD() const {
|
||||
return m_Kd;
|
||||
}
|
||||
|
||||
units::second_t PIDController::GetPeriod() const {
|
||||
return units::second_t(m_period);
|
||||
}
|
||||
|
||||
void PIDController::SetSetpoint(double setpoint) { m_setpoint = setpoint; }
|
||||
void PIDController::SetSetpoint(double setpoint) {
|
||||
m_setpoint = setpoint;
|
||||
}
|
||||
|
||||
double PIDController::GetSetpoint() const { return m_setpoint; }
|
||||
double PIDController::GetSetpoint() const {
|
||||
return m_setpoint;
|
||||
}
|
||||
|
||||
bool PIDController::AtSetpoint() const {
|
||||
double positionError;
|
||||
@@ -72,9 +88,13 @@ void PIDController::EnableContinuousInput(double minimumInput,
|
||||
m_maximumInput = maximumInput;
|
||||
}
|
||||
|
||||
void PIDController::DisableContinuousInput() { m_continuous = false; }
|
||||
void PIDController::DisableContinuousInput() {
|
||||
m_continuous = false;
|
||||
}
|
||||
|
||||
bool PIDController::IsContinuousInputEnabled() const { return m_continuous; }
|
||||
bool PIDController::IsContinuousInputEnabled() const {
|
||||
return m_continuous;
|
||||
}
|
||||
|
||||
void PIDController::SetIntegratorRange(double minimumIntegral,
|
||||
double maximumIntegral) {
|
||||
@@ -88,9 +108,13 @@ void PIDController::SetTolerance(double positionTolerance,
|
||||
m_velocityTolerance = velocityTolerance;
|
||||
}
|
||||
|
||||
double PIDController::GetPositionError() const { return m_positionError; }
|
||||
double PIDController::GetPositionError() const {
|
||||
return m_positionError;
|
||||
}
|
||||
|
||||
double PIDController::GetVelocityError() const { return m_velocityError; }
|
||||
double PIDController::GetVelocityError() const {
|
||||
return m_velocityError;
|
||||
}
|
||||
|
||||
double PIDController::Calculate(double measurement) {
|
||||
m_measurement = measurement;
|
||||
|
||||
@@ -72,4 +72,6 @@ ChassisSpeeds RamseteController::Calculate(
|
||||
desiredState.velocity * desiredState.curvature);
|
||||
}
|
||||
|
||||
void RamseteController::SetEnabled(bool enabled) { m_enabled = enabled; }
|
||||
void RamseteController::SetEnabled(bool enabled) {
|
||||
m_enabled = enabled;
|
||||
}
|
||||
|
||||
@@ -15,13 +15,21 @@
|
||||
|
||||
using namespace frc;
|
||||
|
||||
RobotDriveBase::RobotDriveBase() { SetSafetyEnabled(true); }
|
||||
RobotDriveBase::RobotDriveBase() {
|
||||
SetSafetyEnabled(true);
|
||||
}
|
||||
|
||||
void RobotDriveBase::SetDeadband(double deadband) { m_deadband = deadband; }
|
||||
void RobotDriveBase::SetDeadband(double deadband) {
|
||||
m_deadband = deadband;
|
||||
}
|
||||
|
||||
void RobotDriveBase::SetMaxOutput(double maxOutput) { m_maxOutput = maxOutput; }
|
||||
void RobotDriveBase::SetMaxOutput(double maxOutput) {
|
||||
m_maxOutput = maxOutput;
|
||||
}
|
||||
|
||||
void RobotDriveBase::FeedWatchdog() { Feed(); }
|
||||
void RobotDriveBase::FeedWatchdog() {
|
||||
Feed();
|
||||
}
|
||||
|
||||
double RobotDriveBase::ApplyDeadband(double value, double deadband) {
|
||||
if (std::abs(value) > deadband) {
|
||||
|
||||
@@ -29,7 +29,9 @@ double Vector2d::Dot(const Vector2d& vec) const {
|
||||
return x * vec.x + y * vec.y;
|
||||
}
|
||||
|
||||
double Vector2d::Magnitude() const { return std::sqrt(x * x + y * y); }
|
||||
double Vector2d::Magnitude() const {
|
||||
return std::sqrt(x * x + y * y);
|
||||
}
|
||||
|
||||
double Vector2d::ScalarProject(const Vector2d& vec) const {
|
||||
return Dot(vec) / vec.Magnitude();
|
||||
|
||||
@@ -22,4 +22,6 @@ PIDSourceType Filter::GetPIDSourceType() const {
|
||||
return m_source->GetPIDSourceType();
|
||||
}
|
||||
|
||||
double Filter::PIDGetSource() { return m_source->PIDGet(); }
|
||||
double Filter::PIDGetSource() {
|
||||
return m_source->PIDGet();
|
||||
}
|
||||
|
||||
@@ -31,7 +31,9 @@ units::second_t GetTime() {
|
||||
|
||||
using namespace frc2;
|
||||
|
||||
Timer::Timer() { Reset(); }
|
||||
Timer::Timer() {
|
||||
Reset();
|
||||
}
|
||||
|
||||
Timer::Timer(const Timer& rhs)
|
||||
: m_startTime(rhs.m_startTime),
|
||||
@@ -101,7 +103,9 @@ void Timer::Stop() {
|
||||
}
|
||||
}
|
||||
|
||||
bool Timer::HasElapsed(units::second_t period) const { return Get() > period; }
|
||||
bool Timer::HasElapsed(units::second_t period) const {
|
||||
return Get() > period;
|
||||
}
|
||||
|
||||
bool Timer::HasPeriodPassed(units::second_t period) {
|
||||
return AdvanceIfElapsed(period);
|
||||
|
||||
@@ -82,7 +82,9 @@ void LiveWindow::DisableAllTelemetry() {
|
||||
std::scoped_lock lock(m_impl->mutex);
|
||||
m_impl->telemetryEnabled = false;
|
||||
m_impl->registry.ForeachLiveWindow(m_impl->dataHandle, [&](auto& cbdata) {
|
||||
if (!cbdata.data) cbdata.data = std::make_shared<Impl::Component>();
|
||||
if (!cbdata.data) {
|
||||
cbdata.data = std::make_shared<Impl::Component>();
|
||||
}
|
||||
std::static_pointer_cast<Impl::Component>(cbdata.data)->telemetryEnabled =
|
||||
false;
|
||||
});
|
||||
@@ -95,18 +97,24 @@ bool LiveWindow::IsEnabled() const {
|
||||
|
||||
void LiveWindow::SetEnabled(bool enabled) {
|
||||
std::scoped_lock lock(m_impl->mutex);
|
||||
if (m_impl->liveWindowEnabled == enabled) return;
|
||||
if (m_impl->liveWindowEnabled == enabled) {
|
||||
return;
|
||||
}
|
||||
m_impl->startLiveWindow = enabled;
|
||||
m_impl->liveWindowEnabled = enabled;
|
||||
// Force table generation now to make sure everything is defined
|
||||
UpdateValuesUnsafe();
|
||||
if (enabled) {
|
||||
if (this->enabled) this->enabled();
|
||||
if (this->enabled) {
|
||||
this->enabled();
|
||||
}
|
||||
} else {
|
||||
m_impl->registry.ForeachLiveWindow(m_impl->dataHandle, [&](auto& cbdata) {
|
||||
cbdata.builder.StopLiveWindowMode();
|
||||
});
|
||||
if (this->disabled) this->disabled();
|
||||
if (this->disabled) {
|
||||
this->disabled();
|
||||
}
|
||||
}
|
||||
m_impl->enabledEntry.SetBoolean(enabled);
|
||||
}
|
||||
@@ -118,30 +126,41 @@ void LiveWindow::UpdateValues() {
|
||||
|
||||
void LiveWindow::UpdateValuesUnsafe() {
|
||||
// Only do this if either LiveWindow mode or telemetry is enabled.
|
||||
if (!m_impl->liveWindowEnabled && !m_impl->telemetryEnabled) return;
|
||||
if (!m_impl->liveWindowEnabled && !m_impl->telemetryEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_impl->registry.ForeachLiveWindow(m_impl->dataHandle, [&](auto& cbdata) {
|
||||
if (!cbdata.sendable || cbdata.parent) return;
|
||||
if (!cbdata.sendable || cbdata.parent) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!cbdata.data) cbdata.data = std::make_shared<Impl::Component>();
|
||||
if (!cbdata.data) {
|
||||
cbdata.data = std::make_shared<Impl::Component>();
|
||||
}
|
||||
|
||||
auto& comp = *std::static_pointer_cast<Impl::Component>(cbdata.data);
|
||||
|
||||
if (!m_impl->liveWindowEnabled && !comp.telemetryEnabled) return;
|
||||
if (!m_impl->liveWindowEnabled && !comp.telemetryEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (comp.firstTime) {
|
||||
// By holding off creating the NetworkTable entries, it allows the
|
||||
// components to be redefined. This allows default sensor and actuator
|
||||
// values to be created that are replaced with the custom names from
|
||||
// users calling setName.
|
||||
if (cbdata.name.empty()) return;
|
||||
if (cbdata.name.empty()) {
|
||||
return;
|
||||
}
|
||||
auto ssTable = m_impl->liveWindowTable->GetSubTable(cbdata.subsystem);
|
||||
std::shared_ptr<NetworkTable> table;
|
||||
// Treat name==subsystem as top level of subsystem
|
||||
if (cbdata.name == cbdata.subsystem)
|
||||
if (cbdata.name == cbdata.subsystem) {
|
||||
table = ssTable;
|
||||
else
|
||||
} else {
|
||||
table = ssTable->GetSubTable(cbdata.name);
|
||||
}
|
||||
table->GetEntry(".name").SetString(cbdata.name);
|
||||
cbdata.builder.SetTable(table);
|
||||
cbdata.sendable->InitSendable(cbdata.builder);
|
||||
@@ -150,7 +169,9 @@ void LiveWindow::UpdateValuesUnsafe() {
|
||||
comp.firstTime = false;
|
||||
}
|
||||
|
||||
if (m_impl->startLiveWindow) cbdata.builder.StartLiveWindowMode();
|
||||
if (m_impl->startLiveWindow) {
|
||||
cbdata.builder.StartLiveWindowMode();
|
||||
}
|
||||
cbdata.builder.UpdateTable();
|
||||
});
|
||||
|
||||
|
||||
@@ -6,4 +6,6 @@
|
||||
|
||||
using namespace frc;
|
||||
|
||||
wpi::StringRef LayoutType::GetLayoutName() const { return m_layoutName; }
|
||||
wpi::StringRef LayoutType::GetLayoutName() const {
|
||||
return m_layoutName;
|
||||
}
|
||||
|
||||
@@ -10,13 +10,17 @@
|
||||
|
||||
using namespace frc;
|
||||
|
||||
void Shuffleboard::Update() { GetInstance().Update(); }
|
||||
void Shuffleboard::Update() {
|
||||
GetInstance().Update();
|
||||
}
|
||||
|
||||
ShuffleboardTab& Shuffleboard::GetTab(wpi::StringRef title) {
|
||||
return GetInstance().GetTab(title);
|
||||
}
|
||||
|
||||
void Shuffleboard::SelectTab(int index) { GetInstance().SelectTab(index); }
|
||||
void Shuffleboard::SelectTab(int index) {
|
||||
GetInstance().SelectTab(index);
|
||||
}
|
||||
|
||||
void Shuffleboard::SelectTab(wpi::StringRef title) {
|
||||
GetInstance().SelectTab(title);
|
||||
@@ -36,7 +40,9 @@ void Shuffleboard::StartRecording() {
|
||||
GetRecordingController().StartRecording();
|
||||
}
|
||||
|
||||
void Shuffleboard::StopRecording() { GetRecordingController().StopRecording(); }
|
||||
void Shuffleboard::StopRecording() {
|
||||
GetRecordingController().StopRecording();
|
||||
}
|
||||
|
||||
void Shuffleboard::SetRecordingFileNameFormat(wpi::StringRef format) {
|
||||
GetRecordingController().SetRecordingFileNameFormat(format);
|
||||
|
||||
@@ -65,7 +65,9 @@ ShuffleboardContainer& ShuffleboardComponentBase::GetParent() {
|
||||
return m_parent;
|
||||
}
|
||||
|
||||
const std::string& ShuffleboardComponentBase::GetType() const { return m_type; }
|
||||
const std::string& ShuffleboardComponentBase::GetType() const {
|
||||
return m_type;
|
||||
}
|
||||
|
||||
const wpi::StringMap<std::shared_ptr<nt::Value>>&
|
||||
ShuffleboardComponentBase::GetProperties() const {
|
||||
|
||||
@@ -9,7 +9,9 @@ using namespace frc;
|
||||
ShuffleboardTab::ShuffleboardTab(ShuffleboardRoot& root, wpi::StringRef title)
|
||||
: ShuffleboardValue(title), ShuffleboardContainer(title), m_root(root) {}
|
||||
|
||||
ShuffleboardRoot& ShuffleboardTab::GetRoot() { return m_root; }
|
||||
ShuffleboardRoot& ShuffleboardTab::GetRoot() {
|
||||
return m_root;
|
||||
}
|
||||
|
||||
void ShuffleboardTab::BuildInto(std::shared_ptr<nt::NetworkTable> parentTable,
|
||||
std::shared_ptr<nt::NetworkTable> metaTable) {
|
||||
|
||||
@@ -6,4 +6,6 @@
|
||||
|
||||
using namespace frc;
|
||||
|
||||
wpi::StringRef WidgetType::GetWidgetName() const { return m_widgetName; }
|
||||
wpi::StringRef WidgetType::GetWidgetName() const {
|
||||
return m_widgetName;
|
||||
}
|
||||
|
||||
@@ -20,8 +20,9 @@ AddressableLEDSim::AddressableLEDSim(const AddressableLED& addressableLED)
|
||||
|
||||
AddressableLEDSim AddressableLEDSim::CreateForChannel(int pwmChannel) {
|
||||
int index = HALSIM_FindAddressableLEDForChannel(pwmChannel);
|
||||
if (index < 0)
|
||||
if (index < 0) {
|
||||
throw std::out_of_range("no addressable LED found for PWM channel");
|
||||
}
|
||||
return AddressableLEDSim{index};
|
||||
}
|
||||
|
||||
|
||||
@@ -71,4 +71,6 @@ void AnalogGyroSim::SetInitialized(bool initialized) {
|
||||
HALSIM_SetAnalogGyroInitialized(m_index, initialized);
|
||||
}
|
||||
|
||||
void AnalogGyroSim::ResetData() { HALSIM_ResetAnalogGyroData(m_index); }
|
||||
void AnalogGyroSim::ResetData() {
|
||||
HALSIM_ResetAnalogGyroData(m_index);
|
||||
}
|
||||
|
||||
@@ -176,4 +176,6 @@ void AnalogInputSim::SetAccumulatorDeadband(int accumulatorDeadband) {
|
||||
HALSIM_SetAnalogInAccumulatorDeadband(m_index, accumulatorDeadband);
|
||||
}
|
||||
|
||||
void AnalogInputSim::ResetData() { HALSIM_ResetAnalogInData(m_index); }
|
||||
void AnalogInputSim::ResetData() {
|
||||
HALSIM_ResetAnalogInData(m_index);
|
||||
}
|
||||
|
||||
@@ -53,4 +53,6 @@ void AnalogOutputSim::SetInitialized(bool initialized) {
|
||||
HALSIM_SetAnalogOutInitialized(m_index, initialized);
|
||||
}
|
||||
|
||||
void AnalogOutputSim::ResetData() { HALSIM_ResetAnalogOutData(m_index); }
|
||||
void AnalogOutputSim::ResetData() {
|
||||
HALSIM_ResetAnalogOutData(m_index);
|
||||
}
|
||||
|
||||
@@ -20,7 +20,9 @@ AnalogTriggerSim::AnalogTriggerSim(const AnalogTrigger& analogTrigger)
|
||||
|
||||
AnalogTriggerSim AnalogTriggerSim::CreateForChannel(int channel) {
|
||||
int index = HALSIM_FindAnalogTriggerForChannel(channel);
|
||||
if (index < 0) throw std::out_of_range("no analog trigger found for channel");
|
||||
if (index < 0) {
|
||||
throw std::out_of_range("no analog trigger found for channel");
|
||||
}
|
||||
return AnalogTriggerSim{index};
|
||||
}
|
||||
|
||||
@@ -83,4 +85,6 @@ void AnalogTriggerSim::SetTriggerUpperBound(double triggerUpperBound) {
|
||||
HALSIM_SetAnalogTriggerTriggerUpperBound(m_index, triggerUpperBound);
|
||||
}
|
||||
|
||||
void AnalogTriggerSim::ResetData() { HALSIM_ResetAnalogTriggerData(m_index); }
|
||||
void AnalogTriggerSim::ResetData() {
|
||||
HALSIM_ResetAnalogTriggerData(m_index);
|
||||
}
|
||||
|
||||
@@ -74,4 +74,6 @@ CallbackStore::~CallbackStore() {
|
||||
}
|
||||
}
|
||||
|
||||
void CallbackStore::SetUid(int32_t uid) { this->uid = uid; }
|
||||
void CallbackStore::SetUid(int32_t uid) {
|
||||
this->uid = uid;
|
||||
}
|
||||
|
||||
@@ -47,9 +47,13 @@ std::unique_ptr<CallbackStore> DIOSim::RegisterValueCallback(
|
||||
return store;
|
||||
}
|
||||
|
||||
bool DIOSim::GetValue() const { return HALSIM_GetDIOValue(m_index); }
|
||||
bool DIOSim::GetValue() const {
|
||||
return HALSIM_GetDIOValue(m_index);
|
||||
}
|
||||
|
||||
void DIOSim::SetValue(bool value) { HALSIM_SetDIOValue(m_index, value); }
|
||||
void DIOSim::SetValue(bool value) {
|
||||
HALSIM_SetDIOValue(m_index, value);
|
||||
}
|
||||
|
||||
std::unique_ptr<CallbackStore> DIOSim::RegisterPulseLengthCallback(
|
||||
NotifyCallback callback, bool initialNotify) {
|
||||
@@ -77,7 +81,9 @@ std::unique_ptr<CallbackStore> DIOSim::RegisterIsInputCallback(
|
||||
return store;
|
||||
}
|
||||
|
||||
bool DIOSim::GetIsInput() const { return HALSIM_GetDIOIsInput(m_index); }
|
||||
bool DIOSim::GetIsInput() const {
|
||||
return HALSIM_GetDIOIsInput(m_index);
|
||||
}
|
||||
|
||||
void DIOSim::SetIsInput(bool isInput) {
|
||||
HALSIM_SetDIOIsInput(m_index, isInput);
|
||||
@@ -92,10 +98,14 @@ std::unique_ptr<CallbackStore> DIOSim::RegisterFilterIndexCallback(
|
||||
return store;
|
||||
}
|
||||
|
||||
int DIOSim::GetFilterIndex() const { return HALSIM_GetDIOFilterIndex(m_index); }
|
||||
int DIOSim::GetFilterIndex() const {
|
||||
return HALSIM_GetDIOFilterIndex(m_index);
|
||||
}
|
||||
|
||||
void DIOSim::SetFilterIndex(int filterIndex) {
|
||||
HALSIM_SetDIOFilterIndex(m_index, filterIndex);
|
||||
}
|
||||
|
||||
void DIOSim::ResetData() { HALSIM_ResetDIOData(m_index); }
|
||||
void DIOSim::ResetData() {
|
||||
HALSIM_ResetDIOData(m_index);
|
||||
}
|
||||
|
||||
@@ -20,7 +20,9 @@ DigitalPWMSim::DigitalPWMSim(const DigitalOutput& digitalOutput)
|
||||
|
||||
DigitalPWMSim DigitalPWMSim::CreateForChannel(int channel) {
|
||||
int index = HALSIM_FindDigitalPWMForChannel(channel);
|
||||
if (index < 0) throw std::out_of_range("no digital PWM found for channel");
|
||||
if (index < 0) {
|
||||
throw std::out_of_range("no digital PWM found for channel");
|
||||
}
|
||||
return DigitalPWMSim{index};
|
||||
}
|
||||
|
||||
@@ -71,8 +73,14 @@ std::unique_ptr<CallbackStore> DigitalPWMSim::RegisterPinCallback(
|
||||
return store;
|
||||
}
|
||||
|
||||
int DigitalPWMSim::GetPin() const { return HALSIM_GetDigitalPWMPin(m_index); }
|
||||
int DigitalPWMSim::GetPin() const {
|
||||
return HALSIM_GetDigitalPWMPin(m_index);
|
||||
}
|
||||
|
||||
void DigitalPWMSim::SetPin(int pin) { HALSIM_SetDigitalPWMPin(m_index, pin); }
|
||||
void DigitalPWMSim::SetPin(int pin) {
|
||||
HALSIM_SetDigitalPWMPin(m_index, pin);
|
||||
}
|
||||
|
||||
void DigitalPWMSim::ResetData() { HALSIM_ResetDigitalPWMData(m_index); }
|
||||
void DigitalPWMSim::ResetData() {
|
||||
HALSIM_ResetDigitalPWMData(m_index);
|
||||
}
|
||||
|
||||
@@ -24,7 +24,9 @@ std::unique_ptr<CallbackStore> DriverStationSim::RegisterEnabledCallback(
|
||||
return store;
|
||||
}
|
||||
|
||||
bool DriverStationSim::GetEnabled() { return HALSIM_GetDriverStationEnabled(); }
|
||||
bool DriverStationSim::GetEnabled() {
|
||||
return HALSIM_GetDriverStationEnabled();
|
||||
}
|
||||
|
||||
void DriverStationSim::SetEnabled(bool enabled) {
|
||||
HALSIM_SetDriverStationEnabled(enabled);
|
||||
@@ -56,9 +58,13 @@ std::unique_ptr<CallbackStore> DriverStationSim::RegisterTestCallback(
|
||||
return store;
|
||||
}
|
||||
|
||||
bool DriverStationSim::GetTest() { return HALSIM_GetDriverStationTest(); }
|
||||
bool DriverStationSim::GetTest() {
|
||||
return HALSIM_GetDriverStationTest();
|
||||
}
|
||||
|
||||
void DriverStationSim::SetTest(bool test) { HALSIM_SetDriverStationTest(test); }
|
||||
void DriverStationSim::SetTest(bool test) {
|
||||
HALSIM_SetDriverStationTest(test);
|
||||
}
|
||||
|
||||
std::unique_ptr<CallbackStore> DriverStationSim::RegisterEStopCallback(
|
||||
NotifyCallback callback, bool initialNotify) {
|
||||
@@ -69,7 +75,9 @@ std::unique_ptr<CallbackStore> DriverStationSim::RegisterEStopCallback(
|
||||
return store;
|
||||
}
|
||||
|
||||
bool DriverStationSim::GetEStop() { return HALSIM_GetDriverStationEStop(); }
|
||||
bool DriverStationSim::GetEStop() {
|
||||
return HALSIM_GetDriverStationEStop();
|
||||
}
|
||||
|
||||
void DriverStationSim::SetEStop(bool eStop) {
|
||||
HALSIM_SetDriverStationEStop(eStop);
|
||||
@@ -249,4 +257,6 @@ void DriverStationSim::SetReplayNumber(int replayNumber) {
|
||||
HALSIM_SetReplayNumber(replayNumber);
|
||||
}
|
||||
|
||||
void DriverStationSim::ResetData() { HALSIM_ResetDriverStationData(); }
|
||||
void DriverStationSim::ResetData() {
|
||||
HALSIM_ResetDriverStationData();
|
||||
}
|
||||
|
||||
@@ -20,7 +20,9 @@ DutyCycleSim::DutyCycleSim(const DutyCycle& dutyCycle)
|
||||
|
||||
DutyCycleSim DutyCycleSim::CreateForChannel(int channel) {
|
||||
int index = HALSIM_FindDutyCycleForChannel(channel);
|
||||
if (index < 0) throw std::out_of_range("no duty cycle found for channel");
|
||||
if (index < 0) {
|
||||
throw std::out_of_range("no duty cycle found for channel");
|
||||
}
|
||||
return DutyCycleSim{index};
|
||||
}
|
||||
|
||||
@@ -79,4 +81,6 @@ void DutyCycleSim::SetOutput(double period) {
|
||||
HALSIM_SetDutyCycleOutput(m_index, period);
|
||||
}
|
||||
|
||||
void DutyCycleSim::ResetData() { HALSIM_ResetDutyCycleData(m_index); }
|
||||
void DutyCycleSim::ResetData() {
|
||||
HALSIM_ResetDutyCycleData(m_index);
|
||||
}
|
||||
|
||||
@@ -20,11 +20,15 @@ EncoderSim::EncoderSim(const Encoder& encoder)
|
||||
|
||||
EncoderSim EncoderSim::CreateForChannel(int channel) {
|
||||
int index = HALSIM_FindEncoderForChannel(channel);
|
||||
if (index < 0) throw std::out_of_range("no encoder found for channel");
|
||||
if (index < 0) {
|
||||
throw std::out_of_range("no encoder found for channel");
|
||||
}
|
||||
return EncoderSim{index};
|
||||
}
|
||||
|
||||
EncoderSim EncoderSim::CreateForIndex(int index) { return EncoderSim{index}; }
|
||||
EncoderSim EncoderSim::CreateForIndex(int index) {
|
||||
return EncoderSim{index};
|
||||
}
|
||||
|
||||
std::unique_ptr<CallbackStore> EncoderSim::RegisterInitializedCallback(
|
||||
NotifyCallback callback, bool initialNotify) {
|
||||
@@ -52,9 +56,13 @@ std::unique_ptr<CallbackStore> EncoderSim::RegisterCountCallback(
|
||||
return store;
|
||||
}
|
||||
|
||||
int EncoderSim::GetCount() const { return HALSIM_GetEncoderCount(m_index); }
|
||||
int EncoderSim::GetCount() const {
|
||||
return HALSIM_GetEncoderCount(m_index);
|
||||
}
|
||||
|
||||
void EncoderSim::SetCount(int count) { HALSIM_SetEncoderCount(m_index, count); }
|
||||
void EncoderSim::SetCount(int count) {
|
||||
HALSIM_SetEncoderCount(m_index, count);
|
||||
}
|
||||
|
||||
std::unique_ptr<CallbackStore> EncoderSim::RegisterPeriodCallback(
|
||||
NotifyCallback callback, bool initialNotify) {
|
||||
@@ -82,7 +90,9 @@ std::unique_ptr<CallbackStore> EncoderSim::RegisterResetCallback(
|
||||
return store;
|
||||
}
|
||||
|
||||
bool EncoderSim::GetReset() const { return HALSIM_GetEncoderReset(m_index); }
|
||||
bool EncoderSim::GetReset() const {
|
||||
return HALSIM_GetEncoderReset(m_index);
|
||||
}
|
||||
|
||||
void EncoderSim::SetReset(bool reset) {
|
||||
HALSIM_SetEncoderReset(m_index, reset);
|
||||
@@ -173,14 +183,22 @@ void EncoderSim::SetDistancePerPulse(double distancePerPulse) {
|
||||
HALSIM_SetEncoderDistancePerPulse(m_index, distancePerPulse);
|
||||
}
|
||||
|
||||
void EncoderSim::ResetData() { HALSIM_ResetEncoderData(m_index); }
|
||||
void EncoderSim::ResetData() {
|
||||
HALSIM_ResetEncoderData(m_index);
|
||||
}
|
||||
|
||||
void EncoderSim::SetDistance(double distance) {
|
||||
HALSIM_SetEncoderDistance(m_index, distance);
|
||||
}
|
||||
|
||||
double EncoderSim::GetDistance() { return HALSIM_GetEncoderDistance(m_index); }
|
||||
double EncoderSim::GetDistance() {
|
||||
return HALSIM_GetEncoderDistance(m_index);
|
||||
}
|
||||
|
||||
void EncoderSim::SetRate(double rate) { HALSIM_SetEncoderRate(m_index, rate); }
|
||||
void EncoderSim::SetRate(double rate) {
|
||||
HALSIM_SetEncoderRate(m_index, rate);
|
||||
}
|
||||
|
||||
double EncoderSim::GetRate() { return HALSIM_GetEncoderRate(m_index); }
|
||||
double EncoderSim::GetRate() {
|
||||
return HALSIM_GetEncoderRate(m_index);
|
||||
}
|
||||
|
||||
@@ -15,7 +15,9 @@ GenericHIDSim::GenericHIDSim(const GenericHID& joystick)
|
||||
|
||||
GenericHIDSim::GenericHIDSim(int port) : m_port{port} {}
|
||||
|
||||
void GenericHIDSim::NotifyNewData() { DriverStationSim::NotifyNewData(); }
|
||||
void GenericHIDSim::NotifyNewData() {
|
||||
DriverStationSim::NotifyNewData();
|
||||
}
|
||||
|
||||
void GenericHIDSim::SetRawButton(int button, bool value) {
|
||||
DriverStationSim::SetJoystickButton(m_port, button, value);
|
||||
@@ -29,7 +31,9 @@ void GenericHIDSim::SetPOV(int pov, int value) {
|
||||
DriverStationSim::SetJoystickPOV(m_port, pov, value);
|
||||
}
|
||||
|
||||
void GenericHIDSim::SetPOV(int value) { SetPOV(0, value); }
|
||||
void GenericHIDSim::SetPOV(int value) {
|
||||
SetPOV(0, value);
|
||||
}
|
||||
|
||||
void GenericHIDSim::SetAxisCount(int count) {
|
||||
DriverStationSim::SetJoystickAxisCount(m_port, count);
|
||||
|
||||
@@ -55,6 +55,10 @@ void JoystickSim::SetThrottle(double value) {
|
||||
value);
|
||||
}
|
||||
|
||||
void JoystickSim::SetTrigger(bool state) { SetRawButton(1, state); }
|
||||
void JoystickSim::SetTrigger(bool state) {
|
||||
SetRawButton(1, state);
|
||||
}
|
||||
|
||||
void JoystickSim::SetTop(bool state) { SetRawButton(2, state); }
|
||||
void JoystickSim::SetTop(bool state) {
|
||||
SetRawButton(2, state);
|
||||
}
|
||||
|
||||
@@ -152,4 +152,6 @@ void PCMSim::SetAllSolenoidOutputs(uint8_t outputs) {
|
||||
HALSIM_SetPCMAllSolenoids(m_index, outputs);
|
||||
}
|
||||
|
||||
void PCMSim::ResetData() { HALSIM_ResetPCMData(m_index); }
|
||||
void PCMSim::ResetData() {
|
||||
HALSIM_ResetPCMData(m_index);
|
||||
}
|
||||
|
||||
@@ -61,7 +61,9 @@ std::unique_ptr<CallbackStore> PDPSim::RegisterVoltageCallback(
|
||||
return store;
|
||||
}
|
||||
|
||||
double PDPSim::GetVoltage() const { return HALSIM_GetPDPVoltage(m_index); }
|
||||
double PDPSim::GetVoltage() const {
|
||||
return HALSIM_GetPDPVoltage(m_index);
|
||||
}
|
||||
|
||||
void PDPSim::SetVoltage(double voltage) {
|
||||
HALSIM_SetPDPVoltage(m_index, voltage);
|
||||
@@ -92,4 +94,6 @@ void PDPSim::SetAllCurrents(const double* currents) {
|
||||
HALSIM_SetPDPAllCurrents(m_index, currents);
|
||||
}
|
||||
|
||||
void PDPSim::ResetData() { HALSIM_ResetPDPData(m_index); }
|
||||
void PDPSim::ResetData() {
|
||||
HALSIM_ResetPDPData(m_index);
|
||||
}
|
||||
|
||||
@@ -44,7 +44,9 @@ std::unique_ptr<CallbackStore> PWMSim::RegisterRawValueCallback(
|
||||
return store;
|
||||
}
|
||||
|
||||
int PWMSim::GetRawValue() const { return HALSIM_GetPWMRawValue(m_index); }
|
||||
int PWMSim::GetRawValue() const {
|
||||
return HALSIM_GetPWMRawValue(m_index);
|
||||
}
|
||||
|
||||
void PWMSim::SetRawValue(int rawValue) {
|
||||
HALSIM_SetPWMRawValue(m_index, rawValue);
|
||||
@@ -59,9 +61,13 @@ std::unique_ptr<CallbackStore> PWMSim::RegisterSpeedCallback(
|
||||
return store;
|
||||
}
|
||||
|
||||
double PWMSim::GetSpeed() const { return HALSIM_GetPWMSpeed(m_index); }
|
||||
double PWMSim::GetSpeed() const {
|
||||
return HALSIM_GetPWMSpeed(m_index);
|
||||
}
|
||||
|
||||
void PWMSim::SetSpeed(double speed) { HALSIM_SetPWMSpeed(m_index, speed); }
|
||||
void PWMSim::SetSpeed(double speed) {
|
||||
HALSIM_SetPWMSpeed(m_index, speed);
|
||||
}
|
||||
|
||||
std::unique_ptr<CallbackStore> PWMSim::RegisterPositionCallback(
|
||||
NotifyCallback callback, bool initialNotify) {
|
||||
@@ -72,7 +78,9 @@ std::unique_ptr<CallbackStore> PWMSim::RegisterPositionCallback(
|
||||
return store;
|
||||
}
|
||||
|
||||
double PWMSim::GetPosition() const { return HALSIM_GetPWMPosition(m_index); }
|
||||
double PWMSim::GetPosition() const {
|
||||
return HALSIM_GetPWMPosition(m_index);
|
||||
}
|
||||
|
||||
void PWMSim::SetPosition(double position) {
|
||||
HALSIM_SetPWMPosition(m_index, position);
|
||||
@@ -87,7 +95,9 @@ std::unique_ptr<CallbackStore> PWMSim::RegisterPeriodScaleCallback(
|
||||
return store;
|
||||
}
|
||||
|
||||
int PWMSim::GetPeriodScale() const { return HALSIM_GetPWMPeriodScale(m_index); }
|
||||
int PWMSim::GetPeriodScale() const {
|
||||
return HALSIM_GetPWMPeriodScale(m_index);
|
||||
}
|
||||
|
||||
void PWMSim::SetPeriodScale(int periodScale) {
|
||||
HALSIM_SetPWMPeriodScale(m_index, periodScale);
|
||||
@@ -102,10 +112,14 @@ std::unique_ptr<CallbackStore> PWMSim::RegisterZeroLatchCallback(
|
||||
return store;
|
||||
}
|
||||
|
||||
bool PWMSim::GetZeroLatch() const { return HALSIM_GetPWMZeroLatch(m_index); }
|
||||
bool PWMSim::GetZeroLatch() const {
|
||||
return HALSIM_GetPWMZeroLatch(m_index);
|
||||
}
|
||||
|
||||
void PWMSim::SetZeroLatch(bool zeroLatch) {
|
||||
HALSIM_SetPWMZeroLatch(m_index, zeroLatch);
|
||||
}
|
||||
|
||||
void PWMSim::ResetData() { HALSIM_ResetPWMData(m_index); }
|
||||
void PWMSim::ResetData() {
|
||||
HALSIM_ResetPWMData(m_index);
|
||||
}
|
||||
|
||||
@@ -61,7 +61,9 @@ std::unique_ptr<CallbackStore> RelaySim::RegisterForwardCallback(
|
||||
return store;
|
||||
}
|
||||
|
||||
bool RelaySim::GetForward() const { return HALSIM_GetRelayForward(m_index); }
|
||||
bool RelaySim::GetForward() const {
|
||||
return HALSIM_GetRelayForward(m_index);
|
||||
}
|
||||
|
||||
void RelaySim::SetForward(bool forward) {
|
||||
HALSIM_SetRelayForward(m_index, forward);
|
||||
@@ -76,10 +78,14 @@ std::unique_ptr<CallbackStore> RelaySim::RegisterReverseCallback(
|
||||
return store;
|
||||
}
|
||||
|
||||
bool RelaySim::GetReverse() const { return HALSIM_GetRelayReverse(m_index); }
|
||||
bool RelaySim::GetReverse() const {
|
||||
return HALSIM_GetRelayReverse(m_index);
|
||||
}
|
||||
|
||||
void RelaySim::SetReverse(bool reverse) {
|
||||
HALSIM_SetRelayReverse(m_index, reverse);
|
||||
}
|
||||
|
||||
void RelaySim::ResetData() { HALSIM_ResetRelayData(m_index); }
|
||||
void RelaySim::ResetData() {
|
||||
HALSIM_ResetRelayData(m_index);
|
||||
}
|
||||
|
||||
@@ -21,7 +21,9 @@ std::unique_ptr<CallbackStore> RoboRioSim::RegisterFPGAButtonCallback(
|
||||
return store;
|
||||
}
|
||||
|
||||
bool RoboRioSim::GetFPGAButton() { return HALSIM_GetRoboRioFPGAButton(); }
|
||||
bool RoboRioSim::GetFPGAButton() {
|
||||
return HALSIM_GetRoboRioFPGAButton();
|
||||
}
|
||||
|
||||
void RoboRioSim::SetFPGAButton(bool fPGAButton) {
|
||||
HALSIM_SetRoboRioFPGAButton(fPGAButton);
|
||||
@@ -104,7 +106,9 @@ std::unique_ptr<CallbackStore> RoboRioSim::RegisterUserActive6VCallback(
|
||||
return store;
|
||||
}
|
||||
|
||||
bool RoboRioSim::GetUserActive6V() { return HALSIM_GetRoboRioUserActive6V(); }
|
||||
bool RoboRioSim::GetUserActive6V() {
|
||||
return HALSIM_GetRoboRioUserActive6V();
|
||||
}
|
||||
|
||||
void RoboRioSim::SetUserActive6V(bool userActive6V) {
|
||||
HALSIM_SetRoboRioUserActive6V(userActive6V);
|
||||
@@ -153,7 +157,9 @@ std::unique_ptr<CallbackStore> RoboRioSim::RegisterUserActive5VCallback(
|
||||
return store;
|
||||
}
|
||||
|
||||
bool RoboRioSim::GetUserActive5V() { return HALSIM_GetRoboRioUserActive5V(); }
|
||||
bool RoboRioSim::GetUserActive5V() {
|
||||
return HALSIM_GetRoboRioUserActive5V();
|
||||
}
|
||||
|
||||
void RoboRioSim::SetUserActive5V(bool userActive5V) {
|
||||
HALSIM_SetRoboRioUserActive5V(userActive5V);
|
||||
@@ -202,7 +208,9 @@ std::unique_ptr<CallbackStore> RoboRioSim::RegisterUserActive3V3Callback(
|
||||
return store;
|
||||
}
|
||||
|
||||
bool RoboRioSim::GetUserActive3V3() { return HALSIM_GetRoboRioUserActive3V3(); }
|
||||
bool RoboRioSim::GetUserActive3V3() {
|
||||
return HALSIM_GetRoboRioUserActive3V3();
|
||||
}
|
||||
|
||||
void RoboRioSim::SetUserActive3V3(bool userActive3V3) {
|
||||
HALSIM_SetRoboRioUserActive3V3(userActive3V3);
|
||||
@@ -217,7 +225,9 @@ std::unique_ptr<CallbackStore> RoboRioSim::RegisterUserFaults6VCallback(
|
||||
return store;
|
||||
}
|
||||
|
||||
int RoboRioSim::GetUserFaults6V() { return HALSIM_GetRoboRioUserFaults6V(); }
|
||||
int RoboRioSim::GetUserFaults6V() {
|
||||
return HALSIM_GetRoboRioUserFaults6V();
|
||||
}
|
||||
|
||||
void RoboRioSim::SetUserFaults6V(int userFaults6V) {
|
||||
HALSIM_SetRoboRioUserFaults6V(userFaults6V);
|
||||
@@ -232,7 +242,9 @@ std::unique_ptr<CallbackStore> RoboRioSim::RegisterUserFaults5VCallback(
|
||||
return store;
|
||||
}
|
||||
|
||||
int RoboRioSim::GetUserFaults5V() { return HALSIM_GetRoboRioUserFaults5V(); }
|
||||
int RoboRioSim::GetUserFaults5V() {
|
||||
return HALSIM_GetRoboRioUserFaults5V();
|
||||
}
|
||||
|
||||
void RoboRioSim::SetUserFaults5V(int userFaults5V) {
|
||||
HALSIM_SetRoboRioUserFaults5V(userFaults5V);
|
||||
@@ -247,10 +259,14 @@ std::unique_ptr<CallbackStore> RoboRioSim::RegisterUserFaults3V3Callback(
|
||||
return store;
|
||||
}
|
||||
|
||||
int RoboRioSim::GetUserFaults3V3() { return HALSIM_GetRoboRioUserFaults3V3(); }
|
||||
int RoboRioSim::GetUserFaults3V3() {
|
||||
return HALSIM_GetRoboRioUserFaults3V3();
|
||||
}
|
||||
|
||||
void RoboRioSim::SetUserFaults3V3(int userFaults3V3) {
|
||||
HALSIM_SetRoboRioUserFaults3V3(userFaults3V3);
|
||||
}
|
||||
|
||||
void ResetData() { HALSIM_ResetRoboRioData(); }
|
||||
void ResetData() {
|
||||
HALSIM_ResetRoboRioData();
|
||||
}
|
||||
|
||||
@@ -12,7 +12,9 @@
|
||||
using namespace frc;
|
||||
using namespace frc::sim;
|
||||
|
||||
SPIAccelerometerSim::SPIAccelerometerSim(int index) { m_index = index; }
|
||||
SPIAccelerometerSim::SPIAccelerometerSim(int index) {
|
||||
m_index = index;
|
||||
}
|
||||
|
||||
std::unique_ptr<CallbackStore> SPIAccelerometerSim::RegisterActiveCallback(
|
||||
NotifyCallback callback, bool initialNotify) {
|
||||
|
||||
@@ -37,8 +37,12 @@ std::vector<std::string> SimDeviceSim::GetEnumOptions(hal::SimEnum val) {
|
||||
const char** options = HALSIM_GetSimValueEnumOptions(val, &numOptions);
|
||||
std::vector<std::string> rv;
|
||||
rv.reserve(numOptions);
|
||||
for (int32_t i = 0; i < numOptions; ++i) rv.emplace_back(options[i]);
|
||||
for (int32_t i = 0; i < numOptions; ++i) {
|
||||
rv.emplace_back(options[i]);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
void SimDeviceSim::ResetData() { HALSIM_ResetSimDeviceData(); }
|
||||
void SimDeviceSim::ResetData() {
|
||||
HALSIM_ResetSimDeviceData();
|
||||
}
|
||||
|
||||
@@ -9,21 +9,37 @@
|
||||
namespace frc {
|
||||
namespace sim {
|
||||
|
||||
void SetRuntimeType(HAL_RuntimeType type) { HALSIM_SetRuntimeType(type); }
|
||||
void SetRuntimeType(HAL_RuntimeType type) {
|
||||
HALSIM_SetRuntimeType(type);
|
||||
}
|
||||
|
||||
void WaitForProgramStart() { HALSIM_WaitForProgramStart(); }
|
||||
void WaitForProgramStart() {
|
||||
HALSIM_WaitForProgramStart();
|
||||
}
|
||||
|
||||
void SetProgramStarted() { HALSIM_SetProgramStarted(); }
|
||||
void SetProgramStarted() {
|
||||
HALSIM_SetProgramStarted();
|
||||
}
|
||||
|
||||
bool GetProgramStarted() { return HALSIM_GetProgramStarted(); }
|
||||
bool GetProgramStarted() {
|
||||
return HALSIM_GetProgramStarted();
|
||||
}
|
||||
|
||||
void RestartTiming() { HALSIM_RestartTiming(); }
|
||||
void RestartTiming() {
|
||||
HALSIM_RestartTiming();
|
||||
}
|
||||
|
||||
void PauseTiming() { HALSIM_PauseTiming(); }
|
||||
void PauseTiming() {
|
||||
HALSIM_PauseTiming();
|
||||
}
|
||||
|
||||
void ResumeTiming() { HALSIM_ResumeTiming(); }
|
||||
void ResumeTiming() {
|
||||
HALSIM_ResumeTiming();
|
||||
}
|
||||
|
||||
bool IsTimingPaused() { return HALSIM_IsTimingPaused(); }
|
||||
bool IsTimingPaused() {
|
||||
return HALSIM_IsTimingPaused();
|
||||
}
|
||||
|
||||
void StepTiming(units::second_t delta) {
|
||||
HALSIM_StepTiming(static_cast<uint64_t>(delta.to<double>() * 1e6));
|
||||
|
||||
@@ -50,12 +50,16 @@ FieldObject2d* Field2d::GetObject(const wpi::Twine& name) {
|
||||
std::scoped_lock lock(m_mutex);
|
||||
std::string nameStr = name.str();
|
||||
for (auto&& obj : m_objects) {
|
||||
if (obj->m_name == nameStr) return obj.get();
|
||||
if (obj->m_name == nameStr) {
|
||||
return obj.get();
|
||||
}
|
||||
}
|
||||
m_objects.emplace_back(std::make_unique<FieldObject2d>(
|
||||
std::move(nameStr), FieldObject2d::private_init{}));
|
||||
auto obj = m_objects.back().get();
|
||||
if (m_table) obj->m_entry = m_table->GetEntry(obj->m_name);
|
||||
if (m_table) {
|
||||
obj->m_entry = m_table->GetEntry(obj->m_name);
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,9 @@ void FieldObject2d::SetPose(units::meter_t x, units::meter_t y,
|
||||
Pose2d FieldObject2d::GetPose() const {
|
||||
std::scoped_lock lock(m_mutex);
|
||||
UpdateFromEntry();
|
||||
if (m_poses.empty()) return {};
|
||||
if (m_poses.empty()) {
|
||||
return {};
|
||||
}
|
||||
return m_poses[0];
|
||||
}
|
||||
|
||||
@@ -61,7 +63,9 @@ wpi::ArrayRef<Pose2d> FieldObject2d::GetPoses(
|
||||
}
|
||||
|
||||
void FieldObject2d::UpdateEntry(bool setDefault) {
|
||||
if (!m_entry) return;
|
||||
if (!m_entry) {
|
||||
return;
|
||||
}
|
||||
wpi::SmallVector<double, 9> arr;
|
||||
for (auto&& pose : m_poses) {
|
||||
auto& translation = pose.Translation();
|
||||
@@ -69,19 +73,26 @@ void FieldObject2d::UpdateEntry(bool setDefault) {
|
||||
arr.push_back(translation.Y().to<double>());
|
||||
arr.push_back(pose.Rotation().Degrees().to<double>());
|
||||
}
|
||||
if (setDefault)
|
||||
if (setDefault) {
|
||||
m_entry.SetDefaultDoubleArray(arr);
|
||||
else
|
||||
} else {
|
||||
m_entry.SetDoubleArray(arr);
|
||||
}
|
||||
}
|
||||
|
||||
void FieldObject2d::UpdateFromEntry() const {
|
||||
if (!m_entry) return;
|
||||
if (!m_entry) {
|
||||
return;
|
||||
}
|
||||
auto val = m_entry.GetValue();
|
||||
if (!val || !val->IsDoubleArray()) return;
|
||||
if (!val || !val->IsDoubleArray()) {
|
||||
return;
|
||||
}
|
||||
auto arr = val->GetDoubleArray();
|
||||
auto size = arr.size();
|
||||
if ((size % 3) != 0) return;
|
||||
if ((size % 3) != 0) {
|
||||
return;
|
||||
}
|
||||
m_poses.resize(size / 3);
|
||||
for (size_t i = 0; i < size / 3; ++i) {
|
||||
m_poses[i] =
|
||||
|
||||
@@ -9,8 +9,9 @@
|
||||
using namespace frc;
|
||||
|
||||
SendableBase::SendableBase(bool addLiveWindow) {
|
||||
if (addLiveWindow)
|
||||
if (addLiveWindow) {
|
||||
SendableRegistry::GetInstance().AddLW(this, "");
|
||||
else
|
||||
} else {
|
||||
SendableRegistry::GetInstance().Add(this, "");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,14 +20,20 @@ std::shared_ptr<nt::NetworkTable> SendableBuilderImpl::GetTable() {
|
||||
return m_table;
|
||||
}
|
||||
|
||||
bool SendableBuilderImpl::HasTable() const { return m_table != nullptr; }
|
||||
bool SendableBuilderImpl::HasTable() const {
|
||||
return m_table != nullptr;
|
||||
}
|
||||
|
||||
bool SendableBuilderImpl::IsActuator() const { return m_actuator; }
|
||||
bool SendableBuilderImpl::IsActuator() const {
|
||||
return m_actuator;
|
||||
}
|
||||
|
||||
void SendableBuilderImpl::UpdateTable() {
|
||||
uint64_t time = nt::Now();
|
||||
for (auto& property : m_properties) {
|
||||
if (property.update) property.update(property.entry, time);
|
||||
if (property.update) {
|
||||
property.update(property.entry, time);
|
||||
}
|
||||
}
|
||||
for (auto& updateTable : m_updateTables) {
|
||||
updateTable();
|
||||
@@ -35,26 +41,40 @@ void SendableBuilderImpl::UpdateTable() {
|
||||
}
|
||||
|
||||
void SendableBuilderImpl::StartListeners() {
|
||||
for (auto& property : m_properties) property.StartListener();
|
||||
if (m_controllableEntry) m_controllableEntry.SetBoolean(true);
|
||||
for (auto& property : m_properties) {
|
||||
property.StartListener();
|
||||
}
|
||||
if (m_controllableEntry) {
|
||||
m_controllableEntry.SetBoolean(true);
|
||||
}
|
||||
}
|
||||
|
||||
void SendableBuilderImpl::StopListeners() {
|
||||
for (auto& property : m_properties) property.StopListener();
|
||||
if (m_controllableEntry) m_controllableEntry.SetBoolean(false);
|
||||
for (auto& property : m_properties) {
|
||||
property.StopListener();
|
||||
}
|
||||
if (m_controllableEntry) {
|
||||
m_controllableEntry.SetBoolean(false);
|
||||
}
|
||||
}
|
||||
|
||||
void SendableBuilderImpl::StartLiveWindowMode() {
|
||||
if (m_safeState) m_safeState();
|
||||
if (m_safeState) {
|
||||
m_safeState();
|
||||
}
|
||||
StartListeners();
|
||||
}
|
||||
|
||||
void SendableBuilderImpl::StopLiveWindowMode() {
|
||||
StopListeners();
|
||||
if (m_safeState) m_safeState();
|
||||
if (m_safeState) {
|
||||
m_safeState();
|
||||
}
|
||||
}
|
||||
|
||||
void SendableBuilderImpl::ClearProperties() { m_properties.clear(); }
|
||||
void SendableBuilderImpl::ClearProperties() {
|
||||
m_properties.clear();
|
||||
}
|
||||
|
||||
void SendableBuilderImpl::SetSmartDashboardType(const wpi::Twine& type) {
|
||||
m_table->GetEntry(".type").SetString(type);
|
||||
@@ -92,7 +112,9 @@ void SendableBuilderImpl::AddBooleanProperty(const wpi::Twine& key,
|
||||
[=](nt::NetworkTableEntry entry) -> NT_EntryListener {
|
||||
return entry.AddListener(
|
||||
[=](const nt::EntryNotification& event) {
|
||||
if (!event.value->IsBoolean()) return;
|
||||
if (!event.value->IsBoolean()) {
|
||||
return;
|
||||
}
|
||||
SmartDashboard::PostListenerTask(
|
||||
[=] { setter(event.value->GetBoolean()); });
|
||||
},
|
||||
@@ -116,7 +138,9 @@ void SendableBuilderImpl::AddDoubleProperty(
|
||||
[=](nt::NetworkTableEntry entry) -> NT_EntryListener {
|
||||
return entry.AddListener(
|
||||
[=](const nt::EntryNotification& event) {
|
||||
if (!event.value->IsDouble()) return;
|
||||
if (!event.value->IsDouble()) {
|
||||
return;
|
||||
}
|
||||
SmartDashboard::PostListenerTask(
|
||||
[=] { setter(event.value->GetDouble()); });
|
||||
},
|
||||
@@ -140,7 +164,9 @@ void SendableBuilderImpl::AddStringProperty(
|
||||
[=](nt::NetworkTableEntry entry) -> NT_EntryListener {
|
||||
return entry.AddListener(
|
||||
[=](const nt::EntryNotification& event) {
|
||||
if (!event.value->IsString()) return;
|
||||
if (!event.value->IsString()) {
|
||||
return;
|
||||
}
|
||||
SmartDashboard::PostListenerTask(
|
||||
[=] { setter(event.value->GetString()); });
|
||||
},
|
||||
@@ -164,7 +190,9 @@ void SendableBuilderImpl::AddBooleanArrayProperty(
|
||||
[=](nt::NetworkTableEntry entry) -> NT_EntryListener {
|
||||
return entry.AddListener(
|
||||
[=](const nt::EntryNotification& event) {
|
||||
if (!event.value->IsBooleanArray()) return;
|
||||
if (!event.value->IsBooleanArray()) {
|
||||
return;
|
||||
}
|
||||
SmartDashboard::PostListenerTask(
|
||||
[=] { setter(event.value->GetBooleanArray()); });
|
||||
},
|
||||
@@ -188,7 +216,9 @@ void SendableBuilderImpl::AddDoubleArrayProperty(
|
||||
[=](nt::NetworkTableEntry entry) -> NT_EntryListener {
|
||||
return entry.AddListener(
|
||||
[=](const nt::EntryNotification& event) {
|
||||
if (!event.value->IsDoubleArray()) return;
|
||||
if (!event.value->IsDoubleArray()) {
|
||||
return;
|
||||
}
|
||||
SmartDashboard::PostListenerTask(
|
||||
[=] { setter(event.value->GetDoubleArray()); });
|
||||
},
|
||||
@@ -212,7 +242,9 @@ void SendableBuilderImpl::AddStringArrayProperty(
|
||||
[=](nt::NetworkTableEntry entry) -> NT_EntryListener {
|
||||
return entry.AddListener(
|
||||
[=](const nt::EntryNotification& event) {
|
||||
if (!event.value->IsStringArray()) return;
|
||||
if (!event.value->IsStringArray()) {
|
||||
return;
|
||||
}
|
||||
SmartDashboard::PostListenerTask(
|
||||
[=] { setter(event.value->GetStringArray()); });
|
||||
},
|
||||
@@ -236,7 +268,9 @@ void SendableBuilderImpl::AddRawProperty(
|
||||
[=](nt::NetworkTableEntry entry) -> NT_EntryListener {
|
||||
return entry.AddListener(
|
||||
[=](const nt::EntryNotification& event) {
|
||||
if (!event.value->IsRaw()) return;
|
||||
if (!event.value->IsRaw()) {
|
||||
return;
|
||||
}
|
||||
SmartDashboard::PostListenerTask(
|
||||
[=] { setter(event.value->GetRaw()); });
|
||||
},
|
||||
@@ -284,7 +318,9 @@ void SendableBuilderImpl::AddSmallStringProperty(
|
||||
[=](nt::NetworkTableEntry entry) -> NT_EntryListener {
|
||||
return entry.AddListener(
|
||||
[=](const nt::EntryNotification& event) {
|
||||
if (!event.value->IsString()) return;
|
||||
if (!event.value->IsString()) {
|
||||
return;
|
||||
}
|
||||
SmartDashboard::PostListenerTask(
|
||||
[=] { setter(event.value->GetString()); });
|
||||
},
|
||||
@@ -310,7 +346,9 @@ void SendableBuilderImpl::AddSmallBooleanArrayProperty(
|
||||
[=](nt::NetworkTableEntry entry) -> NT_EntryListener {
|
||||
return entry.AddListener(
|
||||
[=](const nt::EntryNotification& event) {
|
||||
if (!event.value->IsBooleanArray()) return;
|
||||
if (!event.value->IsBooleanArray()) {
|
||||
return;
|
||||
}
|
||||
SmartDashboard::PostListenerTask(
|
||||
[=] { setter(event.value->GetBooleanArray()); });
|
||||
},
|
||||
@@ -337,7 +375,9 @@ void SendableBuilderImpl::AddSmallDoubleArrayProperty(
|
||||
[=](nt::NetworkTableEntry entry) -> NT_EntryListener {
|
||||
return entry.AddListener(
|
||||
[=](const nt::EntryNotification& event) {
|
||||
if (!event.value->IsDoubleArray()) return;
|
||||
if (!event.value->IsDoubleArray()) {
|
||||
return;
|
||||
}
|
||||
SmartDashboard::PostListenerTask(
|
||||
[=] { setter(event.value->GetDoubleArray()); });
|
||||
},
|
||||
@@ -365,7 +405,9 @@ void SendableBuilderImpl::AddSmallStringArrayProperty(
|
||||
[=](nt::NetworkTableEntry entry) -> NT_EntryListener {
|
||||
return entry.AddListener(
|
||||
[=](const nt::EntryNotification& event) {
|
||||
if (!event.value->IsStringArray()) return;
|
||||
if (!event.value->IsStringArray()) {
|
||||
return;
|
||||
}
|
||||
SmartDashboard::PostListenerTask(
|
||||
[=] { setter(event.value->GetStringArray()); });
|
||||
},
|
||||
@@ -391,7 +433,9 @@ void SendableBuilderImpl::AddSmallRawProperty(
|
||||
[=](nt::NetworkTableEntry entry) -> NT_EntryListener {
|
||||
return entry.AddListener(
|
||||
[=](const nt::EntryNotification& event) {
|
||||
if (!event.value->IsRaw()) return;
|
||||
if (!event.value->IsRaw()) {
|
||||
return;
|
||||
}
|
||||
SmartDashboard::PostListenerTask(
|
||||
[=] { setter(event.value->GetRaw()); });
|
||||
},
|
||||
|
||||
@@ -51,9 +51,12 @@ struct SendableRegistry::Impl {
|
||||
SendableRegistry::Impl::Component& SendableRegistry::Impl::GetOrAdd(
|
||||
void* sendable, UID* uid) {
|
||||
UID& compUid = componentMap[sendable];
|
||||
if (compUid == 0)
|
||||
if (compUid == 0) {
|
||||
compUid = components.emplace_back(std::make_unique<Component>()) + 1;
|
||||
if (uid) *uid = compUid;
|
||||
}
|
||||
if (uid) {
|
||||
*uid = compUid;
|
||||
}
|
||||
|
||||
return *components[compUid - 1];
|
||||
}
|
||||
@@ -146,13 +149,17 @@ void SendableRegistry::AddChild(Sendable* parent, void* child) {
|
||||
bool SendableRegistry::Remove(Sendable* sendable) {
|
||||
std::scoped_lock lock(m_impl->mutex);
|
||||
auto it = m_impl->componentMap.find(sendable);
|
||||
if (it == m_impl->componentMap.end()) return false;
|
||||
if (it == m_impl->componentMap.end()) {
|
||||
return false;
|
||||
}
|
||||
UID compUid = it->getSecond();
|
||||
m_impl->components.erase(compUid - 1);
|
||||
m_impl->componentMap.erase(it);
|
||||
// update any parent pointers
|
||||
for (auto&& comp : m_impl->components) {
|
||||
if (comp->parent == sendable) comp->parent = nullptr;
|
||||
if (comp->parent == sendable) {
|
||||
comp->parent = nullptr;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -161,8 +168,9 @@ void SendableRegistry::Move(Sendable* to, Sendable* from) {
|
||||
std::scoped_lock lock(m_impl->mutex);
|
||||
auto it = m_impl->componentMap.find(from);
|
||||
if (it == m_impl->componentMap.end() ||
|
||||
!m_impl->components[it->getSecond() - 1])
|
||||
!m_impl->components[it->getSecond() - 1]) {
|
||||
return;
|
||||
}
|
||||
UID compUid = it->getSecond();
|
||||
m_impl->componentMap.erase(it);
|
||||
m_impl->componentMap[to] = compUid;
|
||||
@@ -175,7 +183,9 @@ void SendableRegistry::Move(Sendable* to, Sendable* from) {
|
||||
}
|
||||
// update any parent pointers
|
||||
for (auto&& comp : m_impl->components) {
|
||||
if (comp->parent == from) comp->parent = to;
|
||||
if (comp->parent == from) {
|
||||
comp->parent = to;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -188,8 +198,9 @@ std::string SendableRegistry::GetName(const Sendable* sendable) const {
|
||||
std::scoped_lock lock(m_impl->mutex);
|
||||
auto it = m_impl->componentMap.find(sendable);
|
||||
if (it == m_impl->componentMap.end() ||
|
||||
!m_impl->components[it->getSecond() - 1])
|
||||
return std::string{};
|
||||
!m_impl->components[it->getSecond() - 1]) {
|
||||
return {};
|
||||
}
|
||||
return m_impl->components[it->getSecond() - 1]->name;
|
||||
}
|
||||
|
||||
@@ -197,8 +208,9 @@ void SendableRegistry::SetName(Sendable* sendable, const wpi::Twine& name) {
|
||||
std::scoped_lock lock(m_impl->mutex);
|
||||
auto it = m_impl->componentMap.find(sendable);
|
||||
if (it == m_impl->componentMap.end() ||
|
||||
!m_impl->components[it->getSecond() - 1])
|
||||
!m_impl->components[it->getSecond() - 1]) {
|
||||
return;
|
||||
}
|
||||
m_impl->components[it->getSecond() - 1]->name = name.str();
|
||||
}
|
||||
|
||||
@@ -207,8 +219,9 @@ void SendableRegistry::SetName(Sendable* sendable, const wpi::Twine& moduleType,
|
||||
std::scoped_lock lock(m_impl->mutex);
|
||||
auto it = m_impl->componentMap.find(sendable);
|
||||
if (it == m_impl->componentMap.end() ||
|
||||
!m_impl->components[it->getSecond() - 1])
|
||||
!m_impl->components[it->getSecond() - 1]) {
|
||||
return;
|
||||
}
|
||||
m_impl->components[it->getSecond() - 1]->SetName(moduleType, channel);
|
||||
}
|
||||
|
||||
@@ -217,8 +230,9 @@ void SendableRegistry::SetName(Sendable* sendable, const wpi::Twine& moduleType,
|
||||
std::scoped_lock lock(m_impl->mutex);
|
||||
auto it = m_impl->componentMap.find(sendable);
|
||||
if (it == m_impl->componentMap.end() ||
|
||||
!m_impl->components[it->getSecond() - 1])
|
||||
!m_impl->components[it->getSecond() - 1]) {
|
||||
return;
|
||||
}
|
||||
m_impl->components[it->getSecond() - 1]->SetName(moduleType, moduleNumber,
|
||||
channel);
|
||||
}
|
||||
@@ -228,8 +242,9 @@ void SendableRegistry::SetName(Sendable* sendable, const wpi::Twine& subsystem,
|
||||
std::scoped_lock lock(m_impl->mutex);
|
||||
auto it = m_impl->componentMap.find(sendable);
|
||||
if (it == m_impl->componentMap.end() ||
|
||||
!m_impl->components[it->getSecond() - 1])
|
||||
!m_impl->components[it->getSecond() - 1]) {
|
||||
return;
|
||||
}
|
||||
auto& comp = *m_impl->components[it->getSecond() - 1];
|
||||
comp.name = name.str();
|
||||
comp.subsystem = subsystem.str();
|
||||
@@ -239,8 +254,9 @@ std::string SendableRegistry::GetSubsystem(const Sendable* sendable) const {
|
||||
std::scoped_lock lock(m_impl->mutex);
|
||||
auto it = m_impl->componentMap.find(sendable);
|
||||
if (it == m_impl->componentMap.end() ||
|
||||
!m_impl->components[it->getSecond() - 1])
|
||||
return std::string{};
|
||||
!m_impl->components[it->getSecond() - 1]) {
|
||||
return {};
|
||||
}
|
||||
return m_impl->components[it->getSecond() - 1]->subsystem;
|
||||
}
|
||||
|
||||
@@ -249,8 +265,9 @@ void SendableRegistry::SetSubsystem(Sendable* sendable,
|
||||
std::scoped_lock lock(m_impl->mutex);
|
||||
auto it = m_impl->componentMap.find(sendable);
|
||||
if (it == m_impl->componentMap.end() ||
|
||||
!m_impl->components[it->getSecond() - 1])
|
||||
!m_impl->components[it->getSecond() - 1]) {
|
||||
return;
|
||||
}
|
||||
m_impl->components[it->getSecond() - 1]->subsystem = subsystem.str();
|
||||
}
|
||||
|
||||
@@ -265,14 +282,16 @@ std::shared_ptr<void> SendableRegistry::SetData(Sendable* sendable, int handle,
|
||||
std::scoped_lock lock(m_impl->mutex);
|
||||
auto it = m_impl->componentMap.find(sendable);
|
||||
if (it == m_impl->componentMap.end() ||
|
||||
!m_impl->components[it->getSecond() - 1])
|
||||
!m_impl->components[it->getSecond() - 1]) {
|
||||
return nullptr;
|
||||
}
|
||||
auto& comp = *m_impl->components[it->getSecond() - 1];
|
||||
std::shared_ptr<void> rv;
|
||||
if (static_cast<size_t>(handle) < comp.data.size())
|
||||
if (static_cast<size_t>(handle) < comp.data.size()) {
|
||||
rv = std::move(comp.data[handle]);
|
||||
else
|
||||
} else {
|
||||
comp.data.resize(handle + 1);
|
||||
}
|
||||
comp.data[handle] = std::move(data);
|
||||
return rv;
|
||||
}
|
||||
@@ -283,10 +302,13 @@ std::shared_ptr<void> SendableRegistry::GetData(Sendable* sendable,
|
||||
std::scoped_lock lock(m_impl->mutex);
|
||||
auto it = m_impl->componentMap.find(sendable);
|
||||
if (it == m_impl->componentMap.end() ||
|
||||
!m_impl->components[it->getSecond() - 1])
|
||||
!m_impl->components[it->getSecond() - 1]) {
|
||||
return nullptr;
|
||||
}
|
||||
auto& comp = *m_impl->components[it->getSecond() - 1];
|
||||
if (static_cast<size_t>(handle) >= comp.data.size()) return nullptr;
|
||||
if (static_cast<size_t>(handle) >= comp.data.size()) {
|
||||
return nullptr;
|
||||
}
|
||||
return comp.data[handle];
|
||||
}
|
||||
|
||||
@@ -294,8 +316,9 @@ void SendableRegistry::EnableLiveWindow(Sendable* sendable) {
|
||||
std::scoped_lock lock(m_impl->mutex);
|
||||
auto it = m_impl->componentMap.find(sendable);
|
||||
if (it == m_impl->componentMap.end() ||
|
||||
!m_impl->components[it->getSecond() - 1])
|
||||
!m_impl->components[it->getSecond() - 1]) {
|
||||
return;
|
||||
}
|
||||
m_impl->components[it->getSecond() - 1]->liveWindow = true;
|
||||
}
|
||||
|
||||
@@ -303,8 +326,9 @@ void SendableRegistry::DisableLiveWindow(Sendable* sendable) {
|
||||
std::scoped_lock lock(m_impl->mutex);
|
||||
auto it = m_impl->componentMap.find(sendable);
|
||||
if (it == m_impl->componentMap.end() ||
|
||||
!m_impl->components[it->getSecond() - 1])
|
||||
!m_impl->components[it->getSecond() - 1]) {
|
||||
return;
|
||||
}
|
||||
m_impl->components[it->getSecond() - 1]->liveWindow = false;
|
||||
}
|
||||
|
||||
@@ -317,10 +341,13 @@ SendableRegistry::UID SendableRegistry::GetUniqueId(Sendable* sendable) {
|
||||
}
|
||||
|
||||
Sendable* SendableRegistry::GetSendable(UID uid) {
|
||||
if (uid == 0) return nullptr;
|
||||
std::scoped_lock lock(m_impl->mutex);
|
||||
if ((uid - 1) >= m_impl->components.size() || !m_impl->components[uid - 1])
|
||||
if (uid == 0) {
|
||||
return nullptr;
|
||||
}
|
||||
std::scoped_lock lock(m_impl->mutex);
|
||||
if ((uid - 1) >= m_impl->components.size() || !m_impl->components[uid - 1]) {
|
||||
return nullptr;
|
||||
}
|
||||
return m_impl->components[uid - 1]->sendable;
|
||||
}
|
||||
|
||||
@@ -328,8 +355,9 @@ void SendableRegistry::Publish(UID sendableUid,
|
||||
std::shared_ptr<NetworkTable> table) {
|
||||
std::scoped_lock lock(m_impl->mutex);
|
||||
if (sendableUid == 0 || (sendableUid - 1) >= m_impl->components.size() ||
|
||||
!m_impl->components[sendableUid - 1])
|
||||
!m_impl->components[sendableUid - 1]) {
|
||||
return;
|
||||
}
|
||||
auto& comp = *m_impl->components[sendableUid - 1];
|
||||
comp.builder = SendableBuilderImpl{}; // clear any current builder
|
||||
comp.builder.SetTable(table);
|
||||
@@ -339,11 +367,14 @@ void SendableRegistry::Publish(UID sendableUid,
|
||||
}
|
||||
|
||||
void SendableRegistry::Update(UID sendableUid) {
|
||||
if (sendableUid == 0) return;
|
||||
if (sendableUid == 0) {
|
||||
return;
|
||||
}
|
||||
std::scoped_lock lock(m_impl->mutex);
|
||||
if ((sendableUid - 1) >= m_impl->components.size() ||
|
||||
!m_impl->components[sendableUid - 1])
|
||||
!m_impl->components[sendableUid - 1]) {
|
||||
return;
|
||||
}
|
||||
m_impl->components[sendableUid - 1]->builder.UpdateTable();
|
||||
}
|
||||
|
||||
@@ -353,11 +384,14 @@ void SendableRegistry::ForeachLiveWindow(
|
||||
assert(dataHandle >= 0);
|
||||
std::scoped_lock lock(m_impl->mutex);
|
||||
wpi::SmallVector<Impl::Component*, 128> components;
|
||||
for (auto&& comp : m_impl->components) components.emplace_back(comp.get());
|
||||
for (auto&& comp : m_impl->components) {
|
||||
components.emplace_back(comp.get());
|
||||
}
|
||||
for (auto comp : components) {
|
||||
if (comp && comp->sendable && comp->liveWindow) {
|
||||
if (static_cast<size_t>(dataHandle) >= comp->data.size())
|
||||
if (static_cast<size_t>(dataHandle) >= comp->data.size()) {
|
||||
comp->data.resize(dataHandle + 1);
|
||||
}
|
||||
CallbackData cbdata{comp->sendable, comp->name,
|
||||
comp->subsystem, comp->parent,
|
||||
comp->data[dataHandle], comp->builder};
|
||||
|
||||
@@ -40,7 +40,9 @@ Singleton& Singleton::GetInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
void SmartDashboard::init() { Singleton::GetInstance(); }
|
||||
void SmartDashboard::init() {
|
||||
Singleton::GetInstance();
|
||||
}
|
||||
|
||||
bool SmartDashboard::ContainsKey(wpi::StringRef key) {
|
||||
return Singleton::GetInstance().table->ContainsKey(key);
|
||||
@@ -106,7 +108,9 @@ void SmartDashboard::PutData(Sendable* value) {
|
||||
return;
|
||||
}
|
||||
auto name = SendableRegistry::GetInstance().GetName(value);
|
||||
if (!name.empty()) PutData(name, value);
|
||||
if (!name.empty()) {
|
||||
PutData(name, value);
|
||||
}
|
||||
}
|
||||
|
||||
Sendable* SmartDashboard::GetData(wpi::StringRef key) {
|
||||
@@ -256,5 +260,7 @@ void SmartDashboard::UpdateValues() {
|
||||
auto& inst = Singleton::GetInstance();
|
||||
listenerExecutor.RunListenerTasks();
|
||||
std::scoped_lock lock(inst.tablesToDataMutex);
|
||||
for (auto& i : inst.tablesToData) registry.Update(i.getValue());
|
||||
for (auto& i : inst.tablesToData) {
|
||||
registry.Update(i.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user