SCRIPT namespace replacements

This commit is contained in:
PJ Reiniger
2025-11-07 20:00:05 -05:00
committed by Peter Johnson
parent ae6c043632
commit 9aca8e0fd6
2622 changed files with 22275 additions and 22275 deletions

View File

@@ -13,9 +13,9 @@
#include "wpi/system/Errors.hpp"
#include "wpi/system/SystemServer.hpp"
using namespace frc;
using namespace wpi;
wpi::mutex ExpansionHub::m_handleLock;
wpi::util::mutex ExpansionHub::m_handleLock;
std::weak_ptr<ExpansionHub::DataStore> ExpansionHub::m_storeMap[4];
class ExpansionHub::DataStore {
@@ -33,11 +33,11 @@ class ExpansionHub::DataStore {
DataStore& operator=(DataStore&) = delete;
DataStore& operator=(DataStore&&) = delete;
nt::BooleanSubscriber m_hubConnectedSubscriber;
wpi::nt::BooleanSubscriber m_hubConnectedSubscriber;
uint32_t m_reservedMotorMask{0};
uint32_t m_reservedServoMask{0};
wpi::mutex m_reservedLock;
wpi::util::mutex m_reservedLock;
int m_usbId;
};

View File

@@ -13,7 +13,7 @@ static constexpr int kPositionMode = 2;
static constexpr int kVelocityMode = 3;
static constexpr int kFollowerMode = 4;
using namespace frc;
using namespace wpi;
ExpansionHubMotor::ExpansionHubMotor(int usbId, int channel)
: m_hub{usbId},
@@ -31,7 +31,7 @@ ExpansionHubMotor::ExpansionHubMotor(int usbId, int channel)
auto systemServer = SystemServer::GetSystemServer();
nt::PubSubOptions options;
wpi::nt::PubSubOptions options;
options.sendAll = true;
options.keepDuplicates = true;
options.periodic = 0.005;
@@ -96,7 +96,7 @@ void ExpansionHubMotor::SetPercentagePower(double power) {
m_setpointPublisher.Set(power);
}
void ExpansionHubMotor::SetVoltage(units::volt_t voltage) {
void ExpansionHubMotor::SetVoltage(wpi::units::volt_t voltage) {
m_modePublisher.Set(kVoltageMode);
m_setpointPublisher.Set(voltage.to<double>());
}
@@ -119,8 +119,8 @@ void ExpansionHubMotor::SetFloatOn0(bool floatOn0) {
m_floatOn0Publisher.Set(floatOn0);
}
units::ampere_t ExpansionHubMotor::GetCurrent() const {
return units::ampere_t{m_currentSubscriber.Get(0)};
wpi::units::ampere_t ExpansionHubMotor::GetCurrent() const {
return wpi::units::ampere_t{m_currentSubscriber.Get(0)};
}
void ExpansionHubMotor::SetDistancePerCount(double perCount) {

View File

@@ -9,13 +9,13 @@
#include "wpi/system/Errors.hpp"
#include "wpi/system/SystemServer.hpp"
using namespace frc;
using namespace wpi;
ExpansionHubPidConstants::ExpansionHubPidConstants(int usbId, int channel,
bool isVelocityPid) {
auto systemServer = SystemServer::GetSystemServer();
nt::PubSubOptions options;
wpi::nt::PubSubOptions options;
options.sendAll = true;
options.keepDuplicates = true;
options.periodic = 0.005;

View File

@@ -7,7 +7,7 @@
#include "wpi/system/Errors.hpp"
#include "wpi/system/SystemServer.hpp"
using namespace frc;
using namespace wpi;
ExpansionHubServo::ExpansionHubServo(int usbId, int channel)
: m_hub{usbId}, m_channel{channel} {
@@ -22,7 +22,7 @@ ExpansionHubServo::ExpansionHubServo(int usbId, int channel)
auto systemServer = SystemServer::GetSystemServer();
nt::PubSubOptions options;
wpi::nt::PubSubOptions options;
options.sendAll = true;
options.keepDuplicates = true;
options.periodic = 0.005;
@@ -67,14 +67,14 @@ void ExpansionHubServo::Set(double value) {
SetPulseWidth(rawValue);
}
void ExpansionHubServo::SetAngle(units::degree_t angle) {
void ExpansionHubServo::SetAngle(wpi::units::degree_t angle) {
angle = std::clamp(angle, m_minServoAngle, m_maxServoAngle);
// NOLINTNEXTLINE(bugprone-integer-division)
Set((angle - m_minServoAngle) / GetServoAngleRange());
}
void ExpansionHubServo::SetPulseWidth(units::microsecond_t pulseWidth) {
void ExpansionHubServo::SetPulseWidth(wpi::units::microsecond_t pulseWidth) {
m_pulseWidthPublisher.Set(pulseWidth.to<double>());
}
@@ -82,20 +82,20 @@ void ExpansionHubServo::SetEnabled(bool enabled) {
m_enabledPublisher.Set(enabled);
}
void ExpansionHubServo::SetFramePeriod(units::microsecond_t framePeriod) {
void ExpansionHubServo::SetFramePeriod(wpi::units::microsecond_t framePeriod) {
m_framePeriodPublisher.Set(framePeriod.to<double>());
}
units::microsecond_t ExpansionHubServo::GetFullRangeScaleFactor() {
wpi::units::microsecond_t ExpansionHubServo::GetFullRangeScaleFactor() {
return m_maxPwm - m_minPwm;
}
units::degree_t ExpansionHubServo::GetServoAngleRange() {
wpi::units::degree_t ExpansionHubServo::GetServoAngleRange() {
return m_maxServoAngle - m_minServoAngle;
}
void ExpansionHubServo::SetPWMRange(units::microsecond_t minPwm,
units::microsecond_t maxPwm) {
void ExpansionHubServo::SetPWMRange(wpi::units::microsecond_t minPwm,
wpi::units::microsecond_t maxPwm) {
if (maxPwm <= minPwm) {
throw FRC_MakeError(err::ParameterOutOfRange,
"Max PWM must be greater than Min PWM");
@@ -106,8 +106,8 @@ void ExpansionHubServo::SetPWMRange(units::microsecond_t minPwm,
void ExpansionHubServo::SetReversed(bool reversed) {}
void ExpansionHubServo::SetAngleRange(units::degree_t minAngle,
units::degree_t maxAngle) {
void ExpansionHubServo::SetAngleRange(wpi::units::degree_t minAngle,
wpi::units::degree_t maxAngle) {
if (maxAngle <= minAngle) {
throw FRC_MakeError(err::ParameterOutOfRange,
"Max angle must be greater than Min angle");

View File

@@ -12,19 +12,19 @@
#include "wpi/util/StackTrace.hpp"
#include "wpi/util/sendable/SendableBuilder.hpp"
using namespace frc;
using namespace wpi;
Tachometer::Tachometer(int channel, EdgeConfiguration configuration)
: m_channel{channel} {
int32_t status = 0;
std::string stackTrace = wpi::GetStackTrace(1);
std::string stackTrace = wpi::util::GetStackTrace(1);
m_handle = HAL_InitializeCounter(
channel, configuration == EdgeConfiguration::kRisingEdge,
stackTrace.c_str(), &status);
FRC_CheckErrorStatus(status, "{}", channel);
HAL_ReportUsage("IO", channel, "Tachometer");
wpi::SendableRegistry::Add(this, "Tachometer", channel);
wpi::util::SendableRegistry::Add(this, "Tachometer", channel);
}
void Tachometer::SetEdgeConfiguration(EdgeConfiguration configuration) {
@@ -34,7 +34,7 @@ void Tachometer::SetEdgeConfiguration(EdgeConfiguration configuration) {
FRC_CheckErrorStatus(status, "{}", m_channel);
}
units::hertz_t Tachometer::GetFrequency() const {
wpi::units::hertz_t Tachometer::GetFrequency() const {
auto period = GetPeriod();
if (period.value() == 0) {
return 0_Hz;
@@ -42,11 +42,11 @@ units::hertz_t Tachometer::GetFrequency() const {
return 1 / period;
}
units::second_t Tachometer::GetPeriod() const {
wpi::units::second_t Tachometer::GetPeriod() const {
int32_t status = 0;
double period = HAL_GetCounterPeriod(m_handle, &status);
FRC_CheckErrorStatus(status, "Channel {}", m_channel);
return units::second_t{period};
return wpi::units::second_t{period};
}
int Tachometer::GetEdgesPerRevolution() const {
@@ -56,7 +56,7 @@ void Tachometer::SetEdgesPerRevolution(int edges) {
m_edgesPerRevolution = edges;
}
units::turns_per_second_t Tachometer::GetRevolutionsPerSecond() const {
wpi::units::turns_per_second_t Tachometer::GetRevolutionsPerSecond() const {
auto period = GetPeriod();
if (period.value() == 0) {
return 0_tps;
@@ -66,11 +66,11 @@ units::turns_per_second_t Tachometer::GetRevolutionsPerSecond() const {
return 0_tps;
}
auto rotationHz = ((1.0 / edgesPerRevolution) / period);
return units::turns_per_second_t{rotationHz.value()};
return wpi::units::turns_per_second_t{rotationHz.value()};
}
units::revolutions_per_minute_t Tachometer::GetRevolutionsPerMinute() const {
return units::revolutions_per_minute_t{GetRevolutionsPerSecond()};
wpi::units::revolutions_per_minute_t Tachometer::GetRevolutionsPerMinute() const {
return wpi::units::revolutions_per_minute_t{GetRevolutionsPerSecond()};
}
bool Tachometer::GetStopped() const {
@@ -80,13 +80,13 @@ bool Tachometer::GetStopped() const {
return stopped;
}
void Tachometer::SetMaxPeriod(units::second_t maxPeriod) {
void Tachometer::SetMaxPeriod(wpi::units::second_t maxPeriod) {
int32_t status = 0;
HAL_SetCounterMaxPeriod(m_handle, maxPeriod.value(), &status);
FRC_CheckErrorStatus(status, "Channel {}", m_channel);
}
void Tachometer::InitSendable(wpi::SendableBuilder& builder) {
void Tachometer::InitSendable(wpi::util::SendableBuilder& builder) {
builder.SetSmartDashboardType("Tachometer");
builder.AddDoubleProperty(
"RPS", [&] { return GetRevolutionsPerSecond().value(); }, nullptr);

View File

@@ -13,12 +13,12 @@
#include "wpi/util/StackTrace.hpp"
#include "wpi/util/sendable/SendableBuilder.hpp"
using namespace frc;
using namespace wpi;
UpDownCounter::UpDownCounter(int channel, EdgeConfiguration configuration)
: m_channel{channel} {
int32_t status = 0;
std::string stackTrace = wpi::GetStackTrace(1);
std::string stackTrace = wpi::util::GetStackTrace(1);
m_handle = HAL_InitializeCounter(
channel, configuration == EdgeConfiguration::kRisingEdge,
stackTrace.c_str(), &status);
@@ -27,7 +27,7 @@ UpDownCounter::UpDownCounter(int channel, EdgeConfiguration configuration)
Reset();
HAL_ReportUsage("IO", channel, "UpDownCounter");
wpi::SendableRegistry::Add(this, "UpDown Counter", channel);
wpi::util::SendableRegistry::Add(this, "UpDown Counter", channel);
}
int UpDownCounter::GetCount() const {
@@ -50,7 +50,7 @@ void UpDownCounter::SetEdgeConfiguration(EdgeConfiguration configuration) {
FRC_CheckErrorStatus(status, "{}", m_channel);
}
void UpDownCounter::InitSendable(wpi::SendableBuilder& builder) {
void UpDownCounter::InitSendable(wpi::util::SendableBuilder& builder) {
builder.SetSmartDashboardType("UpDown Counter");
builder.AddDoubleProperty("Count", [&] { return GetCount(); }, nullptr);
}

View File

@@ -15,7 +15,7 @@
#include "wpi/util/sendable/SendableBuilder.hpp"
#include "wpi/util/sendable/SendableRegistry.hpp"
using namespace frc;
using namespace wpi;
WPI_IGNORE_DEPRECATED
@@ -23,8 +23,8 @@ DifferentialDrive::DifferentialDrive(MotorController& leftMotor,
MotorController& rightMotor)
: DifferentialDrive{[&](double output) { leftMotor.Set(output); },
[&](double output) { rightMotor.Set(output); }} {
wpi::SendableRegistry::AddChild(this, &leftMotor);
wpi::SendableRegistry::AddChild(this, &rightMotor);
wpi::util::SendableRegistry::AddChild(this, &leftMotor);
wpi::util::SendableRegistry::AddChild(this, &rightMotor);
}
WPI_UNIGNORE_DEPRECATED
@@ -34,7 +34,7 @@ DifferentialDrive::DifferentialDrive(std::function<void(double)> leftMotor,
: m_leftMotor{std::move(leftMotor)}, m_rightMotor{std::move(rightMotor)} {
static int instances = 0;
++instances;
wpi::SendableRegistry::Add(this, "DifferentialDrive", instances);
wpi::util::SendableRegistry::Add(this, "DifferentialDrive", instances);
}
void DifferentialDrive::ArcadeDrive(double xSpeed, double zRotation,
@@ -45,8 +45,8 @@ void DifferentialDrive::ArcadeDrive(double xSpeed, double zRotation,
reported = true;
}
xSpeed = ApplyDeadband(xSpeed, m_deadband);
zRotation = ApplyDeadband(zRotation, m_deadband);
xSpeed = wpi::math::ApplyDeadband(xSpeed, m_deadband);
zRotation = wpi::math::ApplyDeadband(zRotation, m_deadband);
auto [left, right] = ArcadeDriveIK(xSpeed, zRotation, squareInputs);
@@ -67,8 +67,8 @@ void DifferentialDrive::CurvatureDrive(double xSpeed, double zRotation,
reported = true;
}
xSpeed = ApplyDeadband(xSpeed, m_deadband);
zRotation = ApplyDeadband(zRotation, m_deadband);
xSpeed = wpi::math::ApplyDeadband(xSpeed, m_deadband);
zRotation = wpi::math::ApplyDeadband(zRotation, m_deadband);
auto [left, right] = CurvatureDriveIK(xSpeed, zRotation, allowTurnInPlace);
@@ -89,8 +89,8 @@ void DifferentialDrive::TankDrive(double leftSpeed, double rightSpeed,
reported = true;
}
leftSpeed = ApplyDeadband(leftSpeed, m_deadband);
rightSpeed = ApplyDeadband(rightSpeed, m_deadband);
leftSpeed = wpi::math::ApplyDeadband(leftSpeed, m_deadband);
rightSpeed = wpi::math::ApplyDeadband(rightSpeed, m_deadband);
auto [left, right] = TankDriveIK(leftSpeed, rightSpeed, squareInputs);
@@ -111,8 +111,8 @@ DifferentialDrive::WheelSpeeds DifferentialDrive::ArcadeDriveIK(
// Square the inputs (while preserving the sign) to increase fine control
// while permitting full power.
if (squareInputs) {
xSpeed = CopyDirectionPow(xSpeed, 2);
zRotation = CopyDirectionPow(zRotation, 2);
xSpeed = wpi::math::CopyDirectionPow(xSpeed, 2);
zRotation = wpi::math::CopyDirectionPow(zRotation, 2);
}
double leftSpeed = xSpeed - zRotation;
@@ -166,8 +166,8 @@ DifferentialDrive::WheelSpeeds DifferentialDrive::TankDriveIK(
// Square the inputs (while preserving the sign) to increase fine control
// while permitting full power.
if (squareInputs) {
leftSpeed = CopyDirectionPow(leftSpeed, 2);
rightSpeed = CopyDirectionPow(rightSpeed, 2);
leftSpeed = wpi::math::CopyDirectionPow(leftSpeed, 2);
rightSpeed = wpi::math::CopyDirectionPow(rightSpeed, 2);
}
return {leftSpeed, rightSpeed};
@@ -187,7 +187,7 @@ std::string DifferentialDrive::GetDescription() const {
return "DifferentialDrive";
}
void DifferentialDrive::InitSendable(wpi::SendableBuilder& builder) {
void DifferentialDrive::InitSendable(wpi::util::SendableBuilder& builder) {
builder.SetSmartDashboardType("DifferentialDrive");
builder.SetActuator(true);
builder.AddDoubleProperty(

View File

@@ -15,7 +15,7 @@
#include "wpi/util/sendable/SendableBuilder.hpp"
#include "wpi/util/sendable/SendableRegistry.hpp"
using namespace frc;
using namespace wpi;
WPI_IGNORE_DEPRECATED
@@ -27,10 +27,10 @@ MecanumDrive::MecanumDrive(MotorController& frontLeftMotor,
[&](double output) { rearLeftMotor.Set(output); },
[&](double output) { frontRightMotor.Set(output); },
[&](double output) { rearRightMotor.Set(output); }} {
wpi::SendableRegistry::AddChild(this, &frontLeftMotor);
wpi::SendableRegistry::AddChild(this, &rearLeftMotor);
wpi::SendableRegistry::AddChild(this, &frontRightMotor);
wpi::SendableRegistry::AddChild(this, &rearRightMotor);
wpi::util::SendableRegistry::AddChild(this, &frontLeftMotor);
wpi::util::SendableRegistry::AddChild(this, &rearLeftMotor);
wpi::util::SendableRegistry::AddChild(this, &frontRightMotor);
wpi::util::SendableRegistry::AddChild(this, &rearRightMotor);
}
WPI_UNIGNORE_DEPRECATED
@@ -45,18 +45,18 @@ MecanumDrive::MecanumDrive(std::function<void(double)> frontLeftMotor,
m_rearRightMotor{std::move(rearRightMotor)} {
static int instances = 0;
++instances;
wpi::SendableRegistry::Add(this, "MecanumDrive", instances);
wpi::util::SendableRegistry::Add(this, "MecanumDrive", instances);
}
void MecanumDrive::DriveCartesian(double xSpeed, double ySpeed,
double zRotation, Rotation2d gyroAngle) {
double zRotation, wpi::math::Rotation2d gyroAngle) {
if (!reported) {
HAL_ReportUsage("RobotDrive", "MecanumCartesian");
reported = true;
}
xSpeed = ApplyDeadband(xSpeed, m_deadband);
ySpeed = ApplyDeadband(ySpeed, m_deadband);
xSpeed = wpi::math::ApplyDeadband(xSpeed, m_deadband);
ySpeed = wpi::math::ApplyDeadband(ySpeed, m_deadband);
auto [frontLeft, frontRight, rearLeft, rearRight] =
DriveCartesianIK(xSpeed, ySpeed, zRotation, gyroAngle);
@@ -74,7 +74,7 @@ void MecanumDrive::DriveCartesian(double xSpeed, double ySpeed,
Feed();
}
void MecanumDrive::DrivePolar(double magnitude, Rotation2d angle,
void MecanumDrive::DrivePolar(double magnitude, wpi::math::Rotation2d angle,
double zRotation) {
if (!reported) {
HAL_ReportUsage("RobotDrive", "MecanumPolar");
@@ -102,13 +102,13 @@ void MecanumDrive::StopMotor() {
MecanumDrive::WheelSpeeds MecanumDrive::DriveCartesianIK(double xSpeed,
double ySpeed,
double zRotation,
Rotation2d gyroAngle) {
wpi::math::Rotation2d gyroAngle) {
xSpeed = std::clamp(xSpeed, -1.0, 1.0);
ySpeed = std::clamp(ySpeed, -1.0, 1.0);
// Compensate for gyro angle.
auto input =
Translation2d{units::meter_t{xSpeed}, units::meter_t{ySpeed}}.RotateBy(
wpi::math::Translation2d{wpi::units::meter_t{xSpeed}, wpi::units::meter_t{ySpeed}}.RotateBy(
-gyroAngle);
double wheelSpeeds[4];
@@ -127,7 +127,7 @@ std::string MecanumDrive::GetDescription() const {
return "MecanumDrive";
}
void MecanumDrive::InitSendable(wpi::SendableBuilder& builder) {
void MecanumDrive::InitSendable(wpi::util::SendableBuilder& builder) {
builder.SetSmartDashboardType("MecanumDrive");
builder.SetActuator(true);
builder.AddDoubleProperty(

View File

@@ -10,7 +10,7 @@
#include "wpi/hardware/motor/MotorController.hpp"
using namespace frc;
using namespace wpi;
RobotDriveBase::RobotDriveBase() {
SetSafetyEnabled(true);

View File

@@ -6,7 +6,7 @@
#include "wpi/hal/DriverStation.h"
using namespace frc;
using namespace wpi;
DSControlWord::DSControlWord() {
HAL_GetControlWord(&m_controlWord);

View File

@@ -33,7 +33,7 @@
#include "wpi/util/mutex.hpp"
#include "wpi/util/timestamp.h"
using namespace frc;
using namespace wpi;
static constexpr int availableToCount(uint64_t available) {
return 64 - std::countl_zero(available);
@@ -45,10 +45,10 @@ namespace {
template <typename Topic>
class MatchDataSenderEntry {
public:
MatchDataSenderEntry(const std::shared_ptr<nt::NetworkTable>& table,
MatchDataSenderEntry(const std::shared_ptr<wpi::nt::NetworkTable>& table,
std::string_view key,
typename Topic::ParamType initialVal,
wpi::json topicProperties = wpi::json::object())
wpi::util::json topicProperties = wpi::util::json::object())
: publisher{Topic{table->GetTopic(key)}.PublishEx(Topic::kTypeString,
topicProperties)},
prevVal{initialVal} {
@@ -70,22 +70,22 @@ class MatchDataSenderEntry {
static constexpr std::string_view kSmartDashboardType = "FMSInfo";
struct MatchDataSender {
std::shared_ptr<nt::NetworkTable> table =
nt::NetworkTableInstance::GetDefault().GetTable("FMSInfo");
MatchDataSenderEntry<nt::StringTopic> typeMetaData{
std::shared_ptr<wpi::nt::NetworkTable> table =
wpi::nt::NetworkTableInstance::GetDefault().GetTable("FMSInfo");
MatchDataSenderEntry<wpi::nt::StringTopic> typeMetaData{
table,
".type",
kSmartDashboardType,
{{"SmartDashboard", kSmartDashboardType}}};
MatchDataSenderEntry<nt::StringTopic> gameSpecificMessage{
MatchDataSenderEntry<wpi::nt::StringTopic> gameSpecificMessage{
table, "GameSpecificMessage", ""};
MatchDataSenderEntry<nt::StringTopic> eventName{table, "EventName", ""};
MatchDataSenderEntry<nt::IntegerTopic> matchNumber{table, "MatchNumber", 0};
MatchDataSenderEntry<nt::IntegerTopic> replayNumber{table, "ReplayNumber", 0};
MatchDataSenderEntry<nt::IntegerTopic> matchType{table, "MatchType", 0};
MatchDataSenderEntry<nt::BooleanTopic> alliance{table, "IsRedAlliance", true};
MatchDataSenderEntry<nt::IntegerTopic> station{table, "StationNumber", 1};
MatchDataSenderEntry<nt::IntegerTopic> controlWord{table, "FMSControlData",
MatchDataSenderEntry<wpi::nt::StringTopic> eventName{table, "EventName", ""};
MatchDataSenderEntry<wpi::nt::IntegerTopic> matchNumber{table, "MatchNumber", 0};
MatchDataSenderEntry<wpi::nt::IntegerTopic> replayNumber{table, "ReplayNumber", 0};
MatchDataSenderEntry<wpi::nt::IntegerTopic> matchType{table, "MatchType", 0};
MatchDataSenderEntry<wpi::nt::BooleanTopic> alliance{table, "IsRedAlliance", true};
MatchDataSenderEntry<wpi::nt::IntegerTopic> station{table, "StationNumber", 1};
MatchDataSenderEntry<wpi::nt::IntegerTopic> controlWord{table, "FMSControlData",
0};
};
@@ -129,12 +129,12 @@ struct Instance {
Instance();
~Instance();
wpi::EventVector refreshEvents;
wpi::util::EventVector refreshEvents;
MatchDataSender matchDataSender;
std::atomic<DataLogSender*> dataLogSender{nullptr};
// Joystick button rising/falling edge flags
wpi::mutex buttonEdgeMutex;
wpi::util::mutex buttonEdgeMutex;
std::array<HAL_JoystickButtons, DriverStation::kJoystickPorts>
previousButtonStates;
std::array<uint32_t, DriverStation::kJoystickPorts> joystickButtonsPressed;
@@ -148,7 +148,7 @@ struct Instance {
bool userInTeleop = false;
bool userInTest = false;
units::second_t nextMessageTime = 0_s;
wpi::units::second_t nextMessageTime = 0_s;
};
} // namespace
@@ -624,9 +624,9 @@ std::optional<int> DriverStation::GetLocation() {
}
}
units::second_t DriverStation::GetMatchTime() {
wpi::units::second_t DriverStation::GetMatchTime() {
int32_t status = 0;
return units::second_t{HAL_GetMatchTime(&status)};
return wpi::units::second_t{HAL_GetMatchTime(&status)};
}
double DriverStation::GetBatteryVoltage() {
@@ -670,7 +670,7 @@ void DriverStation::RefreshData() {
SendMatchData();
if (auto sender = inst.dataLogSender.load()) {
sender->Send(wpi::Now());
sender->Send(wpi::util::Now());
}
}
@@ -706,7 +706,7 @@ void DriverStation::StartDataLog(wpi::log::DataLog& log, bool logJoysticks) {
if (oldSender) {
delete newSender; // already had a sender
} else {
newSender->Init(log, logJoysticks, wpi::Now());
newSender->Init(log, logJoysticks, wpi::util::Now());
}
}

View File

@@ -8,7 +8,7 @@
#include "wpi/hal/UsageReporting.h"
#include "wpi/util/sendable/SendableBuilder.hpp"
using namespace frc;
using namespace wpi;
Gamepad::Gamepad(int port) : GenericHID(port) {
HAL_ReportUsage("HID", port, "Gamepad");
@@ -484,7 +484,7 @@ bool Gamepad::GetButtonForSendable(int button) const {
.value_or(false);
}
void Gamepad::InitSendable(wpi::SendableBuilder& builder) {
void Gamepad::InitSendable(wpi::util::SendableBuilder& builder) {
builder.SetSmartDashboardType("HID");
builder.PublishConstString("ControllerType", "Gamepad");
builder.AddDoubleProperty(

View File

@@ -11,7 +11,7 @@
#include "wpi/hal/DriverStation.h"
#include "wpi/system/Errors.hpp"
using namespace frc;
using namespace wpi;
GenericHID::GenericHID(int port) {
if (port < 0 || port >= DriverStation::kJoystickPorts) {

View File

@@ -9,7 +9,7 @@
#include "wpi/event/BooleanEvent.hpp"
#include "wpi/hal/UsageReporting.h"
using namespace frc;
using namespace wpi;
Joystick::Joystick(int port) : GenericHID(port) {
m_axes[Axis::kX] = kDefaultXChannel;
@@ -117,7 +117,7 @@ double Joystick::GetMagnitude() const {
return std::hypot(GetX(), GetY());
}
units::radian_t Joystick::GetDirection() const {
wpi::units::radian_t Joystick::GetDirection() const {
// https://docs.wpilib.org/en/stable/docs/software/basic-programming/coordinate-system.html#joystick-and-controller-coordinate-system
// A positive rotation around the X axis moves the joystick right, and a
// positive rotation around the Y axis moves the joystick backward. When
@@ -126,5 +126,5 @@ units::radian_t Joystick::GetDirection() const {
//
// It's rotated 90 degrees CCW (y is negated and the arguments are reversed)
// so that 0 radians is forward.
return units::radian_t{std::atan2(GetX(), -GetY())};
return wpi::units::radian_t{std::atan2(GetX(), -GetY())};
}

View File

@@ -7,7 +7,7 @@
#include <memory>
#include <utility>
using namespace frc;
using namespace wpi;
BooleanEvent::BooleanEvent(EventLoop* loop, std::function<bool()> condition)
: m_loop(loop), m_signal(std::move(condition)) {
@@ -67,10 +67,10 @@ BooleanEvent BooleanEvent::Falling() {
});
}
BooleanEvent BooleanEvent::Debounce(units::second_t debounceTime,
frc::Debouncer::DebounceType type) {
BooleanEvent BooleanEvent::Debounce(wpi::units::second_t debounceTime,
wpi::math::Debouncer::DebounceType type) {
return BooleanEvent(
this->m_loop,
[debouncer = frc::Debouncer(debounceTime, type),
[debouncer = wpi::math::Debouncer(debounceTime, type),
state = m_state]() mutable { return debouncer.Calculate(*state); });
}

View File

@@ -8,7 +8,7 @@
#include "wpi/system/Errors.hpp"
using namespace frc;
using namespace wpi;
namespace {
struct RunningSetter {
@@ -22,7 +22,7 @@ struct RunningSetter {
EventLoop::EventLoop() {}
void EventLoop::Bind(wpi::unique_function<void()> action) {
void EventLoop::Bind(wpi::util::unique_function<void()> action) {
if (m_running) {
throw FRC_MakeError(err::Error,
"Cannot bind EventLoop while it is running");
@@ -32,7 +32,7 @@ void EventLoop::Bind(wpi::unique_function<void()> action) {
void EventLoop::Poll() {
RunningSetter runSetter{m_running};
for (wpi::unique_function<void()>& action : m_bindings) {
for (wpi::util::unique_function<void()>& action : m_bindings) {
action();
}
}

View File

@@ -11,33 +11,33 @@
#include "wpi/nt/NetworkTable.hpp"
#include "wpi/nt/NetworkTableInstance.hpp"
using namespace frc;
using namespace wpi;
NetworkBooleanEvent::NetworkBooleanEvent(EventLoop* loop,
nt::BooleanTopic topic)
wpi::nt::BooleanTopic topic)
: NetworkBooleanEvent{loop, topic.Subscribe(false)} {}
NetworkBooleanEvent::NetworkBooleanEvent(EventLoop* loop,
nt::BooleanSubscriber sub)
wpi::nt::BooleanSubscriber sub)
: BooleanEvent{
loop,
[sub = std::make_shared<nt::BooleanSubscriber>(std::move(sub))] {
[sub = std::make_shared<wpi::nt::BooleanSubscriber>(std::move(sub))] {
return sub->GetTopic().GetInstance().IsConnected() && sub->Get();
}} {}
NetworkBooleanEvent::NetworkBooleanEvent(
EventLoop* loop, std::shared_ptr<nt::NetworkTable> table,
EventLoop* loop, std::shared_ptr<wpi::nt::NetworkTable> table,
std::string_view topicName)
: NetworkBooleanEvent{loop, table->GetBooleanTopic(topicName)} {}
NetworkBooleanEvent::NetworkBooleanEvent(EventLoop* loop,
std::string_view tableName,
std::string_view topicName)
: NetworkBooleanEvent{loop, nt::NetworkTableInstance::GetDefault(),
: NetworkBooleanEvent{loop, wpi::nt::NetworkTableInstance::GetDefault(),
tableName, topicName} {}
NetworkBooleanEvent::NetworkBooleanEvent(EventLoop* loop,
nt::NetworkTableInstance inst,
wpi::nt::NetworkTableInstance inst,
std::string_view tableName,
std::string_view topicName)
: NetworkBooleanEvent{loop, inst.GetTable(tableName), topicName} {}

View File

@@ -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);

View File

@@ -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());
}

View File

@@ -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} {}

View File

@@ -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) {

View File

@@ -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");

View File

@@ -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);

View File

@@ -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);
}

View File

@@ -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(); },

View File

@@ -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}); });
}

View File

@@ -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};
}

View File

@@ -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);

View File

@@ -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);
}
}};

View File

@@ -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: {}",

View File

@@ -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);

View File

@@ -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";

View File

@@ -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();

View File

@@ -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) ==

View File

@@ -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();

View File

@@ -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(

View File

@@ -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

View File

@@ -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);

View File

@@ -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);

View File

@@ -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);
}

View File

@@ -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);

View File

@@ -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);

View File

@@ -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 {

View File

@@ -8,7 +8,7 @@
#include "wpi/hal/DriverStation.h"
#include "wpi/util/Synchronization.h"
using namespace frc::internal;
using namespace wpi::internal;
DriverStationModeThread::DriverStationModeThread() {
m_keepAlive = true;
@@ -39,13 +39,13 @@ void DriverStationModeThread::InTest(bool entering) {
}
void DriverStationModeThread::Run() {
wpi::Event event{false, false};
wpi::util::Event event{false, false};
HAL_ProvideNewDataEventHandle(event.GetHandle());
while (m_keepAlive.load()) {
bool timedOut = false;
wpi::WaitForObject(event.GetHandle(), 0.1, &timedOut);
frc::DriverStation::RefreshData();
wpi::util::WaitForObject(event.GetHandle(), 0.1, &timedOut);
wpi::DriverStation::RefreshData();
if (m_userInDisabled) {
HAL_ObserveUserProgramDisabled();
}

View File

@@ -6,9 +6,9 @@
#include "wpi/system/RobotController.hpp"
using namespace frc;
using namespace wpi;
void MotorController::SetVoltage(units::volt_t output) {
void MotorController::SetVoltage(wpi::units::volt_t output) {
// NOLINTNEXTLINE(bugprone-integer-division)
Set(output / RobotController::GetBatteryVoltage());
}

View File

@@ -10,7 +10,7 @@
#include "wpi/util/sendable/SendableBuilder.hpp"
#include "wpi/util/sendable/SendableRegistry.hpp"
using namespace frc;
using namespace wpi;
// Can't use a delegated constructor here because of an MSVC bug.
// https://developercommunity.visualstudio.com/content/problem/583/compiler-bug-with-delegating-a-constructor.html
@@ -25,11 +25,11 @@ MotorControllerGroup::MotorControllerGroup(
void MotorControllerGroup::Initialize() {
for (auto& motorController : m_motorControllers) {
wpi::SendableRegistry::AddChild(this, &motorController.get());
wpi::util::SendableRegistry::AddChild(this, &motorController.get());
}
static int instances = 0;
++instances;
wpi::SendableRegistry::Add(this, "MotorControllerGroup", instances);
wpi::util::SendableRegistry::Add(this, "MotorControllerGroup", instances);
}
void MotorControllerGroup::Set(double speed) {
@@ -38,7 +38,7 @@ void MotorControllerGroup::Set(double speed) {
}
}
void MotorControllerGroup::SetVoltage(units::volt_t output) {
void MotorControllerGroup::SetVoltage(wpi::units::volt_t output) {
for (auto motorController : m_motorControllers) {
motorController.get().SetVoltage(m_isInverted ? -output : output);
}
@@ -71,7 +71,7 @@ void MotorControllerGroup::StopMotor() {
}
}
void MotorControllerGroup::InitSendable(wpi::SendableBuilder& builder) {
void MotorControllerGroup::InitSendable(wpi::util::SendableBuilder& builder) {
builder.SetSmartDashboardType("Motor Controller");
builder.SetActuator(true);
builder.AddDoubleProperty(

View File

@@ -12,7 +12,7 @@
#include "wpi/util/sendable/SendableBuilder.hpp"
#include "wpi/util/sendable/SendableRegistry.hpp"
using namespace frc;
using namespace wpi;
void PWMMotorController::Set(double speed) {
if (m_isInverted) {
@@ -30,7 +30,7 @@ void PWMMotorController::Set(double speed) {
Feed();
}
void PWMMotorController::SetVoltage(units::volt_t output) {
void PWMMotorController::SetVoltage(wpi::units::volt_t output) {
// NOLINTNEXTLINE(bugprone-integer-division)
Set(output / RobotController::GetBatteryVoltage());
}
@@ -39,7 +39,7 @@ double PWMMotorController::Get() const {
return GetSpeed() * (m_isInverted ? -1.0 : 1.0);
}
units::volt_t PWMMotorController::GetVoltage() const {
wpi::units::volt_t PWMMotorController::GetVoltage() const {
return Get() * RobotController::GetBatteryVoltage();
}
@@ -98,9 +98,9 @@ WPI_IGNORE_DEPRECATED
PWMMotorController::PWMMotorController(std::string_view name, int channel)
: m_pwm(channel, false) {
wpi::SendableRegistry::Add(this, name, channel);
wpi::util::SendableRegistry::Add(this, name, channel);
m_simDevice = hal::SimDevice{"PWMMotorController", channel};
m_simDevice = wpi::hal::SimDevice{"PWMMotorController", channel};
if (m_simDevice) {
m_simSpeed = m_simDevice.CreateDouble("Speed", true, 0.0);
m_pwm.SetSimDevice(m_simDevice);
@@ -109,7 +109,7 @@ PWMMotorController::PWMMotorController(std::string_view name, int channel)
WPI_UNIGNORE_DEPRECATED
void PWMMotorController::InitSendable(wpi::SendableBuilder& builder) {
void PWMMotorController::InitSendable(wpi::util::SendableBuilder& builder) {
builder.SetSmartDashboardType("Motor Controller");
builder.SetActuator(true);
builder.AddDoubleProperty(
@@ -117,7 +117,7 @@ void PWMMotorController::InitSendable(wpi::SendableBuilder& builder) {
[=, this](double value) { Set(value); });
}
units::microsecond_t PWMMotorController::GetMinPositivePwm() const {
wpi::units::microsecond_t PWMMotorController::GetMinPositivePwm() const {
if (m_eliminateDeadband) {
return m_deadbandMaxPwm;
} else {
@@ -125,7 +125,7 @@ units::microsecond_t PWMMotorController::GetMinPositivePwm() const {
}
}
units::microsecond_t PWMMotorController::GetMaxNegativePwm() const {
wpi::units::microsecond_t PWMMotorController::GetMaxNegativePwm() const {
if (m_eliminateDeadband) {
return m_deadbandMinPwm;
} else {
@@ -133,11 +133,11 @@ units::microsecond_t PWMMotorController::GetMaxNegativePwm() const {
}
}
units::microsecond_t PWMMotorController::GetPositiveScaleFactor() const {
wpi::units::microsecond_t PWMMotorController::GetPositiveScaleFactor() const {
return m_maxPwm - GetMinPositivePwm();
}
units::microsecond_t PWMMotorController::GetNegativeScaleFactor() const {
wpi::units::microsecond_t PWMMotorController::GetNegativeScaleFactor() const {
return GetMaxNegativePwm() - m_minPwm;
}
@@ -152,15 +152,15 @@ void PWMMotorController::SetSpeed(double speed) {
m_simSpeed.Set(speed);
}
units::microsecond_t rawValue;
wpi::units::microsecond_t rawValue;
if (speed == 0.0) {
rawValue = m_centerPwm;
} else if (speed > 0.0) {
rawValue = units::microsecond_t{static_cast<double>(std::lround(
rawValue = wpi::units::microsecond_t{static_cast<double>(std::lround(
(speed * GetPositiveScaleFactor()).to<double>()))} +
GetMinPositivePwm();
} else {
rawValue = units::microsecond_t{static_cast<double>(std::lround(
rawValue = wpi::units::microsecond_t{static_cast<double>(std::lround(
(speed * GetNegativeScaleFactor()).to<double>()))} +
GetMaxNegativePwm();
}
@@ -169,7 +169,7 @@ void PWMMotorController::SetSpeed(double speed) {
}
double PWMMotorController::GetSpeed() const {
units::microsecond_t rawValue = m_pwm.GetPulseTime();
wpi::units::microsecond_t rawValue = m_pwm.GetPulseTime();
if (rawValue == 0_us) {
return 0.0;
@@ -188,11 +188,11 @@ double PWMMotorController::GetSpeed() const {
}
}
void PWMMotorController::SetBounds(units::microsecond_t maxPwm,
units::microsecond_t deadbandMaxPwm,
units::microsecond_t centerPwm,
units::microsecond_t deadbandMinPwm,
units::microsecond_t minPwm) {
void PWMMotorController::SetBounds(wpi::units::microsecond_t maxPwm,
wpi::units::microsecond_t deadbandMaxPwm,
wpi::units::microsecond_t centerPwm,
wpi::units::microsecond_t deadbandMinPwm,
wpi::units::microsecond_t minPwm) {
m_maxPwm = maxPwm;
m_deadbandMaxPwm = deadbandMaxPwm;
m_centerPwm = centerPwm;

View File

@@ -12,9 +12,9 @@
#include "wpi/system/Errors.hpp"
#include "wpi/util/print.hpp"
using namespace frc;
using namespace wpi;
IterativeRobotBase::IterativeRobotBase(units::second_t period)
IterativeRobotBase::IterativeRobotBase(wpi::units::second_t period)
: m_period(period),
m_watchdog(period, [this] { PrintLoopOverrunMessage(); }) {}
@@ -33,7 +33,7 @@ void IterativeRobotBase::TestInit() {}
void IterativeRobotBase::RobotPeriodic() {
static bool firstRun = true;
if (firstRun) {
wpi::print("Default {}() method... Override me!\n", __FUNCTION__);
wpi::util::print("Default {}() method... Override me!\n", __FUNCTION__);
firstRun = false;
}
}
@@ -41,7 +41,7 @@ void IterativeRobotBase::RobotPeriodic() {
void IterativeRobotBase::SimulationPeriodic() {
static bool firstRun = true;
if (firstRun) {
wpi::print("Default {}() method... Override me!\n", __FUNCTION__);
wpi::util::print("Default {}() method... Override me!\n", __FUNCTION__);
firstRun = false;
}
}
@@ -49,7 +49,7 @@ void IterativeRobotBase::SimulationPeriodic() {
void IterativeRobotBase::DisabledPeriodic() {
static bool firstRun = true;
if (firstRun) {
wpi::print("Default {}() method... Override me!\n", __FUNCTION__);
wpi::util::print("Default {}() method... Override me!\n", __FUNCTION__);
firstRun = false;
}
}
@@ -57,7 +57,7 @@ void IterativeRobotBase::DisabledPeriodic() {
void IterativeRobotBase::AutonomousPeriodic() {
static bool firstRun = true;
if (firstRun) {
wpi::print("Default {}() method... Override me!\n", __FUNCTION__);
wpi::util::print("Default {}() method... Override me!\n", __FUNCTION__);
firstRun = false;
}
}
@@ -65,7 +65,7 @@ void IterativeRobotBase::AutonomousPeriodic() {
void IterativeRobotBase::TeleopPeriodic() {
static bool firstRun = true;
if (firstRun) {
wpi::print("Default {}() method... Override me!\n", __FUNCTION__);
wpi::util::print("Default {}() method... Override me!\n", __FUNCTION__);
firstRun = false;
}
}
@@ -73,7 +73,7 @@ void IterativeRobotBase::TeleopPeriodic() {
void IterativeRobotBase::TestPeriodic() {
static bool firstRun = true;
if (firstRun) {
wpi::print("Default {}() method... Override me!\n", __FUNCTION__);
wpi::util::print("Default {}() method... Override me!\n", __FUNCTION__);
firstRun = false;
}
}
@@ -90,7 +90,7 @@ void IterativeRobotBase::SetNetworkTablesFlushEnabled(bool enabled) {
m_ntFlushEnabled = enabled;
}
units::second_t IterativeRobotBase::GetPeriod() const {
wpi::units::second_t IterativeRobotBase::GetPeriod() const {
return m_period;
}
@@ -183,7 +183,7 @@ void IterativeRobotBase::LoopFunc() {
// Flush NetworkTables
if (m_ntFlushEnabled) {
nt::NetworkTableInstance::GetDefault().FlushLocal();
wpi::nt::NetworkTableInstance::GetDefault().FlushLocal();
}
// Warn on loop time overruns

View File

@@ -6,7 +6,7 @@
#include "wpi/driverstation/DriverStation.hpp"
using namespace frc;
using namespace wpi;
bool RobotState::IsDisabled() {
return DriverStation::IsDisabled();

View File

@@ -14,7 +14,7 @@
#include "wpi/hal/UsageReporting.h"
#include "wpi/system/Errors.hpp"
using namespace frc;
using namespace wpi;
void TimedRobot::StartCompetition() {
if constexpr (IsSimulation()) {
@@ -75,7 +75,7 @@ void TimedRobot::EndCompetition() {
HAL_StopNotifier(m_notifier, &status);
}
TimedRobot::TimedRobot(units::second_t period) : IterativeRobotBase(period) {
TimedRobot::TimedRobot(wpi::units::second_t period) : IterativeRobotBase(period) {
m_startTime = std::chrono::microseconds{RobotController::GetFPGATime()};
AddPeriodic([=, this] { LoopFunc(); }, period);
@@ -87,7 +87,7 @@ TimedRobot::TimedRobot(units::second_t period) : IterativeRobotBase(period) {
HAL_ReportUsage("Framework", "TimedRobot");
}
TimedRobot::TimedRobot(units::hertz_t frequency) : TimedRobot{1 / frequency} {}
TimedRobot::TimedRobot(wpi::units::hertz_t frequency) : TimedRobot{1 / frequency} {}
TimedRobot::~TimedRobot() {
if (m_notifier != HAL_kInvalidHandle) {
@@ -102,7 +102,7 @@ uint64_t TimedRobot::GetLoopStartTime() {
}
void TimedRobot::AddPeriodic(std::function<void()> callback,
units::second_t period, units::second_t offset) {
wpi::units::second_t period, wpi::units::second_t offset) {
m_callbacks.emplace(
callback, m_startTime,
std::chrono::microseconds{static_cast<int64_t>(period.value() * 1e6)},

View File

@@ -6,15 +6,15 @@
#include "wpi/system/Errors.hpp"
using namespace frc;
using namespace wpi;
TimesliceRobot::TimesliceRobot(units::second_t robotPeriodicAllocation,
units::second_t controllerPeriod)
TimesliceRobot::TimesliceRobot(wpi::units::second_t robotPeriodicAllocation,
wpi::units::second_t controllerPeriod)
: m_nextOffset{robotPeriodicAllocation},
m_controllerPeriod{controllerPeriod} {}
void TimesliceRobot::Schedule(std::function<void()> func,
units::second_t allocation) {
wpi::units::second_t allocation) {
if (m_nextOffset + allocation > m_controllerPeriod) {
throw FRC_MakeError(err::Error,
"Function scheduled at offset {} with allocation {} "

View File

@@ -7,10 +7,10 @@
#include "wpi/hardware/accelerometer/ADXL345_I2C.hpp"
#include "wpi/simulation/SimDeviceSim.hpp"
using namespace frc::sim;
using namespace wpi::sim;
ADXL345Sim::ADXL345Sim(const frc::ADXL345_I2C& accel) {
frc::sim::SimDeviceSim deviceSim{"Accel:ADXL345_I2C", accel.GetI2CPort(),
ADXL345Sim::ADXL345Sim(const wpi::ADXL345_I2C& accel) {
wpi::sim::SimDeviceSim deviceSim{"Accel:ADXL345_I2C", accel.GetI2CPort(),
accel.GetI2CDeviceAddress()};
m_simX = deviceSim.GetDouble("x");
m_simY = deviceSim.GetDouble("y");

View File

@@ -10,8 +10,8 @@
#include "wpi/hal/simulation/AddressableLEDData.h"
#include "wpi/hardware/led/AddressableLED.hpp"
using namespace frc;
using namespace frc::sim;
using namespace wpi;
using namespace wpi::sim;
AddressableLEDSim::AddressableLEDSim(int channel) : m_channel{channel} {}

View File

@@ -7,10 +7,10 @@
#include "wpi/hardware/rotation/AnalogEncoder.hpp"
#include "wpi/simulation/SimDeviceSim.hpp"
using namespace frc::sim;
using namespace wpi::sim;
AnalogEncoderSim::AnalogEncoderSim(const frc::AnalogEncoder& encoder) {
frc::sim::SimDeviceSim deviceSim{"AnalogEncoder", encoder.GetChannel()};
AnalogEncoderSim::AnalogEncoderSim(const wpi::AnalogEncoder& encoder) {
wpi::sim::SimDeviceSim deviceSim{"AnalogEncoder", encoder.GetChannel()};
m_positionSim = deviceSim.GetDouble("Position");
}

View File

@@ -9,8 +9,8 @@
#include "wpi/hal/simulation/AnalogInData.h"
#include "wpi/hardware/discrete/AnalogInput.hpp"
using namespace frc;
using namespace frc::sim;
using namespace wpi;
using namespace wpi::sim;
AnalogInputSim::AnalogInputSim(const AnalogInput& analogInput)
: m_index{analogInput.GetChannel()} {}

View File

@@ -9,8 +9,8 @@
#include "wpi/hal/simulation/CTREPCMData.h"
#include "wpi/util/SensorUtil.hpp"
using namespace frc;
using namespace frc::sim;
using namespace wpi;
using namespace wpi::sim;
CTREPCMSim::CTREPCMSim()
: PneumaticsBaseSim{SensorUtil::GetDefaultCTREPCMModule()} {}

View File

@@ -6,15 +6,15 @@
#include <utility>
using namespace frc;
using namespace frc::sim;
using namespace wpi;
using namespace wpi::sim;
void frc::sim::CallbackStoreThunk(const char* name, void* param,
void wpi::sim::CallbackStoreThunk(const char* name, void* param,
const HAL_Value* value) {
reinterpret_cast<CallbackStore*>(param)->callback(name, value);
}
void frc::sim::ConstBufferCallbackStoreThunk(const char* name, void* param,
void wpi::sim::ConstBufferCallbackStoreThunk(const char* name, void* param,
const unsigned char* buffer,
unsigned int count) {
reinterpret_cast<CallbackStore*>(param)->constBufferCallback(name, buffer,

View File

@@ -7,11 +7,11 @@
#include "wpi/system/RobotController.hpp"
#include "wpi/util/MathExtras.hpp"
using namespace frc;
using namespace frc::sim;
using namespace wpi;
using namespace wpi::sim;
DCMotorSim::DCMotorSim(const LinearSystem<2, 1, 2>& plant,
const DCMotor& gearbox,
DCMotorSim::DCMotorSim(const wpi::math::LinearSystem<2, 1, 2>& plant,
const wpi::math::DCMotor& gearbox,
const std::array<double, 2>& measurementStdDevs)
: LinearSystemSim<2, 1, 2>(plant, measurementStdDevs),
m_gearbox(gearbox),
@@ -36,56 +36,56 @@ DCMotorSim::DCMotorSim(const LinearSystem<2, 1, 2>& plant,
m_j(m_gearing * gearbox.Kt.value() /
(gearbox.R.value() * m_plant.B(1, 0))) {}
void DCMotorSim::SetState(units::radian_t angularPosition,
units::radians_per_second_t angularVelocity) {
SetState(Vectord<2>{angularPosition, angularVelocity});
void DCMotorSim::SetState(wpi::units::radian_t angularPosition,
wpi::units::radians_per_second_t angularVelocity) {
SetState(wpi::math::Vectord<2>{angularPosition, angularVelocity});
}
void DCMotorSim::SetAngle(units::radian_t angularPosition) {
void DCMotorSim::SetAngle(wpi::units::radian_t angularPosition) {
SetState(angularPosition, GetAngularVelocity());
}
void DCMotorSim::SetAngularVelocity(
units::radians_per_second_t angularVelocity) {
wpi::units::radians_per_second_t angularVelocity) {
SetState(GetAngularPosition(), angularVelocity);
}
units::radian_t DCMotorSim::GetAngularPosition() const {
return units::radian_t{GetOutput(0)};
wpi::units::radian_t DCMotorSim::GetAngularPosition() const {
return wpi::units::radian_t{GetOutput(0)};
}
units::radians_per_second_t DCMotorSim::GetAngularVelocity() const {
return units::radians_per_second_t{GetOutput(1)};
wpi::units::radians_per_second_t DCMotorSim::GetAngularVelocity() const {
return wpi::units::radians_per_second_t{GetOutput(1)};
}
units::radians_per_second_squared_t DCMotorSim::GetAngularAcceleration() const {
return units::radians_per_second_squared_t{
wpi::units::radians_per_second_squared_t DCMotorSim::GetAngularAcceleration() const {
return wpi::units::radians_per_second_squared_t{
(m_plant.A() * m_x + m_plant.B() * m_u)(1, 0)};
}
units::newton_meter_t DCMotorSim::GetTorque() const {
return units::newton_meter_t{GetAngularAcceleration().value() * m_j.value()};
wpi::units::newton_meter_t DCMotorSim::GetTorque() const {
return wpi::units::newton_meter_t{GetAngularAcceleration().value() * m_j.value()};
}
units::ampere_t DCMotorSim::GetCurrentDraw() const {
wpi::units::ampere_t DCMotorSim::GetCurrentDraw() const {
// I = V / R - omega / (Kv * R)
// Reductions are greater than 1, so a reduction of 10:1 would mean the motor
// is spinning 10x faster than the output.
return m_gearbox.Current(units::radians_per_second_t{m_x(1)} * m_gearing,
units::volt_t{m_u(0)}) *
wpi::sgn(m_u(0));
return m_gearbox.Current(wpi::units::radians_per_second_t{m_x(1)} * m_gearing,
wpi::units::volt_t{m_u(0)}) *
wpi::util::sgn(m_u(0));
}
units::volt_t DCMotorSim::GetInputVoltage() const {
return units::volt_t{GetInput(0)};
wpi::units::volt_t DCMotorSim::GetInputVoltage() const {
return wpi::units::volt_t{GetInput(0)};
}
void DCMotorSim::SetInputVoltage(units::volt_t voltage) {
SetInput(Vectord<1>{voltage.value()});
ClampInput(frc::RobotController::GetBatteryVoltage().value());
void DCMotorSim::SetInputVoltage(wpi::units::volt_t voltage) {
SetInput(wpi::math::Vectord<1>{voltage.value()});
ClampInput(wpi::RobotController::GetBatteryVoltage().value());
}
const DCMotor& DCMotorSim::GetGearbox() const {
const wpi::math::DCMotor& DCMotorSim::GetGearbox() const {
return m_gearbox;
}
@@ -93,6 +93,6 @@ double DCMotorSim::GetGearing() const {
return m_gearing;
}
units::kilogram_square_meter_t DCMotorSim::GetJ() const {
wpi::units::kilogram_square_meter_t DCMotorSim::GetJ() const {
return m_j;
}

View File

@@ -10,8 +10,8 @@
#include "wpi/hardware/discrete/DigitalInput.hpp"
#include "wpi/hardware/discrete/DigitalOutput.hpp"
using namespace frc;
using namespace frc::sim;
using namespace wpi;
using namespace wpi::sim;
DIOSim::DIOSim(const DigitalInput& input) : m_index{input.GetChannel()} {}

View File

@@ -12,12 +12,12 @@
#include "wpi/system/RobotController.hpp"
#include "wpi/util/MathExtras.hpp"
using namespace frc;
using namespace frc::sim;
using namespace wpi;
using namespace wpi::sim;
DifferentialDrivetrainSim::DifferentialDrivetrainSim(
LinearSystem<2, 2, 2> plant, units::meter_t trackwidth, DCMotor driveMotor,
double gearRatio, units::meter_t wheelRadius,
wpi::math::LinearSystem<2, 2, 2> plant, wpi::units::meter_t trackwidth, wpi::math::DCMotor driveMotor,
double gearRatio, wpi::units::meter_t wheelRadius,
const std::array<double, 7>& measurementStdDevs)
: m_plant(std::move(plant)),
m_rb(trackwidth / 2.0),
@@ -32,22 +32,22 @@ DifferentialDrivetrainSim::DifferentialDrivetrainSim(
}
DifferentialDrivetrainSim::DifferentialDrivetrainSim(
frc::DCMotor driveMotor, double gearing, units::kilogram_square_meter_t J,
units::kilogram_t mass, units::meter_t wheelRadius,
units::meter_t trackwidth, const std::array<double, 7>& measurementStdDevs)
wpi::math::DCMotor driveMotor, double gearing, wpi::units::kilogram_square_meter_t J,
wpi::units::kilogram_t mass, wpi::units::meter_t wheelRadius,
wpi::units::meter_t trackwidth, const std::array<double, 7>& measurementStdDevs)
: DifferentialDrivetrainSim(
frc::LinearSystemId::DrivetrainVelocitySystem(
wpi::math::LinearSystemId::DrivetrainVelocitySystem(
driveMotor, mass, wheelRadius, trackwidth / 2.0, J, gearing),
trackwidth, driveMotor, gearing, wheelRadius, measurementStdDevs) {}
Eigen::Vector2d DifferentialDrivetrainSim::ClampInput(
const Eigen::Vector2d& u) {
return frc::DesaturateInputVector<2>(u,
frc::RobotController::GetInputVoltage());
return wpi::math::DesaturateInputVector<2>(u,
wpi::RobotController::GetInputVoltage());
}
void DifferentialDrivetrainSim::SetInputs(units::volt_t leftVoltage,
units::volt_t rightVoltage) {
void DifferentialDrivetrainSim::SetInputs(wpi::units::volt_t leftVoltage,
wpi::units::volt_t rightVoltage) {
m_u << leftVoltage.value(), rightVoltage.value();
m_u = ClampInput(m_u);
}
@@ -56,20 +56,20 @@ void DifferentialDrivetrainSim::SetGearing(double newGearing) {
m_currentGearing = newGearing;
}
void DifferentialDrivetrainSim::Update(units::second_t dt) {
m_x = RKDP([this](auto& x, auto& u) { return Dynamics(x, u); }, m_x, m_u, dt);
m_y = m_x + frc::MakeWhiteNoiseVector<7>(m_measurementStdDevs);
void DifferentialDrivetrainSim::Update(wpi::units::second_t dt) {
m_x = wpi::math::RKDP([this](auto& x, auto& u) { return Dynamics(x, u); }, m_x, m_u, dt);
m_y = m_x + wpi::math::MakeWhiteNoiseVector<7>(m_measurementStdDevs);
}
double DifferentialDrivetrainSim::GetGearing() const {
return m_currentGearing;
}
Vectord<7> DifferentialDrivetrainSim::GetOutput() const {
wpi::math::Vectord<7> DifferentialDrivetrainSim::GetOutput() const {
return m_y;
}
Vectord<7> DifferentialDrivetrainSim::GetState() const {
wpi::math::Vectord<7> DifferentialDrivetrainSim::GetState() const {
return m_x;
}
@@ -81,41 +81,41 @@ double DifferentialDrivetrainSim::GetState(int state) const {
return m_x(state);
}
Rotation2d DifferentialDrivetrainSim::GetHeading() const {
return units::radian_t{GetOutput(State::kHeading)};
wpi::math::Rotation2d DifferentialDrivetrainSim::GetHeading() const {
return wpi::units::radian_t{GetOutput(State::kHeading)};
}
Pose2d DifferentialDrivetrainSim::GetPose() const {
return Pose2d{units::meter_t{GetOutput(State::kX)},
units::meter_t{GetOutput(State::kY)}, GetHeading()};
wpi::math::Pose2d DifferentialDrivetrainSim::GetPose() const {
return wpi::math::Pose2d{wpi::units::meter_t{GetOutput(State::kX)},
wpi::units::meter_t{GetOutput(State::kY)}, GetHeading()};
}
units::ampere_t DifferentialDrivetrainSim::GetLeftCurrentDraw() const {
return m_motor.Current(units::radians_per_second_t{m_x(State::kLeftVelocity) *
wpi::units::ampere_t DifferentialDrivetrainSim::GetLeftCurrentDraw() const {
return m_motor.Current(wpi::units::radians_per_second_t{m_x(State::kLeftVelocity) *
m_currentGearing /
m_wheelRadius.value()},
units::volt_t{m_u(0)}) *
wpi::sgn(m_u(0));
wpi::units::volt_t{m_u(0)}) *
wpi::util::sgn(m_u(0));
}
units::ampere_t DifferentialDrivetrainSim::GetRightCurrentDraw() const {
wpi::units::ampere_t DifferentialDrivetrainSim::GetRightCurrentDraw() const {
return m_motor.Current(
units::radians_per_second_t{m_x(State::kRightVelocity) *
wpi::units::radians_per_second_t{m_x(State::kRightVelocity) *
m_currentGearing /
m_wheelRadius.value()},
units::volt_t{m_u(1)}) *
wpi::sgn(m_u(1));
wpi::units::volt_t{m_u(1)}) *
wpi::util::sgn(m_u(1));
}
units::ampere_t DifferentialDrivetrainSim::GetCurrentDraw() const {
wpi::units::ampere_t DifferentialDrivetrainSim::GetCurrentDraw() const {
return GetLeftCurrentDraw() + GetRightCurrentDraw();
}
void DifferentialDrivetrainSim::SetState(const Vectord<7>& state) {
void DifferentialDrivetrainSim::SetState(const wpi::math::Vectord<7>& state) {
m_x = state;
}
void DifferentialDrivetrainSim::SetPose(const frc::Pose2d& pose) {
void DifferentialDrivetrainSim::SetPose(const wpi::math::Pose2d& pose) {
m_x(State::kX) = pose.X().value();
m_x(State::kY) = pose.Y().value();
m_x(State::kHeading) = pose.Rotation().Radians().value();
@@ -123,19 +123,19 @@ void DifferentialDrivetrainSim::SetPose(const frc::Pose2d& pose) {
m_x(State::kRightPosition) = 0;
}
Vectord<7> DifferentialDrivetrainSim::Dynamics(const Vectord<7>& x,
wpi::math::Vectord<7> DifferentialDrivetrainSim::Dynamics(const wpi::math::Vectord<7>& x,
const Eigen::Vector2d& u) {
// Because G² can be factored out of A, we can divide by the old ratio
// squared and multiply by the new ratio squared to get a new drivetrain
// model.
Matrixd<4, 2> B;
wpi::math::Matrixd<4, 2> B;
B.block<2, 2>(0, 0) = m_plant.B() * m_currentGearing * m_currentGearing /
m_originalGearing / m_originalGearing;
B.block<2, 2>(2, 0).setZero();
// Because G can be factored out of B, we can divide by the old ratio and
// multiply by the new ratio to get a new drivetrain model.
Matrixd<4, 4> A;
wpi::math::Matrixd<4, 4> A;
A.block<2, 2>(0, 0) = m_plant.A() * m_currentGearing / m_originalGearing;
A.block<2, 2>(2, 0).setIdentity();
@@ -143,7 +143,7 @@ Vectord<7> DifferentialDrivetrainSim::Dynamics(const Vectord<7>& x,
double v = (x(State::kLeftVelocity) + x(State::kRightVelocity)) / 2.0;
Vectord<7> xdot;
wpi::math::Vectord<7> xdot;
xdot(0) = v * std::cos(x(State::kHeading));
xdot(1) = v * std::sin(x(State::kHeading));
xdot(2) =

View File

@@ -10,8 +10,8 @@
#include "wpi/hal/simulation/DigitalPWMData.h"
#include "wpi/hardware/discrete/DigitalOutput.hpp"
using namespace frc;
using namespace frc::sim;
using namespace wpi;
using namespace wpi::sim;
DigitalPWMSim::DigitalPWMSim(const DigitalOutput& digitalOutput)
: m_index{digitalOutput.GetChannel()} {}

View File

@@ -9,8 +9,8 @@
#include "wpi/hardware/pneumatic/PneumaticsBase.hpp"
using namespace frc;
using namespace frc::sim;
using namespace wpi;
using namespace wpi::sim;
DoubleSolenoidSim::DoubleSolenoidSim(
std::shared_ptr<PneumaticsBaseSim> moduleSim, int fwd, int rev)

View File

@@ -11,8 +11,8 @@
#include "wpi/hal/simulation/DriverStationData.h"
#include "wpi/hal/simulation/MockHooks.h"
using namespace frc;
using namespace frc::sim;
using namespace wpi;
using namespace wpi::sim;
std::unique_ptr<CallbackStore> DriverStationSim::RegisterEnabledCallback(
NotifyCallback callback, bool initialNotify) {
@@ -153,12 +153,12 @@ void DriverStationSim::SetMatchTime(double matchTime) {
}
void DriverStationSim::NotifyNewData() {
wpi::Event waitEvent{true};
wpi::util::Event waitEvent{true};
HAL_ProvideNewDataEventHandle(waitEvent.GetHandle());
HALSIM_NotifyDriverStationNewData();
wpi::WaitForObject(waitEvent.GetHandle());
wpi::util::WaitForObject(waitEvent.GetHandle());
HAL_RemoveNewDataEventHandle(waitEvent.GetHandle());
frc::DriverStation::RefreshData();
wpi::DriverStation::RefreshData();
}
void DriverStationSim::SetSendError(bool shouldSend) {
@@ -266,17 +266,17 @@ void DriverStationSim::SetJoystickType(int stick, int type) {
}
void DriverStationSim::SetJoystickName(int stick, std::string_view name) {
auto str = wpi::make_string(name);
auto str = wpi::util::make_string(name);
HALSIM_SetJoystickName(stick, &str);
}
void DriverStationSim::SetGameSpecificMessage(std::string_view message) {
auto str = wpi::make_string(message);
auto str = wpi::util::make_string(message);
HALSIM_SetGameSpecificMessage(&str);
}
void DriverStationSim::SetEventName(std::string_view name) {
auto str = wpi::make_string(name);
auto str = wpi::util::make_string(name);
HALSIM_SetEventName(&str);
}

View File

@@ -7,13 +7,13 @@
#include "wpi/hardware/rotation/DutyCycleEncoder.hpp"
#include "wpi/simulation/SimDeviceSim.hpp"
using namespace frc::sim;
using namespace wpi::sim;
DutyCycleEncoderSim::DutyCycleEncoderSim(const frc::DutyCycleEncoder& encoder)
DutyCycleEncoderSim::DutyCycleEncoderSim(const wpi::DutyCycleEncoder& encoder)
: DutyCycleEncoderSim{encoder.GetSourceChannel()} {}
DutyCycleEncoderSim::DutyCycleEncoderSim(int channel) {
frc::sim::SimDeviceSim deviceSim{"DutyCycle:DutyCycleEncoder", channel};
wpi::sim::SimDeviceSim deviceSim{"DutyCycle:DutyCycleEncoder", channel};
m_simPosition = deviceSim.GetDouble("Position");
m_simIsConnected = deviceSim.GetBoolean("Connected");
}

View File

@@ -10,8 +10,8 @@
#include "wpi/hal/simulation/DutyCycleData.h"
#include "wpi/hardware/rotation/DutyCycle.hpp"
using namespace frc;
using namespace frc::sim;
using namespace wpi;
using namespace wpi::sim;
DutyCycleSim::DutyCycleSim(const DutyCycle& dutyCycle)
: m_index{dutyCycle.GetSourceChannel()} {}
@@ -46,11 +46,11 @@ std::unique_ptr<CallbackStore> DutyCycleSim::RegisterFrequencyCallback(
return store;
}
units::hertz_t DutyCycleSim::GetFrequency() const {
return units::hertz_t{HALSIM_GetDutyCycleFrequency(m_index)};
wpi::units::hertz_t DutyCycleSim::GetFrequency() const {
return wpi::units::hertz_t{HALSIM_GetDutyCycleFrequency(m_index)};
}
void DutyCycleSim::SetFrequency(units::hertz_t frequency) {
void DutyCycleSim::SetFrequency(wpi::units::hertz_t frequency) {
HALSIM_SetDutyCycleFrequency(m_index, frequency.value());
}

View File

@@ -9,13 +9,13 @@
#include "wpi/system/RobotController.hpp"
#include "wpi/util/MathExtras.hpp"
using namespace frc;
using namespace frc::sim;
using namespace wpi;
using namespace wpi::sim;
ElevatorSim::ElevatorSim(const LinearSystem<2, 1, 2>& plant,
const DCMotor& gearbox, units::meter_t minHeight,
units::meter_t maxHeight, bool simulateGravity,
units::meter_t startingHeight,
ElevatorSim::ElevatorSim(const wpi::math::LinearSystem<2, 1, 2>& plant,
const wpi::math::DCMotor& gearbox, wpi::units::meter_t minHeight,
wpi::units::meter_t maxHeight, bool simulateGravity,
wpi::units::meter_t startingHeight,
const std::array<double, 2>& measurementStdDevs)
: LinearSystemSim(plant, measurementStdDevs),
m_gearbox(gearbox),
@@ -25,100 +25,100 @@ ElevatorSim::ElevatorSim(const LinearSystem<2, 1, 2>& plant,
SetState(startingHeight, 0_mps);
}
ElevatorSim::ElevatorSim(const DCMotor& gearbox, double gearing,
units::kilogram_t carriageMass,
units::meter_t drumRadius, units::meter_t minHeight,
units::meter_t maxHeight, bool simulateGravity,
units::meter_t startingHeight,
ElevatorSim::ElevatorSim(const wpi::math::DCMotor& gearbox, double gearing,
wpi::units::kilogram_t carriageMass,
wpi::units::meter_t drumRadius, wpi::units::meter_t minHeight,
wpi::units::meter_t maxHeight, bool simulateGravity,
wpi::units::meter_t startingHeight,
const std::array<double, 2>& measurementStdDevs)
: ElevatorSim(LinearSystemId::ElevatorSystem(gearbox, carriageMass,
: ElevatorSim(wpi::math::LinearSystemId::ElevatorSystem(gearbox, carriageMass,
drumRadius, gearing),
gearbox, minHeight, maxHeight, simulateGravity,
startingHeight, measurementStdDevs) {}
template <typename Distance>
requires std::same_as<units::meter, Distance> ||
std::same_as<units::radian, Distance>
requires std::same_as<wpi::units::meter, Distance> ||
std::same_as<wpi::units::radian, Distance>
ElevatorSim::ElevatorSim(decltype(1_V / Velocity_t<Distance>(1)) kV,
decltype(1_V / Acceleration_t<Distance>(1)) kA,
const DCMotor& gearbox, units::meter_t minHeight,
units::meter_t maxHeight, bool simulateGravity,
units::meter_t startingHeight,
const wpi::math::DCMotor& gearbox, wpi::units::meter_t minHeight,
wpi::units::meter_t maxHeight, bool simulateGravity,
wpi::units::meter_t startingHeight,
const std::array<double, 2>& measurementStdDevs)
: ElevatorSim(LinearSystemId::IdentifyPositionSystem(kV, kA), gearbox,
: ElevatorSim(wpi::math::LinearSystemId::IdentifyPositionSystem(kV, kA), gearbox,
minHeight, maxHeight, simulateGravity, startingHeight,
measurementStdDevs) {}
void ElevatorSim::SetState(units::meter_t position,
units::meters_per_second_t velocity) {
void ElevatorSim::SetState(wpi::units::meter_t position,
wpi::units::meters_per_second_t velocity) {
SetState(
Vectord<2>{std::clamp(position, m_minHeight, m_maxHeight), velocity});
wpi::math::Vectord<2>{std::clamp(position, m_minHeight, m_maxHeight), velocity});
}
bool ElevatorSim::WouldHitLowerLimit(units::meter_t elevatorHeight) const {
bool ElevatorSim::WouldHitLowerLimit(wpi::units::meter_t elevatorHeight) const {
return elevatorHeight <= m_minHeight;
}
bool ElevatorSim::WouldHitUpperLimit(units::meter_t elevatorHeight) const {
bool ElevatorSim::WouldHitUpperLimit(wpi::units::meter_t elevatorHeight) const {
return elevatorHeight >= m_maxHeight;
}
bool ElevatorSim::HasHitLowerLimit() const {
return WouldHitLowerLimit(units::meter_t{m_y(0)});
return WouldHitLowerLimit(wpi::units::meter_t{m_y(0)});
}
bool ElevatorSim::HasHitUpperLimit() const {
return WouldHitUpperLimit(units::meter_t{m_y(0)});
return WouldHitUpperLimit(wpi::units::meter_t{m_y(0)});
}
units::meter_t ElevatorSim::GetPosition() const {
return units::meter_t{m_y(0)};
wpi::units::meter_t ElevatorSim::GetPosition() const {
return wpi::units::meter_t{m_y(0)};
}
units::meters_per_second_t ElevatorSim::GetVelocity() const {
return units::meters_per_second_t{m_x(1)};
wpi::units::meters_per_second_t ElevatorSim::GetVelocity() const {
return wpi::units::meters_per_second_t{m_x(1)};
}
units::ampere_t ElevatorSim::GetCurrentDraw() const {
wpi::units::ampere_t ElevatorSim::GetCurrentDraw() const {
// I = V / R - omega / (Kv * R)
// Reductions are greater than 1, so a reduction of 10:1 would mean the motor
// is spinning 10x faster than the output.
double kA = 1.0 / m_plant.B(1, 0);
using Kv_t = units::unit_t<units::compound_unit<
units::volt, units::inverse<units::meters_per_second>>>;
using Kv_t = wpi::units::unit_t<wpi::units::compound_unit<
wpi::units::volt, wpi::units::inverse<wpi::units::meters_per_second>>>;
Kv_t Kv = Kv_t{kA * m_plant.A(1, 1)};
units::meters_per_second_t velocity{m_x(1)};
units::radians_per_second_t motorVelocity = velocity * Kv * m_gearbox.Kv;
wpi::units::meters_per_second_t velocity{m_x(1)};
wpi::units::radians_per_second_t motorVelocity = velocity * Kv * m_gearbox.Kv;
// Perform calculation and return.
return m_gearbox.Current(motorVelocity, units::volt_t{m_u(0)}) *
wpi::sgn(m_u(0));
return m_gearbox.Current(motorVelocity, wpi::units::volt_t{m_u(0)}) *
wpi::util::sgn(m_u(0));
}
void ElevatorSim::SetInputVoltage(units::volt_t voltage) {
SetInput(Vectord<1>{voltage.value()});
ClampInput(frc::RobotController::GetBatteryVoltage().value());
void ElevatorSim::SetInputVoltage(wpi::units::volt_t voltage) {
SetInput(wpi::math::Vectord<1>{voltage.value()});
ClampInput(wpi::RobotController::GetBatteryVoltage().value());
}
Vectord<2> ElevatorSim::UpdateX(const Vectord<2>& currentXhat,
const Vectord<1>& u, units::second_t dt) {
auto updatedXhat = RKDP(
[&](const Vectord<2>& x, const Vectord<1>& u_) -> Vectord<2> {
Vectord<2> xdot = m_plant.A() * x + m_plant.B() * u;
wpi::math::Vectord<2> ElevatorSim::UpdateX(const wpi::math::Vectord<2>& currentXhat,
const wpi::math::Vectord<1>& u, wpi::units::second_t dt) {
auto updatedXhat = wpi::math::RKDP(
[&](const wpi::math::Vectord<2>& x, const wpi::math::Vectord<1>& u_) -> wpi::math::Vectord<2> {
wpi::math::Vectord<2> xdot = m_plant.A() * x + m_plant.B() * u;
if (m_simulateGravity) {
xdot += Vectord<2>{0.0, -9.8};
xdot += wpi::math::Vectord<2>{0.0, -9.8};
}
return xdot;
},
currentXhat, u, dt);
// Check for collision after updating x-hat.
if (WouldHitLowerLimit(units::meter_t{updatedXhat(0)})) {
return Vectord<2>{m_minHeight.value(), 0.0};
if (WouldHitLowerLimit(wpi::units::meter_t{updatedXhat(0)})) {
return wpi::math::Vectord<2>{m_minHeight.value(), 0.0};
}
if (WouldHitUpperLimit(units::meter_t{updatedXhat(0)})) {
return Vectord<2>{m_maxHeight.value(), 0.0};
if (WouldHitUpperLimit(wpi::units::meter_t{updatedXhat(0)})) {
return wpi::math::Vectord<2>{m_maxHeight.value(), 0.0};
}
return updatedXhat;
}

View File

@@ -10,8 +10,8 @@
#include "wpi/hal/simulation/EncoderData.h"
#include "wpi/hardware/rotation/Encoder.hpp"
using namespace frc;
using namespace frc::sim;
using namespace wpi;
using namespace wpi::sim;
EncoderSim::EncoderSim(const Encoder& encoder)
: m_index{encoder.GetFPGAIndex()} {}

View File

@@ -7,11 +7,11 @@
#include "wpi/system/RobotController.hpp"
#include "wpi/util/MathExtras.hpp"
using namespace frc;
using namespace frc::sim;
using namespace wpi;
using namespace wpi::sim;
FlywheelSim::FlywheelSim(const LinearSystem<1, 1, 1>& plant,
const DCMotor& gearbox,
FlywheelSim::FlywheelSim(const wpi::math::LinearSystem<1, 1, 1>& plant,
const wpi::math::DCMotor& gearbox,
const std::array<double, 1>& measurementStdDevs)
: LinearSystemSim<1, 1, 1>(plant, measurementStdDevs),
m_gearbox(gearbox),
@@ -36,38 +36,38 @@ FlywheelSim::FlywheelSim(const LinearSystem<1, 1, 1>& plant,
m_j(m_gearing * gearbox.Kt.value() /
(gearbox.R.value() * m_plant.B(0, 0))) {}
void FlywheelSim::SetVelocity(units::radians_per_second_t velocity) {
LinearSystemSim::SetState(Vectord<1>{velocity.value()});
void FlywheelSim::SetVelocity(wpi::units::radians_per_second_t velocity) {
LinearSystemSim::SetState(wpi::math::Vectord<1>{velocity.value()});
}
units::radians_per_second_t FlywheelSim::GetAngularVelocity() const {
return units::radians_per_second_t{GetOutput(0)};
wpi::units::radians_per_second_t FlywheelSim::GetAngularVelocity() const {
return wpi::units::radians_per_second_t{GetOutput(0)};
}
units::radians_per_second_squared_t FlywheelSim::GetAngularAcceleration()
wpi::units::radians_per_second_squared_t FlywheelSim::GetAngularAcceleration()
const {
return units::radians_per_second_squared_t{
return wpi::units::radians_per_second_squared_t{
(m_plant.A() * m_x + m_plant.B() * m_u)(0, 0)};
}
units::newton_meter_t FlywheelSim::GetTorque() const {
return units::newton_meter_t{GetAngularAcceleration().value() * m_j.value()};
wpi::units::newton_meter_t FlywheelSim::GetTorque() const {
return wpi::units::newton_meter_t{GetAngularAcceleration().value() * m_j.value()};
}
units::ampere_t FlywheelSim::GetCurrentDraw() const {
wpi::units::ampere_t FlywheelSim::GetCurrentDraw() const {
// I = V / R - omega / (Kv * R)
// Reductions are greater than 1, so a reduction of 10:1 would mean the motor
// is spinning 10x faster than the output.
return m_gearbox.Current(units::radians_per_second_t{m_x(0)} * m_gearing,
units::volt_t{m_u(0)}) *
wpi::sgn(m_u(0));
return m_gearbox.Current(wpi::units::radians_per_second_t{m_x(0)} * m_gearing,
wpi::units::volt_t{m_u(0)}) *
wpi::util::sgn(m_u(0));
}
units::volt_t FlywheelSim::GetInputVoltage() const {
return units::volt_t{GetInput(0)};
wpi::units::volt_t FlywheelSim::GetInputVoltage() const {
return wpi::units::volt_t{GetInput(0)};
}
void FlywheelSim::SetInputVoltage(units::volt_t voltage) {
SetInput(Vectord<1>{voltage.value()});
ClampInput(frc::RobotController::GetBatteryVoltage().value());
void FlywheelSim::SetInputVoltage(wpi::units::volt_t voltage) {
SetInput(wpi::math::Vectord<1>{voltage.value()});
ClampInput(wpi::RobotController::GetBatteryVoltage().value());
}

View File

@@ -6,8 +6,8 @@
#include "wpi/driverstation/Gamepad.hpp"
using namespace frc;
using namespace frc::sim;
using namespace wpi;
using namespace wpi::sim;
GamepadSim::GamepadSim(const Gamepad& joystick) : GenericHIDSim{joystick} {
SetAxesMaximumIndex(6);

View File

@@ -8,8 +8,8 @@
#include "wpi/driverstation/GenericHID.hpp"
#include "wpi/simulation/DriverStationSim.hpp"
using namespace frc;
using namespace frc::sim;
using namespace wpi;
using namespace wpi::sim;
GenericHIDSim::GenericHIDSim(const GenericHID& joystick)
: m_port{joystick.GetPort()} {}

View File

@@ -7,8 +7,8 @@
#include "wpi/driverstation/Joystick.hpp"
#include "wpi/simulation/GenericHIDSim.hpp"
using namespace frc;
using namespace frc::sim;
using namespace wpi;
using namespace wpi::sim;
JoystickSim::JoystickSim(const Joystick& joystick)
: GenericHIDSim{joystick}, m_joystick{&joystick} {

View File

@@ -8,15 +8,15 @@
#include "wpi/simulation/SimDeviceSim.hpp"
#include "wpi/units/length.hpp"
using namespace frc;
using namespace frc::sim;
using namespace wpi;
using namespace wpi::sim;
PWMMotorControllerSim::PWMMotorControllerSim(
const PWMMotorController& motorctrl)
: PWMMotorControllerSim(motorctrl.GetChannel()) {}
PWMMotorControllerSim::PWMMotorControllerSim(int channel) {
frc::sim::SimDeviceSim deviceSim{"PWMMotorController", channel};
wpi::sim::SimDeviceSim deviceSim{"PWMMotorController", channel};
m_simSpeed = deviceSim.GetDouble("Speed");
}

View File

@@ -10,8 +10,8 @@
#include "wpi/hardware/discrete/PWM.hpp"
#include "wpi/hardware/motor/PWMMotorController.hpp"
using namespace frc;
using namespace frc::sim;
using namespace wpi;
using namespace wpi::sim;
PWMSim::PWMSim(const PWM& pwm) : m_index{pwm.GetChannel()} {}

View File

@@ -11,8 +11,8 @@
#include "wpi/simulation/REVPHSim.hpp"
#include "wpi/system/Errors.hpp"
using namespace frc;
using namespace frc::sim;
using namespace wpi;
using namespace wpi::sim;
std::shared_ptr<PneumaticsBaseSim> PneumaticsBaseSim::GetForType(
int module, PneumaticsModuleType type) {

View File

@@ -9,8 +9,8 @@
#include "wpi/hal/simulation/PowerDistributionData.h"
#include "wpi/hardware/power/PowerDistribution.hpp"
using namespace frc;
using namespace frc::sim;
using namespace wpi;
using namespace wpi::sim;
PowerDistributionSim::PowerDistributionSim(int module) : m_index{module} {}

View File

@@ -9,8 +9,8 @@
#include "wpi/hal/simulation/REVPHData.h"
#include "wpi/util/SensorUtil.hpp"
using namespace frc;
using namespace frc::sim;
using namespace wpi;
using namespace wpi::sim;
REVPHSim::REVPHSim() : PneumaticsBaseSim{SensorUtil::GetDefaultREVPHModule()} {}

View File

@@ -9,8 +9,8 @@
#include "wpi/hal/simulation/RoboRioData.h"
using namespace frc;
using namespace frc::sim;
using namespace wpi;
using namespace wpi::sim;
std::unique_ptr<CallbackStore> RoboRioSim::RegisterVInVoltageCallback(
NotifyCallback callback, bool initialNotify) {
@@ -21,11 +21,11 @@ std::unique_ptr<CallbackStore> RoboRioSim::RegisterVInVoltageCallback(
return store;
}
units::volt_t RoboRioSim::GetVInVoltage() {
return units::volt_t{HALSIM_GetRoboRioVInVoltage()};
wpi::units::volt_t RoboRioSim::GetVInVoltage() {
return wpi::units::volt_t{HALSIM_GetRoboRioVInVoltage()};
}
void RoboRioSim::SetVInVoltage(units::volt_t vInVoltage) {
void RoboRioSim::SetVInVoltage(wpi::units::volt_t vInVoltage) {
HALSIM_SetRoboRioVInVoltage(vInVoltage.value());
}
@@ -38,11 +38,11 @@ std::unique_ptr<CallbackStore> RoboRioSim::RegisterUserVoltage3V3Callback(
return store;
}
units::volt_t RoboRioSim::GetUserVoltage3V3() {
return units::volt_t{HALSIM_GetRoboRioUserVoltage3V3()};
wpi::units::volt_t RoboRioSim::GetUserVoltage3V3() {
return wpi::units::volt_t{HALSIM_GetRoboRioUserVoltage3V3()};
}
void RoboRioSim::SetUserVoltage3V3(units::volt_t userVoltage3V3) {
void RoboRioSim::SetUserVoltage3V3(wpi::units::volt_t userVoltage3V3) {
HALSIM_SetRoboRioUserVoltage3V3(userVoltage3V3.value());
}
@@ -55,11 +55,11 @@ std::unique_ptr<CallbackStore> RoboRioSim::RegisterUserCurrent3V3Callback(
return store;
}
units::ampere_t RoboRioSim::GetUserCurrent3V3() {
return units::ampere_t{HALSIM_GetRoboRioUserCurrent3V3()};
wpi::units::ampere_t RoboRioSim::GetUserCurrent3V3() {
return wpi::units::ampere_t{HALSIM_GetRoboRioUserCurrent3V3()};
}
void RoboRioSim::SetUserCurrent3V3(units::ampere_t userCurrent3V3) {
void RoboRioSim::SetUserCurrent3V3(wpi::units::ampere_t userCurrent3V3) {
HALSIM_SetRoboRioUserCurrent3V3(userCurrent3V3.value());
}
@@ -106,11 +106,11 @@ std::unique_ptr<CallbackStore> RoboRioSim::RegisterBrownoutVoltageCallback(
return store;
}
units::volt_t RoboRioSim::GetBrownoutVoltage() {
return units::volt_t{HALSIM_GetRoboRioBrownoutVoltage()};
wpi::units::volt_t RoboRioSim::GetBrownoutVoltage() {
return wpi::units::volt_t{HALSIM_GetRoboRioBrownoutVoltage()};
}
void RoboRioSim::SetBrownoutVoltage(units::volt_t vInVoltage) {
void RoboRioSim::SetBrownoutVoltage(wpi::units::volt_t vInVoltage) {
HALSIM_SetRoboRioBrownoutVoltage(vInVoltage.value());
}
@@ -123,11 +123,11 @@ std::unique_ptr<CallbackStore> RoboRioSim::RegisterCPUTempCallback(
return store;
}
units::celsius_t RoboRioSim::GetCPUTemp() {
return units::celsius_t{HALSIM_GetRoboRioCPUTemp()};
wpi::units::celsius_t RoboRioSim::GetCPUTemp() {
return wpi::units::celsius_t{HALSIM_GetRoboRioCPUTemp()};
}
void RoboRioSim::SetCPUTemp(units::celsius_t cpuTemp) {
void RoboRioSim::SetCPUTemp(wpi::units::celsius_t cpuTemp) {
HALSIM_SetRoboRioCPUTemp(cpuTemp.value());
}
@@ -151,26 +151,26 @@ void RoboRioSim::SetTeamNumber(int32_t teamNumber) {
std::string RoboRioSim::GetSerialNumber() {
WPI_String serialNum;
HALSIM_GetRoboRioSerialNumber(&serialNum);
std::string serial{wpi::to_string_view(&serialNum)};
std::string serial{wpi::util::to_string_view(&serialNum)};
WPI_FreeString(&serialNum);
return serial;
}
void RoboRioSim::SetSerialNumber(std::string_view serialNumber) {
auto str = wpi::make_string(serialNumber);
auto str = wpi::util::make_string(serialNumber);
HALSIM_SetRoboRioSerialNumber(&str);
}
std::string RoboRioSim::GetComments() {
WPI_String comments;
HALSIM_GetRoboRioComments(&comments);
std::string serial{wpi::to_string_view(&comments)};
std::string serial{wpi::util::to_string_view(&comments)};
WPI_FreeString(&comments);
return serial;
}
void RoboRioSim::SetComments(std::string_view comments) {
auto str = wpi::make_string(comments);
auto str = wpi::util::make_string(comments);
HALSIM_SetRoboRioComments(&str);
}

View File

@@ -4,12 +4,12 @@
#include "wpi/simulation/SendableChooserSim.hpp"
using namespace frc::sim;
using namespace wpi::sim;
SendableChooserSim::SendableChooserSim(std::string_view path)
: SendableChooserSim(nt::NetworkTableInstance::GetDefault(), path) {}
: SendableChooserSim(wpi::nt::NetworkTableInstance::GetDefault(), path) {}
SendableChooserSim::SendableChooserSim(nt::NetworkTableInstance inst,
SendableChooserSim::SendableChooserSim(wpi::nt::NetworkTableInstance inst,
std::string_view path) {
if constexpr (RobotBase::IsSimulation()) {
m_publisher =

View File

@@ -8,16 +8,16 @@
#include "wpi/simulation/SimDeviceSim.hpp"
#include "wpi/units/length.hpp"
using namespace frc;
using namespace wpi;
SharpIRSim::SharpIRSim(const SharpIR& sharpIR)
: SharpIRSim(sharpIR.GetChannel()) {}
SharpIRSim::SharpIRSim(int channel) {
frc::sim::SimDeviceSim deviceSim{"SharpIR", channel};
wpi::sim::SimDeviceSim deviceSim{"SharpIR", channel};
m_simRange = deviceSim.GetDouble("Range (m)");
}
void SharpIRSim::SetRange(units::meter_t range) {
void SharpIRSim::SetRange(wpi::units::meter_t range) {
m_simRange.Set(range.value());
}

View File

@@ -12,8 +12,8 @@
#include "wpi/hal/SimDevice.h"
#include "wpi/hal/simulation/SimDeviceData.h"
using namespace frc;
using namespace frc::sim;
using namespace wpi;
using namespace wpi::sim;
SimDeviceSim::SimDeviceSim(const char* name)
: m_handle{HALSIM_GetSimDeviceHandle(name)} {}

View File

@@ -6,7 +6,7 @@
#include "wpi/hal/simulation/MockHooks.h"
namespace frc::sim {
namespace wpi::sim {
void SetRuntimeType(HAL_RuntimeType type) {
HALSIM_SetRuntimeType(type);
@@ -40,12 +40,12 @@ bool IsTimingPaused() {
return HALSIM_IsTimingPaused();
}
void StepTiming(units::second_t delta) {
void StepTiming(wpi::units::second_t delta) {
HALSIM_StepTiming(static_cast<uint64_t>(delta.value() * 1e6));
}
void StepTimingAsync(units::second_t delta) {
void StepTimingAsync(wpi::units::second_t delta) {
HALSIM_StepTimingAsync(static_cast<uint64_t>(delta.value() * 1e6));
}
} // namespace frc::sim
} // namespace wpi::sim

View File

@@ -12,14 +12,14 @@
#include "wpi/units/voltage.hpp"
#include "wpi/util/MathExtras.hpp"
using namespace frc;
using namespace frc::sim;
using namespace wpi;
using namespace wpi::sim;
SingleJointedArmSim::SingleJointedArmSim(
const LinearSystem<2, 1, 2>& system, const DCMotor& gearbox, double gearing,
units::meter_t armLength, units::radian_t minAngle,
units::radian_t maxAngle, bool simulateGravity,
units::radian_t startingAngle,
const wpi::math::LinearSystem<2, 1, 2>& system, const wpi::math::DCMotor& gearbox, double gearing,
wpi::units::meter_t armLength, wpi::units::radian_t minAngle,
wpi::units::radian_t maxAngle, bool simulateGravity,
wpi::units::radian_t startingAngle,
const std::array<double, 2>& measurementStdDevs)
: LinearSystemSim<2, 1, 2>(system, measurementStdDevs),
m_armLen(armLength),
@@ -32,61 +32,61 @@ SingleJointedArmSim::SingleJointedArmSim(
}
SingleJointedArmSim::SingleJointedArmSim(
const DCMotor& gearbox, double gearing, units::kilogram_square_meter_t moi,
units::meter_t armLength, units::radian_t minAngle,
units::radian_t maxAngle, bool simulateGravity,
units::radian_t startingAngle,
const wpi::math::DCMotor& gearbox, double gearing, wpi::units::kilogram_square_meter_t moi,
wpi::units::meter_t armLength, wpi::units::radian_t minAngle,
wpi::units::radian_t maxAngle, bool simulateGravity,
wpi::units::radian_t startingAngle,
const std::array<double, 2>& measurementStdDevs)
: SingleJointedArmSim(
LinearSystemId::SingleJointedArmSystem(gearbox, moi, gearing),
wpi::math::LinearSystemId::SingleJointedArmSystem(gearbox, moi, gearing),
gearbox, gearing, armLength, minAngle, maxAngle, simulateGravity,
startingAngle, measurementStdDevs) {}
void SingleJointedArmSim::SetState(units::radian_t angle,
units::radians_per_second_t velocity) {
SetState(Vectord<2>{std::clamp(angle, m_minAngle, m_maxAngle), velocity});
void SingleJointedArmSim::SetState(wpi::units::radian_t angle,
wpi::units::radians_per_second_t velocity) {
SetState(wpi::math::Vectord<2>{std::clamp(angle, m_minAngle, m_maxAngle), velocity});
}
bool SingleJointedArmSim::WouldHitLowerLimit(units::radian_t armAngle) const {
bool SingleJointedArmSim::WouldHitLowerLimit(wpi::units::radian_t armAngle) const {
return armAngle <= m_minAngle;
}
bool SingleJointedArmSim::WouldHitUpperLimit(units::radian_t armAngle) const {
bool SingleJointedArmSim::WouldHitUpperLimit(wpi::units::radian_t armAngle) const {
return armAngle >= m_maxAngle;
}
bool SingleJointedArmSim::HasHitLowerLimit() const {
return WouldHitLowerLimit(units::radian_t{m_y(0)});
return WouldHitLowerLimit(wpi::units::radian_t{m_y(0)});
}
bool SingleJointedArmSim::HasHitUpperLimit() const {
return WouldHitUpperLimit(units::radian_t{m_y(0)});
return WouldHitUpperLimit(wpi::units::radian_t{m_y(0)});
}
units::radian_t SingleJointedArmSim::GetAngle() const {
return units::radian_t{m_y(0)};
wpi::units::radian_t SingleJointedArmSim::GetAngle() const {
return wpi::units::radian_t{m_y(0)};
}
units::radians_per_second_t SingleJointedArmSim::GetVelocity() const {
return units::radians_per_second_t{m_x(1)};
wpi::units::radians_per_second_t SingleJointedArmSim::GetVelocity() const {
return wpi::units::radians_per_second_t{m_x(1)};
}
units::ampere_t SingleJointedArmSim::GetCurrentDraw() const {
wpi::units::ampere_t SingleJointedArmSim::GetCurrentDraw() const {
// Reductions are greater than 1, so a reduction of 10:1 would mean the motor
// is spinning 10x faster than the output
units::radians_per_second_t motorVelocity{m_x(1) * m_gearing};
return m_gearbox.Current(motorVelocity, units::volt_t{m_u(0)}) *
wpi::sgn(m_u(0));
wpi::units::radians_per_second_t motorVelocity{m_x(1) * m_gearing};
return m_gearbox.Current(motorVelocity, wpi::units::volt_t{m_u(0)}) *
wpi::util::sgn(m_u(0));
}
void SingleJointedArmSim::SetInputVoltage(units::volt_t voltage) {
SetInput(Vectord<1>{voltage.value()});
ClampInput(frc::RobotController::GetBatteryVoltage().value());
void SingleJointedArmSim::SetInputVoltage(wpi::units::volt_t voltage) {
SetInput(wpi::math::Vectord<1>{voltage.value()});
ClampInput(wpi::RobotController::GetBatteryVoltage().value());
}
Vectord<2> SingleJointedArmSim::UpdateX(const Vectord<2>& currentXhat,
const Vectord<1>& u,
units::second_t dt) {
wpi::math::Vectord<2> SingleJointedArmSim::UpdateX(const wpi::math::Vectord<2>& currentXhat,
const wpi::math::Vectord<1>& u,
wpi::units::second_t dt) {
// The torque on the arm is given by τ = F⋅r, where F is the force applied by
// gravity and r the distance from pivot to center of mass. Recall from
// dynamics that the sum of torques for a rigid body is τ = J⋅α, were τ is
@@ -111,12 +111,12 @@ Vectord<2> SingleJointedArmSim::UpdateX(const Vectord<2>& currentXhat,
// f(x, u) = Ax + Bu + [0 α]ᵀ
// f(x, u) = Ax + Bu + [0 3/2⋅g⋅cos(θ)/L]ᵀ
Vectord<2> updatedXhat = RKDP(
[&](const auto& x, const auto& u) -> Vectord<2> {
Vectord<2> xdot = m_plant.A() * x + m_plant.B() * u;
wpi::math::Vectord<2> updatedXhat = wpi::math::RKDP(
[&](const auto& x, const auto& u) -> wpi::math::Vectord<2> {
wpi::math::Vectord<2> xdot = m_plant.A() * x + m_plant.B() * u;
if (m_simulateGravity) {
xdot += Vectord<2>{
xdot += wpi::math::Vectord<2>{
0.0, (3.0 / 2.0 * -9.8 / m_armLen * std::cos(x(0))).value()};
}
return xdot;
@@ -124,10 +124,10 @@ Vectord<2> SingleJointedArmSim::UpdateX(const Vectord<2>& currentXhat,
currentXhat, u, dt);
// Check for collisions.
if (WouldHitLowerLimit(units::radian_t{updatedXhat(0)})) {
return Vectord<2>{m_minAngle.value(), 0.0};
} else if (WouldHitUpperLimit(units::radian_t{updatedXhat(0)})) {
return Vectord<2>{m_maxAngle.value(), 0.0};
if (WouldHitLowerLimit(wpi::units::radian_t{updatedXhat(0)})) {
return wpi::math::Vectord<2>{m_minAngle.value(), 0.0};
} else if (WouldHitUpperLimit(wpi::units::radian_t{updatedXhat(0)})) {
return wpi::math::Vectord<2>{m_maxAngle.value(), 0.0};
}
return updatedXhat;
}

View File

@@ -9,8 +9,8 @@
#include "wpi/hardware/pneumatic/PneumaticsBase.hpp"
using namespace frc;
using namespace frc::sim;
using namespace wpi;
using namespace wpi::sim;
SolenoidSim::SolenoidSim(std::shared_ptr<PneumaticsBaseSim> moduleSim,
int channel)

View File

@@ -11,13 +11,13 @@
#include "wpi/nt/NTSendableBuilder.hpp"
#include "wpi/util/sendable/SendableRegistry.hpp"
using namespace frc;
using namespace wpi;
Field2d::Field2d() {
m_objects.emplace_back(
std::make_unique<FieldObject2d>("Robot", FieldObject2d::private_init{}));
m_objects[0]->SetPose(Pose2d{});
wpi::SendableRegistry::Add(this, "Field");
m_objects[0]->SetPose(wpi::math::Pose2d{});
wpi::util::SendableRegistry::Add(this, "Field");
}
Field2d::Field2d(Field2d&& rhs) : SendableHelper(std::move(rhs)) {
@@ -34,18 +34,18 @@ Field2d& Field2d::operator=(Field2d&& rhs) {
return *this;
}
void Field2d::SetRobotPose(const Pose2d& pose) {
void Field2d::SetRobotPose(const wpi::math::Pose2d& pose) {
std::scoped_lock lock(m_mutex);
m_objects[0]->SetPose(pose);
}
void Field2d::SetRobotPose(units::meter_t x, units::meter_t y,
Rotation2d rotation) {
void Field2d::SetRobotPose(wpi::units::meter_t x, wpi::units::meter_t y,
wpi::math::Rotation2d rotation) {
std::scoped_lock lock(m_mutex);
m_objects[0]->SetPose(x, y, rotation);
}
Pose2d Field2d::GetRobotPose() const {
wpi::math::Pose2d Field2d::GetRobotPose() const {
std::scoped_lock lock(m_mutex);
return m_objects[0]->GetPose();
}
@@ -71,7 +71,7 @@ FieldObject2d* Field2d::GetRobotObject() {
return m_objects[0].get();
}
void Field2d::InitSendable(nt::NTSendableBuilder& builder) {
void Field2d::InitSendable(wpi::nt::NTSendableBuilder& builder) {
builder.SetSmartDashboardType("Field2d");
std::scoped_lock lock(m_mutex);

View File

@@ -9,7 +9,7 @@
#include "wpi/math/trajectory/Trajectory.hpp"
using namespace frc;
using namespace wpi;
FieldObject2d::FieldObject2d(FieldObject2d&& rhs) {
std::swap(m_name, rhs.m_name);
@@ -25,16 +25,16 @@ FieldObject2d& FieldObject2d::operator=(FieldObject2d&& rhs) {
return *this;
}
void FieldObject2d::SetPose(const Pose2d& pose) {
void FieldObject2d::SetPose(const wpi::math::Pose2d& pose) {
SetPoses({pose});
}
void FieldObject2d::SetPose(units::meter_t x, units::meter_t y,
Rotation2d rotation) {
void FieldObject2d::SetPose(wpi::units::meter_t x, wpi::units::meter_t y,
wpi::math::Rotation2d rotation) {
SetPoses({{x, y, rotation}});
}
Pose2d FieldObject2d::GetPose() const {
wpi::math::Pose2d FieldObject2d::GetPose() const {
std::scoped_lock lock(m_mutex);
UpdateFromEntry();
if (m_poses.empty()) {
@@ -43,17 +43,17 @@ Pose2d FieldObject2d::GetPose() const {
return m_poses[0];
}
void FieldObject2d::SetPoses(std::span<const Pose2d> poses) {
void FieldObject2d::SetPoses(std::span<const wpi::math::Pose2d> poses) {
std::scoped_lock lock(m_mutex);
m_poses.assign(poses.begin(), poses.end());
UpdateEntry();
}
void FieldObject2d::SetPoses(std::initializer_list<Pose2d> poses) {
void FieldObject2d::SetPoses(std::initializer_list<wpi::math::Pose2d> poses) {
SetPoses({poses.begin(), poses.end()});
}
void FieldObject2d::SetTrajectory(const Trajectory& trajectory) {
void FieldObject2d::SetTrajectory(const wpi::math::Trajectory& trajectory) {
std::scoped_lock lock(m_mutex);
m_poses.clear();
m_poses.reserve(trajectory.States().size());
@@ -63,14 +63,14 @@ void FieldObject2d::SetTrajectory(const Trajectory& trajectory) {
UpdateEntry();
}
std::vector<Pose2d> FieldObject2d::GetPoses() const {
std::vector<wpi::math::Pose2d> FieldObject2d::GetPoses() const {
std::scoped_lock lock(m_mutex);
UpdateFromEntry();
return std::vector<Pose2d>(m_poses.begin(), m_poses.end());
return std::vector<wpi::math::Pose2d>(m_poses.begin(), m_poses.end());
}
std::span<const Pose2d> FieldObject2d::GetPoses(
wpi::SmallVectorImpl<Pose2d>& out) const {
std::span<const wpi::math::Pose2d> FieldObject2d::GetPoses(
wpi::util::SmallVectorImpl<wpi::math::Pose2d>& out) const {
std::scoped_lock lock(m_mutex);
UpdateFromEntry();
out.assign(m_poses.begin(), m_poses.end());
@@ -81,7 +81,7 @@ void FieldObject2d::UpdateEntry(bool setDefault) {
if (!m_entry) {
return;
}
wpi::SmallVector<double, 9> arr;
wpi::util::SmallVector<double, 9> arr;
for (auto&& pose : m_poses) {
auto& translation = pose.Translation();
arr.push_back(translation.X().value());
@@ -107,7 +107,7 @@ void FieldObject2d::UpdateFromEntry() const {
m_poses.resize(size / 3);
for (size_t i = 0; i < size / 3; ++i) {
m_poses[i] =
Pose2d{units::meter_t{arr[i * 3 + 0]}, units::meter_t{arr[i * 3 + 1]},
units::degree_t{arr[i * 3 + 2]}};
wpi::math::Pose2d{wpi::units::meter_t{arr[i * 3 + 0]}, wpi::units::meter_t{arr[i * 3 + 1]},
wpi::units::degree_t{arr[i * 3 + 2]}};
}
}

View File

@@ -6,7 +6,7 @@
#include <utility>
using namespace frc::detail;
using namespace wpi::detail;
void ListenerExecutor::Execute(std::function<void()> task) {
std::scoped_lock lock(m_lock);

View File

@@ -9,7 +9,7 @@
#include "wpi/nt/NTSendableBuilder.hpp"
using namespace frc;
using namespace wpi;
static constexpr std::string_view kBackgroundColor = "backgroundColor";
static constexpr std::string_view kDims = "dims";
@@ -37,7 +37,7 @@ void Mechanism2d::SetBackgroundColor(const Color8Bit& color) {
}
}
void Mechanism2d::InitSendable(nt::NTSendableBuilder& builder) {
void Mechanism2d::InitSendable(wpi::nt::NTSendableBuilder& builder) {
builder.SetSmartDashboardType("Mechanism2d");
std::scoped_lock lock(m_mutex);

View File

@@ -10,14 +10,14 @@
#include "wpi/util/StringExtras.hpp"
#include "wpi/util/json.hpp"
using namespace frc;
using namespace wpi;
static constexpr std::string_view kSmartDashboardType = "line";
MechanismLigament2d::MechanismLigament2d(std::string_view name, double length,
units::degree_t angle,
wpi::units::degree_t angle,
double lineWeight,
const frc::Color8Bit& color)
const wpi::Color8Bit& color)
: MechanismObject2d{name},
m_length{length},
m_angle{angle.value()},
@@ -26,9 +26,9 @@ MechanismLigament2d::MechanismLigament2d(std::string_view name, double length,
}
void MechanismLigament2d::UpdateEntries(
std::shared_ptr<nt::NetworkTable> table) {
std::shared_ptr<wpi::nt::NetworkTable> table) {
m_typePub = table->GetStringTopic(".type").PublishEx(
nt::StringTopic::kTypeString, {{"SmartDashboard", kSmartDashboardType}});
wpi::nt::StringTopic::kTypeString, {{"SmartDashboard", kSmartDashboardType}});
m_typePub.Set(kSmartDashboardType);
m_colorEntry = table->GetStringTopic("color").GetEntry("");
@@ -44,7 +44,7 @@ void MechanismLigament2d::UpdateEntries(
void MechanismLigament2d::SetColor(const Color8Bit& color) {
std::scoped_lock lock(m_mutex);
wpi::format_to_n_c_str(m_color, sizeof(m_color), "#{:02X}{:02X}{:02X}",
wpi::util::format_to_n_c_str(m_color, sizeof(m_color), "#{:02X}{:02X}{:02X}",
color.red, color.green, color.blue);
if (m_colorEntry) {
@@ -52,7 +52,7 @@ void MechanismLigament2d::SetColor(const Color8Bit& color) {
}
}
void MechanismLigament2d::SetAngle(units::degree_t angle) {
void MechanismLigament2d::SetAngle(wpi::units::degree_t angle) {
std::scoped_lock lock(m_mutex);
m_angle = angle.value();
if (m_angleEntry) {

View File

@@ -6,7 +6,7 @@
#include <string>
using namespace frc;
using namespace wpi;
MechanismObject2d::MechanismObject2d(std::string_view name) : m_name{name} {}
@@ -14,7 +14,7 @@ const std::string& MechanismObject2d::GetName() const {
return m_name;
}
void MechanismObject2d::Update(std::shared_ptr<nt::NetworkTable> table) {
void MechanismObject2d::Update(std::shared_ptr<wpi::nt::NetworkTable> table) {
std::scoped_lock lock(m_mutex);
m_table = table;
UpdateEntries(m_table);

View File

@@ -6,7 +6,7 @@
#include "wpi/util/Color8Bit.hpp"
using namespace frc;
using namespace wpi;
MechanismRoot2d::MechanismRoot2d(std::string_view name, double x, double y,
const private_init&)
@@ -19,7 +19,7 @@ void MechanismRoot2d::SetPosition(double x, double y) {
Flush();
}
void MechanismRoot2d::UpdateEntries(std::shared_ptr<nt::NetworkTable> table) {
void MechanismRoot2d::UpdateEntries(std::shared_ptr<wpi::nt::NetworkTable> table) {
m_xPub = table->GetDoubleTopic("x").Publish();
m_yPub = table->GetDoubleTopic("y").Publish();
Flush();

View File

@@ -22,7 +22,7 @@
#include "wpi/util/SmallVector.hpp"
#include "wpi/util/json.hpp"
using namespace frc;
using namespace wpi;
template <typename Topic>
void SendableBuilderImpl::PropertyImpl<Topic>::Update(bool controllable,
@@ -35,13 +35,13 @@ void SendableBuilderImpl::PropertyImpl<Topic>::Update(bool controllable,
}
}
void SendableBuilderImpl::SetTable(std::shared_ptr<nt::NetworkTable> table) {
void SendableBuilderImpl::SetTable(std::shared_ptr<wpi::nt::NetworkTable> table) {
m_table = table;
m_controllablePublisher = table->GetBooleanTopic(".controllable").Publish();
m_controllablePublisher.SetDefault(false);
}
std::shared_ptr<nt::NetworkTable> SendableBuilderImpl::GetTable() {
std::shared_ptr<wpi::nt::NetworkTable> SendableBuilderImpl::GetTable() {
return m_table;
}
@@ -54,7 +54,7 @@ bool SendableBuilderImpl::IsActuator() const {
}
void SendableBuilderImpl::Update() {
uint64_t time = nt::Now();
uint64_t time = wpi::nt::Now();
for (auto& property : m_properties) {
property->Update(m_controllable, time);
}
@@ -84,7 +84,7 @@ void SendableBuilderImpl::ClearProperties() {
void SendableBuilderImpl::SetSmartDashboardType(std::string_view type) {
if (!m_typePublisher) {
m_typePublisher = m_table->GetStringTopic(".type").PublishEx(
nt::StringTopic::kTypeString, {{"SmartDashboard", type}});
wpi::nt::StringTopic::kTypeString, {{"SmartDashboard", type}});
}
m_typePublisher.Set(type);
}
@@ -97,11 +97,11 @@ void SendableBuilderImpl::SetActuator(bool value) {
m_actuator = value;
}
void SendableBuilderImpl::SetUpdateTable(wpi::unique_function<void()> func) {
void SendableBuilderImpl::SetUpdateTable(wpi::util::unique_function<void()> func) {
m_updateTables.emplace_back(std::move(func));
}
nt::Topic SendableBuilderImpl::GetTopic(std::string_view key) {
wpi::nt::Topic SendableBuilderImpl::GetTopic(std::string_view key) {
return m_table->GetTopic(key);
}
@@ -259,7 +259,7 @@ void SendableBuilderImpl::AddRawProperty(
std::function<std::vector<uint8_t>()> getter,
std::function<void(std::span<const uint8_t>)> setter) {
auto topic = m_table->GetRawTopic(key);
auto prop = std::make_unique<PropertyImpl<nt::RawTopic>>();
auto prop = std::make_unique<PropertyImpl<wpi::nt::RawTopic>>();
if (getter) {
prop->pub = topic.Publish(typeString);
prop->updateNetwork = [=](auto& pub, int64_t time) {
@@ -282,7 +282,7 @@ void SendableBuilderImpl::PublishConstRaw(std::string_view key,
std::string_view typeString,
std::span<const uint8_t> value) {
auto topic = m_table->GetRawTopic(key);
auto prop = std::make_unique<PropertyImpl<nt::RawTopic>>();
auto prop = std::make_unique<PropertyImpl<wpi::nt::RawTopic>>();
prop->pub = topic.Publish(typeString);
prop->pub.Set(value);
m_properties.emplace_back(std::move(prop));
@@ -296,7 +296,7 @@ void SendableBuilderImpl::AddSmallPropertyImpl(Topic topic, Getter getter,
if (getter) {
prop->pub = topic.Publish();
prop->updateNetwork = [=](auto& pub, int64_t time) {
wpi::SmallVector<T, Size> buf;
wpi::util::SmallVector<T, Size> buf;
pub.Set(getter(buf), time);
};
}
@@ -314,7 +314,7 @@ void SendableBuilderImpl::AddSmallPropertyImpl(Topic topic, Getter getter,
void SendableBuilderImpl::AddSmallStringProperty(
std::string_view key,
std::function<std::string_view(wpi::SmallVectorImpl<char>& buf)> getter,
std::function<std::string_view(wpi::util::SmallVectorImpl<char>& buf)> getter,
std::function<void(std::string_view)> setter) {
AddSmallPropertyImpl<char, 128>(m_table->GetStringTopic(key),
std::move(getter), std::move(setter));
@@ -322,7 +322,7 @@ void SendableBuilderImpl::AddSmallStringProperty(
void SendableBuilderImpl::AddSmallBooleanArrayProperty(
std::string_view key,
std::function<std::span<const int>(wpi::SmallVectorImpl<int>& buf)> getter,
std::function<std::span<const int>(wpi::util::SmallVectorImpl<int>& buf)> getter,
std::function<void(std::span<const int>)> setter) {
AddSmallPropertyImpl<int, 16>(m_table->GetBooleanArrayTopic(key),
std::move(getter), std::move(setter));
@@ -330,7 +330,7 @@ void SendableBuilderImpl::AddSmallBooleanArrayProperty(
void SendableBuilderImpl::AddSmallIntegerArrayProperty(
std::string_view key,
std::function<std::span<const int64_t>(wpi::SmallVectorImpl<int64_t>& buf)>
std::function<std::span<const int64_t>(wpi::util::SmallVectorImpl<int64_t>& buf)>
getter,
std::function<void(std::span<const int64_t>)> setter) {
AddSmallPropertyImpl<int64_t, 16>(m_table->GetIntegerArrayTopic(key),
@@ -339,7 +339,7 @@ void SendableBuilderImpl::AddSmallIntegerArrayProperty(
void SendableBuilderImpl::AddSmallFloatArrayProperty(
std::string_view key,
std::function<std::span<const float>(wpi::SmallVectorImpl<float>& buf)>
std::function<std::span<const float>(wpi::util::SmallVectorImpl<float>& buf)>
getter,
std::function<void(std::span<const float>)> setter) {
AddSmallPropertyImpl<float, 16>(m_table->GetFloatArrayTopic(key),
@@ -348,7 +348,7 @@ void SendableBuilderImpl::AddSmallFloatArrayProperty(
void SendableBuilderImpl::AddSmallDoubleArrayProperty(
std::string_view key,
std::function<std::span<const double>(wpi::SmallVectorImpl<double>& buf)>
std::function<std::span<const double>(wpi::util::SmallVectorImpl<double>& buf)>
getter,
std::function<void(std::span<const double>)> setter) {
AddSmallPropertyImpl<double, 16>(m_table->GetDoubleArrayTopic(key),
@@ -358,7 +358,7 @@ void SendableBuilderImpl::AddSmallDoubleArrayProperty(
void SendableBuilderImpl::AddSmallStringArrayProperty(
std::string_view key,
std::function<
std::span<const std::string>(wpi::SmallVectorImpl<std::string>& buf)>
std::span<const std::string>(wpi::util::SmallVectorImpl<std::string>& buf)>
getter,
std::function<void(std::span<const std::string>)> setter) {
AddSmallPropertyImpl<std::string, 16>(m_table->GetStringArrayTopic(key),
@@ -367,15 +367,15 @@ void SendableBuilderImpl::AddSmallStringArrayProperty(
void SendableBuilderImpl::AddSmallRawProperty(
std::string_view key, std::string_view typeString,
std::function<std::span<uint8_t>(wpi::SmallVectorImpl<uint8_t>& buf)>
std::function<std::span<uint8_t>(wpi::util::SmallVectorImpl<uint8_t>& buf)>
getter,
std::function<void(std::span<const uint8_t>)> setter) {
auto topic = m_table->GetRawTopic(key);
auto prop = std::make_unique<PropertyImpl<nt::RawTopic>>();
auto prop = std::make_unique<PropertyImpl<wpi::nt::RawTopic>>();
if (getter) {
prop->pub = topic.Publish(typeString);
prop->updateNetwork = [=](auto& pub, int64_t time) {
wpi::SmallVector<uint8_t, 128> buf;
wpi::util::SmallVector<uint8_t, 128> buf;
pub.Set(getter(buf), time);
};
}

View File

@@ -8,12 +8,12 @@
#include "wpi/util/sendable/SendableRegistry.hpp"
using namespace frc;
using namespace wpi;
std::atomic_int SendableChooserBase::s_instances{0};
SendableChooserBase::SendableChooserBase() : m_instance{s_instances++} {
wpi::SendableRegistry::Add(this, "SendableChooser", m_instance);
wpi::util::SendableRegistry::Add(this, "SendableChooser", m_instance);
}
SendableChooserBase::SendableChooserBase(SendableChooserBase&& oth)

View File

@@ -19,15 +19,15 @@
#include "wpi/util/mutex.hpp"
#include "wpi/util/sendable/SendableRegistry.hpp"
using namespace frc;
using namespace wpi;
namespace {
struct Instance {
detail::ListenerExecutor listenerExecutor;
std::shared_ptr<nt::NetworkTable> table =
nt::NetworkTableInstance::GetDefault().GetTable("SmartDashboard");
wpi::StringMap<wpi::SendableRegistry::UID> tablesToData;
wpi::mutex tablesToDataMutex;
std::shared_ptr<wpi::nt::NetworkTable> table =
wpi::nt::NetworkTableInstance::GetDefault().GetTable("SmartDashboard");
wpi::util::StringMap<wpi::util::SendableRegistry::UID> tablesToData;
wpi::util::mutex tablesToDataMutex;
};
} // namespace
@@ -41,11 +41,11 @@ static Instance& GetInstance() {
}
#ifndef __FRC_SYSTEMCORE__
namespace frc::impl {
namespace wpi::impl {
void ResetSmartDashboardInstance() {
std::make_unique<Instance>().swap(GetInstanceHolder());
}
} // namespace frc::impl
} // namespace wpi::impl
#endif
static bool gReported = false;
@@ -74,7 +74,7 @@ bool SmartDashboard::IsPersistent(std::string_view key) {
return GetEntry(key).IsPersistent();
}
nt::NetworkTableEntry SmartDashboard::GetEntry(std::string_view key) {
wpi::nt::NetworkTableEntry SmartDashboard::GetEntry(std::string_view key) {
if (!gReported) {
HAL_ReportUsage("SmartDashboard", "");
gReported = true;
@@ -82,7 +82,7 @@ nt::NetworkTableEntry SmartDashboard::GetEntry(std::string_view key) {
return GetInstance().table->GetEntry(key);
}
void SmartDashboard::PutData(std::string_view key, wpi::Sendable* data) {
void SmartDashboard::PutData(std::string_view key, wpi::util::Sendable* data) {
if (!data) {
throw FRC_MakeError(err::NullParameter, "value");
}
@@ -93,37 +93,37 @@ void SmartDashboard::PutData(std::string_view key, wpi::Sendable* data) {
auto& inst = GetInstance();
std::scoped_lock lock(inst.tablesToDataMutex);
auto& uid = inst.tablesToData[key];
wpi::Sendable* sddata = wpi::SendableRegistry::GetSendable(uid);
wpi::util::Sendable* sddata = wpi::util::SendableRegistry::GetSendable(uid);
if (sddata != data) {
uid = wpi::SendableRegistry::GetUniqueId(data);
uid = wpi::util::SendableRegistry::GetUniqueId(data);
auto dataTable = inst.table->GetSubTable(key);
auto builder = std::make_unique<SendableBuilderImpl>();
auto builderPtr = builder.get();
builderPtr->SetTable(dataTable);
wpi::SendableRegistry::Publish(uid, std::move(builder));
wpi::util::SendableRegistry::Publish(uid, std::move(builder));
builderPtr->StartListeners();
dataTable->GetEntry(".name").SetString(key);
}
}
void SmartDashboard::PutData(wpi::Sendable* value) {
void SmartDashboard::PutData(wpi::util::Sendable* value) {
if (!value) {
throw FRC_MakeError(err::NullParameter, "value");
}
auto name = wpi::SendableRegistry::GetName(value);
auto name = wpi::util::SendableRegistry::GetName(value);
if (!name.empty()) {
PutData(name, value);
}
}
wpi::Sendable* SmartDashboard::GetData(std::string_view key) {
wpi::util::Sendable* SmartDashboard::GetData(std::string_view key) {
auto& inst = GetInstance();
std::scoped_lock lock(inst.tablesToDataMutex);
auto it = inst.tablesToData.find(key);
if (it == inst.tablesToData.end()) {
throw FRC_MakeError(err::SmartDashboardMissingKey, "{}", key);
}
return wpi::SendableRegistry::GetSendable(it->second);
return wpi::util::SendableRegistry::GetSendable(it->second);
}
bool SmartDashboard::PutBoolean(std::string_view keyName, bool value) {
@@ -229,16 +229,16 @@ std::vector<uint8_t> SmartDashboard::GetRaw(
}
bool SmartDashboard::PutValue(std::string_view keyName,
const nt::Value& value) {
const wpi::nt::Value& value) {
return GetInstance().table->GetEntry(keyName).SetValue(value);
}
bool SmartDashboard::SetDefaultValue(std::string_view key,
const nt::Value& defaultValue) {
const wpi::nt::Value& defaultValue) {
return GetEntry(key).SetDefaultValue(defaultValue);
}
nt::Value SmartDashboard::GetValue(std::string_view keyName) {
wpi::nt::Value SmartDashboard::GetValue(std::string_view keyName) {
return GetInstance().table->GetEntry(keyName).GetValue();
}
@@ -251,6 +251,6 @@ void SmartDashboard::UpdateValues() {
inst.listenerExecutor.RunListenerTasks();
std::scoped_lock lock(inst.tablesToDataMutex);
for (auto& i : inst.tablesToData) {
wpi::SendableRegistry::Update(i.second);
wpi::util::SendableRegistry::Update(i.second);
}
}

View File

@@ -10,7 +10,7 @@
#include "wpi/system/DataLogManager.hpp"
using namespace frc::sysid;
using namespace wpi::sysid;
SysIdRoutineLog::SysIdRoutineLog(std::string_view logName)
: m_logName(logName) {}
@@ -27,7 +27,7 @@ SysIdRoutineLog::MotorLog& SysIdRoutineLog::MotorLog::value(
auto& motorEntries = (*m_logEntries)[m_motorName];
if (!motorEntries.contains(name)) {
wpi::log::DataLog& log = frc::DataLogManager::GetLog();
wpi::log::DataLog& log = wpi::DataLogManager::GetLog();
motorEntries[name] = wpi::log::DoubleLogEntry(
log, fmt::format("{}-{}-{}", name, m_motorName, m_logName), unit);
@@ -44,7 +44,7 @@ SysIdRoutineLog::MotorLog SysIdRoutineLog::Motor(std::string_view motorName) {
void SysIdRoutineLog::RecordState(State state) {
if (!m_stateInitialized) {
m_state =
wpi::log::StringLogEntry{frc::DataLogManager::GetLog(),
wpi::log::StringLogEntry{wpi::DataLogManager::GetLog(),
fmt::format("sysid-test-state-{}", m_logName)};
m_stateInitialized = true;
}

View File

@@ -28,11 +28,11 @@
#include "wpi/util/print.hpp"
#include "wpi/util/timestamp.h"
using namespace frc;
using namespace wpi;
namespace {
struct Thread final : public wpi::SafeThread {
struct Thread final : public wpi::util::SafeThread {
Thread(std::string_view dir, std::string_view filename, double period);
~Thread() override;
@@ -56,7 +56,7 @@ struct Thread final : public wpi::SafeThread {
struct Instance {
Instance(std::string_view dir, std::string_view filename, double period);
wpi::SafeThreadOwner<Thread> owner;
wpi::util::SafeThreadOwner<Thread> owner;
};
} // namespace
@@ -138,9 +138,9 @@ void Thread::Main() {
std::vector<fs::directory_entry> entries;
for (auto&& entry : fs::directory_iterator{m_logDir, ec}) {
auto stem = entry.path().stem().string();
if (wpi::starts_with(stem, "FRC_") &&
if (wpi::util::starts_with(stem, "FRC_") &&
entry.path().extension() == ".wpilog" &&
!wpi::starts_with(stem, "FRC_TBD_")) {
!wpi::util::starts_with(stem, "FRC_TBD_")) {
entries.emplace_back(entry);
}
}
@@ -164,7 +164,7 @@ void Thread::Main() {
break;
}
} else {
wpi::print(stderr, "DataLogManager: could not delete {}\n",
wpi::util::print(stderr, "DataLogManager: could not delete {}\n",
entry.path().string());
}
}
@@ -189,13 +189,13 @@ void Thread::Main() {
m_log, "systemTime",
"{\"source\":\"DataLogManager\",\"format\":\"time_t_us\"}"};
wpi::Event newDataEvent;
wpi::util::Event newDataEvent;
DriverStation::ProvideRefreshedDataEventHandle(newDataEvent.GetHandle());
for (;;) {
bool timedOut = false;
bool newData =
wpi::WaitForObject(newDataEvent.GetHandle(), 0.25, &timedOut);
wpi::util::WaitForObject(newDataEvent.GetHandle(), 0.25, &timedOut);
if (!m_active) {
break;
}
@@ -279,7 +279,7 @@ void Thread::Main() {
if (sysTimeCount >= 250) {
sysTimeCount = 0;
if (RobotController::IsSystemTimeValid()) {
sysTimeEntry.Append(wpi::GetSystemTime(), wpi::Now());
sysTimeEntry.Append(wpi::util::GetSystemTime(), wpi::util::Now());
}
}
}
@@ -289,7 +289,7 @@ void Thread::Main() {
void Thread::StartNTLog() {
if (!m_ntLoggerEnabled) {
m_ntLoggerEnabled = true;
auto inst = nt::NetworkTableInstance::GetDefault();
auto inst = wpi::nt::NetworkTableInstance::GetDefault();
m_ntEntryLogger = inst.StartEntryDataLog(m_log, "", "NT:");
m_ntConnLogger = inst.StartConnectionDataLog(m_log, "NTConnection");
}
@@ -298,8 +298,8 @@ void Thread::StartNTLog() {
void Thread::StopNTLog() {
if (m_ntLoggerEnabled) {
m_ntLoggerEnabled = false;
nt::NetworkTableInstance::StopEntryDataLog(m_ntEntryLogger);
nt::NetworkTableInstance::StopConnectionDataLog(m_ntConnLogger);
wpi::nt::NetworkTableInstance::StopEntryDataLog(m_ntEntryLogger);
wpi::nt::NetworkTableInstance::StopConnectionDataLog(m_ntConnLogger);
}
}
@@ -326,10 +326,10 @@ Instance::Instance(std::string_view dir, std::string_view filename,
auto logDir = MakeLogDir(dir);
std::error_code ec;
for (auto&& entry : fs::directory_iterator{logDir, ec}) {
if (wpi::starts_with(entry.path().stem().string(), "FRC_TBD_") &&
if (wpi::util::starts_with(entry.path().stem().string(), "FRC_TBD_") &&
entry.path().extension() == ".wpilog") {
if (!fs::remove(entry, ec)) {
wpi::print(stderr, "DataLogManager: could not delete {}\n",
wpi::util::print(stderr, "DataLogManager: could not delete {}\n",
entry.path().string());
}
}
@@ -361,7 +361,7 @@ void DataLogManager::Stop() {
void DataLogManager::Log(std::string_view message) {
GetInstance().owner.GetThread()->m_messageLog.Append(message);
wpi::print("{}\n", message);
wpi::util::print("{}\n", message);
}
wpi::log::DataLog& DataLogManager::GetLog() {

View File

@@ -12,7 +12,7 @@
#include "wpi/util/StackTrace.hpp"
#include "wpi/util/fs.hpp"
using namespace frc;
using namespace wpi;
RuntimeError::RuntimeError(int32_t code, std::string&& loc, std::string&& stack,
std::string&& message)
@@ -36,7 +36,7 @@ void RuntimeError::Report() const {
m_data->stack.c_str(), 1);
}
const char* frc::GetErrorMessage(int32_t* code) {
const char* wpi::GetErrorMessage(int32_t* code) {
switch (*code) {
#define S(label, offset, message) \
case err::label: \
@@ -53,7 +53,7 @@ const char* frc::GetErrorMessage(int32_t* code) {
}
}
void frc::ReportErrorV(int32_t status, const char* fileName, int lineNumber,
void wpi::ReportErrorV(int32_t status, const char* fileName, int lineNumber,
const char* funcName, fmt::string_view format,
fmt::format_args args) {
if (status == 0) {
@@ -64,10 +64,10 @@ void frc::ReportErrorV(int32_t status, const char* fileName, int lineNumber,
fmt::vformat_to(fmt::appender{out}, format, args);
out.push_back('\0');
HAL_SendError(status < 0, status, 0, out.data(), funcName,
wpi::GetStackTrace(2).c_str(), 1);
wpi::util::GetStackTrace(2).c_str(), 1);
}
RuntimeError frc::MakeErrorV(int32_t status, const char* fileName,
RuntimeError wpi::MakeErrorV(int32_t status, const char* fileName,
int lineNumber, const char* funcName,
fmt::string_view format, fmt::format_args args) {
fmt::memory_buffer out;
@@ -77,6 +77,6 @@ RuntimeError frc::MakeErrorV(int32_t status, const char* fileName,
fileName,
lineNumber,
funcName,
wpi::GetStackTrace(2),
wpi::util::GetStackTrace(2),
fmt::to_string(out)};
}

View File

@@ -9,19 +9,19 @@
#include "wpi/opmode/RobotBase.hpp"
#include "wpi/util/fs.hpp"
std::string frc::filesystem::GetLaunchDirectory() {
std::string wpi::filesystem::GetLaunchDirectory() {
return fs::current_path().string();
}
std::string frc::filesystem::GetOperatingDirectory() {
std::string wpi::filesystem::GetOperatingDirectory() {
if constexpr (!RobotBase::IsSimulation()) {
return "/home/systemcore";
} else {
return frc::filesystem::GetLaunchDirectory();
return wpi::filesystem::GetLaunchDirectory();
}
}
std::string frc::filesystem::GetDeployDirectory() {
std::string wpi::filesystem::GetDeployDirectory() {
if constexpr (!RobotBase::IsSimulation()) {
return "/home/systemcore/deploy";
} else {

View File

@@ -14,7 +14,7 @@
#include "wpi/system/Errors.hpp"
#include "wpi/system/Timer.hpp"
using namespace frc;
using namespace wpi;
Notifier::Notifier(std::function<void()> callback) {
if (!callback) {
@@ -97,7 +97,7 @@ Notifier::Notifier(int priority, std::function<void()> callback) {
if (callback) {
try {
callback();
} catch (const frc::RuntimeError& e) {
} catch (const wpi::RuntimeError& e) {
e.Report();
FRC_ReportError(
err::Error,
@@ -165,7 +165,7 @@ void Notifier::SetCallback(std::function<void()> callback) {
m_callback = callback;
}
void Notifier::StartSingle(units::second_t delay) {
void Notifier::StartSingle(wpi::units::second_t delay) {
std::scoped_lock lock(m_processMutex);
m_periodic = false;
m_period = delay;
@@ -173,7 +173,7 @@ void Notifier::StartSingle(units::second_t delay) {
UpdateAlarm();
}
void Notifier::StartPeriodic(units::second_t period) {
void Notifier::StartPeriodic(wpi::units::second_t period) {
std::scoped_lock lock(m_processMutex);
m_periodic = true;
m_period = period;
@@ -181,7 +181,7 @@ void Notifier::StartPeriodic(units::second_t period) {
UpdateAlarm();
}
void Notifier::StartPeriodic(units::hertz_t frequency) {
void Notifier::StartPeriodic(wpi::units::hertz_t frequency) {
StartPeriodic(1 / frequency);
}

View File

@@ -13,9 +13,9 @@
#include "wpi/util/deprecated.hpp"
WPI_IGNORE_DEPRECATED
using namespace frc;
using namespace wpi;
wpi::mutex Resource::m_createMutex;
wpi::util::mutex Resource::m_createMutex;
void Resource::CreateResourceObject(std::unique_ptr<Resource>& r,
uint32_t elements) {

View File

@@ -12,7 +12,7 @@
#include "wpi/hal/Power.h"
#include "wpi/system/Errors.hpp"
using namespace frc;
using namespace wpi;
std::function<uint64_t()> RobotController::m_timeSource = [] {
return RobotController::GetFPGATime();
@@ -21,7 +21,7 @@ std::function<uint64_t()> RobotController::m_timeSource = [] {
std::string RobotController::GetSerialNumber() {
WPI_String serialNum;
HAL_GetSerialNumber(&serialNum);
std::string ret{wpi::to_string_view(&serialNum)};
std::string ret{wpi::util::to_string_view(&serialNum)};
WPI_FreeString(&serialNum);
return ret;
}
@@ -29,7 +29,7 @@ std::string RobotController::GetSerialNumber() {
std::string RobotController::GetComments() {
WPI_String comments;
HAL_GetComments(&comments);
std::string ret{wpi::to_string_view(&comments)};
std::string ret{wpi::util::to_string_view(&comments)};
WPI_FreeString(&comments);
return ret;
}
@@ -53,11 +53,11 @@ uint64_t RobotController::GetFPGATime() {
return time;
}
units::volt_t RobotController::GetBatteryVoltage() {
wpi::units::volt_t RobotController::GetBatteryVoltage() {
int32_t status = 0;
double retVal = HAL_GetVinVoltage(&status);
FRC_CheckErrorStatus(status, "GetBatteryVoltage");
return units::volt_t{retVal};
return wpi::units::volt_t{retVal};
}
bool RobotController::IsSysActive() {
@@ -142,24 +142,24 @@ void RobotController::ResetRailFaultCounts() {
FRC_CheckErrorStatus(status, "ResetRailFaultCounts");
}
units::volt_t RobotController::GetBrownoutVoltage() {
wpi::units::volt_t RobotController::GetBrownoutVoltage() {
int32_t status = 0;
double retVal = HAL_GetBrownoutVoltage(&status);
FRC_CheckErrorStatus(status, "GetBrownoutVoltage");
return units::volt_t{retVal};
return wpi::units::volt_t{retVal};
}
void RobotController::SetBrownoutVoltage(units::volt_t brownoutVoltage) {
void RobotController::SetBrownoutVoltage(wpi::units::volt_t brownoutVoltage) {
int32_t status = 0;
HAL_SetBrownoutVoltage(brownoutVoltage.value(), &status);
FRC_CheckErrorStatus(status, "SetBrownoutVoltage");
}
units::celsius_t RobotController::GetCPUTemp() {
wpi::units::celsius_t RobotController::GetCPUTemp() {
int32_t status = 0;
double retVal = HAL_GetCPUTemp(&status);
FRC_CheckErrorStatus(status, "GetCPUTemp");
return units::celsius_t{retVal};
return wpi::units::celsius_t{retVal};
}
CANStatus RobotController::GetCANStatus(int busId) {

Some files were not shown because too many files have changed in this diff Show More