mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-22 01:11:42 +00:00
SCRIPT namespace replacements
This commit is contained in:
committed by
Peter Johnson
parent
ae6c043632
commit
9aca8e0fd6
@@ -9,18 +9,18 @@
|
||||
#include "wpi/nt/NTSendableBuilder.hpp"
|
||||
#include "wpi/util/sendable/SendableRegistry.hpp"
|
||||
|
||||
using namespace frc;
|
||||
using namespace wpi;
|
||||
|
||||
ADXL345_I2C::ADXL345_I2C(I2C::Port port, Range range, int deviceAddress)
|
||||
: m_i2c(port, deviceAddress),
|
||||
m_simDevice("Accel:ADXL345_I2C", port, deviceAddress) {
|
||||
if (m_simDevice) {
|
||||
m_simRange = m_simDevice.CreateEnumDouble("range", hal::SimDevice::kOutput,
|
||||
m_simRange = m_simDevice.CreateEnumDouble("range", wpi::hal::SimDevice::kOutput,
|
||||
{"2G", "4G", "8G", "16G"},
|
||||
{2.0, 4.0, 8.0, 16.0}, 0);
|
||||
m_simX = m_simDevice.CreateDouble("x", hal::SimDevice::kInput, 0.0);
|
||||
m_simY = m_simDevice.CreateDouble("y", hal::SimDevice::kInput, 0.0);
|
||||
m_simZ = m_simDevice.CreateDouble("z", hal::SimDevice::kInput, 0.0);
|
||||
m_simX = m_simDevice.CreateDouble("x", wpi::hal::SimDevice::kInput, 0.0);
|
||||
m_simY = m_simDevice.CreateDouble("y", wpi::hal::SimDevice::kInput, 0.0);
|
||||
m_simZ = m_simDevice.CreateDouble("z", wpi::hal::SimDevice::kInput, 0.0);
|
||||
}
|
||||
// Turn on the measurements
|
||||
m_i2c.Write(kPowerCtlRegister, kPowerCtl_Measure);
|
||||
@@ -31,7 +31,7 @@ ADXL345_I2C::ADXL345_I2C(I2C::Port port, Range range, int deviceAddress)
|
||||
fmt::format("I2C[{}][{}]", static_cast<int>(port), deviceAddress),
|
||||
"ADXL345");
|
||||
|
||||
wpi::SendableRegistry::Add(this, "ADXL345_I2C", port);
|
||||
wpi::util::SendableRegistry::Add(this, "ADXL345_I2C", port);
|
||||
}
|
||||
|
||||
I2C::Port ADXL345_I2C::GetI2CPort() const {
|
||||
@@ -93,12 +93,12 @@ ADXL345_I2C::AllAxes ADXL345_I2C::GetAccelerations() {
|
||||
return data;
|
||||
}
|
||||
|
||||
void ADXL345_I2C::InitSendable(nt::NTSendableBuilder& builder) {
|
||||
void ADXL345_I2C::InitSendable(wpi::nt::NTSendableBuilder& builder) {
|
||||
builder.SetSmartDashboardType("3AxisAccelerometer");
|
||||
builder.SetUpdateTable(
|
||||
[this, x = nt::DoubleTopic{builder.GetTopic("X")}.Publish(),
|
||||
y = nt::DoubleTopic{builder.GetTopic("Y")}.Publish(),
|
||||
z = nt::DoubleTopic{builder.GetTopic("Z")}.Publish()]() mutable {
|
||||
[this, x = wpi::nt::DoubleTopic{builder.GetTopic("X")}.Publish(),
|
||||
y = wpi::nt::DoubleTopic{builder.GetTopic("Y")}.Publish(),
|
||||
z = wpi::nt::DoubleTopic{builder.GetTopic("Z")}.Publish()]() mutable {
|
||||
auto data = GetAccelerations();
|
||||
x.Set(data.XAxis);
|
||||
y.Set(data.YAxis);
|
||||
|
||||
@@ -10,15 +10,15 @@
|
||||
#include "wpi/util/sendable/SendableBuilder.hpp"
|
||||
#include "wpi/util/sendable/SendableRegistry.hpp"
|
||||
|
||||
using namespace frc;
|
||||
using namespace wpi;
|
||||
|
||||
AnalogAccelerometer::AnalogAccelerometer(int channel)
|
||||
: AnalogAccelerometer(std::make_shared<AnalogInput>(channel)) {
|
||||
wpi::SendableRegistry::AddChild(this, m_analogInput.get());
|
||||
wpi::util::SendableRegistry::AddChild(this, m_analogInput.get());
|
||||
}
|
||||
|
||||
AnalogAccelerometer::AnalogAccelerometer(AnalogInput* channel)
|
||||
: m_analogInput(channel, wpi::NullDeleter<AnalogInput>()) {
|
||||
: m_analogInput(channel, wpi::util::NullDeleter<AnalogInput>()) {
|
||||
if (!channel) {
|
||||
throw FRC_MakeError(err::NullParameter, "channel");
|
||||
}
|
||||
@@ -45,7 +45,7 @@ void AnalogAccelerometer::SetZero(double zero) {
|
||||
m_zeroGVoltage = zero;
|
||||
}
|
||||
|
||||
void AnalogAccelerometer::InitSendable(wpi::SendableBuilder& builder) {
|
||||
void AnalogAccelerometer::InitSendable(wpi::util::SendableBuilder& builder) {
|
||||
builder.SetSmartDashboardType("Accelerometer");
|
||||
builder.AddDoubleProperty(
|
||||
"Value", [=, this] { return GetAcceleration(); }, nullptr);
|
||||
@@ -54,6 +54,6 @@ void AnalogAccelerometer::InitSendable(wpi::SendableBuilder& builder) {
|
||||
void AnalogAccelerometer::InitAccelerometer() {
|
||||
HAL_ReportUsage("IO", m_analogInput->GetChannel(), "Accelerometer");
|
||||
|
||||
wpi::SendableRegistry::Add(this, "Accelerometer",
|
||||
wpi::util::SendableRegistry::Add(this, "Accelerometer",
|
||||
m_analogInput->GetChannel());
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
#include "wpi/hal/UsageReporting.h"
|
||||
#include "wpi/system/Errors.hpp"
|
||||
|
||||
using namespace frc;
|
||||
using namespace wpi;
|
||||
|
||||
CAN::CAN(int busId, int deviceId)
|
||||
: CAN{busId, deviceId, kTeamManufacturer, kTeamDeviceType} {}
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
#include "wpi/hal/UsageReporting.h"
|
||||
#include "wpi/system/Errors.hpp"
|
||||
|
||||
using namespace frc;
|
||||
using namespace wpi;
|
||||
|
||||
I2C::I2C(Port port, int deviceAddress)
|
||||
: m_port(static_cast<HAL_I2CPort>(port)), m_deviceAddress(deviceAddress) {
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
#include "wpi/hal/UsageReporting.h"
|
||||
#include "wpi/system/Errors.hpp"
|
||||
|
||||
using namespace frc;
|
||||
using namespace wpi;
|
||||
|
||||
SerialPort::SerialPort(int baudRate, Port port, int dataBits,
|
||||
SerialPort::Parity parity,
|
||||
@@ -116,7 +116,7 @@ int SerialPort::Write(std::string_view buffer) {
|
||||
return retVal;
|
||||
}
|
||||
|
||||
void SerialPort::SetTimeout(units::second_t timeout) {
|
||||
void SerialPort::SetTimeout(wpi::units::second_t timeout) {
|
||||
int32_t status = 0;
|
||||
HAL_SetSerialTimeout(m_portHandle, timeout.value(), &status);
|
||||
FRC_CheckErrorStatus(status, "SetTimeout");
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
#include "wpi/util/sendable/SendableBuilder.hpp"
|
||||
#include "wpi/util/sendable/SendableRegistry.hpp"
|
||||
|
||||
using namespace frc;
|
||||
using namespace wpi;
|
||||
|
||||
AnalogInput::AnalogInput(int channel) {
|
||||
if (!SensorUtil::CheckAnalogInputChannel(channel)) {
|
||||
@@ -26,13 +26,13 @@ AnalogInput::AnalogInput(int channel) {
|
||||
|
||||
m_channel = channel;
|
||||
int32_t status = 0;
|
||||
std::string stackTrace = wpi::GetStackTrace(1);
|
||||
std::string stackTrace = wpi::util::GetStackTrace(1);
|
||||
m_port = HAL_InitializeAnalogInputPort(channel, stackTrace.c_str(), &status);
|
||||
FRC_CheckErrorStatus(status, "Channel {}", channel);
|
||||
|
||||
HAL_ReportUsage("IO", channel, "AnalogInput");
|
||||
|
||||
wpi::SendableRegistry::Add(this, "AnalogInput", channel);
|
||||
wpi::util::SendableRegistry::Add(this, "AnalogInput", channel);
|
||||
}
|
||||
|
||||
int AnalogInput::GetValue() const {
|
||||
@@ -124,7 +124,7 @@ void AnalogInput::SetSimDevice(HAL_SimDeviceHandle device) {
|
||||
HAL_SetAnalogInputSimDevice(m_port, device);
|
||||
}
|
||||
|
||||
void AnalogInput::InitSendable(wpi::SendableBuilder& builder) {
|
||||
void AnalogInput::InitSendable(wpi::util::SendableBuilder& builder) {
|
||||
builder.SetSmartDashboardType("Analog Input");
|
||||
builder.AddDoubleProperty(
|
||||
"Value", [=, this] { return GetAverageVoltage(); }, nullptr);
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
#include "wpi/util/sendable/SendableBuilder.hpp"
|
||||
#include "wpi/util/sendable/SendableRegistry.hpp"
|
||||
|
||||
using namespace frc;
|
||||
using namespace wpi;
|
||||
|
||||
DigitalInput::DigitalInput(int channel) {
|
||||
if (!SensorUtil::CheckDigitalChannel(channel)) {
|
||||
@@ -25,12 +25,12 @@ DigitalInput::DigitalInput(int channel) {
|
||||
m_channel = channel;
|
||||
|
||||
int32_t status = 0;
|
||||
std::string stackTrace = wpi::GetStackTrace(1);
|
||||
std::string stackTrace = wpi::util::GetStackTrace(1);
|
||||
m_handle = HAL_InitializeDIOPort(channel, true, stackTrace.c_str(), &status);
|
||||
FRC_CheckErrorStatus(status, "Channel {}", channel);
|
||||
|
||||
HAL_ReportUsage("IO", channel, "DigitalInput");
|
||||
wpi::SendableRegistry::Add(this, "DigitalInput", channel);
|
||||
wpi::util::SendableRegistry::Add(this, "DigitalInput", channel);
|
||||
}
|
||||
|
||||
bool DigitalInput::Get() const {
|
||||
@@ -48,7 +48,7 @@ int DigitalInput::GetChannel() const {
|
||||
return m_channel;
|
||||
}
|
||||
|
||||
void DigitalInput::InitSendable(wpi::SendableBuilder& builder) {
|
||||
void DigitalInput::InitSendable(wpi::util::SendableBuilder& builder) {
|
||||
builder.SetSmartDashboardType("Digital Input");
|
||||
builder.AddBooleanProperty("Value", [=, this] { return Get(); }, nullptr);
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
#include "wpi/util/sendable/SendableBuilder.hpp"
|
||||
#include "wpi/util/sendable/SendableRegistry.hpp"
|
||||
|
||||
using namespace frc;
|
||||
using namespace wpi;
|
||||
|
||||
DigitalOutput::DigitalOutput(int channel) {
|
||||
m_pwmGenerator = HAL_kInvalidHandle;
|
||||
@@ -26,12 +26,12 @@ DigitalOutput::DigitalOutput(int channel) {
|
||||
m_channel = channel;
|
||||
|
||||
int32_t status = 0;
|
||||
std::string stackTrace = wpi::GetStackTrace(1);
|
||||
std::string stackTrace = wpi::util::GetStackTrace(1);
|
||||
m_handle = HAL_InitializeDIOPort(channel, false, stackTrace.c_str(), &status);
|
||||
FRC_CheckErrorStatus(status, "Channel {}", channel);
|
||||
|
||||
HAL_ReportUsage("IO", channel, "DigitalOutput");
|
||||
wpi::SendableRegistry::Add(this, "DigitalOutput", channel);
|
||||
wpi::util::SendableRegistry::Add(this, "DigitalOutput", channel);
|
||||
}
|
||||
|
||||
DigitalOutput::~DigitalOutput() {
|
||||
@@ -62,7 +62,7 @@ int DigitalOutput::GetChannel() const {
|
||||
return m_channel;
|
||||
}
|
||||
|
||||
void DigitalOutput::Pulse(units::second_t pulseLength) {
|
||||
void DigitalOutput::Pulse(wpi::units::second_t pulseLength) {
|
||||
int32_t status = 0;
|
||||
HAL_Pulse(m_handle, pulseLength.value(), &status);
|
||||
FRC_CheckErrorStatus(status, "Channel {}", m_channel);
|
||||
@@ -142,7 +142,7 @@ void DigitalOutput::SetSimDevice(HAL_SimDeviceHandle device) {
|
||||
HAL_SetDIOSimDevice(m_handle, device);
|
||||
}
|
||||
|
||||
void DigitalOutput::InitSendable(wpi::SendableBuilder& builder) {
|
||||
void DigitalOutput::InitSendable(wpi::util::SendableBuilder& builder) {
|
||||
builder.SetSmartDashboardType("Digital Output");
|
||||
builder.AddBooleanProperty(
|
||||
"Value", [=, this] { return Get(); },
|
||||
|
||||
@@ -16,14 +16,14 @@
|
||||
#include "wpi/util/sendable/SendableBuilder.hpp"
|
||||
#include "wpi/util/sendable/SendableRegistry.hpp"
|
||||
|
||||
using namespace frc;
|
||||
using namespace wpi;
|
||||
|
||||
PWM::PWM(int channel, bool registerSendable) {
|
||||
if (!SensorUtil::CheckPWMChannel(channel)) {
|
||||
throw FRC_MakeError(err::ChannelIndexOutOfRange, "Channel {}", channel);
|
||||
}
|
||||
|
||||
auto stack = wpi::GetStackTrace(1);
|
||||
auto stack = wpi::util::GetStackTrace(1);
|
||||
int32_t status = 0;
|
||||
m_handle = HAL_InitializePWMPort(channel, stack.c_str(), &status);
|
||||
FRC_CheckErrorStatus(status, "Channel {}", channel);
|
||||
@@ -34,7 +34,7 @@ PWM::PWM(int channel, bool registerSendable) {
|
||||
|
||||
HAL_ReportUsage("IO", channel, "PWM");
|
||||
if (registerSendable) {
|
||||
wpi::SendableRegistry::Add(this, "PWM", channel);
|
||||
wpi::util::SendableRegistry::Add(this, "PWM", channel);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,18 +44,18 @@ PWM::~PWM() {
|
||||
}
|
||||
}
|
||||
|
||||
void PWM::SetPulseTime(units::microsecond_t time) {
|
||||
void PWM::SetPulseTime(wpi::units::microsecond_t time) {
|
||||
int32_t status = 0;
|
||||
HAL_SetPWMPulseTimeMicroseconds(m_handle, time.value(), &status);
|
||||
FRC_CheckErrorStatus(status, "Channel {}", m_channel);
|
||||
}
|
||||
|
||||
units::microsecond_t PWM::GetPulseTime() const {
|
||||
wpi::units::microsecond_t PWM::GetPulseTime() const {
|
||||
int32_t status = 0;
|
||||
double value = HAL_GetPWMPulseTimeMicroseconds(m_handle, &status);
|
||||
FRC_CheckErrorStatus(status, "Channel {}", m_channel);
|
||||
|
||||
return units::microsecond_t{value};
|
||||
return wpi::units::microsecond_t{value};
|
||||
}
|
||||
|
||||
void PWM::SetDisabled() {
|
||||
@@ -96,10 +96,10 @@ void PWM::SetSimDevice(HAL_SimDeviceHandle device) {
|
||||
HAL_SetPWMSimDevice(m_handle, device);
|
||||
}
|
||||
|
||||
void PWM::InitSendable(wpi::SendableBuilder& builder) {
|
||||
void PWM::InitSendable(wpi::util::SendableBuilder& builder) {
|
||||
builder.SetSmartDashboardType("PWM");
|
||||
builder.SetActuator(true);
|
||||
builder.AddDoubleProperty(
|
||||
"Value", [=, this] { return GetPulseTime().value(); },
|
||||
[=, this](double value) { SetPulseTime(units::millisecond_t{value}); });
|
||||
[=, this](double value) { SetPulseTime(wpi::units::millisecond_t{value}); });
|
||||
}
|
||||
|
||||
@@ -7,14 +7,14 @@
|
||||
#include "wpi/hal/IMU.h"
|
||||
#include "wpi/system/Errors.hpp"
|
||||
|
||||
using namespace frc;
|
||||
using namespace wpi;
|
||||
|
||||
OnboardIMU::OnboardIMU(MountOrientation mountOrientation)
|
||||
: m_mountOrientation{mountOrientation} {
|
||||
// TODO: usage reporting
|
||||
}
|
||||
|
||||
units::radian_t OnboardIMU::GetYawNoOffset() {
|
||||
wpi::units::radian_t OnboardIMU::GetYawNoOffset() {
|
||||
int64_t timestamp;
|
||||
double val;
|
||||
switch (m_mountOrientation) {
|
||||
@@ -30,10 +30,10 @@ units::radian_t OnboardIMU::GetYawNoOffset() {
|
||||
default:
|
||||
val = 0;
|
||||
}
|
||||
return units::radian_t{val};
|
||||
return wpi::units::radian_t{val};
|
||||
}
|
||||
|
||||
units::radian_t OnboardIMU::GetYaw() {
|
||||
wpi::units::radian_t OnboardIMU::GetYaw() {
|
||||
return GetYawNoOffset() - m_yawOffset;
|
||||
}
|
||||
|
||||
@@ -41,23 +41,23 @@ void OnboardIMU::ResetYaw() {
|
||||
m_yawOffset = GetYawNoOffset();
|
||||
}
|
||||
|
||||
Rotation2d OnboardIMU::GetRotation2d() {
|
||||
return Rotation2d{GetYaw()};
|
||||
wpi::math::Rotation2d OnboardIMU::GetRotation2d() {
|
||||
return wpi::math::Rotation2d{GetYaw()};
|
||||
}
|
||||
|
||||
Rotation3d OnboardIMU::GetRotation3d() {
|
||||
return Rotation3d{GetQuaternion()};
|
||||
wpi::math::Rotation3d OnboardIMU::GetRotation3d() {
|
||||
return wpi::math::Rotation3d{GetQuaternion()};
|
||||
}
|
||||
|
||||
Quaternion OnboardIMU::GetQuaternion() {
|
||||
wpi::math::Quaternion OnboardIMU::GetQuaternion() {
|
||||
HAL_Quaternion val;
|
||||
int32_t status = 0;
|
||||
HAL_GetIMUQuaternion(&val, &status);
|
||||
FRC_CheckErrorStatus(status, "Onboard IMU");
|
||||
return Quaternion{val.w, val.x, val.y, val.z};
|
||||
return wpi::math::Quaternion{val.w, val.x, val.y, val.z};
|
||||
}
|
||||
|
||||
units::radian_t OnboardIMU::GetAngleX() {
|
||||
wpi::units::radian_t OnboardIMU::GetAngleX() {
|
||||
HAL_EulerAngles3d val;
|
||||
int32_t status = 0;
|
||||
switch (m_mountOrientation) {
|
||||
@@ -72,10 +72,10 @@ units::radian_t OnboardIMU::GetAngleX() {
|
||||
break;
|
||||
}
|
||||
FRC_CheckErrorStatus(status, "Onboard IMU");
|
||||
return units::radian_t{val.x};
|
||||
return wpi::units::radian_t{val.x};
|
||||
}
|
||||
|
||||
units::radian_t OnboardIMU::GetAngleY() {
|
||||
wpi::units::radian_t OnboardIMU::GetAngleY() {
|
||||
HAL_EulerAngles3d val;
|
||||
int32_t status = 0;
|
||||
switch (m_mountOrientation) {
|
||||
@@ -90,10 +90,10 @@ units::radian_t OnboardIMU::GetAngleY() {
|
||||
break;
|
||||
}
|
||||
FRC_CheckErrorStatus(status, "Onboard IMU");
|
||||
return units::radian_t{val.y};
|
||||
return wpi::units::radian_t{val.y};
|
||||
}
|
||||
|
||||
units::radian_t OnboardIMU::GetAngleZ() {
|
||||
wpi::units::radian_t OnboardIMU::GetAngleZ() {
|
||||
HAL_EulerAngles3d val;
|
||||
int32_t status = 0;
|
||||
switch (m_mountOrientation) {
|
||||
@@ -108,53 +108,53 @@ units::radian_t OnboardIMU::GetAngleZ() {
|
||||
break;
|
||||
}
|
||||
FRC_CheckErrorStatus(status, "Onboard IMU");
|
||||
return units::radian_t{val.z};
|
||||
return wpi::units::radian_t{val.z};
|
||||
}
|
||||
|
||||
units::radians_per_second_t OnboardIMU::GetGyroRateX() {
|
||||
wpi::units::radians_per_second_t OnboardIMU::GetGyroRateX() {
|
||||
HAL_GyroRate3d val;
|
||||
int32_t status = 0;
|
||||
HAL_GetIMUGyroRates(&val, &status);
|
||||
FRC_CheckErrorStatus(status, "Onboard IMU");
|
||||
return units::radians_per_second_t{val.x};
|
||||
return wpi::units::radians_per_second_t{val.x};
|
||||
}
|
||||
|
||||
units::radians_per_second_t OnboardIMU::GetGyroRateY() {
|
||||
wpi::units::radians_per_second_t OnboardIMU::GetGyroRateY() {
|
||||
HAL_GyroRate3d val;
|
||||
int32_t status = 0;
|
||||
HAL_GetIMUGyroRates(&val, &status);
|
||||
FRC_CheckErrorStatus(status, "Onboard IMU");
|
||||
return units::radians_per_second_t{val.y};
|
||||
return wpi::units::radians_per_second_t{val.y};
|
||||
}
|
||||
|
||||
units::radians_per_second_t OnboardIMU::GetGyroRateZ() {
|
||||
wpi::units::radians_per_second_t OnboardIMU::GetGyroRateZ() {
|
||||
HAL_GyroRate3d val;
|
||||
int32_t status = 0;
|
||||
HAL_GetIMUGyroRates(&val, &status);
|
||||
FRC_CheckErrorStatus(status, "Onboard IMU");
|
||||
return units::radians_per_second_t{val.z};
|
||||
return wpi::units::radians_per_second_t{val.z};
|
||||
}
|
||||
|
||||
units::meters_per_second_squared_t OnboardIMU::GetAccelX() {
|
||||
wpi::units::meters_per_second_squared_t OnboardIMU::GetAccelX() {
|
||||
HAL_Acceleration3d val;
|
||||
int32_t status = 0;
|
||||
HAL_GetIMUAcceleration(&val, &status);
|
||||
FRC_CheckErrorStatus(status, "Onboard IMU");
|
||||
return units::meters_per_second_squared_t{val.x};
|
||||
return wpi::units::meters_per_second_squared_t{val.x};
|
||||
}
|
||||
|
||||
units::meters_per_second_squared_t OnboardIMU::GetAccelY() {
|
||||
wpi::units::meters_per_second_squared_t OnboardIMU::GetAccelY() {
|
||||
HAL_Acceleration3d val;
|
||||
int32_t status = 0;
|
||||
HAL_GetIMUAcceleration(&val, &status);
|
||||
FRC_CheckErrorStatus(status, "Onboard IMU");
|
||||
return units::meters_per_second_squared_t{val.x};
|
||||
return wpi::units::meters_per_second_squared_t{val.x};
|
||||
}
|
||||
|
||||
units::meters_per_second_squared_t OnboardIMU::GetAccelZ() {
|
||||
wpi::units::meters_per_second_squared_t OnboardIMU::GetAccelZ() {
|
||||
HAL_Acceleration3d val;
|
||||
int32_t status = 0;
|
||||
HAL_GetIMUAcceleration(&val, &status);
|
||||
FRC_CheckErrorStatus(status, "Onboard IMU");
|
||||
return units::meters_per_second_squared_t{val.x};
|
||||
return wpi::units::meters_per_second_squared_t{val.x};
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
#include "wpi/util/SensorUtil.hpp"
|
||||
#include "wpi/util/StackTrace.hpp"
|
||||
|
||||
using namespace frc;
|
||||
using namespace wpi;
|
||||
|
||||
AddressableLED::AddressableLED(int channel) : m_channel{channel} {
|
||||
if (!SensorUtil::CheckDigitalChannel(channel)) {
|
||||
@@ -23,7 +23,7 @@ AddressableLED::AddressableLED(int channel) : m_channel{channel} {
|
||||
}
|
||||
|
||||
int32_t status = 0;
|
||||
auto stack = wpi::GetStackTrace(1);
|
||||
auto stack = wpi::util::GetStackTrace(1);
|
||||
m_handle = HAL_InitializeAddressableLED(channel, stack.c_str(), &status);
|
||||
FRC_CheckErrorStatus(status, "Channel {}", channel);
|
||||
|
||||
|
||||
@@ -15,20 +15,20 @@
|
||||
#include "wpi/util/MathExtras.hpp"
|
||||
#include "wpi/util/timestamp.h"
|
||||
|
||||
using namespace frc;
|
||||
using namespace wpi;
|
||||
|
||||
LEDPattern::LEDPattern(std::function<void(frc::LEDPattern::LEDReader,
|
||||
std::function<void(int, frc::Color)>)>
|
||||
LEDPattern::LEDPattern(std::function<void(wpi::LEDPattern::LEDReader,
|
||||
std::function<void(int, wpi::Color)>)>
|
||||
impl)
|
||||
: m_impl(std::move(impl)) {}
|
||||
|
||||
void LEDPattern::ApplyTo(LEDPattern::LEDReader reader,
|
||||
std::function<void(int, frc::Color)> writer) const {
|
||||
std::function<void(int, wpi::Color)> writer) const {
|
||||
m_impl(reader, writer);
|
||||
}
|
||||
|
||||
void LEDPattern::ApplyTo(std::span<AddressableLED::LEDData> data,
|
||||
std::function<void(int, frc::Color)> writer) const {
|
||||
std::function<void(int, wpi::Color)> writer) const {
|
||||
ApplyTo(LEDPattern::LEDReader{[=](size_t i) { return data[i]; }, data.size()},
|
||||
writer);
|
||||
}
|
||||
@@ -54,39 +54,39 @@ LEDPattern LEDPattern::Reversed() {
|
||||
|
||||
LEDPattern LEDPattern::OffsetBy(int offset) {
|
||||
return MapIndex([offset](size_t bufLen, size_t i) {
|
||||
return frc::FloorMod(static_cast<int>(i) + offset,
|
||||
return wpi::math::FloorMod(static_cast<int>(i) + offset,
|
||||
static_cast<int>(bufLen));
|
||||
});
|
||||
}
|
||||
|
||||
LEDPattern LEDPattern::ScrollAtRelativeSpeed(units::hertz_t velocity) {
|
||||
LEDPattern LEDPattern::ScrollAtRelativeSpeed(wpi::units::hertz_t velocity) {
|
||||
// velocity is in terms of LED lengths per second (1_hz = full cycle per
|
||||
// second, 0.5_hz = half cycle per second, 2_hz = two cycles per second)
|
||||
// Invert and multiply by 1,000,000 to get microseconds
|
||||
double periodMicros = 1e6 / velocity.value();
|
||||
|
||||
return MapIndex([=](size_t bufLen, size_t i) {
|
||||
auto now = wpi::Now();
|
||||
auto now = wpi::util::Now();
|
||||
|
||||
// index should move by (bufLen) / (period)
|
||||
double t =
|
||||
(now % static_cast<int64_t>(std::floor(periodMicros))) / periodMicros;
|
||||
int offset = static_cast<int>(std::floor(t * bufLen));
|
||||
|
||||
return frc::FloorMod(static_cast<int>(i) + offset,
|
||||
return wpi::math::FloorMod(static_cast<int>(i) + offset,
|
||||
static_cast<int>(bufLen));
|
||||
});
|
||||
}
|
||||
|
||||
LEDPattern LEDPattern::ScrollAtAbsoluteSpeed(
|
||||
units::meters_per_second_t velocity, units::meter_t ledSpacing) {
|
||||
wpi::units::meters_per_second_t velocity, wpi::units::meter_t ledSpacing) {
|
||||
// Velocity is in terms of meters per second
|
||||
// Multiply by 1,000,000 to use microseconds instead of seconds
|
||||
auto microsPerLed =
|
||||
static_cast<int64_t>(std::floor((ledSpacing / velocity).value() * 1e6));
|
||||
|
||||
return MapIndex([=](size_t bufLen, size_t i) {
|
||||
auto now = wpi::Now();
|
||||
auto now = wpi::util::Now();
|
||||
|
||||
// every step in time that's a multiple of microsPerLED will increment
|
||||
// the offset by 1
|
||||
@@ -94,17 +94,17 @@ LEDPattern LEDPattern::ScrollAtAbsoluteSpeed(
|
||||
// offset values for negative velocities
|
||||
auto offset = static_cast<int64_t>(now) / microsPerLed;
|
||||
|
||||
return frc::FloorMod(static_cast<int>(i) + offset,
|
||||
return wpi::math::FloorMod(static_cast<int>(i) + offset,
|
||||
static_cast<int>(bufLen));
|
||||
});
|
||||
}
|
||||
|
||||
LEDPattern LEDPattern::Blink(units::second_t onTime, units::second_t offTime) {
|
||||
auto totalMicros = units::microsecond_t{onTime + offTime}.to<uint64_t>();
|
||||
auto onMicros = units::microsecond_t{onTime}.to<uint64_t>();
|
||||
LEDPattern LEDPattern::Blink(wpi::units::second_t onTime, wpi::units::second_t offTime) {
|
||||
auto totalMicros = wpi::units::microsecond_t{onTime + offTime}.to<uint64_t>();
|
||||
auto onMicros = wpi::units::microsecond_t{onTime}.to<uint64_t>();
|
||||
|
||||
return LEDPattern{[=, self = *this](auto data, auto writer) {
|
||||
if (wpi::Now() % totalMicros < onMicros) {
|
||||
if (wpi::util::Now() % totalMicros < onMicros) {
|
||||
self.ApplyTo(data, writer);
|
||||
} else {
|
||||
LEDPattern::Off().ApplyTo(data, writer);
|
||||
@@ -112,7 +112,7 @@ LEDPattern LEDPattern::Blink(units::second_t onTime, units::second_t offTime) {
|
||||
}};
|
||||
}
|
||||
|
||||
LEDPattern LEDPattern::Blink(units::second_t onTime) {
|
||||
LEDPattern LEDPattern::Blink(wpi::units::second_t onTime) {
|
||||
return LEDPattern::Blink(onTime, onTime);
|
||||
}
|
||||
|
||||
@@ -126,12 +126,12 @@ LEDPattern LEDPattern::SynchronizedBlink(std::function<bool()> signal) {
|
||||
}};
|
||||
}
|
||||
|
||||
LEDPattern LEDPattern::Breathe(units::second_t period) {
|
||||
auto periodMicros = units::microsecond_t{period};
|
||||
LEDPattern LEDPattern::Breathe(wpi::units::second_t period) {
|
||||
auto periodMicros = wpi::units::microsecond_t{period};
|
||||
|
||||
return LEDPattern{[periodMicros, self = *this](auto data, auto writer) {
|
||||
self.ApplyTo(data, [&writer, periodMicros](int i, Color color) {
|
||||
double t = (wpi::Now() % periodMicros.to<uint64_t>()) /
|
||||
double t = (wpi::util::Now() % periodMicros.to<uint64_t>()) /
|
||||
periodMicros.to<double>();
|
||||
double phase = t * 2 * std::numbers::pi;
|
||||
|
||||
@@ -299,9 +299,9 @@ LEDPattern LEDPattern::Gradient(GradientType type,
|
||||
auto color = colors[colorIndex];
|
||||
auto nextColor = colors[nextColorIndex];
|
||||
|
||||
Color gradientColor{wpi::Lerp(color.red, nextColor.red, t),
|
||||
wpi::Lerp(color.green, nextColor.green, t),
|
||||
wpi::Lerp(color.blue, nextColor.blue, t)};
|
||||
Color gradientColor{wpi::util::Lerp(color.red, nextColor.red, t),
|
||||
wpi::util::Lerp(color.green, nextColor.green, t),
|
||||
wpi::util::Lerp(color.blue, nextColor.blue, t)};
|
||||
writer(led, gradientColor);
|
||||
}
|
||||
}};
|
||||
|
||||
@@ -13,23 +13,23 @@
|
||||
#include "wpi/util/SafeThread.hpp"
|
||||
#include "wpi/util/SmallPtrSet.hpp"
|
||||
|
||||
using namespace frc;
|
||||
using namespace wpi;
|
||||
|
||||
namespace {
|
||||
class Thread : public wpi::SafeThread {
|
||||
class Thread : public wpi::util::SafeThread {
|
||||
public:
|
||||
Thread() {}
|
||||
void Main() override;
|
||||
};
|
||||
|
||||
void Thread::Main() {
|
||||
wpi::Event event{false, false};
|
||||
wpi::util::Event event{false, false};
|
||||
HAL_ProvideNewDataEventHandle(event.GetHandle());
|
||||
|
||||
int safetyCounter = 0;
|
||||
while (m_active) {
|
||||
bool timedOut = false;
|
||||
bool signaled = wpi::WaitForObject(event.GetHandle(), 0.1, &timedOut);
|
||||
bool signaled = wpi::util::WaitForObject(event.GetHandle(), 0.1, &timedOut);
|
||||
if (signaled) {
|
||||
HAL_ControlWord controlWord;
|
||||
std::memset(&controlWord, 0, sizeof(controlWord));
|
||||
@@ -56,9 +56,9 @@ namespace {
|
||||
struct MotorSafetyManager {
|
||||
~MotorSafetyManager() { gShutdown = true; }
|
||||
|
||||
wpi::SafeThreadOwner<Thread> thread;
|
||||
wpi::SmallPtrSet<MotorSafety*, 32> instanceList;
|
||||
wpi::mutex listMutex;
|
||||
wpi::util::SafeThreadOwner<Thread> thread;
|
||||
wpi::util::SmallPtrSet<MotorSafety*, 32> instanceList;
|
||||
wpi::util::mutex listMutex;
|
||||
bool threadStarted = false;
|
||||
};
|
||||
} // namespace
|
||||
@@ -69,17 +69,17 @@ static MotorSafetyManager& GetManager() {
|
||||
}
|
||||
|
||||
#ifndef __FRC_SYSTEMCORE__
|
||||
namespace frc::impl {
|
||||
namespace wpi::impl {
|
||||
void ResetMotorSafety() {
|
||||
auto& manager = GetManager();
|
||||
std::scoped_lock lock(manager.listMutex);
|
||||
manager.instanceList.clear();
|
||||
manager.thread.Stop();
|
||||
manager.thread.Join();
|
||||
manager.thread = wpi::SafeThreadOwner<Thread>{};
|
||||
manager.thread = wpi::util::SafeThreadOwner<Thread>{};
|
||||
manager.threadStarted = false;
|
||||
}
|
||||
} // namespace frc::impl
|
||||
} // namespace wpi::impl
|
||||
#endif
|
||||
|
||||
MotorSafety::MotorSafety() {
|
||||
@@ -118,12 +118,12 @@ void MotorSafety::Feed() {
|
||||
m_stopTime = Timer::GetFPGATimestamp() + m_expiration;
|
||||
}
|
||||
|
||||
void MotorSafety::SetExpiration(units::second_t expirationTime) {
|
||||
void MotorSafety::SetExpiration(wpi::units::second_t expirationTime) {
|
||||
std::scoped_lock lock(m_thisMutex);
|
||||
m_expiration = expirationTime;
|
||||
}
|
||||
|
||||
units::second_t MotorSafety::GetExpiration() const {
|
||||
wpi::units::second_t MotorSafety::GetExpiration() const {
|
||||
std::scoped_lock lock(m_thisMutex);
|
||||
return m_expiration;
|
||||
}
|
||||
@@ -145,7 +145,7 @@ bool MotorSafety::IsSafetyEnabled() const {
|
||||
|
||||
void MotorSafety::Check() {
|
||||
bool enabled;
|
||||
units::second_t stopTime;
|
||||
wpi::units::second_t stopTime;
|
||||
|
||||
{
|
||||
std::scoped_lock lock(m_thisMutex);
|
||||
@@ -165,7 +165,7 @@ void MotorSafety::Check() {
|
||||
|
||||
try {
|
||||
StopMotor();
|
||||
} catch (frc::RuntimeError& e) {
|
||||
} catch (wpi::RuntimeError& e) {
|
||||
e.Report();
|
||||
} catch (std::exception& e) {
|
||||
FRC_ReportError(err::Error, "{} StopMotor threw unexpected exception: {}",
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
#include "wpi/util/sendable/SendableBuilder.hpp"
|
||||
#include "wpi/util/sendable/SendableRegistry.hpp"
|
||||
|
||||
using namespace frc;
|
||||
using namespace wpi;
|
||||
|
||||
Compressor::Compressor(int busId, int module, PneumaticsModuleType moduleType)
|
||||
: m_module{PneumaticsBase::GetForType(busId, module, moduleType)},
|
||||
@@ -22,7 +22,7 @@ Compressor::Compressor(int busId, int module, PneumaticsModuleType moduleType)
|
||||
m_module->EnableCompressorDigital();
|
||||
|
||||
m_module->ReportUsage("Compressor", "");
|
||||
wpi::SendableRegistry::Add(this, "Compressor", module);
|
||||
wpi::util::SendableRegistry::Add(this, "Compressor", module);
|
||||
}
|
||||
|
||||
Compressor::Compressor(int busId, PneumaticsModuleType moduleType)
|
||||
@@ -43,15 +43,15 @@ bool Compressor::GetPressureSwitchValue() const {
|
||||
return m_module->GetPressureSwitch();
|
||||
}
|
||||
|
||||
units::ampere_t Compressor::GetCurrent() const {
|
||||
wpi::units::ampere_t Compressor::GetCurrent() const {
|
||||
return m_module->GetCompressorCurrent();
|
||||
}
|
||||
|
||||
units::volt_t Compressor::GetAnalogVoltage() const {
|
||||
wpi::units::volt_t Compressor::GetAnalogVoltage() const {
|
||||
return m_module->GetAnalogVoltage(0);
|
||||
}
|
||||
|
||||
units::pounds_per_square_inch_t Compressor::GetPressure() const {
|
||||
wpi::units::pounds_per_square_inch_t Compressor::GetPressure() const {
|
||||
return m_module->GetPressure(0);
|
||||
}
|
||||
|
||||
@@ -63,13 +63,13 @@ void Compressor::EnableDigital() {
|
||||
m_module->EnableCompressorDigital();
|
||||
}
|
||||
|
||||
void Compressor::EnableAnalog(units::pounds_per_square_inch_t minPressure,
|
||||
units::pounds_per_square_inch_t maxPressure) {
|
||||
void Compressor::EnableAnalog(wpi::units::pounds_per_square_inch_t minPressure,
|
||||
wpi::units::pounds_per_square_inch_t maxPressure) {
|
||||
m_module->EnableCompressorAnalog(minPressure, maxPressure);
|
||||
}
|
||||
|
||||
void Compressor::EnableHybrid(units::pounds_per_square_inch_t minPressure,
|
||||
units::pounds_per_square_inch_t maxPressure) {
|
||||
void Compressor::EnableHybrid(wpi::units::pounds_per_square_inch_t minPressure,
|
||||
wpi::units::pounds_per_square_inch_t maxPressure) {
|
||||
m_module->EnableCompressorHybrid(minPressure, maxPressure);
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ CompressorConfigType Compressor::GetConfigType() const {
|
||||
return m_module->GetCompressorConfigType();
|
||||
}
|
||||
|
||||
void Compressor::InitSendable(wpi::SendableBuilder& builder) {
|
||||
void Compressor::InitSendable(wpi::util::SendableBuilder& builder) {
|
||||
builder.SetSmartDashboardType("Compressor");
|
||||
builder.AddBooleanProperty(
|
||||
"Enabled", [this] { return IsEnabled(); }, nullptr);
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
#include "wpi/util/sendable/SendableBuilder.hpp"
|
||||
#include "wpi/util/sendable/SendableRegistry.hpp"
|
||||
|
||||
using namespace frc;
|
||||
using namespace wpi;
|
||||
|
||||
DoubleSolenoid::DoubleSolenoid(int busId, int module,
|
||||
PneumaticsModuleType moduleType,
|
||||
@@ -52,7 +52,7 @@ DoubleSolenoid::DoubleSolenoid(int busId, int module,
|
||||
fmt::format("Solenoid[{},{}]", m_forwardChannel, m_reverseChannel),
|
||||
"DoubleSolenoid");
|
||||
|
||||
wpi::SendableRegistry::Add(this, "DoubleSolenoid",
|
||||
wpi::util::SendableRegistry::Add(this, "DoubleSolenoid",
|
||||
m_module->GetModuleNumber(), m_forwardChannel);
|
||||
}
|
||||
|
||||
@@ -123,12 +123,12 @@ bool DoubleSolenoid::IsRevSolenoidDisabled() const {
|
||||
return (m_module->GetSolenoidDisabledList() & m_reverseMask) != 0;
|
||||
}
|
||||
|
||||
void DoubleSolenoid::InitSendable(wpi::SendableBuilder& builder) {
|
||||
void DoubleSolenoid::InitSendable(wpi::util::SendableBuilder& builder) {
|
||||
builder.SetSmartDashboardType("Double Solenoid");
|
||||
builder.SetActuator(true);
|
||||
builder.AddSmallStringProperty(
|
||||
"Value",
|
||||
[=, this](wpi::SmallVectorImpl<char>& buf) -> std::string_view {
|
||||
[=, this](wpi::util::SmallVectorImpl<char>& buf) -> std::string_view {
|
||||
switch (Get()) {
|
||||
case kForward:
|
||||
return "Forward";
|
||||
|
||||
@@ -23,24 +23,24 @@
|
||||
#include "wpi/util/SensorUtil.hpp"
|
||||
#include "wpi/util/StackTrace.hpp"
|
||||
|
||||
using namespace frc;
|
||||
using namespace wpi;
|
||||
|
||||
/** Converts volts to PSI per the REV Analog Pressure Sensor datasheet. */
|
||||
units::pounds_per_square_inch_t VoltsToPSI(units::volt_t sensorVoltage,
|
||||
units::volt_t supplyVoltage) {
|
||||
return units::pounds_per_square_inch_t{
|
||||
wpi::units::pounds_per_square_inch_t VoltsToPSI(wpi::units::volt_t sensorVoltage,
|
||||
wpi::units::volt_t supplyVoltage) {
|
||||
return wpi::units::pounds_per_square_inch_t{
|
||||
250 * (sensorVoltage.value() / supplyVoltage.value()) - 25};
|
||||
}
|
||||
|
||||
/** Converts PSI to volts per the REV Analog Pressure Sensor datasheet. */
|
||||
units::volt_t PSIToVolts(units::pounds_per_square_inch_t pressure,
|
||||
units::volt_t supplyVoltage) {
|
||||
return units::volt_t{supplyVoltage.value() *
|
||||
wpi::units::volt_t PSIToVolts(wpi::units::pounds_per_square_inch_t pressure,
|
||||
wpi::units::volt_t supplyVoltage) {
|
||||
return wpi::units::volt_t{supplyVoltage.value() *
|
||||
(0.004 * pressure.value() + 0.1)};
|
||||
}
|
||||
|
||||
wpi::mutex PneumaticHub::m_handleLock;
|
||||
std::unique_ptr<wpi::DenseMap<int, std::weak_ptr<PneumaticHub::DataStore>>[]>
|
||||
wpi::util::mutex PneumaticHub::m_handleLock;
|
||||
std::unique_ptr<wpi::util::DenseMap<int, std::weak_ptr<PneumaticHub::DataStore>>[]>
|
||||
PneumaticHub::m_handleMaps = nullptr;
|
||||
|
||||
// Always called under lock, so we can avoid the double lock from the magic
|
||||
@@ -52,7 +52,7 @@ std::weak_ptr<PneumaticHub::DataStore>& PneumaticHub::GetDataStore(int busId,
|
||||
"Bus {} out of range. Must be [0-{}).", busId, numBuses);
|
||||
if (!m_handleMaps) {
|
||||
m_handleMaps = std::make_unique<
|
||||
wpi::DenseMap<int, std::weak_ptr<PneumaticHub::DataStore>>[]>(numBuses);
|
||||
wpi::util::DenseMap<int, std::weak_ptr<PneumaticHub::DataStore>>[]>(numBuses);
|
||||
}
|
||||
return m_handleMaps[busId][module];
|
||||
}
|
||||
@@ -66,7 +66,7 @@ class PneumaticHub::DataStore {
|
||||
FRC_CheckErrorStatus(status, "Module {}", module);
|
||||
m_moduleObject = PneumaticHub{busId, handle, module};
|
||||
m_moduleObject.m_dataStore =
|
||||
std::shared_ptr<DataStore>{this, wpi::NullDeleter<DataStore>()};
|
||||
std::shared_ptr<DataStore>{this, wpi::util::NullDeleter<DataStore>()};
|
||||
|
||||
auto version = m_moduleObject.GetVersion();
|
||||
|
||||
@@ -89,16 +89,16 @@ class PneumaticHub::DataStore {
|
||||
friend class PneumaticHub;
|
||||
uint32_t m_reservedMask{0};
|
||||
bool m_compressorReserved{false};
|
||||
wpi::mutex m_reservedLock;
|
||||
wpi::util::mutex m_reservedLock;
|
||||
PneumaticHub m_moduleObject{0, HAL_kInvalidHandle, 0};
|
||||
std::array<units::millisecond_t, 16> m_oneShotDurMs{0_ms};
|
||||
std::array<wpi::units::millisecond_t, 16> m_oneShotDurMs{0_ms};
|
||||
};
|
||||
|
||||
PneumaticHub::PneumaticHub(int busId)
|
||||
: PneumaticHub{busId, SensorUtil::GetDefaultREVPHModule()} {}
|
||||
|
||||
PneumaticHub::PneumaticHub(int busId, int module) {
|
||||
std::string stackTrace = wpi::GetStackTrace(1);
|
||||
std::string stackTrace = wpi::util::GetStackTrace(1);
|
||||
std::scoped_lock lock(m_handleLock);
|
||||
auto& res = GetDataStore(busId, module);
|
||||
m_dataStore = res.lock();
|
||||
@@ -134,8 +134,8 @@ void PneumaticHub::EnableCompressorDigital() {
|
||||
}
|
||||
|
||||
void PneumaticHub::EnableCompressorAnalog(
|
||||
units::pounds_per_square_inch_t minPressure,
|
||||
units::pounds_per_square_inch_t maxPressure) {
|
||||
wpi::units::pounds_per_square_inch_t minPressure,
|
||||
wpi::units::pounds_per_square_inch_t maxPressure) {
|
||||
if (minPressure >= maxPressure) {
|
||||
throw FRC_MakeError(err::InvalidParameter,
|
||||
"maxPressure must be greater than minPressure");
|
||||
@@ -154,8 +154,8 @@ void PneumaticHub::EnableCompressorAnalog(
|
||||
// Send the voltage as it would be if the 5V rail was at exactly 5V.
|
||||
// The firmware will compensate for the real 5V rail voltage, which
|
||||
// can fluctuate somewhat over time.
|
||||
units::volt_t minAnalogVoltage = PSIToVolts(minPressure, 5_V);
|
||||
units::volt_t maxAnalogVoltage = PSIToVolts(maxPressure, 5_V);
|
||||
wpi::units::volt_t minAnalogVoltage = PSIToVolts(minPressure, 5_V);
|
||||
wpi::units::volt_t maxAnalogVoltage = PSIToVolts(maxPressure, 5_V);
|
||||
|
||||
int32_t status = 0;
|
||||
HAL_SetREVPHClosedLoopControlAnalog(m_handle, minAnalogVoltage.value(),
|
||||
@@ -164,8 +164,8 @@ void PneumaticHub::EnableCompressorAnalog(
|
||||
}
|
||||
|
||||
void PneumaticHub::EnableCompressorHybrid(
|
||||
units::pounds_per_square_inch_t minPressure,
|
||||
units::pounds_per_square_inch_t maxPressure) {
|
||||
wpi::units::pounds_per_square_inch_t minPressure,
|
||||
wpi::units::pounds_per_square_inch_t maxPressure) {
|
||||
if (minPressure >= maxPressure) {
|
||||
throw FRC_MakeError(err::InvalidParameter,
|
||||
"maxPressure must be greater than minPressure");
|
||||
@@ -184,8 +184,8 @@ void PneumaticHub::EnableCompressorHybrid(
|
||||
// Send the voltage as it would be if the 5V rail was at exactly 5V.
|
||||
// The firmware will compensate for the real 5V rail voltage, which
|
||||
// can fluctuate somewhat over time.
|
||||
units::volt_t minAnalogVoltage = PSIToVolts(minPressure, 5_V);
|
||||
units::volt_t maxAnalogVoltage = PSIToVolts(maxPressure, 5_V);
|
||||
wpi::units::volt_t minAnalogVoltage = PSIToVolts(minPressure, 5_V);
|
||||
wpi::units::volt_t maxAnalogVoltage = PSIToVolts(maxPressure, 5_V);
|
||||
|
||||
int32_t status = 0;
|
||||
HAL_SetREVPHClosedLoopControlHybrid(m_handle, minAnalogVoltage.value(),
|
||||
@@ -207,11 +207,11 @@ bool PneumaticHub::GetPressureSwitch() const {
|
||||
return result;
|
||||
}
|
||||
|
||||
units::ampere_t PneumaticHub::GetCompressorCurrent() const {
|
||||
wpi::units::ampere_t PneumaticHub::GetCompressorCurrent() const {
|
||||
int32_t status = 0;
|
||||
auto result = HAL_GetREVPHCompressorCurrent(m_handle, &status);
|
||||
FRC_ReportError(status, "Module {}", m_module);
|
||||
return units::ampere_t{result};
|
||||
return wpi::units::ampere_t{result};
|
||||
}
|
||||
|
||||
void PneumaticHub::SetSolenoids(int mask, int values) {
|
||||
@@ -245,7 +245,7 @@ void PneumaticHub::FireOneShot(int index) {
|
||||
FRC_ReportError(status, "Module {}", m_module);
|
||||
}
|
||||
|
||||
void PneumaticHub::SetOneShotDuration(int index, units::second_t duration) {
|
||||
void PneumaticHub::SetOneShotDuration(int index, wpi::units::second_t duration) {
|
||||
m_dataStore->m_oneShotDurMs[index] = duration;
|
||||
}
|
||||
|
||||
@@ -370,48 +370,48 @@ void PneumaticHub::ClearStickyFaults() {
|
||||
FRC_ReportError(status, "Module {}", m_module);
|
||||
}
|
||||
|
||||
units::volt_t PneumaticHub::GetInputVoltage() const {
|
||||
wpi::units::volt_t PneumaticHub::GetInputVoltage() const {
|
||||
int32_t status = 0;
|
||||
auto voltage = HAL_GetREVPHVoltage(m_handle, &status);
|
||||
FRC_ReportError(status, "Module {}", m_module);
|
||||
return units::volt_t{voltage};
|
||||
return wpi::units::volt_t{voltage};
|
||||
}
|
||||
|
||||
units::volt_t PneumaticHub::Get5VRegulatedVoltage() const {
|
||||
wpi::units::volt_t PneumaticHub::Get5VRegulatedVoltage() const {
|
||||
int32_t status = 0;
|
||||
auto voltage = HAL_GetREVPH5VVoltage(m_handle, &status);
|
||||
FRC_ReportError(status, "Module {}", m_module);
|
||||
return units::volt_t{voltage};
|
||||
return wpi::units::volt_t{voltage};
|
||||
}
|
||||
|
||||
units::ampere_t PneumaticHub::GetSolenoidsTotalCurrent() const {
|
||||
wpi::units::ampere_t PneumaticHub::GetSolenoidsTotalCurrent() const {
|
||||
int32_t status = 0;
|
||||
auto current = HAL_GetREVPHSolenoidCurrent(m_handle, &status);
|
||||
FRC_ReportError(status, "Module {}", m_module);
|
||||
return units::ampere_t{current};
|
||||
return wpi::units::ampere_t{current};
|
||||
}
|
||||
|
||||
units::volt_t PneumaticHub::GetSolenoidsVoltage() const {
|
||||
wpi::units::volt_t PneumaticHub::GetSolenoidsVoltage() const {
|
||||
int32_t status = 0;
|
||||
auto voltage = HAL_GetREVPHSolenoidVoltage(m_handle, &status);
|
||||
FRC_ReportError(status, "Module {}", m_module);
|
||||
return units::volt_t{voltage};
|
||||
return wpi::units::volt_t{voltage};
|
||||
}
|
||||
|
||||
units::volt_t PneumaticHub::GetAnalogVoltage(int channel) const {
|
||||
wpi::units::volt_t PneumaticHub::GetAnalogVoltage(int channel) const {
|
||||
int32_t status = 0;
|
||||
auto voltage = HAL_GetREVPHAnalogVoltage(m_handle, channel, &status);
|
||||
FRC_ReportError(status, "Module {}", m_module);
|
||||
return units::volt_t{voltage};
|
||||
return wpi::units::volt_t{voltage};
|
||||
}
|
||||
|
||||
units::pounds_per_square_inch_t PneumaticHub::GetPressure(int channel) const {
|
||||
wpi::units::pounds_per_square_inch_t PneumaticHub::GetPressure(int channel) const {
|
||||
int32_t status = 0;
|
||||
auto sensorVoltage = HAL_GetREVPHAnalogVoltage(m_handle, channel, &status);
|
||||
FRC_ReportError(status, "Module {}", m_module);
|
||||
auto supplyVoltage = HAL_GetREVPH5VVoltage(m_handle, &status);
|
||||
FRC_ReportError(status, "Module {}", m_module);
|
||||
return VoltsToPSI(units::volt_t{sensorVoltage}, units::volt_t{supplyVoltage});
|
||||
return VoltsToPSI(wpi::units::volt_t{sensorVoltage}, wpi::units::volt_t{supplyVoltage});
|
||||
}
|
||||
|
||||
Solenoid PneumaticHub::MakeSolenoid(int channel) {
|
||||
@@ -434,7 +434,7 @@ void PneumaticHub::ReportUsage(std::string_view device, std::string_view data) {
|
||||
|
||||
std::shared_ptr<PneumaticsBase> PneumaticHub::GetForModule(int busId,
|
||||
int module) {
|
||||
std::string stackTrace = wpi::GetStackTrace(1);
|
||||
std::string stackTrace = wpi::util::GetStackTrace(1);
|
||||
std::scoped_lock lock(m_handleLock);
|
||||
auto& res = GetDataStore(busId, module);
|
||||
std::shared_ptr<DataStore> dataStore = res.lock();
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
#include "wpi/system/Errors.hpp"
|
||||
#include "wpi/util/SensorUtil.hpp"
|
||||
|
||||
using namespace frc;
|
||||
using namespace wpi;
|
||||
|
||||
static_assert(
|
||||
static_cast<int>(CompressorConfigType::Disabled) ==
|
||||
|
||||
@@ -20,11 +20,11 @@
|
||||
#include "wpi/util/SensorUtil.hpp"
|
||||
#include "wpi/util/StackTrace.hpp"
|
||||
|
||||
using namespace frc;
|
||||
using namespace wpi;
|
||||
|
||||
wpi::mutex PneumaticsControlModule::m_handleLock;
|
||||
wpi::util::mutex PneumaticsControlModule::m_handleLock;
|
||||
std::unique_ptr<
|
||||
wpi::DenseMap<int, std::weak_ptr<PneumaticsControlModule::DataStore>>[]>
|
||||
wpi::util::DenseMap<int, std::weak_ptr<PneumaticsControlModule::DataStore>>[]>
|
||||
PneumaticsControlModule::m_handleMaps = nullptr;
|
||||
|
||||
// Always called under lock, so we can avoid the double lock from the magic
|
||||
@@ -35,7 +35,7 @@ PneumaticsControlModule::GetDataStore(int busId, int module) {
|
||||
FRC_AssertMessage(busId >= 0 && busId < numBuses,
|
||||
"Bus {} out of range. Must be [0-{}).", busId, numBuses);
|
||||
if (!m_handleMaps) {
|
||||
m_handleMaps = std::make_unique<wpi::DenseMap<
|
||||
m_handleMaps = std::make_unique<wpi::util::DenseMap<
|
||||
int, std::weak_ptr<PneumaticsControlModule::DataStore>>[]>(numBuses);
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ class PneumaticsControlModule::DataStore {
|
||||
FRC_CheckErrorStatus(status, "Module {}", module);
|
||||
m_moduleObject = PneumaticsControlModule{busId, handle, module};
|
||||
m_moduleObject.m_dataStore =
|
||||
std::shared_ptr<DataStore>{this, wpi::NullDeleter<DataStore>()};
|
||||
std::shared_ptr<DataStore>{this, wpi::util::NullDeleter<DataStore>()};
|
||||
}
|
||||
|
||||
~DataStore() noexcept { HAL_FreeCTREPCM(m_moduleObject.m_handle); }
|
||||
@@ -63,7 +63,7 @@ class PneumaticsControlModule::DataStore {
|
||||
friend class PneumaticsControlModule;
|
||||
uint32_t m_reservedMask{0};
|
||||
bool m_compressorReserved{false};
|
||||
wpi::mutex m_reservedLock;
|
||||
wpi::util::mutex m_reservedLock;
|
||||
PneumaticsControlModule m_moduleObject{0, HAL_kInvalidHandle, 0};
|
||||
};
|
||||
|
||||
@@ -71,7 +71,7 @@ PneumaticsControlModule::PneumaticsControlModule(int busId)
|
||||
: PneumaticsControlModule{busId, SensorUtil::GetDefaultCTREPCMModule()} {}
|
||||
|
||||
PneumaticsControlModule::PneumaticsControlModule(int busId, int module) {
|
||||
std::string stackTrace = wpi::GetStackTrace(1);
|
||||
std::string stackTrace = wpi::util::GetStackTrace(1);
|
||||
std::scoped_lock lock(m_handleLock);
|
||||
auto& res = GetDataStore(busId, module);
|
||||
m_dataStore = res.lock();
|
||||
@@ -109,16 +109,16 @@ void PneumaticsControlModule::EnableCompressorDigital() {
|
||||
}
|
||||
|
||||
void PneumaticsControlModule::EnableCompressorAnalog(
|
||||
units::pounds_per_square_inch_t minPressure,
|
||||
units::pounds_per_square_inch_t maxPressure) {
|
||||
wpi::units::pounds_per_square_inch_t minPressure,
|
||||
wpi::units::pounds_per_square_inch_t maxPressure) {
|
||||
int32_t status = 0;
|
||||
HAL_SetCTREPCMClosedLoopControl(m_handle, true, &status);
|
||||
FRC_ReportError(status, "Module {}", m_module);
|
||||
}
|
||||
|
||||
void PneumaticsControlModule::EnableCompressorHybrid(
|
||||
units::pounds_per_square_inch_t minPressure,
|
||||
units::pounds_per_square_inch_t maxPressure) {
|
||||
wpi::units::pounds_per_square_inch_t minPressure,
|
||||
wpi::units::pounds_per_square_inch_t maxPressure) {
|
||||
int32_t status = 0;
|
||||
HAL_SetCTREPCMClosedLoopControl(m_handle, true, &status);
|
||||
FRC_ReportError(status, "Module {}", m_module);
|
||||
@@ -139,11 +139,11 @@ bool PneumaticsControlModule::GetPressureSwitch() const {
|
||||
return result;
|
||||
}
|
||||
|
||||
units::ampere_t PneumaticsControlModule::GetCompressorCurrent() const {
|
||||
wpi::units::ampere_t PneumaticsControlModule::GetCompressorCurrent() const {
|
||||
int32_t status = 0;
|
||||
auto result = HAL_GetCTREPCMCompressorCurrent(m_handle, &status);
|
||||
FRC_ReportError(status, "Module {}", m_module);
|
||||
return units::ampere_t{result};
|
||||
return wpi::units::ampere_t{result};
|
||||
}
|
||||
|
||||
bool PneumaticsControlModule::GetCompressorCurrentTooHighFault() const {
|
||||
@@ -235,9 +235,9 @@ void PneumaticsControlModule::FireOneShot(int index) {
|
||||
}
|
||||
|
||||
void PneumaticsControlModule::SetOneShotDuration(int index,
|
||||
units::second_t duration) {
|
||||
wpi::units::second_t duration) {
|
||||
int32_t status = 0;
|
||||
units::millisecond_t millis = duration;
|
||||
wpi::units::millisecond_t millis = duration;
|
||||
HAL_SetCTREPCMOneShotDuration(m_handle, index, millis.to<int32_t>(), &status);
|
||||
FRC_ReportError(status, "Module {}", m_module);
|
||||
}
|
||||
@@ -275,11 +275,11 @@ void PneumaticsControlModule::UnreserveCompressor() {
|
||||
m_dataStore->m_compressorReserved = false;
|
||||
}
|
||||
|
||||
units::volt_t PneumaticsControlModule::GetAnalogVoltage(int channel) const {
|
||||
wpi::units::volt_t PneumaticsControlModule::GetAnalogVoltage(int channel) const {
|
||||
return 0_V;
|
||||
}
|
||||
|
||||
units::pounds_per_square_inch_t PneumaticsControlModule::GetPressure(
|
||||
wpi::units::pounds_per_square_inch_t PneumaticsControlModule::GetPressure(
|
||||
int channel) const {
|
||||
return 0_psi;
|
||||
}
|
||||
@@ -305,7 +305,7 @@ void PneumaticsControlModule::ReportUsage(std::string_view device,
|
||||
|
||||
std::shared_ptr<PneumaticsBase> PneumaticsControlModule::GetForModule(
|
||||
int busId, int module) {
|
||||
std::string stackTrace = wpi::GetStackTrace(1);
|
||||
std::string stackTrace = wpi::util::GetStackTrace(1);
|
||||
std::scoped_lock lock(m_handleLock);
|
||||
auto& res = GetDataStore(busId, module);
|
||||
std::shared_ptr<DataStore> dataStore = res.lock();
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
#include "wpi/util/sendable/SendableBuilder.hpp"
|
||||
#include "wpi/util/sendable/SendableRegistry.hpp"
|
||||
|
||||
using namespace frc;
|
||||
using namespace wpi;
|
||||
|
||||
Solenoid::Solenoid(int busId, int module, PneumaticsModuleType moduleType,
|
||||
int channel)
|
||||
@@ -28,7 +28,7 @@ Solenoid::Solenoid(int busId, int module, PneumaticsModuleType moduleType,
|
||||
}
|
||||
|
||||
m_module->ReportUsage(fmt::format("Solenoid[{}]", m_channel), "Solenoid");
|
||||
wpi::SendableRegistry::Add(this, "Solenoid", m_module->GetModuleNumber(),
|
||||
wpi::util::SendableRegistry::Add(this, "Solenoid", m_module->GetModuleNumber(),
|
||||
m_channel);
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ bool Solenoid::IsDisabled() const {
|
||||
return (m_module->GetSolenoidDisabledList() & m_mask) != 0;
|
||||
}
|
||||
|
||||
void Solenoid::SetPulseDuration(units::second_t duration) {
|
||||
void Solenoid::SetPulseDuration(wpi::units::second_t duration) {
|
||||
m_module->SetOneShotDuration(m_channel, duration);
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ void Solenoid::StartPulse() {
|
||||
m_module->FireOneShot(m_channel);
|
||||
}
|
||||
|
||||
void Solenoid::InitSendable(wpi::SendableBuilder& builder) {
|
||||
void Solenoid::InitSendable(wpi::util::SendableBuilder& builder) {
|
||||
builder.SetSmartDashboardType("Solenoid");
|
||||
builder.SetActuator(true);
|
||||
builder.AddBooleanProperty(
|
||||
|
||||
@@ -17,18 +17,18 @@
|
||||
#include "wpi/util/sendable/SendableRegistry.hpp"
|
||||
|
||||
static_assert(static_cast<HAL_PowerDistributionType>(
|
||||
frc::PowerDistribution::ModuleType::kCTRE) ==
|
||||
wpi::PowerDistribution::ModuleType::kCTRE) ==
|
||||
HAL_PowerDistributionType::HAL_PowerDistributionType_kCTRE);
|
||||
static_assert(static_cast<HAL_PowerDistributionType>(
|
||||
frc::PowerDistribution::ModuleType::kRev) ==
|
||||
wpi::PowerDistribution::ModuleType::kRev) ==
|
||||
HAL_PowerDistributionType::HAL_PowerDistributionType_kRev);
|
||||
static_assert(frc::PowerDistribution::kDefaultModule ==
|
||||
static_assert(wpi::PowerDistribution::kDefaultModule ==
|
||||
HAL_DEFAULT_POWER_DISTRIBUTION_MODULE);
|
||||
|
||||
using namespace frc;
|
||||
using namespace wpi;
|
||||
|
||||
PowerDistribution::PowerDistribution(int busId) {
|
||||
auto stack = wpi::GetStackTrace(1);
|
||||
auto stack = wpi::util::GetStackTrace(1);
|
||||
|
||||
int32_t status = 0;
|
||||
m_handle = HAL_InitializePowerDistribution(
|
||||
@@ -45,12 +45,12 @@ PowerDistribution::PowerDistribution(int busId) {
|
||||
} else {
|
||||
HAL_ReportUsage("PDH", m_module, "");
|
||||
}
|
||||
wpi::SendableRegistry::Add(this, "PowerDistribution", m_module);
|
||||
wpi::util::SendableRegistry::Add(this, "PowerDistribution", m_module);
|
||||
}
|
||||
|
||||
PowerDistribution::PowerDistribution(int busId, int module,
|
||||
ModuleType moduleType) {
|
||||
auto stack = wpi::GetStackTrace(1);
|
||||
auto stack = wpi::util::GetStackTrace(1);
|
||||
|
||||
int32_t status = 0;
|
||||
m_handle = HAL_InitializePowerDistribution(
|
||||
@@ -65,7 +65,7 @@ PowerDistribution::PowerDistribution(int busId, int module,
|
||||
} else {
|
||||
HAL_ReportUsage("PDH_REV", m_module, "");
|
||||
}
|
||||
wpi::SendableRegistry::Add(this, "PowerDistribution", m_module);
|
||||
wpi::util::SendableRegistry::Add(this, "PowerDistribution", m_module);
|
||||
}
|
||||
|
||||
int PowerDistribution::GetNumChannels() const {
|
||||
@@ -320,7 +320,7 @@ PowerDistribution::StickyFaults PowerDistribution::GetStickyFaults() const {
|
||||
return stickyFaults;
|
||||
}
|
||||
|
||||
void PowerDistribution::InitSendable(wpi::SendableBuilder& builder) {
|
||||
void PowerDistribution::InitSendable(wpi::util::SendableBuilder& builder) {
|
||||
builder.SetSmartDashboardType("PowerDistribution");
|
||||
int numChannels = GetNumChannels();
|
||||
// Use manual reads to avoid printing errors
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
#include "wpi/util/sendable/SendableBuilder.hpp"
|
||||
#include "wpi/util/sendable/SendableRegistry.hpp"
|
||||
|
||||
using namespace frc;
|
||||
using namespace wpi;
|
||||
|
||||
SharpIR SharpIR::GP2Y0A02YK0F(int channel) {
|
||||
return SharpIR(channel, 62.28, -1.092, 20_cm, 150_cm);
|
||||
@@ -30,13 +30,13 @@ SharpIR SharpIR::GP2Y0A51SK0F(int channel) {
|
||||
return SharpIR(channel, 5.2819, -1.161, 2_cm, 15_cm);
|
||||
}
|
||||
|
||||
SharpIR::SharpIR(int channel, double a, double b, units::meter_t min,
|
||||
units::meter_t max)
|
||||
SharpIR::SharpIR(int channel, double a, double b, wpi::units::meter_t min,
|
||||
wpi::units::meter_t max)
|
||||
: m_sensor(channel), m_A(a), m_B(b), m_min(min), m_max(max) {
|
||||
HAL_ReportUsage("IO", channel, "SharpIR");
|
||||
wpi::SendableRegistry::Add(this, "SharpIR", channel);
|
||||
wpi::util::SendableRegistry::Add(this, "SharpIR", channel);
|
||||
|
||||
m_simDevice = hal::SimDevice("SharpIR", m_sensor.GetChannel());
|
||||
m_simDevice = wpi::hal::SimDevice("SharpIR", m_sensor.GetChannel());
|
||||
if (m_simDevice) {
|
||||
m_simRange = m_simDevice.CreateDouble("Range (m)", false, 0.0);
|
||||
m_sensor.SetSimDevice(m_simDevice);
|
||||
@@ -47,19 +47,19 @@ int SharpIR::GetChannel() const {
|
||||
return m_sensor.GetChannel();
|
||||
}
|
||||
|
||||
units::meter_t SharpIR::GetRange() const {
|
||||
wpi::units::meter_t SharpIR::GetRange() const {
|
||||
if (m_simRange) {
|
||||
return std::clamp(units::meter_t{m_simRange.Get()}, m_min, m_max);
|
||||
return std::clamp(wpi::units::meter_t{m_simRange.Get()}, m_min, m_max);
|
||||
} else {
|
||||
// Don't allow zero/negative values
|
||||
auto v = std::max(m_sensor.GetVoltage(), 0.00001);
|
||||
|
||||
return std::clamp(units::meter_t{m_A * std::pow(v, m_B) * 1e-2}, m_min,
|
||||
return std::clamp(wpi::units::meter_t{m_A * std::pow(v, m_B) * 1e-2}, m_min,
|
||||
m_max);
|
||||
}
|
||||
}
|
||||
|
||||
void SharpIR::InitSendable(wpi::SendableBuilder& builder) {
|
||||
void SharpIR::InitSendable(wpi::util::SendableBuilder& builder) {
|
||||
builder.SetSmartDashboardType("Ultrasonic");
|
||||
builder.AddDoubleProperty(
|
||||
"Value", [=, this] { return GetRange().value(); }, nullptr);
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
#include "wpi/util/NullDeleter.hpp"
|
||||
#include "wpi/util/sendable/SendableBuilder.hpp"
|
||||
|
||||
using namespace frc;
|
||||
using namespace wpi;
|
||||
|
||||
AnalogEncoder::~AnalogEncoder() {}
|
||||
|
||||
@@ -21,12 +21,12 @@ AnalogEncoder::AnalogEncoder(int channel)
|
||||
: AnalogEncoder(std::make_shared<AnalogInput>(channel)) {}
|
||||
|
||||
AnalogEncoder::AnalogEncoder(AnalogInput& analogInput)
|
||||
: m_analogInput{&analogInput, wpi::NullDeleter<AnalogInput>{}} {
|
||||
: m_analogInput{&analogInput, wpi::util::NullDeleter<AnalogInput>{}} {
|
||||
Init(1.0, 0.0);
|
||||
}
|
||||
|
||||
AnalogEncoder::AnalogEncoder(AnalogInput* analogInput)
|
||||
: m_analogInput{analogInput, wpi::NullDeleter<AnalogInput>{}} {
|
||||
: m_analogInput{analogInput, wpi::util::NullDeleter<AnalogInput>{}} {
|
||||
Init(1.0, 0.0);
|
||||
}
|
||||
|
||||
@@ -41,13 +41,13 @@ AnalogEncoder::AnalogEncoder(int channel, double fullRange, double expectedZero)
|
||||
|
||||
AnalogEncoder::AnalogEncoder(AnalogInput& analogInput, double fullRange,
|
||||
double expectedZero)
|
||||
: m_analogInput{&analogInput, wpi::NullDeleter<AnalogInput>{}} {
|
||||
: m_analogInput{&analogInput, wpi::util::NullDeleter<AnalogInput>{}} {
|
||||
Init(fullRange, expectedZero);
|
||||
}
|
||||
|
||||
AnalogEncoder::AnalogEncoder(AnalogInput* analogInput, double fullRange,
|
||||
double expectedZero)
|
||||
: m_analogInput{analogInput, wpi::NullDeleter<AnalogInput>{}} {
|
||||
: m_analogInput{analogInput, wpi::util::NullDeleter<AnalogInput>{}} {
|
||||
Init(fullRange, expectedZero);
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ AnalogEncoder::AnalogEncoder(std::shared_ptr<AnalogInput> analogInput,
|
||||
}
|
||||
|
||||
void AnalogEncoder::Init(double fullRange, double expectedZero) {
|
||||
m_simDevice = hal::SimDevice{"AnalogEncoder", m_analogInput->GetChannel()};
|
||||
m_simDevice = wpi::hal::SimDevice{"AnalogEncoder", m_analogInput->GetChannel()};
|
||||
|
||||
if (m_simDevice) {
|
||||
m_simPosition = m_simDevice.CreateDouble("Position", false, 0.0);
|
||||
@@ -69,7 +69,7 @@ void AnalogEncoder::Init(double fullRange, double expectedZero) {
|
||||
|
||||
HAL_ReportUsage("IO", m_analogInput->GetChannel(), "AnalogEncoder");
|
||||
|
||||
wpi::SendableRegistry::Add(this, "Analog Encoder",
|
||||
wpi::util::SendableRegistry::Add(this, "Analog Encoder",
|
||||
m_analogInput->GetChannel());
|
||||
}
|
||||
|
||||
@@ -88,7 +88,7 @@ double AnalogEncoder::Get() const {
|
||||
pos = pos * m_fullRange - m_expectedZero;
|
||||
|
||||
// Map from 0 - Full Range
|
||||
double result = InputModulus(pos, 0.0, m_fullRange);
|
||||
double result = wpi::math::InputModulus(pos, 0.0, m_fullRange);
|
||||
// Invert if necessary
|
||||
if (m_isInverted) {
|
||||
return m_fullRange - result;
|
||||
@@ -120,7 +120,7 @@ double AnalogEncoder::MapSensorRange(double pos) const {
|
||||
return pos;
|
||||
}
|
||||
|
||||
void AnalogEncoder::InitSendable(wpi::SendableBuilder& builder) {
|
||||
void AnalogEncoder::InitSendable(wpi::util::SendableBuilder& builder) {
|
||||
builder.SetSmartDashboardType("AbsoluteEncoder");
|
||||
builder.AddDoubleProperty(
|
||||
"Position", [this] { return this->Get(); }, nullptr);
|
||||
|
||||
@@ -12,19 +12,19 @@
|
||||
#include "wpi/util/sendable/SendableBuilder.hpp"
|
||||
#include "wpi/util/sendable/SendableRegistry.hpp"
|
||||
|
||||
using namespace frc;
|
||||
using namespace wpi;
|
||||
|
||||
AnalogPotentiometer::AnalogPotentiometer(int channel, double fullRange,
|
||||
double offset)
|
||||
: AnalogPotentiometer(std::make_shared<AnalogInput>(channel), fullRange,
|
||||
offset) {
|
||||
wpi::SendableRegistry::AddChild(this, m_analog_input.get());
|
||||
wpi::util::SendableRegistry::AddChild(this, m_analog_input.get());
|
||||
}
|
||||
|
||||
AnalogPotentiometer::AnalogPotentiometer(AnalogInput* input, double fullRange,
|
||||
double offset)
|
||||
: AnalogPotentiometer(
|
||||
std::shared_ptr<AnalogInput>(input, wpi::NullDeleter<AnalogInput>()),
|
||||
std::shared_ptr<AnalogInput>(input, wpi::util::NullDeleter<AnalogInput>()),
|
||||
fullRange, offset) {}
|
||||
|
||||
AnalogPotentiometer::AnalogPotentiometer(std::shared_ptr<AnalogInput> input,
|
||||
@@ -32,7 +32,7 @@ AnalogPotentiometer::AnalogPotentiometer(std::shared_ptr<AnalogInput> input,
|
||||
: m_analog_input(std::move(input)),
|
||||
m_fullRange(fullRange),
|
||||
m_offset(offset) {
|
||||
wpi::SendableRegistry::Add(this, "AnalogPotentiometer",
|
||||
wpi::util::SendableRegistry::Add(this, "AnalogPotentiometer",
|
||||
m_analog_input->GetChannel());
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ double AnalogPotentiometer::Get() const {
|
||||
m_offset;
|
||||
}
|
||||
|
||||
void AnalogPotentiometer::InitSendable(wpi::SendableBuilder& builder) {
|
||||
void AnalogPotentiometer::InitSendable(wpi::util::SendableBuilder& builder) {
|
||||
builder.SetSmartDashboardType("Analog Input");
|
||||
builder.AddDoubleProperty("Value", [=, this] { return Get(); }, nullptr);
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
#include "wpi/util/StackTrace.hpp"
|
||||
#include "wpi/util/sendable/SendableBuilder.hpp"
|
||||
|
||||
using namespace frc;
|
||||
using namespace wpi;
|
||||
|
||||
DutyCycle::DutyCycle(int channel) : m_channel{channel} {
|
||||
if (!SensorUtil::CheckDigitalChannel(channel)) {
|
||||
@@ -27,18 +27,18 @@ DutyCycle::DutyCycle(int channel) : m_channel{channel} {
|
||||
|
||||
void DutyCycle::InitDutyCycle() {
|
||||
int32_t status = 0;
|
||||
std::string stackTrace = wpi::GetStackTrace(1);
|
||||
std::string stackTrace = wpi::util::GetStackTrace(1);
|
||||
m_handle = HAL_InitializeDutyCycle(m_channel, stackTrace.c_str(), &status);
|
||||
FRC_CheckErrorStatus(status, "Channel {}", GetSourceChannel());
|
||||
HAL_ReportUsage("IO", m_channel, "DutyCycle");
|
||||
wpi::SendableRegistry::Add(this, "Duty Cycle", m_channel);
|
||||
wpi::util::SendableRegistry::Add(this, "Duty Cycle", m_channel);
|
||||
}
|
||||
|
||||
units::hertz_t DutyCycle::GetFrequency() const {
|
||||
wpi::units::hertz_t DutyCycle::GetFrequency() const {
|
||||
int32_t status = 0;
|
||||
auto retVal = HAL_GetDutyCycleFrequency(m_handle, &status);
|
||||
FRC_CheckErrorStatus(status, "Channel {}", GetSourceChannel());
|
||||
return units::hertz_t{retVal};
|
||||
return wpi::units::hertz_t{retVal};
|
||||
}
|
||||
|
||||
double DutyCycle::GetOutput() const {
|
||||
@@ -48,18 +48,18 @@ double DutyCycle::GetOutput() const {
|
||||
return retVal;
|
||||
}
|
||||
|
||||
units::second_t DutyCycle::GetHighTime() const {
|
||||
wpi::units::second_t DutyCycle::GetHighTime() const {
|
||||
int32_t status = 0;
|
||||
auto retVal = HAL_GetDutyCycleHighTime(m_handle, &status);
|
||||
FRC_CheckErrorStatus(status, "Channel {}", GetSourceChannel());
|
||||
return units::nanosecond_t{static_cast<double>(retVal)};
|
||||
return wpi::units::nanosecond_t{static_cast<double>(retVal)};
|
||||
}
|
||||
|
||||
int DutyCycle::GetSourceChannel() const {
|
||||
return m_channel;
|
||||
}
|
||||
|
||||
void DutyCycle::InitSendable(wpi::SendableBuilder& builder) {
|
||||
void DutyCycle::InitSendable(wpi::util::SendableBuilder& builder) {
|
||||
builder.SetSmartDashboardType("Duty Cycle");
|
||||
builder.AddDoubleProperty(
|
||||
"Frequency", [this] { return this->GetFrequency().value(); }, nullptr);
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
#include "wpi/util/NullDeleter.hpp"
|
||||
#include "wpi/util/sendable/SendableBuilder.hpp"
|
||||
|
||||
using namespace frc;
|
||||
using namespace wpi;
|
||||
|
||||
DutyCycleEncoder::DutyCycleEncoder(int channel)
|
||||
: m_dutyCycle{std::make_shared<DutyCycle>(channel)} {
|
||||
@@ -21,12 +21,12 @@ DutyCycleEncoder::DutyCycleEncoder(int channel)
|
||||
}
|
||||
|
||||
DutyCycleEncoder::DutyCycleEncoder(DutyCycle& dutyCycle)
|
||||
: m_dutyCycle{&dutyCycle, wpi::NullDeleter<DutyCycle>{}} {
|
||||
: m_dutyCycle{&dutyCycle, wpi::util::NullDeleter<DutyCycle>{}} {
|
||||
Init(1.0, 0.0);
|
||||
}
|
||||
|
||||
DutyCycleEncoder::DutyCycleEncoder(DutyCycle* dutyCycle)
|
||||
: m_dutyCycle{dutyCycle, wpi::NullDeleter<DutyCycle>{}} {
|
||||
: m_dutyCycle{dutyCycle, wpi::util::NullDeleter<DutyCycle>{}} {
|
||||
Init(1.0, 0.0);
|
||||
}
|
||||
|
||||
@@ -43,13 +43,13 @@ DutyCycleEncoder::DutyCycleEncoder(int channel, double fullRange,
|
||||
|
||||
DutyCycleEncoder::DutyCycleEncoder(DutyCycle& dutyCycle, double fullRange,
|
||||
double expectedZero)
|
||||
: m_dutyCycle{&dutyCycle, wpi::NullDeleter<DutyCycle>{}} {
|
||||
: m_dutyCycle{&dutyCycle, wpi::util::NullDeleter<DutyCycle>{}} {
|
||||
Init(fullRange, expectedZero);
|
||||
}
|
||||
|
||||
DutyCycleEncoder::DutyCycleEncoder(DutyCycle* dutyCycle, double fullRange,
|
||||
double expectedZero)
|
||||
: m_dutyCycle{dutyCycle, wpi::NullDeleter<DutyCycle>{}} {
|
||||
: m_dutyCycle{dutyCycle, wpi::util::NullDeleter<DutyCycle>{}} {
|
||||
Init(fullRange, expectedZero);
|
||||
}
|
||||
|
||||
@@ -60,19 +60,19 @@ DutyCycleEncoder::DutyCycleEncoder(std::shared_ptr<DutyCycle> dutyCycle,
|
||||
}
|
||||
|
||||
void DutyCycleEncoder::Init(double fullRange, double expectedZero) {
|
||||
m_simDevice = hal::SimDevice{"DutyCycle:DutyCycleEncoder",
|
||||
m_simDevice = wpi::hal::SimDevice{"DutyCycle:DutyCycleEncoder",
|
||||
m_dutyCycle->GetSourceChannel()};
|
||||
|
||||
if (m_simDevice) {
|
||||
m_simPosition = m_simDevice.CreateDouble("Position", false, 0.0);
|
||||
m_simIsConnected =
|
||||
m_simDevice.CreateBoolean("Connected", hal::SimDevice::kInput, true);
|
||||
m_simDevice.CreateBoolean("Connected", wpi::hal::SimDevice::kInput, true);
|
||||
}
|
||||
|
||||
m_fullRange = fullRange;
|
||||
m_expectedZero = expectedZero;
|
||||
|
||||
wpi::SendableRegistry::Add(this, "DutyCycle Encoder",
|
||||
wpi::util::SendableRegistry::Add(this, "DutyCycle Encoder",
|
||||
m_dutyCycle->GetSourceChannel());
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ double DutyCycleEncoder::Get() const {
|
||||
pos = pos * m_fullRange - m_expectedZero;
|
||||
|
||||
// Map from 0 - Full Range
|
||||
double result = InputModulus(pos, 0.0, m_fullRange);
|
||||
double result = wpi::math::InputModulus(pos, 0.0, m_fullRange);
|
||||
// Invert if necessary
|
||||
if (m_isInverted) {
|
||||
return m_fullRange - result;
|
||||
@@ -121,7 +121,7 @@ void DutyCycleEncoder::SetDutyCycleRange(double min, double max) {
|
||||
m_sensorMax = std::clamp(max, 0.0, 1.0);
|
||||
}
|
||||
|
||||
units::hertz_t DutyCycleEncoder::GetFrequency() const {
|
||||
wpi::units::hertz_t DutyCycleEncoder::GetFrequency() const {
|
||||
return m_dutyCycle->GetFrequency();
|
||||
}
|
||||
|
||||
@@ -133,7 +133,7 @@ bool DutyCycleEncoder::IsConnected() const {
|
||||
}
|
||||
|
||||
void DutyCycleEncoder::SetConnectedFrequencyThreshold(
|
||||
units::hertz_t frequency) {
|
||||
wpi::units::hertz_t frequency) {
|
||||
if (frequency < 0_Hz) {
|
||||
frequency = 0_Hz;
|
||||
}
|
||||
@@ -144,7 +144,7 @@ void DutyCycleEncoder::SetInverted(bool inverted) {
|
||||
m_isInverted = inverted;
|
||||
}
|
||||
|
||||
void DutyCycleEncoder::SetAssumedFrequency(units::hertz_t frequency) {
|
||||
void DutyCycleEncoder::SetAssumedFrequency(wpi::units::hertz_t frequency) {
|
||||
if (frequency.value() == 0) {
|
||||
m_period = 0_s;
|
||||
} else {
|
||||
@@ -156,7 +156,7 @@ int DutyCycleEncoder::GetSourceChannel() const {
|
||||
return m_dutyCycle->GetSourceChannel();
|
||||
}
|
||||
|
||||
void DutyCycleEncoder::InitSendable(wpi::SendableBuilder& builder) {
|
||||
void DutyCycleEncoder::InitSendable(wpi::util::SendableBuilder& builder) {
|
||||
builder.SetSmartDashboardType("AbsoluteEncoder");
|
||||
builder.AddDoubleProperty(
|
||||
"Position", [this] { return this->Get(); }, nullptr);
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
#include "wpi/util/sendable/SendableBuilder.hpp"
|
||||
#include "wpi/util/sendable/SendableRegistry.hpp"
|
||||
|
||||
using namespace frc;
|
||||
using namespace wpi;
|
||||
|
||||
Encoder::Encoder(int aChannel, int bChannel, bool reverseDirection,
|
||||
EncodingType encodingType) {
|
||||
@@ -35,14 +35,14 @@ void Encoder::Reset() {
|
||||
FRC_CheckErrorStatus(status, "Reset");
|
||||
}
|
||||
|
||||
units::second_t Encoder::GetPeriod() const {
|
||||
wpi::units::second_t Encoder::GetPeriod() const {
|
||||
int32_t status = 0;
|
||||
double value = HAL_GetEncoderPeriod(m_encoder, &status);
|
||||
FRC_CheckErrorStatus(status, "GetPeriod");
|
||||
return units::second_t{value};
|
||||
return wpi::units::second_t{value};
|
||||
}
|
||||
|
||||
void Encoder::SetMaxPeriod(units::second_t maxPeriod) {
|
||||
void Encoder::SetMaxPeriod(wpi::units::second_t maxPeriod) {
|
||||
int32_t status = 0;
|
||||
HAL_SetEncoderMaxPeriod(m_encoder, maxPeriod.value(), &status);
|
||||
FRC_CheckErrorStatus(status, "SetMaxPeriod");
|
||||
@@ -145,7 +145,7 @@ int Encoder::GetFPGAIndex() const {
|
||||
return val;
|
||||
}
|
||||
|
||||
void Encoder::InitSendable(wpi::SendableBuilder& builder) {
|
||||
void Encoder::InitSendable(wpi::util::SendableBuilder& builder) {
|
||||
int32_t status = 0;
|
||||
HAL_EncoderEncodingType type = HAL_GetEncoderEncodingType(m_encoder, &status);
|
||||
FRC_CheckErrorStatus(status, "GetEncodingType");
|
||||
@@ -184,7 +184,7 @@ void Encoder::InitEncoder(int aChannel, int bChannel, bool reverseDirection,
|
||||
break;
|
||||
}
|
||||
HAL_ReportUsage(fmt::format("IO[{},{}]", aChannel, bChannel), type);
|
||||
// wpi::SendableRegistry::Add(this, "Encoder", m_aSource->GetChannel());
|
||||
// wpi::util::SendableRegistry::Add(this, "Encoder", m_aSource->GetChannel());
|
||||
}
|
||||
|
||||
double Encoder::DecodingScaleFactor() const {
|
||||
|
||||
Reference in New Issue
Block a user