diff --git a/.github/workflows/cmake-android.yml b/.github/workflows/cmake-android.yml index 521273c36ef..8b364db816b 100644 --- a/.github/workflows/cmake-android.yml +++ b/.github/workflows/cmake-android.yml @@ -30,7 +30,7 @@ jobs: - uses: nttld/setup-ndk@v1 id: setup-ndk with: - ndk-version: r27d + ndk-version: r29 add-to-path: false - name: Install sccache diff --git a/.github/workflows/lint-format.yml b/.github/workflows/lint-format.yml index 825fb112d8f..68a3215136c 100644 --- a/.github/workflows/lint-format.yml +++ b/.github/workflows/lint-format.yml @@ -140,7 +140,7 @@ jobs: **/upstream_utils/** **/generated/** ./wpigui/src/main/native/cpp/portable-file-dialogs.* - ./wpimath/src/main/native/include/wpi/units/base.hpp + ./wpimath/src/test/native/cpp/units/main.cpp ./wpinet/src/main/native/linux/AvahiClient.* ./wpiutil/src/main/native/include/wpi/util/FastQueue.hpp ./wpiutil/src/test/native/cpp/json/** diff --git a/.wpiformat b/.wpiformat index 1a6bdb758a1..1d00e9cc714 100644 --- a/.wpiformat +++ b/.wpiformat @@ -22,7 +22,7 @@ generatedFileExclude { thirdparty/ wpigui/src/main/native/cpp/portable-file-dialogs\.cpp$ wpigui/src/main/native/include/wpi/gui/portable-file-dialogs\.h$ - wpimath/src/main/native/include/wpi/units/base\.hpp$ + wpimath/src/test/native/cpp/units/ wpiutil/src/main/native/include/wpi/util/FastQueue\.hpp$ wpiutil/src/test/native/cpp/json/ wpiutil/src/test/native/cpp/llvm/ @@ -31,7 +31,6 @@ generatedFileExclude { modifiableFileExclude { objcpp/ - wpimath/src/test/native/cpp/UnitsTest\.cpp$ wpiutil/src/main/native/cpp/fs\.cpp$ wpiutil/src/main/native/include/wpi/util/fs\.hpp$ } diff --git a/apriltag/src/main/native/cpp/AprilTagPoseEstimator.cpp b/apriltag/src/main/native/cpp/AprilTagPoseEstimator.cpp index ec92e4bdb00..342dc7983c6 100644 --- a/apriltag/src/main/native/cpp/AprilTagPoseEstimator.cpp +++ b/apriltag/src/main/native/cpp/AprilTagPoseEstimator.cpp @@ -46,9 +46,9 @@ static wpi::math::Transform3d MakePose(const apriltag_pose_t& pose) { if (!pose.R || !pose.t) { return {}; } - return {wpi::math::Translation3d{wpi::units::meter_t{pose.t->data[0]}, - wpi::units::meter_t{pose.t->data[1]}, - wpi::units::meter_t{pose.t->data[2]}}, + return {wpi::math::Translation3d{wpi::units::meters<>{pose.t->data[0]}, + wpi::units::meters<>{pose.t->data[1]}, + wpi::units::meters<>{pose.t->data[2]}}, wpi::math::Rotation3d{OrthogonalizeRotationMatrix( Eigen::Map>{ pose.R->data})}}; diff --git a/apriltag/src/main/native/cpp/jni/AprilTagJNI.cpp b/apriltag/src/main/native/cpp/jni/AprilTagJNI.cpp index 3a06dcfa930..980c63f6ea9 100644 --- a/apriltag/src/main/native/cpp/jni/AprilTagJNI.cpp +++ b/apriltag/src/main/native/cpp/jni/AprilTagJNI.cpp @@ -161,7 +161,7 @@ static AprilTagDetector::QuadThresholdParameters FromJavaDetectorQTP( return { FIELD(int, Int, minClusterPixels), FIELD(int, Int, maxNumMaxima), - .criticalAngle = wpi::units::radian_t{static_cast( + .criticalAngle = wpi::units::radians<>{static_cast( env->GetDoubleField(jparams, criticalAngleField))}, FIELD(float, Float, maxLineFitMSE), FIELD(int, Int, minWhiteBlackDiff), @@ -517,7 +517,7 @@ Java_org_wpilib_vision_apriltag_jni_AprilTagJNI_estimatePoseHomography } AprilTagPoseEstimator estimator( - {wpi::units::meter_t{tagSize}, fx, fy, cx, cy}); + {wpi::units::meters<>{tagSize}, fx, fy, cx, cy}); return MakeJObject(env, estimator.EstimateHomography(harr)); } @@ -554,7 +554,7 @@ Java_org_wpilib_vision_apriltag_jni_AprilTagJNI_estimatePoseOrthogonalIteration } AprilTagPoseEstimator estimator( - {wpi::units::meter_t{tagSize}, fx, fy, cx, cy}); + {wpi::units::meters<>{tagSize}, fx, fy, cx, cy}); return MakeJObject(env, estimator.EstimateOrthogonalIteration(harr, carr, nIters)); } @@ -592,7 +592,7 @@ Java_org_wpilib_vision_apriltag_jni_AprilTagJNI_estimatePose } AprilTagPoseEstimator estimator( - {wpi::units::meter_t{tagSize}, fx, fy, cx, cy}); + {wpi::units::meters<>{tagSize}, fx, fy, cx, cy}); return MakeJObject(env, estimator.Estimate(harr, carr)); } diff --git a/apriltag/src/main/native/include/wpi/apriltag/AprilTagDetector.hpp b/apriltag/src/main/native/include/wpi/apriltag/AprilTagDetector.hpp index a32be2c2d30..e2ddc2132a0 100644 --- a/apriltag/src/main/native/include/wpi/apriltag/AprilTagDetector.hpp +++ b/apriltag/src/main/native/include/wpi/apriltag/AprilTagDetector.hpp @@ -98,7 +98,7 @@ class WPILIB_DLLEXPORT AprilTagDetector { * angles that are close to straight or close to 180 degrees. Zero means * that no quads are rejected. Default is 45 degrees. */ - wpi::units::radian_t criticalAngle = 45_deg; + wpi::units::radians<> criticalAngle = 45_deg; /** * When fitting lines to the contours, the maximum mean squared error @@ -255,7 +255,7 @@ class WPILIB_DLLEXPORT AprilTagDetector { void* m_impl; wpi::util::StringMap m_families; - wpi::units::radian_t m_qtpCriticalAngle = 10_deg; + wpi::units::radians<> m_qtpCriticalAngle = 10_deg; }; } // namespace wpi::apriltag diff --git a/apriltag/src/main/native/include/wpi/apriltag/AprilTagPoseEstimator.hpp b/apriltag/src/main/native/include/wpi/apriltag/AprilTagPoseEstimator.hpp index 7f4063e9321..10dd55db139 100644 --- a/apriltag/src/main/native/include/wpi/apriltag/AprilTagPoseEstimator.hpp +++ b/apriltag/src/main/native/include/wpi/apriltag/AprilTagPoseEstimator.hpp @@ -23,7 +23,7 @@ class WPILIB_DLLEXPORT AprilTagPoseEstimator { bool operator==(const Config&) const = default; /** The tag size. */ - wpi::units::meter_t tagSize; + wpi::units::meters<> tagSize; /** Camera horizontal focal length, in pixels. */ double fx; diff --git a/apriltag/src/main/python/semiwrap/AprilTagPoseEstimator.yml b/apriltag/src/main/python/semiwrap/AprilTagPoseEstimator.yml index 4500d407ea4..329954ce03a 100644 --- a/apriltag/src/main/python/semiwrap/AprilTagPoseEstimator.yml +++ b/apriltag/src/main/python/semiwrap/AprilTagPoseEstimator.yml @@ -30,7 +30,7 @@ classes: methods: operator==: inline_code: | - .def(py::init([](wpi::units::meter_t tagSize, double fx, double fy, double cx, double cy) { + .def(py::init([](wpi::units::meters<> tagSize, double fx, double fy, double cx, double cy) { AprilTagPoseEstimator::Config cfg{tagSize, fx, fy, cx, cy}; return std::make_unique(std::move(cfg)); }), py::arg("tag_size"), py::arg("fx"), py::arg("fy"), py::arg("cx"), py::arg("cy")) diff --git a/benchmark/src/main/native/cpp/TravelingSalesmanBenchmark.hpp b/benchmark/src/main/native/cpp/TravelingSalesmanBenchmark.hpp index e70fb847f12..76693e29817 100644 --- a/benchmark/src/main/native/cpp/TravelingSalesmanBenchmark.hpp +++ b/benchmark/src/main/native/cpp/TravelingSalesmanBenchmark.hpp @@ -22,7 +22,7 @@ static constexpr int iterations = 100; inline void BM_TravelingSalesman_Transform(benchmark::State& state) { wpi::math::TravelingSalesman traveler{[](auto pose1, auto pose2) { auto transform = pose2 - pose1; - return wpi::units::math::hypot(transform.X(), transform.Y()).value(); + return wpi::units::hypot(transform.X(), transform.Y()).value(); }}; // NOLINTNEXTLINE(clang-analyzer-deadcode.DeadStores) for (auto _ : state) { @@ -33,7 +33,7 @@ inline void BM_TravelingSalesman_Transform(benchmark::State& state) { inline void BM_TravelingSalesman_Twist(benchmark::State& state) { wpi::math::TravelingSalesman traveler{[](auto pose1, auto pose2) { auto twist = (pose2 - pose1).Log(); - return wpi::units::math::hypot(twist.dx, twist.dy).value(); + return wpi::units::hypot(twist.dx, twist.dy).value(); }}; // NOLINTNEXTLINE(clang-analyzer-deadcode.DeadStores) for (auto _ : state) { diff --git a/commandsv2/src/main/native/cpp/Command.cpp b/commandsv2/src/main/native/cpp/Command.cpp index 67b0597d30f..86179b8d098 100644 --- a/commandsv2/src/main/native/cpp/Command.cpp +++ b/commandsv2/src/main/native/cpp/Command.cpp @@ -65,7 +65,7 @@ void Command::SetSubsystem(std::string_view subsystem) { m_subsystem = subsystem; } -CommandPtr Command::WithTimeout(wpi::units::second_t duration) && { +CommandPtr Command::WithTimeout(wpi::units::seconds<> duration) && { return std::move(*this).ToPtr().WithTimeout(duration); } diff --git a/commandsv2/src/main/native/cpp/CommandPtr.cpp b/commandsv2/src/main/native/cpp/CommandPtr.cpp index 4b75f75e242..c4e5a12a88b 100644 --- a/commandsv2/src/main/native/cpp/CommandPtr.cpp +++ b/commandsv2/src/main/native/cpp/CommandPtr.cpp @@ -132,7 +132,7 @@ CommandPtr CommandPtr::BeforeStarting(CommandPtr&& before) && { return std::move(*this); } -CommandPtr CommandPtr::WithTimeout(wpi::units::second_t duration) && { +CommandPtr CommandPtr::WithTimeout(wpi::units::seconds<> duration) && { AssertValid(); std::vector> temp; temp.emplace_back(std::move(m_ptr)); diff --git a/commandsv2/src/main/native/cpp/CommandScheduler.cpp b/commandsv2/src/main/native/cpp/CommandScheduler.cpp index c683957f894..356553c7a49 100644 --- a/commandsv2/src/main/native/cpp/CommandScheduler.cpp +++ b/commandsv2/src/main/native/cpp/CommandScheduler.cpp @@ -78,7 +78,7 @@ CommandScheduler& CommandScheduler::GetInstance() { return scheduler; } -void CommandScheduler::SetPeriod(wpi::units::second_t period) { +void CommandScheduler::SetPeriod(wpi::units::seconds<> period) { m_watchdog.SetTimeout(period); } diff --git a/commandsv2/src/main/native/cpp/Commands.cpp b/commandsv2/src/main/native/cpp/Commands.cpp index b5a333ca8f0..9eca21d4cce 100644 --- a/commandsv2/src/main/native/cpp/Commands.cpp +++ b/commandsv2/src/main/native/cpp/Commands.cpp @@ -87,7 +87,7 @@ CommandPtr DeferredProxy(wpi::util::unique_function supplier) { {}); } -CommandPtr Wait(wpi::units::second_t duration) { +CommandPtr Wait(wpi::units::seconds<> duration) { return WaitCommand(duration).ToPtr(); } diff --git a/commandsv2/src/main/native/cpp/NotifierCommand.cpp b/commandsv2/src/main/native/cpp/NotifierCommand.cpp index d45986f3e6f..f4644010ec8 100644 --- a/commandsv2/src/main/native/cpp/NotifierCommand.cpp +++ b/commandsv2/src/main/native/cpp/NotifierCommand.cpp @@ -9,7 +9,7 @@ using namespace wpi::cmd; NotifierCommand::NotifierCommand(std::function toRun, - wpi::units::second_t period, + wpi::units::seconds<> period, Requirements requirements) : m_toRun(toRun), m_notifier{std::move(toRun)}, m_period{period} { AddRequirements(requirements); diff --git a/commandsv2/src/main/native/cpp/WaitCommand.cpp b/commandsv2/src/main/native/cpp/WaitCommand.cpp index 3815d651e30..2408837aa75 100644 --- a/commandsv2/src/main/native/cpp/WaitCommand.cpp +++ b/commandsv2/src/main/native/cpp/WaitCommand.cpp @@ -10,7 +10,8 @@ using namespace wpi::cmd; -WaitCommand::WaitCommand(wpi::units::second_t duration) : m_duration{duration} { +WaitCommand::WaitCommand(wpi::units::seconds<> duration) + : m_duration{duration} { SetName(std::format("{}: {}", GetName(), duration)); } diff --git a/commandsv2/src/main/native/cpp/WaitUntilCommand.cpp b/commandsv2/src/main/native/cpp/WaitUntilCommand.cpp index 1074fce8f8b..c730897a878 100644 --- a/commandsv2/src/main/native/cpp/WaitUntilCommand.cpp +++ b/commandsv2/src/main/native/cpp/WaitUntilCommand.cpp @@ -13,7 +13,7 @@ using namespace wpi::cmd; WaitUntilCommand::WaitUntilCommand(std::function condition) : m_condition{std::move(condition)} {} -WaitUntilCommand::WaitUntilCommand(wpi::units::second_t time) +WaitUntilCommand::WaitUntilCommand(wpi::units::seconds<> time) : m_condition{[=] { return wpi::Timer::GetMatchTime() < time; }} {} bool WaitUntilCommand::IsFinished() { diff --git a/commandsv2/src/main/native/cpp/button/CommandJoystick.cpp b/commandsv2/src/main/native/cpp/button/CommandJoystick.cpp index 2bef6c2348f..d06bdbd9b4a 100644 --- a/commandsv2/src/main/native/cpp/button/CommandJoystick.cpp +++ b/commandsv2/src/main/native/cpp/button/CommandJoystick.cpp @@ -30,7 +30,7 @@ double CommandJoystick::GetMagnitude() const { return m_joystick.GetMagnitude(); } -wpi::units::radian_t CommandJoystick::GetDirection() const { +wpi::units::radians<> CommandJoystick::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 diff --git a/commandsv2/src/main/native/cpp/button/Trigger.cpp b/commandsv2/src/main/native/cpp/button/Trigger.cpp index cb369908490..843433b1b9a 100644 --- a/commandsv2/src/main/native/cpp/button/Trigger.cpp +++ b/commandsv2/src/main/native/cpp/button/Trigger.cpp @@ -176,7 +176,7 @@ Trigger Trigger::ToggleOnFalse(CommandPtr&& command) { return *this; } -Trigger Trigger::Debounce(wpi::units::second_t debounceTime, +Trigger Trigger::Debounce(wpi::units::seconds<> debounceTime, wpi::math::Debouncer::DebounceType type) { return Trigger(m_loop, [debouncer = wpi::math::Debouncer(debounceTime, type), condition = m_condition]() mutable { @@ -184,7 +184,7 @@ Trigger Trigger::Debounce(wpi::units::second_t debounceTime, }); } -Trigger Trigger::MultiPress(int requiredPresses, units::second_t windowTime) { +Trigger Trigger::MultiPress(int requiredPresses, units::seconds<> windowTime) { return Trigger(m_loop, [filter = wpi::math::EdgeCounterFilter(requiredPresses, windowTime), condition = m_condition]() mutable { diff --git a/commandsv2/src/main/native/include/wpi/commands2/Command.hpp b/commandsv2/src/main/native/include/wpi/commands2/Command.hpp index 5d1a9032e56..2f7bbc3ea23 100644 --- a/commandsv2/src/main/native/include/wpi/commands2/Command.hpp +++ b/commandsv2/src/main/native/include/wpi/commands2/Command.hpp @@ -191,7 +191,7 @@ class Command : public wpi::telemetry::TelemetryLoggable, * @param duration the timeout duration * @return the command with the timeout added */ - CommandPtr WithTimeout(wpi::units::second_t duration) &&; + CommandPtr WithTimeout(wpi::units::seconds<> duration) &&; /** * Decorates this command with an interrupt condition. If the specified diff --git a/commandsv2/src/main/native/include/wpi/commands2/CommandPtr.hpp b/commandsv2/src/main/native/include/wpi/commands2/CommandPtr.hpp index 405493c80a2..22758fe1bfe 100644 --- a/commandsv2/src/main/native/include/wpi/commands2/CommandPtr.hpp +++ b/commandsv2/src/main/native/include/wpi/commands2/CommandPtr.hpp @@ -125,7 +125,7 @@ class [[nodiscard]] CommandPtr final { * @param duration the timeout duration * @return the command with the timeout added */ - CommandPtr WithTimeout(wpi::units::second_t duration) &&; + CommandPtr WithTimeout(wpi::units::seconds<> duration) &&; /** * Decorates this command with an interrupt condition. If the specified diff --git a/commandsv2/src/main/native/include/wpi/commands2/CommandScheduler.hpp b/commandsv2/src/main/native/include/wpi/commands2/CommandScheduler.hpp index 625b9aaf798..92e369fd0d1 100644 --- a/commandsv2/src/main/native/include/wpi/commands2/CommandScheduler.hpp +++ b/commandsv2/src/main/native/include/wpi/commands2/CommandScheduler.hpp @@ -58,7 +58,7 @@ class CommandScheduler final : public wpi::telemetry::TelemetryLoggable, * Changes the period of the loop overrun watchdog. This should be kept in * sync with the TimedRobot period. */ - void SetPeriod(wpi::units::second_t period); + void SetPeriod(wpi::units::seconds<> period); /** * Get the active button poll. diff --git a/commandsv2/src/main/native/include/wpi/commands2/Commands.hpp b/commandsv2/src/main/native/include/wpi/commands2/Commands.hpp index 84e6f46ea53..c38378c1af7 100644 --- a/commandsv2/src/main/native/include/wpi/commands2/Commands.hpp +++ b/commandsv2/src/main/native/include/wpi/commands2/Commands.hpp @@ -98,7 +98,7 @@ CommandPtr Print(std::string_view msg); * * @param duration after how long the command finishes */ -CommandPtr Wait(wpi::units::second_t duration); +CommandPtr Wait(wpi::units::seconds<> duration); /** * Constructs a command that does nothing, finishing once a condition becomes diff --git a/commandsv2/src/main/native/include/wpi/commands2/NotifierCommand.hpp b/commandsv2/src/main/native/include/wpi/commands2/NotifierCommand.hpp index 06ecafc74d0..58002de8b06 100644 --- a/commandsv2/src/main/native/include/wpi/commands2/NotifierCommand.hpp +++ b/commandsv2/src/main/native/include/wpi/commands2/NotifierCommand.hpp @@ -34,7 +34,7 @@ class NotifierCommand : public CommandHelper { * @param period the period at which the notifier should run * @param requirements the subsystems required by this command */ - NotifierCommand(std::function toRun, wpi::units::second_t period, + NotifierCommand(std::function toRun, wpi::units::seconds<> period, Requirements requirements = {}); NotifierCommand(NotifierCommand&& other); @@ -48,6 +48,6 @@ class NotifierCommand : public CommandHelper { private: std::function m_toRun; wpi::Notifier m_notifier; - wpi::units::second_t m_period; + wpi::units::seconds<> m_period; }; } // namespace wpi::cmd diff --git a/commandsv2/src/main/native/include/wpi/commands2/WaitCommand.hpp b/commandsv2/src/main/native/include/wpi/commands2/WaitCommand.hpp index ffc8964bb28..5bff1c5e212 100644 --- a/commandsv2/src/main/native/include/wpi/commands2/WaitCommand.hpp +++ b/commandsv2/src/main/native/include/wpi/commands2/WaitCommand.hpp @@ -23,7 +23,7 @@ class WaitCommand : public CommandHelper { * * @param duration the time to wait */ - explicit WaitCommand(wpi::units::second_t duration); + explicit WaitCommand(wpi::units::seconds<> duration); WaitCommand(WaitCommand&& other) = default; @@ -44,6 +44,6 @@ class WaitCommand : public CommandHelper { wpi::Timer m_timer; private: - wpi::units::second_t m_duration; + wpi::units::seconds<> m_duration; }; } // namespace wpi::cmd diff --git a/commandsv2/src/main/native/include/wpi/commands2/WaitUntilCommand.hpp b/commandsv2/src/main/native/include/wpi/commands2/WaitUntilCommand.hpp index bbc604fc723..c4735550b0b 100644 --- a/commandsv2/src/main/native/include/wpi/commands2/WaitUntilCommand.hpp +++ b/commandsv2/src/main/native/include/wpi/commands2/WaitUntilCommand.hpp @@ -42,7 +42,7 @@ class WaitUntilCommand : public CommandHelper { * @param time the match time after which to end, in seconds * @see wpi::DriverStation::GetMatchTime() */ - explicit WaitUntilCommand(wpi::units::second_t time); + explicit WaitUntilCommand(wpi::units::seconds<> time); WaitUntilCommand(WaitUntilCommand&& other) = default; diff --git a/commandsv2/src/main/native/include/wpi/commands2/button/CommandJoystick.hpp b/commandsv2/src/main/native/include/wpi/commands2/button/CommandJoystick.hpp index c1d2f9860d8..f3f7e041096 100644 --- a/commandsv2/src/main/native/include/wpi/commands2/button/CommandJoystick.hpp +++ b/commandsv2/src/main/native/include/wpi/commands2/button/CommandJoystick.hpp @@ -76,7 +76,7 @@ class CommandJoystick { * * @return The direction of the vector. */ - wpi::units::radian_t GetDirection() const; + wpi::units::radians<> GetDirection() const; private: CommandGenericHID* m_hid; diff --git a/commandsv2/src/main/native/include/wpi/commands2/button/Trigger.hpp b/commandsv2/src/main/native/include/wpi/commands2/button/Trigger.hpp index 782d02fc0ef..03a9b38f8f9 100644 --- a/commandsv2/src/main/native/include/wpi/commands2/button/Trigger.hpp +++ b/commandsv2/src/main/native/include/wpi/commands2/button/Trigger.hpp @@ -279,7 +279,7 @@ class Trigger { * @param type The debounce type. * @return The debounced trigger. */ - Trigger Debounce(wpi::units::second_t debounceTime, + Trigger Debounce(wpi::units::seconds<> debounceTime, wpi::math::Debouncer::DebounceType type = wpi::math::Debouncer::DebounceType::RISING); @@ -297,7 +297,7 @@ class Trigger { * @param windowTime The time in which the presses must occur. * @return The multi-press trigger. */ - Trigger MultiPress(int requiredPresses, units::second_t windowTime); + Trigger MultiPress(int requiredPresses, units::seconds<> windowTime); /** * Returns the current state of this trigger. diff --git a/commandsv2/src/main/native/include/wpi/commands2/sysid/SysIdRoutine.hpp b/commandsv2/src/main/native/include/wpi/commands2/sysid/SysIdRoutine.hpp index 6990118a684..593e7dd4972 100644 --- a/commandsv2/src/main/native/include/wpi/commands2/sysid/SysIdRoutine.hpp +++ b/commandsv2/src/main/native/include/wpi/commands2/sysid/SysIdRoutine.hpp @@ -16,8 +16,8 @@ namespace wpi::cmd::sysid { -using ramp_rate_t = wpi::units::unit_t>>; +using ramp_rate_t = wpi::units::unit>>; /** Hardware-independent configuration for a SysId test routine. */ class Config { @@ -26,10 +26,10 @@ class Config { ramp_rate_t rampRate{1_V / 1_s}; /// The step voltage output used for dynamic test routines. - wpi::units::volt_t stepVoltage{7_V}; + wpi::units::volts<> stepVoltage{7_V}; /// Safety timeout for the test routine commands. - wpi::units::second_t timeout{10_s}; + wpi::units::seconds<> timeout{10_s}; /// Optional handle for recording test state in a third-party logging /// solution. @@ -49,8 +49,8 @@ class Config { * passed to this callback instead of logged in WPILog. */ Config(std::optional rampRate, - std::optional stepVoltage, - std::optional timeout, + std::optional> stepVoltage, + std::optional> timeout, std::function recordState) : recordState{std::move(recordState)} { if (rampRate) { @@ -69,7 +69,7 @@ class Mechanism { public: /// Sends the SysId-specified drive signal to the mechanism motors during test /// routines. - std::function drive; + std::function)> drive; /// Returns measured data (voltages, positions, velocities) of the mechanism /// motors during test routines. @@ -102,7 +102,7 @@ class Mechanism { * "sysid-test-state-mechanism". Defaults to the name of the subsystem if * left null. */ - Mechanism(std::function drive, + Mechanism(std::function)> drive, std::function log, wpi::cmd::Subsystem* subsystem, std::string_view name) : drive{std::move(drive)}, @@ -127,7 +127,7 @@ class Mechanism { * test commands. The subsystem's `name` will be appended to the log entry * title for the routine's test state, e.g. "sysid-test-state-subsystem". */ - Mechanism(std::function drive, + Mechanism(std::function)> drive, std::function log, wpi::cmd::Subsystem* subsystem) : drive{std::move(drive)}, @@ -190,7 +190,7 @@ class SysIdRoutine : public wpi::sysid::SysIdRoutineLog { private: Config m_config; Mechanism m_mechanism; - wpi::units::volt_t m_outputVolts{0}; + wpi::units::volts<> m_outputVolts{0}; std::function m_recordState; wpi::Timer timer; }; diff --git a/commandsv2/src/test/native/cpp/wpi/command/sysid/SysIdRoutineTest.cpp b/commandsv2/src/test/native/cpp/wpi/command/sysid/SysIdRoutineTest.cpp index a25111e8829..7118877aa3e 100644 --- a/commandsv2/src/test/native/cpp/wpi/command/sysid/SysIdRoutineTest.cpp +++ b/commandsv2/src/test/native/cpp/wpi/command/sysid/SysIdRoutineTest.cpp @@ -14,10 +14,9 @@ #include "wpi/simulation/SimHooks.hpp" #include "wpi/system/DataLogManager.hpp" #include "wpi/system/Timer.hpp" -#include "wpi/units/math.hpp" #define CHECK_NEAR_UNITS(val1, val2, eps) \ - CHECK(wpi::units::math::abs(val1 - val2) <= eps) + CHECK(wpi::units::abs(val1 - val2) <= eps) enum StateTest { Invalid, @@ -40,7 +39,7 @@ class SysIdRoutineTest { } std::vector currentStateList{}; - std::vector sentVoltages{}; + std::vector> sentVoltages{}; wpi::cmd::Subsystem m_subsystem{}; wpi::cmd::sysid::SysIdRoutine m_sysidRoutine{ wpi::cmd::sysid::Config{ @@ -65,7 +64,7 @@ class SysIdRoutineTest { } }}, wpi::cmd::sysid::Mechanism{ - [this](wpi::units::volt_t driveVoltage) { + [this](wpi::units::volts<> driveVoltage) { sentVoltages.emplace_back(driveVoltage); currentStateList.emplace_back(StateTest::InDrive); }, @@ -87,7 +86,7 @@ class SysIdRoutineTest { wpi::cmd::sysid::SysIdRoutine m_emptySysidRoutine{ wpi::cmd::sysid::Config{std::nullopt, std::nullopt, std::nullopt, nullptr}, - wpi::cmd::sysid::Mechanism{[](wpi::units::volt_t driveVoltage) {}, + wpi::cmd::sysid::Mechanism{[](wpi::units::volts<> driveVoltage) {}, nullptr, &m_subsystem}}; wpi::cmd::CommandPtr m_emptyRoutineForward{ @@ -152,28 +151,28 @@ TEST_CASE_METHOD(SysIdRoutineTest, "SysIdRoutineTest DeclareCorrectState", TEST_CASE_METHOD(SysIdRoutineTest, "SysIdRoutineTest OutputCorrectVoltage", "[commandsv2][command]") { RunCommand(std::move(m_quasistaticForward)); - std::vector expectedVoltages{1_V, 0_V}; + std::vector> expectedVoltages{1_V, 0_V}; CHECK_NEAR_UNITS(expectedVoltages[0], sentVoltages[0], 1e-6_V); CHECK_NEAR_UNITS(expectedVoltages[1], sentVoltages[1], 1e-6_V); currentStateList.clear(); sentVoltages.clear(); RunCommand(std::move(m_quasistaticReverse)); - expectedVoltages = std::vector{-1_V, 0_V}; + expectedVoltages = std::vector>{-1_V, 0_V}; CHECK_NEAR_UNITS(expectedVoltages[0], sentVoltages[0], 1e-6_V); CHECK_NEAR_UNITS(expectedVoltages[1], sentVoltages[1], 1e-6_V); currentStateList.clear(); sentVoltages.clear(); RunCommand(std::move(m_dynamicForward)); - expectedVoltages = std::vector{7_V, 0_V}; + expectedVoltages = std::vector>{7_V, 0_V}; CHECK_NEAR_UNITS(expectedVoltages[0], sentVoltages[0], 1e-6_V); CHECK_NEAR_UNITS(expectedVoltages[1], sentVoltages[1], 1e-6_V); currentStateList.clear(); sentVoltages.clear(); RunCommand(std::move(m_dynamicReverse)); - expectedVoltages = std::vector{-7_V, 0_V}; + expectedVoltages = std::vector>{-7_V, 0_V}; CHECK_NEAR_UNITS(expectedVoltages[0], sentVoltages[0], 1e-6_V); CHECK_NEAR_UNITS(expectedVoltages[1], sentVoltages[1], 1e-6_V); currentStateList.clear(); diff --git a/drivers/src/main/native/cpp/odometry/GoBildaPinpoint.cpp b/drivers/src/main/native/cpp/odometry/GoBildaPinpoint.cpp index 869c6644495..342e4a90a28 100644 --- a/drivers/src/main/native/cpp/odometry/GoBildaPinpoint.cpp +++ b/drivers/src/main/native/cpp/odometry/GoBildaPinpoint.cpp @@ -107,8 +107,8 @@ void GoBildaPinpoint::SetErrorDetectionType( m_errorDetectionType = errorDetectionType; } -void GoBildaPinpoint::SetOffsets(wpi::units::meter_t xOffset, - wpi::units::meter_t yOffset) { +void GoBildaPinpoint::SetOffsets(wpi::units::meters<> xOffset, + wpi::units::meters<> yOffset) { float xOffsetMillimeters = MetersToMillimeters(xOffset, "xOffset"); float yOffsetMillimeters = MetersToMillimeters(yOffset, "yOffset"); WriteFloat(Register::X_POD_OFFSET, xOffsetMillimeters); @@ -208,21 +208,21 @@ void GoBildaPinpoint::SetPose(const wpi::math::Pose2d& pose) { } } -void GoBildaPinpoint::SetXPosition(wpi::units::meter_t position) { +void GoBildaPinpoint::SetXPosition(wpi::units::meters<> position) { if (WriteFloat(Register::X_POSITION, MetersToMillimeters(position, "position"))) { m_haveXPosition = false; } } -void GoBildaPinpoint::SetYPosition(wpi::units::meter_t position) { +void GoBildaPinpoint::SetYPosition(wpi::units::meters<> position) { if (WriteFloat(Register::Y_POSITION, MetersToMillimeters(position, "position"))) { m_haveYPosition = false; } } -void GoBildaPinpoint::SetHeading(wpi::units::radian_t heading) { +void GoBildaPinpoint::SetHeading(wpi::units::radians<> heading) { if (WriteFloat(Register::H_ORIENTATION, RequireFiniteFloat(heading.value(), "heading"))) { m_haveHeading = false; @@ -285,9 +285,9 @@ int32_t GoBildaPinpoint::GetLoopTimeMicroseconds() { return m_loopTimeMicroseconds; } -wpi::units::hertz_t GoBildaPinpoint::GetFrequency() { +wpi::units::hertz<> GoBildaPinpoint::GetFrequency() { int32_t loopTime = GetLoopTimeMicroseconds(); - return wpi::units::hertz_t{loopTime == 0 ? 0.0 : 1000000.0 / loopTime}; + return wpi::units::hertz<>{loopTime == 0 ? 0.0 : 1000000.0 / loopTime}; } int32_t GoBildaPinpoint::GetXEncoder() { @@ -300,46 +300,46 @@ int32_t GoBildaPinpoint::GetYEncoder() { return m_yEncoderValue; } -wpi::units::meter_t GoBildaPinpoint::GetXPosition() { +wpi::units::meters<> GoBildaPinpoint::GetXPosition() { ReadIfNotInBulkScope(Register::X_POSITION); - return wpi::units::meter_t{m_xPositionMillimeters / 1000.0}; + return wpi::units::meters<>{m_xPositionMillimeters / 1000.0}; } -wpi::units::meter_t GoBildaPinpoint::GetYPosition() { +wpi::units::meters<> GoBildaPinpoint::GetYPosition() { ReadIfNotInBulkScope(Register::Y_POSITION); - return wpi::units::meter_t{m_yPositionMillimeters / 1000.0}; + return wpi::units::meters<>{m_yPositionMillimeters / 1000.0}; } -wpi::units::radian_t GoBildaPinpoint::GetHeading() { +wpi::units::radians<> GoBildaPinpoint::GetHeading() { ReadIfNotInBulkScope(Register::H_ORIENTATION); - return wpi::units::radian_t{m_headingRadians}; + return wpi::units::radians<>{m_headingRadians}; } -wpi::units::meters_per_second_t GoBildaPinpoint::GetXVelocity() { +wpi::units::meters_per_second<> GoBildaPinpoint::GetXVelocity() { ReadIfNotInBulkScope(Register::X_VELOCITY); - return wpi::units::meters_per_second_t{m_xVelocityMillimetersPerSecond / + return wpi::units::meters_per_second<>{m_xVelocityMillimetersPerSecond / 1000.0}; } -wpi::units::meters_per_second_t GoBildaPinpoint::GetYVelocity() { +wpi::units::meters_per_second<> GoBildaPinpoint::GetYVelocity() { ReadIfNotInBulkScope(Register::Y_VELOCITY); - return wpi::units::meters_per_second_t{m_yVelocityMillimetersPerSecond / + return wpi::units::meters_per_second<>{m_yVelocityMillimetersPerSecond / 1000.0}; } -wpi::units::radians_per_second_t GoBildaPinpoint::GetHeadingVelocity() { +wpi::units::radians_per_second<> GoBildaPinpoint::GetHeadingVelocity() { ReadIfNotInBulkScope(Register::H_VELOCITY); - return wpi::units::radians_per_second_t{m_headingVelocityRadiansPerSecond}; + return wpi::units::radians_per_second<>{m_headingVelocityRadiansPerSecond}; } -wpi::units::meter_t GoBildaPinpoint::GetXOffset() { +wpi::units::meters<> GoBildaPinpoint::GetXOffset() { ReadIfNotInBulkScope(Register::X_POD_OFFSET); - return wpi::units::meter_t{m_xPodOffsetMillimeters / 1000.0}; + return wpi::units::meters<>{m_xPodOffsetMillimeters / 1000.0}; } -wpi::units::meter_t GoBildaPinpoint::GetYOffset() { +wpi::units::meters<> GoBildaPinpoint::GetYOffset() { ReadIfNotInBulkScope(Register::Y_POD_OFFSET); - return wpi::units::meter_t{m_yPodOffsetMillimeters / 1000.0}; + return wpi::units::meters<>{m_yPodOffsetMillimeters / 1000.0}; } wpi::math::Pose2d GoBildaPinpoint::GetPose() { @@ -347,9 +347,9 @@ wpi::math::Pose2d GoBildaPinpoint::GetPose() { ReadPose(); } return wpi::math::Pose2d{ - wpi::units::meter_t{m_xPositionMillimeters / 1000.0}, - wpi::units::meter_t{m_yPositionMillimeters / 1000.0}, - wpi::math::Rotation2d{wpi::units::radian_t{m_headingRadians}}}; + wpi::units::meters<>{m_xPositionMillimeters / 1000.0}, + wpi::units::meters<>{m_yPositionMillimeters / 1000.0}, + wpi::math::Rotation2d{wpi::units::radians<>{m_headingRadians}}}; } wpi::math::Quaternion GoBildaPinpoint::GetQuaternion() { @@ -365,18 +365,18 @@ wpi::math::Rotation3d GoBildaPinpoint::GetRotation3d() { return wpi::math::Rotation3d{GetQuaternion()}; } -wpi::units::radian_t GoBildaPinpoint::GetPitch() { +wpi::units::radians<> GoBildaPinpoint::GetPitch() { if (RequireFirmwareVersion3("Pitch output")) { ReadIfNotInBulkScope(Register::PITCH); } - return wpi::units::radian_t{m_pitchRadians}; + return wpi::units::radians<>{m_pitchRadians}; } -wpi::units::radian_t GoBildaPinpoint::GetRoll() { +wpi::units::radians<> GoBildaPinpoint::GetRoll() { if (RequireFirmwareVersion3("Roll output")) { ReadIfNotInBulkScope(Register::ROLL); } - return wpi::units::radian_t{m_rollRadians}; + return wpi::units::radians<>{m_rollRadians}; } int GoBildaPinpoint::ValidateAddress(int deviceAddress) { @@ -386,7 +386,7 @@ int GoBildaPinpoint::ValidateAddress(int deviceAddress) { return deviceAddress; } -float GoBildaPinpoint::MetersToMillimeters(wpi::units::meter_t meters, +float GoBildaPinpoint::MetersToMillimeters(wpi::units::meters<> meters, const char* parameterName) { return RequireFiniteFloat(meters.value() * 1000.0, parameterName); } diff --git a/drivers/src/main/native/include/wpi/drivers/odometry/GoBildaPinpoint.hpp b/drivers/src/main/native/include/wpi/drivers/odometry/GoBildaPinpoint.hpp index d2b714346d5..3cba0181c74 100644 --- a/drivers/src/main/native/include/wpi/drivers/odometry/GoBildaPinpoint.hpp +++ b/drivers/src/main/native/include/wpi/drivers/odometry/GoBildaPinpoint.hpp @@ -237,7 +237,7 @@ class GoBildaPinpoint { * @throws std::invalid_argument if either offset is nonfinite or cannot be * represented by the device's 32-bit floating-point register. */ - void SetOffsets(wpi::units::meter_t xOffset, wpi::units::meter_t yOffset); + void SetOffsets(wpi::units::meters<> xOffset, wpi::units::meters<> yOffset); /** Recalibrates the IMU. The robot must remain stationary for 0.25 seconds. */ @@ -299,7 +299,7 @@ class GoBildaPinpoint { * @throws std::invalid_argument if position is nonfinite or cannot be * represented by a 32-bit float. */ - void SetXPosition(wpi::units::meter_t position); + void SetXPosition(wpi::units::meters<> position); /** * Overrides the tracked Y position. @@ -308,7 +308,7 @@ class GoBildaPinpoint { * @throws std::invalid_argument if position is nonfinite or cannot be * represented by a 32-bit float. */ - void SetYPosition(wpi::units::meter_t position); + void SetYPosition(wpi::units::meters<> position); /** * Overrides the tracked heading. @@ -317,7 +317,7 @@ class GoBildaPinpoint { * @throws std::invalid_argument if heading is nonfinite or cannot be * represented by a 32-bit float. */ - void SetHeading(wpi::units::radian_t heading); + void SetHeading(wpi::units::radians<> heading); /** @return Device identifier. */ int32_t GetDeviceId(); @@ -370,7 +370,7 @@ class GoBildaPinpoint { int32_t GetLoopTimeMicroseconds(); /** @return Device loop frequency, or zero if no loop time has been read. */ - wpi::units::hertz_t GetFrequency(); + wpi::units::hertz<> GetFrequency(); /** @return Raw X encoder count in ticks. */ int32_t GetXEncoder(); @@ -379,28 +379,28 @@ class GoBildaPinpoint { int32_t GetYEncoder(); /** @return Tracked X position. */ - wpi::units::meter_t GetXPosition(); + wpi::units::meters<> GetXPosition(); /** @return Tracked Y position. */ - wpi::units::meter_t GetYPosition(); + wpi::units::meters<> GetYPosition(); /** @return Continuous tracked heading, not constrained to one rotation. */ - wpi::units::radian_t GetHeading(); + wpi::units::radians<> GetHeading(); /** @return Tracked X velocity. */ - wpi::units::meters_per_second_t GetXVelocity(); + wpi::units::meters_per_second<> GetXVelocity(); /** @return Tracked Y velocity. */ - wpi::units::meters_per_second_t GetYVelocity(); + wpi::units::meters_per_second<> GetYVelocity(); /** @return Heading velocity. */ - wpi::units::radians_per_second_t GetHeadingVelocity(); + wpi::units::radians_per_second<> GetHeadingVelocity(); /** @return X pod offset. */ - wpi::units::meter_t GetXOffset(); + wpi::units::meters<> GetXOffset(); /** @return Y pod offset. */ - wpi::units::meter_t GetYOffset(); + wpi::units::meters<> GetYOffset(); /** * Returns the tracked pose. The heading is normalized by Rotation2d. @@ -439,7 +439,7 @@ class GoBildaPinpoint { * @return Pitch. * @throws std::runtime_error if the firmware is older than v3. */ - wpi::units::radian_t GetPitch(); + wpi::units::radians<> GetPitch(); /** * Returns the roll. @@ -447,7 +447,7 @@ class GoBildaPinpoint { * @return Roll. * @throws std::runtime_error if the firmware is older than v3. */ - wpi::units::radian_t GetRoll(); + wpi::units::radians<> GetRoll(); private: enum class RegisterType { INT32, FLOAT, BULK }; @@ -481,7 +481,7 @@ class GoBildaPinpoint { Register::Y_VELOCITY, Register::H_VELOCITY}; static int ValidateAddress(int deviceAddress); - static float MetersToMillimeters(wpi::units::meter_t meters, + static float MetersToMillimeters(wpi::units::meters<> meters, const char* parameterName); static float RequireFiniteFloat(double value, const char* parameterName); bool RequireFirmwareVersion3(const char* feature); diff --git a/drivers/src/test/native/cpp/odometry/GoBildaPinpointTest.cpp b/drivers/src/test/native/cpp/odometry/GoBildaPinpointTest.cpp index 5b5d064e11f..fb3833f6abb 100644 --- a/drivers/src/test/native/cpp/odometry/GoBildaPinpointTest.cpp +++ b/drivers/src/test/native/cpp/odometry/GoBildaPinpointTest.cpp @@ -570,8 +570,6 @@ TEST_CASE_METHOD( PinpointTestFixture, "GoBildaPinpoint reestablishes pose baseline after omitted bulk samples", "[drivers][gobilda-pinpoint]") { - using wpi::units::meter_t; - SetRegister(Register::DEVICE_VERSION, EncodeInt(3)); wpi::GoBildaPinpoint pinpoint{wpi::I2C::Port::PORT_0}; pinpoint.SetBulkReadScope({Register::DEVICE_STATUS}); @@ -582,8 +580,8 @@ TEST_CASE_METHOD( Register::BULK_READ, Concat(EncodeFloat(1000.0f), EncodeFloat(2000.0f), EncodeFloat(0.5f))); auto pose = pinpoint.GetPose(); - CHECK(pose.X() == meter_t{1.0}); - CHECK(pose.Y() == meter_t{2.0}); + CHECK(pose.X() == 1.0_m); + CHECK(pose.Y() == 2.0_m); SetRegister(Register::BULK_READ, EncodeInt(1)); pinpoint.Update(); @@ -592,8 +590,8 @@ TEST_CASE_METHOD( Register::BULK_READ, Concat(EncodeFloat(7000.0f), EncodeFloat(8000.0f), EncodeFloat(1.0f))); pose = pinpoint.GetPose(); - CHECK(pose.X() == meter_t{7.0}); - CHECK(pose.Y() == meter_t{8.0}); + CHECK(pose.X() == 7.0_m); + CHECK(pose.Y() == 8.0_m); CHECK(pose.Rotation().Radians().value() == Catch::Approx(1.0)); CHECK(pinpoint.GetFailureCount() == 0); @@ -601,8 +599,8 @@ TEST_CASE_METHOD( Register::BULK_READ, Concat(EncodeFloat(13000.0f), EncodeFloat(8000.0f), EncodeFloat(1.0f))); pose = pinpoint.GetPose(); - CHECK(pose.X() == meter_t{7.0}); - CHECK(pose.Y() == meter_t{8.0}); + CHECK(pose.X() == 7.0_m); + CHECK(pose.Y() == 8.0_m); CHECK(pose.Rotation().Radians().value() == Catch::Approx(1.0)); CHECK(pinpoint.GetLastFailureReason() == wpi::GoBildaPinpoint::FailureReason::CHANGE_TOO_LARGE); @@ -611,17 +609,14 @@ TEST_CASE_METHOD( TEST_CASE_METHOD(PinpointTestFixture, "GoBildaPinpoint pose writes reset local validation baselines", "[drivers][gobilda-pinpoint]") { - using wpi::units::meter_t; - using wpi::units::radian_t; - SetRegister(Register::DEVICE_VERSION, EncodeInt(2)); SetRegister(Register::BULK_READ, FixedBulkData(1, 1000, 0, 0, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f)); wpi::GoBildaPinpoint pinpoint{wpi::I2C::Port::PORT_0}; pinpoint.Update(); - pinpoint.SetPose(wpi::math::Pose2d{meter_t{7.0}, meter_t{-7.0}, - wpi::math::Rotation2d{radian_t{1.0}}}); + pinpoint.SetPose( + wpi::math::Pose2d{7.0_m, -7.0_m, wpi::math::Rotation2d{1.0_rad}}); SetRegister( Register::BULK_READ, FixedBulkData(1, 1000, 0, 0, 7000.0f, -7000.0f, 1.0f, 0.0f, 0.0f, 0.0f)); @@ -629,9 +624,9 @@ TEST_CASE_METHOD(PinpointTestFixture, CHECK(pinpoint.GetXPosition().value() == Catch::Approx(7.0)); CHECK(pinpoint.GetYPosition().value() == Catch::Approx(-7.0)); - pinpoint.SetXPosition(meter_t{-7.0}); - pinpoint.SetYPosition(meter_t{7.0}); - pinpoint.SetHeading(radian_t{130.0}); + pinpoint.SetXPosition(-7.0_m); + pinpoint.SetYPosition(7.0_m); + pinpoint.SetHeading(130.0_rad); SetRegister(Register::BULK_READ, FixedBulkData(1, 1000, 0, 0, -7000.0f, 7000.0f, 130.0f, 0.0f, 0.0f, 0.0f)); @@ -801,10 +796,10 @@ TEST_CASE_METHOD(PinpointTestFixture, std::invalid_argument); wpi::GoBildaPinpoint pinpoint{wpi::I2C::Port::PORT_0}; - CHECK_THROWS_AS(pinpoint.SetOffsets( - wpi::units::meter_t{1.0}, - wpi::units::meter_t{std::numeric_limits::max()}), - std::invalid_argument); + CHECK_THROWS_AS( + pinpoint.SetOffsets( + 1.0_m, wpi::units::meters<>{std::numeric_limits::max()}), + std::invalid_argument); CHECK(m_writes.empty()); CHECK_THROWS_AS(pinpoint.SetEncoderResolution(0.0), std::invalid_argument); CHECK_THROWS_AS( @@ -817,16 +812,16 @@ TEST_CASE_METHOD(PinpointTestFixture, "[drivers][gobilda-pinpoint]") { wpi::GoBildaPinpoint pinpoint{wpi::I2C::Port::PORT_0}; - CHECK_THROWS_AS(pinpoint.SetPose(wpi::math::Pose2d{ - wpi::units::meter_t{1.0}, - wpi::units::meter_t{std::numeric_limits::max()}, - wpi::math::Rotation2d{}}), - std::invalid_argument); + CHECK_THROWS_AS( + pinpoint.SetPose(wpi::math::Pose2d{ + 1.0_m, wpi::units::meters<>{std::numeric_limits::max()}, + wpi::math::Rotation2d{}}), + std::invalid_argument); CHECK(m_writes.empty()); CHECK_THROWS_AS(pinpoint.SetPose(wpi::math::Pose2d{ - wpi::units::meter_t{1.0}, wpi::units::meter_t{2.0}, - wpi::math::Rotation2d{wpi::units::radian_t{ + 1.0_m, 2.0_m, + wpi::math::Rotation2d{wpi::units::radians<>{ std::numeric_limits::quiet_NaN()}}}), std::invalid_argument); CHECK(m_writes.empty()); diff --git a/fields/generate_fields.py b/fields/generate_fields.py index 9649e336529..3cb570ae1fc 100755 --- a/fields/generate_fields.py +++ b/fields/generate_fields.py @@ -45,8 +45,8 @@ def number_literal(value: float) -> str: return json.dumps(value) -def cpp_meter_t(value: float) -> str: - return f"wpi::units::meter_t{{{number_literal(value)}}}" +def cpp_meters(value: float) -> str: + return f"wpi::units::meters<>{{{number_literal(value)}}}" def java_identifier_suffix(value: str) -> str: @@ -321,7 +321,7 @@ def make_environment(template_root: Path) -> Environment: env.filters["java_nullable_string"] = java_nullable_string env.filters["cpp_nullable_string"] = cpp_nullable_string env.filters["number"] = number_literal - env.filters["cpp_meter_t"] = cpp_meter_t + env.filters["cpp_meters"] = cpp_meters return env diff --git a/fields/src/generate/main/native/cpp/fields/fields.cpp.jinja b/fields/src/generate/main/native/cpp/fields/fields.cpp.jinja index 1bef34cb6c7..48176aa380f 100644 --- a/fields/src/generate/main/native/cpp/fields/fields.cpp.jinja +++ b/fields/src/generate/main/native/cpp/fields/fields.cpp.jinja @@ -49,9 +49,9 @@ static constexpr FieldTag FIELD_TAGS_{{ field.enum }}[] = { {{ tag.id }}, wpi::math::Pose3d{ wpi::math::Translation3d{ - {{ tag.translation.x|cpp_meter_t }}, - {{ tag.translation.y|cpp_meter_t }}, - {{ tag.translation.z|cpp_meter_t }}, + {{ tag.translation.x|cpp_meters }}, + {{ tag.translation.y|cpp_meters }}, + {{ tag.translation.z|cpp_meters }}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ {{ tag.quaternion.W|number }}, @@ -117,8 +117,8 @@ Field GetField(FieldId field) { result.m_image.emplace(data.fieldImage, data.top, data.left, data.bottom, data.right); } - result.m_fieldLength = wpi::units::meter_t{data.length}; - result.m_fieldWidth = wpi::units::meter_t{data.width}; + result.m_fieldLength = wpi::units::meters<>{data.length}; + result.m_fieldWidth = wpi::units::meters<>{data.width}; result.m_program = data.program; result.m_resourceFile = data.resourceFile; result.m_hasTags = data.hasTags; diff --git a/fields/src/generated/main/native/cpp/fields/fields.cpp b/fields/src/generated/main/native/cpp/fields/fields.cpp index e8518a0f2e8..bcdd0856e82 100644 --- a/fields/src/generated/main/native/cpp/fields/fields.cpp +++ b/fields/src/generated/main/native/cpp/fields/fields.cpp @@ -62,9 +62,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2022_RAPID_REACT[] = { 0, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{-0.0035306}, - wpi::units::meter_t{7.578928199999999}, - wpi::units::meter_t{0.8858503999999999}, + wpi::units::meters<>{-0.0035306}, + wpi::units::meters<>{7.578928199999999}, + wpi::units::meters<>{0.8858503999999999}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 1.0, @@ -78,9 +78,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2022_RAPID_REACT[] = { 1, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{3.2327088}, - wpi::units::meter_t{5.486654}, - wpi::units::meter_t{1.7254728}, + wpi::units::meters<>{3.2327088}, + wpi::units::meters<>{5.486654}, + wpi::units::meters<>{1.7254728}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 1.0, @@ -94,9 +94,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2022_RAPID_REACT[] = { 2, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{3.067812}, - wpi::units::meter_t{5.3305202}, - wpi::units::meter_t{1.3762228}, + wpi::units::meters<>{3.067812}, + wpi::units::meters<>{5.3305202}, + wpi::units::meters<>{1.3762228}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 0.7071067811865476, @@ -110,9 +110,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2022_RAPID_REACT[] = { 3, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{0.0039878}, - wpi::units::meter_t{5.058536999999999}, - wpi::units::meter_t{0.80645}, + wpi::units::meters<>{0.0039878}, + wpi::units::meters<>{5.058536999999999}, + wpi::units::meters<>{0.80645}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 1.0, @@ -126,9 +126,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2022_RAPID_REACT[] = { 4, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{0.0039878}, - wpi::units::meter_t{3.5124898}, - wpi::units::meter_t{0.80645}, + wpi::units::meters<>{0.0039878}, + wpi::units::meters<>{3.5124898}, + wpi::units::meters<>{0.80645}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 1.0, @@ -142,9 +142,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2022_RAPID_REACT[] = { 5, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{0.12110719999999998}, - wpi::units::meter_t{1.7178274}, - wpi::units::meter_t{0.8906002000000001}, + wpi::units::meters<>{0.12110719999999998}, + wpi::units::meters<>{1.7178274}, + wpi::units::meters<>{0.8906002000000001}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 0.9196502204050923, @@ -158,9 +158,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2022_RAPID_REACT[] = { 6, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{0.8733027999999999}, - wpi::units::meter_t{0.9412985999999999}, - wpi::units::meter_t{0.8906002000000001}, + wpi::units::meters<>{0.8733027999999999}, + wpi::units::meters<>{0.9412985999999999}, + wpi::units::meters<>{0.8906002000000001}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 0.9196502204050923, @@ -174,9 +174,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2022_RAPID_REACT[] = { 7, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{1.6150844}, - wpi::units::meter_t{0.15725139999999999}, - wpi::units::meter_t{0.8906002000000001}, + wpi::units::meters<>{1.6150844}, + wpi::units::meters<>{0.15725139999999999}, + wpi::units::meters<>{0.8906002000000001}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 0.9196502204050923, @@ -190,9 +190,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2022_RAPID_REACT[] = { 10, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{16.4627306}, - wpi::units::meter_t{0.6506718}, - wpi::units::meter_t{0.8858503999999999}, + wpi::units::meters<>{16.4627306}, + wpi::units::meters<>{0.6506718}, + wpi::units::meters<>{0.8858503999999999}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 6.123233995736766e-17, @@ -206,9 +206,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2022_RAPID_REACT[] = { 11, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{13.2350002}, - wpi::units::meter_t{2.743454}, - wpi::units::meter_t{1.7254728}, + wpi::units::meters<>{13.2350002}, + wpi::units::meters<>{2.743454}, + wpi::units::meters<>{1.7254728}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 6.123233995736766e-17, @@ -222,9 +222,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2022_RAPID_REACT[] = { 12, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{13.391388000000001}, - wpi::units::meter_t{2.8998418}, - wpi::units::meter_t{1.3762228}, + wpi::units::meters<>{13.391388000000001}, + wpi::units::meters<>{2.8998418}, + wpi::units::meters<>{1.3762228}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 0.7071067811865476, @@ -238,9 +238,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2022_RAPID_REACT[] = { 13, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{16.4552122}, - wpi::units::meter_t{3.1755079999999998}, - wpi::units::meter_t{0.80645}, + wpi::units::meters<>{16.4552122}, + wpi::units::meters<>{3.1755079999999998}, + wpi::units::meters<>{0.80645}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 6.123233995736766e-17, @@ -254,9 +254,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2022_RAPID_REACT[] = { 14, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{16.4552122}, - wpi::units::meter_t{4.7171356}, - wpi::units::meter_t{0.80645}, + wpi::units::meters<>{16.4552122}, + wpi::units::meters<>{4.7171356}, + wpi::units::meters<>{0.80645}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 6.123233995736766e-17, @@ -270,9 +270,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2022_RAPID_REACT[] = { 15, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{16.3350194}, - wpi::units::meter_t{6.5149729999999995}, - wpi::units::meter_t{0.8937752}, + wpi::units::meters<>{16.3350194}, + wpi::units::meters<>{6.5149729999999995}, + wpi::units::meters<>{0.8937752}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ -0.37298778257580906, @@ -286,9 +286,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2022_RAPID_REACT[] = { 16, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{15.5904946}, - wpi::units::meter_t{7.292695599999999}, - wpi::units::meter_t{0.8906002000000001}, + wpi::units::meters<>{15.5904946}, + wpi::units::meters<>{7.292695599999999}, + wpi::units::meters<>{0.8906002000000001}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ -0.37298778257580906, @@ -302,9 +302,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2022_RAPID_REACT[] = { 17, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{14.847188999999998}, - wpi::units::meter_t{8.0691228}, - wpi::units::meter_t{0.8906002000000001}, + wpi::units::meters<>{14.847188999999998}, + wpi::units::meters<>{8.0691228}, + wpi::units::meters<>{0.8906002000000001}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ -0.37298778257580906, @@ -318,9 +318,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2022_RAPID_REACT[] = { 40, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{7.874127}, - wpi::units::meter_t{4.9131728}, - wpi::units::meter_t{0.7032752}, + wpi::units::meters<>{7.874127}, + wpi::units::meters<>{4.9131728}, + wpi::units::meters<>{0.7032752}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 0.5446390350150271, @@ -334,9 +334,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2022_RAPID_REACT[] = { 41, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{7.4312271999999995}, - wpi::units::meter_t{3.759327}, - wpi::units::meter_t{0.7032752}, + wpi::units::meters<>{7.4312271999999995}, + wpi::units::meters<>{3.759327}, + wpi::units::meters<>{0.7032752}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ -0.20791169081775934, @@ -350,9 +350,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2022_RAPID_REACT[] = { 42, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{8.585073}, - wpi::units::meter_t{3.3164272}, - wpi::units::meter_t{0.7032752}, + wpi::units::meters<>{8.585073}, + wpi::units::meters<>{3.3164272}, + wpi::units::meters<>{0.7032752}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 0.838670567945424, @@ -366,9 +366,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2022_RAPID_REACT[] = { 43, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{9.0279728}, - wpi::units::meter_t{4.470273}, - wpi::units::meter_t{0.7032752}, + wpi::units::meters<>{9.0279728}, + wpi::units::meters<>{4.470273}, + wpi::units::meters<>{0.7032752}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 0.9781476007338057, @@ -382,9 +382,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2022_RAPID_REACT[] = { 50, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{7.6790296}, - wpi::units::meter_t{4.3261534}, - wpi::units::meter_t{2.4177244}, + wpi::units::meters<>{7.6790296}, + wpi::units::meters<>{4.3261534}, + wpi::units::meters<>{2.4177244}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 0.17729273396782605, @@ -398,9 +398,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2022_RAPID_REACT[] = { 51, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{8.0182466}, - wpi::units::meter_t{3.5642296}, - wpi::units::meter_t{2.4177244}, + wpi::units::meters<>{8.0182466}, + wpi::units::meters<>{3.5642296}, + wpi::units::meters<>{2.4177244}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ -0.5510435465842192, @@ -414,9 +414,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2022_RAPID_REACT[] = { 52, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{8.7801704}, - wpi::units::meter_t{3.9034466}, - wpi::units::meter_t{2.4177244}, + wpi::units::meters<>{8.7801704}, + wpi::units::meters<>{3.9034466}, + wpi::units::meters<>{2.4177244}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ -0.9565859910053994, @@ -430,9 +430,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2022_RAPID_REACT[] = { 53, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{8.4409534}, - wpi::units::meter_t{4.6653704}, - wpi::units::meter_t{2.4177244}, + wpi::units::meters<>{8.4409534}, + wpi::units::meters<>{4.6653704}, + wpi::units::meters<>{2.4177244}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 0.8017733354717241, @@ -449,9 +449,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2023_CHARGED_UP[] = { 1, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{15.513558}, - wpi::units::meter_t{1.071626}, - wpi::units::meter_t{0.462788}, + wpi::units::meters<>{15.513558}, + wpi::units::meters<>{1.071626}, + wpi::units::meters<>{0.462788}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 0.0, @@ -465,9 +465,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2023_CHARGED_UP[] = { 2, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{15.513558}, - wpi::units::meter_t{2.748026}, - wpi::units::meter_t{0.462788}, + wpi::units::meters<>{15.513558}, + wpi::units::meters<>{2.748026}, + wpi::units::meters<>{0.462788}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 0.0, @@ -481,9 +481,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2023_CHARGED_UP[] = { 3, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{15.513558}, - wpi::units::meter_t{4.424426}, - wpi::units::meter_t{0.462788}, + wpi::units::meters<>{15.513558}, + wpi::units::meters<>{4.424426}, + wpi::units::meters<>{0.462788}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 0.0, @@ -497,9 +497,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2023_CHARGED_UP[] = { 4, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{16.178784}, - wpi::units::meter_t{6.749796}, - wpi::units::meter_t{0.695452}, + wpi::units::meters<>{16.178784}, + wpi::units::meters<>{6.749796}, + wpi::units::meters<>{0.695452}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 0.0, @@ -513,9 +513,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2023_CHARGED_UP[] = { 5, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{0.36195}, - wpi::units::meter_t{6.749796}, - wpi::units::meter_t{0.695452}, + wpi::units::meters<>{0.36195}, + wpi::units::meters<>{6.749796}, + wpi::units::meters<>{0.695452}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 1.0, @@ -529,9 +529,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2023_CHARGED_UP[] = { 6, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{1.02743}, - wpi::units::meter_t{4.424426}, - wpi::units::meter_t{0.462788}, + wpi::units::meters<>{1.02743}, + wpi::units::meters<>{4.424426}, + wpi::units::meters<>{0.462788}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 1.0, @@ -545,9 +545,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2023_CHARGED_UP[] = { 7, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{1.02743}, - wpi::units::meter_t{2.748026}, - wpi::units::meter_t{0.462788}, + wpi::units::meters<>{1.02743}, + wpi::units::meters<>{2.748026}, + wpi::units::meters<>{0.462788}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 1.0, @@ -561,9 +561,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2023_CHARGED_UP[] = { 8, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{1.02743}, - wpi::units::meter_t{1.071626}, - wpi::units::meter_t{0.462788}, + wpi::units::meters<>{1.02743}, + wpi::units::meters<>{1.071626}, + wpi::units::meters<>{0.462788}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 1.0, @@ -580,9 +580,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2024_CRESCENDO[] = { 1, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{15.079471999999997}, - wpi::units::meter_t{0.24587199999999998}, - wpi::units::meter_t{1.355852}, + wpi::units::meters<>{15.079471999999997}, + wpi::units::meters<>{0.24587199999999998}, + wpi::units::meters<>{1.355852}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 0.5000000000000001, @@ -596,9 +596,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2024_CRESCENDO[] = { 2, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{16.185134}, - wpi::units::meter_t{0.883666}, - wpi::units::meter_t{1.355852}, + wpi::units::meters<>{16.185134}, + wpi::units::meters<>{0.883666}, + wpi::units::meters<>{1.355852}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 0.5000000000000001, @@ -612,9 +612,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2024_CRESCENDO[] = { 3, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{16.579342}, - wpi::units::meter_t{4.982717999999999}, - wpi::units::meter_t{1.4511020000000001}, + wpi::units::meters<>{16.579342}, + wpi::units::meters<>{4.982717999999999}, + wpi::units::meters<>{1.4511020000000001}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 6.123233995736766e-17, @@ -628,9 +628,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2024_CRESCENDO[] = { 4, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{16.579342}, - wpi::units::meter_t{5.547867999999999}, - wpi::units::meter_t{1.4511020000000001}, + wpi::units::meters<>{16.579342}, + wpi::units::meters<>{5.547867999999999}, + wpi::units::meters<>{1.4511020000000001}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 6.123233995736766e-17, @@ -644,9 +644,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2024_CRESCENDO[] = { 5, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{14.700757999999999}, - wpi::units::meter_t{8.2042}, - wpi::units::meter_t{1.355852}, + wpi::units::meters<>{14.700757999999999}, + wpi::units::meters<>{8.2042}, + wpi::units::meters<>{1.355852}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ -0.7071067811865475, @@ -660,9 +660,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2024_CRESCENDO[] = { 6, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{1.8415}, - wpi::units::meter_t{8.2042}, - wpi::units::meter_t{1.355852}, + wpi::units::meters<>{1.8415}, + wpi::units::meters<>{8.2042}, + wpi::units::meters<>{1.355852}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ -0.7071067811865475, @@ -676,9 +676,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2024_CRESCENDO[] = { 7, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{-0.038099999999999995}, - wpi::units::meter_t{5.547867999999999}, - wpi::units::meter_t{1.4511020000000001}, + wpi::units::meters<>{-0.038099999999999995}, + wpi::units::meters<>{5.547867999999999}, + wpi::units::meters<>{1.4511020000000001}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 1.0, @@ -692,9 +692,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2024_CRESCENDO[] = { 8, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{-0.038099999999999995}, - wpi::units::meter_t{4.982717999999999}, - wpi::units::meter_t{1.4511020000000001}, + wpi::units::meters<>{-0.038099999999999995}, + wpi::units::meters<>{4.982717999999999}, + wpi::units::meters<>{1.4511020000000001}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 1.0, @@ -708,9 +708,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2024_CRESCENDO[] = { 9, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{0.356108}, - wpi::units::meter_t{0.883666}, - wpi::units::meter_t{1.355852}, + wpi::units::meters<>{0.356108}, + wpi::units::meters<>{0.883666}, + wpi::units::meters<>{1.355852}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 0.8660254037844387, @@ -724,9 +724,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2024_CRESCENDO[] = { 10, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{1.4615159999999998}, - wpi::units::meter_t{0.24587199999999998}, - wpi::units::meter_t{1.355852}, + wpi::units::meters<>{1.4615159999999998}, + wpi::units::meters<>{0.24587199999999998}, + wpi::units::meters<>{1.355852}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 0.8660254037844387, @@ -740,9 +740,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2024_CRESCENDO[] = { 11, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{11.904726}, - wpi::units::meter_t{3.7132259999999997}, - wpi::units::meter_t{1.3208}, + wpi::units::meters<>{11.904726}, + wpi::units::meters<>{3.7132259999999997}, + wpi::units::meters<>{1.3208}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ -0.8660254037844387, @@ -756,9 +756,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2024_CRESCENDO[] = { 12, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{11.904726}, - wpi::units::meter_t{4.49834}, - wpi::units::meter_t{1.3208}, + wpi::units::meters<>{11.904726}, + wpi::units::meters<>{4.49834}, + wpi::units::meters<>{1.3208}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 0.8660254037844387, @@ -772,9 +772,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2024_CRESCENDO[] = { 13, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{11.220196}, - wpi::units::meter_t{4.105148}, - wpi::units::meter_t{1.3208}, + wpi::units::meters<>{11.220196}, + wpi::units::meters<>{4.105148}, + wpi::units::meters<>{1.3208}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 6.123233995736766e-17, @@ -788,9 +788,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2024_CRESCENDO[] = { 14, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{5.320792}, - wpi::units::meter_t{4.105148}, - wpi::units::meter_t{1.3208}, + wpi::units::meters<>{5.320792}, + wpi::units::meters<>{4.105148}, + wpi::units::meters<>{1.3208}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 1.0, @@ -804,9 +804,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2024_CRESCENDO[] = { 15, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{4.641342}, - wpi::units::meter_t{4.49834}, - wpi::units::meter_t{1.3208}, + wpi::units::meters<>{4.641342}, + wpi::units::meters<>{4.49834}, + wpi::units::meters<>{1.3208}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 0.5000000000000001, @@ -820,9 +820,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2024_CRESCENDO[] = { 16, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{4.641342}, - wpi::units::meter_t{3.7132259999999997}, - wpi::units::meter_t{1.3208}, + wpi::units::meters<>{4.641342}, + wpi::units::meters<>{3.7132259999999997}, + wpi::units::meters<>{1.3208}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ -0.4999999999999998, @@ -839,9 +839,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2025_REEFSCAPE_WELDED[] = { 1, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{16.697198}, - wpi::units::meter_t{0.65532}, - wpi::units::meter_t{1.4859}, + wpi::units::meters<>{16.697198}, + wpi::units::meters<>{0.65532}, + wpi::units::meters<>{1.4859}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 0.4539904997395468, @@ -855,9 +855,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2025_REEFSCAPE_WELDED[] = { 2, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{16.697198}, - wpi::units::meter_t{7.3964799999999995}, - wpi::units::meter_t{1.4859}, + wpi::units::meters<>{16.697198}, + wpi::units::meters<>{7.3964799999999995}, + wpi::units::meters<>{1.4859}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ -0.45399049973954675, @@ -871,9 +871,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2025_REEFSCAPE_WELDED[] = { 3, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{11.560809999999998}, - wpi::units::meter_t{8.05561}, - wpi::units::meter_t{1.30175}, + wpi::units::meters<>{11.560809999999998}, + wpi::units::meters<>{8.05561}, + wpi::units::meters<>{1.30175}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ -0.7071067811865475, @@ -887,9 +887,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2025_REEFSCAPE_WELDED[] = { 4, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{9.276079999999999}, - wpi::units::meter_t{6.137656}, - wpi::units::meter_t{1.8679160000000001}, + wpi::units::meters<>{9.276079999999999}, + wpi::units::meters<>{6.137656}, + wpi::units::meters<>{1.8679160000000001}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 0.9659258262890683, @@ -903,9 +903,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2025_REEFSCAPE_WELDED[] = { 5, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{9.276079999999999}, - wpi::units::meter_t{1.914906}, - wpi::units::meter_t{1.8679160000000001}, + wpi::units::meters<>{9.276079999999999}, + wpi::units::meters<>{1.914906}, + wpi::units::meters<>{1.8679160000000001}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 0.9659258262890683, @@ -919,9 +919,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2025_REEFSCAPE_WELDED[] = { 6, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{13.474446}, - wpi::units::meter_t{3.3063179999999996}, - wpi::units::meter_t{0.308102}, + wpi::units::meters<>{13.474446}, + wpi::units::meters<>{3.3063179999999996}, + wpi::units::meters<>{0.308102}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ -0.8660254037844387, @@ -935,9 +935,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2025_REEFSCAPE_WELDED[] = { 7, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{13.890498}, - wpi::units::meter_t{4.0259}, - wpi::units::meter_t{0.308102}, + wpi::units::meters<>{13.890498}, + wpi::units::meters<>{4.0259}, + wpi::units::meters<>{0.308102}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 1.0, @@ -951,9 +951,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2025_REEFSCAPE_WELDED[] = { 8, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{13.474446}, - wpi::units::meter_t{4.745482}, - wpi::units::meter_t{0.308102}, + wpi::units::meters<>{13.474446}, + wpi::units::meters<>{4.745482}, + wpi::units::meters<>{0.308102}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 0.8660254037844387, @@ -967,9 +967,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2025_REEFSCAPE_WELDED[] = { 9, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{12.643358}, - wpi::units::meter_t{4.745482}, - wpi::units::meter_t{0.308102}, + wpi::units::meters<>{12.643358}, + wpi::units::meters<>{4.745482}, + wpi::units::meters<>{0.308102}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 0.5000000000000001, @@ -983,9 +983,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2025_REEFSCAPE_WELDED[] = { 10, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{12.227305999999999}, - wpi::units::meter_t{4.0259}, - wpi::units::meter_t{0.308102}, + wpi::units::meters<>{12.227305999999999}, + wpi::units::meters<>{4.0259}, + wpi::units::meters<>{0.308102}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 6.123233995736766e-17, @@ -999,9 +999,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2025_REEFSCAPE_WELDED[] = { 11, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{12.643358}, - wpi::units::meter_t{3.3063179999999996}, - wpi::units::meter_t{0.308102}, + wpi::units::meters<>{12.643358}, + wpi::units::meters<>{3.3063179999999996}, + wpi::units::meters<>{0.308102}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ -0.4999999999999998, @@ -1015,9 +1015,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2025_REEFSCAPE_WELDED[] = { 12, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{0.851154}, - wpi::units::meter_t{0.65532}, - wpi::units::meter_t{1.4859}, + wpi::units::meters<>{0.851154}, + wpi::units::meters<>{0.65532}, + wpi::units::meters<>{1.4859}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 0.8910065241883679, @@ -1031,9 +1031,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2025_REEFSCAPE_WELDED[] = { 13, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{0.851154}, - wpi::units::meter_t{7.3964799999999995}, - wpi::units::meter_t{1.4859}, + wpi::units::meters<>{0.851154}, + wpi::units::meters<>{7.3964799999999995}, + wpi::units::meters<>{1.4859}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ -0.8910065241883678, @@ -1047,9 +1047,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2025_REEFSCAPE_WELDED[] = { 14, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{8.272272}, - wpi::units::meter_t{6.137656}, - wpi::units::meter_t{1.8679160000000001}, + wpi::units::meters<>{8.272272}, + wpi::units::meters<>{6.137656}, + wpi::units::meters<>{1.8679160000000001}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 5.914589856893349e-17, @@ -1063,9 +1063,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2025_REEFSCAPE_WELDED[] = { 15, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{8.272272}, - wpi::units::meter_t{1.914906}, - wpi::units::meter_t{1.8679160000000001}, + wpi::units::meters<>{8.272272}, + wpi::units::meters<>{1.914906}, + wpi::units::meters<>{1.8679160000000001}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 5.914589856893349e-17, @@ -1079,9 +1079,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2025_REEFSCAPE_WELDED[] = { 16, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{5.9875419999999995}, - wpi::units::meter_t{-0.0038099999999999996}, - wpi::units::meter_t{1.30175}, + wpi::units::meters<>{5.9875419999999995}, + wpi::units::meters<>{-0.0038099999999999996}, + wpi::units::meters<>{1.30175}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 0.7071067811865476, @@ -1095,9 +1095,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2025_REEFSCAPE_WELDED[] = { 17, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{4.073905999999999}, - wpi::units::meter_t{3.3063179999999996}, - wpi::units::meter_t{0.308102}, + wpi::units::meters<>{4.073905999999999}, + wpi::units::meters<>{3.3063179999999996}, + wpi::units::meters<>{0.308102}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ -0.4999999999999998, @@ -1111,9 +1111,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2025_REEFSCAPE_WELDED[] = { 18, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{3.6576}, - wpi::units::meter_t{4.0259}, - wpi::units::meter_t{0.308102}, + wpi::units::meters<>{3.6576}, + wpi::units::meters<>{4.0259}, + wpi::units::meters<>{0.308102}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 6.123233995736766e-17, @@ -1127,9 +1127,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2025_REEFSCAPE_WELDED[] = { 19, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{4.073905999999999}, - wpi::units::meter_t{4.745482}, - wpi::units::meter_t{0.308102}, + wpi::units::meters<>{4.073905999999999}, + wpi::units::meters<>{4.745482}, + wpi::units::meters<>{0.308102}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 0.5000000000000001, @@ -1143,9 +1143,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2025_REEFSCAPE_WELDED[] = { 20, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{4.904739999999999}, - wpi::units::meter_t{4.745482}, - wpi::units::meter_t{0.308102}, + wpi::units::meters<>{4.904739999999999}, + wpi::units::meters<>{4.745482}, + wpi::units::meters<>{0.308102}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 0.8660254037844387, @@ -1159,9 +1159,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2025_REEFSCAPE_WELDED[] = { 21, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{5.321046}, - wpi::units::meter_t{4.0259}, - wpi::units::meter_t{0.308102}, + wpi::units::meters<>{5.321046}, + wpi::units::meters<>{4.0259}, + wpi::units::meters<>{0.308102}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 1.0, @@ -1175,9 +1175,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2025_REEFSCAPE_WELDED[] = { 22, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{4.904739999999999}, - wpi::units::meter_t{3.3063179999999996}, - wpi::units::meter_t{0.308102}, + wpi::units::meters<>{4.904739999999999}, + wpi::units::meters<>{3.3063179999999996}, + wpi::units::meters<>{0.308102}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ -0.8660254037844387, @@ -1194,9 +1194,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2025_REEFSCAPE_ANDY_MARK[] = { 1, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{16.687292}, - wpi::units::meter_t{0.628142}, - wpi::units::meter_t{1.4859}, + wpi::units::meters<>{16.687292}, + wpi::units::meters<>{0.628142}, + wpi::units::meters<>{1.4859}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 0.4539904997395468, @@ -1210,9 +1210,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2025_REEFSCAPE_ANDY_MARK[] = { 2, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{16.687292}, - wpi::units::meter_t{7.414259999999999}, - wpi::units::meter_t{1.4859}, + wpi::units::meters<>{16.687292}, + wpi::units::meters<>{7.414259999999999}, + wpi::units::meters<>{1.4859}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ -0.45399049973954675, @@ -1226,9 +1226,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2025_REEFSCAPE_ANDY_MARK[] = { 3, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{11.49096}, - wpi::units::meter_t{8.031733999999998}, - wpi::units::meter_t{1.30175}, + wpi::units::meters<>{11.49096}, + wpi::units::meters<>{8.031733999999998}, + wpi::units::meters<>{1.30175}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ -0.7071067811865475, @@ -1242,9 +1242,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2025_REEFSCAPE_ANDY_MARK[] = { 4, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{9.276079999999999}, - wpi::units::meter_t{6.132575999999999}, - wpi::units::meter_t{1.8679160000000001}, + wpi::units::meters<>{9.276079999999999}, + wpi::units::meters<>{6.132575999999999}, + wpi::units::meters<>{1.8679160000000001}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 0.9659258262890683, @@ -1258,9 +1258,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2025_REEFSCAPE_ANDY_MARK[] = { 5, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{9.276079999999999}, - wpi::units::meter_t{1.9098259999999998}, - wpi::units::meter_t{1.8679160000000001}, + wpi::units::meters<>{9.276079999999999}, + wpi::units::meters<>{1.9098259999999998}, + wpi::units::meters<>{1.8679160000000001}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 0.9659258262890683, @@ -1274,9 +1274,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2025_REEFSCAPE_ANDY_MARK[] = { 6, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{13.474446}, - wpi::units::meter_t{3.3012379999999997}, - wpi::units::meter_t{0.308102}, + wpi::units::meters<>{13.474446}, + wpi::units::meters<>{3.3012379999999997}, + wpi::units::meters<>{0.308102}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ -0.8660254037844387, @@ -1290,9 +1290,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2025_REEFSCAPE_ANDY_MARK[] = { 7, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{13.890498}, - wpi::units::meter_t{4.0208200000000005}, - wpi::units::meter_t{0.308102}, + wpi::units::meters<>{13.890498}, + wpi::units::meters<>{4.0208200000000005}, + wpi::units::meters<>{0.308102}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 1.0, @@ -1306,9 +1306,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2025_REEFSCAPE_ANDY_MARK[] = { 8, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{13.474446}, - wpi::units::meter_t{4.740402}, - wpi::units::meter_t{0.308102}, + wpi::units::meters<>{13.474446}, + wpi::units::meters<>{4.740402}, + wpi::units::meters<>{0.308102}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 0.8660254037844387, @@ -1322,9 +1322,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2025_REEFSCAPE_ANDY_MARK[] = { 9, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{12.643358}, - wpi::units::meter_t{4.740402}, - wpi::units::meter_t{0.308102}, + wpi::units::meters<>{12.643358}, + wpi::units::meters<>{4.740402}, + wpi::units::meters<>{0.308102}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 0.5000000000000001, @@ -1338,9 +1338,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2025_REEFSCAPE_ANDY_MARK[] = { 10, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{12.227305999999999}, - wpi::units::meter_t{4.0208200000000005}, - wpi::units::meter_t{0.308102}, + wpi::units::meters<>{12.227305999999999}, + wpi::units::meters<>{4.0208200000000005}, + wpi::units::meters<>{0.308102}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 6.123233995736766e-17, @@ -1354,9 +1354,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2025_REEFSCAPE_ANDY_MARK[] = { 11, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{12.643358}, - wpi::units::meter_t{3.3012379999999997}, - wpi::units::meter_t{0.308102}, + wpi::units::meters<>{12.643358}, + wpi::units::meters<>{3.3012379999999997}, + wpi::units::meters<>{0.308102}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ -0.4999999999999998, @@ -1370,9 +1370,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2025_REEFSCAPE_ANDY_MARK[] = { 12, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{0.8613139999999999}, - wpi::units::meter_t{0.628142}, - wpi::units::meter_t{1.4859}, + wpi::units::meters<>{0.8613139999999999}, + wpi::units::meters<>{0.628142}, + wpi::units::meters<>{1.4859}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 0.8910065241883679, @@ -1386,9 +1386,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2025_REEFSCAPE_ANDY_MARK[] = { 13, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{0.8613139999999999}, - wpi::units::meter_t{7.414259999999999}, - wpi::units::meter_t{1.4859}, + wpi::units::meters<>{0.8613139999999999}, + wpi::units::meters<>{7.414259999999999}, + wpi::units::meters<>{1.4859}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ -0.8910065241883678, @@ -1402,9 +1402,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2025_REEFSCAPE_ANDY_MARK[] = { 14, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{8.272272}, - wpi::units::meter_t{6.132575999999999}, - wpi::units::meter_t{1.8679160000000001}, + wpi::units::meters<>{8.272272}, + wpi::units::meters<>{6.132575999999999}, + wpi::units::meters<>{1.8679160000000001}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 5.914589856893349e-17, @@ -1418,9 +1418,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2025_REEFSCAPE_ANDY_MARK[] = { 15, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{8.272272}, - wpi::units::meter_t{1.9098259999999998}, - wpi::units::meter_t{1.8679160000000001}, + wpi::units::meters<>{8.272272}, + wpi::units::meters<>{1.9098259999999998}, + wpi::units::meters<>{1.8679160000000001}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 5.914589856893349e-17, @@ -1434,9 +1434,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2025_REEFSCAPE_ANDY_MARK[] = { 16, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{6.057646}, - wpi::units::meter_t{0.010667999999999999}, - wpi::units::meter_t{1.30175}, + wpi::units::meters<>{6.057646}, + wpi::units::meters<>{0.010667999999999999}, + wpi::units::meters<>{1.30175}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 0.7071067811865476, @@ -1450,9 +1450,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2025_REEFSCAPE_ANDY_MARK[] = { 17, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{4.073905999999999}, - wpi::units::meter_t{3.3012379999999997}, - wpi::units::meter_t{0.308102}, + wpi::units::meters<>{4.073905999999999}, + wpi::units::meters<>{3.3012379999999997}, + wpi::units::meters<>{0.308102}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ -0.4999999999999998, @@ -1466,9 +1466,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2025_REEFSCAPE_ANDY_MARK[] = { 18, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{3.6576}, - wpi::units::meter_t{4.0208200000000005}, - wpi::units::meter_t{0.308102}, + wpi::units::meters<>{3.6576}, + wpi::units::meters<>{4.0208200000000005}, + wpi::units::meters<>{0.308102}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 6.123233995736766e-17, @@ -1482,9 +1482,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2025_REEFSCAPE_ANDY_MARK[] = { 19, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{4.073905999999999}, - wpi::units::meter_t{4.740402}, - wpi::units::meter_t{0.308102}, + wpi::units::meters<>{4.073905999999999}, + wpi::units::meters<>{4.740402}, + wpi::units::meters<>{0.308102}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 0.5000000000000001, @@ -1498,9 +1498,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2025_REEFSCAPE_ANDY_MARK[] = { 20, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{4.904739999999999}, - wpi::units::meter_t{4.740402}, - wpi::units::meter_t{0.308102}, + wpi::units::meters<>{4.904739999999999}, + wpi::units::meters<>{4.740402}, + wpi::units::meters<>{0.308102}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 0.8660254037844387, @@ -1514,9 +1514,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2025_REEFSCAPE_ANDY_MARK[] = { 21, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{5.321046}, - wpi::units::meter_t{4.0208200000000005}, - wpi::units::meter_t{0.308102}, + wpi::units::meters<>{5.321046}, + wpi::units::meters<>{4.0208200000000005}, + wpi::units::meters<>{0.308102}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 1.0, @@ -1530,9 +1530,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2025_REEFSCAPE_ANDY_MARK[] = { 22, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{4.904739999999999}, - wpi::units::meter_t{3.3012379999999997}, - wpi::units::meter_t{0.308102}, + wpi::units::meters<>{4.904739999999999}, + wpi::units::meters<>{3.3012379999999997}, + wpi::units::meters<>{0.308102}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ -0.8660254037844387, @@ -1549,9 +1549,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2026_REBUILT_WELDED[] = { 1, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{11.8779798}, - wpi::units::meter_t{7.4247756}, - wpi::units::meter_t{0.889}, + wpi::units::meters<>{11.8779798}, + wpi::units::meters<>{7.4247756}, + wpi::units::meters<>{0.889}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 6.123233995736766e-17, @@ -1565,9 +1565,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2026_REBUILT_WELDED[] = { 2, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{11.9154194}, - wpi::units::meter_t{4.638039999999999}, - wpi::units::meter_t{1.12395}, + wpi::units::meters<>{11.9154194}, + wpi::units::meters<>{4.638039999999999}, + wpi::units::meters<>{1.12395}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 0.7071067811865476, @@ -1581,9 +1581,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2026_REBUILT_WELDED[] = { 3, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{11.3118646}, - wpi::units::meter_t{4.3902376}, - wpi::units::meter_t{1.12395}, + wpi::units::meters<>{11.3118646}, + wpi::units::meters<>{4.3902376}, + wpi::units::meters<>{1.12395}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 6.123233995736766e-17, @@ -1597,9 +1597,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2026_REBUILT_WELDED[] = { 4, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{11.3118646}, - wpi::units::meter_t{4.0346376}, - wpi::units::meter_t{1.12395}, + wpi::units::meters<>{11.3118646}, + wpi::units::meters<>{4.0346376}, + wpi::units::meters<>{1.12395}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 6.123233995736766e-17, @@ -1613,9 +1613,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2026_REBUILT_WELDED[] = { 5, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{11.9154194}, - wpi::units::meter_t{3.4312351999999997}, - wpi::units::meter_t{1.12395}, + wpi::units::meters<>{11.9154194}, + wpi::units::meters<>{3.4312351999999997}, + wpi::units::meters<>{1.12395}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ -0.7071067811865475, @@ -1629,9 +1629,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2026_REBUILT_WELDED[] = { 6, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{11.8779798}, - wpi::units::meter_t{0.6444996}, - wpi::units::meter_t{0.889}, + wpi::units::meters<>{11.8779798}, + wpi::units::meters<>{0.6444996}, + wpi::units::meters<>{0.889}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 6.123233995736766e-17, @@ -1645,9 +1645,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2026_REBUILT_WELDED[] = { 7, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{11.9528844}, - wpi::units::meter_t{0.6444996}, - wpi::units::meter_t{0.889}, + wpi::units::meters<>{11.9528844}, + wpi::units::meters<>{0.6444996}, + wpi::units::meters<>{0.889}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 1.0, @@ -1661,9 +1661,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2026_REBUILT_WELDED[] = { 8, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{12.2710194}, - wpi::units::meter_t{3.4312351999999997}, - wpi::units::meter_t{1.12395}, + wpi::units::meters<>{12.2710194}, + wpi::units::meters<>{3.4312351999999997}, + wpi::units::meters<>{1.12395}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ -0.7071067811865475, @@ -1677,9 +1677,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2026_REBUILT_WELDED[] = { 9, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{12.519177399999998}, - wpi::units::meter_t{3.6790375999999996}, - wpi::units::meter_t{1.12395}, + wpi::units::meters<>{12.519177399999998}, + wpi::units::meters<>{3.6790375999999996}, + wpi::units::meters<>{1.12395}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 1.0, @@ -1693,9 +1693,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2026_REBUILT_WELDED[] = { 10, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{12.519177399999998}, - wpi::units::meter_t{4.0346376}, - wpi::units::meter_t{1.12395}, + wpi::units::meters<>{12.519177399999998}, + wpi::units::meters<>{4.0346376}, + wpi::units::meters<>{1.12395}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 1.0, @@ -1709,9 +1709,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2026_REBUILT_WELDED[] = { 11, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{12.2710194}, - wpi::units::meter_t{4.638039999999999}, - wpi::units::meter_t{1.12395}, + wpi::units::meters<>{12.2710194}, + wpi::units::meters<>{4.638039999999999}, + wpi::units::meters<>{1.12395}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 0.7071067811865476, @@ -1725,9 +1725,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2026_REBUILT_WELDED[] = { 12, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{11.9528844}, - wpi::units::meter_t{7.4247756}, - wpi::units::meter_t{0.889}, + wpi::units::meters<>{11.9528844}, + wpi::units::meters<>{7.4247756}, + wpi::units::meters<>{0.889}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 1.0, @@ -1741,9 +1741,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2026_REBUILT_WELDED[] = { 13, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{16.5333172}, - wpi::units::meter_t{7.4033126}, - wpi::units::meter_t{0.55245}, + wpi::units::meters<>{16.5333172}, + wpi::units::meters<>{7.4033126}, + wpi::units::meters<>{0.55245}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 6.123233995736766e-17, @@ -1757,9 +1757,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2026_REBUILT_WELDED[] = { 14, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{16.5333172}, - wpi::units::meter_t{6.9715126}, - wpi::units::meter_t{0.55245}, + wpi::units::meters<>{16.5333172}, + wpi::units::meters<>{6.9715126}, + wpi::units::meters<>{0.55245}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 6.123233995736766e-17, @@ -1773,9 +1773,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2026_REBUILT_WELDED[] = { 15, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{16.5329616}, - wpi::units::meter_t{4.3235626}, - wpi::units::meter_t{0.55245}, + wpi::units::meters<>{16.5329616}, + wpi::units::meters<>{4.3235626}, + wpi::units::meters<>{0.55245}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 6.123233995736766e-17, @@ -1789,9 +1789,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2026_REBUILT_WELDED[] = { 16, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{16.5329616}, - wpi::units::meter_t{3.8917626}, - wpi::units::meter_t{0.55245}, + wpi::units::meters<>{16.5329616}, + wpi::units::meters<>{3.8917626}, + wpi::units::meters<>{0.55245}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 6.123233995736766e-17, @@ -1805,9 +1805,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2026_REBUILT_WELDED[] = { 17, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{4.6630844}, - wpi::units::meter_t{0.6444996}, - wpi::units::meter_t{0.889}, + wpi::units::meters<>{4.6630844}, + wpi::units::meters<>{0.6444996}, + wpi::units::meters<>{0.889}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 1.0, @@ -1821,9 +1821,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2026_REBUILT_WELDED[] = { 18, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{4.6256194}, - wpi::units::meter_t{3.4312351999999997}, - wpi::units::meter_t{1.12395}, + wpi::units::meters<>{4.6256194}, + wpi::units::meters<>{3.4312351999999997}, + wpi::units::meters<>{1.12395}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ -0.7071067811865475, @@ -1837,9 +1837,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2026_REBUILT_WELDED[] = { 19, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{5.229174199999999}, - wpi::units::meter_t{3.6790375999999996}, - wpi::units::meter_t{1.12395}, + wpi::units::meters<>{5.229174199999999}, + wpi::units::meters<>{3.6790375999999996}, + wpi::units::meters<>{1.12395}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 1.0, @@ -1853,9 +1853,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2026_REBUILT_WELDED[] = { 20, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{5.229174199999999}, - wpi::units::meter_t{4.0346376}, - wpi::units::meter_t{1.12395}, + wpi::units::meters<>{5.229174199999999}, + wpi::units::meters<>{4.0346376}, + wpi::units::meters<>{1.12395}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 1.0, @@ -1869,9 +1869,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2026_REBUILT_WELDED[] = { 21, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{4.6256194}, - wpi::units::meter_t{4.638039999999999}, - wpi::units::meter_t{1.12395}, + wpi::units::meters<>{4.6256194}, + wpi::units::meters<>{4.638039999999999}, + wpi::units::meters<>{1.12395}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 0.7071067811865476, @@ -1885,9 +1885,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2026_REBUILT_WELDED[] = { 22, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{4.6630844}, - wpi::units::meter_t{7.4247756}, - wpi::units::meter_t{0.889}, + wpi::units::meters<>{4.6630844}, + wpi::units::meters<>{7.4247756}, + wpi::units::meters<>{0.889}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 1.0, @@ -1901,9 +1901,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2026_REBUILT_WELDED[] = { 23, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{4.5881798}, - wpi::units::meter_t{7.4247756}, - wpi::units::meter_t{0.889}, + wpi::units::meters<>{4.5881798}, + wpi::units::meters<>{7.4247756}, + wpi::units::meters<>{0.889}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 6.123233995736766e-17, @@ -1917,9 +1917,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2026_REBUILT_WELDED[] = { 24, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{4.2700194}, - wpi::units::meter_t{4.638039999999999}, - wpi::units::meter_t{1.12395}, + wpi::units::meters<>{4.2700194}, + wpi::units::meters<>{4.638039999999999}, + wpi::units::meters<>{1.12395}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 0.7071067811865476, @@ -1933,9 +1933,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2026_REBUILT_WELDED[] = { 25, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{4.0218614}, - wpi::units::meter_t{4.3902376}, - wpi::units::meter_t{1.12395}, + wpi::units::meters<>{4.0218614}, + wpi::units::meters<>{4.3902376}, + wpi::units::meters<>{1.12395}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 6.123233995736766e-17, @@ -1949,9 +1949,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2026_REBUILT_WELDED[] = { 26, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{4.0218614}, - wpi::units::meter_t{4.0346376}, - wpi::units::meter_t{1.12395}, + wpi::units::meters<>{4.0218614}, + wpi::units::meters<>{4.0346376}, + wpi::units::meters<>{1.12395}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 6.123233995736766e-17, @@ -1965,9 +1965,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2026_REBUILT_WELDED[] = { 27, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{4.2700194}, - wpi::units::meter_t{3.4312351999999997}, - wpi::units::meter_t{1.12395}, + wpi::units::meters<>{4.2700194}, + wpi::units::meters<>{3.4312351999999997}, + wpi::units::meters<>{1.12395}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ -0.7071067811865475, @@ -1981,9 +1981,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2026_REBUILT_WELDED[] = { 28, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{4.5881798}, - wpi::units::meter_t{0.6444996}, - wpi::units::meter_t{0.889}, + wpi::units::meters<>{4.5881798}, + wpi::units::meters<>{0.6444996}, + wpi::units::meters<>{0.889}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 6.123233995736766e-17, @@ -1997,9 +1997,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2026_REBUILT_WELDED[] = { 29, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{0.0077469999999999995}, - wpi::units::meter_t{0.6659626}, - wpi::units::meter_t{0.55245}, + wpi::units::meters<>{0.0077469999999999995}, + wpi::units::meters<>{0.6659626}, + wpi::units::meters<>{0.55245}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 1.0, @@ -2013,9 +2013,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2026_REBUILT_WELDED[] = { 30, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{0.0077469999999999995}, - wpi::units::meter_t{1.0977626}, - wpi::units::meter_t{0.55245}, + wpi::units::meters<>{0.0077469999999999995}, + wpi::units::meters<>{1.0977626}, + wpi::units::meters<>{0.55245}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 1.0, @@ -2029,9 +2029,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2026_REBUILT_WELDED[] = { 31, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{0.0080772}, - wpi::units::meter_t{3.7457125999999996}, - wpi::units::meter_t{0.55245}, + wpi::units::meters<>{0.0080772}, + wpi::units::meters<>{3.7457125999999996}, + wpi::units::meters<>{0.55245}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 1.0, @@ -2045,9 +2045,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2026_REBUILT_WELDED[] = { 32, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{0.0080772}, - wpi::units::meter_t{4.1775126}, - wpi::units::meter_t{0.55245}, + wpi::units::meters<>{0.0080772}, + wpi::units::meters<>{4.1775126}, + wpi::units::meters<>{0.55245}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 1.0, @@ -2064,9 +2064,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2026_REBUILT_ANDY_MARK[] = { 1, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{11.863959}, - wpi::units::meter_t{7.411491399999999}, - wpi::units::meter_t{0.889}, + wpi::units::meters<>{11.863959}, + wpi::units::meters<>{7.411491399999999}, + wpi::units::meters<>{0.889}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 6.123233995736766e-17, @@ -2080,9 +2080,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2026_REBUILT_ANDY_MARK[] = { 2, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{11.9013986}, - wpi::units::meter_t{4.6247558}, - wpi::units::meter_t{1.12395}, + wpi::units::meters<>{11.9013986}, + wpi::units::meters<>{4.6247558}, + wpi::units::meters<>{1.12395}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 0.7071067811865476, @@ -2096,9 +2096,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2026_REBUILT_ANDY_MARK[] = { 3, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{11.2978438}, - wpi::units::meter_t{4.3769534}, - wpi::units::meter_t{1.12395}, + wpi::units::meters<>{11.2978438}, + wpi::units::meters<>{4.3769534}, + wpi::units::meters<>{1.12395}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 6.123233995736766e-17, @@ -2112,9 +2112,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2026_REBUILT_ANDY_MARK[] = { 4, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{11.2978438}, - wpi::units::meter_t{4.0213534}, - wpi::units::meter_t{1.12395}, + wpi::units::meters<>{11.2978438}, + wpi::units::meters<>{4.0213534}, + wpi::units::meters<>{1.12395}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 6.123233995736766e-17, @@ -2128,9 +2128,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2026_REBUILT_ANDY_MARK[] = { 5, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{11.9013986}, - wpi::units::meter_t{3.417951}, - wpi::units::meter_t{1.12395}, + wpi::units::meters<>{11.9013986}, + wpi::units::meters<>{3.417951}, + wpi::units::meters<>{1.12395}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ -0.7071067811865475, @@ -2144,9 +2144,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2026_REBUILT_ANDY_MARK[] = { 6, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{11.863959}, - wpi::units::meter_t{0.6312154}, - wpi::units::meter_t{0.889}, + wpi::units::meters<>{11.863959}, + wpi::units::meters<>{0.6312154}, + wpi::units::meters<>{0.889}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 6.123233995736766e-17, @@ -2160,9 +2160,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2026_REBUILT_ANDY_MARK[] = { 7, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{11.9388636}, - wpi::units::meter_t{0.6312154}, - wpi::units::meter_t{0.889}, + wpi::units::meters<>{11.9388636}, + wpi::units::meters<>{0.6312154}, + wpi::units::meters<>{0.889}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 1.0, @@ -2176,9 +2176,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2026_REBUILT_ANDY_MARK[] = { 8, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{12.2569986}, - wpi::units::meter_t{3.417951}, - wpi::units::meter_t{1.12395}, + wpi::units::meters<>{12.2569986}, + wpi::units::meters<>{3.417951}, + wpi::units::meters<>{1.12395}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ -0.7071067811865475, @@ -2192,9 +2192,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2026_REBUILT_ANDY_MARK[] = { 9, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{12.5051566}, - wpi::units::meter_t{3.6657534}, - wpi::units::meter_t{1.12395}, + wpi::units::meters<>{12.5051566}, + wpi::units::meters<>{3.6657534}, + wpi::units::meters<>{1.12395}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 1.0, @@ -2208,9 +2208,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2026_REBUILT_ANDY_MARK[] = { 10, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{12.5051566}, - wpi::units::meter_t{4.0213534}, - wpi::units::meter_t{1.12395}, + wpi::units::meters<>{12.5051566}, + wpi::units::meters<>{4.0213534}, + wpi::units::meters<>{1.12395}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 1.0, @@ -2224,9 +2224,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2026_REBUILT_ANDY_MARK[] = { 11, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{12.2569986}, - wpi::units::meter_t{4.6247558}, - wpi::units::meter_t{1.12395}, + wpi::units::meters<>{12.2569986}, + wpi::units::meters<>{4.6247558}, + wpi::units::meters<>{1.12395}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 0.7071067811865476, @@ -2240,9 +2240,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2026_REBUILT_ANDY_MARK[] = { 12, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{11.9388636}, - wpi::units::meter_t{7.411491399999999}, - wpi::units::meter_t{0.889}, + wpi::units::meters<>{11.9388636}, + wpi::units::meters<>{7.411491399999999}, + wpi::units::meters<>{0.889}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 1.0, @@ -2256,9 +2256,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2026_REBUILT_ANDY_MARK[] = { 13, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{16.499332}, - wpi::units::meter_t{7.391907999999999}, - wpi::units::meter_t{0.55245}, + wpi::units::meters<>{16.499332}, + wpi::units::meters<>{7.391907999999999}, + wpi::units::meters<>{0.55245}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 6.123233995736766e-17, @@ -2272,9 +2272,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2026_REBUILT_ANDY_MARK[] = { 14, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{16.499332}, - wpi::units::meter_t{6.960107999999999}, - wpi::units::meter_t{0.55245}, + wpi::units::meters<>{16.499332}, + wpi::units::meters<>{6.960107999999999}, + wpi::units::meters<>{0.55245}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 6.123233995736766e-17, @@ -2288,9 +2288,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2026_REBUILT_ANDY_MARK[] = { 15, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{16.4989764}, - wpi::units::meter_t{4.3124882}, - wpi::units::meter_t{0.55245}, + wpi::units::meters<>{16.4989764}, + wpi::units::meters<>{4.3124882}, + wpi::units::meters<>{0.55245}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 6.123233995736766e-17, @@ -2304,9 +2304,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2026_REBUILT_ANDY_MARK[] = { 16, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{16.4989764}, - wpi::units::meter_t{3.8806881999999994}, - wpi::units::meter_t{0.55245}, + wpi::units::meters<>{16.4989764}, + wpi::units::meters<>{3.8806881999999994}, + wpi::units::meters<>{0.55245}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 6.123233995736766e-17, @@ -2320,9 +2320,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2026_REBUILT_ANDY_MARK[] = { 17, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{4.6490636}, - wpi::units::meter_t{0.6312154}, - wpi::units::meter_t{0.889}, + wpi::units::meters<>{4.6490636}, + wpi::units::meters<>{0.6312154}, + wpi::units::meters<>{0.889}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 1.0, @@ -2336,9 +2336,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2026_REBUILT_ANDY_MARK[] = { 18, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{4.6115986}, - wpi::units::meter_t{3.417951}, - wpi::units::meter_t{1.12395}, + wpi::units::meters<>{4.6115986}, + wpi::units::meters<>{3.417951}, + wpi::units::meters<>{1.12395}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ -0.7071067811865475, @@ -2352,9 +2352,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2026_REBUILT_ANDY_MARK[] = { 19, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{5.2151534}, - wpi::units::meter_t{3.6657534}, - wpi::units::meter_t{1.12395}, + wpi::units::meters<>{5.2151534}, + wpi::units::meters<>{3.6657534}, + wpi::units::meters<>{1.12395}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 1.0, @@ -2368,9 +2368,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2026_REBUILT_ANDY_MARK[] = { 20, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{5.2151534}, - wpi::units::meter_t{4.0213534}, - wpi::units::meter_t{1.12395}, + wpi::units::meters<>{5.2151534}, + wpi::units::meters<>{4.0213534}, + wpi::units::meters<>{1.12395}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 1.0, @@ -2384,9 +2384,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2026_REBUILT_ANDY_MARK[] = { 21, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{4.6115986}, - wpi::units::meter_t{4.6247558}, - wpi::units::meter_t{1.12395}, + wpi::units::meters<>{4.6115986}, + wpi::units::meters<>{4.6247558}, + wpi::units::meters<>{1.12395}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 0.7071067811865476, @@ -2400,9 +2400,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2026_REBUILT_ANDY_MARK[] = { 22, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{4.6490636}, - wpi::units::meter_t{7.411491399999999}, - wpi::units::meter_t{0.889}, + wpi::units::meters<>{4.6490636}, + wpi::units::meters<>{7.411491399999999}, + wpi::units::meters<>{0.889}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 1.0, @@ -2416,9 +2416,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2026_REBUILT_ANDY_MARK[] = { 23, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{4.574159}, - wpi::units::meter_t{7.411491399999999}, - wpi::units::meter_t{0.889}, + wpi::units::meters<>{4.574159}, + wpi::units::meters<>{7.411491399999999}, + wpi::units::meters<>{0.889}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 6.123233995736766e-17, @@ -2432,9 +2432,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2026_REBUILT_ANDY_MARK[] = { 24, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{4.2559986}, - wpi::units::meter_t{4.6247558}, - wpi::units::meter_t{1.12395}, + wpi::units::meters<>{4.2559986}, + wpi::units::meters<>{4.6247558}, + wpi::units::meters<>{1.12395}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 0.7071067811865476, @@ -2448,9 +2448,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2026_REBUILT_ANDY_MARK[] = { 25, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{4.007866}, - wpi::units::meter_t{4.3769534}, - wpi::units::meter_t{1.12395}, + wpi::units::meters<>{4.007866}, + wpi::units::meters<>{4.3769534}, + wpi::units::meters<>{1.12395}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 6.123233995736766e-17, @@ -2464,9 +2464,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2026_REBUILT_ANDY_MARK[] = { 26, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{4.007866}, - wpi::units::meter_t{4.0213534}, - wpi::units::meter_t{1.12395}, + wpi::units::meters<>{4.007866}, + wpi::units::meters<>{4.0213534}, + wpi::units::meters<>{1.12395}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 6.123233995736766e-17, @@ -2480,9 +2480,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2026_REBUILT_ANDY_MARK[] = { 27, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{4.2559986}, - wpi::units::meter_t{3.417951}, - wpi::units::meter_t{1.12395}, + wpi::units::meters<>{4.2559986}, + wpi::units::meters<>{3.417951}, + wpi::units::meters<>{1.12395}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ -0.7071067811865475, @@ -2496,9 +2496,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2026_REBUILT_ANDY_MARK[] = { 28, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{4.574159}, - wpi::units::meter_t{0.6312154}, - wpi::units::meter_t{0.889}, + wpi::units::meters<>{4.574159}, + wpi::units::meters<>{0.6312154}, + wpi::units::meters<>{0.889}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 6.123233995736766e-17, @@ -2512,9 +2512,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2026_REBUILT_ANDY_MARK[] = { 29, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{0.0136906}, - wpi::units::meter_t{0.6507734}, - wpi::units::meter_t{0.55245}, + wpi::units::meters<>{0.0136906}, + wpi::units::meters<>{0.6507734}, + wpi::units::meters<>{0.55245}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 1.0, @@ -2528,9 +2528,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2026_REBUILT_ANDY_MARK[] = { 30, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{0.0136906}, - wpi::units::meter_t{1.0825734}, - wpi::units::meter_t{0.55245}, + wpi::units::meters<>{0.0136906}, + wpi::units::meters<>{1.0825734}, + wpi::units::meters<>{0.55245}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 1.0, @@ -2544,9 +2544,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2026_REBUILT_ANDY_MARK[] = { 31, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{0.0140462}, - wpi::units::meter_t{3.7301932}, - wpi::units::meter_t{0.55245}, + wpi::units::meters<>{0.0140462}, + wpi::units::meters<>{3.7301932}, + wpi::units::meters<>{0.55245}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 1.0, @@ -2560,9 +2560,9 @@ static constexpr FieldTag FIELD_TAGS_FRC_2026_REBUILT_ANDY_MARK[] = { 32, wpi::math::Pose3d{ wpi::math::Translation3d{ - wpi::units::meter_t{0.0140462}, - wpi::units::meter_t{4.1619931999999995}, - wpi::units::meter_t{0.55245}, + wpi::units::meters<>{0.0140462}, + wpi::units::meters<>{4.1619931999999995}, + wpi::units::meters<>{0.55245}, }, wpi::math::Rotation3d{wpi::math::Quaternion{ 1.0, @@ -2926,8 +2926,8 @@ Field GetField(FieldId field) { result.m_image.emplace(data.fieldImage, data.top, data.left, data.bottom, data.right); } - result.m_fieldLength = wpi::units::meter_t{data.length}; - result.m_fieldWidth = wpi::units::meter_t{data.width}; + result.m_fieldLength = wpi::units::meters<>{data.length}; + result.m_fieldWidth = wpi::units::meters<>{data.width}; result.m_program = data.program; result.m_resourceFile = data.resourceFile; result.m_hasTags = data.hasTags; diff --git a/fields/src/main/native/cpp/Field.cpp b/fields/src/main/native/cpp/Field.cpp index 0afd3c06415..5db4c03b961 100644 --- a/fields/src/main/native/cpp/Field.cpp +++ b/fields/src/main/native/cpp/Field.cpp @@ -35,7 +35,7 @@ Field::Field(std::string_view path) { Field::Field(std::string_view name, std::string_view season, std::string_view game, std::optional image, - wpi::units::meter_t fieldLength, wpi::units::meter_t fieldWidth, + wpi::units::meters<> fieldLength, wpi::units::meters<> fieldWidth, std::string_view program, std::vector tags) : m_name{name}, m_season{season}, @@ -90,11 +90,11 @@ std::optional Field::GetImage() const { return m_image; } -wpi::units::meter_t Field::GetLength() const { +wpi::units::meters<> Field::GetLength() const { return m_fieldLength; } -wpi::units::meter_t Field::GetWidth() const { +wpi::units::meters<> Field::GetWidth() const { return m_fieldWidth; } @@ -245,10 +245,10 @@ void wpi::fields::from_json(const wpi::util::json& json, Field& field) { field.m_image = json.at("field-image").get(); } - field.m_fieldLength = wpi::units::meter_t{ + field.m_fieldLength = wpi::units::meters<>{ json.at("field-dimensions").at("length").get_number()}; - field.m_fieldWidth = - wpi::units::meter_t{json.at("field-dimensions").at("width").get_number()}; + field.m_fieldWidth = wpi::units::meters<>{ + json.at("field-dimensions").at("width").get_number()}; field.m_program = json.at("program").get_string(); field.m_resourceFile.clear(); field.m_hasTags = json.contains("field-tags"); diff --git a/fields/src/main/native/include/wpi/fields/Field.hpp b/fields/src/main/native/include/wpi/fields/Field.hpp index 09aaf67a5a7..f3c700aa819 100644 --- a/fields/src/main/native/include/wpi/fields/Field.hpp +++ b/fields/src/main/native/include/wpi/fields/Field.hpp @@ -70,8 +70,8 @@ class WPILIB_DLLEXPORT Field final { * @param tags Field tag metadata. */ Field(std::string_view name, std::string_view season, std::string_view game, - std::optional image, wpi::units::meter_t fieldLength, - wpi::units::meter_t fieldWidth, std::string_view program, + std::optional image, wpi::units::meters<> fieldLength, + wpi::units::meters<> fieldWidth, std::string_view program, std::vector tags = {}); Field(const Field& other); @@ -122,14 +122,14 @@ class WPILIB_DLLEXPORT Field final { * * @return Length. */ - wpi::units::meter_t GetLength() const; + wpi::units::meters<> GetLength() const; /** * Gets the width. * * @return Width. */ - wpi::units::meter_t GetWidth() const; + wpi::units::meters<> GetWidth() const; /** * Returns the FIRST program. @@ -227,8 +227,8 @@ class WPILIB_DLLEXPORT Field final { std::string m_season; std::string m_game; std::optional m_image; - wpi::units::meter_t m_fieldLength; - wpi::units::meter_t m_fieldWidth; + wpi::units::meters<> m_fieldLength; + wpi::units::meters<> m_fieldWidth; std::string m_program; std::string m_resourceFile; bool m_hasTags = false; diff --git a/fields/src/main/python/semiwrap/Field.yml b/fields/src/main/python/semiwrap/Field.yml index a42f2ac8583..51c89f0ff08 100644 --- a/fields/src/main/python/semiwrap/Field.yml +++ b/fields/src/main/python/semiwrap/Field.yml @@ -19,7 +19,7 @@ classes: overloads: "": std::string_view: - ? std::string_view, std::string_view, std::string_view, std::optional, wpi::units::meter_t, wpi::units::meter_t, std::string_view, std::vector + ? std::string_view, std::string_view, std::string_view, std::optional, wpi::units::meters<>, wpi::units::meters<>, std::string_view, std::vector : operator==: GetName: diff --git a/glass/src/lib/native/cpp/other/Field2D.cpp b/glass/src/lib/native/cpp/other/Field2D.cpp index f2cb5cc0a98..2e8354c4a47 100644 --- a/glass/src/lib/native/cpp/other/Field2D.cpp +++ b/glass/src/lib/native/cpp/other/Field2D.cpp @@ -53,10 +53,10 @@ constexpr std::string_view POSE2D_ARRAY_TYPE = "struct:Pose2d[]"; // Per-frame field data (not persistent) struct FieldFrameData { wpi::math::Translation2d GetPosFromScreen(const ImVec2& cursor) const { - return {wpi::units::meter_t{(std::clamp(cursor.x, min.x, max.x) - min.x) / - scale}, - wpi::units::meter_t{(max.y - std::clamp(cursor.y, min.y, max.y)) / - scale}}; + return {wpi::units::meters<>{(std::clamp(cursor.x, min.x, max.x) - min.x) / + scale}, + wpi::units::meters<>{(max.y - std::clamp(cursor.y, min.y, max.y)) / + scale}}; } ImVec2 GetScreenFromPos(const wpi::math::Translation2d& pos) const { return {min.x + scale * pos.X().to(), @@ -77,7 +77,7 @@ struct SelectedTargetInfo { FieldObjectModel* objModel = nullptr; std::string name; size_t index; - wpi::units::radian_t rot; + wpi::units::radians<> rot; ImVec2 poseCenter; // center of the pose (screen coordinates) ImVec2 center; // center of the target (screen coordinates) float radius; // target radius @@ -89,7 +89,7 @@ struct SelectedTargetInfo { struct PoseDragState { SelectedTargetInfo target; ImVec2 initialOffset; - wpi::units::radian_t initialAngle = 0_rad; + wpi::units::radians<> initialAngle = 0_rad; }; // Popup edit state @@ -141,8 +141,8 @@ struct DisplayOptions { float weight = DEFAULT_WEIGHT; int color = DEFAULT_COLOR; - wpi::units::meter_t width = DEFAULT_WIDTH; - wpi::units::meter_t length = DEFAULT_LENGTH; + wpi::units::meters<> width = DEFAULT_WIDTH; + wpi::units::meters<> length = DEFAULT_LENGTH; bool arrows = DEFAULT_ARROWS; int arrowSize = DEFAULT_ARROW_SIZE; @@ -161,7 +161,7 @@ class PoseFrameData { size_t index, const FieldFrameData& ffd, const DisplayOptions& displayOptions); void SetPosition(const wpi::math::Translation2d& pos); - void SetRotation(wpi::units::radian_t rot); + void SetRotation(wpi::units::radians<> rot); const wpi::math::Rotation2d& GetRotation() const { return m_pose.Rotation(); } const wpi::math::Pose2d& GetPose() const { return m_pose; } float GetHitRadius() const { return m_hitRadius; } @@ -275,19 +275,19 @@ static PoseDragState gDragState; static PopupState gPopupState; static DisplayUnits gDisplayUnits = DISPLAY_METERS; -static double ConvertDisplayLength(wpi::units::meter_t v) { +static double ConvertDisplayLength(wpi::units::meters<> v) { switch (gDisplayUnits) { case DISPLAY_FEET: - return v.convert().value(); + return v.convert().value(); case DISPLAY_INCHES: - return v.convert().value(); + return v.convert().value(); case DISPLAY_METERS: default: return v.value(); } } -static double ConvertDisplayAngle(wpi::units::degree_t v) { +static double ConvertDisplayAngle(wpi::units::degrees<> v) { return v.value(); } @@ -324,7 +324,7 @@ static void AcceptFieldObjectDrop(Field2DModel* model) { ImGui::EndDragDropTarget(); } -static bool InputLength(const char* label, wpi::units::meter_t* v, +static bool InputLength(const char* label, wpi::units::meters<>* v, double step = 0.0, double step_fast = 0.0, const char* format = "%.6f", ImGuiInputTextFlags flags = 0) { @@ -332,14 +332,14 @@ static bool InputLength(const char* label, wpi::units::meter_t* v, if (ImGui::InputDouble(label, &dv, step, step_fast, format, flags)) { switch (gDisplayUnits) { case DISPLAY_FEET: - *v = wpi::units::foot_t{dv}; + *v = wpi::units::feet<>{dv}; break; case DISPLAY_INCHES: - *v = wpi::units::inch_t{dv}; + *v = wpi::units::inches<>{dv}; break; case DISPLAY_METERS: default: - *v = wpi::units::meter_t{dv}; + *v = wpi::units::meters<>{dv}; break; } return true; @@ -351,7 +351,7 @@ static bool InputFloatLength(const char* label, float* v, double step = 0.0, double step_fast = 0.0, const char* format = "%.3f", ImGuiInputTextFlags flags = 0) { - wpi::units::meter_t uv{*v}; + wpi::units::meters<> uv{*v}; if (InputLength(label, &uv, step, step_fast, format, flags)) { *v = uv.to(); return true; @@ -359,13 +359,13 @@ static bool InputFloatLength(const char* label, float* v, double step = 0.0, return false; } -static bool InputAngle(const char* label, wpi::units::degree_t* v, +static bool InputAngle(const char* label, wpi::units::degrees<>* v, double step = 0.0, double step_fast = 0.0, const char* format = "%.6f", ImGuiInputTextFlags flags = 0) { double dv = ConvertDisplayAngle(*v); if (ImGui::InputDouble(label, &dv, step, step_fast, format, flags)) { - *v = wpi::units::degree_t{dv}; + *v = wpi::units::degrees<>{dv}; return true; } return false; @@ -660,8 +660,8 @@ DisplayOptions ObjectInfo::GetDisplayOptions() const { rv.style = static_cast(m_style.GetValue()); rv.weight = m_weight; rv.color = ImGui::ColorConvertFloat4ToU32(m_color.GetColor()); - rv.width = wpi::units::meter_t{m_width}; - rv.length = wpi::units::meter_t{m_length}; + rv.width = wpi::units::meters<>{m_width}; + rv.length = wpi::units::meters<>{m_length}; rv.arrows = m_arrows; rv.arrowSize = m_arrowSize; rv.arrowWeight = m_arrowWeight; @@ -801,7 +801,7 @@ void PoseFrameData::SetPosition(const wpi::math::Translation2d& pos) { m_model.SetPose(m_index, m_pose); } -void PoseFrameData::SetRotation(wpi::units::radian_t rot) { +void PoseFrameData::SetRotation(wpi::units::radians<> rot) { m_pose = wpi::math::Pose2d{m_pose.Translation(), rot}; m_model.SetPose(m_index, m_pose); } @@ -906,7 +906,7 @@ void PoseFrameData::HandleDrag(const ImVec2& cursor) { } else { ImVec2 off = cursor - m_center; SetRotation(gDragState.initialAngle - - wpi::units::radian_t{std::atan2(off.y, off.x)}); + wpi::units::radians<>{std::atan2(off.y, off.x)}); gDragState.target.center = m_corners[gDragState.target.corner - 2]; gDragState.target.rot = GetRotation().Radians(); } @@ -1099,8 +1099,8 @@ void FieldDisplay::Display(FieldInfo* field, Field2DModel* model, gDragState.initialOffset = m_mousePos - target->poseCenter; if (target->corner != 1) { gDragState.initialAngle = - wpi::units::radian_t{std::atan2(gDragState.initialOffset.y, - gDragState.initialOffset.x)} + + wpi::units::radians<>{std::atan2(gDragState.initialOffset.y, + gDragState.initialOffset.x)} + target->rot; } } diff --git a/glass/src/lib/native/cpp/other/Mechanism2D.cpp b/glass/src/lib/native/cpp/other/Mechanism2D.cpp index ef5a0273ced..21e90fc0d40 100644 --- a/glass/src/lib/native/cpp/other/Mechanism2D.cpp +++ b/glass/src/lib/native/cpp/other/Mechanism2D.cpp @@ -38,10 +38,10 @@ namespace { // Per-frame data (not persistent) struct FrameData { wpi::math::Translation2d GetPosFromScreen(const ImVec2& cursor) const { - return {wpi::units::meter_t{(std::clamp(cursor.x, min.x, max.x) - min.x) / - scale}, - wpi::units::meter_t{(max.y - std::clamp(cursor.y, min.y, max.y)) / - scale}}; + return {wpi::units::meters<>{(std::clamp(cursor.x, min.x, max.x) - min.x) / + scale}, + wpi::units::meters<>{(max.y - std::clamp(cursor.y, min.y, max.y)) / + scale}}; } ImVec2 GetScreenFromPos(const wpi::math::Translation2d& pos) const { return {min.x + scale * pos.X().to(), diff --git a/glass/src/lib/native/include/wpi/glass/other/Mechanism2D.hpp b/glass/src/lib/native/include/wpi/glass/other/Mechanism2D.hpp index 025c3e1f43f..2502bbdaa14 100644 --- a/glass/src/lib/native/include/wpi/glass/other/Mechanism2D.hpp +++ b/glass/src/lib/native/include/wpi/glass/other/Mechanism2D.hpp @@ -31,7 +31,7 @@ class MechanismObjectModel : public MechanismObjectGroup { // line accessors virtual double GetWeight() const = 0; virtual wpi::math::Rotation2d GetAngle() const = 0; - virtual wpi::units::meter_t GetLength() const = 0; + virtual wpi::units::meters<> GetLength() const = 0; }; class MechanismRootModel : public MechanismObjectGroup { diff --git a/glass/src/libnt/native/cpp/NTMechanism2D.cpp b/glass/src/libnt/native/cpp/NTMechanism2D.cpp index d45f4389bfb..72288608111 100644 --- a/glass/src/libnt/native/cpp/NTMechanism2D.cpp +++ b/glass/src/libnt/native/cpp/NTMechanism2D.cpp @@ -103,11 +103,11 @@ bool NTMechanism2DModel::NTMechanismObjectModel::NTUpdate( } } else if (valueData->topic == m_angleTopic.GetHandle()) { if (valueData->value && valueData->value.IsDouble()) { - m_angleValue = wpi::units::degree_t{valueData->value.GetDouble()}; + m_angleValue = wpi::units::degrees<>{valueData->value.GetDouble()}; } } else if (valueData->topic == m_lengthTopic.GetHandle()) { if (valueData->value && valueData->value.IsDouble()) { - m_lengthValue = wpi::units::meter_t{valueData->value.GetDouble()}; + m_lengthValue = wpi::units::meters<>{valueData->value.GetDouble()}; } } else { m_group.NTUpdate(event, childName); @@ -131,8 +131,8 @@ bool NTMechanism2DModel::RootModel::NTUpdate(const wpi::nt::Event& event, if (valueData->value && valueData->value.IsDoubleArray()) { auto arr = valueData->value.GetDoubleArray(); if (arr.size() == 2) { - m_pos = wpi::math::Translation2d{wpi::units::meter_t{arr[0]}, - wpi::units::meter_t{arr[1]}}; + m_pos = wpi::math::Translation2d{wpi::units::meters<>{arr[0]}, + wpi::units::meters<>{arr[1]}}; } } } else { @@ -201,7 +201,7 @@ void NTMechanism2DModel::Update() { auto arr = valueData->value.GetDoubleArray(); if (arr.size() == 2) { m_dimensionsValue = wpi::math::Translation2d{ - wpi::units::meter_t{arr[0]}, wpi::units::meter_t{arr[1]}}; + wpi::units::meters<>{arr[0]}, wpi::units::meters<>{arr[1]}}; } } } else if (valueData->topic == m_bgColorTopic.GetHandle()) { diff --git a/glass/src/libnt/native/include/wpi/glass/networktables/NTMechanism2D.hpp b/glass/src/libnt/native/include/wpi/glass/networktables/NTMechanism2D.hpp index 98a4dabd4bc..2e49ad2df23 100644 --- a/glass/src/libnt/native/include/wpi/glass/networktables/NTMechanism2D.hpp +++ b/glass/src/libnt/native/include/wpi/glass/networktables/NTMechanism2D.hpp @@ -94,7 +94,7 @@ class NTMechanism2DModel : public Mechanism2DModel { ImU32 GetColor() const final { return m_colorValue; } double GetWeight() const final { return m_weightValue; } wpi::math::Rotation2d GetAngle() const final { return m_angleValue; } - wpi::units::meter_t GetLength() const final { return m_lengthValue; } + wpi::units::meters<> GetLength() const final { return m_lengthValue; } bool NTUpdate(const wpi::nt::Event& event, std::string_view name); @@ -111,7 +111,7 @@ class NTMechanism2DModel : public Mechanism2DModel { ImU32 m_colorValue = IM_COL32_WHITE; double m_weightValue = 1.0; wpi::math::Rotation2d m_angleValue; - wpi::units::meter_t m_lengthValue = 0.0_m; + wpi::units::meters<> m_lengthValue = 0.0_m; }; class RootModel final : public MechanismRootModel { diff --git a/ntcore/src/main/native/include/wpi/nt/UnitTopic.hpp b/ntcore/src/main/native/include/wpi/nt/UnitTopic.hpp index 39b11b39ab7..df84d9aed6e 100644 --- a/ntcore/src/main/native/include/wpi/nt/UnitTopic.hpp +++ b/ntcore/src/main/native/include/wpi/nt/UnitTopic.hpp @@ -21,7 +21,7 @@ class UnitTopic; /** * Timestamped unit. * - * @tparam T unit type, e.g. wpi::units::meter_t + * @tparam T unit type, e.g. wpi::units::meters<> */ template struct TimestampedUnit { @@ -49,7 +49,7 @@ struct TimestampedUnit { /** * NetworkTables unit-typed subscriber. * - * @tparam T unit type, e.g. wpi::units::meter_t + * @tparam T unit type, e.g. wpi::units::meters<> */ template class UnitSubscriber : public Subscriber { @@ -87,7 +87,7 @@ class UnitSubscriber : public Subscriber { * @return value */ ValueType Get(ParamType defaultValue) const { - return T{::wpi::nt::GetDouble(m_subHandle, defaultValue.value())}; + return T{::wpi::nt::GetDouble(m_subHandle, defaultValue.raw())}; } /** @@ -109,7 +109,7 @@ class UnitSubscriber : public Subscriber { */ TimestampedValueType GetAtomic(ParamType defaultValue) const { auto doubleVal = - ::wpi::nt::GetAtomicDouble(m_subHandle, defaultValue.value()); + ::wpi::nt::GetAtomicDouble(m_subHandle, defaultValue.raw()); return {doubleVal.time, doubleVal.serverTime, doubleVal.value}; } @@ -148,7 +148,7 @@ class UnitSubscriber : public Subscriber { /** * NetworkTables unit-typed publisher. * - * @tparam T unit type, e.g. wpi::units::meter_t + * @tparam T unit type, e.g. wpi::units::meters<> */ template class UnitPublisher : public Publisher { @@ -176,7 +176,7 @@ class UnitPublisher : public Publisher { * @param time timestamp; 0 indicates current NT time should be used */ void Set(ParamType value, int64_t time = 0) { - ::wpi::nt::SetDouble(m_pubHandle, value.value(), time); + ::wpi::nt::SetDouble(m_pubHandle, value.raw(), time); } /** @@ -187,7 +187,7 @@ class UnitPublisher : public Publisher { * @param value value */ void SetDefault(ParamType value) { - ::wpi::nt::SetDefaultDouble(m_pubHandle, value.value()); + ::wpi::nt::SetDefaultDouble(m_pubHandle, value.raw()); } /** @@ -205,7 +205,7 @@ class UnitPublisher : public Publisher { * * @note Unlike NetworkTableEntry, the entry goes away when this is destroyed. * - * @tparam T unit type, e.g. wpi::units::meter_t + * @tparam T unit type, e.g. wpi::units::meters<> */ template class UnitEntry final : public UnitSubscriber, public UnitPublisher { @@ -265,7 +265,7 @@ class UnitEntry final : public UnitSubscriber, public UnitPublisher { * correct behavior the publisher and subscriber must use the same unit type, * but this can be checked at runtime using IsMatchingUnit(). * - * @tparam T unit type, e.g. wpi::units::meter_t + * @tparam T unit type, e.g. wpi::units::meters<> */ template class UnitTopic final : public Topic { diff --git a/romiVendordep/src/main/native/cpp/romi/RomiGyro.cpp b/romiVendordep/src/main/native/cpp/romi/RomiGyro.cpp index 4a6e3d0e877..6d5875cda5a 100644 --- a/romiVendordep/src/main/native/cpp/romi/RomiGyro.cpp +++ b/romiVendordep/src/main/native/cpp/romi/RomiGyro.cpp @@ -26,57 +26,57 @@ RomiGyro::RomiGyro() : m_simDevice("Gyro:RomiGyro") { } } -wpi::units::radian_t RomiGyro::GetAngle() const { +wpi::units::radians<> RomiGyro::GetAngle() const { return GetAngleZ(); } -wpi::units::radians_per_second_t RomiGyro::GetRate() const { +wpi::units::radians_per_second<> RomiGyro::GetRate() const { return GetRateZ(); } -wpi::units::radians_per_second_t RomiGyro::GetRateX() const { +wpi::units::radians_per_second<> RomiGyro::GetRateX() const { if (m_simRateX) { - return wpi::units::degrees_per_second_t{m_simRateX.Get()}; + return wpi::units::degrees_per_second<>{m_simRateX.Get()}; } return 0.0_rad_per_s; } -wpi::units::radians_per_second_t RomiGyro::GetRateY() const { +wpi::units::radians_per_second<> RomiGyro::GetRateY() const { if (m_simRateY) { - return wpi::units::degrees_per_second_t{m_simRateY.Get()}; + return wpi::units::degrees_per_second<>{m_simRateY.Get()}; } return 0.0_rad_per_s; } -wpi::units::radians_per_second_t RomiGyro::GetRateZ() const { +wpi::units::radians_per_second<> RomiGyro::GetRateZ() const { if (m_simRateZ) { - return wpi::units::degrees_per_second_t{m_simRateZ.Get()}; + return wpi::units::degrees_per_second<>{m_simRateZ.Get()}; } return 0.0_rad_per_s; } -wpi::units::radian_t RomiGyro::GetAngleX() const { +wpi::units::radians<> RomiGyro::GetAngleX() const { if (m_simAngleX) { - return wpi::units::degree_t{m_simAngleX.Get() - m_angleXOffset}; + return wpi::units::degrees<>{m_simAngleX.Get() - m_angleXOffset}; } return 0.0_rad; } -wpi::units::radian_t RomiGyro::GetAngleY() const { +wpi::units::radians<> RomiGyro::GetAngleY() const { if (m_simAngleY) { - return wpi::units::degree_t{m_simAngleY.Get() - m_angleYOffset}; + return wpi::units::degrees<>{m_simAngleY.Get() - m_angleYOffset}; } return 0.0_rad; } -wpi::units::radian_t RomiGyro::GetAngleZ() const { +wpi::units::radians<> RomiGyro::GetAngleZ() const { if (m_simAngleZ) { - return wpi::units::degree_t{m_simAngleZ.Get() - m_angleZOffset}; + return wpi::units::degrees<>{m_simAngleZ.Get() - m_angleZOffset}; } return 0.0_rad; diff --git a/romiVendordep/src/main/native/cpp/romi/RomiServo.cpp b/romiVendordep/src/main/native/cpp/romi/RomiServo.cpp index 5289776427c..95ef59fcf81 100644 --- a/romiVendordep/src/main/native/cpp/romi/RomiServo.cpp +++ b/romiVendordep/src/main/native/cpp/romi/RomiServo.cpp @@ -26,8 +26,8 @@ RomiServo::RomiServo(int channel) { } } -void RomiServo::SetAngle(wpi::units::radian_t angle) { - angle = std::clamp(angle, 0_deg, 180_deg); +void RomiServo::SetAngle(wpi::units::radians<> angle) { + angle = std::clamp>(angle, 0_deg, 180_deg); double pos = angle.value() / std::numbers::pi; if (m_simPosition) { @@ -35,9 +35,9 @@ void RomiServo::SetAngle(wpi::units::radian_t angle) { } } -wpi::units::radian_t RomiServo::GetAngle() const { +wpi::units::radians<> RomiServo::GetAngle() const { if (m_simPosition) { - return wpi::units::radian_t{m_simPosition.Get() * std::numbers::pi}; + return wpi::units::radians<>{m_simPosition.Get() * std::numbers::pi}; } return 90_deg; diff --git a/romiVendordep/src/main/native/include/wpi/romi/OnBoardIO.hpp b/romiVendordep/src/main/native/include/wpi/romi/OnBoardIO.hpp index acf9c14fa0a..cec16a0113f 100644 --- a/romiVendordep/src/main/native/include/wpi/romi/OnBoardIO.hpp +++ b/romiVendordep/src/main/native/include/wpi/romi/OnBoardIO.hpp @@ -34,7 +34,7 @@ class OnBoardIO { OnBoardIO(OnBoardIO::ChannelMode dio1, OnBoardIO::ChannelMode dio2); static constexpr auto MESSAGE_INTERVAL = 1_s; - wpi::units::second_t m_nextMessageTime = 0_s; + wpi::units::seconds<> m_nextMessageTime = 0_s; /** * Gets if the A button is pressed. diff --git a/romiVendordep/src/main/native/include/wpi/romi/RomiGyro.hpp b/romiVendordep/src/main/native/include/wpi/romi/RomiGyro.hpp index 848439069cf..9419fe1410e 100644 --- a/romiVendordep/src/main/native/include/wpi/romi/RomiGyro.hpp +++ b/romiVendordep/src/main/native/include/wpi/romi/RomiGyro.hpp @@ -36,7 +36,7 @@ class RomiGyro : public wpi::telemetry::TelemetryLoggable { * * @return The current heading of the robot. */ - wpi::units::radian_t GetAngle() const; + wpi::units::radians<> GetAngle() const; /** * Return the rate of rotation of the gyro @@ -45,49 +45,49 @@ class RomiGyro : public wpi::telemetry::TelemetryLoggable { * * @return The current rate. */ - wpi::units::radians_per_second_t GetRate() const; + wpi::units::radians_per_second<> GetRate() const; /** * Get the rate of turn in around the X-axis. * * @return Rate of turn. */ - wpi::units::radians_per_second_t GetRateX() const; + wpi::units::radians_per_second<> GetRateX() const; /** * Get the rate of turn in around the Y-axis. * * @return Rate of turn. */ - wpi::units::radians_per_second_t GetRateY() const; + wpi::units::radians_per_second<> GetRateY() const; /** * Get the rate of turn around the Z-axis. * * @return Rate of turn. */ - wpi::units::radians_per_second_t GetRateZ() const; + wpi::units::radians_per_second<> GetRateZ() const; /** * Get the currently reported angle around the X-axis. * * @return Current angle around X-axis. */ - wpi::units::radian_t GetAngleX() const; + wpi::units::radians<> GetAngleX() const; /** * Get the currently reported angle around the Y-axis. * * @return Current angle around Y-axis. */ - wpi::units::radian_t GetAngleY() const; + wpi::units::radians<> GetAngleY() const; /** * Get the currently reported angle around the Z-axis. * * @return Current angle around Z-axis. */ - wpi::units::radian_t GetAngleZ() const; + wpi::units::radians<> GetAngleZ() const; /** * Resets the gyro diff --git a/romiVendordep/src/main/native/include/wpi/romi/RomiServo.hpp b/romiVendordep/src/main/native/include/wpi/romi/RomiServo.hpp index 994d0fd553b..d6e66387ff4 100644 --- a/romiVendordep/src/main/native/include/wpi/romi/RomiServo.hpp +++ b/romiVendordep/src/main/native/include/wpi/romi/RomiServo.hpp @@ -33,14 +33,14 @@ class RomiServo { * * @param angle Desired angle in radians */ - void SetAngle(wpi::units::radian_t angle); + void SetAngle(wpi::units::radians<> angle); /** * Get the servo angle. * * @return Current servo angle in radians */ - wpi::units::radian_t GetAngle() const; + wpi::units::radians<> GetAngle() const; private: hal::SimDevice m_simDevice; diff --git a/telemetry/doc/cpp.md b/telemetry/doc/cpp.md index f32c4bf5681..eb13340bdcb 100644 --- a/telemetry/doc/cpp.md +++ b/telemetry/doc/cpp.md @@ -138,7 +138,7 @@ class Shooter { private: wpi::telemetry::TelemetryTable& m_telemetry = wpi::telemetry::GetTable("Shooter"); wpi::Encoder m_encoder{0, 1}; - units::volt_t m_lastVoltage = 0_V; + wpi::units::volts<> m_lastVoltage = 0_V; }; ``` diff --git a/tools/sysid/src/main/native/cpp/analysis/AnalysisManager.cpp b/tools/sysid/src/main/native/cpp/analysis/AnalysisManager.cpp index 77d1c501d3b..28d09e7a2c8 100644 --- a/tools/sysid/src/main/native/cpp/analysis/AnalysisManager.cpp +++ b/tools/sysid/src/main/native/cpp/analysis/AnalysisManager.cpp @@ -17,7 +17,7 @@ using namespace sysid; -static double Lerp(wpi::units::second_t time, +static double Lerp(wpi::units::seconds<> time, std::vector>& data) { auto next = std::find_if(data.begin(), data.end(), [&](const auto& entry) { return entry.time > time; diff --git a/tools/sysid/src/main/native/cpp/analysis/ArmSim.cpp b/tools/sysid/src/main/native/cpp/analysis/ArmSim.cpp index d8681a45ed1..7c33e95fb88 100644 --- a/tools/sysid/src/main/native/cpp/analysis/ArmSim.cpp +++ b/tools/sysid/src/main/native/cpp/analysis/ArmSim.cpp @@ -26,7 +26,7 @@ ArmSim::ArmSim(double Ks, double Kv, double Ka, double Kg, double offset, Reset(initialPosition, initialVelocity); } -void ArmSim::Update(wpi::units::volt_t voltage, wpi::units::second_t dt) { +void ArmSim::Update(wpi::units::volts<> voltage, wpi::units::seconds<> dt) { // Returns arm acceleration under gravity auto f = [=, this]( const Eigen::Vector& x, @@ -52,7 +52,7 @@ double ArmSim::GetVelocity() const { return m_x(1); } -double ArmSim::GetAcceleration(wpi::units::volt_t voltage) const { +double ArmSim::GetAcceleration(wpi::units::volts<> voltage) const { Eigen::Vector u{voltage.value()}; return (m_A * m_x.block<1, 1>(1, 0) + m_B * u + m_c * wpi::util::sgn(GetVelocity()) + diff --git a/tools/sysid/src/main/native/cpp/analysis/ElevatorSim.cpp b/tools/sysid/src/main/native/cpp/analysis/ElevatorSim.cpp index 0b5c4a44fa0..2a13acb108c 100644 --- a/tools/sysid/src/main/native/cpp/analysis/ElevatorSim.cpp +++ b/tools/sysid/src/main/native/cpp/analysis/ElevatorSim.cpp @@ -19,7 +19,8 @@ ElevatorSim::ElevatorSim(double Ks, double Kv, double Ka, double Kg, Reset(initialPosition, initialVelocity); } -void ElevatorSim::Update(wpi::units::volt_t voltage, wpi::units::second_t dt) { +void ElevatorSim::Update(wpi::units::volts<> voltage, + wpi::units::seconds<> dt) { Eigen::Vector u{voltage.value()}; // Given dx/dt = Ax + Bu + c sgn(x) + d, @@ -40,7 +41,7 @@ double ElevatorSim::GetVelocity() const { return m_x(1); } -double ElevatorSim::GetAcceleration(wpi::units::volt_t voltage) const { +double ElevatorSim::GetAcceleration(wpi::units::volts<> voltage) const { Eigen::Vector u{voltage.value()}; return (m_A * m_x + m_B * u + m_c * wpi::util::sgn(GetVelocity()) + m_d)(1); } diff --git a/tools/sysid/src/main/native/cpp/analysis/FeedbackAnalysis.cpp b/tools/sysid/src/main/native/cpp/analysis/FeedbackAnalysis.cpp index 31d71707cf4..e1d7d4b2256 100644 --- a/tools/sysid/src/main/native/cpp/analysis/FeedbackAnalysis.cpp +++ b/tools/sysid/src/main/native/cpp/analysis/FeedbackAnalysis.cpp @@ -22,7 +22,7 @@ FeedbackGains sysid::CalculatePositionFeedbackGains( const FeedbackControllerPreset& preset, const LQRParameters& params, double Kv, double Ka) { using Kv_t = decltype(1_V / 1_mps); - using Ka_t = decltype(1_V / 1_mps_sq); + using Ka_t = decltype(1_V / 1_mps2); if (!std::isfinite(Kv) || !std::isfinite(Ka)) { return {0.0, 0.0}; @@ -54,7 +54,7 @@ FeedbackGains sysid::CalculatePositionFeedbackGains( controller.K(0, 0) * preset.outputConversionFactor, controller.K(0, 1) * preset.outputConversionFactor / (preset.normalized ? 1 - : wpi::units::second_t{preset.period}.value())}; + : wpi::units::seconds<>{preset.period}.value())}; } FeedbackGains sysid::CalculateVelocityFeedbackGains( diff --git a/tools/sysid/src/main/native/cpp/analysis/FeedforwardAnalysis.cpp b/tools/sysid/src/main/native/cpp/analysis/FeedforwardAnalysis.cpp index 76d62a75c14..0913e31082a 100644 --- a/tools/sysid/src/main/native/cpp/analysis/FeedforwardAnalysis.cpp +++ b/tools/sysid/src/main/native/cpp/analysis/FeedforwardAnalysis.cpp @@ -14,7 +14,6 @@ #include #include "wpi/sysid/analysis/OLS.hpp" -#include "wpi/units/math.hpp" #include "wpi/units/time.hpp" #include "wpi/util/StringExtras.hpp" diff --git a/tools/sysid/src/main/native/cpp/analysis/FilteringUtils.cpp b/tools/sysid/src/main/native/cpp/analysis/FilteringUtils.cpp index 8beecf9e466..2c2d605955f 100644 --- a/tools/sysid/src/main/native/cpp/analysis/FilteringUtils.cpp +++ b/tools/sysid/src/main/native/cpp/analysis/FilteringUtils.cpp @@ -115,16 +115,16 @@ static void PrepareMechData(std::vector* data, } } -std::tuple +std::tuple, wpi::units::seconds<>, wpi::units::seconds<>> sysid::TrimStepVoltageData(std::vector* data, AnalysisManager::Settings* settings, - wpi::units::second_t minStepTime, - wpi::units::second_t maxStepTime) { + wpi::units::seconds<> minStepTime, + wpi::units::seconds<> maxStepTime) { auto voltageBegins = std::find_if(data->begin(), data->end(), [](auto& datum) { return std::abs(datum.voltage) > 0; }); - wpi::units::second_t firstTimestamp = voltageBegins->timestamp; + wpi::units::seconds<> firstTimestamp = voltageBegins->timestamp; double firstPosition = voltageBegins->position; auto motionBegins = std::find_if( @@ -133,7 +133,7 @@ sysid::TrimStepVoltageData(std::vector* data, (settings->velocityThreshold * datum.dt.value()); }); - wpi::units::second_t positionDelay; + wpi::units::seconds<> positionDelay; if (motionBegins != data->end()) { positionDelay = motionBegins->timestamp - firstTimestamp; } else { @@ -159,7 +159,7 @@ sysid::TrimStepVoltageData(std::vector* data, maxAccel->acceleration; }); - wpi::units::second_t velocityDelay; + wpi::units::seconds<> velocityDelay; if (accelBegins != data->end()) { velocityDelay = accelBegins->timestamp - firstTimestamp; @@ -229,9 +229,9 @@ double sysid::GetMaxSpeed( return max; } -wpi::units::second_t sysid::GetMeanTimeDelta( +wpi::units::seconds<> sysid::GetMeanTimeDelta( const std::vector& data) { - std::vector dts; + std::vector> dts; for (const auto& pt : data) { if (pt.dt > 0_s && pt.dt < 500_ms) { @@ -242,8 +242,8 @@ wpi::units::second_t sysid::GetMeanTimeDelta( return std::accumulate(dts.begin(), dts.end(), 0_s) / dts.size(); } -wpi::units::second_t sysid::GetMeanTimeDelta(const Storage& data) { - std::vector dts; +wpi::units::seconds<> sysid::GetMeanTimeDelta(const Storage& data) { + std::vector> dts; for (const auto& pt : data.slowForward) { if (pt.dt > 0_s && pt.dt < 500_ms) { @@ -320,7 +320,7 @@ static std::string RemoveStr(std::string_view str, std::string_view removeStr) { * * @return The maximum duration of the Dynamic Tests */ -static wpi::units::second_t GetMaxStepTime( +static wpi::units::seconds<> GetMaxStepTime( wpi::util::StringMap>& data) { auto maxStepTime = 0_s; for (auto& it : data) { @@ -342,9 +342,9 @@ static wpi::units::second_t GetMaxStepTime( void sysid::InitialTrimAndFilter( wpi::util::StringMap>* data, AnalysisManager::Settings* settings, - std::vector& positionDelays, - std::vector& velocityDelays, - wpi::units::second_t& minStepTime, wpi::units::second_t& maxStepTime, + std::vector>& positionDelays, + std::vector>& velocityDelays, + wpi::units::seconds<>& minStepTime, wpi::units::seconds<>& maxStepTime, std::string_view unit) { auto& preparedData = *data; diff --git a/tools/sysid/src/main/native/cpp/analysis/SimpleMotorSim.cpp b/tools/sysid/src/main/native/cpp/analysis/SimpleMotorSim.cpp index acd0a3cfda4..d3445030bc8 100644 --- a/tools/sysid/src/main/native/cpp/analysis/SimpleMotorSim.cpp +++ b/tools/sysid/src/main/native/cpp/analysis/SimpleMotorSim.cpp @@ -16,8 +16,8 @@ SimpleMotorSim::SimpleMotorSim(double Ks, double Kv, double Ka, Reset(initialPosition, initialVelocity); } -void SimpleMotorSim::Update(wpi::units::volt_t voltage, - wpi::units::second_t dt) { +void SimpleMotorSim::Update(wpi::units::volts<> voltage, + wpi::units::seconds<> dt) { Eigen::Vector u{voltage.value()}; // Given dx/dt = Ax + Bu + c sgn(x), @@ -37,7 +37,7 @@ double SimpleMotorSim::GetVelocity() const { return m_x(1); } -double SimpleMotorSim::GetAcceleration(wpi::units::volt_t voltage) const { +double SimpleMotorSim::GetAcceleration(wpi::units::volts<> voltage) const { Eigen::Vector u{voltage.value()}; return (m_A * m_x + m_B * u + m_c * wpi::util::sgn(GetVelocity()))(1); } diff --git a/tools/sysid/src/main/native/cpp/view/Analyzer.cpp b/tools/sysid/src/main/native/cpp/view/Analyzer.cpp index 5b28f682df0..e50239d8a3f 100644 --- a/tools/sysid/src/main/native/cpp/view/Analyzer.cpp +++ b/tools/sysid/src/main/native/cpp/view/Analyzer.cpp @@ -55,8 +55,8 @@ void Analyzer::UpdateFeedforwardGains() { m_settings.preset.measurementDelay = m_settings.type == FeedbackControllerLoopType::POSITION // Clamp feedback measurement delay to ≥ 0 - ? wpi::units::math::max(0_s, m_manager->GetPositionDelay()) - : wpi::units::math::max(0_s, m_manager->GetVelocityDelay()); + ? wpi::units::max(0_s, m_manager->GetPositionDelay()) + : wpi::units::max(0_s, m_manager->GetVelocityDelay()); PrepareGraphs(); } catch (const sysid::InvalidDataError& e) { m_state = AnalyzerState::GENERAL_DATA_ERROR; @@ -83,7 +83,7 @@ void Analyzer::UpdateFeedbackGains() { const auto& Ka = m_feedforwardGains.Ka; if (Kv.isValidGain && Ka.isValidGain) { const auto& fb = m_manager->CalculateFeedback(Kv, Ka); - m_timescale = wpi::units::second_t{Ka.gain / Kv.gain}; + m_timescale = wpi::units::seconds<>{Ka.gain / Kv.gain}; m_timescaleValid = true; m_Kp = fb.Kp; m_Kd = fb.Kd; @@ -468,7 +468,7 @@ void Analyzer::DisplayFeedforwardParameters(float beginX, float beginY) { if (ImGui::SliderFloat("Test Duration", &m_stepTestDuration, m_manager->GetMinStepTime().value(), m_manager->GetMaxStepTime().value(), "%.2f")) { - m_settings.stepTestDuration = wpi::units::second_t{m_stepTestDuration}; + m_settings.stepTestDuration = wpi::units::seconds<>{m_stepTestDuration}; PrepareData(); } } diff --git a/tools/sysid/src/main/native/cpp/view/AnalyzerPlot.cpp b/tools/sysid/src/main/native/cpp/view/AnalyzerPlot.cpp index 2ec11d29847..a5cb9d3cd0f 100644 --- a/tools/sysid/src/main/native/cpp/view/AnalyzerPlot.cpp +++ b/tools/sysid/src/main/native/cpp/view/AnalyzerPlot.cpp @@ -18,7 +18,6 @@ #include "wpi/sysid/analysis/ElevatorSim.hpp" #include "wpi/sysid/analysis/FilteringUtils.hpp" #include "wpi/sysid/analysis/SimpleMotorSim.hpp" -#include "wpi/units/math.hpp" using namespace sysid; @@ -29,7 +28,7 @@ static ImPlotPoint Getter(int idx, void* data) { template static std::vector> PopulateTimeDomainSim( const std::vector& data, - const std::array& startTimes, size_t step, + const std::array, 4>& startTimes, size_t step, Model model, double* simSquaredErrorSum, double* squaredVariationSum, int* timeSeriesPoints) { // Create the vector of ImPlotPoints that will contain our simulated data. @@ -41,7 +40,7 @@ static std::vector> PopulateTimeDomainSim( tmp.emplace_back(startTime.value(), data[0].velocity); model.Reset(data[0].position, data[0].velocity); - wpi::units::second_t t = 0_s; + wpi::units::seconds<> t = 0_s; for (size_t i = 1; i < data.size(); ++i) { const auto& now = data[i]; @@ -59,7 +58,7 @@ static std::vector> PopulateTimeDomainSim( continue; } - model.Update(wpi::units::volt_t{pre.voltage}, + model.Update(wpi::units::volts<>{pre.voltage}, now.timestamp - pre.timestamp); tmp.emplace_back((startTime + t).value(), model.GetVelocity()); *simSquaredErrorSum += std::pow(now.velocity - model.GetVelocity(), 2); @@ -131,7 +130,7 @@ void AnalyzerPlot::SetRawData(const Storage& data, std::string_view unit, void AnalyzerPlot::SetData( const Storage& rawData, const Storage& filteredData, std::string_view unit, const AnalysisManager::FeedforwardGains& ffGains, - const std::array& startTimes, AnalysisType type, + const std::array, 4>& startTimes, AnalysisType type, std::atomic& abort) { double simSquaredErrorSum = 0; double squaredVariationSum = 0; @@ -163,7 +162,7 @@ void AnalyzerPlot::SetData( auto slowStep = std::ceil(slow.size() * 1.0 / MAX_SIZE * 4); auto fastStep = std::ceil(fast.size() * 1.0 / MAX_SIZE * 4); - wpi::units::second_t dtMean = GetMeanTimeDelta(filteredData); + wpi::units::seconds<> dtMean = GetMeanTimeDelta(filteredData); // Velocity-vs-time plots { @@ -192,7 +191,7 @@ void AnalyzerPlot::SetData( slow[i].timestamp) == startTimes.end()) { m_timestepData.data.emplace_back( (slow[i].timestamp).value(), - wpi::units::millisecond_t{slow[i].dt}.value()); + wpi::units::milliseconds<>{slow[i].dt}.value()); } } } @@ -217,7 +216,7 @@ void AnalyzerPlot::SetData( fast[i].timestamp) == startTimes.end()) { m_timestepData.data.emplace_back( (fast[i].timestamp).value(), - wpi::units::millisecond_t{fast[i].dt}.value()); + wpi::units::milliseconds<>{fast[i].dt}.value()); } } } @@ -334,7 +333,7 @@ void AnalyzerPlot::SetData( startTimes.end()) { m_timestepData.data.emplace_back( (slow[i].timestamp).value(), - wpi::units::millisecond_t{slow[i].dt}.value()); + wpi::units::milliseconds<>{slow[i].dt}.value()); } } } @@ -351,20 +350,19 @@ void AnalyzerPlot::SetData( startTimes.end()) { m_timestepData.data.emplace_back( (fast[i].timestamp).value(), - wpi::units::millisecond_t{fast[i].dt}.value()); + wpi::units::milliseconds<>{fast[i].dt}.value()); } } } auto minTime = - wpi::units::math::min(slow.front().timestamp, fast.front().timestamp); + wpi::units::min(slow.front().timestamp, fast.front().timestamp); m_timestepData.fitLine[0] = - ImPlotPoint{minTime.value(), wpi::units::millisecond_t{dtMean}.value()}; + ImPlotPoint{minTime.value(), wpi::units::milliseconds<>{dtMean}.value()}; - auto maxTime = - wpi::units::math::max(slow.back().timestamp, fast.back().timestamp); + auto maxTime = wpi::units::max(slow.back().timestamp, fast.back().timestamp); m_timestepData.fitLine[1] = - ImPlotPoint{maxTime.value(), wpi::units::millisecond_t{dtMean}.value()}; + ImPlotPoint{maxTime.value(), wpi::units::milliseconds<>{dtMean}.value()}; // RMSE = std::sqrt(sum((x_i - x^_i)^2) / N) where sum represents the sum of // all time series points, x_i represents the velocity at a timestep, x^_i diff --git a/tools/sysid/src/main/native/cpp/view/DataSelector.cpp b/tools/sysid/src/main/native/cpp/view/DataSelector.cpp index 81dcd82d0b2..175abba3f0c 100644 --- a/tools/sysid/src/main/native/cpp/view/DataSelector.cpp +++ b/tools/sysid/src/main/native/cpp/view/DataSelector.cpp @@ -252,7 +252,7 @@ static void AddSamples(std::vector>& samples, [](const auto& datapoint, double val) { return datapoint.first < val; }); for (auto it = begin; it != end; ++it) { - samples.emplace_back(wpi::units::second_t{it->first * 1.0e-9}, + samples.emplace_back(wpi::units::seconds<>{it->first * 1.0e-9}, T{it->second}); } } diff --git a/tools/sysid/src/main/native/include/wpi/sysid/analysis/AnalysisManager.hpp b/tools/sysid/src/main/native/include/wpi/sysid/analysis/AnalysisManager.hpp index b0da026c898..b88ca1904bd 100644 --- a/tools/sysid/src/main/native/include/wpi/sysid/analysis/AnalysisManager.hpp +++ b/tools/sysid/src/main/native/include/wpi/sysid/analysis/AnalysisManager.hpp @@ -69,7 +69,7 @@ class AnalysisManager { * The duration of the dynamic test that should be considered. A value of * zero indicates it needs to be set to the default. */ - wpi::units::second_t stepTestDuration = 0_s; + wpi::units::seconds<> stepTestDuration = 0_s; }; struct FeedforwardGain { @@ -280,7 +280,7 @@ class AnalysisManager { * * @return The minimum step test duration. */ - wpi::units::second_t GetMinStepTime() const { return m_minStepTime; } + wpi::units::seconds<> GetMinStepTime() const { return m_minStepTime; } /** * Returns the maximum duration of the Step Voltage Test of the currently @@ -288,7 +288,7 @@ class AnalysisManager { * * @return Maximum step test duration */ - wpi::units::second_t GetMaxStepTime() const { return m_maxStepTime; } + wpi::units::seconds<> GetMaxStepTime() const { return m_maxStepTime; } /** * Returns the estimated time delay of the measured position, including @@ -296,7 +296,7 @@ class AnalysisManager { * * @return Position delay in milliseconds */ - wpi::units::millisecond_t GetPositionDelay() const { + wpi::units::milliseconds<> GetPositionDelay() const { return std::accumulate(m_positionDelays.begin(), m_positionDelays.end(), 0_s) / m_positionDelays.size(); @@ -308,7 +308,7 @@ class AnalysisManager { * * @return Velocity delay in milliseconds */ - wpi::units::millisecond_t GetVelocityDelay() const { + wpi::units::milliseconds<> GetVelocityDelay() const { return std::accumulate(m_velocityDelays.begin(), m_velocityDelays.end(), 0_s) / m_positionDelays.size(); @@ -319,7 +319,7 @@ class AnalysisManager { * * @return The start times for each test */ - const std::array& GetStartTimes() const { + const std::array, 4>& GetStartTimes() const { return m_startTimes; } @@ -333,16 +333,16 @@ class AnalysisManager { Storage m_filteredDataset; // Stores the various start times of the different tests. - std::array m_startTimes; + std::array, 4> m_startTimes; // The settings for this instance. This contains pointers to the feedback // controller preset, LQR parameters, acceleration window size, etc. Settings& m_settings; - wpi::units::second_t m_minStepTime{0}; - wpi::units::second_t m_maxStepTime{std::numeric_limits::infinity()}; - std::vector m_positionDelays; - std::vector m_velocityDelays; + wpi::units::seconds<> m_minStepTime{0}; + wpi::units::seconds<> m_maxStepTime{std::numeric_limits::infinity()}; + std::vector> m_positionDelays; + std::vector> m_velocityDelays; void PrepareGeneralData(); }; diff --git a/tools/sysid/src/main/native/include/wpi/sysid/analysis/ArmSim.hpp b/tools/sysid/src/main/native/include/wpi/sysid/analysis/ArmSim.hpp index e3f7e388348..56c8ba54a25 100644 --- a/tools/sysid/src/main/native/include/wpi/sysid/analysis/ArmSim.hpp +++ b/tools/sysid/src/main/native/include/wpi/sysid/analysis/ArmSim.hpp @@ -36,7 +36,7 @@ class ArmSim { * @param voltage Voltage to apply over the timestep. * @param dt Sample period. */ - void Update(wpi::units::volt_t voltage, wpi::units::second_t dt); + void Update(wpi::units::volts<> voltage, wpi::units::seconds<> dt); /** * Returns the position. @@ -58,7 +58,7 @@ class ArmSim { * @param voltage The voltage that is being applied to the mechanism / input * @return The acceleration given the state and input */ - double GetAcceleration(wpi::units::volt_t voltage) const; + double GetAcceleration(wpi::units::volts<> voltage) const; /** * Resets model position and velocity. diff --git a/tools/sysid/src/main/native/include/wpi/sysid/analysis/ElevatorSim.hpp b/tools/sysid/src/main/native/include/wpi/sysid/analysis/ElevatorSim.hpp index 622e88d43a3..0e9ca381944 100644 --- a/tools/sysid/src/main/native/include/wpi/sysid/analysis/ElevatorSim.hpp +++ b/tools/sysid/src/main/native/include/wpi/sysid/analysis/ElevatorSim.hpp @@ -34,7 +34,7 @@ class ElevatorSim { * @param voltage Voltage to apply over the timestep. * @param dt Sample period. */ - void Update(wpi::units::volt_t voltage, wpi::units::second_t dt); + void Update(wpi::units::volts<> voltage, wpi::units::seconds<> dt); /** * Returns the position. @@ -56,7 +56,7 @@ class ElevatorSim { * @param voltage The voltage that is being applied to the mechanism / input * @return The acceleration given the state and input */ - double GetAcceleration(wpi::units::volt_t voltage) const; + double GetAcceleration(wpi::units::volts<> voltage) const; /** * Resets model position and velocity. diff --git a/tools/sysid/src/main/native/include/wpi/sysid/analysis/FeedbackControllerPreset.hpp b/tools/sysid/src/main/native/include/wpi/sysid/analysis/FeedbackControllerPreset.hpp index e7da6880c35..28bf56bfbf4 100644 --- a/tools/sysid/src/main/native/include/wpi/sysid/analysis/FeedbackControllerPreset.hpp +++ b/tools/sysid/src/main/native/include/wpi/sysid/analysis/FeedbackControllerPreset.hpp @@ -29,7 +29,7 @@ struct FeedbackControllerPreset { /** * The period at which the controller runs. */ - wpi::units::millisecond_t period; + wpi::units::milliseconds<> period; /** * Whether the controller gains are time-normalized. @@ -39,7 +39,7 @@ struct FeedbackControllerPreset { /** * The measurement delay in the encoder measurements. */ - wpi::units::millisecond_t measurementDelay; + wpi::units::milliseconds<> measurementDelay; /** * Checks equality between two feedback controller presets. diff --git a/tools/sysid/src/main/native/include/wpi/sysid/analysis/FilteringUtils.hpp b/tools/sysid/src/main/native/include/wpi/sysid/analysis/FilteringUtils.hpp index e1e93176088..cef085666c6 100644 --- a/tools/sysid/src/main/native/include/wpi/sysid/analysis/FilteringUtils.hpp +++ b/tools/sysid/src/main/native/include/wpi/sysid/analysis/FilteringUtils.hpp @@ -144,11 +144,11 @@ void ApplyMedianFilter(std::vector* data, int window); * @param maxStepTime The maximum step test duration. * @return The updated minimum step test duration. */ -std::tuple +std::tuple, wpi::units::seconds<>, wpi::units::seconds<>> TrimStepVoltageData(std::vector* data, AnalysisManager::Settings* settings, - wpi::units::second_t minStepTime, - wpi::units::second_t maxStepTime); + wpi::units::seconds<> minStepTime, + wpi::units::seconds<> maxStepTime); /** * Compute the mean time delta of the given data. @@ -156,7 +156,7 @@ TrimStepVoltageData(std::vector* data, * @param data A reference to all of the collected PreparedData * @return The mean time delta for all the data points */ -wpi::units::second_t GetMeanTimeDelta(const std::vector& data); +wpi::units::seconds<> GetMeanTimeDelta(const std::vector& data); /** * Compute the mean time delta of the given data. @@ -164,7 +164,7 @@ wpi::units::second_t GetMeanTimeDelta(const std::vector& data); * @param data A reference to all of the collected PreparedData * @return The mean time delta for all the data points */ -wpi::units::second_t GetMeanTimeDelta(const Storage& data); +wpi::units::seconds<> GetMeanTimeDelta(const Storage& data); /** * Creates a central finite difference filter that computes the nth @@ -188,7 +188,7 @@ wpi::units::second_t GetMeanTimeDelta(const Storage& data); */ template wpi::math::LinearFilter CentralFiniteDifference( - wpi::units::second_t period) { + wpi::units::seconds<> period) { static_assert(Samples % 2 != 0, "Number of samples must be odd."); // Generate stencil points from -(samples - 1)/2 to (samples - 1)/2 @@ -222,10 +222,10 @@ wpi::math::LinearFilter CentralFiniteDifference( */ void InitialTrimAndFilter(wpi::util::StringMap>* data, AnalysisManager::Settings* settings, - std::vector& positionDelays, - std::vector& velocityDelays, - wpi::units::second_t& minStepTime, - wpi::units::second_t& maxStepTime, + std::vector>& positionDelays, + std::vector>& velocityDelays, + wpi::units::seconds<>& minStepTime, + wpi::units::seconds<>& maxStepTime, std::string_view unit = ""); /** diff --git a/tools/sysid/src/main/native/include/wpi/sysid/analysis/SimpleMotorSim.hpp b/tools/sysid/src/main/native/include/wpi/sysid/analysis/SimpleMotorSim.hpp index ff749b8743e..e844f1ce25a 100644 --- a/tools/sysid/src/main/native/include/wpi/sysid/analysis/SimpleMotorSim.hpp +++ b/tools/sysid/src/main/native/include/wpi/sysid/analysis/SimpleMotorSim.hpp @@ -34,7 +34,7 @@ class SimpleMotorSim { * @param voltage Voltage to apply over the timestep. * @param dt Sample period. */ - void Update(wpi::units::volt_t voltage, wpi::units::second_t dt); + void Update(wpi::units::volts<> voltage, wpi::units::seconds<> dt); /** * Returns the position. @@ -56,7 +56,7 @@ class SimpleMotorSim { * @param voltage The voltage that is being applied to the mechanism / input * @return The acceleration given the state and input */ - double GetAcceleration(wpi::units::volt_t voltage) const; + double GetAcceleration(wpi::units::volts<> voltage) const; /** * Resets model position and velocity. diff --git a/tools/sysid/src/main/native/include/wpi/sysid/analysis/Storage.hpp b/tools/sysid/src/main/native/include/wpi/sysid/analysis/Storage.hpp index ae17192ecdb..1f359f97d31 100644 --- a/tools/sysid/src/main/native/include/wpi/sysid/analysis/Storage.hpp +++ b/tools/sysid/src/main/native/include/wpi/sysid/analysis/Storage.hpp @@ -22,14 +22,14 @@ struct MotorData { // Timestamps are not necessarily aligned! struct Run { template - requires std::is_arithmetic_v || wpi::units::traits::is_unit_t_v + requires std::is_arithmetic_v || wpi::units::traits::is_unit_v struct Sample { - Sample(wpi::units::second_t time, T measurement) + Sample(wpi::units::seconds<> time, T measurement) : time{time}, measurement{measurement} {} - wpi::units::second_t time; + wpi::units::seconds<> time; T measurement; }; - std::vector> voltage; + std::vector>> voltage; std::vector> position; std::vector> velocity; }; @@ -51,7 +51,7 @@ struct PreparedData { /** * The timestamp of the data point. */ - wpi::units::second_t timestamp; + wpi::units::seconds<> timestamp; /** * The voltage of the data point. @@ -71,7 +71,7 @@ struct PreparedData { /** * The difference in timestamps between this point and the next point. */ - wpi::units::second_t dt = 0_s; + wpi::units::seconds<> dt = 0_s; /** * The acceleration of the data point diff --git a/tools/sysid/src/main/native/include/wpi/sysid/analysis/TrackwidthAnalysis.hpp b/tools/sysid/src/main/native/include/wpi/sysid/analysis/TrackwidthAnalysis.hpp index ad8454f707b..5aae0e891de 100644 --- a/tools/sysid/src/main/native/include/wpi/sysid/analysis/TrackwidthAnalysis.hpp +++ b/tools/sysid/src/main/native/include/wpi/sysid/analysis/TrackwidthAnalysis.hpp @@ -19,7 +19,7 @@ namespace sysid { * @param accum The accumulated gyro angle. */ constexpr double CalculateTrackwidth(double l, double r, - wpi::units::radian_t accum) { + wpi::units::radians<> accum) { // The below comes from solving ω = (vr − vl) / 2r for 2r. return (gcem::abs(r) + gcem::abs(l)) / gcem::abs(accum.value()); } diff --git a/tools/sysid/src/main/native/include/wpi/sysid/view/Analyzer.hpp b/tools/sysid/src/main/native/include/wpi/sysid/view/Analyzer.hpp index 1bd5f891a81..b3c7ee576cf 100644 --- a/tools/sysid/src/main/native/include/wpi/sysid/view/Analyzer.hpp +++ b/tools/sysid/src/main/native/include/wpi/sysid/view/Analyzer.hpp @@ -221,7 +221,7 @@ class Analyzer : public wpi::glass::View { double m_accelRMSE; double m_Kp; double m_Kd; - wpi::units::millisecond_t m_timescale; + wpi::units::milliseconds<> m_timescale; bool m_timescaleValid = false; // Units diff --git a/tools/sysid/src/main/native/include/wpi/sysid/view/AnalyzerPlot.hpp b/tools/sysid/src/main/native/include/wpi/sysid/view/AnalyzerPlot.hpp index a14780059a6..6ddc70c0e54 100644 --- a/tools/sysid/src/main/native/include/wpi/sysid/view/AnalyzerPlot.hpp +++ b/tools/sysid/src/main/native/include/wpi/sysid/view/AnalyzerPlot.hpp @@ -55,7 +55,7 @@ class AnalyzerPlot { void SetData(const Storage& rawData, const Storage& filteredData, std::string_view unit, const AnalysisManager::FeedforwardGains& ff, - const std::array& startTimes, + const std::array, 4>& startTimes, AnalysisType type, std::atomic& abort); /** diff --git a/tools/sysid/src/test/native/cpp/analysis/FeedforwardAnalysisTest.cpp b/tools/sysid/src/test/native/cpp/analysis/FeedforwardAnalysisTest.cpp index ebc0f55b486..3acc4c8a1e4 100644 --- a/tools/sysid/src/test/native/cpp/analysis/FeedforwardAnalysisTest.cpp +++ b/tools/sysid/src/test/native/cpp/analysis/FeedforwardAnalysisTest.cpp @@ -45,9 +45,9 @@ inline constexpr int MOVEMENT_COMBINATIONS = 16; template sysid::Storage CollectData(Model& model, std::bitset<4> movements) { constexpr auto U_STEP = 0.25_V / 1_s; - constexpr wpi::units::volt_t U_MAX = 7_V; - constexpr wpi::units::second_t T = 5_ms; - constexpr wpi::units::second_t TEST_DURATION = 5_s; + constexpr wpi::units::volts<> U_MAX = 7_V; + constexpr wpi::units::seconds<> T = 5_ms; + constexpr wpi::units::seconds<> TEST_DURATION = 5_s; sysid::Storage storage; auto& [slowForward, slowBackward, fastForward, fastBackward] = storage; diff --git a/tools/sysid/src/test/native/cpp/analysis/FilterTest.cpp b/tools/sysid/src/test/native/cpp/analysis/FilterTest.cpp index 5418ac7fe4c..b275165457e 100644 --- a/tools/sysid/src/test/native/cpp/analysis/FilterTest.cpp +++ b/tools/sysid/src/test/native/cpp/analysis/FilterTest.cpp @@ -50,7 +50,7 @@ void FillStepVoltageData(std::vector& data) { auto& datum = data.at(i); datum.timestamp = previousDatum.timestamp + previousDatum.dt; datum.position = 0.5 * previousDatum.acceleration * - wpi::units::math::pow<2>(previousDatum.dt).value() + + wpi::units::pow<2>(previousDatum.dt).value() + previousDatum.velocity * previousDatum.dt.value() + previousDatum.position; datum.velocity = previousDatum.velocity + @@ -137,7 +137,7 @@ TEST_CASE("FilterTest StepTrim", "[sysid]") { } template -void AssertCentralResults(F&& f, DfDx&& dfdx, wpi::units::second_t h, +void AssertCentralResults(F&& f, DfDx&& dfdx, wpi::units::seconds<> h, double min, double max) { static_assert(Samples % 2 != 0, "Number of samples must be odd."); diff --git a/upstream_utils/units.py b/upstream_utils/units.py new file mode 100755 index 00000000000..88e1fc50daa --- /dev/null +++ b/upstream_utils/units.py @@ -0,0 +1,171 @@ +#!/usr/bin/env python3 + +import os +import re +import shutil +from pathlib import Path + +from llvm import _replace_macro_invocations + +from upstream_utils import Lib, walk_cwd_and_copy_if, walk_if + + +def _replace_gtest_assertions(content: str): + comparison_macros = { + "EXPECT_EQ": ("CHECK", "=="), + "EXPECT_STREQ": ("CHECK", "=="), + "EXPECT_DOUBLE_EQ": ("CHECK", "=="), + "EXPECT_STRNE": ("CHECK", "!="), + "EXPECT_NE": ("CHECK", "!="), + "EXPECT_LT": ("CHECK", "<"), + "EXPECT_LE": ("CHECK", "<="), + "EXPECT_GT": ("CHECK", ">"), + "EXPECT_GE": ("CHECK", ">="), + "ASSERT_EQ": ("REQUIRE", "=="), + "ASSERT_NE": ("REQUIRE", "!="), + "ASSERT_LT": ("REQUIRE", "<"), + "ASSERT_LE": ("REQUIRE", "<="), + "ASSERT_GT": ("REQUIRE", ">"), + "ASSERT_GE": ("REQUIRE", ">="), + } + boolean_macros = { + "EXPECT_TRUE": "CHECK", + "EXPECT_FALSE": "CHECK_FALSE", + "ASSERT_TRUE": "REQUIRE", + "ASSERT_FALSE": "REQUIRE_FALSE", + } + + def replace(macro: str, args: list[str]): + if macro in comparison_macros and len(args) == 2: + catch_macro, op = comparison_macros[macro] + if macro == "EXPECT_STRNE" or macro == "EXPECT_STREQ": + return f"{catch_macro}(std::string_view({args[0]}) {op} {args[1]})" + return f"{catch_macro}({args[0]} {op} {args[1]})" + if macro in boolean_macros and len(args) == 1: + return f"{boolean_macros[macro]}({args[0]})" + if macro in {"EXPECT_DEATH", "ASSERT_DEATH"} and len(args) == 2: + return f"CHECK_DEATH({args[0]}, {args[1]})" + if macro == "EXPECT_THROW" and len(args) == 2: + return f"CHECK_THROWS_AS({args[0]}, {args[1]})" + if macro == "EXPECT_NEAR" and len(args) == 3: + return f"CHECK_THAT({args[0]}, Catch::Matchers::WithinAbs({args[1]}, {args[2]}))" + return None + + return _replace_macro_invocations( + content, + set(comparison_macros) + | set(boolean_macros) + | {"EXPECT_DEATH", "ASSERT_DEATH", "EXPECT_THROW", "EXPECT_NEAR"}, + replace, + ) + + +def run_test_replacements(files: list[Path]): + catch_includes = ( + "#include \n" + "#include \n" + "#include \n" + "#include \n" + "#include \n" + ) + + for wpi_file in files: + with open(wpi_file) as f: + content = f.read() + + had_gtest = ( + '#include "gmock/gmock.h"\n' in content + or '#include "gtest/gtest.h"\n' in content + or "#include \n" in content + or "#include \n" in content + ) + content = content.replace('#include "gmock/gmock.h"\n', "") + content = content.replace('#include "gtest/gtest.h"\n', "") + content = content.replace("#include \n", "") + content = content.replace("#include \n", "") + content = content.replace(" : public ::testing::Test", "") + if had_gtest and "#include \n)(?!#include ")', content) + if include_match: + content = ( + content[: include_match.end()] + + catch_includes + + content[include_match.end() :] + ) + + content = re.sub( + r"\bTEST\(([^,\n]+),\s*([^)]+)\)", + r'TEST_CASE("\1 \2", "[wpimath][units]")', + content, + ) + content = re.sub( + r"\bTEST_F\(([^,\n]+),\s*([^)]+)\)", + r'TEST_CASE_METHOD(\1, "\1 \2", "[wpimath][units]")', + content, + ) + content = re.sub(r"\bSCOPED_TRACE\(", "UNSCOPED_INFO(", content) + content = _replace_gtest_assertions(content) + + with open(wpi_file, "w") as f: + f.write(content) + + +def copy_upstream_src(wpilib_root: Path): + upstream_root = Path(".").absolute() + wpimath = wpilib_root / "wpimath" + + # Delete old install + for d in [ + "src/main/native/thirdparty/units/include", + "src/test/native/cpp/units", + ]: + shutil.rmtree(wpimath / d, ignore_errors=True) + + # Copy units include files into allwpilib + os.chdir(upstream_root / "include") + files = walk_if(Path("."), lambda dp, f: True) + src_include_files = [f.absolute() for f in files] + wpimath_units_root = wpimath / "src/main/native/thirdparty/units/include/wpi" + dest_include_files = [(wpimath_units_root / f).with_suffix(".hpp") for f in files] + + # Rename to .hpp + for i in range(len(src_include_files)): + dest_dir = dest_include_files[i].parent + if not dest_dir.exists(): + dest_dir.mkdir(parents=True) + shutil.copyfile(src_include_files[i], dest_include_files[i]) + + os.chdir(upstream_root / "test") + test_files = walk_cwd_and_copy_if( + lambda dp, f: f == "main.cpp" or f == "odrDimensionConcept.h", + wpimath / "src/test/native/cpp/units", + ) + run_test_replacements(test_files) + # Perform namespace renames + for wpi_file in dest_include_files + test_files: + content: str + with open(wpi_file) as f: + content = f.read() + + content = content.replace("units::", "wpi::units::") + content = content.replace("namespace units", "namespace wpi::units") + content = re.sub( + "#include ", "#include ") + + with open(wpi_file, "w") as f: + f.write(content) + + +def main(): + name = "units" + url = "https://github.com/nholthaus/units.git" + tag = "v3.6.0" + + units = Lib(name, url, tag, copy_upstream_src) + units.main() + + +if __name__ == "__main__": + main() diff --git a/upstream_utils/units_patches/0001-Add-more-units.patch b/upstream_utils/units_patches/0001-Add-more-units.patch new file mode 100644 index 00000000000..cb3b933cfa9 --- /dev/null +++ b/upstream_utils/units_patches/0001-Add-more-units.patch @@ -0,0 +1,328 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Joseph Eng <91924258+KangarooKoala@users.noreply.github.com> +Date: Wed, 3 Dec 2025 17:56:23 -0800 +Subject: [PATCH 01/12] Add more units + +--- + include/units/angular_acceleration.h | 71 ++++++++++++++++++++++++++++ + include/units/angular_jerk.h | 69 +++++++++++++++++++++++++++ + include/units/angular_velocity.h | 1 + + include/units/core.h | 2 + + include/units/curvature.h | 57 ++++++++++++++++++++++ + include/units/moment_of_inertia.h | 57 ++++++++++++++++++++++ + 6 files changed, 257 insertions(+) + create mode 100644 include/units/angular_acceleration.h + create mode 100644 include/units/angular_jerk.h + create mode 100644 include/units/curvature.h + create mode 100644 include/units/moment_of_inertia.h + +diff --git a/include/units/angular_acceleration.h b/include/units/angular_acceleration.h +new file mode 100644 +index 0000000000000000000000000000000000000000..2554472a3bbca39550854de7a84d832560812375 +--- /dev/null ++++ b/include/units/angular_acceleration.h +@@ -0,0 +1,71 @@ ++//-------------------------------------------------------------------------------------------------- ++// ++// UnitConversion: A compile-time c++14 unit conversion library with no dependencies ++// ++//-------------------------------------------------------------------------------------------------- ++// ++// The MIT License (MIT) ++// ++// Permission is hereby granted, free of charge, to any person obtaining a copy of this software ++// and associated documentation files (the "Software"), to deal in the Software without ++// restriction, including without limitation the rights to use, copy, modify, merge, publish, ++// distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the ++// Software is furnished to do so, subject to the following conditions: ++// ++// The above copyright notice and this permission notice shall be included in all copies or ++// substantial portions of the Software. ++// ++// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING ++// BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ++// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, ++// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING ++// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ++// ++//-------------------------------------------------------------------------------------------------- ++// ++// Copyright (c) 2016 Nic Holthaus ++// ++//-------------------------------------------------------------------------------------------------- ++// ++// ATTRIBUTION: ++// Parts of this work have been adapted from: ++// http://stackoverflow.com/questions/35069778/create-comparison-trait-for-template-classes-whose-parameters-are-in-a-different ++// http://stackoverflow.com/questions/28253399/check-traits-for-all-variadic-template-arguments/28253503 ++// http://stackoverflow.com/questions/36321295/rational-approximation-of-square-root-of-stdratio-at-compile-time?noredirect=1#comment60266601_36321295 ++// https://github.com/swatanabe/cppnow17-units ++// ++//-------------------------------------------------------------------------------------------------- ++// ++/// @file units/angular_acceleration.h ++/// @brief units representing angular acceleration values ++// ++//-------------------------------------------------------------------------------------------------- ++ ++#pragma once ++ ++#ifndef units_angular_acceleration_h_ ++#define units_angular_acceleration_h_ ++ ++#include ++#include ++ ++namespace units ++{ ++ /** ++ * @namespace units::angular_acceleration ++ * @brief namespace for unit types and containers representing angular acceleration values ++ * @details The SI unit for angular acceleration is `radians_per_second_squared`, and the corresponding `dimension` ++ *dimension is `angular_acceleration_unit`. ++ * @anchor angularAccelerationContainers ++ * @sa See unit for more information on unit type containers. ++ */ ++ UNIT_ADD(angular_acceleration, radians_per_second_squared, rad_per_s_sq, conversion_factor, dimension::angular_acceleration>) ++ UNIT_ADD(angular_acceleration, degrees_per_second_squared, deg_per_s_sq, compound_conversion_factor>>) ++ UNIT_ADD(angular_acceleration, turns_per_second_squared, tr_per_s_sq, compound_conversion_factor>>) ++ UNIT_ADD(angular_acceleration, revolutions_per_minute_squared, rev_per_m_sq, compound_conversion_factor>>) ++ UNIT_ADD(angular_acceleration, revolutions_per_minute_per_second, rev_per_m_per_s, compound_conversion_factor, inverse>) ++ ++ UNIT_ADD_DIMENSION_TRAIT(angular_acceleration, AngularAcceleration) ++} // namespace units ++ ++#endif // units_angular_acceleration_h_ +diff --git a/include/units/angular_jerk.h b/include/units/angular_jerk.h +new file mode 100644 +index 0000000000000000000000000000000000000000..92613acbf5c8866373b9b39227e7ec3962477338 +--- /dev/null ++++ b/include/units/angular_jerk.h +@@ -0,0 +1,69 @@ ++//-------------------------------------------------------------------------------------------------- ++// ++// UnitConversion: A compile-time c++14 unit conversion library with no dependencies ++// ++//-------------------------------------------------------------------------------------------------- ++// ++// The MIT License (MIT) ++// ++// Permission is hereby granted, free of charge, to any person obtaining a copy of this software ++// and associated documentation files (the "Software"), to deal in the Software without ++// restriction, including without limitation the rights to use, copy, modify, merge, publish, ++// distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the ++// Software is furnished to do so, subject to the following conditions: ++// ++// The above copyright notice and this permission notice shall be included in all copies or ++// substantial portions of the Software. ++// ++// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING ++// BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ++// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, ++// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING ++// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ++// ++//-------------------------------------------------------------------------------------------------- ++// ++// Copyright (c) 2016 Nic Holthaus ++// ++//-------------------------------------------------------------------------------------------------- ++// ++// ATTRIBUTION: ++// Parts of this work have been adapted from: ++// http://stackoverflow.com/questions/35069778/create-comparison-trait-for-template-classes-whose-parameters-are-in-a-different ++// http://stackoverflow.com/questions/28253399/check-traits-for-all-variadic-template-arguments/28253503 ++// http://stackoverflow.com/questions/36321295/rational-approximation-of-square-root-of-stdratio-at-compile-time?noredirect=1#comment60266601_36321295 ++// https://github.com/swatanabe/cppnow17-units ++// ++//-------------------------------------------------------------------------------------------------- ++// ++/// @file units/angular_jerk.h ++/// @brief units representing angular jerk values ++// ++//-------------------------------------------------------------------------------------------------- ++ ++#pragma once ++ ++#ifndef units_angular_jerk_h_ ++#define units_angular_jerk_h_ ++ ++#include ++#include ++ ++namespace units ++{ ++ /** ++ * @namespace units::angular_jerk ++ * @brief namespace for unit types and containers representing angular jerk values ++ * @details The SI unit for angular jerk is `radians_per_second_squared`, and the corresponding `dimension` ++ *dimension is `angular_jerk_unit`. ++ * @anchor angularJerkContainers ++ * @sa See unit for more information on unit type containers. ++ */ ++ UNIT_ADD(angular_jerk, radians_per_second_cubed, rad_per_s_cu, conversion_factor, dimension::angular_jerk>) ++ UNIT_ADD(angular_jerk, degrees_per_second_cubed, deg_per_s_cu, compound_conversion_factor>>) ++ UNIT_ADD(angular_jerk, turns_per_second_cubed, tr_per_s_cu, compound_conversion_factor>>) ++ ++ UNIT_ADD_DIMENSION_TRAIT(angular_jerk, AngularJerk) ++} // namespace units ++ ++#endif // units_jerk_h_ +diff --git a/include/units/angular_velocity.h b/include/units/angular_velocity.h +index e39a54941883fa3d5bcb2add2fff42003881c7d1..14a0d41005dcd8e25a678081fde7408fed6c7d53 100644 +--- a/include/units/angular_velocity.h ++++ b/include/units/angular_velocity.h +@@ -61,6 +61,7 @@ namespace units + */ + UNIT_ADD(angular_velocity, radians_per_second, rad_per_s, conversion_factor, dimension::angular_velocity>) + UNIT_ADD(angular_velocity, degrees_per_second, deg_per_s, compound_conversion_factor>) ++ UNIT_ADD(angular_velocity, turns_per_second, tps, compound_conversion_factor>) + UNIT_ADD(angular_velocity, revolutions_per_minute, rpm, conversion_factor, radians_per_second_, std::ratio<1>>) + UNIT_ADD(angular_velocity, revolutions_per_second, rps, conversion_factor, radians_per_second<>, std::ratio<1>>) + UNIT_ADD(angular_velocity, milliarcseconds_per_year, mas_per_yr, compound_conversion_factor, inverse>>) +diff --git a/include/units/core.h b/include/units/core.h +index 6d02beb2180b79adc376af529cba8a6ee1215ac6..c868f7876f0b2370681e298a21e5e9103a7a7ed4 100644 +--- a/include/units/core.h ++++ b/include/units/core.h +@@ -1348,6 +1348,7 @@ namespace units + using velocity = dimension_divide; ///< Represents an SI derived unit of velocity + using angular_velocity = dimension_divide; ///< Represents an SI derived unit of angular velocity + using acceleration = dimension_divide; ///< Represents an SI derived unit of acceleration ++ using angular_acceleration = dimension_divide; ///< Represents an SI derived unit of angular acceleration + using force = dimension_multiply; ///< Represents an SI derived unit of force + using area = dimension_pow>; ///< Represents an SI derived unit of area + using volume = dimension_pow>; ///< Represents an SI derived unit of volume +@@ -1379,6 +1380,7 @@ namespace units + + // OTHER UNIT TYPES + using jerk = make_dimension, time, std::ratio<-3>>; ///< Represents an SI derived unit of jerk ++ using angular_jerk = make_dimension, time, std::ratio<-3>>; ///< Represents an SI derived unit of angular jerk + using torque = dimension_multiply; ///< Represents an SI derived unit of torque + using density = dimension_divide; ///< Represents an SI derived unit of density + using dynamic_viscosity = dimension_multiply; ///< Represents an SI derived unit of dynamic (absolute) viscosity +diff --git a/include/units/curvature.h b/include/units/curvature.h +new file mode 100644 +index 0000000000000000000000000000000000000000..8dcd7451a6ef5db0e47df6c9e7438f397fdc6794 +--- /dev/null ++++ b/include/units/curvature.h +@@ -0,0 +1,57 @@ ++//-------------------------------------------------------------------------------------------------- ++// ++// UnitConversion: A compile-time c++14 unit conversion library with no dependencies ++// ++//-------------------------------------------------------------------------------------------------- ++// ++// The MIT License (MIT) ++// ++// Permission is hereby granted, free of charge, to any person obtaining a copy of this software ++// and associated documentation files (the "Software"), to deal in the Software without ++// restriction, including without limitation the rights to use, copy, modify, merge, publish, ++// distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the ++// Software is furnished to do so, subject to the following conditions: ++// ++// The above copyright notice and this permission notice shall be included in all copies or ++// substantial portions of the Software. ++// ++// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING ++// BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ++// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, ++// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING ++// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ++// ++//-------------------------------------------------------------------------------------------------- ++// ++// Copyright (c) 2016 Nic Holthaus ++// ++//-------------------------------------------------------------------------------------------------- ++// ++// ATTRIBUTION: ++// Parts of this work have been adapted from: ++// http://stackoverflow.com/questions/35069778/create-comparison-trait-for-template-classes-whose-parameters-are-in-a-different ++// http://stackoverflow.com/questions/28253399/check-traits-for-all-variadic-template-arguments/28253503 ++// http://stackoverflow.com/questions/36321295/rational-approximation-of-square-root-of-stdratio-at-compile-time?noredirect=1#comment60266601_36321295 ++// https://github.com/swatanabe/cppnow17-units ++// ++//-------------------------------------------------------------------------------------------------- ++// ++/// @file units/curvature.h ++/// @brief units representing curvature values ++// ++//-------------------------------------------------------------------------------------------------- ++ ++#pragma once ++ ++#ifndef units_curvature_h_ ++#define units_curvature_h_ ++ ++#include ++#include ++ ++namespace units ++{ ++using curvature_t = unit>>; ++} // namespace units ++ ++#endif // units_curvature_h_ +diff --git a/include/units/moment_of_inertia.h b/include/units/moment_of_inertia.h +new file mode 100644 +index 0000000000000000000000000000000000000000..60d80d19c5f7e9baa32e5d6549b73c50c6f5c53f +--- /dev/null ++++ b/include/units/moment_of_inertia.h +@@ -0,0 +1,57 @@ ++//-------------------------------------------------------------------------------------------------- ++// ++// UnitConversion: A compile-time c++14 unit conversion library with no dependencies ++// ++//-------------------------------------------------------------------------------------------------- ++// ++// The MIT License (MIT) ++// ++// Permission is hereby granted, free of charge, to any person obtaining a copy of this software ++// and associated documentation files (the "Software"), to deal in the Software without ++// restriction, including without limitation the rights to use, copy, modify, merge, publish, ++// distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the ++// Software is furnished to do so, subject to the following conditions: ++// ++// The above copyright notice and this permission notice shall be included in all copies or ++// substantial portions of the Software. ++// ++// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING ++// BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ++// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, ++// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING ++// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ++// ++//-------------------------------------------------------------------------------------------------- ++// ++// Copyright (c) 2016 Nic Holthaus ++// ++//-------------------------------------------------------------------------------------------------- ++// ++// ATTRIBUTION: ++// Parts of this work have been adapted from: ++// http://stackoverflow.com/questions/35069778/create-comparison-trait-for-template-classes-whose-parameters-are-in-a-different ++// http://stackoverflow.com/questions/28253399/check-traits-for-all-variadic-template-arguments/28253503 ++// http://stackoverflow.com/questions/36321295/rational-approximation-of-square-root-of-stdratio-at-compile-time?noredirect=1#comment60266601_36321295 ++// https://github.com/swatanabe/cppnow17-units ++// ++//-------------------------------------------------------------------------------------------------- ++// ++/// @file units/moment_of_inertia.h ++/// @brief units representing moment_of_inertia values ++// ++//-------------------------------------------------------------------------------------------------- ++ ++#pragma once ++ ++#ifndef units_moment_of_inertia_h_ ++#define units_moment_of_inertia_h_ ++ ++#include ++#include ++ ++namespace units ++{ ++ UNIT_ADD(moment_of_inertia, kilogram_square_meters, kg_sq_m, compound_conversion_factor) ++} // namespace units ++ ++#endif // units_moment_of_inertia_h_ diff --git a/upstream_utils/units_patches/0002-Disable-iostream-support-by-default.patch b/upstream_utils/units_patches/0002-Disable-iostream-support-by-default.patch new file mode 100644 index 00000000000..4d7d3f7e8ab --- /dev/null +++ b/upstream_utils/units_patches/0002-Disable-iostream-support-by-default.patch @@ -0,0 +1,39 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Gold856 <117957790+Gold856@users.noreply.github.com> +Date: Sat, 22 Aug 2026 15:53:24 -0400 +Subject: [PATCH 02/12] Disable iostream support by default + +--- + include/units/core.h | 6 ++++++ + test/main.cpp | 1 + + 2 files changed, 7 insertions(+) + +diff --git a/include/units/core.h b/include/units/core.h +index c868f7876f0b2370681e298a21e5e9103a7a7ed4..1b260af3ceba4ce85ae31104f489b2347d4ed012 100644 +--- a/include/units/core.h ++++ b/include/units/core.h +@@ -69,6 +69,12 @@ + #include + #include + ++// We don't want to use iostream, but do want format ++#ifndef UNIT_LIB_FORCE_IOSTREAM ++#define UNIT_LIB_DISABLE_IOSTREAM ++#endif ++#define UNIT_LIB_ENABLE_FORMAT ++ + // --------------------------------------------------------------------------------------------------------------------- + // TEXT-FEATURE CONFIGURATION (opt-out; full capability is the default) + // --------------------------------------------------------------------------------------------------------------------- +diff --git a/test/main.cpp b/test/main.cpp +index bb3e0acb36b6d190b920425da19b79d05c44d68a..3b705a95d3ae68a70f7f91451a8b052c7c93e715 100644 +--- a/test/main.cpp ++++ b/test/main.cpp +@@ -6,6 +6,7 @@ + // test + #endif + ++#define UNIT_LIB_FORCE_IOSTREAM + #include + #include + #include diff --git a/upstream_utils/units_patches/0003-Group-doxygen-modules.patch b/upstream_utils/units_patches/0003-Group-doxygen-modules.patch new file mode 100644 index 00000000000..82874626999 --- /dev/null +++ b/upstream_utils/units_patches/0003-Group-doxygen-modules.patch @@ -0,0 +1,61 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Joseph Eng <91924258+KangarooKoala@users.noreply.github.com> +Date: Thu, 11 Dec 2025 20:30:41 -0800 +Subject: [PATCH 03/12] Group doxygen modules + +--- + include/units/core.h | 10 ++++++++++ + 1 file changed, 10 insertions(+) + +diff --git a/include/units/core.h b/include/units/core.h +index 1b260af3ceba4ce85ae31104f489b2347d4ed012..7f1f6a39b01004b3f720255fd39134e23fb8a1ae 100644 +--- a/include/units/core.h ++++ b/include/units/core.h +@@ -599,14 +599,20 @@ namespace units + // DOXYGEN + //---------------------------------- + ++ /** ++ * @defgroup Units Unit API ++ */ ++ + /** + * @defgroup UnitTypes Unit Types ++ * @ingroup Units + * @brief Defines a series of classes which contain dimensioned values. Unit types + * store a value, and support various arithmetic operations. + */ + + /** + * @defgroup UnitManipulators Unit Manipulators ++ * @ingroup Units + * @brief Defines a series of classes used to manipulate unit types, such as `inverse<>`, `squared<>`, and + * metric prefixes. Unit manipulators can be chained together, e.g. + * `inverse>>` to represent picoseconds^-2. +@@ -614,22 +620,26 @@ namespace units + + /** + * @defgroup UnitMath Unit Math ++ * @ingroup Units + * @brief Defines a collection of unit-enabled, strongly-typed versions of `` functions. + * @details Includes most c++11 extensions. + */ + + /** + * @defgroup Conversion Explicit Conversion ++ * @ingroup Units + * @brief Functions used to convert values of one logical type to another. + */ + + /** + * @defgroup TypeTraits Type Traits ++ * @ingroup Units + * @brief Defines a series of classes to obtain unit type information at compile-time. + */ + + /** + * @defgroup STDTypeTraits Standard Type Traits Specializations ++ * @ingroup Units + * @brief Specialization of `std::common_type` for unit types. + */ + diff --git a/upstream_utils/units_patches/0004-Fix-doxygen-macro-name-typo.patch b/upstream_utils/units_patches/0004-Fix-doxygen-macro-name-typo.patch new file mode 100644 index 00000000000..1b1577a4814 --- /dev/null +++ b/upstream_utils/units_patches/0004-Fix-doxygen-macro-name-typo.patch @@ -0,0 +1,22 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Joseph Eng <91924258+KangarooKoala@users.noreply.github.com> +Date: Fri, 12 Dec 2025 15:08:27 -0800 +Subject: [PATCH 04/12] Fix doxygen macro name typo + +--- + include/units/core.h | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/include/units/core.h b/include/units/core.h +index 7f1f6a39b01004b3f720255fd39134e23fb8a1ae..42b9a4a6c53cdea7b60e28febe24c262244ad7d7 100644 +--- a/include/units/core.h ++++ b/include/units/core.h +@@ -2518,7 +2518,7 @@ namespace units + + namespace traits + { +-#ifdef FOR_DOXYGEN_PURPOSOES_ONLY ++#ifdef FOR_DOXYGEN_PURPOSES_ONLY + /** + * @ingroup TypeTraits + * @brief Trait for accessing the publicly defined types of `units::unit` diff --git a/upstream_utils/units_patches/0005-Use-gcem-for-C-20-constexpr-support.patch b/upstream_utils/units_patches/0005-Use-gcem-for-C-20-constexpr-support.patch new file mode 100644 index 00000000000..9bb83f26ebe --- /dev/null +++ b/upstream_utils/units_patches/0005-Use-gcem-for-C-20-constexpr-support.patch @@ -0,0 +1,399 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Joseph Eng <91924258+KangarooKoala@users.noreply.github.com> +Date: Tue, 16 Dec 2025 14:52:27 -0800 +Subject: [PATCH 05/12] Use gcem for C++20 constexpr support + +--- + include/units/angle.h | 54 ++++++++++++++-------------- + include/units/core.h | 82 ++++++++++++++++++++++++++++++++++--------- + 2 files changed, 93 insertions(+), 43 deletions(-) + +diff --git a/include/units/angle.h b/include/units/angle.h +index 0273ba237d99626824e2ddc2600d4fc152c52103..627b61d797150c7c33a9752f32c47fd700f16b35 100644 +--- a/include/units/angle.h ++++ b/include/units/angle.h +@@ -46,6 +46,8 @@ + #ifndef units_angle_h_ + #define units_angle_h_ + ++#include ++ + #include + + namespace units +@@ -88,9 +90,9 @@ namespace units + * @returns Returns the cosine of angle + */ + template, int> = 0> +- dimensionless> cos(const AngleUnit angle) noexcept ++ constexpr dimensionless> cos(const AngleUnit angle) noexcept + { +- return std::cos(convert>>(angle).value()); ++ return gcem::cos(convert>>(angle).value()); + } + + /** +@@ -102,9 +104,9 @@ namespace units + * @returns Returns the sine of angle + */ + template, int> = 0> +- dimensionless> sin(const AngleUnit angle) noexcept ++ constexpr dimensionless> sin(const AngleUnit angle) noexcept + { +- return std::sin(convert>>(angle).value()); ++ return gcem::sin(convert>>(angle).value()); + } + /** + * @ingroup UnitMath +@@ -115,9 +117,9 @@ namespace units + * @returns Returns the tangent of angle + */ + template, int> = 0> +- dimensionless> tan(const AngleUnit angle) noexcept ++ constexpr dimensionless> tan(const AngleUnit angle) noexcept + { +- return std::tan(convert>>(angle).value()); ++ return gcem::tan(convert>>(angle).value()); + } + + /** +@@ -128,10 +130,10 @@ namespace units + * @returns Principal arc cosine of x, in the interval [0,pi] radians. + */ + template, int> = 0> +- radians> acos(const dimensionlessUnit x) noexcept ++ constexpr radians> acos(const dimensionlessUnit x) noexcept + { + return radians>( +- std::acos(x.template to>())); ++ gcem::acos(x.template to>())); + } + + /** +@@ -142,10 +144,10 @@ namespace units + * @returns Principal arc sine of x, in the interval [-pi/2,+pi/2] radians. + */ + template, int> = 0> +- radians> asin(const dimensionlessUnit x) noexcept ++ constexpr radians> asin(const dimensionlessUnit x) noexcept + { + return radians>( +- std::asin(x.template to>())); ++ gcem::asin(x.template to>())); + } + + /** +@@ -160,10 +162,10 @@ namespace units + * @returns Principal arc tangent of x, in the interval [-pi/2,+pi/2] radians. + */ + template, int> = 0> +- radians> atan(const dimensionlessUnit x) noexcept ++ constexpr radians> atan(const dimensionlessUnit x) noexcept + { + return radians>( +- std::atan(x.template to>())); ++ gcem::atan(x.template to>())); + } + + /** +@@ -176,12 +178,12 @@ namespace units + * @returns Returns the principal value of the arc tangent of y/x, expressed in radians. + */ + template() / std::declval())>, int> = 0> +- radians>> atan2( ++ constexpr radians>> atan2( + const Y y, const X x) noexcept + { + using CommonUnit = std::common_type_t; + // X and Y could be different length units, so normalize them +- return radians>(std::atan2(CommonUnit(y).value(), CommonUnit(x).value())); ++ return radians>(gcem::atan2(CommonUnit(y).value(), CommonUnit(x).value())); + } + + //---------------------------------- +@@ -199,9 +201,9 @@ namespace units + * @returns the hyperbolic cosine of x + */ + template, int> = 0> +- dimensionless> cosh(const dimensionlessUnit x) noexcept ++ constexpr dimensionless> cosh(const dimensionlessUnit x) noexcept + { +- return std::cosh(x.template to>()); ++ return gcem::cosh(x.template to>()); + } + + /** +@@ -215,9 +217,9 @@ namespace units + * @returns the hyperbolic sine of x + */ + template, int> = 0> +- dimensionless> sinh(const dimensionlessUnit x) noexcept ++ constexpr dimensionless> sinh(const dimensionlessUnit x) noexcept + { +- return std::sinh(x.template to>()); ++ return gcem::sinh(x.template to>()); + } + + /** +@@ -231,9 +233,9 @@ namespace units + * @returns the hyperbolic tangent of x + */ + template, int> = 0> +- dimensionless> tanh(const dimensionlessUnit x) noexcept ++ constexpr dimensionless> tanh(const dimensionlessUnit x) noexcept + { +- return std::tanh(x.template to>()); ++ return gcem::tanh(x.template to>()); + } + + /** +@@ -246,10 +248,10 @@ namespace units + * @returns the nonnegative arc hyperbolic cosine of x, as a dimensionless quantity. + */ + template, int> = 0> +- dimensionless> acosh(const dimensionlessUnit x) noexcept ++ constexpr dimensionless> acosh(const dimensionlessUnit x) noexcept + { + return dimensionless>( +- std::acosh(x.template to>())); ++ gcem::acosh(x.template to>())); + } + + /** +@@ -261,10 +263,10 @@ namespace units + * @returns the arc hyperbolic sine of x, as a dimensionless quantity. + */ + template, int> = 0> +- dimensionless> asinh(const dimensionlessUnit x) noexcept ++ constexpr dimensionless> asinh(const dimensionlessUnit x) noexcept + { + return dimensionless>( +- std::asinh(x.template to>())); ++ gcem::asinh(x.template to>())); + } + + /** +@@ -277,10 +279,10 @@ namespace units + * @returns the arc hyperbolic tangent of x, as a dimensionless quantity. + */ + template, int> = 0> +- dimensionless> atanh(const dimensionlessUnit x) noexcept ++ constexpr dimensionless> atanh(const dimensionlessUnit x) noexcept + { + return dimensionless>( +- std::atanh(x.template to>())); ++ gcem::atanh(x.template to>())); + } + } // namespace units + +diff --git a/include/units/core.h b/include/units/core.h +index 42b9a4a6c53cdea7b60e28febe24c262244ad7d7..c9b9511cc0d64581d32d6f14d547e26f81ef9a51 100644 +--- a/include/units/core.h ++++ b/include/units/core.h +@@ -128,6 +128,8 @@ + #include + #endif + ++#include ++ + #if defined(UNIT_LIB_ENABLE_STRING) + #include + +@@ -5258,7 +5260,7 @@ namespace units + template + constexpr dimensionless> exp(const UnitType x) noexcept + { +- return std::exp(x.value()); ++ return gcem::exp(x.value()); + } + + /** +@@ -5273,7 +5275,7 @@ namespace units + template + constexpr dimensionless> log(const UnitType x) noexcept + { +- return std::log(x.value()); ++ return gcem::log(x.value()); + } + + /** +@@ -5287,7 +5289,7 @@ namespace units + template + constexpr dimensionless> log10(const UnitType x) noexcept + { +- return std::log10(x.value()); ++ return gcem::log10(x.value()); + } + + /** +@@ -5340,7 +5342,7 @@ namespace units + template + constexpr dimensionless> expm1(const UnitType x) noexcept + { +- return std::expm1(x.value()); ++ return gcem::expm1(x.value()); + } + + /** +@@ -5355,7 +5357,7 @@ namespace units + template + constexpr dimensionless> log1p(const UnitType x) noexcept + { +- return std::log1p(x.value()); ++ return gcem::log1p(x.value()); + } + + /** +@@ -5369,7 +5371,7 @@ namespace units + template + constexpr dimensionless> log2(const UnitType x) noexcept + { +- return std::log2(x.value()); ++ return gcem::log2(x.value()); + } + + //---------------------------------- +@@ -5412,7 +5414,7 @@ namespace units + constexpr detail::floating_point_promotion_t> hypot(const UnitTypeLhs& x, const UnitTypeRhs& y) + { + using CommonUnit = decltype(units::hypot(x, y)); +- return CommonUnit(std::hypot(CommonUnit(x).raw(), CommonUnit(y).raw())); ++ return CommonUnit(gcem::hypot(CommonUnit(x).raw(), CommonUnit(y).raw())); + } + + //---------------------------------- +@@ -5458,7 +5460,7 @@ namespace units + constexpr detail::floating_point_promotion_t> fmod(const UnitTypeLhs numer, const UnitTypeRhs denom) noexcept + { + using CommonUnit = decltype(units::fmod(numer, denom)); +- return CommonUnit(std::fmod(CommonUnit(numer).raw(), CommonUnit(denom).raw())); ++ return CommonUnit(gcem::fmod(CommonUnit(numer).raw(), CommonUnit(denom).raw())); + } + + /** +@@ -5472,7 +5474,7 @@ namespace units + template + constexpr detail::floating_point_promotion_t trunc(const UnitType x) noexcept + { +- return detail::floating_point_promotion_t(std::trunc(x.raw())); ++ return detail::floating_point_promotion_t(gcem::trunc(x.raw())); + } + + /** +@@ -5486,7 +5488,7 @@ namespace units + template + constexpr detail::floating_point_promotion_t round(const UnitType x) noexcept + { +- return detail::floating_point_promotion_t(std::round(x.raw())); ++ return detail::floating_point_promotion_t(gcem::round(x.raw())); + } + + /** @cond */ // DOXYGEN IGNORE +@@ -5665,14 +5667,14 @@ namespace units + template + constexpr detail::floating_point_promotion_t copysign(const UnitTypeLhs x, const UnitTypeRhs y) noexcept + { +- return detail::floating_point_promotion_t(std::copysign(x.raw(), y.raw())); // no need for conversion to get the correct sign. ++ return detail::floating_point_promotion_t(gcem::copysign(x.raw(), y.raw())); // no need for conversion to get the correct sign. + } + + /// Overload to copy the sign from a raw double + template + constexpr detail::floating_point_promotion_t copysign(const UnitTypeLhs x, const T& y) noexcept + { +- return detail::floating_point_promotion_t(std::copysign(x.raw(), y)); ++ return detail::floating_point_promotion_t(gcem::copysign(x.raw(), y)); + } + + //---------------------------------- +@@ -5708,7 +5710,31 @@ namespace units + constexpr detail::floating_point_promotion_t> fmax(const UnitTypeLhs x, const UnitTypeRhs y) noexcept + { + using CommonUnit = decltype(units::fmax(x, y)); +- return CommonUnit(std::fmax(CommonUnit(x).raw(), CommonUnit(y).raw())); ++ if (std::is_constant_evaluated()) ++ { ++ using UnderlyingType = CommonUnit::underlying_type; ++ UnderlyingType xval = CommonUnit(x).value(); ++ UnderlyingType yval = CommonUnit(y).value(); ++ // x is NaN, return y (whether or not y is NaN) ++ if (xval != xval) ++ { ++ return CommonUnit(yval); ++ } ++ // y is NaN, return x ++ else if (yval != yval) ++ { ++ return CommonUnit(xval); ++ } ++ // non-NaN values, safe to use normal max ++ else ++ { ++ return CommonUnit(gcem::max(xval, yval)); ++ } ++ } ++ else ++ { ++ return CommonUnit(std::fmax(CommonUnit(x).raw(), CommonUnit(y).raw())); ++ } + } + + /** +@@ -5725,7 +5751,29 @@ namespace units + constexpr detail::floating_point_promotion_t> fmin(const UnitTypeLhs x, const UnitTypeRhs y) noexcept + { + using CommonUnit = decltype(units::fmin(x, y)); +- return CommonUnit(std::fmin(CommonUnit(x).raw(), CommonUnit(y).raw())); ++ if (std::is_constant_evaluated()) { ++ using UnderlyingType = CommonUnit::underlying_type; ++ UnderlyingType xval = CommonUnit(x).value(); ++ UnderlyingType yval = CommonUnit(y).value(); ++ // x is NaN, return y (whether or not y is NaN) ++ if (xval != xval) ++ { ++ return CommonUnit(yval); ++ } ++ // y is NaN, return x ++ else if (yval != yval) ++ { ++ return CommonUnit(xval); ++ } ++ // non-NaN values, safe to use normal min ++ { ++ return CommonUnit(gcem::min(xval, yval)); ++ } ++ } ++ else ++ { ++ return CommonUnit(std::fmin(CommonUnit(x).raw(), CommonUnit(y).raw())); ++ } + } + + //---------------------------------- +@@ -5742,7 +5790,7 @@ namespace units + template + constexpr detail::floating_point_promotion_t fabs(const UnitType x) noexcept + { +- return detail::floating_point_promotion_t(std::fabs(x.raw())); ++ return detail::floating_point_promotion_t(gcem::fabs(x.raw())); + } + + /** +@@ -5755,7 +5803,7 @@ namespace units + template + constexpr UnitType abs(const UnitType x) noexcept + { +- return UnitType(std::abs(x.raw())); ++ return UnitType(gcem::abs(x.raw())); + } + + /** +@@ -5976,7 +6024,7 @@ namespace std + template + constexpr bool signbit(U x) + { +- return std::signbit(x.raw()); ++ return gcem::signbit(x.raw()); + } + } // namespace std + diff --git a/upstream_utils/units_patches/0006-Add-using-directive-for-literals-namespace.patch b/upstream_utils/units_patches/0006-Add-using-directive-for-literals-namespace.patch new file mode 100644 index 00000000000..c7460555eb3 --- /dev/null +++ b/upstream_utils/units_patches/0006-Add-using-directive-for-literals-namespace.patch @@ -0,0 +1,23 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Joseph Eng <91924258+KangarooKoala@users.noreply.github.com> +Date: Wed, 17 Dec 2025 17:27:13 -0800 +Subject: [PATCH 06/12] Add using-directive for literals namespace + +--- + include/units/core.h | 5 +++++ + 1 file changed, 5 insertions(+) + +diff --git a/include/units/core.h b/include/units/core.h +index c9b9511cc0d64581d32d6f14d547e26f81ef9a51..73638ba1ee5138502ab57f2dfc742770469b09e8 100644 +--- a/include/units/core.h ++++ b/include/units/core.h +@@ -6376,4 +6376,9 @@ namespace units + #endif + #endif + ++#ifndef UNIT_NO_LITERAL_SUPPORT ++namespace units::literals {} ++using namespace units::literals; ++#endif ++ + #endif // UNIT_CORE_H diff --git a/upstream_utils/units_patches/0007-Update-PLURAL_TAG-for-minutes.patch b/upstream_utils/units_patches/0007-Update-PLURAL_TAG-for-minutes.patch new file mode 100644 index 00000000000..ad50e84bcb6 --- /dev/null +++ b/upstream_utils/units_patches/0007-Update-PLURAL_TAG-for-minutes.patch @@ -0,0 +1,48 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Joseph Eng <91924258+KangarooKoala@users.noreply.github.com> +Date: Wed, 17 Dec 2025 17:35:32 -0800 +Subject: [PATCH 07/12] Update PLURAL_TAG for minutes + +--- + include/units/time.h | 15 ++++++--------- + 1 file changed, 6 insertions(+), 9 deletions(-) + +diff --git a/include/units/time.h b/include/units/time.h +index 9289985cfb8c1ba074025b2f9ef0d4128dbf16d3..3fe2f9f4c961e918c3f582e717410a0f0296d371 100644 +--- a/include/units/time.h ++++ b/include/units/time.h +@@ -49,20 +49,17 @@ + #include + + /** +- * @def UNIT_ADD_WITH_PLURAL_TAG(namespaceName, namePlural, abbreviation, definition) +- * @brief Like `UNIT_ADD`, but WITHOUT the unit constant, whose name would collide with the +- * abbreviation, e.g. `minutes` with abbreviation `min` (the constant `min` clashes). +- * @details Registers everything `UNIT_ADD` does except `UNIT_ADD_CONSTANT`: the strong conversion +- * factor and the named-class registration are included so `name()`/`abbreviation()` resolve +- * and diagnostics print the friendly type, exactly as for a `UNIT_ADD` unit. ++ * @def UNIT_ADD_WITH_PLURAL_CONSTANT(namespaceName, namePlural, abbreviation, definition) ++ * @brief Like `UNIT_ADD`, but the constant name is plural, e.g. `5 * mins` + * @sa `UNIT_ADD` + */ +-#define UNIT_ADD_WITH_PLURAL_TAG(namespaceName, namePlural, abbreviation, /*definition*/...) \ ++#define UNIT_ADD_WITH_PLURAL_CONSTANT(namespaceName, namePlural, abbreviation, /*definition*/...) \ + UNIT_ADD_STRONG_CONVERSION_FACTOR(namespaceName, namePlural, __VA_ARGS__) \ + UNIT_ADD_UNIT_DEFINITION(namespaceName, namePlural, __VA_ARGS__) \ + UNIT_ADD_NAME(namespaceName, namePlural, abbreviation) \ + UNIT_REGISTER_NAMED_CLASS(namespaceName, namePlural) \ +- UNIT_ADD_LITERALS(namespaceName, namePlural, abbreviation) ++ UNIT_ADD_LITERALS(namespaceName, namePlural, abbreviation) \ ++ UNIT_ADD_CONSTANT(namespaceName, namePlural, abbreviation##s) + + namespace units + { +@@ -75,7 +72,7 @@ namespace units + * @sa See unit for more information on unit type containers. + */ + UNIT_ADD_WITH_METRIC_PREFIXES(time, seconds, s, conversion_factor, dimension::time>) +- UNIT_ADD_WITH_PLURAL_TAG(time, minutes, min, conversion_factor, seconds_>) ++ UNIT_ADD_WITH_PLURAL_CONSTANT(time, minutes, min, conversion_factor, seconds_>) + UNIT_ADD(time, hours, hr, conversion_factor, minutes<>>) + UNIT_ADD(time, days, d, conversion_factor, hours_>) + UNIT_ADD(time, weeks, wk, conversion_factor, days_>) diff --git a/upstream_utils/units_patches/0008-Don-t-use-__int128.patch b/upstream_utils/units_patches/0008-Don-t-use-__int128.patch new file mode 100644 index 00000000000..8b1e745a2c4 --- /dev/null +++ b/upstream_utils/units_patches/0008-Don-t-use-__int128.patch @@ -0,0 +1,29 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Gold856 <117957790+Gold856@users.noreply.github.com> +Date: Mon, 17 Aug 2026 21:47:06 -0400 +Subject: [PATCH 08/12] Don't use __int128 + +--- + include/units/core.h | 6 ------ + 1 file changed, 6 deletions(-) + +diff --git a/include/units/core.h b/include/units/core.h +index 73638ba1ee5138502ab57f2dfc742770469b09e8..6101b5dd8c10fe26ddfe77d3d5a0e39eb4d76a5b 100644 +--- a/include/units/core.h ++++ b/include/units/core.h +@@ -2257,15 +2257,9 @@ namespace units + /// value that fits the target; a double-width intermediate holds the product. `__int128` is used where the + /// compiler provides it; otherwise the intermediate falls back to `std::intmax_t` (the widest standard + /// integer) and a manual 128-bit mul-divide guards the product. +-#if defined(__SIZEOF_INT128__) +- using widest_signed_int = __int128; +- using widest_unsigned_int = unsigned __int128; +- inline constexpr bool has_builtin_int128 = true; +-#else + using widest_signed_int = std::intmax_t; + using widest_unsigned_int = std::uintmax_t; + inline constexpr bool has_builtin_int128 = false; +-#endif + + /// Compute `value * num / den` for an integral `value` without overflowing the intermediate product, in a + /// double-width intermediate. On a compiler with `__int128` the whole expression rides in 128 bits; without diff --git a/upstream_utils/units_patches/0009-Remove-self-referential-include.patch b/upstream_utils/units_patches/0009-Remove-self-referential-include.patch new file mode 100644 index 00000000000..547f8e623ab --- /dev/null +++ b/upstream_utils/units_patches/0009-Remove-self-referential-include.patch @@ -0,0 +1,21 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Gold856 <117957790+Gold856@users.noreply.github.com> +Date: Wed, 19 Aug 2026 19:20:28 -0400 +Subject: [PATCH 09/12] Remove self-referential include + +--- + include/units/core.h | 1 - + 1 file changed, 1 deletion(-) + +diff --git a/include/units/core.h b/include/units/core.h +index 6101b5dd8c10fe26ddfe77d3d5a0e39eb4d76a5b..089690db7ddb8d98da97823b90626ca816035a43 100644 +--- a/include/units/core.h ++++ b/include/units/core.h +@@ -55,7 +55,6 @@ + // INCLUDES + //-------------------- + +-#include "core.h" + #include + #include + #include diff --git a/upstream_utils/units_patches/0010-Convert-tests-to-Catch2.patch b/upstream_utils/units_patches/0010-Convert-tests-to-Catch2.patch new file mode 100644 index 00000000000..fc26d5a1280 --- /dev/null +++ b/upstream_utils/units_patches/0010-Convert-tests-to-Catch2.patch @@ -0,0 +1,151 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Gold856 <117957790+Gold856@users.noreply.github.com> +Date: Fri, 21 Aug 2026 17:06:34 -0400 +Subject: [PATCH 10/12] Convert tests to Catch2 + +--- + test/main.cpp | 35 ++++++++++++++--------------------- + test/odrDimensionConcept.h | 4 ++-- + 2 files changed, 16 insertions(+), 23 deletions(-) + +diff --git a/test/main.cpp b/test/main.cpp +index 3b705a95d3ae68a70f7f91451a8b052c7c93e715..324ff5b7fd323364b4497d6b093d41b771957baa 100644 +--- a/test/main.cpp ++++ b/test/main.cpp +@@ -10,6 +10,7 @@ + #include + #include + #include ++#include + #include + #include + #include +@@ -21,12 +22,15 @@ + #include + #include + #include ++#include + #include + #include + #include + #include + #include +-#include ++// #include ++// Disable all tests that try to use iostream, as Catch2 can't capture stdout ++#define UNIT_LIB_DISABLE_IOSTREAM + + using namespace units; + using namespace units::literals; +@@ -2226,7 +2230,7 @@ TEST_F(UnitType, unitTypeMultiplication) + + // dimensionless result + result = 60_km / 400_mm; +- EXPECT_EQ(150'000, result); ++ EXPECT_EQ(150000, result); + + // concentration + percent pResult = percent(5.0) * percent(4.0); +@@ -2553,7 +2557,7 @@ TEST_F(UnitType, unitTypeDivision) + unit>> k = 50.0_pct / 1.0_m; + EXPECT_DOUBLE_EQ(k.value(), 0.5); + meters l = 10.0_km / 25.0_pct; +- EXPECT_EQ(l, 40'000.0_m); ++ EXPECT_EQ(l, 40000.0_m); + dimensionless m_dim = 5.0_pct / 4.0_pct; + EXPECT_EQ(m_dim, 1.25); + auto n = 5_pct / 4_pct; +@@ -3191,9 +3195,9 @@ TEST_F(UnitType, integerConversionWidensIntermediate) + (void)big; + + // 5e16 ft * 381 = 1.905e19 overflows int64 (max ~9.2e18), but 5e16 * 381 / 1250 = 1.524e16 fits. +- const std::int64_t v = 50'000'000'000'000'000LL; ++ const std::int64_t v = 50000000000000000LL; + const auto meters = units::convert>(feet(v)); +- EXPECT_EQ(15'240'000'000'000'000LL, meters.value()); ++ EXPECT_EQ(15240000000000000LL, meters.value()); + + // Ordinary and negative magnitudes are exact and unchanged (widening never alters a result that already fit). + EXPECT_EQ(381, units::convert>(feet(1250)).value()); +@@ -3257,7 +3261,7 @@ TEST_F(UnitType, hashOfLargeValueDoesNotOverflow) + // intermediate. With the widened conversion the hash of a big value is computed without undefined behavior + // (run under -fsanitize=undefined this must not trip). Equal values under one key type hash equally. + const auto h = std::hash>()(kilometers(3000)); // 3e9 mm +- EXPECT_EQ(h, std::hash>()(millimeters(3'000'000'000LL))); ++ EXPECT_EQ(h, std::hash>()(millimeters(3000000000LL))); + EXPECT_EQ(std::hash>()(meters(7)), std::hash>()(meters(7))); + } + +@@ -3542,7 +3546,7 @@ TEST(Consistency, recovers_input_values) + { + for (int i = 0; i <= 100; ++i) + { +- EXPECT_DOUBLE_EQ(i, units::concentration::percent(i).value() * 100); ++ CHECK_THAT(i, Catch::Matchers::WithinULP(units::concentration::percent(i).value() * 100, 1)); + } + } + +@@ -6232,12 +6236,7 @@ TEST_F(CaseStudies, selfDefinedUnits) + liters_per_second_squared copy = original; + + EXPECT_DOUBLE_EQ(original.to(), copy.to()); +- +- testing::internal::CaptureStdout(); +- std::cout << original; +- std::string output = testing::internal::GetCapturedStdout(); +- EXPECT_STREQ("0.005 m^3 s^-2", output.c_str()); +-} ++ } + + TEST_F(CaseStudies, idealGasLaw) + { +@@ -6371,7 +6370,7 @@ TEST_F(CompoundAssign, worksAcrossDimensions) + v *= 2.0; + EXPECT_NEAR(53.6448, v.value(), 5.0e-9); + } +- ++/* + // ---- #311: torque pound_feet is the named unit; foot_pounds is a deprecated alias --------------------------------- + TEST_F(TorqueNaming, poundFeetIsTheTorqueUnit) + { +@@ -7493,7 +7492,7 @@ TEST_F(Serialization, typedFastPathPropagatesDecodeError) + EXPECT_FALSE(r.has_value()); + EXPECT_EQ(units::deserialize_error::bad_version, r.error()); + } +- ++*/ + //====================================================================================================================== + // std::format SUPPORT + //====================================================================================================================== +@@ -7910,9 +7909,3 @@ TEST(Format, throwsOnMismatchedValueTypeSpec) + const units::meters md(3.5); + EXPECT_THROW((void)std::vformat("{:x}", std::make_format_args(md)), std::format_error); + } +- +-int main(int argc, char* argv[]) +-{ +- ::testing::InitGoogleTest(&argc, argv); +- return RUN_ALL_TESTS(); +-} +diff --git a/test/odrDimensionConcept.h b/test/odrDimensionConcept.h +index 6de67ff3db276e1ce35019a6d8500378b7efa3ff..c3ac2d0d52022004c4fb9bd989ba623c81c1ddb1 100644 +--- a/test/odrDimensionConcept.h ++++ b/test/odrDimensionConcept.h +@@ -195,7 +195,7 @@ TEST(OdrSafetyInvariant, LayoutIsIdenticalNamedVsPlainBase) + static_assert(sizeof(meters_per_second) == sizeof(double), "named velocity is exactly its underlying"); + SUCCEED(); + } +- ++/* + TEST(OdrSafetyInvariant, SerializationIsIdenticalNamedVsPlainBase) + { + // Audit surface (c): serialization is STABLE because the wire form is keyed on the runtime dimension signature +@@ -225,7 +225,7 @@ TEST(OdrSafetyInvariant, SerializationIsIdenticalNamedVsPlainBase) + EXPECT_DOUBLE_EQ(2.5, backNamed->template to()->value()); + EXPECT_DOUBLE_EQ(2.5, backBase->template to()->value()); + } +- ++*/ + //====================================================================================================================== + // sqrt — audit-proven STABLE (S7): sqrt(area) -> length, value and dimension correct + //====================================================================================================================== diff --git a/upstream_utils/units_patches/0011-Add-Tunable-and-Telemetry-support.patch b/upstream_utils/units_patches/0011-Add-Tunable-and-Telemetry-support.patch new file mode 100644 index 00000000000..3dae8f3746f --- /dev/null +++ b/upstream_utils/units_patches/0011-Add-Tunable-and-Telemetry-support.patch @@ -0,0 +1,136 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Gold856 <117957790+Gold856@users.noreply.github.com> +Date: Sat, 22 Aug 2026 02:38:08 -0400 +Subject: [PATCH 11/12] Add Tunable and Telemetry support + +--- + include/units/core.h | 95 ++++++++++++++++++++++++++++++++++++++++++++ + 1 file changed, 95 insertions(+) + +diff --git a/include/units/core.h b/include/units/core.h +index 089690db7ddb8d98da97823b90626ca816035a43..7c62a965d80ddefe57c56d612e5b236764564497 100644 +--- a/include/units/core.h ++++ b/include/units/core.h +@@ -127,6 +127,11 @@ + #include + #endif + ++#if __has_include() && !defined(UNIT_LIB_DISABLE_TELEMETRY) ++#include ++#include ++#include ++#endif + #include + + #if defined(UNIT_LIB_ENABLE_STRING) +@@ -211,6 +216,29 @@ namespace units + // MACROS + //------------------------------ + ++/** ++ * @def UNIT_ADD_TELEMETRY(namespaceName, namePlural, abbreviation) ++ * @brief Macro for generating the boiler-plate code needed for telemetry for a new unit. ++ * @details The macro generates the code to insert units into a wpi::telemetry::TelemetryTable ++ * @param namespaceName namespace in which the new units will be encapsulated. ++ * @param namePlural plural version of the unit name, e.g. 'meters' ++ * @param abbrev - abbreviated unit name, e.g. 'm' ++ * @note When UNIT_LIB_DISABLE_TELEMETRY is defined, the macro does not generate any code ++ */ ++#if __has_include() && !defined(UNIT_LIB_DISABLE_TELEMETRY) ++ #define UNIT_ADD_TELEMETRY(namespaceName, namePlural, abbrev)\ ++ inline namespace namespaceName\ ++ {\ ++ inline void LogValueTo(wpi::telemetry::TelemetryTable& table, std::string_view name, const namePlural <>& value)\ ++ {\ ++ table.SetProperty(name, "unit", "\"" #abbrev "\"");\ ++ table.Log(name, value.value());\ ++ }\ ++ } ++#else ++ #define UNIT_ADD_TELEMETRY(namespaceName, namePlural, abbrev) ++#endif ++ + /** + * @def UNIT_ADD_STRONG_CONVERSION_FACTOR(namespaceName, namePlural, __VA_ARGS__) + * @brief Helper macro for generating the boilerplate code generating the tags of a new unit. +@@ -465,6 +493,7 @@ namespace units + UNIT_ADD_UNIT_DEFINITION(namespaceName, namePlural, __VA_ARGS__) \ + UNIT_ADD_NAME(namespaceName, namePlural, abbreviation) \ + UNIT_REGISTER_NAMED_CLASS(namespaceName, namePlural) \ ++ UNIT_ADD_TELEMETRY(namespaceName, namePlural, abbreviation) \ + UNIT_ADD_LITERALS(namespaceName, namePlural, abbreviation) \ + UNIT_ADD_CONSTANT(namespaceName, namePlural, abbreviation) + +@@ -6369,6 +6398,72 @@ namespace units + #endif + #endif + ++//---------------------------------------------------------------------------------------------------------------------- ++// TELEMETRY SUPPORT ++//---------------------------------------------------------------------------------------------------------------------- ++namespace wpi::units { ++#if (__has_include() && !defined(UNIT_LIB_DISABLE_TELEMETRY)) || (__has_include() && !defined(UNIT_LIB_DISABLE_TUNABLE)) ++ namespace detail ++ { ++ template ++ constexpr auto only_if(const auto& s) ++ { ++ if constexpr (b) ++ { ++ return s; ++ } ++ else ++ { ++ using namespace wpi::util::literals; ++ return ""_ct_string; ++ } ++ } ++ ++ template ++ consteval auto dim_to_string(const dim&) ++ { ++ using namespace wpi::util::literals; ++ return wpi::util::Concat(only_if(" "_ct_string), ++ only_if<(E::num != 0)>(wpi::util::ct_string, std::string_view(D::abbreviation).size()>(std::string_view(D::abbreviation))), ++ only_if<(E::num != 0 && E::num != 1)>("^"_ct_string), only_if<(E::num != 0 && E::num != 1)>(wpi::util::NumToCtString()), only_if<(E::den != 1)>("/"_ct_string), ++ only_if<(E::den != 1)>(wpi::util::NumToCtString())); ++ } ++ template ++ consteval auto dims_to_string(const dimension_t&) ++ { ++ using namespace wpi::util::literals; ++ return wpi::util::Concat(dim_to_string(Dim{}), dim_to_string(Dims{})...); ++ } ++ // For dimensionless ++ consteval auto dims_to_string(const dimension_t<>&) ++ { ++ using namespace wpi::util::literals; ++ return ""_ct_string; ++ } ++ template ++ consteval auto ComplexAbbrev() ++ { ++ using conversion_factor = typename traits::unit_traits::conversion_factor; ++ using DimType = traits::dimension_of_t; ++ return dims_to_string(DimType{}); ++ } ++ } // namespace detail ++#endif ++ ++#if __has_include() && !defined(UNIT_LIB_DISABLE_TELEMETRY) ++ template ++ inline void LogValueTo(wpi::telemetry::TelemetryTable& table, std::string_view n, const Unit& value) ++ { ++ using BaseUnits = unit, traits::dimension_of_t>>; ++ using UnderlyingType = typename traits::unit_traits::underlying_type; ++ using namespace wpi::util::literals; ++ auto unitJson = wpi::util::Concat("\""_ct_string, detail::ComplexAbbrev(), "\""_ct_string); ++ table.SetProperty(n, "unit", unitJson); ++ table.Log(n, BaseUnits(value).template to()); ++ } ++#endif ++} // namespace wpi::units ++ + #ifndef UNIT_NO_LITERAL_SUPPORT + namespace units::literals {} + using namespace units::literals; diff --git a/upstream_utils/units_patches/0012-Move-ifdef-to-always-enable-to_string.patch b/upstream_utils/units_patches/0012-Move-ifdef-to-always-enable-to_string.patch new file mode 100644 index 00000000000..41f3058b417 --- /dev/null +++ b/upstream_utils/units_patches/0012-Move-ifdef-to-always-enable-to_string.patch @@ -0,0 +1,29 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Gold856 <117957790+Gold856@users.noreply.github.com> +Date: Sat, 22 Aug 2026 05:22:29 -0400 +Subject: [PATCH 12/12] Move ifdef to always enable to_string + +--- + include/units/core.h | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/include/units/core.h b/include/units/core.h +index 7c62a965d80ddefe57c56d612e5b236764564497..6fe49a1ba6505a9f53465234dd73d38391c0d938 100644 +--- a/include/units/core.h ++++ b/include/units/core.h +@@ -3604,6 +3604,7 @@ namespace units + + return os; + } ++#endif + + //---------------------------- + // to_string +@@ -3630,7 +3631,6 @@ namespace units + s.append(detail::unit_label(obj)); + return s; + } +-#endif + + //------------------------------ + // std::ratio helpers diff --git a/wpilibc/src/main/native/cpp/drive/MecanumDrive.cpp b/wpilibc/src/main/native/cpp/drive/MecanumDrive.cpp index 0aa43aa1a67..850c2ff5560 100644 --- a/wpilibc/src/main/native/cpp/drive/MecanumDrive.cpp +++ b/wpilibc/src/main/native/cpp/drive/MecanumDrive.cpp @@ -94,8 +94,8 @@ MecanumDrive::WheelVelocities MecanumDrive::DriveCartesianIK( yVelocity = std::clamp(yVelocity, -1.0, 1.0); // Compensate for gyro angle. - auto input = wpi::math::Translation2d{wpi::units::meter_t{xVelocity}, - wpi::units::meter_t{yVelocity}} + auto input = wpi::math::Translation2d{wpi::units::meters<>{xVelocity}, + wpi::units::meters<>{yVelocity}} .RotateBy(-gyroAngle); double wheelVelocities[4]; diff --git a/wpilibc/src/main/native/cpp/driverstation/Joystick.cpp b/wpilibc/src/main/native/cpp/driverstation/Joystick.cpp index 43a8558c6eb..68efd37a412 100644 --- a/wpilibc/src/main/native/cpp/driverstation/Joystick.cpp +++ b/wpilibc/src/main/native/cpp/driverstation/Joystick.cpp @@ -148,7 +148,7 @@ double Joystick::GetMagnitude() const { return std::hypot(GetX(), GetY()); } -wpi::units::radian_t Joystick::GetDirection() const { +wpi::units::radians<> 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 @@ -157,5 +157,5 @@ wpi::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 wpi::units::radian_t{std::atan2(GetX(), -GetY())}; + return wpi::units::radians<>{std::atan2(GetX(), -GetY())}; } diff --git a/wpilibc/src/main/native/cpp/driverstation/internal/DriverStationBackend.cpp b/wpilibc/src/main/native/cpp/driverstation/internal/DriverStationBackend.cpp index 06572256c5d..2c93e7dc0fc 100644 --- a/wpilibc/src/main/native/cpp/driverstation/internal/DriverStationBackend.cpp +++ b/wpilibc/src/main/native/cpp/driverstation/internal/DriverStationBackend.cpp @@ -1020,9 +1020,9 @@ std::optional DriverStationBackend::GetLocation() { } } -wpi::units::second_t DriverStationBackend::GetMatchTime() { +wpi::units::seconds<> DriverStationBackend::GetMatchTime() { int32_t status = 0; - return wpi::units::second_t{HAL_GetMatchTime(&status)}; + return wpi::units::seconds<>{HAL_GetMatchTime(&status)}; } double DriverStationBackend::GetBatteryVoltage() { diff --git a/wpilibc/src/main/native/cpp/event/BooleanEvent.cpp b/wpilibc/src/main/native/cpp/event/BooleanEvent.cpp index 35f9f457b76..bac2962ec00 100644 --- a/wpilibc/src/main/native/cpp/event/BooleanEvent.cpp +++ b/wpilibc/src/main/native/cpp/event/BooleanEvent.cpp @@ -67,7 +67,7 @@ BooleanEvent BooleanEvent::Falling() { }); } -BooleanEvent BooleanEvent::Debounce(wpi::units::second_t debounceTime, +BooleanEvent BooleanEvent::Debounce(wpi::units::seconds<> debounceTime, wpi::math::Debouncer::DebounceType type) { return BooleanEvent( this->m_loop, diff --git a/wpilibc/src/main/native/cpp/framework/IterativeRobotBase.cpp b/wpilibc/src/main/native/cpp/framework/IterativeRobotBase.cpp index 991c2f80278..1b13c5726fc 100644 --- a/wpilibc/src/main/native/cpp/framework/IterativeRobotBase.cpp +++ b/wpilibc/src/main/native/cpp/framework/IterativeRobotBase.cpp @@ -15,7 +15,7 @@ using namespace wpi; -IterativeRobotBase::IterativeRobotBase(wpi::units::second_t period) +IterativeRobotBase::IterativeRobotBase(wpi::units::seconds<> period) : m_period(period), m_watchdog(period, [this] { PrintLoopOverrunMessage(); }) {} @@ -87,7 +87,7 @@ void IterativeRobotBase::TeleopExit() {} void IterativeRobotBase::UtilityExit() {} -wpi::units::second_t IterativeRobotBase::GetPeriod() const { +wpi::units::seconds<> IterativeRobotBase::GetPeriod() const { return m_period; } diff --git a/wpilibc/src/main/native/cpp/framework/OpModeRobot.cpp b/wpilibc/src/main/native/cpp/framework/OpModeRobot.cpp index 6308a8edc82..24d04e92f57 100644 --- a/wpilibc/src/main/native/cpp/framework/OpModeRobot.cpp +++ b/wpilibc/src/main/native/cpp/framework/OpModeRobot.cpp @@ -28,7 +28,7 @@ using namespace wpi; -OpModeRobotBase::OpModeRobotBase(wpi::units::second_t period) +OpModeRobotBase::OpModeRobotBase(wpi::units::seconds<> period) : m_period{period}, m_loopOverrunAlert{ "opmode-loop-overrun", @@ -51,7 +51,7 @@ OpModeRobotBase::OpModeRobotBase(wpi::units::second_t period) OpModeRobotBase::OpModeRobotBase() : OpModeRobotBase(DEFAULT_PERIOD) {} void OpModeRobotBase::AddPeriodic(std::function callback, - wpi::units::second_t period) { + wpi::units::seconds<> period) { m_callbacks.Add(std::move(callback), m_startTime, period); } diff --git a/wpilibc/src/main/native/cpp/framework/RobotBase.cpp b/wpilibc/src/main/native/cpp/framework/RobotBase.cpp index 8dd59251716..d6098f96271 100644 --- a/wpilibc/src/main/native/cpp/framework/RobotBase.cpp +++ b/wpilibc/src/main/native/cpp/framework/RobotBase.cpp @@ -83,8 +83,8 @@ class WPILibMathShared : public wpi::math::MathShared { args); } - wpi::units::second_t GetTimestamp() override { - return wpi::units::second_t{wpi::util::Now() * 1.0e-9}; + wpi::units::seconds<> GetTimestamp() override { + return wpi::units::seconds<>{wpi::util::Now() * 1.0e-9}; } }; } // namespace diff --git a/wpilibc/src/main/native/cpp/framework/TimedRobot.cpp b/wpilibc/src/main/native/cpp/framework/TimedRobot.cpp index 8183d4d6efe..96c7ca2c98c 100644 --- a/wpilibc/src/main/native/cpp/framework/TimedRobot.cpp +++ b/wpilibc/src/main/native/cpp/framework/TimedRobot.cpp @@ -40,7 +40,7 @@ void TimedRobot::EndCompetition() { m_notifier = HAL_INVALID_HANDLE; } -TimedRobot::TimedRobot(wpi::units::second_t period) +TimedRobot::TimedRobot(wpi::units::seconds<> period) : IterativeRobotBase(period) { m_startTime = std::chrono::nanoseconds{RobotController::GetMonotonicTime()}; AddPeriodic([=, this] { LoopFunc(); }, period); @@ -53,7 +53,7 @@ TimedRobot::TimedRobot(wpi::units::second_t period) wpi::util::ReportUsage("Framework", "TimedRobot"); } -TimedRobot::TimedRobot(wpi::units::hertz_t frequency) +TimedRobot::TimedRobot(wpi::units::hertz<> frequency) : TimedRobot{1 / frequency} {} TimedRobot::~TimedRobot() { @@ -63,7 +63,7 @@ TimedRobot::~TimedRobot() { } void TimedRobot::AddPeriodic(std::function callback, - wpi::units::second_t period, - wpi::units::second_t offset) { + wpi::units::seconds<> period, + wpi::units::seconds<> offset) { m_callbacks.Add(std::move(callback), m_startTime, period, offset); } diff --git a/wpilibc/src/main/native/cpp/framework/TimesliceRobot.cpp b/wpilibc/src/main/native/cpp/framework/TimesliceRobot.cpp index 48e212c92c5..f21b0a4544e 100644 --- a/wpilibc/src/main/native/cpp/framework/TimesliceRobot.cpp +++ b/wpilibc/src/main/native/cpp/framework/TimesliceRobot.cpp @@ -8,13 +8,13 @@ using namespace wpi; -TimesliceRobot::TimesliceRobot(wpi::units::second_t robotPeriodicAllocation, - wpi::units::second_t controllerPeriod) +TimesliceRobot::TimesliceRobot(wpi::units::seconds<> robotPeriodicAllocation, + wpi::units::seconds<> controllerPeriod) : m_nextOffset{robotPeriodicAllocation}, m_controllerPeriod{controllerPeriod} {} void TimesliceRobot::Schedule(std::function func, - wpi::units::second_t allocation) { + wpi::units::seconds<> allocation) { if (m_nextOffset + allocation > m_controllerPeriod) { throw WPILIB_MakeError(err::Error, "Function scheduled at offset {} with allocation {} " diff --git a/wpilibc/src/main/native/cpp/hardware/bus/SerialPort.cpp b/wpilibc/src/main/native/cpp/hardware/bus/SerialPort.cpp index 48c08ff5877..08f3fb00dcd 100644 --- a/wpilibc/src/main/native/cpp/hardware/bus/SerialPort.cpp +++ b/wpilibc/src/main/native/cpp/hardware/bus/SerialPort.cpp @@ -119,7 +119,7 @@ int SerialPort::Write(std::string_view buffer) { return retVal; } -void SerialPort::SetTimeout(wpi::units::second_t timeout) { +void SerialPort::SetTimeout(wpi::units::seconds<> timeout) { int32_t status = 0; HAL_SetSerialTimeout(m_portHandle, timeout.value(), &status); WPILIB_CheckErrorStatus(status, "SetTimeout"); diff --git a/wpilibc/src/main/native/cpp/hardware/counter/Tachometer.cpp b/wpilibc/src/main/native/cpp/hardware/counter/Tachometer.cpp index 8a69288a72e..2420727bc22 100644 --- a/wpilibc/src/main/native/cpp/hardware/counter/Tachometer.cpp +++ b/wpilibc/src/main/native/cpp/hardware/counter/Tachometer.cpp @@ -33,18 +33,18 @@ void Tachometer::SetEdgeConfiguration(EdgeConfiguration configuration) { WPILIB_CheckErrorStatus(status, "{}", m_channel); } -void Tachometer::SetRateWindow(wpi::units::millisecond_t window) { +void Tachometer::SetRateWindow(wpi::units::milliseconds<> window) { int32_t status = 0; HAL_SetCounterRateWindow(m_handle, static_cast(window.value()), &status); WPILIB_CheckErrorStatus(status, "Channel {}", m_channel); } -wpi::units::hertz_t Tachometer::GetFrequency() const { +wpi::units::hertz<> Tachometer::GetFrequency() const { int32_t status = 0; double rate = HAL_GetCounterRate(m_handle, &status); WPILIB_CheckErrorStatus(status, "Channel {}", m_channel); - return wpi::units::hertz_t{rate}; + return wpi::units::hertz<>{rate}; } int Tachometer::GetEdgesPerRevolution() const { @@ -54,18 +54,18 @@ void Tachometer::SetEdgesPerRevolution(int edges) { m_edgesPerRevolution = edges; } -wpi::units::turns_per_second_t Tachometer::GetRevolutionsPerSecond() const { +wpi::units::turns_per_second<> Tachometer::GetRevolutionsPerSecond() const { int edgesPerRevolution = GetEdgesPerRevolution(); if (edgesPerRevolution == 0) { return 0_tps; } auto rotationHz = GetFrequency() / edgesPerRevolution; - return wpi::units::turns_per_second_t{rotationHz.value()}; + return wpi::units::turns_per_second<>{rotationHz.value()}; } -wpi::units::revolutions_per_minute_t Tachometer::GetRevolutionsPerMinute() +wpi::units::revolutions_per_minute<> Tachometer::GetRevolutionsPerMinute() const { - return wpi::units::revolutions_per_minute_t{GetRevolutionsPerSecond()}; + return wpi::units::revolutions_per_minute<>{GetRevolutionsPerSecond()}; } bool Tachometer::GetStopped() const { diff --git a/wpilibc/src/main/native/cpp/hardware/discrete/DigitalOutput.cpp b/wpilibc/src/main/native/cpp/hardware/discrete/DigitalOutput.cpp index 3cccd100187..e0ffe29dbaf 100644 --- a/wpilibc/src/main/native/cpp/hardware/discrete/DigitalOutput.cpp +++ b/wpilibc/src/main/native/cpp/hardware/discrete/DigitalOutput.cpp @@ -55,7 +55,7 @@ int DigitalOutput::GetChannel() const { return m_channel; } -void DigitalOutput::Pulse(wpi::units::second_t pulseLength) { +void DigitalOutput::Pulse(wpi::units::seconds<> pulseLength) { int32_t status = 0; HAL_Pulse(m_handle, pulseLength.value(), &status); WPILIB_CheckErrorStatus(status, "Channel {}", m_channel); diff --git a/wpilibc/src/main/native/cpp/hardware/discrete/PWM.cpp b/wpilibc/src/main/native/cpp/hardware/discrete/PWM.cpp index dfe7b63cd05..d4adf10b5c2 100644 --- a/wpilibc/src/main/native/cpp/hardware/discrete/PWM.cpp +++ b/wpilibc/src/main/native/cpp/hardware/discrete/PWM.cpp @@ -32,18 +32,18 @@ PWM::~PWM() { } } -void PWM::SetPulseTime(wpi::units::microsecond_t time) { +void PWM::SetPulseTime(wpi::units::microseconds<> time) { int32_t status = 0; HAL_SetPWMPulseTimeMicroseconds(m_handle, time.value(), &status); WPILIB_CheckErrorStatus(status, "Channel {}", m_channel); } -wpi::units::microsecond_t PWM::GetPulseTime() const { +wpi::units::microseconds<> PWM::GetPulseTime() const { int32_t status = 0; double value = HAL_GetPWMPulseTimeMicroseconds(m_handle, &status); WPILIB_CheckErrorStatus(status, "Channel {}", m_channel); - return wpi::units::microsecond_t{value}; + return wpi::units::microseconds<>{value}; } void PWM::SetDisabled() { @@ -52,7 +52,7 @@ void PWM::SetDisabled() { WPILIB_CheckErrorStatus(status, "Channel {}", m_channel); } -void PWM::SetOutputPeriod(wpi::units::millisecond_t period) { +void PWM::SetOutputPeriod(wpi::units::milliseconds<> period) { int32_t status = 0; switch (static_cast(period.value())) { diff --git a/wpilibc/src/main/native/cpp/hardware/expansionhub/ExpansionHubCRServo.cpp b/wpilibc/src/main/native/cpp/hardware/expansionhub/ExpansionHubCRServo.cpp index 109685a08e1..c7555a76a5f 100644 --- a/wpilibc/src/main/native/cpp/hardware/expansionhub/ExpansionHubCRServo.cpp +++ b/wpilibc/src/main/native/cpp/hardware/expansionhub/ExpansionHubCRServo.cpp @@ -66,7 +66,7 @@ void ExpansionHubCRServo::SetThrottle(double value) { SetPulseWidth(rawValue); } -void ExpansionHubCRServo::SetPulseWidth(wpi::units::microsecond_t pulseWidth) { +void ExpansionHubCRServo::SetPulseWidth(wpi::units::microseconds<> pulseWidth) { SetEnabled(true); m_pulseWidthPublisher.Set(pulseWidth.value()); } @@ -76,16 +76,17 @@ void ExpansionHubCRServo::SetEnabled(bool enabled) { } void ExpansionHubCRServo::SetFramePeriod( - wpi::units::microsecond_t framePeriod) { + wpi::units::microseconds<> framePeriod) { m_framePeriodPublisher.Set(framePeriod.value()); } -wpi::units::microsecond_t ExpansionHubCRServo::GetFullRangeScaleFactor() const { +wpi::units::microseconds<> ExpansionHubCRServo::GetFullRangeScaleFactor() + const { return m_maxPwm - m_minPwm; } -void ExpansionHubCRServo::SetPWMRange(wpi::units::microsecond_t minPwm, - wpi::units::microsecond_t maxPwm) { +void ExpansionHubCRServo::SetPWMRange(wpi::units::microseconds<> minPwm, + wpi::units::microseconds<> maxPwm) { if (maxPwm <= minPwm) { throw WPILIB_MakeError(err::ParameterOutOfRange, "Max PWM must be greater than Min PWM"); diff --git a/wpilibc/src/main/native/cpp/hardware/expansionhub/ExpansionHubMotor.cpp b/wpilibc/src/main/native/cpp/hardware/expansionhub/ExpansionHubMotor.cpp index 241df7723d8..2e5e30bb20f 100644 --- a/wpilibc/src/main/native/cpp/hardware/expansionhub/ExpansionHubMotor.cpp +++ b/wpilibc/src/main/native/cpp/hardware/expansionhub/ExpansionHubMotor.cpp @@ -102,7 +102,7 @@ void ExpansionHubMotor::SetThrottle(double throttle) { m_setpointPublisher.Set(throttle); } -void ExpansionHubMotor::SetVoltage(wpi::units::volt_t voltage) { +void ExpansionHubMotor::SetVoltage(wpi::units::volts<> voltage) { SetEnabled(true); m_modePublisher.Set(VOLTAGE_MODE); m_setpointPublisher.Set(voltage.value()); @@ -128,8 +128,8 @@ void ExpansionHubMotor::SetNeutralMode(NeutralMode mode) { m_floatOn0Publisher.Set(mode == NeutralMode::COAST); } -wpi::units::ampere_t ExpansionHubMotor::GetCurrent() const { - return wpi::units::ampere_t{m_currentSubscriber.Get(0)}; +wpi::units::amperes<> ExpansionHubMotor::GetCurrent() const { + return wpi::units::amperes<>{m_currentSubscriber.Get(0)}; } void ExpansionHubMotor::SetDistancePerCount(double perCount) { diff --git a/wpilibc/src/main/native/cpp/hardware/expansionhub/ExpansionHubServo.cpp b/wpilibc/src/main/native/cpp/hardware/expansionhub/ExpansionHubServo.cpp index 7db7633d4d2..dda84cfab1b 100644 --- a/wpilibc/src/main/native/cpp/hardware/expansionhub/ExpansionHubServo.cpp +++ b/wpilibc/src/main/native/cpp/hardware/expansionhub/ExpansionHubServo.cpp @@ -65,14 +65,14 @@ void ExpansionHubServo::SetPosition(double value) { SetPulseWidth(rawValue); } -void ExpansionHubServo::SetAngle(wpi::units::degree_t angle) { +void ExpansionHubServo::SetAngle(wpi::units::degrees<> angle) { angle = std::clamp(angle, m_minServoAngle, m_maxServoAngle); // NOLINTNEXTLINE(bugprone-integer-division) SetPosition((angle - m_minServoAngle) / GetServoAngleRange()); } -void ExpansionHubServo::SetPulseWidth(wpi::units::microsecond_t pulseWidth) { +void ExpansionHubServo::SetPulseWidth(wpi::units::microseconds<> pulseWidth) { SetEnabled(true); m_pulseWidthPublisher.Set(pulseWidth.value()); } @@ -81,20 +81,20 @@ void ExpansionHubServo::SetEnabled(bool enabled) { m_enabledPublisher.Set(enabled); } -void ExpansionHubServo::SetFramePeriod(wpi::units::microsecond_t framePeriod) { +void ExpansionHubServo::SetFramePeriod(wpi::units::microseconds<> framePeriod) { m_framePeriodPublisher.Set(framePeriod.value()); } -wpi::units::microsecond_t ExpansionHubServo::GetFullRangeScaleFactor() { +wpi::units::microseconds<> ExpansionHubServo::GetFullRangeScaleFactor() { return m_maxPwm - m_minPwm; } -wpi::units::degree_t ExpansionHubServo::GetServoAngleRange() { +wpi::units::degrees<> ExpansionHubServo::GetServoAngleRange() { return m_maxServoAngle - m_minServoAngle; } -void ExpansionHubServo::SetPWMRange(wpi::units::microsecond_t minPwm, - wpi::units::microsecond_t maxPwm) { +void ExpansionHubServo::SetPWMRange(wpi::units::microseconds<> minPwm, + wpi::units::microseconds<> maxPwm) { if (maxPwm <= minPwm) { throw WPILIB_MakeError(err::ParameterOutOfRange, "Max PWM must be greater than Min PWM"); @@ -107,8 +107,8 @@ void ExpansionHubServo::SetReversed(const bool reversed) { m_reversed = reversed; } -void ExpansionHubServo::SetAngleRange(wpi::units::degree_t minAngle, - wpi::units::degree_t maxAngle) { +void ExpansionHubServo::SetAngleRange(wpi::units::degrees<> minAngle, + wpi::units::degrees<> maxAngle) { if (maxAngle <= minAngle) { throw WPILIB_MakeError(err::ParameterOutOfRange, "Max angle must be greater than Min angle"); diff --git a/wpilibc/src/main/native/cpp/hardware/imu/OnboardIMU.cpp b/wpilibc/src/main/native/cpp/hardware/imu/OnboardIMU.cpp index 34451cb2dde..e9c7380cccb 100644 --- a/wpilibc/src/main/native/cpp/hardware/imu/OnboardIMU.cpp +++ b/wpilibc/src/main/native/cpp/hardware/imu/OnboardIMU.cpp @@ -14,7 +14,7 @@ OnboardIMU::OnboardIMU(MountOrientation mountOrientation) // TODO: usage reporting } -wpi::units::radian_t OnboardIMU::GetYawNoOffset() { +wpi::units::radians<> OnboardIMU::GetYawNoOffset() { int64_t timestamp; double val; switch (m_mountOrientation) { @@ -30,10 +30,10 @@ wpi::units::radian_t OnboardIMU::GetYawNoOffset() { default: val = 0; } - return wpi::units::radian_t{val}; + return wpi::units::radians<>{val}; } -wpi::units::radian_t OnboardIMU::GetYaw() { +wpi::units::radians<> OnboardIMU::GetYaw() { return GetYawNoOffset() - m_yawOffset; } @@ -57,7 +57,7 @@ wpi::math::Quaternion OnboardIMU::GetQuaternion() { return wpi::math::Quaternion{val.w, val.x, val.y, val.z}; } -wpi::units::radian_t OnboardIMU::GetAngleX() { +wpi::units::radians<> OnboardIMU::GetAngleX() { HAL_EulerAngles3d val; int32_t status = 0; switch (m_mountOrientation) { @@ -72,10 +72,10 @@ wpi::units::radian_t OnboardIMU::GetAngleX() { break; } WPILIB_CheckErrorStatus(status, "Onboard IMU"); - return wpi::units::radian_t{val.x}; + return wpi::units::radians<>{val.x}; } -wpi::units::radian_t OnboardIMU::GetAngleY() { +wpi::units::radians<> OnboardIMU::GetAngleY() { HAL_EulerAngles3d val; int32_t status = 0; switch (m_mountOrientation) { @@ -90,10 +90,10 @@ wpi::units::radian_t OnboardIMU::GetAngleY() { break; } WPILIB_CheckErrorStatus(status, "Onboard IMU"); - return wpi::units::radian_t{val.y}; + return wpi::units::radians<>{val.y}; } -wpi::units::radian_t OnboardIMU::GetAngleZ() { +wpi::units::radians<> OnboardIMU::GetAngleZ() { HAL_EulerAngles3d val; int32_t status = 0; switch (m_mountOrientation) { @@ -108,53 +108,53 @@ wpi::units::radian_t OnboardIMU::GetAngleZ() { break; } WPILIB_CheckErrorStatus(status, "Onboard IMU"); - return wpi::units::radian_t{val.z}; + return wpi::units::radians<>{val.z}; } -wpi::units::radians_per_second_t OnboardIMU::GetGyroRateX() { +wpi::units::radians_per_second<> OnboardIMU::GetGyroRateX() { HAL_GyroRate3d val; int32_t status = 0; HAL_GetIMUGyroRates(&val, &status); WPILIB_CheckErrorStatus(status, "Onboard IMU"); - return wpi::units::radians_per_second_t{val.x}; + return wpi::units::radians_per_second<>{val.x}; } -wpi::units::radians_per_second_t OnboardIMU::GetGyroRateY() { +wpi::units::radians_per_second<> OnboardIMU::GetGyroRateY() { HAL_GyroRate3d val; int32_t status = 0; HAL_GetIMUGyroRates(&val, &status); WPILIB_CheckErrorStatus(status, "Onboard IMU"); - return wpi::units::radians_per_second_t{val.y}; + return wpi::units::radians_per_second<>{val.y}; } -wpi::units::radians_per_second_t OnboardIMU::GetGyroRateZ() { +wpi::units::radians_per_second<> OnboardIMU::GetGyroRateZ() { HAL_GyroRate3d val; int32_t status = 0; HAL_GetIMUGyroRates(&val, &status); WPILIB_CheckErrorStatus(status, "Onboard IMU"); - return wpi::units::radians_per_second_t{val.z}; + return wpi::units::radians_per_second<>{val.z}; } -wpi::units::meters_per_second_squared_t OnboardIMU::GetAccelX() { +wpi::units::meters_per_second_squared<> OnboardIMU::GetAccelX() { HAL_Acceleration3d val; int32_t status = 0; HAL_GetIMUAcceleration(&val, &status); WPILIB_CheckErrorStatus(status, "Onboard IMU"); - return wpi::units::meters_per_second_squared_t{val.x}; + return wpi::units::meters_per_second_squared<>{val.x}; } -wpi::units::meters_per_second_squared_t OnboardIMU::GetAccelY() { +wpi::units::meters_per_second_squared<> OnboardIMU::GetAccelY() { HAL_Acceleration3d val; int32_t status = 0; HAL_GetIMUAcceleration(&val, &status); WPILIB_CheckErrorStatus(status, "Onboard IMU"); - return wpi::units::meters_per_second_squared_t{val.y}; + return wpi::units::meters_per_second_squared<>{val.y}; } -wpi::units::meters_per_second_squared_t OnboardIMU::GetAccelZ() { +wpi::units::meters_per_second_squared<> OnboardIMU::GetAccelZ() { HAL_Acceleration3d val; int32_t status = 0; HAL_GetIMUAcceleration(&val, &status); WPILIB_CheckErrorStatus(status, "Onboard IMU"); - return wpi::units::meters_per_second_squared_t{val.z}; + return wpi::units::meters_per_second_squared<>{val.z}; } diff --git a/wpilibc/src/main/native/cpp/hardware/led/LEDPattern.cpp b/wpilibc/src/main/native/cpp/hardware/led/LEDPattern.cpp index 6e82651fbcf..1e463a3f3ac 100644 --- a/wpilibc/src/main/native/cpp/hardware/led/LEDPattern.cpp +++ b/wpilibc/src/main/native/cpp/hardware/led/LEDPattern.cpp @@ -69,7 +69,7 @@ LEDPattern LEDPattern::OffsetBy(int offset) { }); } -LEDPattern LEDPattern::ScrollAtRelativeVelocity(wpi::units::hertz_t velocity) { +LEDPattern LEDPattern::ScrollAtRelativeVelocity(wpi::units::hertz<> 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,000 to get nanoseconds @@ -89,7 +89,7 @@ LEDPattern LEDPattern::ScrollAtRelativeVelocity(wpi::units::hertz_t velocity) { } LEDPattern LEDPattern::ScrollAtAbsoluteVelocity( - wpi::units::meters_per_second_t velocity, wpi::units::meter_t ledSpacing) { + wpi::units::meters_per_second<> velocity, wpi::units::meters<> ledSpacing) { // Velocity is in terms of meters per second // Multiply by 1,000,000,000 to use nanoseconds instead of seconds auto nanosPerLed = @@ -107,10 +107,10 @@ LEDPattern LEDPattern::ScrollAtAbsoluteVelocity( }); } -LEDPattern LEDPattern::Blink(wpi::units::second_t onTime, - wpi::units::second_t offTime) { - auto totalNanos = wpi::units::nanosecond_t{onTime + offTime}.to(); - auto onNanos = wpi::units::nanosecond_t{onTime}.to(); +LEDPattern LEDPattern::Blink(wpi::units::seconds<> onTime, + wpi::units::seconds<> offTime) { + auto totalNanos = wpi::units::nanoseconds<>{onTime + offTime}.to(); + auto onNanos = wpi::units::nanoseconds<>{onTime}.to(); return LEDPattern{[=, self = *this](auto data, auto writer) { if (wpi::util::Now() % totalNanos < onNanos) { @@ -121,7 +121,7 @@ LEDPattern LEDPattern::Blink(wpi::units::second_t onTime, }}; } -LEDPattern LEDPattern::Blink(wpi::units::second_t onTime) { +LEDPattern LEDPattern::Blink(wpi::units::seconds<> onTime) { return LEDPattern::Blink(onTime, onTime); } @@ -135,8 +135,8 @@ LEDPattern LEDPattern::SynchronizedBlink(std::function signal) { }}; } -LEDPattern LEDPattern::Breathe(wpi::units::second_t period) { - auto periodNanos = wpi::units::nanosecond_t{period}; +LEDPattern LEDPattern::Breathe(wpi::units::seconds<> period) { + auto periodNanos = wpi::units::nanoseconds<>{period}; return LEDPattern{[periodNanos, self = *this](auto data, auto writer) { self.ApplyTo(data, [&writer, periodNanos](int i, wpi::util::Color color) { diff --git a/wpilibc/src/main/native/cpp/hardware/motor/MotorController.cpp b/wpilibc/src/main/native/cpp/hardware/motor/MotorController.cpp index 712dfe8cdc2..da6a977c051 100644 --- a/wpilibc/src/main/native/cpp/hardware/motor/MotorController.cpp +++ b/wpilibc/src/main/native/cpp/hardware/motor/MotorController.cpp @@ -8,7 +8,7 @@ using namespace wpi; -void MotorController::SetVoltage(wpi::units::volt_t voltage) { +void MotorController::SetVoltage(wpi::units::volts<> voltage) { // NOLINTNEXTLINE(bugprone-integer-division) SetThrottle(voltage / RobotController::GetBatteryVoltage()); } diff --git a/wpilibc/src/main/native/cpp/hardware/motor/MotorSafety.cpp b/wpilibc/src/main/native/cpp/hardware/motor/MotorSafety.cpp index e5e5ba60dfe..f0331c35377 100644 --- a/wpilibc/src/main/native/cpp/hardware/motor/MotorSafety.cpp +++ b/wpilibc/src/main/native/cpp/hardware/motor/MotorSafety.cpp @@ -118,12 +118,12 @@ void MotorSafety::Feed() { m_stopTime = Timer::GetMonotonicTimestamp() + m_expiration; } -void MotorSafety::SetExpiration(wpi::units::second_t expirationTime) { +void MotorSafety::SetExpiration(wpi::units::seconds<> expirationTime) { std::scoped_lock lock(m_thisMutex); m_expiration = expirationTime; } -wpi::units::second_t MotorSafety::GetExpiration() const { +wpi::units::seconds<> 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; - wpi::units::second_t stopTime; + wpi::units::seconds<> stopTime; { std::scoped_lock lock(m_thisMutex); diff --git a/wpilibc/src/main/native/cpp/hardware/motor/PWMMotorController.cpp b/wpilibc/src/main/native/cpp/hardware/motor/PWMMotorController.cpp index d7258e427f8..73a76f99f4d 100644 --- a/wpilibc/src/main/native/cpp/hardware/motor/PWMMotorController.cpp +++ b/wpilibc/src/main/native/cpp/hardware/motor/PWMMotorController.cpp @@ -32,7 +32,7 @@ double PWMMotorController::GetThrottle() const { return GetDutyCycleInternal() * (m_isInverted ? -1.0 : 1.0); } -wpi::units::volt_t PWMMotorController::GetVoltage() const { +wpi::units::volts<> PWMMotorController::GetVoltage() const { return GetThrottle() * RobotController::GetBatteryVoltage(); } @@ -96,7 +96,7 @@ std::string_view PWMMotorController::GetTelemetryType() const { return "Motor Controller"; } -wpi::units::microsecond_t PWMMotorController::GetMinPositivePwm() const { +wpi::units::microseconds<> PWMMotorController::GetMinPositivePwm() const { if (m_eliminateDeadband) { return m_deadbandMaxPwm; } else { @@ -104,7 +104,7 @@ wpi::units::microsecond_t PWMMotorController::GetMinPositivePwm() const { } } -wpi::units::microsecond_t PWMMotorController::GetMaxNegativePwm() const { +wpi::units::microseconds<> PWMMotorController::GetMaxNegativePwm() const { if (m_eliminateDeadband) { return m_deadbandMinPwm; } else { @@ -112,11 +112,11 @@ wpi::units::microsecond_t PWMMotorController::GetMaxNegativePwm() const { } } -wpi::units::microsecond_t PWMMotorController::GetPositiveScaleFactor() const { +wpi::units::microseconds<> PWMMotorController::GetPositiveScaleFactor() const { return m_maxPwm - GetMinPositivePwm(); } -wpi::units::microsecond_t PWMMotorController::GetNegativeScaleFactor() const { +wpi::units::microseconds<> PWMMotorController::GetNegativeScaleFactor() const { return GetMaxNegativePwm() - m_minPwm; } @@ -131,15 +131,15 @@ void PWMMotorController::SetDutyCycleInternal(double dutyCycle) { m_simThrottle.Set(dutyCycle); } - wpi::units::microsecond_t rawValue; + wpi::units::microseconds<> rawValue; if (dutyCycle == 0.0) { rawValue = m_centerPwm; } else if (dutyCycle > 0.0) { - rawValue = wpi::units::microsecond_t{static_cast(std::lround( + rawValue = wpi::units::microseconds<>{static_cast(std::lround( (dutyCycle * GetPositiveScaleFactor()).value()))} + GetMinPositivePwm(); } else { - rawValue = wpi::units::microsecond_t{static_cast(std::lround( + rawValue = wpi::units::microseconds<>{static_cast(std::lround( (dutyCycle * GetNegativeScaleFactor()).value()))} + GetMaxNegativePwm(); } @@ -148,7 +148,7 @@ void PWMMotorController::SetDutyCycleInternal(double dutyCycle) { } double PWMMotorController::GetDutyCycleInternal() const { - wpi::units::microsecond_t rawValue = m_pwm.GetPulseTime(); + wpi::units::microseconds<> rawValue = m_pwm.GetPulseTime(); if (rawValue == 0_us) { return 0.0; @@ -167,11 +167,11 @@ double PWMMotorController::GetDutyCycleInternal() const { } } -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) { +void PWMMotorController::SetBounds(wpi::units::microseconds<> maxPwm, + wpi::units::microseconds<> deadbandMaxPwm, + wpi::units::microseconds<> centerPwm, + wpi::units::microseconds<> deadbandMinPwm, + wpi::units::microseconds<> minPwm) { m_maxPwm = maxPwm; m_deadbandMaxPwm = deadbandMaxPwm; m_centerPwm = centerPwm; diff --git a/wpilibc/src/main/native/cpp/hardware/pneumatic/Compressor.cpp b/wpilibc/src/main/native/cpp/hardware/pneumatic/Compressor.cpp index 2beb32658e7..aa89febb73d 100644 --- a/wpilibc/src/main/native/cpp/hardware/pneumatic/Compressor.cpp +++ b/wpilibc/src/main/native/cpp/hardware/pneumatic/Compressor.cpp @@ -40,15 +40,15 @@ bool Compressor::GetPressureSwitchValue() const { return m_module->GetPressureSwitch(); } -wpi::units::ampere_t Compressor::GetCurrent() const { +wpi::units::amperes<> Compressor::GetCurrent() const { return m_module->GetCompressorCurrent(); } -wpi::units::volt_t Compressor::GetAnalogVoltage() const { +wpi::units::volts<> Compressor::GetAnalogVoltage() const { return m_module->GetAnalogVoltage(0); } -wpi::units::pounds_per_square_inch_t Compressor::GetPressure() const { +wpi::units::pounds_per_square_inch<> Compressor::GetPressure() const { return m_module->GetPressure(0); } @@ -61,14 +61,14 @@ void Compressor::EnableDigital() { } void Compressor::EnableAnalog( - wpi::units::pounds_per_square_inch_t minPressure, - wpi::units::pounds_per_square_inch_t maxPressure) { + wpi::units::pounds_per_square_inch<> minPressure, + wpi::units::pounds_per_square_inch<> maxPressure) { m_module->EnableCompressorAnalog(minPressure, maxPressure); } void Compressor::EnableHybrid( - wpi::units::pounds_per_square_inch_t minPressure, - wpi::units::pounds_per_square_inch_t maxPressure) { + wpi::units::pounds_per_square_inch<> minPressure, + wpi::units::pounds_per_square_inch<> maxPressure) { m_module->EnableCompressorHybrid(minPressure, maxPressure); } diff --git a/wpilibc/src/main/native/cpp/hardware/pneumatic/PneumaticHub.cpp b/wpilibc/src/main/native/cpp/hardware/pneumatic/PneumaticHub.cpp index c7910b87591..2fb6b9429fb 100644 --- a/wpilibc/src/main/native/cpp/hardware/pneumatic/PneumaticHub.cpp +++ b/wpilibc/src/main/native/cpp/hardware/pneumatic/PneumaticHub.cpp @@ -24,17 +24,17 @@ using namespace wpi; /** Converts volts to PSI per the REV Analog Pressure Sensor datasheet. */ -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{ +wpi::units::pounds_per_square_inch<> VoltsToPSI( + wpi::units::volts<> sensorVoltage, wpi::units::volts<> supplyVoltage) { + return wpi::units::pounds_per_square_inch<>{ 250 * (sensorVoltage.value() / supplyVoltage.value()) - 25}; } /** Converts PSI to volts per the REV Analog Pressure Sensor datasheet. */ -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::units::volts<> PSIToVolts(wpi::units::pounds_per_square_inch<> pressure, + wpi::units::volts<> supplyVoltage) { + return wpi::units::volts<>{supplyVoltage.value() * + (0.004 * pressure.value() + 0.1)}; } wpi::util::mutex PneumaticHub::m_handleLock; @@ -93,7 +93,7 @@ class PneumaticHub::DataStore { bool m_compressorReserved{false}; wpi::util::mutex m_reservedLock; PneumaticHub m_moduleObject{CANBus::CAN_S0, HAL_INVALID_HANDLE, 0}; - std::array m_oneShotDurMs{0_ms}; + std::array, 16> m_oneShotDurMs{0_ms}; }; PneumaticHub::PneumaticHub(CANBus busId) @@ -136,8 +136,8 @@ void PneumaticHub::EnableCompressorDigital() { } void PneumaticHub::EnableCompressorAnalog( - wpi::units::pounds_per_square_inch_t minPressure, - wpi::units::pounds_per_square_inch_t maxPressure) { + wpi::units::pounds_per_square_inch<> minPressure, + wpi::units::pounds_per_square_inch<> maxPressure) { if (minPressure >= maxPressure) { throw WPILIB_MakeError(err::InvalidParameter, "maxPressure must be greater than minPressure"); @@ -156,8 +156,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. - wpi::units::volt_t minAnalogVoltage = PSIToVolts(minPressure, 5_V); - wpi::units::volt_t maxAnalogVoltage = PSIToVolts(maxPressure, 5_V); + wpi::units::volts<> minAnalogVoltage = PSIToVolts(minPressure, 5_V); + wpi::units::volts<> maxAnalogVoltage = PSIToVolts(maxPressure, 5_V); int32_t status = 0; HAL_SetREVPHClosedLoopControlAnalog(m_handle, minAnalogVoltage.value(), @@ -166,8 +166,8 @@ void PneumaticHub::EnableCompressorAnalog( } void PneumaticHub::EnableCompressorHybrid( - wpi::units::pounds_per_square_inch_t minPressure, - wpi::units::pounds_per_square_inch_t maxPressure) { + wpi::units::pounds_per_square_inch<> minPressure, + wpi::units::pounds_per_square_inch<> maxPressure) { if (minPressure >= maxPressure) { throw WPILIB_MakeError(err::InvalidParameter, "maxPressure must be greater than minPressure"); @@ -186,8 +186,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. - wpi::units::volt_t minAnalogVoltage = PSIToVolts(minPressure, 5_V); - wpi::units::volt_t maxAnalogVoltage = PSIToVolts(maxPressure, 5_V); + wpi::units::volts<> minAnalogVoltage = PSIToVolts(minPressure, 5_V); + wpi::units::volts<> maxAnalogVoltage = PSIToVolts(maxPressure, 5_V); int32_t status = 0; HAL_SetREVPHClosedLoopControlHybrid(m_handle, minAnalogVoltage.value(), @@ -209,11 +209,11 @@ bool PneumaticHub::GetPressureSwitch() const { return result; } -wpi::units::ampere_t PneumaticHub::GetCompressorCurrent() const { +wpi::units::amperes<> PneumaticHub::GetCompressorCurrent() const { int32_t status = 0; auto result = HAL_GetREVPHCompressorCurrent(m_handle, &status); WPILIB_ReportError(status, "Module {}", m_module); - return wpi::units::ampere_t{result}; + return wpi::units::amperes<>{result}; } void PneumaticHub::SetSolenoids(int mask, int values) { @@ -248,7 +248,7 @@ void PneumaticHub::FireOneShot(int index) { } void PneumaticHub::SetOneShotDuration(int index, - wpi::units::second_t duration) { + wpi::units::seconds<> duration) { m_dataStore->m_oneShotDurMs[index] = duration; } @@ -373,50 +373,50 @@ void PneumaticHub::ClearStickyFaults() { WPILIB_ReportError(status, "Module {}", m_module); } -wpi::units::volt_t PneumaticHub::GetInputVoltage() const { +wpi::units::volts<> PneumaticHub::GetInputVoltage() const { int32_t status = 0; auto voltage = HAL_GetREVPHVoltage(m_handle, &status); WPILIB_ReportError(status, "Module {}", m_module); - return wpi::units::volt_t{voltage}; + return wpi::units::volts<>{voltage}; } -wpi::units::volt_t PneumaticHub::Get5VRegulatedVoltage() const { +wpi::units::volts<> PneumaticHub::Get5VRegulatedVoltage() const { int32_t status = 0; auto voltage = HAL_GetREVPH5VVoltage(m_handle, &status); WPILIB_ReportError(status, "Module {}", m_module); - return wpi::units::volt_t{voltage}; + return wpi::units::volts<>{voltage}; } -wpi::units::ampere_t PneumaticHub::GetSolenoidsTotalCurrent() const { +wpi::units::amperes<> PneumaticHub::GetSolenoidsTotalCurrent() const { int32_t status = 0; auto current = HAL_GetREVPHSolenoidCurrent(m_handle, &status); WPILIB_ReportError(status, "Module {}", m_module); - return wpi::units::ampere_t{current}; + return wpi::units::amperes<>{current}; } -wpi::units::volt_t PneumaticHub::GetSolenoidsVoltage() const { +wpi::units::volts<> PneumaticHub::GetSolenoidsVoltage() const { int32_t status = 0; auto voltage = HAL_GetREVPHSolenoidVoltage(m_handle, &status); WPILIB_ReportError(status, "Module {}", m_module); - return wpi::units::volt_t{voltage}; + return wpi::units::volts<>{voltage}; } -wpi::units::volt_t PneumaticHub::GetAnalogVoltage(int channel) const { +wpi::units::volts<> PneumaticHub::GetAnalogVoltage(int channel) const { int32_t status = 0; auto voltage = HAL_GetREVPHAnalogVoltage(m_handle, channel, &status); WPILIB_ReportError(status, "Module {}", m_module); - return wpi::units::volt_t{voltage}; + return wpi::units::volts<>{voltage}; } -wpi::units::pounds_per_square_inch_t PneumaticHub::GetPressure( +wpi::units::pounds_per_square_inch<> PneumaticHub::GetPressure( int channel) const { int32_t status = 0; auto sensorVoltage = HAL_GetREVPHAnalogVoltage(m_handle, channel, &status); WPILIB_ReportError(status, "Module {}", m_module); auto supplyVoltage = HAL_GetREVPH5VVoltage(m_handle, &status); WPILIB_ReportError(status, "Module {}", m_module); - return VoltsToPSI(wpi::units::volt_t{sensorVoltage}, - wpi::units::volt_t{supplyVoltage}); + return VoltsToPSI(wpi::units::volts<>{sensorVoltage}, + wpi::units::volts<>{supplyVoltage}); } Solenoid PneumaticHub::MakeSolenoid(int channel) { diff --git a/wpilibc/src/main/native/cpp/hardware/pneumatic/PneumaticsControlModule.cpp b/wpilibc/src/main/native/cpp/hardware/pneumatic/PneumaticsControlModule.cpp index 421e134ce0c..d4beb2ee3a0 100644 --- a/wpilibc/src/main/native/cpp/hardware/pneumatic/PneumaticsControlModule.cpp +++ b/wpilibc/src/main/native/cpp/hardware/pneumatic/PneumaticsControlModule.cpp @@ -111,16 +111,16 @@ void PneumaticsControlModule::EnableCompressorDigital() { } void PneumaticsControlModule::EnableCompressorAnalog( - wpi::units::pounds_per_square_inch_t minPressure, - wpi::units::pounds_per_square_inch_t maxPressure) { + wpi::units::pounds_per_square_inch<> minPressure, + wpi::units::pounds_per_square_inch<> maxPressure) { int32_t status = 0; HAL_SetCTREPCMClosedLoopControl(m_handle, true, &status); WPILIB_ReportError(status, "Module {}", m_module); } void PneumaticsControlModule::EnableCompressorHybrid( - wpi::units::pounds_per_square_inch_t minPressure, - wpi::units::pounds_per_square_inch_t maxPressure) { + wpi::units::pounds_per_square_inch<> minPressure, + wpi::units::pounds_per_square_inch<> maxPressure) { int32_t status = 0; HAL_SetCTREPCMClosedLoopControl(m_handle, true, &status); WPILIB_ReportError(status, "Module {}", m_module); @@ -141,11 +141,11 @@ bool PneumaticsControlModule::GetPressureSwitch() const { return result; } -wpi::units::ampere_t PneumaticsControlModule::GetCompressorCurrent() const { +wpi::units::amperes<> PneumaticsControlModule::GetCompressorCurrent() const { int32_t status = 0; auto result = HAL_GetCTREPCMCompressorCurrent(m_handle, &status); WPILIB_ReportError(status, "Module {}", m_module); - return wpi::units::ampere_t{result}; + return wpi::units::amperes<>{result}; } bool PneumaticsControlModule::GetCompressorCurrentTooHighFault() const { @@ -237,9 +237,9 @@ void PneumaticsControlModule::FireOneShot(int index) { } void PneumaticsControlModule::SetOneShotDuration( - int index, wpi::units::second_t duration) { + int index, wpi::units::seconds<> duration) { int32_t status = 0; - wpi::units::millisecond_t millis = duration; + wpi::units::milliseconds<> millis = duration; HAL_SetCTREPCMOneShotDuration(m_handle, index, millis.to(), &status); WPILIB_ReportError(status, "Module {}", m_module); } @@ -277,12 +277,12 @@ void PneumaticsControlModule::UnreserveCompressor() { m_dataStore->m_compressorReserved = false; } -wpi::units::volt_t PneumaticsControlModule::GetAnalogVoltage( +wpi::units::volts<> PneumaticsControlModule::GetAnalogVoltage( int channel) const { return 0_V; } -wpi::units::pounds_per_square_inch_t PneumaticsControlModule::GetPressure( +wpi::units::pounds_per_square_inch<> PneumaticsControlModule::GetPressure( int channel) const { return 0_psi; } diff --git a/wpilibc/src/main/native/cpp/hardware/pneumatic/Solenoid.cpp b/wpilibc/src/main/native/cpp/hardware/pneumatic/Solenoid.cpp index 697463911e9..89fdab2f42c 100644 --- a/wpilibc/src/main/native/cpp/hardware/pneumatic/Solenoid.cpp +++ b/wpilibc/src/main/native/cpp/hardware/pneumatic/Solenoid.cpp @@ -61,7 +61,7 @@ bool Solenoid::IsDisabled() const { return (m_module->GetSolenoidDisabledList() & m_mask) != 0; } -void Solenoid::SetPulseDuration(wpi::units::second_t duration) { +void Solenoid::SetPulseDuration(wpi::units::seconds<> duration) { m_module->SetOneShotDuration(m_channel, duration); } diff --git a/wpilibc/src/main/native/cpp/hardware/range/SharpIR.cpp b/wpilibc/src/main/native/cpp/hardware/range/SharpIR.cpp index 94d922e4b95..a05a8461d7b 100644 --- a/wpilibc/src/main/native/cpp/hardware/range/SharpIR.cpp +++ b/wpilibc/src/main/native/cpp/hardware/range/SharpIR.cpp @@ -29,8 +29,8 @@ SharpIR SharpIR::GP2Y0A51SK0F(int channel) { return SharpIR(channel, 5.2819, -1.161, 2_cm, 15_cm); } -SharpIR::SharpIR(int channel, double a, double b, wpi::units::meter_t min, - wpi::units::meter_t max) +SharpIR::SharpIR(int channel, double a, double b, wpi::units::meters<> min, + wpi::units::meters<> max) : m_sensor(channel), m_A(a), m_B(b), m_min(min), m_max(max) { wpi::util::ReportUsage("IO", channel, "SharpIR"); @@ -46,15 +46,15 @@ int SharpIR::GetChannel() const { return m_sensor.GetChannel(); } -wpi::units::meter_t SharpIR::GetRange() const { +wpi::units::meters<> SharpIR::GetRange() const { if (m_simRange) { - return std::clamp(wpi::units::meter_t{m_simRange.Get()}, m_min, m_max); + return std::clamp(wpi::units::meters<>{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(wpi::units::meter_t{m_A * std::pow(v, m_B) * 1e-2}, m_min, - m_max); + return std::clamp(wpi::units::meters<>{m_A * std::pow(v, m_B) * 1e-2}, + m_min, m_max); } } diff --git a/wpilibc/src/main/native/cpp/hardware/rotation/DutyCycle.cpp b/wpilibc/src/main/native/cpp/hardware/rotation/DutyCycle.cpp index 0aa057f6446..d173ec1891a 100644 --- a/wpilibc/src/main/native/cpp/hardware/rotation/DutyCycle.cpp +++ b/wpilibc/src/main/native/cpp/hardware/rotation/DutyCycle.cpp @@ -27,11 +27,11 @@ void DutyCycle::InitDutyCycle() { wpi::util::ReportUsage("IO", m_channel, "DutyCycle"); } -wpi::units::hertz_t DutyCycle::GetFrequency() const { +wpi::units::hertz<> DutyCycle::GetFrequency() const { int32_t status = 0; auto retVal = HAL_GetDutyCycleFrequency(m_handle, &status); WPILIB_CheckErrorStatus(status, "Channel {}", GetSourceChannel()); - return wpi::units::hertz_t{retVal}; + return wpi::units::hertz<>{retVal}; } double DutyCycle::GetOutput() const { @@ -41,11 +41,11 @@ double DutyCycle::GetOutput() const { return retVal; } -wpi::units::second_t DutyCycle::GetHighTime() const { +wpi::units::seconds<> DutyCycle::GetHighTime() const { int32_t status = 0; auto retVal = HAL_GetDutyCycleHighTime(m_handle, &status); WPILIB_CheckErrorStatus(status, "Channel {}", GetSourceChannel()); - return wpi::units::nanosecond_t{static_cast(retVal)}; + return wpi::units::nanoseconds<>{static_cast(retVal)}; } int DutyCycle::GetSourceChannel() const { diff --git a/wpilibc/src/main/native/cpp/hardware/rotation/DutyCycleEncoder.cpp b/wpilibc/src/main/native/cpp/hardware/rotation/DutyCycleEncoder.cpp index 77d2e242666..83e84973492 100644 --- a/wpilibc/src/main/native/cpp/hardware/rotation/DutyCycleEncoder.cpp +++ b/wpilibc/src/main/native/cpp/hardware/rotation/DutyCycleEncoder.cpp @@ -118,7 +118,7 @@ void DutyCycleEncoder::SetDutyCycleRange(double min, double max) { m_sensorMax = std::clamp(max, 0.0, 1.0); } -wpi::units::hertz_t DutyCycleEncoder::GetFrequency() const { +wpi::units::hertz<> DutyCycleEncoder::GetFrequency() const { return m_dutyCycle->GetFrequency(); } @@ -130,7 +130,7 @@ bool DutyCycleEncoder::IsConnected() const { } void DutyCycleEncoder::SetConnectedFrequencyThreshold( - wpi::units::hertz_t frequency) { + wpi::units::hertz<> frequency) { if (frequency < 0_Hz) { frequency = 0_Hz; } @@ -141,7 +141,7 @@ void DutyCycleEncoder::SetInverted(bool inverted) { m_isInverted = inverted; } -void DutyCycleEncoder::SetAssumedFrequency(wpi::units::hertz_t frequency) { +void DutyCycleEncoder::SetAssumedFrequency(wpi::units::hertz<> frequency) { if (frequency.value() == 0) { m_period = 0_s; } else { diff --git a/wpilibc/src/main/native/cpp/hardware/rotation/Encoder.cpp b/wpilibc/src/main/native/cpp/hardware/rotation/Encoder.cpp index 969c7e6a874..3fd9e0d12a8 100644 --- a/wpilibc/src/main/native/cpp/hardware/rotation/Encoder.cpp +++ b/wpilibc/src/main/native/cpp/hardware/rotation/Encoder.cpp @@ -73,7 +73,7 @@ double Encoder::GetRate() const { return value; } -void Encoder::SetRateWindow(wpi::units::millisecond_t window) { +void Encoder::SetRateWindow(wpi::units::milliseconds<> window) { int32_t status = 0; HAL_SetEncoderRateWindow(m_encoder, static_cast(window.value()), &status); diff --git a/wpilibc/src/main/native/cpp/internal/PeriodicPriorityQueue.cpp b/wpilibc/src/main/native/cpp/internal/PeriodicPriorityQueue.cpp index 40a461fd378..8afd9e98614 100644 --- a/wpilibc/src/main/native/cpp/internal/PeriodicPriorityQueue.cpp +++ b/wpilibc/src/main/native/cpp/internal/PeriodicPriorityQueue.cpp @@ -36,8 +36,8 @@ PeriodicPriorityQueue::Callback::Callback(std::function func, PeriodicPriorityQueue::Callback::Callback(std::function func, std::chrono::nanoseconds startTime, - wpi::units::second_t period, - wpi::units::second_t offset) + wpi::units::seconds<> period, + wpi::units::seconds<> offset) : Callback{ std::move(func), startTime, std::chrono::nanoseconds{static_cast(period.value() * 1e9)}, @@ -46,8 +46,8 @@ PeriodicPriorityQueue::Callback::Callback(std::function func, PeriodicPriorityQueue::Callback::Callback(std::function func, std::chrono::nanoseconds startTime, - wpi::units::second_t period) - : Callback{std::move(func), startTime, period, wpi::units::second_t{0}} {} + wpi::units::seconds<> period) + : Callback{std::move(func), startTime, period, 0_s} {} void PeriodicPriorityQueue::Add(std::function func, std::chrono::nanoseconds startTime, @@ -64,14 +64,14 @@ void PeriodicPriorityQueue::Add(std::function func, void PeriodicPriorityQueue::Add(std::function func, std::chrono::nanoseconds startTime, - wpi::units::second_t period) { - Add(std::move(func), startTime, period, wpi::units::second_t{0}); + wpi::units::seconds<> period) { + Add(std::move(func), startTime, period, wpi::units::seconds<>{0}); } void PeriodicPriorityQueue::Add(std::function func, std::chrono::nanoseconds startTime, - wpi::units::second_t period, - wpi::units::second_t offset) { + wpi::units::seconds<> period, + wpi::units::seconds<> offset) { m_queue.emplace(std::move(func), startTime, period, offset); } @@ -106,7 +106,7 @@ bool PeriodicPriorityQueue::RunCallbacks(HAL_NotifierHandle notifier) { const std::chrono::nanoseconds currentTime{ RobotController::GetMonotonicTime()}; - m_loopStartTime = wpi::units::nanosecond_t{currentTime}; + m_loopStartTime = wpi::units::nanoseconds<>{currentTime}; callback.func(); diff --git a/wpilibc/src/main/native/cpp/opmode/PeriodicOpMode.cpp b/wpilibc/src/main/native/cpp/opmode/PeriodicOpMode.cpp index 88e04c7657c..b17a2b03b8b 100644 --- a/wpilibc/src/main/native/cpp/opmode/PeriodicOpMode.cpp +++ b/wpilibc/src/main/native/cpp/opmode/PeriodicOpMode.cpp @@ -18,8 +18,8 @@ PeriodicOpMode::PeriodicOpMode() } void PeriodicOpMode::AddPeriodic(std::function callback, - wpi::units::second_t period, - wpi::units::second_t offset) { + wpi::units::seconds<> period, + wpi::units::seconds<> offset) { m_callbacks.emplace_back( std::move(callback), m_startTime, std::chrono::nanoseconds{static_cast(period.value() * 1e9)}, diff --git a/wpilibc/src/main/native/cpp/simulation/DCMotorSim.cpp b/wpilibc/src/main/native/cpp/simulation/DCMotorSim.cpp index 3485487e6b9..cb159fffb1a 100644 --- a/wpilibc/src/main/native/cpp/simulation/DCMotorSim.cpp +++ b/wpilibc/src/main/native/cpp/simulation/DCMotorSim.cpp @@ -36,53 +36,53 @@ DCMotorSim::DCMotorSim(const wpi::math::LinearSystem<2, 1, 2>& plant, m_j(m_gearing * gearbox.Kt.value() / (gearbox.R.value() * m_plant.B(1, 0))) {} -void DCMotorSim::SetState(wpi::units::radian_t angularPosition, - wpi::units::radians_per_second_t angularVelocity) { +void DCMotorSim::SetState(wpi::units::radians<> angularPosition, + wpi::units::radians_per_second<> angularVelocity) { SetState(wpi::math::Vectord<2>{angularPosition, angularVelocity}); } -void DCMotorSim::SetAngle(wpi::units::radian_t angularPosition) { +void DCMotorSim::SetAngle(wpi::units::radians<> angularPosition) { SetState(angularPosition, GetAngularVelocity()); } void DCMotorSim::SetAngularVelocity( - wpi::units::radians_per_second_t angularVelocity) { + wpi::units::radians_per_second<> angularVelocity) { SetState(GetAngularPosition(), angularVelocity); } -wpi::units::radian_t DCMotorSim::GetAngularPosition() const { - return wpi::units::radian_t{GetOutput(0)}; +wpi::units::radians<> DCMotorSim::GetAngularPosition() const { + return wpi::units::radians<>{GetOutput(0)}; } -wpi::units::radians_per_second_t DCMotorSim::GetAngularVelocity() const { - return wpi::units::radians_per_second_t{GetOutput(1)}; +wpi::units::radians_per_second<> DCMotorSim::GetAngularVelocity() const { + return wpi::units::radians_per_second<>{GetOutput(1)}; } -wpi::units::radians_per_second_squared_t DCMotorSim::GetAngularAcceleration() +wpi::units::radians_per_second_squared<> DCMotorSim::GetAngularAcceleration() const { - return wpi::units::radians_per_second_squared_t{ + return wpi::units::radians_per_second_squared<>{ (m_plant.A() * m_x + m_plant.B() * m_u)(1, 0)}; } -wpi::units::newton_meter_t DCMotorSim::GetTorque() const { - return wpi::units::newton_meter_t{GetAngularAcceleration().value() * - m_j.value()}; +wpi::units::newton_meters<> DCMotorSim::GetTorque() const { + return wpi::units::newton_meters<>{GetAngularAcceleration().value() * + m_j.value()}; } -wpi::units::ampere_t DCMotorSim::GetCurrentDraw() const { +wpi::units::amperes<> 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(wpi::units::radians_per_second_t{m_x(1)} * m_gearing, - wpi::units::volt_t{m_u(0)}) * + return m_gearbox.Current(wpi::units::radians_per_second<>{m_x(1)} * m_gearing, + wpi::units::volts<>{m_u(0)}) * wpi::util::sgn(m_u(0)); } -wpi::units::volt_t DCMotorSim::GetInputVoltage() const { - return wpi::units::volt_t{GetInput(0)}; +wpi::units::volts<> DCMotorSim::GetInputVoltage() const { + return wpi::units::volts<>{GetInput(0)}; } -void DCMotorSim::SetInputVoltage(wpi::units::volt_t voltage) { +void DCMotorSim::SetInputVoltage(wpi::units::volts<> voltage) { SetInput(wpi::math::Vectord<1>{voltage.value()}); ClampInput(wpi::RobotController::GetBatteryVoltage().value()); } @@ -95,6 +95,6 @@ double DCMotorSim::GetGearing() const { return m_gearing; } -wpi::units::kilogram_square_meter_t DCMotorSim::GetJ() const { +wpi::units::kilogram_square_meters<> DCMotorSim::GetJ() const { return m_j; } diff --git a/wpilibc/src/main/native/cpp/simulation/DifferentialDrivetrainSim.cpp b/wpilibc/src/main/native/cpp/simulation/DifferentialDrivetrainSim.cpp index 81abcb845b3..f4ea91272fb 100644 --- a/wpilibc/src/main/native/cpp/simulation/DifferentialDrivetrainSim.cpp +++ b/wpilibc/src/main/native/cpp/simulation/DifferentialDrivetrainSim.cpp @@ -17,9 +17,9 @@ using namespace wpi; using namespace wpi::sim; DifferentialDrivetrainSim::DifferentialDrivetrainSim( - wpi::math::LinearSystem<2, 2, 2> plant, wpi::units::meter_t trackwidth, + wpi::math::LinearSystem<2, 2, 2> plant, wpi::units::meters<> trackwidth, wpi::math::DCMotor driveMotor, double gearRatio, - wpi::units::meter_t wheelRadius, + wpi::units::meters<> wheelRadius, const std::array& measurementStdDevs) : m_plant(std::move(plant)), m_rb(trackwidth / 2.0), @@ -35,8 +35,8 @@ DifferentialDrivetrainSim::DifferentialDrivetrainSim( DifferentialDrivetrainSim::DifferentialDrivetrainSim( 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, + wpi::units::kilogram_square_meters<> J, wpi::units::kilograms<> mass, + wpi::units::meters<> wheelRadius, wpi::units::meters<> trackwidth, const std::array& measurementStdDevs) : DifferentialDrivetrainSim( wpi::math::Models::DifferentialDriveFromPhysicalConstants( @@ -49,8 +49,8 @@ Eigen::Vector2d DifferentialDrivetrainSim::ClampInput( u, wpi::RobotController::GetInputVoltage()); } -void DifferentialDrivetrainSim::SetInputs(wpi::units::volt_t leftVoltage, - wpi::units::volt_t rightVoltage) { +void DifferentialDrivetrainSim::SetInputs(wpi::units::volts<> leftVoltage, + wpi::units::volts<> rightVoltage) { m_u << leftVoltage.value(), rightVoltage.value(); m_u = ClampInput(m_u); } @@ -59,7 +59,7 @@ void DifferentialDrivetrainSim::SetGearing(double newGearing) { m_currentGearing = newGearing; } -void DifferentialDrivetrainSim::Update(wpi::units::second_t dt) { +void DifferentialDrivetrainSim::Update(wpi::units::seconds<> 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::Normal<7>(m_measurementStdDevs); @@ -86,34 +86,34 @@ double DifferentialDrivetrainSim::GetState(int state) const { } wpi::math::Rotation2d DifferentialDrivetrainSim::GetHeading() const { - return wpi::units::radian_t{GetOutput(State::HEADING)}; + return wpi::units::radians<>{GetOutput(State::HEADING)}; } wpi::math::Pose2d DifferentialDrivetrainSim::GetPose() const { - return wpi::math::Pose2d{wpi::units::meter_t{GetOutput(State::X)}, - wpi::units::meter_t{GetOutput(State::Y)}, + return wpi::math::Pose2d{wpi::units::meters<>{GetOutput(State::X)}, + wpi::units::meters<>{GetOutput(State::Y)}, GetHeading()}; } -wpi::units::ampere_t DifferentialDrivetrainSim::GetLeftCurrentDraw() const { +wpi::units::amperes<> DifferentialDrivetrainSim::GetLeftCurrentDraw() const { return m_motor.Current( - wpi::units::radians_per_second_t{m_x(State::LEFT_VELOCITY) * + wpi::units::radians_per_second<>{m_x(State::LEFT_VELOCITY) * m_currentGearing / m_wheelRadius.value()}, - wpi::units::volt_t{m_u(0)}) * + wpi::units::volts<>{m_u(0)}) * wpi::util::sgn(m_u(0)); } -wpi::units::ampere_t DifferentialDrivetrainSim::GetRightCurrentDraw() const { +wpi::units::amperes<> DifferentialDrivetrainSim::GetRightCurrentDraw() const { return m_motor.Current( - wpi::units::radians_per_second_t{m_x(State::RIGHT_VELOCITY) * + wpi::units::radians_per_second<>{m_x(State::RIGHT_VELOCITY) * m_currentGearing / m_wheelRadius.value()}, - wpi::units::volt_t{m_u(1)}) * + wpi::units::volts<>{m_u(1)}) * wpi::util::sgn(m_u(1)); } -wpi::units::ampere_t DifferentialDrivetrainSim::GetCurrentDraw() const { +wpi::units::amperes<> DifferentialDrivetrainSim::GetCurrentDraw() const { return GetLeftCurrentDraw() + GetRightCurrentDraw(); } diff --git a/wpilibc/src/main/native/cpp/simulation/DutyCycleSim.cpp b/wpilibc/src/main/native/cpp/simulation/DutyCycleSim.cpp index a98f1a378e7..9380c5f3841 100644 --- a/wpilibc/src/main/native/cpp/simulation/DutyCycleSim.cpp +++ b/wpilibc/src/main/native/cpp/simulation/DutyCycleSim.cpp @@ -46,11 +46,11 @@ std::unique_ptr DutyCycleSim::RegisterFrequencyCallback( return store; } -wpi::units::hertz_t DutyCycleSim::GetFrequency() const { - return wpi::units::hertz_t{HALSIM_GetDutyCycleFrequency(m_index)}; +wpi::units::hertz<> DutyCycleSim::GetFrequency() const { + return wpi::units::hertz<>{HALSIM_GetDutyCycleFrequency(m_index)}; } -void DutyCycleSim::SetFrequency(wpi::units::hertz_t frequency) { +void DutyCycleSim::SetFrequency(wpi::units::hertz<> frequency) { HALSIM_SetDutyCycleFrequency(m_index, frequency.value()); } diff --git a/wpilibc/src/main/native/cpp/simulation/ElevatorSim.cpp b/wpilibc/src/main/native/cpp/simulation/ElevatorSim.cpp index 27e2de00191..7cf5449e244 100644 --- a/wpilibc/src/main/native/cpp/simulation/ElevatorSim.cpp +++ b/wpilibc/src/main/native/cpp/simulation/ElevatorSim.cpp @@ -14,9 +14,9 @@ using namespace wpi::sim; 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, + wpi::units::meters<> minHeight, + wpi::units::meters<> maxHeight, bool simulateGravity, + wpi::units::meters<> startingHeight, const std::array& measurementStdDevs) : LinearSystemSim(plant, measurementStdDevs), m_gearbox(gearbox), @@ -27,11 +27,11 @@ ElevatorSim::ElevatorSim(const wpi::math::LinearSystem<2, 1, 2>& plant, } 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, + wpi::units::kilograms<> carriageMass, + wpi::units::meters<> drumRadius, + wpi::units::meters<> minHeight, + wpi::units::meters<> maxHeight, bool simulateGravity, + wpi::units::meters<> startingHeight, const std::array& measurementStdDevs) : ElevatorSim(wpi::math::Models::ElevatorFromPhysicalConstants( gearbox, carriageMass, drumRadius, gearing), @@ -39,74 +39,76 @@ ElevatorSim::ElevatorSim(const wpi::math::DCMotor& gearbox, double gearing, startingHeight, measurementStdDevs) {} template - requires std::same_as || - std::same_as + requires std::same_as || + std::same_as ElevatorSim::ElevatorSim(decltype(1_V / Velocity_t(1)) kV, decltype(1_V / Acceleration_t(1)) kA, const wpi::math::DCMotor& gearbox, - wpi::units::meter_t minHeight, - wpi::units::meter_t maxHeight, bool simulateGravity, - wpi::units::meter_t startingHeight, + wpi::units::meters<> minHeight, + wpi::units::meters<> maxHeight, bool simulateGravity, + wpi::units::meters<> startingHeight, const std::array& measurementStdDevs) : ElevatorSim(wpi::math::Models::ElevatorFromSysId(kV, kA), gearbox, minHeight, maxHeight, simulateGravity, startingHeight, measurementStdDevs) {} -void ElevatorSim::SetState(wpi::units::meter_t position, - wpi::units::meters_per_second_t velocity) { +void ElevatorSim::SetState(wpi::units::meters<> position, + wpi::units::meters_per_second<> velocity) { SetState(wpi::math::Vectord<2>{std::clamp(position, m_minHeight, m_maxHeight), velocity}); } -bool ElevatorSim::WouldHitLowerLimit(wpi::units::meter_t elevatorHeight) const { +bool ElevatorSim::WouldHitLowerLimit( + wpi::units::meters<> elevatorHeight) const { return elevatorHeight <= m_minHeight; } -bool ElevatorSim::WouldHitUpperLimit(wpi::units::meter_t elevatorHeight) const { +bool ElevatorSim::WouldHitUpperLimit( + wpi::units::meters<> elevatorHeight) const { return elevatorHeight >= m_maxHeight; } bool ElevatorSim::HasHitLowerLimit() const { - return WouldHitLowerLimit(wpi::units::meter_t{m_y(0)}); + return WouldHitLowerLimit(wpi::units::meters<>{m_y(0)}); } bool ElevatorSim::HasHitUpperLimit() const { - return WouldHitUpperLimit(wpi::units::meter_t{m_y(0)}); + return WouldHitUpperLimit(wpi::units::meters<>{m_y(0)}); } -wpi::units::meter_t ElevatorSim::GetPosition() const { - return wpi::units::meter_t{m_y(0)}; +wpi::units::meters<> ElevatorSim::GetPosition() const { + return wpi::units::meters<>{m_y(0)}; } -wpi::units::meters_per_second_t ElevatorSim::GetVelocity() const { - return wpi::units::meters_per_second_t{m_x(1)}; +wpi::units::meters_per_second<> ElevatorSim::GetVelocity() const { + return wpi::units::meters_per_second<>{m_x(1)}; } -wpi::units::ampere_t ElevatorSim::GetCurrentDraw() const { +wpi::units::amperes<> 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 = wpi::units::unit_t>>; + using Kv_t = wpi::units::unit>>; Kv_t Kv = Kv_t{-kA * m_plant.A(1, 1)}; - wpi::units::meters_per_second_t velocity{m_x(1)}; - wpi::units::radians_per_second_t motorVelocity = velocity * Kv * m_gearbox.Kv; + wpi::units::meters_per_second<> velocity{m_x(1)}; + wpi::units::radians_per_second<> motorVelocity = velocity * Kv * m_gearbox.Kv; // Perform calculation and return. - return m_gearbox.Current(motorVelocity, wpi::units::volt_t{m_u(0)}) * + return m_gearbox.Current(motorVelocity, wpi::units::volts<>{m_u(0)}) * wpi::util::sgn(m_u(0)); } -void ElevatorSim::SetInputVoltage(wpi::units::volt_t voltage) { +void ElevatorSim::SetInputVoltage(wpi::units::volts<> voltage) { SetInput(wpi::math::Vectord<1>{voltage.value()}); ClampInput(wpi::RobotController::GetBatteryVoltage().value()); } wpi::math::Vectord<2> ElevatorSim::UpdateX( const wpi::math::Vectord<2>& currentXhat, const wpi::math::Vectord<1>& u, - wpi::units::second_t dt) { + wpi::units::seconds<> dt) { auto updatedXhat = wpi::math::RKDP( [&](const wpi::math::Vectord<2>& x, const wpi::math::Vectord<1>& u_) -> wpi::math::Vectord<2> { @@ -119,10 +121,10 @@ wpi::math::Vectord<2> ElevatorSim::UpdateX( }, currentXhat, u, dt); // Check for collision after updating x-hat. - if (WouldHitLowerLimit(wpi::units::meter_t{updatedXhat(0)})) { + if (WouldHitLowerLimit(wpi::units::meters<>{updatedXhat(0)})) { return wpi::math::Vectord<2>{m_minHeight.value(), 0.0}; } - if (WouldHitUpperLimit(wpi::units::meter_t{updatedXhat(0)})) { + if (WouldHitUpperLimit(wpi::units::meters<>{updatedXhat(0)})) { return wpi::math::Vectord<2>{m_maxHeight.value(), 0.0}; } return updatedXhat; diff --git a/wpilibc/src/main/native/cpp/simulation/FlywheelSim.cpp b/wpilibc/src/main/native/cpp/simulation/FlywheelSim.cpp index 25f893a5c5b..403d4d8a25f 100644 --- a/wpilibc/src/main/native/cpp/simulation/FlywheelSim.cpp +++ b/wpilibc/src/main/native/cpp/simulation/FlywheelSim.cpp @@ -36,39 +36,39 @@ FlywheelSim::FlywheelSim(const wpi::math::LinearSystem<1, 1, 1>& plant, m_j(m_gearing * gearbox.Kt.value() / (gearbox.R.value() * m_plant.B(0, 0))) {} -void FlywheelSim::SetVelocity(wpi::units::radians_per_second_t velocity) { +void FlywheelSim::SetVelocity(wpi::units::radians_per_second<> velocity) { LinearSystemSim::SetState(wpi::math::Vectord<1>{velocity.value()}); } -wpi::units::radians_per_second_t FlywheelSim::GetAngularVelocity() const { - return wpi::units::radians_per_second_t{GetOutput(0)}; +wpi::units::radians_per_second<> FlywheelSim::GetAngularVelocity() const { + return wpi::units::radians_per_second<>{GetOutput(0)}; } -wpi::units::radians_per_second_squared_t FlywheelSim::GetAngularAcceleration() +wpi::units::radians_per_second_squared<> FlywheelSim::GetAngularAcceleration() const { - return wpi::units::radians_per_second_squared_t{ + return wpi::units::radians_per_second_squared<>{ (m_plant.A() * m_x + m_plant.B() * m_u)(0, 0)}; } -wpi::units::newton_meter_t FlywheelSim::GetTorque() const { - return wpi::units::newton_meter_t{GetAngularAcceleration().value() * - m_j.value()}; +wpi::units::newton_meters<> FlywheelSim::GetTorque() const { + return wpi::units::newton_meters<>{GetAngularAcceleration().value() * + m_j.value()}; } -wpi::units::ampere_t FlywheelSim::GetCurrentDraw() const { +wpi::units::amperes<> 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(wpi::units::radians_per_second_t{m_x(0)} * m_gearing, - wpi::units::volt_t{m_u(0)}) * + return m_gearbox.Current(wpi::units::radians_per_second<>{m_x(0)} * m_gearing, + wpi::units::volts<>{m_u(0)}) * wpi::util::sgn(m_u(0)); } -wpi::units::volt_t FlywheelSim::GetInputVoltage() const { - return wpi::units::volt_t{GetInput(0)}; +wpi::units::volts<> FlywheelSim::GetInputVoltage() const { + return wpi::units::volts<>{GetInput(0)}; } -void FlywheelSim::SetInputVoltage(wpi::units::volt_t voltage) { +void FlywheelSim::SetInputVoltage(wpi::units::volts<> voltage) { SetInput(wpi::math::Vectord<1>{voltage.value()}); ClampInput(wpi::RobotController::GetBatteryVoltage().value()); } diff --git a/wpilibc/src/main/native/cpp/simulation/OnboardIMUSim.cpp b/wpilibc/src/main/native/cpp/simulation/OnboardIMUSim.cpp index 1076353a399..05b4bc7fe34 100644 --- a/wpilibc/src/main/native/cpp/simulation/OnboardIMUSim.cpp +++ b/wpilibc/src/main/native/cpp/simulation/OnboardIMUSim.cpp @@ -8,41 +8,41 @@ namespace wpi::sim { -void OnboardIMUSim::SetAngleX(wpi::units::radian_t angle) { +void OnboardIMUSim::SetAngleX(wpi::units::radians<> angle) { HALSIM_SetIMUAngleX(angle.to()); } -void OnboardIMUSim::SetAngleY(wpi::units::radian_t angle) { +void OnboardIMUSim::SetAngleY(wpi::units::radians<> angle) { HALSIM_SetIMUAngleY(angle.to()); } -void OnboardIMUSim::SetAngleZ(wpi::units::radian_t angle) { +void OnboardIMUSim::SetAngleZ(wpi::units::radians<> angle) { HALSIM_SetIMUAngleZ(angle.to()); } -void OnboardIMUSim::SetGyroRateX(wpi::units::radians_per_second_t rate) { +void OnboardIMUSim::SetGyroRateX(wpi::units::radians_per_second<> rate) { HALSIM_SetIMUGyroRateX(rate.to()); } -void OnboardIMUSim::SetGyroRateY(wpi::units::radians_per_second_t rate) { +void OnboardIMUSim::SetGyroRateY(wpi::units::radians_per_second<> rate) { HALSIM_SetIMUGyroRateY(rate.to()); } -void OnboardIMUSim::SetGyroRateZ(wpi::units::radians_per_second_t rate) { +void OnboardIMUSim::SetGyroRateZ(wpi::units::radians_per_second<> rate) { HALSIM_SetIMUGyroRateZ(rate.to()); } -void OnboardIMUSim::SetAccelX(wpi::units::meters_per_second_squared_t accel) { +void OnboardIMUSim::SetAccelX(wpi::units::meters_per_second_squared<> accel) { HALSIM_SetIMUAccelX(accel.to()); } -void OnboardIMUSim::SetAccelY(wpi::units::meters_per_second_squared_t accel) { +void OnboardIMUSim::SetAccelY(wpi::units::meters_per_second_squared<> accel) { HALSIM_SetIMUAccelY(accel.to()); } -void OnboardIMUSim::SetAccelZ(wpi::units::meters_per_second_squared_t accel) { +void OnboardIMUSim::SetAccelZ(wpi::units::meters_per_second_squared<> accel) { HALSIM_SetIMUAccelZ(accel.to()); } -void OnboardIMUSim::SetYaw(wpi::units::radian_t angle) { +void OnboardIMUSim::SetYaw(wpi::units::radians<> angle) { HALSIM_SetIMUYaw(angle.to()); } diff --git a/wpilibc/src/main/native/cpp/simulation/RoboRioSim.cpp b/wpilibc/src/main/native/cpp/simulation/RoboRioSim.cpp index 0e774699ee2..451b9397616 100644 --- a/wpilibc/src/main/native/cpp/simulation/RoboRioSim.cpp +++ b/wpilibc/src/main/native/cpp/simulation/RoboRioSim.cpp @@ -22,11 +22,11 @@ std::unique_ptr RoboRioSim::RegisterVInVoltageCallback( return store; } -wpi::units::volt_t RoboRioSim::GetVInVoltage() { - return wpi::units::volt_t{HALSIM_GetRoboRioVInVoltage()}; +wpi::units::volts<> RoboRioSim::GetVInVoltage() { + return wpi::units::volts<>{HALSIM_GetRoboRioVInVoltage()}; } -void RoboRioSim::SetVInVoltage(wpi::units::volt_t vInVoltage) { +void RoboRioSim::SetVInVoltage(wpi::units::volts<> vInVoltage) { HALSIM_SetRoboRioVInVoltage(vInVoltage.value()); } @@ -39,11 +39,11 @@ std::unique_ptr RoboRioSim::RegisterUserVoltage3V3Callback( return store; } -wpi::units::volt_t RoboRioSim::GetUserVoltage3V3() { - return wpi::units::volt_t{HALSIM_GetRoboRioUserVoltage3V3()}; +wpi::units::volts<> RoboRioSim::GetUserVoltage3V3() { + return wpi::units::volts<>{HALSIM_GetRoboRioUserVoltage3V3()}; } -void RoboRioSim::SetUserVoltage3V3(wpi::units::volt_t userVoltage3V3) { +void RoboRioSim::SetUserVoltage3V3(wpi::units::volts<> userVoltage3V3) { HALSIM_SetRoboRioUserVoltage3V3(userVoltage3V3.value()); } @@ -56,11 +56,11 @@ std::unique_ptr RoboRioSim::RegisterUserCurrent3V3Callback( return store; } -wpi::units::ampere_t RoboRioSim::GetUserCurrent3V3() { - return wpi::units::ampere_t{HALSIM_GetRoboRioUserCurrent3V3()}; +wpi::units::amperes<> RoboRioSim::GetUserCurrent3V3() { + return wpi::units::amperes<>{HALSIM_GetRoboRioUserCurrent3V3()}; } -void RoboRioSim::SetUserCurrent3V3(wpi::units::ampere_t userCurrent3V3) { +void RoboRioSim::SetUserCurrent3V3(wpi::units::amperes<> userCurrent3V3) { HALSIM_SetRoboRioUserCurrent3V3(userCurrent3V3.value()); } @@ -107,11 +107,11 @@ std::unique_ptr RoboRioSim::RegisterBrownoutVoltageCallback( return store; } -wpi::units::volt_t RoboRioSim::GetBrownoutVoltage() { - return wpi::units::volt_t{HALSIM_GetRoboRioBrownoutVoltage()}; +wpi::units::volts<> RoboRioSim::GetBrownoutVoltage() { + return wpi::units::volts<>{HALSIM_GetRoboRioBrownoutVoltage()}; } -void RoboRioSim::SetBrownoutVoltage(wpi::units::volt_t vInVoltage) { +void RoboRioSim::SetBrownoutVoltage(wpi::units::volts<> vInVoltage) { HALSIM_SetRoboRioBrownoutVoltage(vInVoltage.value()); } @@ -125,12 +125,12 @@ RoboRioSim::RegisterBrownoutRecoveryVoltageCallback(NotifyCallback callback, return store; } -wpi::units::volt_t RoboRioSim::GetBrownoutRecoveryVoltage() { - return wpi::units::volt_t{HALSIM_GetRoboRioBrownoutRecoveryVoltage()}; +wpi::units::volts<> RoboRioSim::GetBrownoutRecoveryVoltage() { + return wpi::units::volts<>{HALSIM_GetRoboRioBrownoutRecoveryVoltage()}; } void RoboRioSim::SetBrownoutRecoveryVoltage( - wpi::units::volt_t brownoutRecoveryVoltage) { + wpi::units::volts<> brownoutRecoveryVoltage) { HALSIM_SetRoboRioBrownoutRecoveryVoltage(brownoutRecoveryVoltage.value()); } @@ -143,11 +143,11 @@ std::unique_ptr RoboRioSim::RegisterCPUTempCallback( return store; } -wpi::units::celsius_t RoboRioSim::GetCPUTemp() { - return wpi::units::celsius_t{HALSIM_GetRoboRioCPUTemp()}; +wpi::units::celsius<> RoboRioSim::GetCPUTemp() { + return wpi::units::celsius<>{HALSIM_GetRoboRioCPUTemp()}; } -void RoboRioSim::SetCPUTemp(wpi::units::celsius_t cpuTemp) { +void RoboRioSim::SetCPUTemp(wpi::units::celsius<> cpuTemp) { HALSIM_SetRoboRioCPUTemp(cpuTemp.value()); } diff --git a/wpilibc/src/main/native/cpp/simulation/SharpIRSim.cpp b/wpilibc/src/main/native/cpp/simulation/SharpIRSim.cpp index 963149dadf8..6aec0d4a9b0 100644 --- a/wpilibc/src/main/native/cpp/simulation/SharpIRSim.cpp +++ b/wpilibc/src/main/native/cpp/simulation/SharpIRSim.cpp @@ -18,6 +18,6 @@ SharpIRSim::SharpIRSim(int channel) { m_simRange = deviceSim.GetDouble("Range (m)"); } -void SharpIRSim::SetRange(wpi::units::meter_t range) { +void SharpIRSim::SetRange(wpi::units::meters<> range) { m_simRange.Set(range.value()); } diff --git a/wpilibc/src/main/native/cpp/simulation/SimHooks.cpp b/wpilibc/src/main/native/cpp/simulation/SimHooks.cpp index f1aa6c5bde8..cd8e419faff 100644 --- a/wpilibc/src/main/native/cpp/simulation/SimHooks.cpp +++ b/wpilibc/src/main/native/cpp/simulation/SimHooks.cpp @@ -48,11 +48,11 @@ bool IsTimingPaused() { return HALSIM_IsTimingPaused(); } -void StepTiming(wpi::units::second_t delta) { +void StepTiming(wpi::units::seconds<> delta) { HALSIM_StepTiming(static_cast(delta.value() * 1e9)); } -void StepTimingAsync(wpi::units::second_t delta) { +void StepTimingAsync(wpi::units::seconds<> delta) { HALSIM_StepTimingAsync(static_cast(delta.value() * 1e9)); } diff --git a/wpilibc/src/main/native/cpp/simulation/SingleJointedArmSim.cpp b/wpilibc/src/main/native/cpp/simulation/SingleJointedArmSim.cpp index 77080037460..64347afe60d 100644 --- a/wpilibc/src/main/native/cpp/simulation/SingleJointedArmSim.cpp +++ b/wpilibc/src/main/native/cpp/simulation/SingleJointedArmSim.cpp @@ -18,9 +18,9 @@ using namespace wpi::sim; SingleJointedArmSim::SingleJointedArmSim( 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, + wpi::units::meters<> armLength, wpi::units::radians<> minAngle, + wpi::units::radians<> maxAngle, bool simulateGravity, + wpi::units::radians<> startingAngle, const std::array& measurementStdDevs) : LinearSystemSim<2, 1, 2>(system, measurementStdDevs), m_armLen(armLength), @@ -34,9 +34,9 @@ SingleJointedArmSim::SingleJointedArmSim( SingleJointedArmSim::SingleJointedArmSim( 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, + wpi::units::kilogram_square_meters<> moi, wpi::units::meters<> armLength, + wpi::units::radians<> minAngle, wpi::units::radians<> maxAngle, + bool simulateGravity, wpi::units::radians<> startingAngle, const std::array& measurementStdDevs) : SingleJointedArmSim( wpi::math::Models::SingleJointedArmFromPhysicalConstants(gearbox, moi, @@ -44,54 +44,54 @@ SingleJointedArmSim::SingleJointedArmSim( gearbox, gearing, armLength, minAngle, maxAngle, simulateGravity, startingAngle, measurementStdDevs) {} -void SingleJointedArmSim::SetState(wpi::units::radian_t angle, - wpi::units::radians_per_second_t velocity) { +void SingleJointedArmSim::SetState(wpi::units::radians<> angle, + wpi::units::radians_per_second<> velocity) { SetState(wpi::math::Vectord<2>{std::clamp(angle, m_minAngle, m_maxAngle), velocity}); } bool SingleJointedArmSim::WouldHitLowerLimit( - wpi::units::radian_t armAngle) const { + wpi::units::radians<> armAngle) const { return armAngle <= m_minAngle; } bool SingleJointedArmSim::WouldHitUpperLimit( - wpi::units::radian_t armAngle) const { + wpi::units::radians<> armAngle) const { return armAngle >= m_maxAngle; } bool SingleJointedArmSim::HasHitLowerLimit() const { - return WouldHitLowerLimit(wpi::units::radian_t{m_y(0)}); + return WouldHitLowerLimit(wpi::units::radians<>{m_y(0)}); } bool SingleJointedArmSim::HasHitUpperLimit() const { - return WouldHitUpperLimit(wpi::units::radian_t{m_y(0)}); + return WouldHitUpperLimit(wpi::units::radians<>{m_y(0)}); } -wpi::units::radian_t SingleJointedArmSim::GetAngle() const { - return wpi::units::radian_t{m_y(0)}; +wpi::units::radians<> SingleJointedArmSim::GetAngle() const { + return wpi::units::radians<>{m_y(0)}; } -wpi::units::radians_per_second_t SingleJointedArmSim::GetVelocity() const { - return wpi::units::radians_per_second_t{m_x(1)}; +wpi::units::radians_per_second<> SingleJointedArmSim::GetVelocity() const { + return wpi::units::radians_per_second<>{m_x(1)}; } -wpi::units::ampere_t SingleJointedArmSim::GetCurrentDraw() const { +wpi::units::amperes<> 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 - 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::units::radians_per_second<> motorVelocity{m_x(1) * m_gearing}; + return m_gearbox.Current(motorVelocity, wpi::units::volts<>{m_u(0)}) * wpi::util::sgn(m_u(0)); } -void SingleJointedArmSim::SetInputVoltage(wpi::units::volt_t voltage) { +void SingleJointedArmSim::SetInputVoltage(wpi::units::volts<> voltage) { SetInput(wpi::math::Vectord<1>{voltage.value()}); ClampInput(wpi::RobotController::GetBatteryVoltage().value()); } wpi::math::Vectord<2> SingleJointedArmSim::UpdateX( const wpi::math::Vectord<2>& currentXhat, const wpi::math::Vectord<1>& u, - wpi::units::second_t dt) { + wpi::units::seconds<> 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 @@ -129,9 +129,9 @@ wpi::math::Vectord<2> SingleJointedArmSim::UpdateX( currentXhat, u, dt); // Check for collisions. - if (WouldHitLowerLimit(wpi::units::radian_t{updatedXhat(0)})) { + if (WouldHitLowerLimit(wpi::units::radians<>{updatedXhat(0)})) { return wpi::math::Vectord<2>{m_minAngle.value(), 0.0}; - } else if (WouldHitUpperLimit(wpi::units::radian_t{updatedXhat(0)})) { + } else if (WouldHitUpperLimit(wpi::units::radians<>{updatedXhat(0)})) { return wpi::math::Vectord<2>{m_maxAngle.value(), 0.0}; } return updatedXhat; diff --git a/wpilibc/src/main/native/cpp/smartdashboard/Field2d.cpp b/wpilibc/src/main/native/cpp/smartdashboard/Field2d.cpp index d2b3ef5ec9c..372292cd62f 100644 --- a/wpilibc/src/main/native/cpp/smartdashboard/Field2d.cpp +++ b/wpilibc/src/main/native/cpp/smartdashboard/Field2d.cpp @@ -52,7 +52,7 @@ void Field2d::SetRobotPose(const wpi::math::Pose2d& pose) { GetRobotObject()->SetPose(pose); } -void Field2d::SetRobotPose(wpi::units::meter_t x, wpi::units::meter_t y, +void Field2d::SetRobotPose(wpi::units::meters<> x, wpi::units::meters<> y, wpi::math::Rotation2d rotation) { GetRobotObject()->SetPose(x, y, rotation); } diff --git a/wpilibc/src/main/native/cpp/smartdashboard/FieldObject2d.cpp b/wpilibc/src/main/native/cpp/smartdashboard/FieldObject2d.cpp index d116126cb0c..72baa498d9f 100644 --- a/wpilibc/src/main/native/cpp/smartdashboard/FieldObject2d.cpp +++ b/wpilibc/src/main/native/cpp/smartdashboard/FieldObject2d.cpp @@ -30,7 +30,7 @@ void FieldObject2d::SetPose(const wpi::math::Pose2d& pose) { SetPoses({pose}); } -void FieldObject2d::SetPose(wpi::units::meter_t x, wpi::units::meter_t y, +void FieldObject2d::SetPose(wpi::units::meters<> x, wpi::units::meters<> y, wpi::math::Rotation2d rotation) { SetPoses({{x, y, rotation}}); } diff --git a/wpilibc/src/main/native/cpp/smartdashboard/MechanismLigament2d.cpp b/wpilibc/src/main/native/cpp/smartdashboard/MechanismLigament2d.cpp index 3a13dcf1c2d..16dd4d86769 100644 --- a/wpilibc/src/main/native/cpp/smartdashboard/MechanismLigament2d.cpp +++ b/wpilibc/src/main/native/cpp/smartdashboard/MechanismLigament2d.cpp @@ -13,7 +13,7 @@ using namespace wpi; MechanismLigament2d::MechanismLigament2d(std::string_view name, double length, - wpi::units::degree_t angle, + wpi::units::degrees<> angle, double lineWeight, const wpi::util::Color8Bit& color) : MechanismObject2d{name}, @@ -45,7 +45,7 @@ void MechanismLigament2d::SetColor(const wpi::util::Color8Bit& color) { color.red, color.green, color.blue); } -void MechanismLigament2d::SetAngle(wpi::units::degree_t angle) { +void MechanismLigament2d::SetAngle(wpi::units::degrees<> angle) { std::scoped_lock lock(m_mutex); m_angle = angle.value(); } diff --git a/wpilibc/src/main/native/cpp/system/Notifier.cpp b/wpilibc/src/main/native/cpp/system/Notifier.cpp index 5537015283e..dc9f64c8fc0 100644 --- a/wpilibc/src/main/native/cpp/system/Notifier.cpp +++ b/wpilibc/src/main/native/cpp/system/Notifier.cpp @@ -103,20 +103,20 @@ void Notifier::SetCallback(std::function callback) { m_callback = callback; } -void Notifier::StartSingle(wpi::units::second_t delay) { +void Notifier::StartSingle(wpi::units::seconds<> delay) { int32_t status = 0; HAL_SetNotifierAlarm(m_notifier, static_cast(delay * 1e9), 0, false, false, &status); } -void Notifier::StartPeriodic(wpi::units::second_t period) { +void Notifier::StartPeriodic(wpi::units::seconds<> period) { int32_t status = 0; HAL_SetNotifierAlarm(m_notifier, static_cast(period * 1e9), static_cast(period * 1e9), false, false, &status); } -void Notifier::StartPeriodic(wpi::units::hertz_t frequency) { +void Notifier::StartPeriodic(wpi::units::hertz<> frequency) { StartPeriodic(1 / frequency); } diff --git a/wpilibc/src/main/native/cpp/system/RobotController.cpp b/wpilibc/src/main/native/cpp/system/RobotController.cpp index f544d88410c..fbadca80406 100644 --- a/wpilibc/src/main/native/cpp/system/RobotController.cpp +++ b/wpilibc/src/main/native/cpp/system/RobotController.cpp @@ -51,11 +51,11 @@ int64_t RobotController::GetMonotonicTime() { return HAL_GetMonotonicTime(); } -wpi::units::volt_t RobotController::GetBatteryVoltage() { +wpi::units::volts<> RobotController::GetBatteryVoltage() { int32_t status = 0; double retVal = HAL_GetVinVoltage(&status); WPILIB_CheckErrorStatus(status, "GetBatteryVoltage"); - return wpi::units::volt_t{retVal}; + return wpi::units::volts<>{retVal}; } bool RobotController::IsSysActive() { @@ -140,19 +140,19 @@ void RobotController::ResetRailFaultCounts() { WPILIB_CheckErrorStatus(status, "ResetRailFaultCounts"); } -void RobotController::SetBrownoutVoltages(wpi::units::volt_t brownoutVoltage, - wpi::units::volt_t recoveryVoltage) { +void RobotController::SetBrownoutVoltages(wpi::units::volts<> brownoutVoltage, + wpi::units::volts<> recoveryVoltage) { int32_t status = 0; HAL_SetBrownoutVoltages(brownoutVoltage.value(), recoveryVoltage.value(), &status); WPILIB_CheckErrorStatus(status, "SetBrownoutVoltages"); } -wpi::units::celsius_t RobotController::GetCPUTemp() { +wpi::units::celsius<> RobotController::GetCPUTemp() { int32_t status = 0; double retVal = HAL_GetCPUTemp(&status); WPILIB_CheckErrorStatus(status, "GetCPUTemp"); - return wpi::units::celsius_t{retVal}; + return wpi::units::celsius<>{retVal}; } CANStatus RobotController::GetCANStatus(CANBus busId) { diff --git a/wpilibc/src/main/native/cpp/system/Timer.cpp b/wpilibc/src/main/native/cpp/system/Timer.cpp index cc940e46b1f..eef4b9226bf 100644 --- a/wpilibc/src/main/native/cpp/system/Timer.cpp +++ b/wpilibc/src/main/native/cpp/system/Timer.cpp @@ -14,16 +14,16 @@ namespace wpi { -void Wait(wpi::units::second_t seconds) { +void Wait(wpi::units::seconds<> seconds) { std::this_thread::sleep_for(std::chrono::duration(seconds.value())); } -wpi::units::second_t GetSystemTime() { +wpi::units::seconds<> GetSystemTime() { using std::chrono::duration; using std::chrono::duration_cast; using std::chrono::system_clock; - return wpi::units::second_t{ + return wpi::units::seconds<>{ duration_cast>(system_clock::now().time_since_epoch()) .count()}; } @@ -45,8 +45,8 @@ Timer::Timer() { Reset(); } -wpi::units::second_t Timer::Get() const { - return wpi::units::nanosecond_t{GetNanoseconds()}; +wpi::units::seconds<> Timer::Get() const { + return wpi::units::nanoseconds<>{GetNanoseconds()}; } double Timer::GetNanoseconds() const { @@ -88,12 +88,12 @@ void Timer::Stop() { } } -bool Timer::HasElapsed(wpi::units::second_t period) const { - return GetNanoseconds() >= wpi::units::nanosecond_t{period}.value(); +bool Timer::HasElapsed(wpi::units::seconds<> period) const { + return GetNanoseconds() >= wpi::units::nanoseconds<>{period}.value(); } -bool Timer::AdvanceIfElapsed(wpi::units::second_t period) { - double periodNs = wpi::units::nanosecond_t{period}.value(); +bool Timer::AdvanceIfElapsed(wpi::units::seconds<> period) { + double periodNs = wpi::units::nanoseconds<>{period}.value(); if (GetNanoseconds() >= periodNs) { // Advance the start time by the period. @@ -118,15 +118,15 @@ Timer Timer::CreateStarted() { return timer; } -wpi::units::second_t Timer::GetTimestamp() { +wpi::units::seconds<> Timer::GetTimestamp() { return GetTimestampNanoseconds(); } -wpi::units::second_t Timer::GetMonotonicTimestamp() { +wpi::units::seconds<> Timer::GetMonotonicTimestamp() { return std::chrono::nanoseconds{ static_cast(wpi::RobotController::GetMonotonicTime())}; } -wpi::units::second_t Timer::GetMatchTime() { +wpi::units::seconds<> Timer::GetMatchTime() { return wpi::MatchState::GetMatchTime(); } diff --git a/wpilibc/src/main/native/cpp/system/Watchdog.cpp b/wpilibc/src/main/native/cpp/system/Watchdog.cpp index 826480d2f42..2a981566c4f 100644 --- a/wpilibc/src/main/native/cpp/system/Watchdog.cpp +++ b/wpilibc/src/main/native/cpp/system/Watchdog.cpp @@ -104,7 +104,7 @@ void Watchdog::Impl::Main() { // has occurred, so call its timeout function. auto watchdog = m_watchdogs.pop(); - wpi::units::second_t now{curTime * 1e-9}; + wpi::units::seconds<> now{curTime * 1e-9}; if (now - watchdog->m_lastTimeoutPrintTime > MIN_PRINT_PERIOD) { watchdog->m_lastTimeoutPrintTime = now; if (!watchdog->m_suppressTimeoutMessage) { @@ -126,7 +126,8 @@ void Watchdog::Impl::Main() { } } -Watchdog::Watchdog(wpi::units::second_t timeout, std::function callback) +Watchdog::Watchdog(wpi::units::seconds<> timeout, + std::function callback) : m_timeout(timeout), m_callback(std::move(callback)), m_impl(GetImpl()) {} Watchdog::~Watchdog() { @@ -159,11 +160,11 @@ Watchdog& Watchdog::operator=(Watchdog&& rhs) { return *this; } -wpi::units::second_t Watchdog::GetTime() const { +wpi::units::seconds<> Watchdog::GetTime() const { return Timer::GetMonotonicTimestamp() - m_startTime; } -void Watchdog::SetTimeout(wpi::units::second_t timeout) { +void Watchdog::SetTimeout(wpi::units::seconds<> timeout) { m_startTime = Timer::GetMonotonicTimestamp(); m_tracer.ClearEpochs(); @@ -177,7 +178,7 @@ void Watchdog::SetTimeout(wpi::units::second_t timeout) { m_impl->UpdateAlarm(); } -wpi::units::second_t Watchdog::GetTimeout() const { +wpi::units::seconds<> Watchdog::GetTimeout() const { std::scoped_lock lock(m_impl->m_mutex); return m_timeout; } diff --git a/wpilibc/src/main/native/include/wpi/driverstation/Joystick.hpp b/wpilibc/src/main/native/include/wpi/driverstation/Joystick.hpp index 42363b7cf6a..8e5e83f6696 100644 --- a/wpilibc/src/main/native/include/wpi/driverstation/Joystick.hpp +++ b/wpilibc/src/main/native/include/wpi/driverstation/Joystick.hpp @@ -330,7 +330,7 @@ class Joystick : public HIDDevice { * * @return The direction of the vector. */ - wpi::units::radian_t GetDirection() const; + wpi::units::radians<> GetDirection() const; private: enum Axis { X, Y, Z, TWIST, THROTTLE, NUM_AXES }; diff --git a/wpilibc/src/main/native/include/wpi/driverstation/MatchState.hpp b/wpilibc/src/main/native/include/wpi/driverstation/MatchState.hpp index 1ed6ebbba6a..9200cd0c622 100644 --- a/wpilibc/src/main/native/include/wpi/driverstation/MatchState.hpp +++ b/wpilibc/src/main/native/include/wpi/driverstation/MatchState.hpp @@ -39,7 +39,7 @@ class MatchState final { * * @return Time remaining in current match period (auto or teleop) in seconds */ - static wpi::units::second_t GetMatchTime() { + static wpi::units::seconds<> GetMatchTime() { return wpi::internal::DriverStationBackend::GetMatchTime(); } diff --git a/wpilibc/src/main/native/include/wpi/driverstation/internal/DriverStationBackend.hpp b/wpilibc/src/main/native/include/wpi/driverstation/internal/DriverStationBackend.hpp index b1aec738fd3..7db64eed9de 100644 --- a/wpilibc/src/main/native/include/wpi/driverstation/internal/DriverStationBackend.hpp +++ b/wpilibc/src/main/native/include/wpi/driverstation/internal/DriverStationBackend.hpp @@ -546,7 +546,7 @@ class DriverStationBackend final { * * @return Time remaining in current match period (auto or teleop) in seconds */ - static wpi::units::second_t GetMatchTime(); + static wpi::units::seconds<> GetMatchTime(); /** * Read the battery voltage. diff --git a/wpilibc/src/main/native/include/wpi/event/BooleanEvent.hpp b/wpilibc/src/main/native/include/wpi/event/BooleanEvent.hpp index 9e299ae206d..ac36c3cfd11 100644 --- a/wpilibc/src/main/native/include/wpi/event/BooleanEvent.hpp +++ b/wpilibc/src/main/native/include/wpi/event/BooleanEvent.hpp @@ -122,7 +122,7 @@ class BooleanEvent { * @param type The debounce type. * @return The debounced event. */ - BooleanEvent Debounce(wpi::units::second_t debounceTime, + BooleanEvent Debounce(wpi::units::seconds<> debounceTime, wpi::math::Debouncer::DebounceType type = wpi::math::Debouncer::DebounceType::RISING); diff --git a/wpilibc/src/main/native/include/wpi/framework/IterativeRobotBase.hpp b/wpilibc/src/main/native/include/wpi/framework/IterativeRobotBase.hpp index 69e5e00b940..5e9380c1fce 100644 --- a/wpilibc/src/main/native/include/wpi/framework/IterativeRobotBase.hpp +++ b/wpilibc/src/main/native/include/wpi/framework/IterativeRobotBase.hpp @@ -190,7 +190,7 @@ class IterativeRobotBase : public RobotBase { /** * Gets time period between calls to Periodic() functions. */ - wpi::units::second_t GetPeriod() const; + wpi::units::seconds<> GetPeriod() const; /** * Prints list of epochs added so far and their times. @@ -202,7 +202,7 @@ class IterativeRobotBase : public RobotBase { * * @param period Period. */ - explicit IterativeRobotBase(wpi::units::second_t period); + explicit IterativeRobotBase(wpi::units::seconds<> period); ~IterativeRobotBase() override = default; @@ -217,7 +217,7 @@ class IterativeRobotBase : public RobotBase { private: int m_lastMode = -1; - wpi::units::second_t m_period; + wpi::units::seconds<> m_period; Watchdog m_watchdog; bool m_calledDsConnected = false; diff --git a/wpilibc/src/main/native/include/wpi/framework/OpModeRobot.hpp b/wpilibc/src/main/native/include/wpi/framework/OpModeRobot.hpp index 6a633ef9155..963ba932306 100644 --- a/wpilibc/src/main/native/include/wpi/framework/OpModeRobot.hpp +++ b/wpilibc/src/main/native/include/wpi/framework/OpModeRobot.hpp @@ -80,7 +80,7 @@ class OpModeRobotBase : public RobotBase { * * @param period The period of the robot loop function. */ - explicit OpModeRobotBase(wpi::units::second_t period); + explicit OpModeRobotBase(wpi::units::seconds<> period); /** * Constructor for an OpModeRobot with a default loop time of 0.02 seconds. @@ -144,7 +144,8 @@ class OpModeRobotBase : public RobotBase { * @param callback The callback to run. * @param period The period at which to run the callback. */ - void AddPeriodic(std::function callback, wpi::units::second_t period); + void AddPeriodic(std::function callback, + wpi::units::seconds<> period); /** * Return the system clock time in nanoseconds for the start of the current @@ -156,7 +157,7 @@ class OpModeRobotBase : public RobotBase { * @return Robot running time in nanoseconds, as of the start of the current * periodic function. */ - wpi::units::nanosecond_t GetLoopStartTime() const { + wpi::units::nanoseconds<> GetLoopStartTime() const { return m_callbacks.GetLoopStartTime(); } @@ -255,7 +256,7 @@ class OpModeRobotBase : public RobotBase { wpi::internal::PeriodicPriorityQueue m_callbacks; HAL_NotifierHandle m_notifier; - wpi::units::second_t m_period; + wpi::units::seconds<> m_period; std::chrono::nanoseconds m_startTime; wpi::util::Alert m_loopOverrunAlert; Watchdog m_watchdog; @@ -295,7 +296,8 @@ class OpModeRobot : public OpModeRobotBase { * * @param period The period of the robot loop function. */ - explicit OpModeRobot(wpi::units::second_t period) : OpModeRobotBase{period} {} + explicit OpModeRobot(wpi::units::seconds<> period) + : OpModeRobotBase{period} {} /** * Constructor for an OpModeRobot with a default loop time of 0.02 seconds. diff --git a/wpilibc/src/main/native/include/wpi/framework/TimedRobot.hpp b/wpilibc/src/main/native/include/wpi/framework/TimedRobot.hpp index 7ec4e4f823d..3a1bc206966 100644 --- a/wpilibc/src/main/native/include/wpi/framework/TimedRobot.hpp +++ b/wpilibc/src/main/native/include/wpi/framework/TimedRobot.hpp @@ -44,14 +44,14 @@ class TimedRobot : public IterativeRobotBase { * * @param period The period of the robot loop function. */ - explicit TimedRobot(wpi::units::second_t period = DEFAULT_PERIOD); + explicit TimedRobot(wpi::units::seconds<> period = DEFAULT_PERIOD); /** * Constructor for TimedRobot. * * @param frequency The frequency of the robot loop function. */ - explicit TimedRobot(wpi::units::hertz_t frequency); + explicit TimedRobot(wpi::units::hertz<> frequency); TimedRobot(TimedRobot&&) = default; TimedRobot& operator=(TimedRobot&&) = default; @@ -68,7 +68,7 @@ class TimedRobot : public IterativeRobotBase { * @return Robot running time in nanoseconds, as of the start of the current * periodic function. */ - wpi::units::nanosecond_t GetLoopStartTime() const { + wpi::units::nanoseconds<> GetLoopStartTime() const { return m_callbacks.GetLoopStartTime(); } @@ -84,8 +84,8 @@ class TimedRobot : public IterativeRobotBase { * for scheduling a callback in a different timeslot relative * to TimedRobot. */ - void AddPeriodic(std::function callback, wpi::units::second_t period, - wpi::units::second_t offset = 0_s); + void AddPeriodic(std::function callback, wpi::units::seconds<> period, + wpi::units::seconds<> offset = 0_s); protected: wpi::util::Handle m_notifier; diff --git a/wpilibc/src/main/native/include/wpi/framework/TimesliceRobot.hpp b/wpilibc/src/main/native/include/wpi/framework/TimesliceRobot.hpp index 21a41c3c8ff..9ed5f73dd7e 100644 --- a/wpilibc/src/main/native/include/wpi/framework/TimesliceRobot.hpp +++ b/wpilibc/src/main/native/include/wpi/framework/TimesliceRobot.hpp @@ -93,8 +93,8 @@ class TimesliceRobot : public TimedRobot { * allocations should be less than or equal to this * value. */ - explicit TimesliceRobot(wpi::units::second_t robotPeriodicAllocation, - wpi::units::second_t controllerPeriod); + explicit TimesliceRobot(wpi::units::seconds<> robotPeriodicAllocation, + wpi::units::seconds<> controllerPeriod); /** * Schedule a periodic function with the constructor's controller period and @@ -110,11 +110,11 @@ class TimesliceRobot : public TimedRobot { * @param allocation The function's runtime allocation out of the controller * period. */ - void Schedule(std::function func, wpi::units::second_t allocation); + void Schedule(std::function func, wpi::units::seconds<> allocation); private: - wpi::units::second_t m_nextOffset; - wpi::units::second_t m_controllerPeriod; + wpi::units::seconds<> m_nextOffset; + wpi::units::seconds<> m_controllerPeriod; }; } // namespace wpi diff --git a/wpilibc/src/main/native/include/wpi/hardware/bus/SerialPort.hpp b/wpilibc/src/main/native/include/wpi/hardware/bus/SerialPort.hpp index 990b9a8f17b..a511c7565b1 100644 --- a/wpilibc/src/main/native/include/wpi/hardware/bus/SerialPort.hpp +++ b/wpilibc/src/main/native/include/wpi/hardware/bus/SerialPort.hpp @@ -198,7 +198,7 @@ class SerialPort { * * @param timeout The time to wait for I/O. */ - void SetTimeout(wpi::units::second_t timeout); + void SetTimeout(wpi::units::seconds<> timeout); /** * Specify the size of the input buffer. diff --git a/wpilibc/src/main/native/include/wpi/hardware/counter/Tachometer.hpp b/wpilibc/src/main/native/include/wpi/hardware/counter/Tachometer.hpp index 9c108f2b59d..1cf4cae7dd9 100644 --- a/wpilibc/src/main/native/include/wpi/hardware/counter/Tachometer.hpp +++ b/wpilibc/src/main/native/include/wpi/hardware/counter/Tachometer.hpp @@ -50,14 +50,14 @@ class Tachometer : public wpi::telemetry::TelemetryLoggable { * @param window The rate calculation window. Valid values are 5 ms through * 255 ms. The default is 50 ms. */ - void SetRateWindow(wpi::units::millisecond_t window); + void SetRateWindow(wpi::units::milliseconds<> window); /** * Gets the tachometer frequency. * * @return Current frequency. */ - wpi::units::hertz_t GetFrequency() const; + wpi::units::hertz<> GetFrequency() const; /** * Gets the number of edges per revolution. @@ -81,7 +81,7 @@ class Tachometer : public wpi::telemetry::TelemetryLoggable { * @return Current RPS. * @Common This is one of the commonly used methods for this class */ - wpi::units::turns_per_second_t GetRevolutionsPerSecond() const; + wpi::units::turns_per_second<> GetRevolutionsPerSecond() const; /** * Gets the current tachometer revolutions per minute. @@ -91,7 +91,7 @@ class Tachometer : public wpi::telemetry::TelemetryLoggable { * @return Current RPM. * @Common This is one of the commonly used methods for this class */ - wpi::units::revolutions_per_minute_t GetRevolutionsPerMinute() const; + wpi::units::revolutions_per_minute<> GetRevolutionsPerMinute() const; /** * Gets if the tachometer is stopped. diff --git a/wpilibc/src/main/native/include/wpi/hardware/discrete/DigitalOutput.hpp b/wpilibc/src/main/native/include/wpi/hardware/discrete/DigitalOutput.hpp index 2babed258a5..799bd7531a0 100644 --- a/wpilibc/src/main/native/include/wpi/hardware/discrete/DigitalOutput.hpp +++ b/wpilibc/src/main/native/include/wpi/hardware/discrete/DigitalOutput.hpp @@ -65,7 +65,7 @@ class DigitalOutput : public wpi::telemetry::TelemetryLoggable { * @param pulseLength The pulse length in seconds * @Common This is one of the commonly used methods for this class */ - void Pulse(wpi::units::second_t pulseLength); + void Pulse(wpi::units::seconds<> pulseLength); /** * Determine if the pulse is still going. diff --git a/wpilibc/src/main/native/include/wpi/hardware/discrete/PWM.hpp b/wpilibc/src/main/native/include/wpi/hardware/discrete/PWM.hpp index e0b7e20c238..d40f36af49d 100644 --- a/wpilibc/src/main/native/include/wpi/hardware/discrete/PWM.hpp +++ b/wpilibc/src/main/native/include/wpi/hardware/discrete/PWM.hpp @@ -50,7 +50,7 @@ class PWM : public wpi::telemetry::TelemetryLoggable { * @param time Microsecond PWM value. Range 0 - 4096. * @Common This is one of the commonly used methods for this class */ - void SetPulseTime(wpi::units::microsecond_t time); + void SetPulseTime(wpi::units::microseconds<> time); /** * Get the PWM pulse time directly from the hardware. @@ -59,7 +59,7 @@ class PWM : public wpi::telemetry::TelemetryLoggable { * * @return Microsecond PWM control value. Range 0 - 4096. */ - wpi::units::microsecond_t GetPulseTime() const; + wpi::units::microseconds<> GetPulseTime() const; /** * Temporarily disables the PWM output. The next set call will re-enable @@ -73,7 +73,7 @@ class PWM : public wpi::telemetry::TelemetryLoggable { * @param period The output period to apply to this channel, in milliseconds. * Valid values are 5ms, 10ms, and 20ms. Default is 20 ms. */ - void SetOutputPeriod(wpi::units::millisecond_t period); + void SetOutputPeriod(wpi::units::milliseconds<> period); int GetChannel() const; diff --git a/wpilibc/src/main/native/include/wpi/hardware/expansionhub/ExpansionHubCRServo.hpp b/wpilibc/src/main/native/include/wpi/hardware/expansionhub/ExpansionHubCRServo.hpp index f6a8dfcad55..b3cff907e5b 100644 --- a/wpilibc/src/main/native/include/wpi/hardware/expansionhub/ExpansionHubCRServo.hpp +++ b/wpilibc/src/main/native/include/wpi/hardware/expansionhub/ExpansionHubCRServo.hpp @@ -44,7 +44,7 @@ class ExpansionHubCRServo { * * @param pulseWidth Pulse width */ - void SetPulseWidth(wpi::units::microsecond_t pulseWidth); + void SetPulseWidth(wpi::units::microseconds<> pulseWidth); /** * Sets if the servo output is enabled or not. Defaults to false. @@ -58,7 +58,7 @@ class ExpansionHubCRServo { * * @param framePeriod The frame period */ - void SetFramePeriod(wpi::units::microsecond_t framePeriod); + void SetFramePeriod(wpi::units::microseconds<> framePeriod); /** * Gets if the underlying ExpansionHub is connected. @@ -76,8 +76,8 @@ class ExpansionHubCRServo { * @param minPwm Minimum PWM * @param maxPwm Maximum PWM */ - void SetPWMRange(wpi::units::microsecond_t minPwm, - wpi::units::microsecond_t maxPwm); + void SetPWMRange(wpi::units::microseconds<> minPwm, + wpi::units::microseconds<> maxPwm); /** * Sets whether the servo is reversed. @@ -89,13 +89,13 @@ class ExpansionHubCRServo { void SetReversed(bool reversed); private: - wpi::units::microsecond_t GetFullRangeScaleFactor() const; + wpi::units::microseconds<> GetFullRangeScaleFactor() const; ExpansionHub m_hub; int m_channel; - wpi::units::microsecond_t m_minPwm = 600_us; - wpi::units::microsecond_t m_maxPwm = 2400_us; + wpi::units::microseconds<> m_minPwm = 600_us; + wpi::units::microseconds<> m_maxPwm = 2400_us; bool m_reversed = false; diff --git a/wpilibc/src/main/native/include/wpi/hardware/expansionhub/ExpansionHubMotor.hpp b/wpilibc/src/main/native/include/wpi/hardware/expansionhub/ExpansionHubMotor.hpp index dedd8294314..e4fa7e8006d 100644 --- a/wpilibc/src/main/native/include/wpi/hardware/expansionhub/ExpansionHubMotor.hpp +++ b/wpilibc/src/main/native/include/wpi/hardware/expansionhub/ExpansionHubMotor.hpp @@ -62,7 +62,7 @@ class ExpansionHubMotor { * * @param voltage The voltage to drive the motor at */ - void SetVoltage(wpi::units::volt_t voltage); + void SetVoltage(wpi::units::volts<> voltage); /** * Command the motor to drive to a specific position setpoint. This value will @@ -100,7 +100,7 @@ class ExpansionHubMotor { * * @return Motor current */ - wpi::units::ampere_t GetCurrent() const; + wpi::units::amperes<> GetCurrent() const; /** * Sets the distance per count of the encoder. Used to scale encoder readings. diff --git a/wpilibc/src/main/native/include/wpi/hardware/expansionhub/ExpansionHubServo.hpp b/wpilibc/src/main/native/include/wpi/hardware/expansionhub/ExpansionHubServo.hpp index 635b810da7b..13c71611891 100644 --- a/wpilibc/src/main/native/include/wpi/hardware/expansionhub/ExpansionHubServo.hpp +++ b/wpilibc/src/main/native/include/wpi/hardware/expansionhub/ExpansionHubServo.hpp @@ -49,14 +49,14 @@ class ExpansionHubServo { * current angle range. * @Common This is one of the commonly used methods for this class */ - void SetAngle(wpi::units::degree_t angle); + void SetAngle(wpi::units::degrees<> angle); /** * Sets the raw pulse width output on the servo. * * @param pulseWidth Pulse width */ - void SetPulseWidth(wpi::units::microsecond_t pulseWidth); + void SetPulseWidth(wpi::units::microseconds<> pulseWidth); /** * Sets if the servo output is enabled or not. Defaults to false. @@ -70,7 +70,7 @@ class ExpansionHubServo { * * @param framePeriod The frame period */ - void SetFramePeriod(wpi::units::microsecond_t framePeriod); + void SetFramePeriod(wpi::units::microseconds<> framePeriod); /** * Gets if the underlying ExpansionHub is connected. @@ -88,8 +88,8 @@ class ExpansionHubServo { * @param minAngle Minimum angle * @param maxAngle Maximum angle */ - void SetAngleRange(wpi::units::degree_t minAngle, - wpi::units::degree_t maxAngle); + void SetAngleRange(wpi::units::degrees<> minAngle, + wpi::units::degrees<> maxAngle); /** * Sets the PWM range for the servo. @@ -100,8 +100,8 @@ class ExpansionHubServo { * @param minPwm Minimum PWM * @param maxPwm Maximum PWM */ - void SetPWMRange(wpi::units::microsecond_t minPwm, - wpi::units::microsecond_t maxPwm); + void SetPWMRange(wpi::units::microseconds<> minPwm, + wpi::units::microseconds<> maxPwm); /** * Sets whether the servo is reversed. @@ -113,17 +113,17 @@ class ExpansionHubServo { void SetReversed(bool reversed); private: - wpi::units::microsecond_t GetFullRangeScaleFactor(); - wpi::units::degree_t GetServoAngleRange(); + wpi::units::microseconds<> GetFullRangeScaleFactor(); + wpi::units::degrees<> GetServoAngleRange(); ExpansionHub m_hub; int m_channel; - wpi::units::degree_t m_maxServoAngle = 180.0_deg; - wpi::units::degree_t m_minServoAngle = 0.0_deg; + wpi::units::degrees<> m_maxServoAngle = 180.0_deg; + wpi::units::degrees<> m_minServoAngle = 0.0_deg; - wpi::units::microsecond_t m_minPwm = 600_us; - wpi::units::microsecond_t m_maxPwm = 2400_us; + wpi::units::microseconds<> m_minPwm = 600_us; + wpi::units::microseconds<> m_maxPwm = 2400_us; bool m_reversed = false; diff --git a/wpilibc/src/main/native/include/wpi/hardware/imu/OnboardIMU.hpp b/wpilibc/src/main/native/include/wpi/hardware/imu/OnboardIMU.hpp index 8493a996a87..29813d2ce28 100644 --- a/wpilibc/src/main/native/include/wpi/hardware/imu/OnboardIMU.hpp +++ b/wpilibc/src/main/native/include/wpi/hardware/imu/OnboardIMU.hpp @@ -43,7 +43,7 @@ class OnboardIMU { * @return yaw value * @Common This is one of the commonly used methods for this class */ - wpi::units::radian_t GetYaw(); + wpi::units::radians<> GetYaw(); /** * Reset the current yaw value to 0. Future reads of the yaw value will be @@ -75,59 +75,59 @@ class OnboardIMU { * Get the angle about the X axis of the IMU. * @return angle about the X axis */ - wpi::units::radian_t GetAngleX(); + wpi::units::radians<> GetAngleX(); /** * Get the angle about the Y axis of the IMU. * @return angle about the Y axis */ - wpi::units::radian_t GetAngleY(); + wpi::units::radians<> GetAngleY(); /** * Get the angle about the Z axis of the IMU. * @return angle about the Z axis */ - wpi::units::radian_t GetAngleZ(); + wpi::units::radians<> GetAngleZ(); /** * Get the angular rate about the X axis of the IMU. * @return angular rate about the X axis */ - wpi::units::radians_per_second_t GetGyroRateX(); + wpi::units::radians_per_second<> GetGyroRateX(); /** * Get the angular rate about the Y axis of the IMU. * @return angular rate about the Y axis */ - wpi::units::radians_per_second_t GetGyroRateY(); + wpi::units::radians_per_second<> GetGyroRateY(); /** * Get the angular rate about the Z axis of the IMU. * @return angular rate about the Z axis */ - wpi::units::radians_per_second_t GetGyroRateZ(); + wpi::units::radians_per_second<> GetGyroRateZ(); /** * Get the acceleration along the X axis of the IMU. * @return acceleration along the X axis */ - wpi::units::meters_per_second_squared_t GetAccelX(); + wpi::units::meters_per_second_squared<> GetAccelX(); /** * Get the acceleration along the Z axis of the IMU. * @return acceleration along the Z axis */ - wpi::units::meters_per_second_squared_t GetAccelY(); + wpi::units::meters_per_second_squared<> GetAccelY(); /** * Get the acceleration along the Z axis of the IMU. * @return acceleration along the Z axis */ - wpi::units::meters_per_second_squared_t GetAccelZ(); + wpi::units::meters_per_second_squared<> GetAccelZ(); private: - wpi::units::radian_t GetYawNoOffset(); + wpi::units::radians<> GetYawNoOffset(); MountOrientation m_mountOrientation; - wpi::units::radian_t m_yawOffset{0}; + wpi::units::radians<> m_yawOffset{0}; }; } // namespace wpi diff --git a/wpilibc/src/main/native/include/wpi/hardware/led/LEDPattern.hpp b/wpilibc/src/main/native/include/wpi/hardware/led/LEDPattern.hpp index d4139b623a4..b0f2e88ccec 100644 --- a/wpilibc/src/main/native/include/wpi/hardware/led/LEDPattern.hpp +++ b/wpilibc/src/main/native/include/wpi/hardware/led/LEDPattern.hpp @@ -121,7 +121,7 @@ class LEDPattern { * long (assuming equal LED density on both segments). */ [[nodiscard]] - LEDPattern ScrollAtRelativeVelocity(wpi::units::hertz_t velocity); + LEDPattern ScrollAtRelativeVelocity(wpi::units::hertz<> velocity); /** * Creates a pattern that plays this one scrolling up an LED strip. A negative @@ -132,12 +132,12 @@ class LEDPattern { * *
    *   // LEDs per meter, a known value taken from the spec sheet of our
-   * particular LED strip wpi::units::meter_t LED_SPACING =
-   * wpi::units::meter_t{1 /60.0};
+   * particular LED strip wpi::units::meters<> LED_SPACING =
+   * wpi::units::meters<>{1 /60.0};
    *
    *   wpi::LEDPattern rainbow = wpi::LEDPattern::Rainbow();
    *   wpi::LEDPattern scrollingRainbow = rainbow.ScrollAtAbsoluteVelocity(
-   *     wpi::units::feet_per_second_t{1 / 3.0}, LED_SPACING);
+   *     wpi::units::feet_per_second<>{1 / 3.0}, LED_SPACING);
    * 
* *

Note that this pattern will scroll faster if applied to a less @@ -150,8 +150,8 @@ class LEDPattern { * @return the scrolling pattern */ [[nodiscard]] - LEDPattern ScrollAtAbsoluteVelocity(wpi::units::meters_per_second_t velocity, - wpi::units::meter_t ledSpacing); + LEDPattern ScrollAtAbsoluteVelocity(wpi::units::meters_per_second<> velocity, + wpi::units::meters<> ledSpacing); /** * Creates a pattern that switches between playing this pattern and turning @@ -162,10 +162,10 @@ class LEDPattern { * @return the blinking pattern */ [[nodiscard]] - LEDPattern Blink(wpi::units::second_t onTime, wpi::units::second_t offTime); + LEDPattern Blink(wpi::units::seconds<> onTime, wpi::units::seconds<> offTime); /** - * Like {@link LEDPattern::Blink(wpi::units::second_t)}, but where the + * Like {@link LEDPattern::Blink(wpi::units::seconds<>)}, but where the * "off" time is exactly equal to the "on" time. * * @param onTime how long the pattern should play for (and be turned off for), @@ -173,7 +173,7 @@ class LEDPattern { * @return the blinking pattern */ [[nodiscard]] - LEDPattern Blink(wpi::units::second_t onTime); + LEDPattern Blink(wpi::units::seconds<> onTime); /** * Creates a pattern that blinks this one on and off in sync with a true/false @@ -195,7 +195,7 @@ class LEDPattern { * @return the breathing pattern */ [[nodiscard]] - LEDPattern Breathe(wpi::units::second_t period); + LEDPattern Breathe(wpi::units::seconds<> period); /** * Creates a pattern that plays this pattern overlaid on another. Anywhere diff --git a/wpilibc/src/main/native/include/wpi/hardware/motor/MotorController.hpp b/wpilibc/src/main/native/include/wpi/hardware/motor/MotorController.hpp index 25dbc2ac1f2..91a043baeb5 100644 --- a/wpilibc/src/main/native/include/wpi/hardware/motor/MotorController.hpp +++ b/wpilibc/src/main/native/include/wpi/hardware/motor/MotorController.hpp @@ -37,7 +37,7 @@ class MotorController { * * @param voltage The voltage. */ - virtual void SetVoltage(wpi::units::volt_t voltage); + virtual void SetVoltage(wpi::units::volts<> voltage); /** * Gets the throttle of the motor controller. diff --git a/wpilibc/src/main/native/include/wpi/hardware/motor/MotorSafety.hpp b/wpilibc/src/main/native/include/wpi/hardware/motor/MotorSafety.hpp index 45f079fdceb..2022a55dcb6 100644 --- a/wpilibc/src/main/native/include/wpi/hardware/motor/MotorSafety.hpp +++ b/wpilibc/src/main/native/include/wpi/hardware/motor/MotorSafety.hpp @@ -41,14 +41,14 @@ class MotorSafety { * * @param expirationTime The timeout value. */ - void SetExpiration(wpi::units::second_t expirationTime); + void SetExpiration(wpi::units::seconds<> expirationTime); /** * Retrieve the timeout value for the corresponding motor safety object. * * @return the timeout value. */ - wpi::units::second_t GetExpiration() const; + wpi::units::seconds<> GetExpiration() const; /** * Determine if the motor is still operating or has timed out. @@ -108,13 +108,13 @@ class MotorSafety { static constexpr auto DEFAULT_SAFETY_EXPIRATION = 100_ms; // The expiration time for this object - wpi::units::second_t m_expiration = DEFAULT_SAFETY_EXPIRATION; + wpi::units::seconds<> m_expiration = DEFAULT_SAFETY_EXPIRATION; // True if motor safety is enabled for this motor bool m_enabled = false; // The FPGA clock value when the motor has expired - wpi::units::second_t m_stopTime = Timer::GetMonotonicTimestamp(); + wpi::units::seconds<> m_stopTime = Timer::GetMonotonicTimestamp(); mutable wpi::util::mutex m_thisMutex; }; diff --git a/wpilibc/src/main/native/include/wpi/hardware/motor/PWMMotorController.hpp b/wpilibc/src/main/native/include/wpi/hardware/motor/PWMMotorController.hpp index 92a028d03cd..8dce1495442 100644 --- a/wpilibc/src/main/native/include/wpi/hardware/motor/PWMMotorController.hpp +++ b/wpilibc/src/main/native/include/wpi/hardware/motor/PWMMotorController.hpp @@ -41,7 +41,7 @@ class PWMMotorController : public MotorController, * @return The voltage of the motor controller, nominally between -12 V and 12 * V. */ - virtual wpi::units::volt_t GetVoltage() const; + virtual wpi::units::volts<> GetVoltage() const; void SetInverted(bool isInverted) override; @@ -101,11 +101,11 @@ class PWMMotorController : public MotorController, void SetDutyCycleInternal(double dutyCycle); double GetDutyCycleInternal() const; - void 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); + void SetBounds(wpi::units::microseconds<> maxPwm, + wpi::units::microseconds<> deadbandMaxPwm, + wpi::units::microseconds<> centerPwm, + wpi::units::microseconds<> deadbandMinPwm, + wpi::units::microseconds<> minPwm); private: bool m_isInverted = false; @@ -116,16 +116,16 @@ class PWMMotorController : public MotorController, wpi::hal::SimDouble m_simThrottle; bool m_eliminateDeadband{0}; - wpi::units::microsecond_t m_minPwm{0}; - wpi::units::microsecond_t m_deadbandMinPwm{0}; - wpi::units::microsecond_t m_centerPwm{0}; - wpi::units::microsecond_t m_deadbandMaxPwm{0}; - wpi::units::microsecond_t m_maxPwm{0}; - - wpi::units::microsecond_t GetMinPositivePwm() const; - wpi::units::microsecond_t GetMaxNegativePwm() const; - wpi::units::microsecond_t GetPositiveScaleFactor() const; - wpi::units::microsecond_t GetNegativeScaleFactor() const; + wpi::units::microseconds<> m_minPwm{0}; + wpi::units::microseconds<> m_deadbandMinPwm{0}; + wpi::units::microseconds<> m_centerPwm{0}; + wpi::units::microseconds<> m_deadbandMaxPwm{0}; + wpi::units::microseconds<> m_maxPwm{0}; + + wpi::units::microseconds<> GetMinPositivePwm() const; + wpi::units::microseconds<> GetMaxNegativePwm() const; + wpi::units::microseconds<> GetPositiveScaleFactor() const; + wpi::units::microseconds<> GetNegativeScaleFactor() const; PWM* GetPwm() { return &m_pwm; } }; diff --git a/wpilibc/src/main/native/include/wpi/hardware/pneumatic/Compressor.hpp b/wpilibc/src/main/native/include/wpi/hardware/pneumatic/Compressor.hpp index 79785b72728..cdb4b147554 100644 --- a/wpilibc/src/main/native/include/wpi/hardware/pneumatic/Compressor.hpp +++ b/wpilibc/src/main/native/include/wpi/hardware/pneumatic/Compressor.hpp @@ -75,7 +75,7 @@ class Compressor : public wpi::telemetry::TelemetryLoggable { * * @return Current drawn by the compressor. */ - wpi::units::ampere_t GetCurrent() const; + wpi::units::amperes<> GetCurrent() const; /** * If supported by the device, returns the analog input voltage (on channel @@ -86,7 +86,7 @@ class Compressor : public wpi::telemetry::TelemetryLoggable { * * @return The analog input voltage, in volts. */ - wpi::units::volt_t GetAnalogVoltage() const; + wpi::units::volts<> GetAnalogVoltage() const; /** * If supported by the device, returns the pressure read by the analog @@ -97,7 +97,7 @@ class Compressor : public wpi::telemetry::TelemetryLoggable { * * @return The pressure read by the analog pressure sensor. */ - wpi::units::pounds_per_square_inch_t GetPressure() const; + wpi::units::pounds_per_square_inch<> GetPressure() const; /** * Disable the compressor. @@ -127,8 +127,8 @@ class Compressor : public wpi::telemetry::TelemetryLoggable { * @param maxPressure The maximum pressure. The compressor will turn off when * the pressure reaches this value. */ - void EnableAnalog(wpi::units::pounds_per_square_inch_t minPressure, - wpi::units::pounds_per_square_inch_t maxPressure); + void EnableAnalog(wpi::units::pounds_per_square_inch<> minPressure, + wpi::units::pounds_per_square_inch<> maxPressure); /** * If supported by the device, enables the compressor in hybrid mode. This @@ -159,8 +159,8 @@ class Compressor : public wpi::telemetry::TelemetryLoggable { * off when the pressure reaches this value or the pressure switch is * disconnected or indicates that the system is full. */ - void EnableHybrid(wpi::units::pounds_per_square_inch_t minPressure, - wpi::units::pounds_per_square_inch_t maxPressure); + void EnableHybrid(wpi::units::pounds_per_square_inch<> minPressure, + wpi::units::pounds_per_square_inch<> maxPressure); /** * Returns the active compressor configuration. diff --git a/wpilibc/src/main/native/include/wpi/hardware/pneumatic/PneumaticHub.hpp b/wpilibc/src/main/native/include/wpi/hardware/pneumatic/PneumaticHub.hpp index 5890146f027..35c06f710b1 100644 --- a/wpilibc/src/main/native/include/wpi/hardware/pneumatic/PneumaticHub.hpp +++ b/wpilibc/src/main/native/include/wpi/hardware/pneumatic/PneumaticHub.hpp @@ -58,8 +58,8 @@ class PneumaticHub : public PneumaticsBase { * minPressure. */ void EnableCompressorAnalog( - wpi::units::pounds_per_square_inch_t minPressure, - wpi::units::pounds_per_square_inch_t maxPressure) override; + wpi::units::pounds_per_square_inch<> minPressure, + wpi::units::pounds_per_square_inch<> maxPressure) override; /** * Enables the compressor in hybrid mode. This mode uses both a digital @@ -88,14 +88,14 @@ class PneumaticHub : public PneumaticsBase { * minPressure. */ void EnableCompressorHybrid( - wpi::units::pounds_per_square_inch_t minPressure, - wpi::units::pounds_per_square_inch_t maxPressure) override; + wpi::units::pounds_per_square_inch<> minPressure, + wpi::units::pounds_per_square_inch<> maxPressure) override; CompressorConfigType GetCompressorConfigType() const override; bool GetPressureSwitch() const override; - wpi::units::ampere_t GetCompressorCurrent() const override; + wpi::units::amperes<> GetCompressorCurrent() const override; void SetSolenoids(int mask, int values) override; @@ -107,7 +107,7 @@ class PneumaticHub : public PneumaticsBase { void FireOneShot(int index) override; - void SetOneShotDuration(int index, wpi::units::second_t duration) override; + void SetOneShotDuration(int index, wpi::units::seconds<> duration) override; bool CheckSolenoidChannel(int channel) const override; @@ -258,28 +258,28 @@ class PneumaticHub : public PneumaticsBase { * * @return The input voltage. */ - wpi::units::volt_t GetInputVoltage() const; + wpi::units::volts<> GetInputVoltage() const; /** * Returns the current voltage of the regulated 5v supply. * * @return The current voltage of the 5v supply. */ - wpi::units::volt_t Get5VRegulatedVoltage() const; + wpi::units::volts<> Get5VRegulatedVoltage() const; /** * Returns the total current drawn by all solenoids. * * @return Total current drawn by all solenoids. */ - wpi::units::ampere_t GetSolenoidsTotalCurrent() const; + wpi::units::amperes<> GetSolenoidsTotalCurrent() const; /** * Returns the current voltage of the solenoid power supply. * * @return The current voltage of the solenoid power supply. */ - wpi::units::volt_t GetSolenoidsVoltage() const; + wpi::units::volts<> GetSolenoidsVoltage() const; /** * Returns the raw voltage of the specified analog input channel. @@ -287,7 +287,7 @@ class PneumaticHub : public PneumaticsBase { * @param channel The analog input channel to read voltage from. * @return The voltage of the specified analog input channel. */ - wpi::units::volt_t GetAnalogVoltage(int channel) const override; + wpi::units::volts<> GetAnalogVoltage(int channel) const override; /** * Returns the pressure read by an analog pressure sensor on the specified @@ -297,7 +297,7 @@ class PneumaticHub : public PneumaticsBase { * @return The pressure read by an analog pressure sensor on the specified * analog input channel. */ - wpi::units::pounds_per_square_inch_t GetPressure(int channel) const override; + wpi::units::pounds_per_square_inch<> GetPressure(int channel) const override; private: class DataStore; diff --git a/wpilibc/src/main/native/include/wpi/hardware/pneumatic/PneumaticsBase.hpp b/wpilibc/src/main/native/include/wpi/hardware/pneumatic/PneumaticsBase.hpp index 483dd85d1c4..928f86c8522 100644 --- a/wpilibc/src/main/native/include/wpi/hardware/pneumatic/PneumaticsBase.hpp +++ b/wpilibc/src/main/native/include/wpi/hardware/pneumatic/PneumaticsBase.hpp @@ -47,7 +47,7 @@ class PneumaticsBase { * * @return The current drawn by the compressor. */ - virtual wpi::units::ampere_t GetCompressorCurrent() const = 0; + virtual wpi::units::amperes<> GetCompressorCurrent() const = 0; /** Disables the compressor. */ virtual void DisableCompressor() = 0; @@ -76,8 +76,8 @@ class PneumaticsBase { * off when the pressure reaches this value. */ virtual void EnableCompressorAnalog( - wpi::units::pounds_per_square_inch_t minPressure, - wpi::units::pounds_per_square_inch_t maxPressure) = 0; + wpi::units::pounds_per_square_inch<> minPressure, + wpi::units::pounds_per_square_inch<> maxPressure) = 0; /** * If supported by the device, enables the compressor in hybrid mode. This @@ -109,8 +109,8 @@ class PneumaticsBase { * disconnected or indicates that the system is full. */ virtual void EnableCompressorHybrid( - wpi::units::pounds_per_square_inch_t minPressure, - wpi::units::pounds_per_square_inch_t maxPressure) = 0; + wpi::units::pounds_per_square_inch<> minPressure, + wpi::units::pounds_per_square_inch<> maxPressure) = 0; /** * Returns the active compressor configuration. @@ -165,7 +165,8 @@ class PneumaticsBase { * @param index solenoid index * @param duration shot duration */ - virtual void SetOneShotDuration(int index, wpi::units::second_t duration) = 0; + virtual void SetOneShotDuration(int index, + wpi::units::seconds<> duration) = 0; /** * Check if a solenoid channel is valid. @@ -216,7 +217,7 @@ class PneumaticsBase { * @param channel The analog input channel to read voltage from. * @return The voltage of the specified analog input channel. */ - virtual wpi::units::volt_t GetAnalogVoltage(int channel) const = 0; + virtual wpi::units::volts<> GetAnalogVoltage(int channel) const = 0; /** * If supported by the device, returns the pressure read by an analog @@ -229,7 +230,7 @@ class PneumaticsBase { * @return The pressure read by an analog pressure sensor on the * specified analog input channel. */ - virtual wpi::units::pounds_per_square_inch_t GetPressure( + virtual wpi::units::pounds_per_square_inch<> GetPressure( int channel) const = 0; /** diff --git a/wpilibc/src/main/native/include/wpi/hardware/pneumatic/PneumaticsControlModule.hpp b/wpilibc/src/main/native/include/wpi/hardware/pneumatic/PneumaticsControlModule.hpp index 1bffcc3ab7b..97a51e6b1b2 100644 --- a/wpilibc/src/main/native/include/wpi/hardware/pneumatic/PneumaticsControlModule.hpp +++ b/wpilibc/src/main/native/include/wpi/hardware/pneumatic/PneumaticsControlModule.hpp @@ -53,8 +53,8 @@ class PneumaticsControlModule : public PneumaticsBase { * @see EnableCompressorDigital() */ void EnableCompressorAnalog( - wpi::units::pounds_per_square_inch_t minPressure, - wpi::units::pounds_per_square_inch_t maxPressure) override; + wpi::units::pounds_per_square_inch<> minPressure, + wpi::units::pounds_per_square_inch<> maxPressure) override; /** * Enables the compressor in digital mode. Hybrid mode is unsupported by the @@ -65,14 +65,14 @@ class PneumaticsControlModule : public PneumaticsBase { * @see EnableCompressorDigital() */ void EnableCompressorHybrid( - wpi::units::pounds_per_square_inch_t minPressure, - wpi::units::pounds_per_square_inch_t maxPressure) override; + wpi::units::pounds_per_square_inch<> minPressure, + wpi::units::pounds_per_square_inch<> maxPressure) override; CompressorConfigType GetCompressorConfigType() const override; bool GetPressureSwitch() const override; - wpi::units::ampere_t GetCompressorCurrent() const override; + wpi::units::amperes<> GetCompressorCurrent() const override; /** * Return whether the compressor current is currently too high. @@ -162,7 +162,7 @@ class PneumaticsControlModule : public PneumaticsBase { void FireOneShot(int index) override; - void SetOneShotDuration(int index, wpi::units::second_t duration) override; + void SetOneShotDuration(int index, wpi::units::seconds<> duration) override; bool CheckSolenoidChannel(int channel) const override; @@ -180,7 +180,7 @@ class PneumaticsControlModule : public PneumaticsBase { * @param channel Unsupported. * @return 0 */ - wpi::units::volt_t GetAnalogVoltage(int channel) const override; + wpi::units::volts<> GetAnalogVoltage(int channel) const override; /** * Unsupported by the CTRE PCM. @@ -188,7 +188,7 @@ class PneumaticsControlModule : public PneumaticsBase { * @param channel Unsupported. * @return 0 */ - wpi::units::pounds_per_square_inch_t GetPressure(int channel) const override; + wpi::units::pounds_per_square_inch<> GetPressure(int channel) const override; Solenoid MakeSolenoid(int channel) override; DoubleSolenoid MakeDoubleSolenoid(int forwardChannel, diff --git a/wpilibc/src/main/native/include/wpi/hardware/pneumatic/Solenoid.hpp b/wpilibc/src/main/native/include/wpi/hardware/pneumatic/Solenoid.hpp index 99641d55424..f89800ea6e8 100644 --- a/wpilibc/src/main/native/include/wpi/hardware/pneumatic/Solenoid.hpp +++ b/wpilibc/src/main/native/include/wpi/hardware/pneumatic/Solenoid.hpp @@ -100,7 +100,7 @@ class Solenoid : public wpi::telemetry::TelemetryLoggable { * * @see startPulse() */ - void SetPulseDuration(wpi::units::second_t duration); + void SetPulseDuration(wpi::units::seconds<> duration); /** * %Trigger the pneumatics module to generate a pulse of the duration set in diff --git a/wpilibc/src/main/native/include/wpi/hardware/range/SharpIR.hpp b/wpilibc/src/main/native/include/wpi/hardware/range/SharpIR.hpp index 467b395770e..c450b2fd92d 100644 --- a/wpilibc/src/main/native/include/wpi/hardware/range/SharpIR.hpp +++ b/wpilibc/src/main/native/include/wpi/hardware/range/SharpIR.hpp @@ -64,8 +64,8 @@ class SharpIR : public wpi::telemetry::TelemetryLoggable { * @param min Minimum distance to report * @param max Maximum distance to report */ - SharpIR(int channel, double a, double b, wpi::units::meter_t min, - wpi::units::meter_t max); + SharpIR(int channel, double a, double b, wpi::units::meters<> min, + wpi::units::meters<> max); /** * Get the analog input channel number. @@ -80,7 +80,7 @@ class SharpIR : public wpi::telemetry::TelemetryLoggable { * @return range of the target returned by the sensor * @Common This is one of the commonly used methods for this class */ - wpi::units::meter_t GetRange() const; + wpi::units::meters<> GetRange() const; void LogTo(wpi::telemetry::TelemetryTable& table) const override; @@ -94,8 +94,8 @@ class SharpIR : public wpi::telemetry::TelemetryLoggable { double m_A; double m_B; - wpi::units::meter_t m_min; - wpi::units::meter_t m_max; + wpi::units::meters<> m_min; + wpi::units::meters<> m_max; }; } // namespace wpi diff --git a/wpilibc/src/main/native/include/wpi/hardware/rotation/DutyCycle.hpp b/wpilibc/src/main/native/include/wpi/hardware/rotation/DutyCycle.hpp index 500e519825f..d420fab2e25 100644 --- a/wpilibc/src/main/native/include/wpi/hardware/rotation/DutyCycle.hpp +++ b/wpilibc/src/main/native/include/wpi/hardware/rotation/DutyCycle.hpp @@ -39,7 +39,7 @@ class DutyCycle : public wpi::telemetry::TelemetryLoggable { * * @return frequency */ - wpi::units::hertz_t GetFrequency() const; + wpi::units::hertz<> GetFrequency() const; /** * Get the output ratio of the duty cycle signal. @@ -55,7 +55,7 @@ class DutyCycle : public wpi::telemetry::TelemetryLoggable { * * @return high time of last pulse */ - wpi::units::second_t GetHighTime() const; + wpi::units::seconds<> GetHighTime() const; /** * Get the channel of the source. diff --git a/wpilibc/src/main/native/include/wpi/hardware/rotation/DutyCycleEncoder.hpp b/wpilibc/src/main/native/include/wpi/hardware/rotation/DutyCycleEncoder.hpp index 753c55098bf..fb2116c1d64 100644 --- a/wpilibc/src/main/native/include/wpi/hardware/rotation/DutyCycleEncoder.hpp +++ b/wpilibc/src/main/native/include/wpi/hardware/rotation/DutyCycleEncoder.hpp @@ -104,7 +104,7 @@ class DutyCycleEncoder : public wpi::telemetry::TelemetryLoggable { * * @return duty cycle frequency */ - wpi::units::hertz_t GetFrequency() const; + wpi::units::hertz<> GetFrequency() const; /** * Get if the sensor is connected @@ -123,7 +123,7 @@ class DutyCycleEncoder : public wpi::telemetry::TelemetryLoggable { * * @param frequency the minimum frequency. */ - void SetConnectedFrequencyThreshold(wpi::units::hertz_t frequency); + void SetConnectedFrequencyThreshold(wpi::units::hertz<> frequency); /** * Get the encoder value. @@ -158,7 +158,7 @@ class DutyCycleEncoder : public wpi::telemetry::TelemetryLoggable { * * @param frequency the assumed frequency of the sensor */ - void SetAssumedFrequency(wpi::units::hertz_t frequency); + void SetAssumedFrequency(wpi::units::hertz<> frequency); /** * Set if this encoder is inverted. @@ -183,10 +183,10 @@ class DutyCycleEncoder : public wpi::telemetry::TelemetryLoggable { double MapSensorRange(double pos) const; std::shared_ptr m_dutyCycle; - wpi::units::hertz_t m_frequencyThreshold = {100_Hz}; + wpi::units::hertz<> m_frequencyThreshold = {100_Hz}; double m_fullRange; double m_expectedZero; - wpi::units::second_t m_period{0_s}; + wpi::units::seconds<> m_period{0_s}; double m_sensorMin{0.0}; double m_sensorMax{1.0}; bool m_isInverted{false}; diff --git a/wpilibc/src/main/native/include/wpi/hardware/rotation/Encoder.hpp b/wpilibc/src/main/native/include/wpi/hardware/rotation/Encoder.hpp index c7262f28825..a32bab85baf 100644 --- a/wpilibc/src/main/native/include/wpi/hardware/rotation/Encoder.hpp +++ b/wpilibc/src/main/native/include/wpi/hardware/rotation/Encoder.hpp @@ -133,7 +133,7 @@ class Encoder : public CounterBase, public wpi::telemetry::TelemetryLoggable { * @param window The rate calculation window. Valid values are 5 ms through * 255 ms. The default is 50 ms. */ - void SetRateWindow(wpi::units::millisecond_t window); + void SetRateWindow(wpi::units::milliseconds<> window); /** * Set the distance per pulse for this encoder. diff --git a/wpilibc/src/main/native/include/wpi/internal/PeriodicPriorityQueue.hpp b/wpilibc/src/main/native/include/wpi/internal/PeriodicPriorityQueue.hpp index 23422445df8..a7baed1518c 100644 --- a/wpilibc/src/main/native/include/wpi/internal/PeriodicPriorityQueue.hpp +++ b/wpilibc/src/main/native/include/wpi/internal/PeriodicPriorityQueue.hpp @@ -74,7 +74,7 @@ class PeriodicPriorityQueue { * @param offset The offset from the common starting time. */ Callback(std::function func, std::chrono::nanoseconds startTime, - wpi::units::second_t period, wpi::units::second_t offset); + wpi::units::seconds<> period, wpi::units::seconds<> offset); /** * Construct a callback container using units-based period. @@ -84,7 +84,7 @@ class PeriodicPriorityQueue { * @param period The period at which to run the callback. */ Callback(std::function func, std::chrono::nanoseconds startTime, - wpi::units::second_t period); + wpi::units::seconds<> period); bool operator>(const Callback& rhs) const { if (expirationTime == rhs.expirationTime) { @@ -126,7 +126,7 @@ class PeriodicPriorityQueue { * @param period The period at which to run the callback. */ void Add(std::function func, std::chrono::nanoseconds startTime, - wpi::units::second_t period); + wpi::units::seconds<> period); /** * Adds a periodic callback to the queue. @@ -138,7 +138,7 @@ class PeriodicPriorityQueue { * @param offset The offset from the common starting time. */ void Add(std::function func, std::chrono::nanoseconds startTime, - wpi::units::second_t period, wpi::units::second_t offset); + wpi::units::seconds<> period, wpi::units::seconds<> offset); /** * Adds a pre-constructed callback to the queue. @@ -201,13 +201,13 @@ class PeriodicPriorityQueue { * @return Robot running time in nanoseconds, as of the start of the current * periodic function. */ - wpi::units::nanosecond_t GetLoopStartTime() const { return m_loopStartTime; } + wpi::units::nanoseconds<> GetLoopStartTime() const { return m_loopStartTime; } private: wpi::util::priority_queue, std::greater<>> m_queue; - wpi::units::nanosecond_t m_loopStartTime{0}; + wpi::units::nanoseconds<> m_loopStartTime{0}; }; } // namespace wpi::internal diff --git a/wpilibc/src/main/native/include/wpi/opmode/PeriodicOpMode.hpp b/wpilibc/src/main/native/include/wpi/opmode/PeriodicOpMode.hpp index f51da7941c1..f6cd64e00cf 100644 --- a/wpilibc/src/main/native/include/wpi/opmode/PeriodicOpMode.hpp +++ b/wpilibc/src/main/native/include/wpi/opmode/PeriodicOpMode.hpp @@ -101,7 +101,7 @@ class PeriodicOpMode : public OpMode { * @param period The period at which to run the callback. */ void AddPeriodic(std::function callback, - wpi::units::second_t period) { + wpi::units::seconds<> period) { AddPeriodic(std::move(callback), period, period); } @@ -117,8 +117,8 @@ class PeriodicOpMode : public OpMode { * for scheduling a callback in a different timeslot relative * to TimedRobot. */ - void AddPeriodic(std::function callback, wpi::units::second_t period, - wpi::units::second_t offset); + void AddPeriodic(std::function callback, wpi::units::seconds<> period, + wpi::units::seconds<> offset); private: std::vector m_callbacks; diff --git a/wpilibc/src/main/native/include/wpi/simulation/BatterySim.hpp b/wpilibc/src/main/native/include/wpi/simulation/BatterySim.hpp index 65175b21395..a51446561b8 100644 --- a/wpilibc/src/main/native/include/wpi/simulation/BatterySim.hpp +++ b/wpilibc/src/main/native/include/wpi/simulation/BatterySim.hpp @@ -31,9 +31,9 @@ class BatterySim { * @param currents The currents drawn from the battery. * @return The battery's voltage under load. */ - static wpi::units::volt_t Calculate( - wpi::units::volt_t nominalVoltage, wpi::units::ohm_t resistance, - std::span currents) { + static wpi::units::volts<> Calculate( + wpi::units::volts<> nominalVoltage, wpi::units::ohms<> resistance, + std::span> currents) { return std::max(0_V, nominalVoltage - std::accumulate(currents.begin(), currents.end(), 0_A) * resistance); @@ -51,9 +51,9 @@ class BatterySim { * @param currents The currents drawn from the battery. * @return The battery's voltage under load. */ - static wpi::units::volt_t Calculate( - wpi::units::volt_t nominalVoltage, wpi::units::ohm_t resistance, - std::initializer_list currents) { + static wpi::units::volts<> Calculate( + wpi::units::volts<> nominalVoltage, wpi::units::ohms<> resistance, + std::initializer_list> currents) { return std::max(0_V, nominalVoltage - std::accumulate(currents.begin(), currents.end(), 0_A) * resistance); @@ -69,8 +69,8 @@ class BatterySim { * @param currents The currents drawn from the battery. * @return The battery's voltage under load. */ - static wpi::units::volt_t Calculate( - std::span currents) { + static wpi::units::volts<> Calculate( + std::span> currents) { return Calculate(12_V, 0.02_Ohm, currents); } @@ -84,8 +84,8 @@ class BatterySim { * @param currents The currents drawn from the battery. * @return The battery's voltage under load. */ - static wpi::units::volt_t Calculate( - std::initializer_list currents) { + static wpi::units::volts<> Calculate( + std::initializer_list> currents) { return Calculate(12_V, 0.02_Ohm, currents); } }; diff --git a/wpilibc/src/main/native/include/wpi/simulation/DCMotorSim.hpp b/wpilibc/src/main/native/include/wpi/simulation/DCMotorSim.hpp index f94d383d3d9..454c3ab704e 100644 --- a/wpilibc/src/main/native/include/wpi/simulation/DCMotorSim.hpp +++ b/wpilibc/src/main/native/include/wpi/simulation/DCMotorSim.hpp @@ -41,71 +41,71 @@ class DCMotorSim : public LinearSystemSim<2, 1, 2> { * @param angularPosition The new position * @param angularVelocity The new velocity */ - void SetState(wpi::units::radian_t angularPosition, - wpi::units::radians_per_second_t angularVelocity); + void SetState(wpi::units::radians<> angularPosition, + wpi::units::radians_per_second<> angularVelocity); /** * Sets the DC motor's angular position. * * @param angularPosition The new position in radians. */ - void SetAngle(wpi::units::radian_t angularPosition); + void SetAngle(wpi::units::radians<> angularPosition); /** * Sets the DC motor's angular velocity. * * @param angularVelocity The new velocity in radians per second. */ - void SetAngularVelocity(wpi::units::radians_per_second_t angularVelocity); + void SetAngularVelocity(wpi::units::radians_per_second<> angularVelocity); /** * Returns the DC motor position. * * @return The DC motor position. */ - wpi::units::radian_t GetAngularPosition() const; + wpi::units::radians<> GetAngularPosition() const; /** * Returns the DC motor velocity. * * @return The DC motor velocity. */ - wpi::units::radians_per_second_t GetAngularVelocity() const; + wpi::units::radians_per_second<> GetAngularVelocity() const; /** * Returns the DC motor acceleration. * * @return The DC motor acceleration */ - wpi::units::radians_per_second_squared_t GetAngularAcceleration() const; + wpi::units::radians_per_second_squared<> GetAngularAcceleration() const; /** * Returns the DC motor torque. * * @return The DC motor torque */ - wpi::units::newton_meter_t GetTorque() const; + wpi::units::newton_meters<> GetTorque() const; /** * Returns the DC motor current draw. * * @return The DC motor current draw. */ - wpi::units::ampere_t GetCurrentDraw() const; + wpi::units::amperes<> GetCurrentDraw() const; /** * Gets the input voltage for the DC motor. * * @return The DC motor input voltage. */ - wpi::units::volt_t GetInputVoltage() const; + wpi::units::volts<> GetInputVoltage() const; /** * Sets the input voltage for the DC motor. * * @param voltage The input voltage. */ - void SetInputVoltage(wpi::units::volt_t voltage); + void SetInputVoltage(wpi::units::volts<> voltage); /** * Returns the gearbox. @@ -120,11 +120,11 @@ class DCMotorSim : public LinearSystemSim<2, 1, 2> { /** * Returns the moment of inertia */ - wpi::units::kilogram_square_meter_t GetJ() const; + wpi::units::kilogram_square_meters<> GetJ() const; private: wpi::math::DCMotor m_gearbox; double m_gearing; - wpi::units::kilogram_square_meter_t m_j; + wpi::units::kilogram_square_meters<> m_j; }; } // namespace wpi::sim diff --git a/wpilibc/src/main/native/include/wpi/simulation/DifferentialDrivetrainSim.hpp b/wpilibc/src/main/native/include/wpi/simulation/DifferentialDrivetrainSim.hpp index 305fb8e00f8..7350720ed82 100644 --- a/wpilibc/src/main/native/include/wpi/simulation/DifferentialDrivetrainSim.hpp +++ b/wpilibc/src/main/native/include/wpi/simulation/DifferentialDrivetrainSim.hpp @@ -41,9 +41,9 @@ class DifferentialDrivetrainSim { * reasonable starting point. */ DifferentialDrivetrainSim( - wpi::math::LinearSystem<2, 2, 2> plant, wpi::units::meter_t trackwidth, + wpi::math::LinearSystem<2, 2, 2> plant, wpi::units::meters<> trackwidth, wpi::math::DCMotor driveMotor, double gearingRatio, - wpi::units::meter_t wheelRadius, + wpi::units::meters<> wheelRadius, const std::array& measurementStdDevs = {}); /** @@ -68,8 +68,8 @@ class DifferentialDrivetrainSim { */ DifferentialDrivetrainSim( 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, + wpi::units::kilogram_square_meters<> J, wpi::units::kilograms<> mass, + wpi::units::meters<> wheelRadius, wpi::units::meters<> trackwidth, const std::array& measurementStdDevs = {}); /** @@ -88,8 +88,8 @@ class DifferentialDrivetrainSim { * @param leftVoltage The left voltage. * @param rightVoltage The right voltage. */ - void SetInputs(wpi::units::volt_t leftVoltage, - wpi::units::volt_t rightVoltage); + void SetInputs(wpi::units::volts<> leftVoltage, + wpi::units::volts<> rightVoltage); /** * Sets the gearing reduction on the drivetrain. This is commonly used for @@ -103,9 +103,9 @@ class DifferentialDrivetrainSim { * Updates the simulation. * * @param dt The time that's passed since the last - * Update(wpi::units::second_t) call. + * Update(wpi::units::seconds<>) call. */ - void Update(wpi::units::second_t dt); + void Update(wpi::units::seconds<> dt); /** * Returns the current gearing reduction of the drivetrain, as output over @@ -143,48 +143,48 @@ class DifferentialDrivetrainSim { * Get the right encoder position in meters. * @return The encoder position. */ - wpi::units::meter_t GetRightPosition() const { - return wpi::units::meter_t{GetOutput(State::RIGHT_POSITION)}; + wpi::units::meters<> GetRightPosition() const { + return wpi::units::meters<>{GetOutput(State::RIGHT_POSITION)}; } /** * Get the right encoder velocity in meters per second. * @return The encoder velocity. */ - wpi::units::meters_per_second_t GetRightVelocity() const { - return wpi::units::meters_per_second_t{GetOutput(State::RIGHT_VELOCITY)}; + wpi::units::meters_per_second<> GetRightVelocity() const { + return wpi::units::meters_per_second<>{GetOutput(State::RIGHT_VELOCITY)}; } /** * Get the left encoder position in meters. * @return The encoder position. */ - wpi::units::meter_t GetLeftPosition() const { - return wpi::units::meter_t{GetOutput(State::LEFT_POSITION)}; + wpi::units::meters<> GetLeftPosition() const { + return wpi::units::meters<>{GetOutput(State::LEFT_POSITION)}; } /** * Get the left encoder velocity in meters per second. * @return The encoder velocity. */ - wpi::units::meters_per_second_t GetLeftVelocity() const { - return wpi::units::meters_per_second_t{GetOutput(State::LEFT_VELOCITY)}; + wpi::units::meters_per_second<> GetLeftVelocity() const { + return wpi::units::meters_per_second<>{GetOutput(State::LEFT_VELOCITY)}; } /** * Returns the currently drawn current for the right side. */ - wpi::units::ampere_t GetRightCurrentDraw() const; + wpi::units::amperes<> GetRightCurrentDraw() const; /** * Returns the currently drawn current for the left side. */ - wpi::units::ampere_t GetLeftCurrentDraw() const; + wpi::units::amperes<> GetLeftCurrentDraw() const; /** * Returns the currently drawn current. */ - wpi::units::ampere_t GetCurrentDraw() const; + wpi::units::amperes<> GetCurrentDraw() const; /** * Sets the system state. @@ -280,11 +280,11 @@ class DifferentialDrivetrainSim { class KitbotWheelSize { public: /// Six inch diameter wheels. - static constexpr wpi::units::meter_t SIX_INCH = 6_in; + static constexpr wpi::units::meters<> SIX_INCH = 6_in; /// Eight inch diameter wheels. - static constexpr wpi::units::meter_t EIGHT_INCH = 8_in; + static constexpr wpi::units::meters<> EIGHT_INCH = 8_in; /// Ten inch diameter wheels. - static constexpr wpi::units::meter_t TEN_INCH = 10_in; + static constexpr wpi::units::meters<> TEN_INCH = 10_in; }; /** @@ -301,11 +301,11 @@ class DifferentialDrivetrainSim { * starting point. */ static DifferentialDrivetrainSim CreateKitbotSim( - wpi::math::DCMotor motor, double gearing, wpi::units::meter_t wheelSize, + wpi::math::DCMotor motor, double gearing, wpi::units::meters<> wheelSize, const std::array& measurementStdDevs = {}) { // MOI estimation -- note that I = mr² for point masses - wpi::units::kilogram_square_meter_t batteryMoi = 12.5_lb * 10_in * 10_in; - wpi::units::kilogram_square_meter_t gearboxMoi = + wpi::units::kilogram_square_meters<> batteryMoi = 12.5_lb * 10_in * 10_in; + wpi::units::kilogram_square_meters<> gearboxMoi = (2.8_lb + 2.0_lb) * 2 // CIM plus toughbox per side * (26_in / 2) * (26_in / 2); @@ -330,8 +330,8 @@ class DifferentialDrivetrainSim { * starting point. */ static DifferentialDrivetrainSim CreateKitbotSim( - wpi::math::DCMotor motor, double gearing, wpi::units::meter_t wheelSize, - wpi::units::kilogram_square_meter_t J, + wpi::math::DCMotor motor, double gearing, wpi::units::meters<> wheelSize, + wpi::units::kilogram_square_meters<> J, const std::array& measurementStdDevs = {}) { return DifferentialDrivetrainSim{ motor, gearing, J, 60_lb, wheelSize / 2.0, 26_in, measurementStdDevs}; @@ -351,8 +351,8 @@ class DifferentialDrivetrainSim { wpi::math::Vectord<7> GetOutput() const; wpi::math::LinearSystem<2, 2, 2> m_plant; - wpi::units::meter_t m_rb; - wpi::units::meter_t m_wheelRadius; + wpi::units::meters<> m_rb; + wpi::units::meters<> m_wheelRadius; wpi::math::DCMotor m_motor; diff --git a/wpilibc/src/main/native/include/wpi/simulation/DutyCycleSim.hpp b/wpilibc/src/main/native/include/wpi/simulation/DutyCycleSim.hpp index 49293ffc850..61e53696216 100644 --- a/wpilibc/src/main/native/include/wpi/simulation/DutyCycleSim.hpp +++ b/wpilibc/src/main/native/include/wpi/simulation/DutyCycleSim.hpp @@ -76,14 +76,14 @@ class DutyCycleSim { * * @return the duty cycle frequency */ - wpi::units::hertz_t GetFrequency() const; + wpi::units::hertz<> GetFrequency() const; /** * Change the duty cycle frequency. * * @param frequency the new frequency */ - void SetFrequency(wpi::units::hertz_t frequency); + void SetFrequency(wpi::units::hertz<> frequency); /** * Register a callback to be run whenever the output changes. diff --git a/wpilibc/src/main/native/include/wpi/simulation/ElevatorSim.hpp b/wpilibc/src/main/native/include/wpi/simulation/ElevatorSim.hpp index 02b6d362c3a..41605499830 100644 --- a/wpilibc/src/main/native/include/wpi/simulation/ElevatorSim.hpp +++ b/wpilibc/src/main/native/include/wpi/simulation/ElevatorSim.hpp @@ -19,14 +19,15 @@ namespace wpi::sim { class ElevatorSim : public LinearSystemSim<2, 1, 2> { public: template - using Velocity_t = wpi::units::unit_t>>; + using Velocity_t = wpi::units::unit>>; template - using Acceleration_t = wpi::units::unit_t>, - wpi::units::inverse>>; + using Acceleration_t = + wpi::units::unit>, + wpi::units::inverse>>; /** * Constructs a simulated elevator mechanism. @@ -41,9 +42,9 @@ class ElevatorSim : public LinearSystemSim<2, 1, 2> { * @param measurementStdDevs The standard deviation of the measurements. */ 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 wpi::math::DCMotor& gearbox, wpi::units::meters<> minHeight, + wpi::units::meters<> maxHeight, bool simulateGravity, + wpi::units::meters<> startingHeight, const std::array& measurementStdDevs = {0.0, 0.0}); /** @@ -61,10 +62,10 @@ class ElevatorSim : public LinearSystemSim<2, 1, 2> { * @param measurementStdDevs The standard deviation of the measurements. */ 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, + wpi::units::kilograms<> carriageMass, + wpi::units::meters<> drumRadius, wpi::units::meters<> minHeight, + wpi::units::meters<> maxHeight, bool simulateGravity, + wpi::units::meters<> startingHeight, const std::array& measurementStdDevs = {0.0, 0.0}); /** @@ -80,13 +81,13 @@ class ElevatorSim : public LinearSystemSim<2, 1, 2> { * @param measurementStdDevs The standard deviation of the measurements. */ template - requires std::same_as || - std::same_as + requires std::same_as || + std::same_as ElevatorSim(decltype(1_V / Velocity_t(1)) kV, decltype(1_V / Acceleration_t(1)) kA, - const wpi::math::DCMotor& gearbox, wpi::units::meter_t minHeight, - wpi::units::meter_t maxHeight, bool simulateGravity, - wpi::units::meter_t startingHeight, + const wpi::math::DCMotor& gearbox, wpi::units::meters<> minHeight, + wpi::units::meters<> maxHeight, bool simulateGravity, + wpi::units::meters<> startingHeight, const std::array& measurementStdDevs = {0.0, 0.0}); using LinearSystemSim::SetState; @@ -97,8 +98,8 @@ class ElevatorSim : public LinearSystemSim<2, 1, 2> { * @param position The new position * @param velocity The new velocity */ - void SetState(wpi::units::meter_t position, - wpi::units::meters_per_second_t velocity); + void SetState(wpi::units::meters<> position, + wpi::units::meters_per_second<> velocity); /** * Returns whether the elevator would hit the lower limit. @@ -106,7 +107,7 @@ class ElevatorSim : public LinearSystemSim<2, 1, 2> { * @param elevatorHeight The elevator height. * @return Whether the elevator would hit the lower limit. */ - bool WouldHitLowerLimit(wpi::units::meter_t elevatorHeight) const; + bool WouldHitLowerLimit(wpi::units::meters<> elevatorHeight) const; /** * Returns whether the elevator would hit the upper limit. @@ -114,7 +115,7 @@ class ElevatorSim : public LinearSystemSim<2, 1, 2> { * @param elevatorHeight The elevator height. * @return Whether the elevator would hit the upper limit. */ - bool WouldHitUpperLimit(wpi::units::meter_t elevatorHeight) const; + bool WouldHitUpperLimit(wpi::units::meters<> elevatorHeight) const; /** * Returns whether the elevator has hit the lower limit. @@ -135,28 +136,28 @@ class ElevatorSim : public LinearSystemSim<2, 1, 2> { * * @return The position of the elevator. */ - wpi::units::meter_t GetPosition() const; + wpi::units::meters<> GetPosition() const; /** * Returns the velocity of the elevator. * * @return The velocity of the elevator. */ - wpi::units::meters_per_second_t GetVelocity() const; + wpi::units::meters_per_second<> GetVelocity() const; /** * Returns the elevator current draw. * * @return The elevator current draw. */ - wpi::units::ampere_t GetCurrentDraw() const; + wpi::units::amperes<> GetCurrentDraw() const; /** * Sets the input voltage for the elevator. * * @param voltage The input voltage. */ - void SetInputVoltage(wpi::units::volt_t voltage); + void SetInputVoltage(wpi::units::volts<> voltage); protected: /** @@ -168,12 +169,12 @@ class ElevatorSim : public LinearSystemSim<2, 1, 2> { */ wpi::math::Vectord<2> UpdateX(const wpi::math::Vectord<2>& currentXhat, const wpi::math::Vectord<1>& u, - wpi::units::second_t dt) override; + wpi::units::seconds<> dt) override; private: wpi::math::DCMotor m_gearbox; - wpi::units::meter_t m_minHeight; - wpi::units::meter_t m_maxHeight; + wpi::units::meters<> m_minHeight; + wpi::units::meters<> m_maxHeight; bool m_simulateGravity; }; } // namespace wpi::sim diff --git a/wpilibc/src/main/native/include/wpi/simulation/FlywheelSim.hpp b/wpilibc/src/main/native/include/wpi/simulation/FlywheelSim.hpp index e8f7a1bf048..878607663cb 100644 --- a/wpilibc/src/main/native/include/wpi/simulation/FlywheelSim.hpp +++ b/wpilibc/src/main/native/include/wpi/simulation/FlywheelSim.hpp @@ -38,49 +38,49 @@ class FlywheelSim : public LinearSystemSim<1, 1, 1> { * * @param velocity The new velocity */ - void SetVelocity(wpi::units::radians_per_second_t velocity); + void SetVelocity(wpi::units::radians_per_second<> velocity); /** * Returns the flywheel's velocity. * * @return The flywheel's velocity. */ - wpi::units::radians_per_second_t GetAngularVelocity() const; + wpi::units::radians_per_second<> GetAngularVelocity() const; /** * Returns the flywheel's acceleration. * * @return The flywheel's acceleration */ - wpi::units::radians_per_second_squared_t GetAngularAcceleration() const; + wpi::units::radians_per_second_squared<> GetAngularAcceleration() const; /** * Returns the flywheel's torque. * * @return The flywheel's torque */ - wpi::units::newton_meter_t GetTorque() const; + wpi::units::newton_meters<> GetTorque() const; /** * Returns the flywheel's current draw. * * @return The flywheel's current draw. */ - wpi::units::ampere_t GetCurrentDraw() const; + wpi::units::amperes<> GetCurrentDraw() const; /** * Gets the input voltage for the flywheel. * * @return The flywheel input voltage. */ - wpi::units::volt_t GetInputVoltage() const; + wpi::units::volts<> GetInputVoltage() const; /** * Sets the input voltage for the flywheel. * * @param voltage The input voltage. */ - void SetInputVoltage(wpi::units::volt_t voltage); + void SetInputVoltage(wpi::units::volts<> voltage); /** * Returns the gearbox. @@ -95,11 +95,11 @@ class FlywheelSim : public LinearSystemSim<1, 1, 1> { /** * Returns the moment of inertia */ - wpi::units::kilogram_square_meter_t J() const { return m_j; } + wpi::units::kilogram_square_meters<> J() const { return m_j; } private: wpi::math::DCMotor m_gearbox; double m_gearing; - wpi::units::kilogram_square_meter_t m_j; + wpi::units::kilogram_square_meters<> m_j; }; } // namespace wpi::sim diff --git a/wpilibc/src/main/native/include/wpi/simulation/LinearSystemSim.hpp b/wpilibc/src/main/native/include/wpi/simulation/LinearSystemSim.hpp index 55a97c2e0d5..ea11866d744 100644 --- a/wpilibc/src/main/native/include/wpi/simulation/LinearSystemSim.hpp +++ b/wpilibc/src/main/native/include/wpi/simulation/LinearSystemSim.hpp @@ -50,7 +50,7 @@ class LinearSystemSim { * * @param dt The time between updates. */ - void Update(wpi::units::second_t dt) { + void Update(wpi::units::seconds<> dt) { // Update x. By default, this is the linear system dynamics xₖ₊₁ = Axₖ + // Buₖ. m_x = UpdateX(m_x, m_u, dt); @@ -133,7 +133,7 @@ class LinearSystemSim { */ virtual wpi::math::Vectord UpdateX( const wpi::math::Vectord& currentXhat, - const wpi::math::Vectord& u, wpi::units::second_t dt) { + const wpi::math::Vectord& u, wpi::units::seconds<> dt) { return m_plant.CalculateX(currentXhat, u, dt); } diff --git a/wpilibc/src/main/native/include/wpi/simulation/OnboardIMUSim.hpp b/wpilibc/src/main/native/include/wpi/simulation/OnboardIMUSim.hpp index a17eafd2a65..71491dabf0f 100644 --- a/wpilibc/src/main/native/include/wpi/simulation/OnboardIMUSim.hpp +++ b/wpilibc/src/main/native/include/wpi/simulation/OnboardIMUSim.hpp @@ -12,19 +12,19 @@ namespace wpi::sim { class OnboardIMUSim { public: - void SetAngleX(wpi::units::radian_t angle); - void SetAngleY(wpi::units::radian_t angle); - void SetAngleZ(wpi::units::radian_t angle); + void SetAngleX(wpi::units::radians<> angle); + void SetAngleY(wpi::units::radians<> angle); + void SetAngleZ(wpi::units::radians<> angle); - void SetGyroRateX(wpi::units::radians_per_second_t rate); - void SetGyroRateY(wpi::units::radians_per_second_t rate); - void SetGyroRateZ(wpi::units::radians_per_second_t rate); + void SetGyroRateX(wpi::units::radians_per_second<> rate); + void SetGyroRateY(wpi::units::radians_per_second<> rate); + void SetGyroRateZ(wpi::units::radians_per_second<> rate); - void SetAccelX(wpi::units::meters_per_second_squared_t accel); - void SetAccelY(wpi::units::meters_per_second_squared_t accel); - void SetAccelZ(wpi::units::meters_per_second_squared_t accel); + void SetAccelX(wpi::units::meters_per_second_squared<> accel); + void SetAccelY(wpi::units::meters_per_second_squared<> accel); + void SetAccelZ(wpi::units::meters_per_second_squared<> accel); - void SetYaw(wpi::units::radian_t angle); + void SetYaw(wpi::units::radians<> angle); }; } // namespace wpi::sim diff --git a/wpilibc/src/main/native/include/wpi/simulation/RoboRioSim.hpp b/wpilibc/src/main/native/include/wpi/simulation/RoboRioSim.hpp index 5069dc7d3ce..bbb54bc059b 100644 --- a/wpilibc/src/main/native/include/wpi/simulation/RoboRioSim.hpp +++ b/wpilibc/src/main/native/include/wpi/simulation/RoboRioSim.hpp @@ -36,14 +36,14 @@ class RoboRioSim { * * @return the Vin voltage */ - static wpi::units::volt_t GetVInVoltage(); + static wpi::units::volts<> GetVInVoltage(); /** * Define the Vin voltage. * * @param vInVoltage the new voltage */ - static void SetVInVoltage(wpi::units::volt_t vInVoltage); + static void SetVInVoltage(wpi::units::volts<> vInVoltage); /** * Register a callback to be run whenever the 3.3V rail voltage changes. @@ -62,14 +62,14 @@ class RoboRioSim { * * @return the 3.3V rail voltage */ - static wpi::units::volt_t GetUserVoltage3V3(); + static wpi::units::volts<> GetUserVoltage3V3(); /** * Define the 3.3V rail voltage. * * @param userVoltage3V3 the new voltage */ - static void SetUserVoltage3V3(wpi::units::volt_t userVoltage3V3); + static void SetUserVoltage3V3(wpi::units::volts<> userVoltage3V3); /** * Register a callback to be run whenever the 3.3V rail current changes. @@ -88,14 +88,14 @@ class RoboRioSim { * * @return the 3.3V rail current */ - static wpi::units::ampere_t GetUserCurrent3V3(); + static wpi::units::amperes<> GetUserCurrent3V3(); /** * Define the 3.3V rail current. * * @param userCurrent3V3 the new current */ - static void SetUserCurrent3V3(wpi::units::ampere_t userCurrent3V3); + static void SetUserCurrent3V3(wpi::units::amperes<> userCurrent3V3); /** * Register a callback to be run whenever the 3.3V rail active state changes. @@ -166,14 +166,14 @@ class RoboRioSim { * * @return the brownout voltage */ - static wpi::units::volt_t GetBrownoutVoltage(); + static wpi::units::volts<> GetBrownoutVoltage(); /** * Define the brownout voltage. * * @param brownoutVoltage the new voltage */ - static void SetBrownoutVoltage(wpi::units::volt_t brownoutVoltage); + static void SetBrownoutVoltage(wpi::units::volts<> brownoutVoltage); /** * Register a callback to be run whenever the brownout recovery voltage @@ -192,7 +192,7 @@ class RoboRioSim { * * @return the brownout recovery voltage */ - static wpi::units::volt_t GetBrownoutRecoveryVoltage(); + static wpi::units::volts<> GetBrownoutRecoveryVoltage(); /** * Define the brownout recovery voltage. @@ -200,7 +200,7 @@ class RoboRioSim { * @param brownoutRecoveryVoltage the new voltage */ static void SetBrownoutRecoveryVoltage( - wpi::units::volt_t brownoutRecoveryVoltage); + wpi::units::volts<> brownoutRecoveryVoltage); /** * Register a callback to be run whenever the cpu temp changes. @@ -218,14 +218,14 @@ class RoboRioSim { * * @return the cpu temp. */ - static wpi::units::celsius_t GetCPUTemp(); + static wpi::units::celsius<> GetCPUTemp(); /** * Define the cpu temp. * * @param cpuTemp the new cpu temp. */ - static void SetCPUTemp(wpi::units::celsius_t cpuTemp); + static void SetCPUTemp(wpi::units::celsius<> cpuTemp); /** * Register a callback to be run whenever the team number changes. diff --git a/wpilibc/src/main/native/include/wpi/simulation/SharpIRSim.hpp b/wpilibc/src/main/native/include/wpi/simulation/SharpIRSim.hpp index de3a7fd6465..1b98d62b2cb 100644 --- a/wpilibc/src/main/native/include/wpi/simulation/SharpIRSim.hpp +++ b/wpilibc/src/main/native/include/wpi/simulation/SharpIRSim.hpp @@ -32,7 +32,7 @@ class SharpIRSim { * * @param range range of the target returned by the sensor */ - void SetRange(wpi::units::meter_t range); + void SetRange(wpi::units::meters<> range); private: wpi::hal::SimDouble m_simRange; diff --git a/wpilibc/src/main/native/include/wpi/simulation/SimHooks.hpp b/wpilibc/src/main/native/include/wpi/simulation/SimHooks.hpp index 3888b742558..0af3ca6e317 100644 --- a/wpilibc/src/main/native/include/wpi/simulation/SimHooks.hpp +++ b/wpilibc/src/main/native/include/wpi/simulation/SimHooks.hpp @@ -81,13 +81,13 @@ bool IsTimingPaused(); * * @param delta the amount to advance (in seconds) */ -void StepTiming(wpi::units::second_t delta); +void StepTiming(wpi::units::seconds<> delta); /** * Advance the simulator time and return immediately. * * @param delta the amount to advance (in seconds) */ -void StepTimingAsync(wpi::units::second_t delta); +void StepTimingAsync(wpi::units::seconds<> delta); } // namespace wpi::sim diff --git a/wpilibc/src/main/native/include/wpi/simulation/SingleJointedArmSim.hpp b/wpilibc/src/main/native/include/wpi/simulation/SingleJointedArmSim.hpp index 52837268916..6005c902951 100644 --- a/wpilibc/src/main/native/include/wpi/simulation/SingleJointedArmSim.hpp +++ b/wpilibc/src/main/native/include/wpi/simulation/SingleJointedArmSim.hpp @@ -38,10 +38,10 @@ class SingleJointedArmSim : public LinearSystemSim<2, 1, 2> { */ SingleJointedArmSim(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, + wpi::units::meters<> armLength, + wpi::units::radians<> minAngle, + wpi::units::radians<> maxAngle, bool simulateGravity, + wpi::units::radians<> startingAngle, const std::array& measurementStdDevs = {0.0, 0.0}); /** @@ -63,9 +63,9 @@ class SingleJointedArmSim : public LinearSystemSim<2, 1, 2> { */ SingleJointedArmSim( 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, + wpi::units::kilogram_square_meters<> moi, wpi::units::meters<> armLength, + wpi::units::radians<> minAngle, wpi::units::radians<> maxAngle, + bool simulateGravity, wpi::units::radians<> startingAngle, const std::array& measurementStdDevs = {0.0, 0.0}); using LinearSystemSim::SetState; @@ -77,8 +77,8 @@ class SingleJointedArmSim : public LinearSystemSim<2, 1, 2> { * @param angle The new angle. * @param velocity The new angular velocity. */ - void SetState(wpi::units::radian_t angle, - wpi::units::radians_per_second_t velocity); + void SetState(wpi::units::radians<> angle, + wpi::units::radians_per_second<> velocity); /** * Returns whether the arm would hit the lower limit. @@ -86,7 +86,7 @@ class SingleJointedArmSim : public LinearSystemSim<2, 1, 2> { * @param armAngle The arm height. * @return Whether the arm would hit the lower limit. */ - bool WouldHitLowerLimit(wpi::units::radian_t armAngle) const; + bool WouldHitLowerLimit(wpi::units::radians<> armAngle) const; /** * Returns whether the arm would hit the upper limit. @@ -94,7 +94,7 @@ class SingleJointedArmSim : public LinearSystemSim<2, 1, 2> { * @param armAngle The arm height. * @return Whether the arm would hit the upper limit. */ - bool WouldHitUpperLimit(wpi::units::radian_t armAngle) const; + bool WouldHitUpperLimit(wpi::units::radians<> armAngle) const; /** * Returns whether the arm has hit the lower limit. @@ -115,28 +115,28 @@ class SingleJointedArmSim : public LinearSystemSim<2, 1, 2> { * * @return The current arm angle. */ - wpi::units::radian_t GetAngle() const; + wpi::units::radians<> GetAngle() const; /** * Returns the current arm velocity. * * @return The current arm velocity. */ - wpi::units::radians_per_second_t GetVelocity() const; + wpi::units::radians_per_second<> GetVelocity() const; /** * Returns the arm current draw. * * @return The arm current draw. */ - wpi::units::ampere_t GetCurrentDraw() const; + wpi::units::amperes<> GetCurrentDraw() const; /** * Sets the input voltage for the arm. * * @param voltage The input voltage. */ - void SetInputVoltage(wpi::units::volt_t voltage); + void SetInputVoltage(wpi::units::volts<> voltage); /** * Calculates a rough estimate of the moment of inertia of an arm given its @@ -147,8 +147,8 @@ class SingleJointedArmSim : public LinearSystemSim<2, 1, 2> { * * @return The calculated moment of inertia. */ - static constexpr wpi::units::kilogram_square_meter_t EstimateMOI( - wpi::units::meter_t length, wpi::units::kilogram_t mass) { + static constexpr wpi::units::kilogram_square_meters<> EstimateMOI( + wpi::units::meters<> length, wpi::units::kilograms<> mass) { return 1.0 / 3.0 * mass * length * length; } @@ -162,12 +162,12 @@ class SingleJointedArmSim : public LinearSystemSim<2, 1, 2> { */ wpi::math::Vectord<2> UpdateX(const wpi::math::Vectord<2>& currentXhat, const wpi::math::Vectord<1>& u, - wpi::units::second_t dt) override; + wpi::units::seconds<> dt) override; private: - wpi::units::meter_t m_armLen; - wpi::units::radian_t m_minAngle; - wpi::units::radian_t m_maxAngle; + wpi::units::meters<> m_armLen; + wpi::units::radians<> m_minAngle; + wpi::units::radians<> m_maxAngle; const wpi::math::DCMotor m_gearbox; double m_gearing; bool m_simulateGravity; diff --git a/wpilibc/src/main/native/include/wpi/smartdashboard/Field2d.hpp b/wpilibc/src/main/native/include/wpi/smartdashboard/Field2d.hpp index 4141950cdce..f89d535b0d4 100644 --- a/wpilibc/src/main/native/include/wpi/smartdashboard/Field2d.hpp +++ b/wpilibc/src/main/native/include/wpi/smartdashboard/Field2d.hpp @@ -61,7 +61,7 @@ class Field2d : public wpi::telemetry::TelemetryLoggable, * @param y Y location * @param rotation rotation */ - void SetRobotPose(wpi::units::meter_t x, wpi::units::meter_t y, + void SetRobotPose(wpi::units::meters<> x, wpi::units::meters<> y, wpi::math::Rotation2d rotation); /** diff --git a/wpilibc/src/main/native/include/wpi/smartdashboard/FieldObject2d.hpp b/wpilibc/src/main/native/include/wpi/smartdashboard/FieldObject2d.hpp index 3f6dc260a0a..a6394e33d13 100644 --- a/wpilibc/src/main/native/include/wpi/smartdashboard/FieldObject2d.hpp +++ b/wpilibc/src/main/native/include/wpi/smartdashboard/FieldObject2d.hpp @@ -55,7 +55,7 @@ class FieldObject2d { * @param y Y location * @param rotation rotation */ - void SetPose(wpi::units::meter_t x, wpi::units::meter_t y, + void SetPose(wpi::units::meters<> x, wpi::units::meters<> y, wpi::math::Rotation2d rotation); /** diff --git a/wpilibc/src/main/native/include/wpi/smartdashboard/MechanismLigament2d.hpp b/wpilibc/src/main/native/include/wpi/smartdashboard/MechanismLigament2d.hpp index 2d7b425be92..cd9516b68e8 100644 --- a/wpilibc/src/main/native/include/wpi/smartdashboard/MechanismLigament2d.hpp +++ b/wpilibc/src/main/native/include/wpi/smartdashboard/MechanismLigament2d.hpp @@ -23,7 +23,7 @@ namespace wpi { class MechanismLigament2d : public MechanismObject2d { public: MechanismLigament2d(std::string_view name, double length, - wpi::units::degree_t angle, double lineWidth = 6, + wpi::units::degrees<> angle, double lineWidth = 6, const wpi::util::Color8Bit& color = {235, 137, 52}); /** @@ -59,7 +59,7 @@ class MechanismLigament2d : public MechanismObject2d { * * @param angle the angle */ - void SetAngle(wpi::units::degree_t angle); + void SetAngle(wpi::units::degrees<> angle); /** * Get the ligament's angle relative to its parent. diff --git a/wpilibc/src/main/native/include/wpi/sysid/SysIdRoutineLog.hpp b/wpilibc/src/main/native/include/wpi/sysid/SysIdRoutineLog.hpp index e8f9f16394c..e80da19c87d 100644 --- a/wpilibc/src/main/native/include/wpi/sysid/SysIdRoutineLog.hpp +++ b/wpilibc/src/main/native/include/wpi/sysid/SysIdRoutineLog.hpp @@ -64,7 +64,7 @@ class SysIdRoutineLog { * @param voltage The voltage to record. * @return The motor log (for call chaining). */ - MotorLog& voltage(wpi::units::volt_t voltage) { + MotorLog& voltage(wpi::units::volts<> voltage) { return value("voltage", voltage.value(), voltage.name()); } @@ -74,7 +74,7 @@ class SysIdRoutineLog { * @param position The linear position to record. * @return The motor log (for call chaining). */ - MotorLog& position(wpi::units::meter_t position) { + MotorLog& position(wpi::units::meters<> position) { return value("position", position.value(), position.name()); } @@ -84,7 +84,7 @@ class SysIdRoutineLog { * @param position The angular position to record. * @return The motor log (for call chaining). */ - MotorLog& position(wpi::units::turn_t position) { + MotorLog& position(wpi::units::turns<> position) { return value("position", position.value(), position.name()); } @@ -94,7 +94,7 @@ class SysIdRoutineLog { * @param velocity The linear velocity to record. * @return The motor log (for call chaining). */ - MotorLog& velocity(wpi::units::meters_per_second_t velocity) { + MotorLog& velocity(wpi::units::meters_per_second<> velocity) { return value("velocity", velocity.value(), velocity.name()); } @@ -104,7 +104,7 @@ class SysIdRoutineLog { * @param velocity The angular velocity to record. * @return The motor log (for call chaining). */ - MotorLog& velocity(wpi::units::turns_per_second_t velocity) { + MotorLog& velocity(wpi::units::turns_per_second<> velocity) { return value("velocity", velocity.value(), velocity.name()); } @@ -117,7 +117,7 @@ class SysIdRoutineLog { * @return The motor log (for call chaining). */ MotorLog& acceleration( - wpi::units::meters_per_second_squared_t acceleration) { + wpi::units::meters_per_second_squared<> acceleration) { return value("acceleration", acceleration.value(), acceleration.name()); } @@ -130,7 +130,7 @@ class SysIdRoutineLog { * @return The motor log (for call chaining). */ MotorLog& acceleration( - wpi::units::turns_per_second_squared_t acceleration) { + wpi::units::turns_per_second_squared<> acceleration) { return value("acceleration", acceleration.value(), acceleration.name()); } @@ -142,7 +142,7 @@ class SysIdRoutineLog { * @param current The current to record. * @return The motor log (for call chaining). */ - MotorLog& current(wpi::units::ampere_t current) { + MotorLog& current(wpi::units::amperes<> current) { return value("current", current.value(), current.name()); } diff --git a/wpilibc/src/main/native/include/wpi/system/Notifier.hpp b/wpilibc/src/main/native/include/wpi/system/Notifier.hpp index 169b55750f6..d6cabfeb741 100644 --- a/wpilibc/src/main/native/include/wpi/system/Notifier.hpp +++ b/wpilibc/src/main/native/include/wpi/system/Notifier.hpp @@ -96,7 +96,7 @@ class Notifier { * * @param delay Time to wait before the callback is called. */ - void StartSingle(wpi::units::second_t delay); + void StartSingle(wpi::units::seconds<> delay); /** * Run the callback periodically with the given period. @@ -107,7 +107,7 @@ class Notifier { * @param period Period after which to call the callback starting one * period after the call to this method. */ - void StartPeriodic(wpi::units::second_t period); + void StartPeriodic(wpi::units::seconds<> period); /** * Run the callback periodically with the given frequency. @@ -118,7 +118,7 @@ class Notifier { * @param frequency Frequency after which to call the callback starting one * period after the call to this method. */ - void StartPeriodic(wpi::units::hertz_t frequency); + void StartPeriodic(wpi::units::hertz<> frequency); /** * Stop further callback invocations. diff --git a/wpilibc/src/main/native/include/wpi/system/RobotController.hpp b/wpilibc/src/main/native/include/wpi/system/RobotController.hpp index 6f027c103b1..76a4be80e57 100644 --- a/wpilibc/src/main/native/include/wpi/system/RobotController.hpp +++ b/wpilibc/src/main/native/include/wpi/system/RobotController.hpp @@ -82,7 +82,7 @@ class RobotController { * * @return The battery voltage in Volts. */ - static wpi::units::volt_t GetBatteryVoltage(); + static wpi::units::volts<> GetBatteryVoltage(); /** * Check if the FPGA outputs are enabled. @@ -181,15 +181,15 @@ class RobotController { * @param recoveryVoltage the voltage where the robot will recover from * brownout */ - static void SetBrownoutVoltages(wpi::units::volt_t brownoutVoltage, - wpi::units::volt_t recoveryVoltage); + static void SetBrownoutVoltages(wpi::units::volts<> brownoutVoltage, + wpi::units::volts<> recoveryVoltage); /** * Get the current CPU temperature. * * @return current CPU temperature */ - static wpi::units::celsius_t GetCPUTemp(); + static wpi::units::celsius<> GetCPUTemp(); /** * Get the current status of the CAN bus. diff --git a/wpilibc/src/main/native/include/wpi/system/Timer.hpp b/wpilibc/src/main/native/include/wpi/system/Timer.hpp index 80fd5648f66..2973c6321df 100644 --- a/wpilibc/src/main/native/include/wpi/system/Timer.hpp +++ b/wpilibc/src/main/native/include/wpi/system/Timer.hpp @@ -20,7 +20,7 @@ namespace wpi { * * @param seconds Length of time to pause, in seconds. */ -void Wait(wpi::units::second_t seconds); +void Wait(wpi::units::seconds<> seconds); /** * @brief Gives real-time clock system time with nanosecond resolution @@ -28,7 +28,7 @@ void Wait(wpi::units::second_t seconds); * on Saturday. * @Common This is one of the commonly used methods for this class */ -wpi::units::second_t GetSystemTime(); +wpi::units::seconds<> GetSystemTime(); /** * A timer class. @@ -62,7 +62,7 @@ class Timer { * @return Current time value for this timer in seconds * @Common This is one of the commonly used methods for this class */ - wpi::units::second_t Get() const; + wpi::units::seconds<> Get() const; /** * Reset the timer by setting the time to 0. @@ -112,7 +112,7 @@ class Timer { * @param period The period to check. * @return True if the period has passed. */ - bool HasElapsed(wpi::units::second_t period) const; + bool HasElapsed(wpi::units::seconds<> period) const; /** * Check if the period specified has passed and if it has, advance the start @@ -122,7 +122,7 @@ class Timer { * @param period The period to check for. * @return True if the period has passed. */ - bool AdvanceIfElapsed(wpi::units::second_t period); + bool AdvanceIfElapsed(wpi::units::seconds<> period); /** * Whether the timer is currently running. @@ -151,7 +151,7 @@ class Timer { * * @returns Robot running time in seconds. */ - static wpi::units::second_t GetTimestamp(); + static wpi::units::seconds<> GetTimestamp(); /** * Return the monotonic clock time in seconds. @@ -160,7 +160,7 @@ class Timer { * * @returns Monotonic time in seconds. */ - static wpi::units::second_t GetMonotonicTimestamp(); + static wpi::units::seconds<> GetMonotonicTimestamp(); /** * Return the approximate match time. The FMS does not send an official match @@ -181,7 +181,7 @@ class Timer { * * @return Time remaining in current match period (auto or teleop) in seconds */ - static wpi::units::second_t GetMatchTime(); + static wpi::units::seconds<> GetMatchTime(); private: double GetNanoseconds() const; diff --git a/wpilibc/src/main/native/include/wpi/system/Watchdog.hpp b/wpilibc/src/main/native/include/wpi/system/Watchdog.hpp index 07214eb7cee..c77c47e62bd 100644 --- a/wpilibc/src/main/native/include/wpi/system/Watchdog.hpp +++ b/wpilibc/src/main/native/include/wpi/system/Watchdog.hpp @@ -31,10 +31,10 @@ class Watchdog { * resolution. * @param callback This function is called when the timeout expires. */ - Watchdog(wpi::units::second_t timeout, std::function callback); + Watchdog(wpi::units::seconds<> timeout, std::function callback); template - Watchdog(wpi::units::second_t timeout, Callable&& f, Arg&& arg, + Watchdog(wpi::units::seconds<> timeout, Callable&& f, Arg&& arg, Args&&... args) : Watchdog(timeout, std::bind(std::forward(f), std::forward(arg), @@ -48,7 +48,7 @@ class Watchdog { /** * Returns the time since the watchdog was last fed. */ - wpi::units::second_t GetTime() const; + wpi::units::seconds<> GetTime() const; /** * Sets the watchdog's timeout. @@ -56,12 +56,12 @@ class Watchdog { * @param timeout The watchdog's timeout in seconds with nanosecond * resolution. */ - void SetTimeout(wpi::units::second_t timeout); + void SetTimeout(wpi::units::seconds<> timeout); /** * Returns the watchdog's timeout. */ - wpi::units::second_t GetTimeout() const; + wpi::units::seconds<> GetTimeout() const; /** * Returns true if the watchdog timer has expired. @@ -114,11 +114,11 @@ class Watchdog { // Used for timeout print rate-limiting static constexpr auto MIN_PRINT_PERIOD = 1_s; - wpi::units::second_t m_startTime = 0_s; - wpi::units::second_t m_timeout; - wpi::units::second_t m_expirationTime = 0_s; + wpi::units::seconds<> m_startTime = 0_s; + wpi::units::seconds<> m_timeout; + wpi::units::seconds<> m_expirationTime = 0_s; std::function m_callback; - wpi::units::second_t m_lastTimeoutPrintTime = 0_s; + wpi::units::seconds<> m_lastTimeoutPrintTime = 0_s; Tracer m_tracer; bool m_isExpired = false; diff --git a/wpilibc/src/main/python/semiwrap/Field2d.yml b/wpilibc/src/main/python/semiwrap/Field2d.yml index 5779943b419..e7d2a7e482c 100644 --- a/wpilibc/src/main/python/semiwrap/Field2d.yml +++ b/wpilibc/src/main/python/semiwrap/Field2d.yml @@ -5,7 +5,7 @@ classes: SetRobotPose: overloads: const wpi::math::Pose2d&: - wpi::units::meter_t, wpi::units::meter_t, wpi::math::Rotation2d: + wpi::units::meters<>, wpi::units::meters<>, wpi::math::Rotation2d: GetRobotPose: GetObject: return_value_policy: reference_internal diff --git a/wpilibc/src/main/python/semiwrap/FieldObject2d.yml b/wpilibc/src/main/python/semiwrap/FieldObject2d.yml index acce1b6ee94..8e6f141f4bb 100644 --- a/wpilibc/src/main/python/semiwrap/FieldObject2d.yml +++ b/wpilibc/src/main/python/semiwrap/FieldObject2d.yml @@ -13,7 +13,7 @@ classes: SetPose: overloads: const wpi::math::Pose2d&: - wpi::units::meter_t, wpi::units::meter_t, wpi::math::Rotation2d: + wpi::units::meters<>, wpi::units::meters<>, wpi::math::Rotation2d: GetPose: SetPoses: overloads: diff --git a/wpilibc/src/main/python/semiwrap/IterativeRobotBase.yml b/wpilibc/src/main/python/semiwrap/IterativeRobotBase.yml index bb68d7e31b2..73a31c7896a 100644 --- a/wpilibc/src/main/python/semiwrap/IterativeRobotBase.yml +++ b/wpilibc/src/main/python/semiwrap/IterativeRobotBase.yml @@ -15,7 +15,7 @@ classes: overloads: double: ignore: true - wpi::units::second_t: + wpi::units::seconds<>: LoopFunc: SimulationInit: SimulationPeriodic: diff --git a/wpilibc/src/main/python/semiwrap/Joystick.yml b/wpilibc/src/main/python/semiwrap/Joystick.yml index c634772fa2d..71bdeeeb2c7 100644 --- a/wpilibc/src/main/python/semiwrap/Joystick.yml +++ b/wpilibc/src/main/python/semiwrap/Joystick.yml @@ -56,6 +56,6 @@ classes: GetRawAxis: GetPOV: inline_code: | - .def("get_direction_degrees", [](const Joystick &self) -> wpi::units::degree_t { + .def("get_direction_degrees", [](const Joystick &self) -> wpi::units::degrees<> { return self.GetDirection(); }) diff --git a/wpilibc/src/main/python/semiwrap/LEDPattern.yml b/wpilibc/src/main/python/semiwrap/LEDPattern.yml index f5a0ed6db14..e6729c0c992 100644 --- a/wpilibc/src/main/python/semiwrap/LEDPattern.yml +++ b/wpilibc/src/main/python/semiwrap/LEDPattern.yml @@ -27,8 +27,8 @@ classes: ScrollAtAbsoluteVelocity: Blink: overloads: - wpi::units::second_t, wpi::units::second_t: - wpi::units::second_t: + wpi::units::seconds<>, wpi::units::seconds<>: + wpi::units::seconds<>: SynchronizedBlink: Breathe: OverlayOn: diff --git a/wpilibc/src/main/python/semiwrap/MecanumDrive.yml b/wpilibc/src/main/python/semiwrap/MecanumDrive.yml index b9b57a0ea1e..744a0cd0e11 100644 --- a/wpilibc/src/main/python/semiwrap/MecanumDrive.yml +++ b/wpilibc/src/main/python/semiwrap/MecanumDrive.yml @@ -4,7 +4,7 @@ extra_includes: classes: wpi::MecanumDrive: force_type_casters: - - wpi::units::radian_t + - wpi::units::radians<> methods: MecanumDrive: overloads: diff --git a/wpilibc/src/main/python/semiwrap/MechanismObject2d.yml b/wpilibc/src/main/python/semiwrap/MechanismObject2d.yml index 740b2470261..4f2e027f6fc 100644 --- a/wpilibc/src/main/python/semiwrap/MechanismObject2d.yml +++ b/wpilibc/src/main/python/semiwrap/MechanismObject2d.yml @@ -4,7 +4,7 @@ extra_includes: classes: wpi::MechanismObject2d: force_type_casters: - - wpi::units::degree_t + - wpi::units::degrees<> attributes: m_mutex: ignore: true @@ -20,7 +20,7 @@ classes: inline_code: |- cls_MechanismObject2d .def("append_ligament", [](MechanismObject2d *self, - std::string_view name, double length, wpi::units::degree_t angle, + std::string_view name, double length, wpi::units::degrees<> angle, double line_width, const wpi::util::Color8Bit& color) { return self->Append(name, length, angle, line_width, color); }, diff --git a/wpilibc/src/main/python/semiwrap/MechanismRoot2d.yml b/wpilibc/src/main/python/semiwrap/MechanismRoot2d.yml index f1deb752fc9..c5f1c46ebaa 100644 --- a/wpilibc/src/main/python/semiwrap/MechanismRoot2d.yml +++ b/wpilibc/src/main/python/semiwrap/MechanismRoot2d.yml @@ -4,7 +4,7 @@ extra_includes: classes: wpi::MechanismRoot2d: force_type_casters: - - wpi::units::degree_t + - wpi::units::degrees<> methods: MechanismRoot2d: ignore: true @@ -20,7 +20,7 @@ inline_code: |- cls_MechanismRoot2d .def("get_name", [](MechanismRoot2d *self) { return self->GetName(); }, release_gil()) .def("append_ligament", [](MechanismRoot2d *self, - std::string_view name, double length, wpi::units::degree_t angle, + std::string_view name, double length, wpi::units::degrees<> angle, double line_width, const wpi::util::Color8Bit& color) { return self->Append(name, length, angle, line_width, color); }, diff --git a/wpilibc/src/main/python/semiwrap/Notifier.yml b/wpilibc/src/main/python/semiwrap/Notifier.yml index 28f4fb2617e..8583e41dca0 100644 --- a/wpilibc/src/main/python/semiwrap/Notifier.yml +++ b/wpilibc/src/main/python/semiwrap/Notifier.yml @@ -11,11 +11,11 @@ classes: overloads: double: ignore: true - wpi::units::second_t: + wpi::units::seconds<>: StartPeriodic: overloads: double: ignore: true - wpi::units::second_t: + wpi::units::seconds<>: Stop: GetOverrun: diff --git a/wpilibc/src/main/python/semiwrap/OpModeRobot.yml b/wpilibc/src/main/python/semiwrap/OpModeRobot.yml index 1c44c138633..e6d8ef1cea5 100644 --- a/wpilibc/src/main/python/semiwrap/OpModeRobot.yml +++ b/wpilibc/src/main/python/semiwrap/OpModeRobot.yml @@ -7,7 +7,7 @@ classes: StartCompetition: OpModeRobotBase: overloads: - wpi::units::second_t: + wpi::units::seconds<>: "": DriverStationConnected: NonePeriodic: @@ -41,7 +41,7 @@ classes: methods: OpModeRobot: overloads: - wpi::units::second_t: + wpi::units::seconds<>: "": AddOpMode: overloads: diff --git a/wpilibc/src/main/python/semiwrap/PeriodicOpMode.yml b/wpilibc/src/main/python/semiwrap/PeriodicOpMode.yml index 3ba7c756fd0..473928d8d36 100644 --- a/wpilibc/src/main/python/semiwrap/PeriodicOpMode.yml +++ b/wpilibc/src/main/python/semiwrap/PeriodicOpMode.yml @@ -7,7 +7,7 @@ classes: End: AddPeriodic: overloads: - std::function, wpi::units::second_t: - std::function, wpi::units::second_t, wpi::units::second_t: + std::function, wpi::units::seconds<>: + std::function, wpi::units::seconds<>, wpi::units::seconds<>: PeriodicOpMode: GetCallbacks: diff --git a/wpilibc/src/main/python/semiwrap/PeriodicPriorityQueue.yml b/wpilibc/src/main/python/semiwrap/PeriodicPriorityQueue.yml index f721a0754e5..b6d964efa9e 100644 --- a/wpilibc/src/main/python/semiwrap/PeriodicPriorityQueue.yml +++ b/wpilibc/src/main/python/semiwrap/PeriodicPriorityQueue.yml @@ -8,8 +8,8 @@ classes: overloads: std::function, std::chrono::nanoseconds, std::chrono::nanoseconds: std::function, std::chrono::nanoseconds, std::chrono::nanoseconds, std::chrono::nanoseconds: - std::function, std::chrono::nanoseconds, wpi::units::second_t: - std::function, std::chrono::nanoseconds, wpi::units::second_t, wpi::units::second_t: + std::function, std::chrono::nanoseconds, wpi::units::seconds<>: + std::function, std::chrono::nanoseconds, wpi::units::seconds<>, wpi::units::seconds<>: Callback: Remove: Clear: @@ -27,7 +27,7 @@ classes: Callback: overloads: std::function, std::chrono::nanoseconds, std::chrono::nanoseconds, std::chrono::nanoseconds: - std::function, std::chrono::nanoseconds, wpi::units::second_t, wpi::units::second_t: - std::function, std::chrono::nanoseconds, wpi::units::second_t: + std::function, std::chrono::nanoseconds, wpi::units::seconds<>, wpi::units::seconds<>: + std::function, std::chrono::nanoseconds, wpi::units::seconds<>: operator>: operator==: diff --git a/wpilibc/src/main/python/semiwrap/SysIdRoutineLog.yml b/wpilibc/src/main/python/semiwrap/SysIdRoutineLog.yml index a8ee207fcc1..ba40e88510d 100644 --- a/wpilibc/src/main/python/semiwrap/SysIdRoutineLog.yml +++ b/wpilibc/src/main/python/semiwrap/SysIdRoutineLog.yml @@ -19,17 +19,17 @@ classes: voltage: position: overloads: - wpi::units::meter_t: - wpi::units::turn_t: + wpi::units::meters<>: + wpi::units::turns<>: rename: angular_position velocity: overloads: - wpi::units::meters_per_second_t: - wpi::units::turns_per_second_t: + wpi::units::meters_per_second<>: + wpi::units::turns_per_second<>: rename: angular_velocity acceleration: overloads: - wpi::units::meters_per_second_squared_t: - wpi::units::turns_per_second_squared_t: + wpi::units::meters_per_second_squared<>: + wpi::units::turns_per_second_squared<>: rename: angular_acceleration current: diff --git a/wpilibc/src/main/python/semiwrap/TimedRobot.yml b/wpilibc/src/main/python/semiwrap/TimedRobot.yml index d7fba7fdb9c..ab808609265 100644 --- a/wpilibc/src/main/python/semiwrap/TimedRobot.yml +++ b/wpilibc/src/main/python/semiwrap/TimedRobot.yml @@ -18,5 +18,5 @@ classes: default: 0_s TimedRobot: overloads: - wpi::units::second_t: - wpi::units::hertz_t: + wpi::units::seconds<>: + wpi::units::hertz<>: diff --git a/wpilibc/src/main/python/semiwrap/Watchdog.yml b/wpilibc/src/main/python/semiwrap/Watchdog.yml index e00b98c4850..da361c7aa3b 100644 --- a/wpilibc/src/main/python/semiwrap/Watchdog.yml +++ b/wpilibc/src/main/python/semiwrap/Watchdog.yml @@ -3,15 +3,15 @@ classes: methods: Watchdog: overloads: - wpi::units::second_t, std::function: - wpi::units::second_t, Callable&&, Arg&&, Args&&...: + wpi::units::seconds<>, std::function: + wpi::units::seconds<>, Callable&&, Arg&&, Args&&...: ignore: true GetTime: SetTimeout: overloads: double: ignore: true - wpi::units::second_t: + wpi::units::seconds<>: GetTimeout: IsExpired: AddEpoch: diff --git a/wpilibc/src/main/python/semiwrap/simulation/BatterySim.yml b/wpilibc/src/main/python/semiwrap/simulation/BatterySim.yml index ef2ad412d3f..3dd4a87aec2 100644 --- a/wpilibc/src/main/python/semiwrap/simulation/BatterySim.yml +++ b/wpilibc/src/main/python/semiwrap/simulation/BatterySim.yml @@ -1,13 +1,13 @@ classes: wpi::sim::BatterySim: force_type_casters: - - wpi::units::ampere_t + - wpi::units::amperes<> methods: Calculate: overloads: - wpi::units::volt_t, wpi::units::ohm_t, std::span: - wpi::units::volt_t, wpi::units::ohm_t, std::initializer_list: + wpi::units::volts<>, wpi::units::ohms<>, std::span>: + wpi::units::volts<>, wpi::units::ohms<>, std::initializer_list>: ignore: true - std::span: - std::initializer_list: + std::span>: + std::initializer_list>: ignore: true diff --git a/wpilibc/src/main/python/semiwrap/simulation/DCMotorSim.yml b/wpilibc/src/main/python/semiwrap/simulation/DCMotorSim.yml index 103f91b967b..d6302b1eebe 100644 --- a/wpilibc/src/main/python/semiwrap/simulation/DCMotorSim.yml +++ b/wpilibc/src/main/python/semiwrap/simulation/DCMotorSim.yml @@ -27,9 +27,9 @@ inline_code: | cls_DCMotorSim // java API compatibility .def("get_angular_position_rotations", [](const DCMotorSim &self) { - return wpi::units::turn_t{self.GetAngularPosition()}; + return wpi::units::turns<>{self.GetAngularPosition()}; }, py::doc("Returns the DC motor position in rotations")) .def("get_angular_velocity_rpm", [](const DCMotorSim &self) { - return wpi::units::revolutions_per_minute_t{self.GetAngularVelocity()}; + return wpi::units::revolutions_per_minute<>{self.GetAngularVelocity()}; }, py::doc("Returns the DC motor velocity in revolutions per minute")) ; diff --git a/wpilibc/src/main/python/semiwrap/simulation/DifferentialDrivetrainSim.yml b/wpilibc/src/main/python/semiwrap/simulation/DifferentialDrivetrainSim.yml index dd30c03af1b..831172501ad 100644 --- a/wpilibc/src/main/python/semiwrap/simulation/DifferentialDrivetrainSim.yml +++ b/wpilibc/src/main/python/semiwrap/simulation/DifferentialDrivetrainSim.yml @@ -6,11 +6,11 @@ classes: methods: DifferentialDrivetrainSim: overloads: - ? wpi::math::LinearSystem<2, 2, 2>, wpi::units::meter_t, wpi::math::DCMotor, double, wpi::units::meter_t, const std::array& + ? wpi::math::LinearSystem<2, 2, 2>, wpi::units::meters<>, wpi::math::DCMotor, double, wpi::units::meters<>, const std::array& : param_override: measurementStdDevs: default: std::array{} - ? wpi::math::DCMotor, double, wpi::units::kilogram_square_meter_t, wpi::units::kilogram_t, wpi::units::meter_t, wpi::units::meter_t, const std::array& + ? wpi::math::DCMotor, double, wpi::units::kilogram_square_meters<>, wpi::units::kilograms<>, wpi::units::meters<>, wpi::units::meters<>, const std::array& : param_override: measurementStdDevs: default: std::array{} @@ -33,11 +33,11 @@ classes: Dynamics: CreateKitbotSim: overloads: - wpi::math::DCMotor, double, wpi::units::meter_t, const std::array&: + wpi::math::DCMotor, double, wpi::units::meters<>, const std::array&: param_override: measurementStdDevs: default: std::array{} - wpi::math::DCMotor, double, wpi::units::meter_t, wpi::units::kilogram_square_meter_t, const std::array&: + wpi::math::DCMotor, double, wpi::units::meters<>, wpi::units::kilogram_square_meters<>, const std::array&: param_override: measurementStdDevs: default: std::array{} @@ -79,22 +79,22 @@ classes: inline_code: |- cls_DifferentialDrivetrainSim - .def("get_left_position_feet", [](DifferentialDrivetrainSim * self) -> wpi::units::foot_t { + .def("get_left_position_feet", [](DifferentialDrivetrainSim * self) -> wpi::units::feet<> { return self->GetLeftPosition(); }) - .def("get_left_position_inches", [](DifferentialDrivetrainSim * self) -> wpi::units::inch_t { + .def("get_left_position_inches", [](DifferentialDrivetrainSim * self) -> wpi::units::inches<> { return self->GetLeftPosition(); }) - .def("get_left_velocity_fps", [](DifferentialDrivetrainSim * self) -> wpi::units::feet_per_second_t { + .def("get_left_velocity_fps", [](DifferentialDrivetrainSim * self) -> wpi::units::feet_per_second<> { return self->GetLeftVelocity(); }) - .def("get_right_position_feet", [](DifferentialDrivetrainSim * self) -> wpi::units::foot_t { + .def("get_right_position_feet", [](DifferentialDrivetrainSim * self) -> wpi::units::feet<> { return self->GetRightPosition(); }) - .def("get_right_position_inches", [](DifferentialDrivetrainSim * self) -> wpi::units::inch_t { + .def("get_right_position_inches", [](DifferentialDrivetrainSim * self) -> wpi::units::inches<> { return self->GetRightPosition(); }) - .def("get_right_velocity_fps", [](DifferentialDrivetrainSim * self) -> wpi::units::feet_per_second_t { + .def("get_right_velocity_fps", [](DifferentialDrivetrainSim * self) -> wpi::units::feet_per_second<> { return self->GetRightVelocity(); }) ; diff --git a/wpilibc/src/main/python/semiwrap/simulation/ElevatorSim.yml b/wpilibc/src/main/python/semiwrap/simulation/ElevatorSim.yml index 2aaa0ac989b..b368866e3fc 100644 --- a/wpilibc/src/main/python/semiwrap/simulation/ElevatorSim.yml +++ b/wpilibc/src/main/python/semiwrap/simulation/ElevatorSim.yml @@ -7,15 +7,15 @@ classes: methods: ElevatorSim: overloads: - ? const wpi::math::LinearSystem<2, 1, 2>&, const wpi::math::DCMotor&, wpi::units::meter_t, wpi::units::meter_t, bool, wpi::units::meter_t, const std::array& + ? const wpi::math::LinearSystem<2, 1, 2>&, const wpi::math::DCMotor&, wpi::units::meters<>, wpi::units::meters<>, bool, wpi::units::meters<>, const std::array& : param_override: measurementStdDevs: default: std::array{0.0, 0.0} - ? const wpi::math::DCMotor&, double, wpi::units::kilogram_t, wpi::units::meter_t, wpi::units::meter_t, wpi::units::meter_t, bool, wpi::units::meter_t, const std::array& + ? const wpi::math::DCMotor&, double, wpi::units::kilograms<>, wpi::units::meters<>, wpi::units::meters<>, wpi::units::meters<>, bool, wpi::units::meters<>, const std::array& : param_override: measurementStdDevs: default: std::array{0.0} - ? decltype(1_V/Velocity_t (1)), decltype(1_V/Acceleration_t (1)), const wpi::math::DCMotor&, wpi::units::meter_t, wpi::units::meter_t, bool, wpi::units::meter_t, const std::array& + ? decltype(1_V/Velocity_t (1)), decltype(1_V/Acceleration_t (1)), const wpi::math::DCMotor&, wpi::units::meters<>, wpi::units::meters<>, bool, wpi::units::meters<>, const std::array& : ignore: true SetState: WouldHitLowerLimit: @@ -30,13 +30,13 @@ classes: inline_code: |- cls_ElevatorSim - .def("get_position_feet", [](ElevatorSim * self) -> wpi::units::foot_t { + .def("get_position_feet", [](ElevatorSim * self) -> wpi::units::feet<> { return self->GetPosition(); }) - .def("get_position_inches", [](ElevatorSim * self) -> wpi::units::inch_t { + .def("get_position_inches", [](ElevatorSim * self) -> wpi::units::inches<> { return self->GetPosition(); }) - .def("get_velocity_fps", [](ElevatorSim * self) -> wpi::units::feet_per_second_t { + .def("get_velocity_fps", [](ElevatorSim * self) -> wpi::units::feet_per_second<> { return self->GetVelocity(); }) ; diff --git a/wpilibc/src/main/python/semiwrap/simulation/FlywheelSim.yml b/wpilibc/src/main/python/semiwrap/simulation/FlywheelSim.yml index 931b684c48c..aa5c8c81b11 100644 --- a/wpilibc/src/main/python/semiwrap/simulation/FlywheelSim.yml +++ b/wpilibc/src/main/python/semiwrap/simulation/FlywheelSim.yml @@ -10,7 +10,7 @@ classes: param_override: measurementStdDevs: default: std::array{0.0} - const wpi::math::DCMotor&, double, wpi::units::kilogram_square_meter_t, const std::array&: + const wpi::math::DCMotor&, double, wpi::units::kilogram_square_meters<>, const std::array&: param_override: measurementStdDevs: default: std::array{0.0} diff --git a/wpilibc/src/main/python/semiwrap/simulation/SingleJointedArmSim.yml b/wpilibc/src/main/python/semiwrap/simulation/SingleJointedArmSim.yml index 85b3cbee008..e991d2f2338 100644 --- a/wpilibc/src/main/python/semiwrap/simulation/SingleJointedArmSim.yml +++ b/wpilibc/src/main/python/semiwrap/simulation/SingleJointedArmSim.yml @@ -7,11 +7,11 @@ classes: methods: SingleJointedArmSim: overloads: - ? const wpi::math::LinearSystem<2, 1, 2>&, const wpi::math::DCMotor&, double, wpi::units::meter_t, wpi::units::radian_t, wpi::units::radian_t, bool, wpi::units::radian_t, const std::array& + ? const wpi::math::LinearSystem<2, 1, 2>&, const wpi::math::DCMotor&, double, wpi::units::meters<>, wpi::units::radians<>, wpi::units::radians<>, bool, wpi::units::radians<>, const std::array& : param_override: measurementStdDevs: default: std::array{0.0, 0.0} - ? const wpi::math::DCMotor&, double, wpi::units::kilogram_square_meter_t, wpi::units::meter_t, wpi::units::radian_t, wpi::units::radian_t, bool, wpi::units::radian_t, const std::array& + ? const wpi::math::DCMotor&, double, wpi::units::kilogram_square_meters<>, wpi::units::meters<>, wpi::units::radians<>, wpi::units::radians<>, bool, wpi::units::radians<>, const std::array& : param_override: measurementStdDevs: default: std::array{0.0, 0.0} @@ -29,10 +29,10 @@ classes: inline_code: |- cls_SingleJointedArmSim - .def("get_angle_degrees", [](SingleJointedArmSim * self) -> wpi::units::degree_t { + .def("get_angle_degrees", [](SingleJointedArmSim * self) -> wpi::units::degrees<> { return self->GetAngle(); }) - .def("get_velocity_dps", [](SingleJointedArmSim * self) -> wpi::units::degrees_per_second_t { + .def("get_velocity_dps", [](SingleJointedArmSim * self) -> wpi::units::degrees_per_second<> { return self->GetVelocity(); }) ; diff --git a/wpilibc/src/main/python/wpilib/src/rpy/MotorControllerGroup.cpp b/wpilibc/src/main/python/wpilib/src/rpy/MotorControllerGroup.cpp index 7c8b8b48b15..9111fa92db7 100644 --- a/wpilibc/src/main/python/wpilib/src/rpy/MotorControllerGroup.cpp +++ b/wpilibc/src/main/python/wpilib/src/rpy/MotorControllerGroup.cpp @@ -14,7 +14,7 @@ void PyMotorControllerGroup::SetThrottle(double throttle) { } } -void PyMotorControllerGroup::SetVoltage(wpi::units::volt_t voltage) { +void PyMotorControllerGroup::SetVoltage(wpi::units::volts<> voltage) { for (auto motorController : m_motorControllers) { motorController->SetVoltage(m_isInverted ? -voltage : voltage); } diff --git a/wpilibc/src/main/python/wpilib/src/rpy/MotorControllerGroup.h b/wpilibc/src/main/python/wpilib/src/rpy/MotorControllerGroup.h index e3f0a6e4ba7..61b54ed27c0 100644 --- a/wpilibc/src/main/python/wpilib/src/rpy/MotorControllerGroup.h +++ b/wpilibc/src/main/python/wpilib/src/rpy/MotorControllerGroup.h @@ -25,7 +25,7 @@ class PyMotorControllerGroup : public MotorController, PyMotorControllerGroup& operator=(PyMotorControllerGroup&&) = default; void SetThrottle(double throttle) override; - void SetVoltage(wpi::units::volt_t voltage) override; + void SetVoltage(wpi::units::volts<> voltage) override; double GetThrottle() const override; void SetInverted(bool isInverted) override; bool GetInverted() const override; diff --git a/wpilibc/src/main/python/wpilib/src/rpy/Notifier.cpp b/wpilibc/src/main/python/wpilib/src/rpy/Notifier.cpp index a57719c4292..52ba0d4a4a7 100644 --- a/wpilibc/src/main/python/wpilib/src/rpy/Notifier.cpp +++ b/wpilibc/src/main/python/wpilib/src/rpy/Notifier.cpp @@ -126,17 +126,17 @@ void PyNotifier::SetCallback(std::function handler) { m_handler = handler; } -void PyNotifier::StartSingle(wpi::units::second_t delay) { +void PyNotifier::StartSingle(wpi::units::seconds<> delay) { int32_t status = 0; HAL_SetNotifierAlarm(m_notifier, - wpi::units::nanosecond_t{delay}.to(), 0, false, + wpi::units::nanoseconds<>{delay}.to(), 0, false, false, &status); WPILIB_CheckErrorStatus(status, "SetNotifierAlarm"); } -void PyNotifier::StartPeriodic(wpi::units::second_t period) { +void PyNotifier::StartPeriodic(wpi::units::seconds<> period) { int32_t status = 0; - auto periodNs = wpi::units::nanosecond_t{period}.to(); + auto periodNs = wpi::units::nanoseconds<>{period}.to(); HAL_SetNotifierAlarm(m_notifier, periodNs, periodNs, false, false, &status); WPILIB_CheckErrorStatus(status, "SetNotifierAlarm"); } diff --git a/wpilibc/src/main/python/wpilib/src/rpy/Notifier.h b/wpilibc/src/main/python/wpilib/src/rpy/Notifier.h index 4666e569b76..5d8ee0b7f69 100644 --- a/wpilibc/src/main/python/wpilib/src/rpy/Notifier.h +++ b/wpilibc/src/main/python/wpilib/src/rpy/Notifier.h @@ -66,7 +66,7 @@ class PyNotifier { * * @param delay Amount of time to wait before the handler is called. */ - void StartSingle(wpi::units::second_t delay); + void StartSingle(wpi::units::seconds<> delay); /** * Register for periodic event notification. @@ -78,7 +78,7 @@ class PyNotifier { * @param period Period to call the handler starting one period * after the call to this method. */ - void StartPeriodic(wpi::units::second_t period); + void StartPeriodic(wpi::units::seconds<> period); /** * Stop timer events from occurring. diff --git a/wpilibc/src/test/native/cpp/AnalogPotentiometerTest.cpp b/wpilibc/src/test/native/cpp/AnalogPotentiometerTest.cpp index 0eb3835e449..51d27db6dfb 100644 --- a/wpilibc/src/test/native/cpp/AnalogPotentiometerTest.cpp +++ b/wpilibc/src/test/native/cpp/AnalogPotentiometerTest.cpp @@ -91,7 +91,7 @@ TEST_CASE("AnalogPotentiometerTest WithModifiedBatteryVoltage", "[wpilibc]") { CHECK(90 == pot.Get()); // Simulate a lower battery voltage - RoboRioSim::SetUserVoltage3V3(wpi::units::volt_t{2.5}); + RoboRioSim::SetUserVoltage3V3(wpi::units::volts<>{2.5}); sim.SetVoltage(2.5); CHECK(270.0 == pot.Get()); diff --git a/wpilibc/src/test/native/cpp/DataLogTelemetryBackendTest.cpp b/wpilibc/src/test/native/cpp/DataLogTelemetryBackendTest.cpp index ed14541c834..213fbc7c2f2 100644 --- a/wpilibc/src/test/native/cpp/DataLogTelemetryBackendTest.cpp +++ b/wpilibc/src/test/native/cpp/DataLogTelemetryBackendTest.cpp @@ -323,11 +323,9 @@ TEST_CASE_METHOD(DataLogTelemetryBackendTest, TEST_CASE_METHOD(DataLogTelemetryBackendTest, "DataLogTelemetryBackendTest LogsStructAndProtobufDataTypes", "[wpilibc][telemetry]") { - const wpi::math::Translation2d value{wpi::units::meter_t{1.25}, - wpi::units::meter_t{2.5}}; + const wpi::math::Translation2d value{1.25_m, 2.5_m}; const std::array array{ - value, wpi::math::Translation2d{wpi::units::meter_t{3.75}, - wpi::units::meter_t{4.5}}}; + value, wpi::math::Translation2d{3.75_m, 4.5_m}}; wpi::util::ProtobufMessage msg; const std::string structType{std::string_view{ wpi::util::GetStructTypeString()}}; diff --git a/wpilibc/src/test/native/cpp/JoystickTest.cpp b/wpilibc/src/test/native/cpp/JoystickTest.cpp index dffae7842a2..bb87163fbbe 100644 --- a/wpilibc/src/test/native/cpp/JoystickTest.cpp +++ b/wpilibc/src/test/native/cpp/JoystickTest.cpp @@ -54,18 +54,18 @@ TEST_CASE("JoystickTest GetDirection", "[wpilibc]") { joysim.SetX(0.5); joysim.SetY(0); joysim.NotifyNewData(); - REQUIRE_THAT(wpi::units::radian_t{90_deg}.value(), + REQUIRE_THAT(wpi::units::radians<>{90_deg}.value(), Catch::Matchers::WithinAbs(joy.GetDirection().value(), 0.001)); joysim.SetX(0); joysim.SetY(-.5); joysim.NotifyNewData(); - REQUIRE_THAT(wpi::units::radian_t{0_deg}.value(), + REQUIRE_THAT(wpi::units::radians<>{0_deg}.value(), Catch::Matchers::WithinAbs(joy.GetDirection().value(), 0.001)); joysim.SetX(0.5); joysim.SetY(-0.5); joysim.NotifyNewData(); - REQUIRE_THAT(wpi::units::radian_t{45_deg}.value(), + REQUIRE_THAT(wpi::units::radians<>{45_deg}.value(), Catch::Matchers::WithinAbs(joy.GetDirection().value(), 0.001)); } diff --git a/wpilibc/src/test/native/cpp/LEDPatternTest.cpp b/wpilibc/src/test/native/cpp/LEDPatternTest.cpp index 55f24979413..5b67eff3e01 100644 --- a/wpilibc/src/test/native/cpp/LEDPatternTest.cpp +++ b/wpilibc/src/test/native/cpp/LEDPatternTest.cpp @@ -212,7 +212,7 @@ TEST_CASE("LEDPatternTest ScrollRelativeForward", "[wpilibc]") { // Scrolling at 1/256th of the buffer per second, // or 1 individual diode per second auto scroll = - pattern.ScrollAtRelativeVelocity(wpi::units::hertz_t{1 / 256.0}); + pattern.ScrollAtRelativeVelocity(wpi::units::hertz<>{1 / 256.0}); static int64_t now = 0; WPI_SetNowImpl([] { return now; }); @@ -256,7 +256,7 @@ TEST_CASE("LEDPatternTest ScrollRelativeBackward", "[wpilibc]") { // Scrolling at 1/256th of the buffer per second, // or 1 individual diode per second auto scroll = - pattern.ScrollAtRelativeVelocity(wpi::units::hertz_t{-1 / 256.0}); + pattern.ScrollAtRelativeVelocity(wpi::units::hertz<>{-1 / 256.0}); static int64_t now = 0; WPI_SetNowImpl([] { return now; }); @@ -693,7 +693,7 @@ TEST_CASE("LEDPatternTest Breathe", "[wpilibc]") { wpi::util::Color midGray{0.5, 0.5, 0.5}; std::array buffer; auto white = LEDPattern::Solid(wpi::util::Color::WHITE); - auto pattern = white.Breathe(wpi::units::nanosecond_t{4}); + auto pattern = white.Breathe(4_ns); static int64_t now = 0; WPI_SetNowImpl([] { return now; }); @@ -972,7 +972,7 @@ TEST_CASE("LEDPatternTest RelativeScrollingMask", "[wpilibc]") { auto pattern = LEDPattern::Steps(colorSteps) .Mask(LEDPattern::Steps(maskSteps)) - .ScrollAtRelativeVelocity(wpi::units::hertz_t{1e9 / 8.0}); + .ScrollAtRelativeVelocity(wpi::units::hertz<>{1e9 / 8.0}); pattern.ApplyTo(buffer); diff --git a/wpilibc/src/test/native/cpp/OnboardIMUTest.cpp b/wpilibc/src/test/native/cpp/OnboardIMUTest.cpp index ab292892ddc..9d8e197d510 100644 --- a/wpilibc/src/test/native/cpp/OnboardIMUTest.cpp +++ b/wpilibc/src/test/native/cpp/OnboardIMUTest.cpp @@ -30,19 +30,19 @@ TEST_CASE("OnboardIMUTest SimDevices", "[wpilibc]") { sim::OnboardIMUSim sim{}; - sim.SetAngleX(wpi::units::radian_t{1}); - sim.SetAngleY(wpi::units::radian_t{2}); - sim.SetAngleZ(wpi::units::radian_t{3}); + sim.SetAngleX(wpi::units::radians<>{1}); + sim.SetAngleY(wpi::units::radians<>{2}); + sim.SetAngleZ(wpi::units::radians<>{3}); - sim.SetGyroRateX(wpi::units::radians_per_second_t{3.504}); - sim.SetGyroRateY(wpi::units::radians_per_second_t{1.91}); - sim.SetGyroRateZ(wpi::units::radians_per_second_t{22.9}); + sim.SetGyroRateX(wpi::units::radians_per_second<>{3.504}); + sim.SetGyroRateY(wpi::units::radians_per_second<>{1.91}); + sim.SetGyroRateZ(wpi::units::radians_per_second<>{22.9}); - sim.SetAccelX(wpi::units::meters_per_second_squared_t{-1}); - sim.SetAccelY(wpi::units::meters_per_second_squared_t{-2}); - sim.SetAccelZ(wpi::units::meters_per_second_squared_t{-3}); + sim.SetAccelX(wpi::units::meters_per_second_squared<>{-1}); + sim.SetAccelY(wpi::units::meters_per_second_squared<>{-2}); + sim.SetAccelZ(wpi::units::meters_per_second_squared<>{-3}); - sim.SetYaw(wpi::units::radian_t{1.234}); + sim.SetYaw(wpi::units::radians<>{1.234}); CHECK(1.0 == imu.GetAngleX().value()); CHECK(2.0 == imu.GetAngleY().value()); diff --git a/wpilibc/src/test/native/cpp/TimerTest.cpp b/wpilibc/src/test/native/cpp/TimerTest.cpp index 1e9cb347270..e77168a2ce1 100644 --- a/wpilibc/src/test/native/cpp/TimerTest.cpp +++ b/wpilibc/src/test/native/cpp/TimerTest.cpp @@ -162,7 +162,7 @@ TEST_CASE_METHOD(TimerTest, Timer timer; timer.Start(); - auto period = wpi::units::second_t{1.0 / 60.0}; + auto period = wpi::units::seconds<>{1.0 / 60.0}; for (int64_t i = 1; i <= 60; ++i) { mockTime = (i * 1'000'000'000LL + 59) / 60 + 100; @@ -184,7 +184,7 @@ TEST_CASE_METHOD(TimerTest, timer.Start(); mockTime = 1; - auto period = wpi::units::nanosecond_t{0.1}; + auto period = wpi::units::nanoseconds<>{0.1}; for (int i = 0; i < 10; ++i) { CHECK(timer.AdvanceIfElapsed(period)); diff --git a/wpilibc/src/test/native/cpp/UnitNetworkTablesTest.cpp b/wpilibc/src/test/native/cpp/UnitNetworkTablesTest.cpp index 82a0ced3cb3..73849be7b12 100644 --- a/wpilibc/src/test/native/cpp/UnitNetworkTablesTest.cpp +++ b/wpilibc/src/test/native/cpp/UnitNetworkTablesTest.cpp @@ -20,17 +20,17 @@ class UnitNetworkTablesTest { TEST_CASE_METHOD(UnitNetworkTablesTest, "UnitNetworkTablesTest Publish", "[wpilibc]") { auto topic = - wpi::nt::UnitTopic{inst.GetTopic("meterTest")}; + wpi::nt::UnitTopic>{inst.GetTopic("meterTest")}; auto pub = topic.Publish(); pub.Set(2_m); - REQUIRE(topic.GetProperty("unit") == "meter"); + REQUIRE(topic.GetProperty("unit") == "meters"); REQUIRE(topic.IsMatchingUnit()); } TEST_CASE_METHOD(UnitNetworkTablesTest, "UnitNetworkTablesTest SubscribeDouble", "[wpilibc]") { auto topic = - wpi::nt::UnitTopic{inst.GetTopic("meterTest")}; + wpi::nt::UnitTopic>{inst.GetTopic("meterTest")}; auto pub = topic.Publish(); auto sub = inst.GetDoubleTopic("meterTest").Subscribe(0); REQUIRE(sub.Get() == 0); @@ -42,7 +42,7 @@ TEST_CASE_METHOD(UnitNetworkTablesTest, "UnitNetworkTablesTest SubscribeDouble", TEST_CASE_METHOD(UnitNetworkTablesTest, "UnitNetworkTablesTest SubscribeUnit", "[wpilibc]") { auto topic = - wpi::nt::UnitTopic{inst.GetTopic("meterTest")}; + wpi::nt::UnitTopic>{inst.GetTopic("meterTest")}; auto pub = topic.Publish(); auto sub = topic.Subscribe(0_m); REQUIRE(sub.Get() == 0_m); diff --git a/wpilibc/src/test/native/cpp/hardware/counter/TachometerTest.cpp b/wpilibc/src/test/native/cpp/hardware/counter/TachometerTest.cpp index dfe9625f19e..66af89aca42 100644 --- a/wpilibc/src/test/native/cpp/hardware/counter/TachometerTest.cpp +++ b/wpilibc/src/test/native/cpp/hardware/counter/TachometerTest.cpp @@ -15,10 +15,10 @@ TEST_CASE("Tachometer SetRateWindow", "[wpilibc][counter]") { wpi::Tachometer tachometer(0, wpi::EdgeConfiguration::RISING_EDGE); - CHECK_NOTHROW(tachometer.SetRateWindow(wpi::units::millisecond_t{5})); - CHECK_NOTHROW(tachometer.SetRateWindow(wpi::units::millisecond_t{255})); - CHECK_THROWS(tachometer.SetRateWindow(wpi::units::millisecond_t{4})); - CHECK_THROWS(tachometer.SetRateWindow(wpi::units::millisecond_t{256})); + CHECK_NOTHROW(tachometer.SetRateWindow(wpi::units::milliseconds<>{5})); + CHECK_NOTHROW(tachometer.SetRateWindow(wpi::units::milliseconds<>{255})); + CHECK_THROWS(tachometer.SetRateWindow(wpi::units::milliseconds<>{4})); + CHECK_THROWS(tachometer.SetRateWindow(wpi::units::milliseconds<>{256})); } TEST_CASE("Tachometer stopped state matches rate", "[wpilibc][counter]") { diff --git a/wpilibc/src/test/native/cpp/simulation/DCMotorSimTest.cpp b/wpilibc/src/test/native/cpp/simulation/DCMotorSimTest.cpp index 49bd76ed439..26d9ef365e4 100644 --- a/wpilibc/src/test/native/cpp/simulation/DCMotorSimTest.cpp +++ b/wpilibc/src/test/native/cpp/simulation/DCMotorSimTest.cpp @@ -19,7 +19,7 @@ TEST_CASE("DCMotorSimTest VoltageSteadyState", "[wpilibc][simulation]") { wpi::math::DCMotor gearbox = wpi::math::DCMotor::NEO(1); auto plant = wpi::math::Models::SingleJointedArmFromPhysicalConstants( - wpi::math::DCMotor::NEO(1), wpi::units::kilogram_square_meter_t{0.0005}, + wpi::math::DCMotor::NEO(1), wpi::units::kilogram_square_meters<>{0.0005}, 1.0); wpi::sim::DCMotorSim sim{plant, gearbox}; @@ -67,7 +67,7 @@ TEST_CASE("DCMotorSimTest VoltageSteadyState", "[wpilibc][simulation]") { TEST_CASE("DCMotorSimTest PositionFeedbackControl", "[wpilibc][simulation]") { wpi::math::DCMotor gearbox = wpi::math::DCMotor::NEO(1); auto plant = wpi::math::Models::SingleJointedArmFromPhysicalConstants( - wpi::math::DCMotor::NEO(1), wpi::units::kilogram_square_meter_t{0.0005}, + wpi::math::DCMotor::NEO(1), wpi::units::kilogram_square_meters<>{0.0005}, 1.0); wpi::sim::DCMotorSim sim{plant, gearbox}; diff --git a/wpilibc/src/test/native/cpp/simulation/DifferentialDrivetrainSimTest.cpp b/wpilibc/src/test/native/cpp/simulation/DifferentialDrivetrainSimTest.cpp index 5cd07bdf0fe..7aaee607394 100644 --- a/wpilibc/src/test/native/cpp/simulation/DifferentialDrivetrainSimTest.cpp +++ b/wpilibc/src/test/native/cpp/simulation/DifferentialDrivetrainSimTest.cpp @@ -17,7 +17,6 @@ #include "wpi/math/trajectory/constraint/DifferentialDriveKinematicsConstraint.hpp" #include "wpi/simulation/RoboRioSim.hpp" #include "wpi/units/current.hpp" -#include "wpi/units/math.hpp" #include "wpi/units/moment_of_inertia.hpp" TEST_CASE("DifferentialDrivetrainSimTest Convergence", @@ -43,7 +42,7 @@ TEST_CASE("DifferentialDrivetrainSimTest Convergence", // Ground truth. wpi::math::Vectord<7> groundTruthX = wpi::math::Vectord<7>::Zero(); - wpi::math::TrajectoryConfig config{1_mps, 1_mps_sq}; + wpi::math::TrajectoryConfig config{1_mps, 1_mps2}; config.AddConstraint( wpi::math::DifferentialDriveKinematicsConstraint(kinematics, 1_mps)); @@ -60,8 +59,8 @@ TEST_CASE("DifferentialDrivetrainSimTest Convergence", auto clampedVoltages = sim.ClampInput(voltages); // Sim periodic code. - sim.SetInputs(wpi::units::volt_t{clampedVoltages(0, 0)}, - wpi::units::volt_t{clampedVoltages(1, 0)}); + sim.SetInputs(wpi::units::volts<>{clampedVoltages(0, 0)}, + wpi::units::volts<>{clampedVoltages(1, 0)}); sim.Update(20_ms); // Update ground truth. @@ -125,5 +124,5 @@ TEST_CASE("DifferentialDrivetrainSimTest ModelStability", sim.Update(20_ms); } - CHECK(wpi::units::math::abs(sim.GetPose().Translation().Norm()) < 100_m); + CHECK(wpi::units::abs(sim.GetPose().Translation().Norm()) < 100_m); } diff --git a/wpilibc/src/test/native/cpp/simulation/ElevatorSimTest.cpp b/wpilibc/src/test/native/cpp/simulation/ElevatorSimTest.cpp index 3c3e9d36aeb..b30a722b6e1 100644 --- a/wpilibc/src/test/native/cpp/simulation/ElevatorSimTest.cpp +++ b/wpilibc/src/test/native/cpp/simulation/ElevatorSimTest.cpp @@ -18,7 +18,7 @@ #include "wpi/units/time.hpp" #define CHECK_NEAR_UNITS(val1, val2, eps) \ - CHECK(wpi::units::math::abs(val1 - val2) <= eps) + CHECK(wpi::units::abs(val1 - val2) <= eps) TEST_CASE("ElevatorSimTest StateSpaceSim", "[wpilibc][simulation]") { wpi::sim::ElevatorSim sim(wpi::math::DCMotor::Vex775Pro(4), 14.67, 8_kg, @@ -100,7 +100,7 @@ TEST_CASE("ElevatorSimTest Stability", "[wpilibc][simulation]") { wpi::math::Models::ElevatorFromPhysicalConstants( wpi::math::DCMotor::Vex775Pro(4), 4_kg, 0.5_in, 100) .Slice(0); - CHECK_NEAR_UNITS(wpi::units::meter_t{system.CalculateX( + CHECK_NEAR_UNITS(wpi::units::meters<>{system.CalculateX( wpi::math::Vectord<2>{0.0, 0.0}, wpi::math::Vectord<1>{12.0}, 20_ms * 50)(0)}, sim.GetPosition(), 1_cm); diff --git a/wpilibc/src/test/native/cpp/simulation/EncoderSimTest.cpp b/wpilibc/src/test/native/cpp/simulation/EncoderSimTest.cpp index 85735b9dff0..499da9c2ebe 100644 --- a/wpilibc/src/test/native/cpp/simulation/EncoderSimTest.cpp +++ b/wpilibc/src/test/native/cpp/simulation/EncoderSimTest.cpp @@ -57,10 +57,10 @@ TEST_CASE("EncoderSimTest SetRateWindow", "[wpilibc][simulation]") { Encoder encoder(0, 1); - CHECK_NOTHROW(encoder.SetRateWindow(wpi::units::millisecond_t{5})); - CHECK_NOTHROW(encoder.SetRateWindow(wpi::units::millisecond_t{255})); - CHECK_THROWS(encoder.SetRateWindow(wpi::units::millisecond_t{4})); - CHECK_THROWS(encoder.SetRateWindow(wpi::units::millisecond_t{256})); + CHECK_NOTHROW(encoder.SetRateWindow(wpi::units::milliseconds<>{5})); + CHECK_NOTHROW(encoder.SetRateWindow(wpi::units::milliseconds<>{255})); + CHECK_THROWS(encoder.SetRateWindow(wpi::units::milliseconds<>{4})); + CHECK_THROWS(encoder.SetRateWindow(wpi::units::milliseconds<>{256})); } TEST_CASE("EncoderSimTest ResetDataClearsRateCallbacks", diff --git a/wpilibc/src/test/native/cpp/simulation/RoboRioSimTest.cpp b/wpilibc/src/test/native/cpp/simulation/RoboRioSimTest.cpp index b554d26ce3c..074e43ad2d8 100644 --- a/wpilibc/src/test/native/cpp/simulation/RoboRioSimTest.cpp +++ b/wpilibc/src/test/native/cpp/simulation/RoboRioSimTest.cpp @@ -24,7 +24,7 @@ TEST_CASE("RoboRioSimTest SetVin", "[wpilibc][simulation]") { voltageCallback.GetCallback(), false); constexpr double TEST_VOLTAGE = 1.91; - RoboRioSim::SetVInVoltage(wpi::units::volt_t{TEST_VOLTAGE}); + RoboRioSim::SetVInVoltage(wpi::units::volts<>{TEST_VOLTAGE}); CHECK(voltageCallback.WasTriggered()); CHECK(TEST_VOLTAGE == voltageCallback.GetLastValue()); CHECK(TEST_VOLTAGE == RoboRioSim::GetVInVoltage().value()); @@ -61,8 +61,8 @@ TEST_CASE("RoboRioSimTest SetBrownout", "[wpilibc][simulation]") { constexpr double EXPECTED_RECOVERY_VOLTAGE = 8.0; RobotController::SetBrownoutVoltages( - wpi::units::volt_t{REQUESTED_BROWNOUT_VOLTAGE}, - wpi::units::volt_t{REQUESTED_RECOVERY_VOLTAGE}); + wpi::units::volts<>{REQUESTED_BROWNOUT_VOLTAGE}, + wpi::units::volts<>{REQUESTED_RECOVERY_VOLTAGE}); CHECK(brownoutVoltageCallback.WasTriggered()); CHECK(recoveryVoltageCallback.WasTriggered()); CHECK(EXPECTED_BROWNOUT_VOLTAGE == brownoutVoltageCallback.GetLastValue()); @@ -115,13 +115,13 @@ TEST_CASE("RoboRioSimTest Set3V3", "[wpilibc][simulation]") { constexpr double TEST_CURRENT = 174; constexpr int TEST_FAULTS = 229; - RoboRioSim::SetUserVoltage3V3(wpi::units::volt_t{TEST_VOLTAGE}); + RoboRioSim::SetUserVoltage3V3(wpi::units::volts<>{TEST_VOLTAGE}); CHECK(voltageCallback.WasTriggered()); CHECK(TEST_VOLTAGE == voltageCallback.GetLastValue()); CHECK(TEST_VOLTAGE == RoboRioSim::GetUserVoltage3V3().value()); CHECK(TEST_VOLTAGE == RobotController::GetVoltage3V3()); - RoboRioSim::SetUserCurrent3V3(wpi::units::ampere_t{TEST_CURRENT}); + RoboRioSim::SetUserCurrent3V3(wpi::units::amperes<>{TEST_CURRENT}); CHECK(currentCallback.WasTriggered()); CHECK(TEST_CURRENT == currentCallback.GetLastValue()); CHECK(TEST_CURRENT == RoboRioSim::GetUserCurrent3V3().value()); @@ -148,7 +148,7 @@ TEST_CASE("RoboRioSimTest SetCPUTemp", "[wpilibc][simulation]") { RoboRioSim::RegisterCPUTempCallback(callback.GetCallback(), false); constexpr double CPU_TEMP = 100.0; - RoboRioSim::SetCPUTemp(wpi::units::celsius_t{CPU_TEMP}); + RoboRioSim::SetCPUTemp(wpi::units::celsius<>{CPU_TEMP}); CHECK(callback.WasTriggered()); CHECK(CPU_TEMP == callback.GetLastValue()); CHECK(CPU_TEMP == RoboRioSim::GetCPUTemp().value()); diff --git a/wpilibc/src/test/native/cpp/simulation/StateSpaceSimTest.cpp b/wpilibc/src/test/native/cpp/simulation/StateSpaceSimTest.cpp index 260fcc9095a..216ef7d6a73 100644 --- a/wpilibc/src/test/native/cpp/simulation/StateSpaceSimTest.cpp +++ b/wpilibc/src/test/native/cpp/simulation/StateSpaceSimTest.cpp @@ -24,7 +24,7 @@ TEST_CASE("StateSpaceSimTest FlywheelSim", "[wpilibc][simulation]") { 0.01_V / 1_rad_per_s_sq); wpi::sim::FlywheelSim sim{plant, wpi::math::DCMotor::NEO(2)}; wpi::math::PIDController controller{0.2, 0.0, 0.0}; - wpi::math::SimpleMotorFeedforward feedforward{ + wpi::math::SimpleMotorFeedforward feedforward{ 0_V, 0.02_V / 1_rad_per_s, 0.01_V / 1_rad_per_s_sq}; wpi::Encoder encoder{0, 1}; wpi::sim::EncoderSim encoderSim{encoder}; @@ -36,7 +36,7 @@ TEST_CASE("StateSpaceSimTest FlywheelSim", "[wpilibc][simulation]") { for (int i = 0; i < 100; i++) { // RobotPeriodic runs first auto voltageOut = controller.Calculate(encoder.GetRate(), 200.0); - motor.SetVoltage(wpi::units::volt_t{voltageOut} + + motor.SetVoltage(wpi::units::volts<>{voltageOut} + feedforward.Calculate(200_rad_per_s)); // Then, SimulationPeriodic runs diff --git a/wpilibc/src/test/native/cpp/smartdashboard/Mechanism2dTest.cpp b/wpilibc/src/test/native/cpp/smartdashboard/Mechanism2dTest.cpp index 6bb1a54e480..afa0b30d191 100644 --- a/wpilibc/src/test/native/cpp/smartdashboard/Mechanism2dTest.cpp +++ b/wpilibc/src/test/native/cpp/smartdashboard/Mechanism2dTest.cpp @@ -93,7 +93,7 @@ TEST_CASE_METHOD(Mechanism2dTest, "Mechanism2dTest Ligament", wpi::Mechanism2d mechanism{5, 10}; wpi::MechanismRoot2d* root = mechanism.GetRoot("root", 1, 2); wpi::MechanismLigament2d* ligament = root->Append( - "ligament", 3, wpi::units::degree_t{90}, 1, + "ligament", 3, wpi::units::degrees<>{90}, 1, wpi::util::Color8Bit{255, 255, 255}); wpi::telemetry::Log("mechanism", mechanism); { @@ -114,7 +114,7 @@ TEST_CASE_METHOD(Mechanism2dTest, "Mechanism2dTest Ligament", mock->Clear(); } - ligament->SetAngle(wpi::units::degree_t{45}); + ligament->SetAngle(wpi::units::degrees<>{45}); ligament->SetColor({0, 0, 0}); ligament->SetLength(2); ligament->SetLineWeight(4); diff --git a/wpilibcExamples/src/main/cpp/examples/ArmSimulation/cpp/subsystems/Arm.cpp b/wpilibcExamples/src/main/cpp/examples/ArmSimulation/cpp/subsystems/Arm.cpp index 2d0a15e140d..919d987ff06 100644 --- a/wpilibcExamples/src/main/cpp/examples/ArmSimulation/cpp/subsystems/Arm.cpp +++ b/wpilibcExamples/src/main/cpp/examples/ArmSimulation/cpp/subsystems/Arm.cpp @@ -42,7 +42,7 @@ void Arm::SimulationPeriodic() { void Arm::LoadPreferences() { // Read Preferences for Arm setpoint and kP on entering Teleop - armSetpoint = wpi::units::degree_t{ + armSetpoint = wpi::units::degrees<>{ wpi::Preferences::GetDouble(ARM_POSITION_KEY, armSetpoint.value())}; if (armKp != wpi::Preferences::GetDouble(ARM_P_KEY, armKp)) { armKp = wpi::Preferences::GetDouble(ARM_P_KEY, armKp); @@ -54,8 +54,8 @@ void Arm::ReachSetpoint() { // Here, we run PID control like normal, with a setpoint read from // preferences in degrees. double pidOutput = controller.Calculate( - encoder.GetDistance(), (wpi::units::radian_t{armSetpoint}.value())); - motor.SetVoltage(wpi::units::volt_t{pidOutput}); + encoder.GetDistance(), (wpi::units::radians<>{armSetpoint}.value())); + motor.SetVoltage(wpi::units::volts<>{pidOutput}); } void Arm::Stop() { diff --git a/wpilibcExamples/src/main/cpp/examples/ArmSimulation/include/Constants.hpp b/wpilibcExamples/src/main/cpp/examples/ArmSimulation/include/Constants.hpp index bcd33612870..d78fbd5b813 100644 --- a/wpilibcExamples/src/main/cpp/examples/ArmSimulation/include/Constants.hpp +++ b/wpilibcExamples/src/main/cpp/examples/ArmSimulation/include/Constants.hpp @@ -31,14 +31,14 @@ inline constexpr std::string_view ARM_POSITION_KEY = "ArmPosition"; inline constexpr std::string_view ARM_P_KEY = "ArmP"; inline constexpr double DEFAULT_ARM_KP = 50.0; -inline constexpr wpi::units::degree_t DEFAULT_ARM_SETPOINT = 75.0_deg; +inline constexpr wpi::units::degrees<> DEFAULT_ARM_SETPOINT = 75.0_deg; -inline constexpr wpi::units::radian_t MIN_ANGLE = -75.0_deg; -inline constexpr wpi::units::radian_t MAX_ANGLE = 255.0_deg; +inline constexpr wpi::units::radians<> MIN_ANGLE = -75.0_deg; +inline constexpr wpi::units::radians<> MAX_ANGLE = 255.0_deg; inline constexpr double ARM_REDUCTION = 200.0; -inline constexpr wpi::units::kilogram_t ARM_MASS = 8.0_kg; -inline constexpr wpi::units::meter_t ARM_LENGTH = 30.0_in; +inline constexpr wpi::units::kilograms<> ARM_MASS = 8.0_kg; +inline constexpr wpi::units::meters<> ARM_LENGTH = 30.0_in; // distance per pulse = (angle per revolution) / (pulses per revolution) // = (2 * PI rads) / (4096 pulses) diff --git a/wpilibcExamples/src/main/cpp/examples/ArmSimulation/include/subsystems/Arm.hpp b/wpilibcExamples/src/main/cpp/examples/ArmSimulation/include/subsystems/Arm.hpp index 968bb3adbd9..79b668e9161 100644 --- a/wpilibcExamples/src/main/cpp/examples/ArmSimulation/include/subsystems/Arm.hpp +++ b/wpilibcExamples/src/main/cpp/examples/ArmSimulation/include/subsystems/Arm.hpp @@ -30,7 +30,7 @@ class Arm { private: // The P gain for the PID controller that drives this arm. double armKp = DEFAULT_ARM_KP; - wpi::units::degree_t armSetpoint = DEFAULT_ARM_SETPOINT; + wpi::units::degrees<> armSetpoint = DEFAULT_ARM_SETPOINT; // The arm gearbox represents a gearbox containing two Vex 775pro motors. wpi::math::DCMotor armGearbox = wpi::math::DCMotor::Vex775Pro(2); diff --git a/wpilibcExamples/src/main/cpp/examples/DifferentialDriveBot/cpp/Drivetrain.cpp b/wpilibcExamples/src/main/cpp/examples/DifferentialDriveBot/cpp/Drivetrain.cpp index 130e3913f9b..55aebf2f8c3 100644 --- a/wpilibcExamples/src/main/cpp/examples/DifferentialDriveBot/cpp/Drivetrain.cpp +++ b/wpilibcExamples/src/main/cpp/examples/DifferentialDriveBot/cpp/Drivetrain.cpp @@ -13,17 +13,17 @@ void Drivetrain::SetVelocities( const double rightOutput = rightPIDController.Calculate( rightEncoder.GetRate(), velocities.right.value()); - leftLeader.SetVoltage(wpi::units::volt_t{leftOutput} + leftFeedforward); - rightLeader.SetVoltage(wpi::units::volt_t{rightOutput} + rightFeedforward); + leftLeader.SetVoltage(wpi::units::volts<>{leftOutput} + leftFeedforward); + rightLeader.SetVoltage(wpi::units::volts<>{rightOutput} + rightFeedforward); } -void Drivetrain::Drive(wpi::units::meters_per_second_t xVelocity, - wpi::units::radians_per_second_t rot) { +void Drivetrain::Drive(wpi::units::meters_per_second<> xVelocity, + wpi::units::radians_per_second<> rot) { SetVelocities(kinematics.ToWheelVelocities({xVelocity, 0_mps, rot})); } void Drivetrain::UpdateOdometry() { odometry.Update(imu.GetRotation2d(), - wpi::units::meter_t{leftEncoder.GetDistance()}, - wpi::units::meter_t{rightEncoder.GetDistance()}); + wpi::units::meters<>{leftEncoder.GetDistance()}, + wpi::units::meters<>{rightEncoder.GetDistance()}); } diff --git a/wpilibcExamples/src/main/cpp/examples/DifferentialDriveBot/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/DifferentialDriveBot/cpp/Robot.cpp index 914d9950db3..0f978c00d9a 100644 --- a/wpilibcExamples/src/main/cpp/examples/DifferentialDriveBot/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/examples/DifferentialDriveBot/cpp/Robot.cpp @@ -35,8 +35,9 @@ class Robot : public wpi::TimedRobot { // Slew rate limiters to make joystick inputs more gentle; 1/3 sec from 0 // to 1. - wpi::math::SlewRateLimiter velocityLimiter{3 / 1_s}; - wpi::math::SlewRateLimiter rotLimiter{3 / 1_s}; + wpi::math::SlewRateLimiter velocityLimiter{3 / + 1_s}; + wpi::math::SlewRateLimiter rotLimiter{3 / 1_s}; Drivetrain drive; }; diff --git a/wpilibcExamples/src/main/cpp/examples/DifferentialDriveBot/include/Drivetrain.hpp b/wpilibcExamples/src/main/cpp/examples/DifferentialDriveBot/include/Drivetrain.hpp index 4b46a8d4e16..dc78ab31d16 100644 --- a/wpilibcExamples/src/main/cpp/examples/DifferentialDriveBot/include/Drivetrain.hpp +++ b/wpilibcExamples/src/main/cpp/examples/DifferentialDriveBot/include/Drivetrain.hpp @@ -45,19 +45,19 @@ class Drivetrain { rightEncoder.Reset(); } - static constexpr wpi::units::meters_per_second_t MAX_VELOCITY = + static constexpr wpi::units::meters_per_second<> MAX_VELOCITY = 3.0_mps; // 3 meters per second - static constexpr wpi::units::radians_per_second_t MAX_ANGULAR_VELOCITY{ + static constexpr wpi::units::radians_per_second<> MAX_ANGULAR_VELOCITY{ std::numbers::pi}; // 1/2 rotation per second void SetVelocities( const wpi::math::DifferentialDriveWheelVelocities& velocities); - void Drive(wpi::units::meters_per_second_t xVelocity, - wpi::units::radians_per_second_t rot); + void Drive(wpi::units::meters_per_second<> xVelocity, + wpi::units::radians_per_second<> rot); void UpdateOdometry(); private: - static constexpr wpi::units::meter_t TRACKWIDTH = 0.381_m * 2; + static constexpr wpi::units::meters<> TRACKWIDTH = 0.381_m * 2; static constexpr double WHEEL_RADIUS = 0.0508; // meters static constexpr int ENCODER_RESOLUTION = 4096; @@ -76,11 +76,11 @@ class Drivetrain { wpi::math::DifferentialDriveKinematics kinematics{TRACKWIDTH}; wpi::math::DifferentialDriveOdometry odometry{ - imu.GetRotation2d(), wpi::units::meter_t{leftEncoder.GetDistance()}, - wpi::units::meter_t{rightEncoder.GetDistance()}}; + imu.GetRotation2d(), wpi::units::meters<>{leftEncoder.GetDistance()}, + wpi::units::meters<>{rightEncoder.GetDistance()}}; // Gains are for example purposes only - must be determined for your own // robot! - wpi::math::SimpleMotorFeedforward feedforward{ + wpi::math::SimpleMotorFeedforward feedforward{ 1_V, 3_V / 1_mps}; }; diff --git a/wpilibcExamples/src/main/cpp/examples/DifferentialDrivePoseEstimator/cpp/Drivetrain.cpp b/wpilibcExamples/src/main/cpp/examples/DifferentialDrivePoseEstimator/cpp/Drivetrain.cpp index cf34141c9a2..b3efa8b9f4f 100644 --- a/wpilibcExamples/src/main/cpp/examples/DifferentialDrivePoseEstimator/cpp/Drivetrain.cpp +++ b/wpilibcExamples/src/main/cpp/examples/DifferentialDrivePoseEstimator/cpp/Drivetrain.cpp @@ -44,12 +44,12 @@ void Drivetrain::SetVelocities( const double rightOutput = rightPIDController.Calculate( rightEncoder.GetRate(), velocities.right.value()); - leftLeader.SetVoltage(wpi::units::volt_t{leftOutput} + leftFeedforward); - rightLeader.SetVoltage(wpi::units::volt_t{rightOutput} + rightFeedforward); + leftLeader.SetVoltage(wpi::units::volts<>{leftOutput} + leftFeedforward); + rightLeader.SetVoltage(wpi::units::volts<>{rightOutput} + rightFeedforward); } -void Drivetrain::Drive(wpi::units::meters_per_second_t xVelocity, - wpi::units::radians_per_second_t rot) { +void Drivetrain::Drive(wpi::units::meters_per_second<> xVelocity, + wpi::units::radians_per_second<> rot) { SetVelocities(kinematics.ToWheelVelocities({xVelocity, 0_mps, rot})); } @@ -79,9 +79,9 @@ wpi::math::Pose3d Drivetrain::ObjectToRobotPose( std::vector val{cameraToObjectEntry.Get()}; // Reconstruct cameraToObject Transform3D from networktables. - wpi::math::Translation3d translation{wpi::units::meter_t{val[0]}, - wpi::units::meter_t{val[1]}, - wpi::units::meter_t{val[2]}}; + wpi::math::Translation3d translation{wpi::units::meters<>{val[0]}, + wpi::units::meters<>{val[1]}, + wpi::units::meters<>{val[2]}}; wpi::math::Rotation3d rotation{ wpi::math::Quaternion{val[3], val[4], val[5], val[6]}}; wpi::math::Transform3d cameraToObject{translation, rotation}; @@ -92,8 +92,8 @@ wpi::math::Pose3d Drivetrain::ObjectToRobotPose( void Drivetrain::UpdateOdometry() { poseEstimator.Update(imu.GetRotation2d(), - wpi::units::meter_t{leftEncoder.GetDistance()}, - wpi::units::meter_t{rightEncoder.GetDistance()}); + wpi::units::meters<>{leftEncoder.GetDistance()}, + wpi::units::meters<>{rightEncoder.GetDistance()}); // Publish cameraToObject transformation to networktables --this would // normally be handled by the computer vision solution. @@ -120,9 +120,9 @@ void Drivetrain::SimulationPeriodic() { // To update our simulation, we set motor voltage inputs, update the // simulation, and write the simulated positions and velocities to our // simulated encoder and gyro. - drivetrainSimulator.SetInputs(wpi::units::volt_t{leftLeader.GetThrottle()} * + drivetrainSimulator.SetInputs(wpi::units::volts<>{leftLeader.GetThrottle()} * wpi::RobotController::GetInputVoltage(), - wpi::units::volt_t{rightLeader.GetThrottle()} * + wpi::units::volts<>{rightLeader.GetThrottle()} * wpi::RobotController::GetInputVoltage()); drivetrainSimulator.Update(20_ms); diff --git a/wpilibcExamples/src/main/cpp/examples/DifferentialDrivePoseEstimator/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/DifferentialDrivePoseEstimator/cpp/Robot.cpp index baa48e7f59c..d0724a642f8 100644 --- a/wpilibcExamples/src/main/cpp/examples/DifferentialDrivePoseEstimator/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/examples/DifferentialDrivePoseEstimator/cpp/Robot.cpp @@ -39,8 +39,9 @@ class Robot : public wpi::TimedRobot { // Slew rate limiters to make joystick inputs more gentle; 1/3 sec from 0 // to 1. - wpi::math::SlewRateLimiter velocityLimiter{3 / 1_s}; - wpi::math::SlewRateLimiter rotLimiter{3 / 1_s}; + wpi::math::SlewRateLimiter velocityLimiter{3 / + 1_s}; + wpi::math::SlewRateLimiter rotLimiter{3 / 1_s}; Drivetrain drive; }; diff --git a/wpilibcExamples/src/main/cpp/examples/DifferentialDrivePoseEstimator/include/Drivetrain.hpp b/wpilibcExamples/src/main/cpp/examples/DifferentialDrivePoseEstimator/include/Drivetrain.hpp index 6672a895ccf..d98ea8b2a10 100644 --- a/wpilibcExamples/src/main/cpp/examples/DifferentialDrivePoseEstimator/include/Drivetrain.hpp +++ b/wpilibcExamples/src/main/cpp/examples/DifferentialDrivePoseEstimator/include/Drivetrain.hpp @@ -37,9 +37,9 @@ class Drivetrain { public: Drivetrain(); - static constexpr wpi::units::meters_per_second_t MAX_VELOCITY = + static constexpr wpi::units::meters_per_second<> MAX_VELOCITY = 3.0_mps; // 3 meters per second - static constexpr wpi::units::radians_per_second_t MAX_ANGULAR_VELOCITY{ + static constexpr wpi::units::radians_per_second<> MAX_ANGULAR_VELOCITY{ std::numbers::pi}; // 1/2 rotation per second /** @@ -55,8 +55,8 @@ class Drivetrain { * @param xVelocity Linear velocity. * @param rot Angular Velocity. */ - void Drive(wpi::units::meters_per_second_t xVelocity, - wpi::units::radians_per_second_t rot); + void Drive(wpi::units::meters_per_second<> xVelocity, + wpi::units::radians_per_second<> rot); /** * Updates the field-relative position. @@ -108,8 +108,8 @@ class Drivetrain { wpi::nt::DoubleArrayEntry& cameraToObjectEntry); private: - static constexpr wpi::units::meter_t TRACKWIDTH = 0.381_m * 2; - static constexpr wpi::units::meter_t WHEEL_RADIUS = 0.0508_m; + static constexpr wpi::units::meters<> TRACKWIDTH = 0.381_m * 2; + static constexpr wpi::units::meters<> WHEEL_RADIUS = 0.0508_m; static constexpr int ENCODER_RESOLUTION = 4096; static constexpr std::array DEFAULT_VAL{0.0, 0.0, 0.0, 0.0, @@ -118,7 +118,7 @@ class Drivetrain { wpi::math::Transform3d robotToCamera{ wpi::math::Translation3d{1_m, 1_m, 1_m}, wpi::math::Rotation3d{0_rad, 0_rad, - wpi::units::radian_t{std::numbers::pi / 2}}}; + wpi::units::radians<>{std::numbers::pi / 2}}}; wpi::nt::NetworkTableInstance inst{ wpi::nt::NetworkTableInstance::GetDefault()}; @@ -151,15 +151,15 @@ class Drivetrain { // robot! wpi::math::DifferentialDrivePoseEstimator poseEstimator{ imu.GetRotation2d(), - wpi::units::meter_t{leftEncoder.GetDistance()}, - wpi::units::meter_t{rightEncoder.GetDistance()}, + wpi::units::meters<>{leftEncoder.GetDistance()}, + wpi::units::meters<>{rightEncoder.GetDistance()}, wpi::math::Pose2d{}, {0.01, 0.01, 0.01}, {0.1, 0.1, 0.1}}; // Gains are for example purposes only - must be determined for your own // robot! - wpi::math::SimpleMotorFeedforward feedforward{ + wpi::math::SimpleMotorFeedforward feedforward{ 1_V, 3_V / 1_mps}; // Simulation classes @@ -170,7 +170,7 @@ class Drivetrain { wpi::Field2d fieldApproximation; wpi::math::LinearSystem<2, 2, 2> drivetrainSystem = wpi::math::Models::DifferentialDriveFromSysId( - 1.98_V / 1_mps, 0.2_V / 1_mps_sq, 1.5_V / 1_mps, 0.3_V / 1_mps_sq); + 1.98_V / 1_mps, 0.2_V / 1_mps2, 1.5_V / 1_mps, 0.3_V / 1_mps2); wpi::sim::DifferentialDrivetrainSim drivetrainSimulator{ drivetrainSystem, TRACKWIDTH, wpi::math::DCMotor::CIM(2), 8, 2_in}; }; diff --git a/wpilibcExamples/src/main/cpp/examples/DifferentialDrivePoseEstimator/include/ExampleGlobalMeasurementSensor.hpp b/wpilibcExamples/src/main/cpp/examples/DifferentialDrivePoseEstimator/include/ExampleGlobalMeasurementSensor.hpp index a004c8e5df1..f8e551d2c1e 100644 --- a/wpilibcExamples/src/main/cpp/examples/DifferentialDrivePoseEstimator/include/ExampleGlobalMeasurementSensor.hpp +++ b/wpilibcExamples/src/main/cpp/examples/DifferentialDrivePoseEstimator/include/ExampleGlobalMeasurementSensor.hpp @@ -17,9 +17,9 @@ class ExampleGlobalMeasurementSensor { const wpi::math::Pose2d& estimatedRobotPose) { auto randVec = wpi::math::Normal(0.1, 0.1, 0.1); return wpi::math::Pose2d{ - estimatedRobotPose.X() + wpi::units::meter_t{randVec(0)}, - estimatedRobotPose.Y() + wpi::units::meter_t{randVec(1)}, + estimatedRobotPose.X() + wpi::units::meters<>{randVec(0)}, + estimatedRobotPose.Y() + wpi::units::meters<>{randVec(1)}, estimatedRobotPose.Rotation() + - wpi::math::Rotation2d{wpi::units::radian_t{randVec(2)}}}; + wpi::math::Rotation2d{wpi::units::radians<>{randVec(2)}}}; } }; diff --git a/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/cpp/subsystems/DriveSubsystem.cpp b/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/cpp/subsystems/DriveSubsystem.cpp index ae0114d0eef..7a1ea0f9292 100644 --- a/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/cpp/subsystems/DriveSubsystem.cpp +++ b/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/cpp/subsystems/DriveSubsystem.cpp @@ -31,10 +31,10 @@ void DriveSubsystem::Periodic() { } void DriveSubsystem::SetDriveStates( - wpi::math::TrapezoidProfile::State currentLeft, - wpi::math::TrapezoidProfile::State currentRight, - wpi::math::TrapezoidProfile::State nextLeft, - wpi::math::TrapezoidProfile::State nextRight) { + wpi::math::TrapezoidProfile::State currentLeft, + wpi::math::TrapezoidProfile::State currentRight, + wpi::math::TrapezoidProfile::State nextLeft, + wpi::math::TrapezoidProfile::State nextRight) { // Feedforward is divided by battery voltage to normalize it to [-1, 1] leftLeader.SetSetpoint( ExampleSmartMotorController::PIDMode::POSITION, @@ -57,12 +57,12 @@ void DriveSubsystem::ResetEncoders() { rightLeader.ResetEncoder(); } -wpi::units::meter_t DriveSubsystem::GetLeftEncoderDistance() { - return wpi::units::meter_t{leftLeader.GetEncoderDistance()}; +wpi::units::meters<> DriveSubsystem::GetLeftEncoderDistance() { + return wpi::units::meters<>{leftLeader.GetEncoderDistance()}; } -wpi::units::meter_t DriveSubsystem::GetRightEncoderDistance() { - return wpi::units::meter_t{rightLeader.GetEncoderDistance()}; +wpi::units::meters<> DriveSubsystem::GetRightEncoderDistance() { + return wpi::units::meters<>{rightLeader.GetEncoderDistance()}; } void DriveSubsystem::SetMaxOutput(double maxOutput) { @@ -70,7 +70,7 @@ void DriveSubsystem::SetMaxOutput(double maxOutput) { } wpi::cmd::CommandPtr DriveSubsystem::ProfiledDriveDistance( - wpi::units::meter_t distance) { + wpi::units::meters<> distance) { return StartRun( [&] { // Restart timer so profile setpoints start at the beginning @@ -92,7 +92,7 @@ wpi::cmd::CommandPtr DriveSubsystem::ProfiledDriveDistance( } wpi::cmd::CommandPtr DriveSubsystem::DynamicProfiledDriveDistance( - wpi::units::meter_t distance) { + wpi::units::meters<> distance) { return StartRun( [&] { // Restart timer so profile setpoints start at the beginning diff --git a/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/include/Constants.hpp b/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/include/Constants.hpp index e7947a8ee6c..5fe2f410f15 100644 --- a/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/include/Constants.hpp +++ b/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/include/Constants.hpp @@ -20,7 +20,7 @@ */ namespace DriveConstants { -inline constexpr wpi::units::second_t DT{0.02}; +inline constexpr wpi::units::seconds<> DT{0.02}; inline constexpr int LEFT_MOTOR1_PORT = 0; inline constexpr int LEFT_MOTOR2_PORT = 1; inline constexpr int RIGHT_MOTOR1_PORT = 2; @@ -37,7 +37,7 @@ inline constexpr auto ka = 0.15_V * 1_s * 1_s / 1_m; inline constexpr double kp = 1; inline constexpr auto MAX_VELOCITY = 3_mps; -inline constexpr auto MAX_ACCELERATION = 3_mps_sq; +inline constexpr auto MAX_ACCELERATION = 3_mps2; } // namespace DriveConstants diff --git a/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/include/subsystems/DriveSubsystem.hpp b/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/include/subsystems/DriveSubsystem.hpp index fef5f484911..01d35364c6f 100644 --- a/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/include/subsystems/DriveSubsystem.hpp +++ b/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/include/subsystems/DriveSubsystem.hpp @@ -35,10 +35,10 @@ class DriveSubsystem : public wpi::cmd::SubsystemBase { * @param nextRight The next right wheel state. */ void SetDriveStates( - wpi::math::TrapezoidProfile::State currentLeft, - wpi::math::TrapezoidProfile::State currentRight, - wpi::math::TrapezoidProfile::State nextLeft, - wpi::math::TrapezoidProfile::State nextRight); + wpi::math::TrapezoidProfile::State currentLeft, + wpi::math::TrapezoidProfile::State currentRight, + wpi::math::TrapezoidProfile::State nextLeft, + wpi::math::TrapezoidProfile::State nextRight); /** * Drives the robot using arcade controls. @@ -58,14 +58,14 @@ class DriveSubsystem : public wpi::cmd::SubsystemBase { * * @return the average of the TWO encoder readings */ - wpi::units::meter_t GetLeftEncoderDistance(); + wpi::units::meters<> GetLeftEncoderDistance(); /** * Gets the distance of the right encoder. * * @return the average of the TWO encoder readings */ - wpi::units::meter_t GetRightEncoderDistance(); + wpi::units::meters<> GetRightEncoderDistance(); /** * Sets the max output of the drive. Useful for scaling the drive to drive @@ -82,7 +82,7 @@ class DriveSubsystem : public wpi::cmd::SubsystemBase { * @param distance The distance to drive forward. * @return A command. */ - wpi::cmd::CommandPtr ProfiledDriveDistance(wpi::units::meter_t distance); + wpi::cmd::CommandPtr ProfiledDriveDistance(wpi::units::meters<> distance); /** * Creates a command to drive forward a specified distance using a motion @@ -92,14 +92,14 @@ class DriveSubsystem : public wpi::cmd::SubsystemBase { * @return A command. */ wpi::cmd::CommandPtr DynamicProfiledDriveDistance( - wpi::units::meter_t distance); + wpi::units::meters<> distance); private: - wpi::math::TrapezoidProfile profile{ + wpi::math::TrapezoidProfile profile{ {DriveConstants::MAX_VELOCITY, DriveConstants::MAX_ACCELERATION}}; wpi::Timer timer; - wpi::units::meter_t initialLeftDistance; - wpi::units::meter_t initialRightDistance; + wpi::units::meters<> initialLeftDistance; + wpi::units::meters<> initialRightDistance; // Components (e.g. motor controllers and sensors) should generally be // declared private and exposed only through public methods. @@ -110,7 +110,7 @@ class DriveSubsystem : public wpi::cmd::SubsystemBase { ExampleSmartMotorController rightFollower; // A feedforward component for the drive - wpi::math::SimpleMotorFeedforward feedforward; + wpi::math::SimpleMotorFeedforward feedforward; // The robot's drive wpi::DifferentialDrive drive{[&](double output) { leftLeader.Set(output); }, diff --git a/wpilibcExamples/src/main/cpp/examples/ElevatorExponentialProfile/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/ElevatorExponentialProfile/cpp/Robot.cpp index f646b6f1ff4..a86f65bd2b2 100644 --- a/wpilibcExamples/src/main/cpp/examples/ElevatorExponentialProfile/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/examples/ElevatorExponentialProfile/cpp/Robot.cpp @@ -15,7 +15,7 @@ class Robot : public wpi::TimedRobot { public: - static constexpr wpi::units::second_t DT = 20_ms; + static constexpr wpi::units::seconds<> DT = 20_ms; Robot() { // Note: These gains are fake, and will have to be tuned for your robot. @@ -45,17 +45,17 @@ class Robot : public wpi::TimedRobot { private: wpi::Joystick joystick{1}; ExampleSmartMotorController motor{1}; - wpi::math::SimpleMotorFeedforward feedforward{ + wpi::math::SimpleMotorFeedforward feedforward{ // Note: These gains are fake, and will have to be tuned for your robot. - 1_V, 1_V / 1_mps, 1_V / 1_mps_sq}; + 1_V, 1_V / 1_mps, 1_V / 1_mps2}; // Create a motion profile with the given maximum velocity and maximum // acceleration constraints for the next setpoint. - wpi::math::ExponentialProfile profile{ - {10_V, 1_V / 1_mps, 1_V / 1_mps_sq}}; - wpi::math::ExponentialProfile::State + wpi::math::ExponentialProfile + profile{{10_V, 1_V / 1_mps, 1_V / 1_mps2}}; + wpi::math::ExponentialProfile::State goal; - wpi::math::ExponentialProfile::State + wpi::math::ExponentialProfile::State setpoint; }; diff --git a/wpilibcExamples/src/main/cpp/examples/ElevatorExponentialSimulation/cpp/subsystems/Elevator.cpp b/wpilibcExamples/src/main/cpp/examples/ElevatorExponentialSimulation/cpp/subsystems/Elevator.cpp index 4851f6f350d..1eaa70a05c8 100644 --- a/wpilibcExamples/src/main/cpp/examples/ElevatorExponentialSimulation/cpp/subsystems/Elevator.cpp +++ b/wpilibcExamples/src/main/cpp/examples/ElevatorExponentialSimulation/cpp/subsystems/Elevator.cpp @@ -39,8 +39,8 @@ void Elevator::UpdateTelemetry() { wpi::telemetry::Log("Elevator Sim", mech2d); } -void Elevator::ReachGoal(wpi::units::meter_t goal) { - wpi::math::ExponentialProfile::State +void Elevator::ReachGoal(wpi::units::meters<> goal) { + wpi::math::ExponentialProfile::State goalState{goal, 0_mps}; auto next = profile.Calculate(20_ms, setpoint, goalState); @@ -50,7 +50,7 @@ void Elevator::ReachGoal(wpi::units::meter_t goal) { auto feedforwardOutput = feedforward.Calculate(setpoint.velocity, next.velocity); - motor.SetVoltage(wpi::units::volt_t{pidOutput} + feedforwardOutput); + motor.SetVoltage(wpi::units::volts<>{pidOutput} + feedforwardOutput); setpoint = next; } diff --git a/wpilibcExamples/src/main/cpp/examples/ElevatorExponentialSimulation/include/Constants.hpp b/wpilibcExamples/src/main/cpp/examples/ElevatorExponentialSimulation/include/Constants.hpp index 4233f410e4f..be9d5ed18ba 100644 --- a/wpilibcExamples/src/main/cpp/examples/ElevatorExponentialSimulation/include/Constants.hpp +++ b/wpilibcExamples/src/main/cpp/examples/ElevatorExponentialSimulation/include/Constants.hpp @@ -32,20 +32,20 @@ inline constexpr double ELEVATOR_KP = 0.75; inline constexpr double ELEVATOR_KI = 0.0; inline constexpr double ELEVATOR_KD = 0.0; -inline constexpr wpi::units::volt_t ELEVATOR_MAX_V = 10_V; -inline constexpr wpi::units::volt_t ELEVATOR_KS = 0.0_V; -inline constexpr wpi::units::volt_t ELEVATOR_KG = 0.62_V; +inline constexpr wpi::units::volts<> ELEVATOR_MAX_V = 10_V; +inline constexpr wpi::units::volts<> ELEVATOR_KS = 0.0_V; +inline constexpr wpi::units::volts<> ELEVATOR_KG = 0.62_V; inline constexpr auto ELEVATOR_KV = 3.9_V / 1_mps; -inline constexpr auto ELEVATOR_KA = 0.06_V / 1_mps_sq; +inline constexpr auto ELEVATOR_KA = 0.06_V / 1_mps2; inline constexpr double ELEVATOR_GEARING = 5.0; -inline constexpr wpi::units::meter_t ELEVATOR_DRUM_RADIUS = 1_in; -inline constexpr wpi::units::kilogram_t CARRIAGE_MASS = 12_lb; +inline constexpr wpi::units::meters<> ELEVATOR_DRUM_RADIUS = 1_in; +inline constexpr wpi::units::kilograms<> CARRIAGE_MASS = 12_lb; -inline constexpr wpi::units::meter_t SETPOINT = 42.875_in; -inline constexpr wpi::units::meter_t LOWER_SETPOINT = 15_in; -inline constexpr wpi::units::meter_t MIN_ELEVATOR_HEIGHT = 0_cm; -inline constexpr wpi::units::meter_t MAX_ELEVATOR_HEIGHT = 50_in; +inline constexpr wpi::units::meters<> SETPOINT = 42.875_in; +inline constexpr wpi::units::meters<> LOWER_SETPOINT = 15_in; +inline constexpr wpi::units::meters<> MIN_ELEVATOR_HEIGHT = 0_cm; +inline constexpr wpi::units::meters<> MAX_ELEVATOR_HEIGHT = 50_in; // distance per pulse = (distance per revolution) / (pulses per revolution) // = (Pi * D) / ppr diff --git a/wpilibcExamples/src/main/cpp/examples/ElevatorExponentialSimulation/include/subsystems/Elevator.hpp b/wpilibcExamples/src/main/cpp/examples/ElevatorExponentialSimulation/include/subsystems/Elevator.hpp index f2c6de3035d..2fa79cf1976 100644 --- a/wpilibcExamples/src/main/cpp/examples/ElevatorExponentialSimulation/include/subsystems/Elevator.hpp +++ b/wpilibcExamples/src/main/cpp/examples/ElevatorExponentialSimulation/include/subsystems/Elevator.hpp @@ -25,7 +25,7 @@ class Elevator { Elevator(); void SimulationPeriodic(); void UpdateTelemetry(); - void ReachGoal(wpi::units::meter_t goal); + void ReachGoal(wpi::units::meters<> goal); void Reset(); void Stop(); @@ -34,13 +34,13 @@ class Elevator { wpi::math::DCMotor elevatorGearbox = wpi::math::DCMotor::NEO(2); // Standard classes for controlling our elevator - wpi::math::ExponentialProfile::Constraints constraints{ + wpi::math::ExponentialProfile::Constraints constraints{ Constants::ELEVATOR_MAX_V, Constants::ELEVATOR_KV, Constants::ELEVATOR_KA}; - wpi::math::ExponentialProfile profile{ - constraints}; - wpi::math::ExponentialProfile::State + wpi::math::ExponentialProfile + profile{constraints}; + wpi::math::ExponentialProfile::State setpoint; wpi::math::PIDController controller{ diff --git a/wpilibcExamples/src/main/cpp/examples/ElevatorProfiledPID/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/ElevatorProfiledPID/cpp/Robot.cpp index aad0f975cf0..66583b1e15a 100644 --- a/wpilibcExamples/src/main/cpp/examples/ElevatorProfiledPID/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/examples/ElevatorProfiledPID/cpp/Robot.cpp @@ -19,7 +19,7 @@ class Robot : public wpi::TimedRobot { public: - static constexpr wpi::units::second_t DT = 20_ms; + static constexpr wpi::units::seconds<> DT = 20_ms; Robot() { encoder.SetDistancePerPulse(1.0 / 360.0 * 2.0 * std::numbers::pi * 1.5); @@ -33,20 +33,20 @@ class Robot : public wpi::TimedRobot { } // Run controller and update motor output - motor.SetVoltage(wpi::units::volt_t{controller.Calculate( - wpi::units::meter_t{encoder.GetDistance()})} + + motor.SetVoltage(wpi::units::volts<>{controller.Calculate( + wpi::units::meters<>{encoder.GetDistance()})} + feedforward.Calculate(controller.GetSetpoint().velocity)); } private: - static constexpr wpi::units::meters_per_second_t MAX_VELOCITY = 1.75_mps; - static constexpr wpi::units::meters_per_second_squared_t MAX_ACCELERATION = - 0.75_mps_sq; + static constexpr wpi::units::meters_per_second<> MAX_VELOCITY = 1.75_mps; + static constexpr wpi::units::meters_per_second_squared<> MAX_ACCELERATION = + 0.75_mps2; static constexpr double kP = 1.3; static constexpr double kI = 0.0; static constexpr double kD = 0.7; - static constexpr wpi::units::volt_t kS = 1.1_V; - static constexpr wpi::units::volt_t kG = 1.2_V; + static constexpr wpi::units::volts<> kS = 1.1_V; + static constexpr wpi::units::volts<> kG = 1.2_V; static constexpr auto kV = 1.3_V / 1_mps; wpi::Joystick joystick{1}; @@ -55,9 +55,9 @@ class Robot : public wpi::TimedRobot { // Create a PID controller whose setpoint's change is subject to maximum // velocity and acceleration constraints. - wpi::math::TrapezoidProfile::Constraints constraints{ + wpi::math::TrapezoidProfile::Constraints constraints{ MAX_VELOCITY, MAX_ACCELERATION}; - wpi::math::ProfiledPIDController controller{ + wpi::math::ProfiledPIDController controller{ kP, kI, kD, constraints, DT}; wpi::math::ElevatorFeedforward feedforward{kS, kG, kV}; }; diff --git a/wpilibcExamples/src/main/cpp/examples/ElevatorSimulation/cpp/subsystems/Elevator.cpp b/wpilibcExamples/src/main/cpp/examples/ElevatorSimulation/cpp/subsystems/Elevator.cpp index 6d5cb8b539d..7e8dc926ba5 100644 --- a/wpilibcExamples/src/main/cpp/examples/ElevatorSimulation/cpp/subsystems/Elevator.cpp +++ b/wpilibcExamples/src/main/cpp/examples/ElevatorSimulation/cpp/subsystems/Elevator.cpp @@ -39,14 +39,14 @@ void Elevator::UpdateTelemetry() { wpi::telemetry::Log("Elevator Sim", mech2d); } -void Elevator::ReachGoal(wpi::units::meter_t goal) { +void Elevator::ReachGoal(wpi::units::meters<> goal) { controller.SetGoal(goal); // With the setpoint value we run PID control like normal double pidOutput = - controller.Calculate(wpi::units::meter_t{encoder.GetDistance()}); - wpi::units::volt_t feedforwardOutput = + controller.Calculate(wpi::units::meters<>{encoder.GetDistance()}); + wpi::units::volts<> feedforwardOutput = feedforward.Calculate(controller.GetSetpoint().velocity); - motor.SetVoltage(wpi::units::volt_t{pidOutput} + feedforwardOutput); + motor.SetVoltage(wpi::units::volts<>{pidOutput} + feedforwardOutput); } void Elevator::Stop() { diff --git a/wpilibcExamples/src/main/cpp/examples/ElevatorSimulation/include/Constants.hpp b/wpilibcExamples/src/main/cpp/examples/ElevatorSimulation/include/Constants.hpp index df3a8440fe3..ddf93bb806c 100644 --- a/wpilibcExamples/src/main/cpp/examples/ElevatorSimulation/include/Constants.hpp +++ b/wpilibcExamples/src/main/cpp/examples/ElevatorSimulation/include/Constants.hpp @@ -34,18 +34,18 @@ inline constexpr double ELEVATOR_KP = 5.0; inline constexpr double ELEVATOR_KI = 0.0; inline constexpr double ELEVATOR_KD = 0.0; -inline constexpr wpi::units::volt_t ELEVATOR_KS = 0.0_V; -inline constexpr wpi::units::volt_t ELEVATOR_KG = 0.762_V; +inline constexpr wpi::units::volts<> ELEVATOR_KS = 0.0_V; +inline constexpr wpi::units::volts<> ELEVATOR_KG = 0.762_V; inline constexpr auto ELEVATOR_KV = 0.762_V / 1_mps; -inline constexpr auto ELEVATOR_KA = 0.0_V / 1_mps_sq; +inline constexpr auto ELEVATOR_KA = 0.0_V / 1_mps2; inline constexpr double ELEVATOR_GEARING = 10.0; -inline constexpr wpi::units::meter_t ELEVATOR_DRUM_RADIUS = 2_in; -inline constexpr wpi::units::kilogram_t CARRIAGE_MASS = 4.0_kg; +inline constexpr wpi::units::meters<> ELEVATOR_DRUM_RADIUS = 2_in; +inline constexpr wpi::units::kilograms<> CARRIAGE_MASS = 4.0_kg; -inline constexpr wpi::units::meter_t SETPOINT = 75_cm; -inline constexpr wpi::units::meter_t MIN_ELEVATOR_HEIGHT = 0_cm; -inline constexpr wpi::units::meter_t MAX_ELEVATOR_HEIGHT = 1.25_m; +inline constexpr wpi::units::meters<> SETPOINT = 75_cm; +inline constexpr wpi::units::meters<> MIN_ELEVATOR_HEIGHT = 0_cm; +inline constexpr wpi::units::meters<> MAX_ELEVATOR_HEIGHT = 1.25_m; // distance per pulse = (distance per revolution) / (pulses per revolution) // = (Pi * D) / ppr diff --git a/wpilibcExamples/src/main/cpp/examples/ElevatorSimulation/include/subsystems/Elevator.hpp b/wpilibcExamples/src/main/cpp/examples/ElevatorSimulation/include/subsystems/Elevator.hpp index c06095a4303..4d8d1635caf 100644 --- a/wpilibcExamples/src/main/cpp/examples/ElevatorSimulation/include/subsystems/Elevator.hpp +++ b/wpilibcExamples/src/main/cpp/examples/ElevatorSimulation/include/subsystems/Elevator.hpp @@ -25,7 +25,7 @@ class Elevator { Elevator(); void SimulationPeriodic(); void UpdateTelemetry(); - void ReachGoal(wpi::units::meter_t goal); + void ReachGoal(wpi::units::meters<> goal); void Stop(); private: @@ -33,9 +33,9 @@ class Elevator { wpi::math::DCMotor elevatorGearbox = wpi::math::DCMotor::Vex775Pro(4); // Standard classes for controlling our elevator - wpi::math::TrapezoidProfile::Constraints constraints{ - 2.45_mps, 2.45_mps_sq}; - wpi::math::ProfiledPIDController controller{ + wpi::math::TrapezoidProfile::Constraints constraints{ + 2.45_mps, 2.45_mps2}; + wpi::math::ProfiledPIDController controller{ Constants::ELEVATOR_KP, Constants::ELEVATOR_KI, Constants::ELEVATOR_KD, constraints}; diff --git a/wpilibcExamples/src/main/cpp/examples/ElevatorTrapezoidProfile/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/ElevatorTrapezoidProfile/cpp/Robot.cpp index b5b63654d3c..946800f3108 100644 --- a/wpilibcExamples/src/main/cpp/examples/ElevatorTrapezoidProfile/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/examples/ElevatorTrapezoidProfile/cpp/Robot.cpp @@ -15,7 +15,7 @@ class Robot : public wpi::TimedRobot { public: - static constexpr wpi::units::second_t DT = 20_ms; + static constexpr wpi::units::seconds<> DT = 20_ms; Robot() { // Note: These gains are fake, and will have to be tuned for your robot. @@ -42,16 +42,16 @@ class Robot : public wpi::TimedRobot { private: wpi::Joystick joystick{1}; ExampleSmartMotorController motor{1}; - wpi::math::SimpleMotorFeedforward feedforward{ + wpi::math::SimpleMotorFeedforward feedforward{ // Note: These gains are fake, and will have to be tuned for your robot. 1_V, 1.5_V * 1_s / 1_m}; // Create a motion profile with the given maximum velocity and maximum // acceleration constraints for the next setpoint. - wpi::math::TrapezoidProfile profile{ - {1.75_mps, 0.75_mps_sq}}; - wpi::math::TrapezoidProfile::State goal; - wpi::math::TrapezoidProfile::State setpoint; + wpi::math::TrapezoidProfile profile{ + {1.75_mps, 0.75_mps2}}; + wpi::math::TrapezoidProfile::State goal; + wpi::math::TrapezoidProfile::State setpoint; }; #ifndef RUNNING_WPILIB_TESTS diff --git a/wpilibcExamples/src/main/cpp/examples/MecanumBot/cpp/Drivetrain.cpp b/wpilibcExamples/src/main/cpp/examples/MecanumBot/cpp/Drivetrain.cpp index 19660e1b872..e201b952c50 100644 --- a/wpilibcExamples/src/main/cpp/examples/MecanumBot/cpp/Drivetrain.cpp +++ b/wpilibcExamples/src/main/cpp/examples/MecanumBot/cpp/Drivetrain.cpp @@ -8,18 +8,18 @@ wpi::math::MecanumDriveWheelPositions Drivetrain::GetCurrentWheelDistances() const { - return {wpi::units::meter_t{frontLeftEncoder.GetDistance()}, - wpi::units::meter_t{frontRightEncoder.GetDistance()}, - wpi::units::meter_t{backLeftEncoder.GetDistance()}, - wpi::units::meter_t{backRightEncoder.GetDistance()}}; + return {wpi::units::meters<>{frontLeftEncoder.GetDistance()}, + wpi::units::meters<>{frontRightEncoder.GetDistance()}, + wpi::units::meters<>{backLeftEncoder.GetDistance()}, + wpi::units::meters<>{backRightEncoder.GetDistance()}}; } wpi::math::MecanumDriveWheelVelocities Drivetrain::GetCurrentWheelVelocities() const { - return {wpi::units::meters_per_second_t{frontLeftEncoder.GetRate()}, - wpi::units::meters_per_second_t{frontRightEncoder.GetRate()}, - wpi::units::meters_per_second_t{backLeftEncoder.GetRate()}, - wpi::units::meters_per_second_t{backRightEncoder.GetRate()}}; + return {wpi::units::meters_per_second<>{frontLeftEncoder.GetRate()}, + wpi::units::meters_per_second<>{frontRightEncoder.GetRate()}, + wpi::units::meters_per_second<>{backLeftEncoder.GetRate()}, + wpi::units::meters_per_second<>{backRightEncoder.GetRate()}}; } void Drivetrain::SetVelocities( @@ -42,20 +42,20 @@ void Drivetrain::SetVelocities( const double backRightOutput = backRightPIDController.Calculate( backRightEncoder.GetRate(), wheelVelocities.rearRight.value()); - frontLeftMotor.SetVoltage(wpi::units::volt_t{frontLeftOutput} + + frontLeftMotor.SetVoltage(wpi::units::volts<>{frontLeftOutput} + frontLeftFeedforward); - frontRightMotor.SetVoltage(wpi::units::volt_t{frontRightOutput} + + frontRightMotor.SetVoltage(wpi::units::volts<>{frontRightOutput} + frontRightFeedforward); - backLeftMotor.SetVoltage(wpi::units::volt_t{backLeftOutput} + + backLeftMotor.SetVoltage(wpi::units::volts<>{backLeftOutput} + backLeftFeedforward); - backRightMotor.SetVoltage(wpi::units::volt_t{backRightOutput} + + backRightMotor.SetVoltage(wpi::units::volts<>{backRightOutput} + backRightFeedforward); } -void Drivetrain::Drive(wpi::units::meters_per_second_t xVelocity, - wpi::units::meters_per_second_t yVelocity, - wpi::units::radians_per_second_t rot, bool fieldRelative, - wpi::units::second_t period) { +void Drivetrain::Drive(wpi::units::meters_per_second<> xVelocity, + wpi::units::meters_per_second<> yVelocity, + wpi::units::radians_per_second<> rot, bool fieldRelative, + wpi::units::seconds<> period) { wpi::math::ChassisVelocities chassisVelocities{xVelocity, yVelocity, rot}; if (fieldRelative) { chassisVelocities = chassisVelocities.ToRobotRelative(imu.GetRotation2d()); diff --git a/wpilibcExamples/src/main/cpp/examples/MecanumBot/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/MecanumBot/cpp/Robot.cpp index 2eb98a114d4..41330875feb 100644 --- a/wpilibcExamples/src/main/cpp/examples/MecanumBot/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/examples/MecanumBot/cpp/Robot.cpp @@ -22,9 +22,11 @@ class Robot : public wpi::TimedRobot { // Slew rate limiters to make joystick inputs more gentle; 1/3 sec from 0 // to 1. - wpi::math::SlewRateLimiter xVelocityLimiter{3 / 1_s}; - wpi::math::SlewRateLimiter yVelocityLimiter{3 / 1_s}; - wpi::math::SlewRateLimiter rotLimiter{3 / 1_s}; + wpi::math::SlewRateLimiter xVelocityLimiter{3 / + 1_s}; + wpi::math::SlewRateLimiter yVelocityLimiter{3 / + 1_s}; + wpi::math::SlewRateLimiter rotLimiter{3 / 1_s}; void DriveWithJoystick(bool fieldRelative) { // Get the x velocity. We are inverting this because gamepads return diff --git a/wpilibcExamples/src/main/cpp/examples/MecanumBot/include/Drivetrain.hpp b/wpilibcExamples/src/main/cpp/examples/MecanumBot/include/Drivetrain.hpp index 14399adc66f..52fe0c52951 100644 --- a/wpilibcExamples/src/main/cpp/examples/MecanumBot/include/Drivetrain.hpp +++ b/wpilibcExamples/src/main/cpp/examples/MecanumBot/include/Drivetrain.hpp @@ -34,15 +34,15 @@ class Drivetrain { wpi::math::MecanumDriveWheelVelocities GetCurrentWheelVelocities() const; void SetVelocities( const wpi::math::MecanumDriveWheelVelocities& wheelVelocities); - void Drive(wpi::units::meters_per_second_t xVelocity, - wpi::units::meters_per_second_t yVelocity, - wpi::units::radians_per_second_t rot, bool fieldRelative, - wpi::units::second_t period); + void Drive(wpi::units::meters_per_second<> xVelocity, + wpi::units::meters_per_second<> yVelocity, + wpi::units::radians_per_second<> rot, bool fieldRelative, + wpi::units::seconds<> period); void UpdateOdometry(); - static constexpr wpi::units::meters_per_second_t MAX_VELOCITY = + static constexpr wpi::units::meters_per_second<> MAX_VELOCITY = 3.0_mps; // 3 meters per second - static constexpr wpi::units::radians_per_second_t MAX_ANGULAR_VELOCITY{ + static constexpr wpi::units::radians_per_second<> MAX_ANGULAR_VELOCITY{ std::numbers::pi}; // 1/2 rotation per second private: @@ -77,6 +77,6 @@ class Drivetrain { // Gains are for example purposes only - must be determined for your own // robot! - wpi::math::SimpleMotorFeedforward feedforward{ + wpi::math::SimpleMotorFeedforward feedforward{ 1_V, 3_V / 1_mps}; }; diff --git a/wpilibcExamples/src/main/cpp/examples/MecanumDrivePoseEstimator/cpp/Drivetrain.cpp b/wpilibcExamples/src/main/cpp/examples/MecanumDrivePoseEstimator/cpp/Drivetrain.cpp index ddc41bc01a8..440ffa7f674 100644 --- a/wpilibcExamples/src/main/cpp/examples/MecanumDrivePoseEstimator/cpp/Drivetrain.cpp +++ b/wpilibcExamples/src/main/cpp/examples/MecanumDrivePoseEstimator/cpp/Drivetrain.cpp @@ -9,32 +9,32 @@ wpi::math::MecanumDriveWheelPositions Drivetrain::GetCurrentWheelDistances() const { - return {wpi::units::meter_t{frontLeftEncoder.GetDistance()}, - wpi::units::meter_t{frontRightEncoder.GetDistance()}, - wpi::units::meter_t{backLeftEncoder.GetDistance()}, - wpi::units::meter_t{backRightEncoder.GetDistance()}}; + return {wpi::units::meters<>{frontLeftEncoder.GetDistance()}, + wpi::units::meters<>{frontRightEncoder.GetDistance()}, + wpi::units::meters<>{backLeftEncoder.GetDistance()}, + wpi::units::meters<>{backRightEncoder.GetDistance()}}; } wpi::math::MecanumDriveWheelVelocities Drivetrain::GetCurrentWheelVelocities() const { - return {wpi::units::meters_per_second_t{frontLeftEncoder.GetRate()}, - wpi::units::meters_per_second_t{frontRightEncoder.GetRate()}, - wpi::units::meters_per_second_t{backLeftEncoder.GetRate()}, - wpi::units::meters_per_second_t{backRightEncoder.GetRate()}}; + return {wpi::units::meters_per_second<>{frontLeftEncoder.GetRate()}, + wpi::units::meters_per_second<>{frontRightEncoder.GetRate()}, + wpi::units::meters_per_second<>{backLeftEncoder.GetRate()}, + wpi::units::meters_per_second<>{backRightEncoder.GetRate()}}; } void Drivetrain::SetVelocities( const wpi::math::MecanumDriveWheelVelocities& wheelVelocities) { - std::function, const wpi::Encoder&, wpi::math::PIDController&, wpi::PWMSparkMax&)> calcAndSetVelocities = - [&feedforward = feedforward](wpi::units::meters_per_second_t velocity, + [&feedforward = feedforward](wpi::units::meters_per_second<> velocity, const auto& encoder, auto& controller, auto& motor) { auto ff = feedforward.Calculate(velocity); double output = controller.Calculate(encoder.GetRate(), velocity.value()); - motor.SetVoltage(wpi::units::volt_t{output} + ff); + motor.SetVoltage(wpi::units::volts<>{output} + ff); }; calcAndSetVelocities(wheelVelocities.frontLeft, frontLeftEncoder, @@ -47,10 +47,10 @@ void Drivetrain::SetVelocities( backRightPIDController, backRightMotor); } -void Drivetrain::Drive(wpi::units::meters_per_second_t xVelocity, - wpi::units::meters_per_second_t yVelocity, - wpi::units::radians_per_second_t rot, bool fieldRelative, - wpi::units::second_t period) { +void Drivetrain::Drive(wpi::units::meters_per_second<> xVelocity, + wpi::units::meters_per_second<> yVelocity, + wpi::units::radians_per_second<> rot, bool fieldRelative, + wpi::units::seconds<> period) { wpi::math::ChassisVelocities chassisVelocities{xVelocity, yVelocity, rot}; if (fieldRelative) { chassisVelocities = chassisVelocities.ToRobotRelative( diff --git a/wpilibcExamples/src/main/cpp/examples/MecanumDrivePoseEstimator/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/MecanumDrivePoseEstimator/cpp/Robot.cpp index 2eb98a114d4..41330875feb 100644 --- a/wpilibcExamples/src/main/cpp/examples/MecanumDrivePoseEstimator/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/examples/MecanumDrivePoseEstimator/cpp/Robot.cpp @@ -22,9 +22,11 @@ class Robot : public wpi::TimedRobot { // Slew rate limiters to make joystick inputs more gentle; 1/3 sec from 0 // to 1. - wpi::math::SlewRateLimiter xVelocityLimiter{3 / 1_s}; - wpi::math::SlewRateLimiter yVelocityLimiter{3 / 1_s}; - wpi::math::SlewRateLimiter rotLimiter{3 / 1_s}; + wpi::math::SlewRateLimiter xVelocityLimiter{3 / + 1_s}; + wpi::math::SlewRateLimiter yVelocityLimiter{3 / + 1_s}; + wpi::math::SlewRateLimiter rotLimiter{3 / 1_s}; void DriveWithJoystick(bool fieldRelative) { // Get the x velocity. We are inverting this because gamepads return diff --git a/wpilibcExamples/src/main/cpp/examples/MecanumDrivePoseEstimator/include/Drivetrain.hpp b/wpilibcExamples/src/main/cpp/examples/MecanumDrivePoseEstimator/include/Drivetrain.hpp index 367c1890c15..45d0aa096d6 100644 --- a/wpilibcExamples/src/main/cpp/examples/MecanumDrivePoseEstimator/include/Drivetrain.hpp +++ b/wpilibcExamples/src/main/cpp/examples/MecanumDrivePoseEstimator/include/Drivetrain.hpp @@ -34,14 +34,14 @@ class Drivetrain { wpi::math::MecanumDriveWheelVelocities GetCurrentWheelVelocities() const; void SetVelocities( const wpi::math::MecanumDriveWheelVelocities& wheelVelocities); - void Drive(wpi::units::meters_per_second_t xVelocity, - wpi::units::meters_per_second_t yVelocity, - wpi::units::radians_per_second_t rot, bool fieldRelative, - wpi::units::second_t period); + void Drive(wpi::units::meters_per_second<> xVelocity, + wpi::units::meters_per_second<> yVelocity, + wpi::units::radians_per_second<> rot, bool fieldRelative, + wpi::units::seconds<> period); void UpdateOdometry(); static constexpr auto MAX_VELOCITY = 3.0_mps; // 3 meters per second - static constexpr wpi::units::radians_per_second_t MAX_ANGULAR_VELOCITY{ + static constexpr wpi::units::radians_per_second<> MAX_ANGULAR_VELOCITY{ std::numbers::pi}; // 1/2 rotation per second private: @@ -73,7 +73,7 @@ class Drivetrain { // Gains are for example purposes only - must be determined for your own // robot! - wpi::math::SimpleMotorFeedforward feedforward{ + wpi::math::SimpleMotorFeedforward feedforward{ 1_V, 3_V / 1_mps}; // Gains are for example purposes only - must be determined for your own diff --git a/wpilibcExamples/src/main/cpp/examples/MecanumDrivePoseEstimator/include/ExampleGlobalMeasurementSensor.hpp b/wpilibcExamples/src/main/cpp/examples/MecanumDrivePoseEstimator/include/ExampleGlobalMeasurementSensor.hpp index a004c8e5df1..f8e551d2c1e 100644 --- a/wpilibcExamples/src/main/cpp/examples/MecanumDrivePoseEstimator/include/ExampleGlobalMeasurementSensor.hpp +++ b/wpilibcExamples/src/main/cpp/examples/MecanumDrivePoseEstimator/include/ExampleGlobalMeasurementSensor.hpp @@ -17,9 +17,9 @@ class ExampleGlobalMeasurementSensor { const wpi::math::Pose2d& estimatedRobotPose) { auto randVec = wpi::math::Normal(0.1, 0.1, 0.1); return wpi::math::Pose2d{ - estimatedRobotPose.X() + wpi::units::meter_t{randVec(0)}, - estimatedRobotPose.Y() + wpi::units::meter_t{randVec(1)}, + estimatedRobotPose.X() + wpi::units::meters<>{randVec(0)}, + estimatedRobotPose.Y() + wpi::units::meters<>{randVec(1)}, estimatedRobotPose.Rotation() + - wpi::math::Rotation2d{wpi::units::radian_t{randVec(2)}}}; + wpi::math::Rotation2d{wpi::units::radians<>{randVec(2)}}}; } }; diff --git a/wpilibcExamples/src/main/cpp/examples/Mechanism2d/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/Mechanism2d/cpp/Robot.cpp index ff1bee89e5b..613d51a6427 100644 --- a/wpilibcExamples/src/main/cpp/examples/Mechanism2d/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/examples/Mechanism2d/cpp/Robot.cpp @@ -35,7 +35,7 @@ class Robot : public wpi::TimedRobot { // update the dashboard mechanism's state elevator->SetLength(ELEVATOR_MINIMUM_LENGTH + elevatorEncoder.GetDistance()); - wrist->SetAngle(wpi::units::degree_t{wristPotentiometer.Get()}); + wrist->SetAngle(wpi::units::degrees<>{wristPotentiometer.Get()}); // publish to telemetry wpi::telemetry::Log("Mech2d", mech); diff --git a/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/cpp/subsystems/Drive.cpp b/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/cpp/subsystems/Drive.cpp index fd554856a02..c4fb646bb6e 100644 --- a/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/cpp/subsystems/Drive.cpp +++ b/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/cpp/subsystems/Drive.cpp @@ -39,7 +39,7 @@ wpi::cmd::CommandPtr Drive::ArcadeDriveCommand(std::function fwd, .WithName("ArcadeDrive"); } -wpi::cmd::CommandPtr Drive::DriveDistanceCommand(wpi::units::meter_t distance, +wpi::cmd::CommandPtr Drive::DriveDistanceCommand(wpi::units::meters<> distance, double velocity) { return RunOnce([this] { // Reset encoders at the start of the command @@ -49,15 +49,15 @@ wpi::cmd::CommandPtr Drive::DriveDistanceCommand(wpi::units::meter_t distance, // Drive forward at specified velocity .AndThen(Run([this, velocity] { drive.ArcadeDrive(velocity, 0.0); })) .Until([this, distance] { - return wpi::units::math::max( - wpi::units::meter_t(leftEncoder.GetDistance()), - wpi::units::meter_t(rightEncoder.GetDistance())) >= distance; + return wpi::units::max(wpi::units::meters<>(leftEncoder.GetDistance()), + wpi::units::meters<>( + rightEncoder.GetDistance())) >= distance; }) // Stop the drive when the command ends .FinallyDo([this](bool interrupted) { drive.ArcadeDrive(0.0, 0.0); }); } -wpi::cmd::CommandPtr Drive::TurnToAngleCommand(wpi::units::degree_t angle) { +wpi::cmd::CommandPtr Drive::TurnToAngleCommand(wpi::units::degrees<> angle) { return StartRun([this] { controller.Reset(imu.GetRotation2d().Degrees()); }, [this, angle] { drive.ArcadeDrive( diff --git a/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/cpp/subsystems/Pneumatics.cpp b/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/cpp/subsystems/Pneumatics.cpp index a9bd132f0e6..828015b8f35 100644 --- a/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/cpp/subsystems/Pneumatics.cpp +++ b/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/cpp/subsystems/Pneumatics.cpp @@ -20,8 +20,8 @@ wpi::cmd::CommandPtr Pneumatics::DisableCompressorCommand() { }); } -wpi::units::pounds_per_square_inch_t Pneumatics::GetPressure() { +wpi::units::pounds_per_square_inch<> Pneumatics::GetPressure() { // Get the pressure (in PSI) from an analog pressure sensor connected to // the RIO. - return wpi::units::pounds_per_square_inch_t{pressureTransducer.Get()}; + return wpi::units::pounds_per_square_inch<>{pressureTransducer.Get()}; } diff --git a/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/cpp/subsystems/Shooter.cpp b/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/cpp/subsystems/Shooter.cpp index 84375494fa0..6a1eda0bf37 100644 --- a/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/cpp/subsystems/Shooter.cpp +++ b/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/cpp/subsystems/Shooter.cpp @@ -20,14 +20,14 @@ Shooter::Shooter() { } wpi::cmd::CommandPtr Shooter::ShootCommand( - wpi::units::turns_per_second_t setpoint) { + wpi::units::turns_per_second<> setpoint) { return wpi::cmd::Parallel( // Run the shooter flywheel at the desired setpoint using // feedforward and feedback Run([this, setpoint] { shooterMotor.SetVoltage( shooterFeedforward.Calculate(setpoint) + - wpi::units::volt_t(shooterFeedback.Calculate( + wpi::units::volts<>(shooterFeedback.Calculate( shooterEncoder.GetRate(), setpoint.value()))); }), // Wait until the shooter has reached the setpoint, and then diff --git a/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/include/Constants.hpp b/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/include/Constants.hpp index fe4a049988a..e1fe8552481 100644 --- a/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/include/Constants.hpp +++ b/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/include/Constants.hpp @@ -24,7 +24,7 @@ inline constexpr bool LEFT_ENCODER_REVERSED = false; inline constexpr bool RIGHT_ENCODER_REVERSED = true; inline constexpr double ENCODER_CPR = 1024; -inline constexpr wpi::units::meter_t WHEEL_DIAMETER = 6_in; +inline constexpr wpi::units::meters<> WHEEL_DIAMETER = 6_in; inline constexpr double ENCODER_DISTANCE_PER_PULSE = // Assumes the encoders are directly mounted on the wheel shafts ((WHEEL_DIAMETER * std::numbers::pi) / ENCODER_CPR).value(); @@ -76,7 +76,7 @@ inline constexpr auto SHOOTER_TOLERANCE = 50_tps; // robot. inline constexpr double kP = 1; -inline constexpr wpi::units::volt_t kS = 0.05_V; +inline constexpr wpi::units::volts<> kS = 0.05_V; // Should have value 12V at free speed inline constexpr auto kV = 12_V / SHOOTER_FREE; @@ -88,7 +88,7 @@ inline constexpr int DRIVER_CONTROLLER_PORT = 0; } // namespace OIConstants namespace AutoConstants { -constexpr wpi::units::second_t TIMEOUT = 3_s; -constexpr wpi::units::meter_t DRIVE_DISTANCE = 2_m; +constexpr wpi::units::seconds<> TIMEOUT = 3_s; +constexpr wpi::units::meters<> DRIVE_DISTANCE = 2_m; constexpr double DRIVE_VELOCITY = 0.5; } // namespace AutoConstants diff --git a/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/include/subsystems/Drive.hpp b/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/include/subsystems/Drive.hpp index 4beb113b573..714018f7bb4 100644 --- a/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/include/subsystems/Drive.hpp +++ b/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/include/subsystems/Drive.hpp @@ -37,7 +37,7 @@ class Drive : public wpi::cmd::SubsystemBase { * @param distance The distance to drive forward in meters * @param velocity The fraction of max velocity at which to drive */ - wpi::cmd::CommandPtr DriveDistanceCommand(wpi::units::meter_t distance, + wpi::cmd::CommandPtr DriveDistanceCommand(wpi::units::meters<> distance, double velocity); /** @@ -46,7 +46,7 @@ class Drive : public wpi::cmd::SubsystemBase { * * @param angle The angle to turn to */ - wpi::cmd::CommandPtr TurnToAngleCommand(wpi::units::degree_t angle); + wpi::cmd::CommandPtr TurnToAngleCommand(wpi::units::degrees<> angle); private: wpi::PWMSparkMax leftLeader{DriveConstants::LEFT_MOTOR1_PORT}; @@ -67,11 +67,11 @@ class Drive : public wpi::cmd::SubsystemBase { wpi::OnboardIMU imu{wpi::OnboardIMU::FLAT}; - wpi::math::ProfiledPIDController controller{ + wpi::math::ProfiledPIDController controller{ DriveConstants::TURN_P, DriveConstants::TURN_I, DriveConstants::TURN_D, {DriveConstants::MAX_TURN_RATE, DriveConstants::MAX_TURN_ACCELERATION}}; - wpi::math::SimpleMotorFeedforward feedforward{ + wpi::math::SimpleMotorFeedforward feedforward{ DriveConstants::ks, DriveConstants::kv, DriveConstants::ka}; }; diff --git a/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/include/subsystems/Pneumatics.hpp b/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/include/subsystems/Pneumatics.hpp index 844d1bcecc7..1c431e3e7a8 100644 --- a/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/include/subsystems/Pneumatics.hpp +++ b/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/include/subsystems/Pneumatics.hpp @@ -23,7 +23,7 @@ class Pneumatics : wpi::cmd::SubsystemBase { * * @return the measured pressure, in PSI */ - wpi::units::pounds_per_square_inch_t GetPressure(); + wpi::units::pounds_per_square_inch<> GetPressure(); private: // External analog pressure sensor diff --git a/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/include/subsystems/Shooter.hpp b/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/include/subsystems/Shooter.hpp index 96d10c619b5..4961ef0513b 100644 --- a/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/include/subsystems/Shooter.hpp +++ b/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/include/subsystems/Shooter.hpp @@ -27,7 +27,7 @@ class Shooter : public wpi::cmd::SubsystemBase { * * @param setpointRotationsPerSecond The desired shooter velocity */ - wpi::cmd::CommandPtr ShootCommand(wpi::units::turns_per_second_t setpoint); + wpi::cmd::CommandPtr ShootCommand(wpi::units::turns_per_second<> setpoint); private: wpi::PWMSparkMax shooterMotor{ShooterConstants::SHOOTER_MOTOR_PORT}; @@ -36,7 +36,7 @@ class Shooter : public wpi::cmd::SubsystemBase { wpi::Encoder shooterEncoder{ShooterConstants::ENCODER_PORTS[0], ShooterConstants::ENCODER_PORTS[1], ShooterConstants::ENCODER_REVERSED}; - wpi::math::SimpleMotorFeedforward shooterFeedforward{ + wpi::math::SimpleMotorFeedforward shooterFeedforward{ ShooterConstants::kS, ShooterConstants::kV}; wpi::math::PIDController shooterFeedback{ShooterConstants::kP, 0.0, 0.0}; }; diff --git a/wpilibcExamples/src/main/cpp/examples/RomiReference/cpp/commands/DriveDistance.cpp b/wpilibcExamples/src/main/cpp/examples/RomiReference/cpp/commands/DriveDistance.cpp index d3d186cff2d..ba6fbcbf6e2 100644 --- a/wpilibcExamples/src/main/cpp/examples/RomiReference/cpp/commands/DriveDistance.cpp +++ b/wpilibcExamples/src/main/cpp/examples/RomiReference/cpp/commands/DriveDistance.cpp @@ -4,8 +4,6 @@ #include "commands/DriveDistance.hpp" -#include "wpi/units/math.hpp" - void DriveDistance::Initialize() { drive->ArcadeDrive(0, 0); drive->ResetEncoders(); @@ -20,5 +18,5 @@ void DriveDistance::End(bool interrupted) { } bool DriveDistance::IsFinished() { - return wpi::units::math::abs(drive->GetAverageDistance()) >= distance; + return wpi::units::abs(drive->GetAverageDistance()) >= distance; } diff --git a/wpilibcExamples/src/main/cpp/examples/RomiReference/cpp/commands/TurnDegrees.cpp b/wpilibcExamples/src/main/cpp/examples/RomiReference/cpp/commands/TurnDegrees.cpp index 27a25e1591b..76a39791548 100644 --- a/wpilibcExamples/src/main/cpp/examples/RomiReference/cpp/commands/TurnDegrees.cpp +++ b/wpilibcExamples/src/main/cpp/examples/RomiReference/cpp/commands/TurnDegrees.cpp @@ -6,8 +6,6 @@ #include -#include "wpi/units/math.hpp" - void TurnDegrees::Initialize() { // Set motors to stop, read encoder values for starting point drive->ArcadeDrive(0, 0); @@ -33,8 +31,8 @@ bool TurnDegrees::IsFinished() { return GetAverageTurningDistance() >= inchPerDegree * angle; } -wpi::units::meter_t TurnDegrees::GetAverageTurningDistance() { - auto l = wpi::units::math::abs(drive->GetLeftDistance()); - auto r = wpi::units::math::abs(drive->GetRightDistance()); +wpi::units::meters<> TurnDegrees::GetAverageTurningDistance() { + auto l = wpi::units::abs(drive->GetLeftDistance()); + auto r = wpi::units::abs(drive->GetRightDistance()); return (l + r) / 2; } diff --git a/wpilibcExamples/src/main/cpp/examples/RomiReference/cpp/subsystems/Drivetrain.cpp b/wpilibcExamples/src/main/cpp/examples/RomiReference/cpp/subsystems/Drivetrain.cpp index 2b1fae45566..1a626641e24 100644 --- a/wpilibcExamples/src/main/cpp/examples/RomiReference/cpp/subsystems/Drivetrain.cpp +++ b/wpilibcExamples/src/main/cpp/examples/RomiReference/cpp/subsystems/Drivetrain.cpp @@ -48,27 +48,27 @@ int Drivetrain::GetRightEncoderCount() { return rightEncoder.Get(); } -wpi::units::meter_t Drivetrain::GetLeftDistance() { - return wpi::units::meter_t{leftEncoder.GetDistance()}; +wpi::units::meters<> Drivetrain::GetLeftDistance() { + return wpi::units::meters<>{leftEncoder.GetDistance()}; } -wpi::units::meter_t Drivetrain::GetRightDistance() { - return wpi::units::meter_t{rightEncoder.GetDistance()}; +wpi::units::meters<> Drivetrain::GetRightDistance() { + return wpi::units::meters<>{rightEncoder.GetDistance()}; } -wpi::units::meter_t Drivetrain::GetAverageDistance() { +wpi::units::meters<> Drivetrain::GetAverageDistance() { return (GetLeftDistance() + GetRightDistance()) / 2.0; } -wpi::units::radian_t Drivetrain::GetGyroAngleX() { +wpi::units::radians<> Drivetrain::GetGyroAngleX() { return gyro.GetAngleX(); } -wpi::units::radian_t Drivetrain::GetGyroAngleY() { +wpi::units::radians<> Drivetrain::GetGyroAngleY() { return gyro.GetAngleY(); } -wpi::units::radian_t Drivetrain::GetGyroAngleZ() { +wpi::units::radians<> Drivetrain::GetGyroAngleZ() { return gyro.GetAngleZ(); } diff --git a/wpilibcExamples/src/main/cpp/examples/RomiReference/include/commands/DriveDistance.hpp b/wpilibcExamples/src/main/cpp/examples/RomiReference/include/commands/DriveDistance.hpp index 9b2a3f33790..c99dada5072 100644 --- a/wpilibcExamples/src/main/cpp/examples/RomiReference/include/commands/DriveDistance.hpp +++ b/wpilibcExamples/src/main/cpp/examples/RomiReference/include/commands/DriveDistance.hpp @@ -20,7 +20,7 @@ class DriveDistance * @param distance The distance the robot will drive * @param drive The drivetrain subsystem on which this command will run */ - DriveDistance(double velocity, wpi::units::meter_t distance, + DriveDistance(double velocity, wpi::units::meters<> distance, Drivetrain* drive) : velocity(velocity), distance(distance), drive(drive) { AddRequirements(drive); @@ -33,6 +33,6 @@ class DriveDistance private: double velocity; - wpi::units::meter_t distance; + wpi::units::meters<> distance; Drivetrain* drive; }; diff --git a/wpilibcExamples/src/main/cpp/examples/RomiReference/include/commands/DriveTime.hpp b/wpilibcExamples/src/main/cpp/examples/RomiReference/include/commands/DriveTime.hpp index fc3a458268d..b881143e6e6 100644 --- a/wpilibcExamples/src/main/cpp/examples/RomiReference/include/commands/DriveTime.hpp +++ b/wpilibcExamples/src/main/cpp/examples/RomiReference/include/commands/DriveTime.hpp @@ -21,7 +21,7 @@ class DriveTime : public wpi::cmd::CommandHelper { * @param time How much time to drive * @param drive The drivetrain subsystem on which this command will run */ - DriveTime(double velocity, wpi::units::second_t time, Drivetrain* drive) + DriveTime(double velocity, wpi::units::seconds<> time, Drivetrain* drive) : velocity(velocity), duration(time), drive(drive) { AddRequirements(drive); } @@ -33,7 +33,7 @@ class DriveTime : public wpi::cmd::CommandHelper { private: double velocity; - wpi::units::second_t duration; + wpi::units::seconds<> duration; Drivetrain* drive; wpi::Timer timer; }; diff --git a/wpilibcExamples/src/main/cpp/examples/RomiReference/include/commands/TurnDegrees.hpp b/wpilibcExamples/src/main/cpp/examples/RomiReference/include/commands/TurnDegrees.hpp index 2b049ae67a0..ce81e9a5856 100644 --- a/wpilibcExamples/src/main/cpp/examples/RomiReference/include/commands/TurnDegrees.hpp +++ b/wpilibcExamples/src/main/cpp/examples/RomiReference/include/commands/TurnDegrees.hpp @@ -22,7 +22,7 @@ class TurnDegrees * @param degrees Degrees to turn. Leverages encoders to compare distance. * @param drive The drive subsystem on which this command will run */ - TurnDegrees(double velocity, wpi::units::degree_t angle, Drivetrain* drive) + TurnDegrees(double velocity, wpi::units::degrees<> angle, Drivetrain* drive) : velocity(velocity), angle(angle), drive(drive) { AddRequirements(drive); } @@ -34,8 +34,8 @@ class TurnDegrees private: double velocity; - wpi::units::degree_t angle; + wpi::units::degrees<> angle; Drivetrain* drive; - wpi::units::meter_t GetAverageTurningDistance(); + wpi::units::meters<> GetAverageTurningDistance(); }; diff --git a/wpilibcExamples/src/main/cpp/examples/RomiReference/include/commands/TurnTime.hpp b/wpilibcExamples/src/main/cpp/examples/RomiReference/include/commands/TurnTime.hpp index 24e179c8c66..85ca1cacec4 100644 --- a/wpilibcExamples/src/main/cpp/examples/RomiReference/include/commands/TurnTime.hpp +++ b/wpilibcExamples/src/main/cpp/examples/RomiReference/include/commands/TurnTime.hpp @@ -20,7 +20,7 @@ class TurnTime : public wpi::cmd::CommandHelper { * @param time How much time to turn * @param drive The drive subsystem on which this command will run */ - TurnTime(double velocity, wpi::units::second_t time, Drivetrain* drive) + TurnTime(double velocity, wpi::units::seconds<> time, Drivetrain* drive) : velocity(velocity), duration(time), drive(drive) { AddRequirements(drive); } @@ -32,7 +32,7 @@ class TurnTime : public wpi::cmd::CommandHelper { private: double velocity; - wpi::units::second_t duration; + wpi::units::seconds<> duration; Drivetrain* drive; wpi::Timer timer; }; diff --git a/wpilibcExamples/src/main/cpp/examples/RomiReference/include/subsystems/Drivetrain.hpp b/wpilibcExamples/src/main/cpp/examples/RomiReference/include/subsystems/Drivetrain.hpp index 53137a2f0f9..317de5c3ad1 100644 --- a/wpilibcExamples/src/main/cpp/examples/RomiReference/include/subsystems/Drivetrain.hpp +++ b/wpilibcExamples/src/main/cpp/examples/RomiReference/include/subsystems/Drivetrain.hpp @@ -15,7 +15,7 @@ class Drivetrain : public wpi::cmd::SubsystemBase { public: static constexpr double COUNTS_PER_REVOLUTION = 1440.0; - static constexpr wpi::units::meter_t WHEEL_DIAMETER = 70_mm; + static constexpr wpi::units::meters<> WHEEL_DIAMETER = 70_mm; Drivetrain(); @@ -56,42 +56,42 @@ class Drivetrain : public wpi::cmd::SubsystemBase { * * @return the left-side distance driven */ - wpi::units::meter_t GetLeftDistance(); + wpi::units::meters<> GetLeftDistance(); /** * Gets the right distance driven. * * @return the right-side distance driven */ - wpi::units::meter_t GetRightDistance(); + wpi::units::meters<> GetRightDistance(); /** * Returns the average distance traveled by the left and right encoders. * * @return The average distance traveled by the left and right encoders. */ - wpi::units::meter_t GetAverageDistance(); + wpi::units::meters<> GetAverageDistance(); /** * Current angle of the Romi around the X-axis. * * @return The current angle of the Romi. */ - wpi::units::radian_t GetGyroAngleX(); + wpi::units::radians<> GetGyroAngleX(); /** * Current angle of the Romi around the Y-axis. * * @return The current angle of the Romi. */ - wpi::units::radian_t GetGyroAngleY(); + wpi::units::radians<> GetGyroAngleY(); /** * Current angle of the Romi around the Z-axis. * * @return The current angle of the Romi. */ - wpi::units::radian_t GetGyroAngleZ(); + wpi::units::radians<> GetGyroAngleZ(); /** * Reset the gyro. diff --git a/wpilibcExamples/src/main/cpp/examples/SimpleDifferentialDriveSimulation/cpp/Drivetrain.cpp b/wpilibcExamples/src/main/cpp/examples/SimpleDifferentialDriveSimulation/cpp/Drivetrain.cpp index a27c816042e..89bf9720312 100644 --- a/wpilibcExamples/src/main/cpp/examples/SimpleDifferentialDriveSimulation/cpp/Drivetrain.cpp +++ b/wpilibcExamples/src/main/cpp/examples/SimpleDifferentialDriveSimulation/cpp/Drivetrain.cpp @@ -16,26 +16,26 @@ void Drivetrain::SetVelocities( double rightOutput = rightPIDController.Calculate(rightEncoder.GetRate(), velocities.right.value()); - leftLeader.SetVoltage(wpi::units::volt_t{leftOutput} + leftFeedforward); - rightLeader.SetVoltage(wpi::units::volt_t{rightOutput} + rightFeedforward); + leftLeader.SetVoltage(wpi::units::volts<>{leftOutput} + leftFeedforward); + rightLeader.SetVoltage(wpi::units::volts<>{rightOutput} + rightFeedforward); } -void Drivetrain::Drive(wpi::units::meters_per_second_t xVelocity, - wpi::units::radians_per_second_t rot) { +void Drivetrain::Drive(wpi::units::meters_per_second<> xVelocity, + wpi::units::radians_per_second<> rot) { SetVelocities(kinematics.ToWheelVelocities({xVelocity, 0_mps, rot})); } void Drivetrain::UpdateOdometry() { odometry.Update(imu.GetRotation2d(), - wpi::units::meter_t{leftEncoder.GetDistance()}, - wpi::units::meter_t{rightEncoder.GetDistance()}); + wpi::units::meters<>{leftEncoder.GetDistance()}, + wpi::units::meters<>{rightEncoder.GetDistance()}); } void Drivetrain::ResetOdometry(const wpi::math::Pose2d& pose) { drivetrainSimulator.SetPose(pose); - odometry.ResetPosition(imu.GetRotation2d(), - wpi::units::meter_t{leftEncoder.GetDistance()}, - wpi::units::meter_t{rightEncoder.GetDistance()}, pose); + odometry.ResetPosition( + imu.GetRotation2d(), wpi::units::meters<>{leftEncoder.GetDistance()}, + wpi::units::meters<>{rightEncoder.GetDistance()}, pose); } void Drivetrain::SimulationPeriodic() { @@ -43,9 +43,9 @@ void Drivetrain::SimulationPeriodic() { // simulation, and write the simulated positions and velocities to our // simulated encoder and gyro. We negate the right side so that positive // voltages make the right side move forward. - drivetrainSimulator.SetInputs(wpi::units::volt_t{leftLeader.GetThrottle()} * + drivetrainSimulator.SetInputs(wpi::units::volts<>{leftLeader.GetThrottle()} * wpi::RobotController::GetInputVoltage(), - wpi::units::volt_t{rightLeader.GetThrottle()} * + wpi::units::volts<>{rightLeader.GetThrottle()} * wpi::RobotController::GetInputVoltage()); drivetrainSimulator.Update(20_ms); diff --git a/wpilibcExamples/src/main/cpp/examples/SimpleDifferentialDriveSimulation/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/SimpleDifferentialDriveSimulation/cpp/Robot.cpp index 0e94e766785..284c72c723c 100644 --- a/wpilibcExamples/src/main/cpp/examples/SimpleDifferentialDriveSimulation/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/examples/SimpleDifferentialDriveSimulation/cpp/Robot.cpp @@ -16,7 +16,7 @@ class Robot : public wpi::TimedRobot { : trajectory(wpi::math::DrivetrainSplineTrajectoryGenerator::Generate( wpi::math::Pose2d{2_m, 2_m, 0_rad}, {}, wpi::math::Pose2d{6_m, 4_m, 0_rad}, - wpi::math::TrajectoryConfig(2_mps, 2_mps_sq))) {} + wpi::math::TrajectoryConfig(2_mps, 2_mps2))) {} void RobotPeriodic() override { drive.Periodic(); } @@ -55,8 +55,9 @@ class Robot : public wpi::TimedRobot { // Slew rate limiters to make joystick inputs more gentle; 1/3 sec from 0 // to 1. - wpi::math::SlewRateLimiter velocityLimiter{3 / 1_s}; - wpi::math::SlewRateLimiter rotLimiter{3 / 1_s}; + wpi::math::SlewRateLimiter velocityLimiter{3 / + 1_s}; + wpi::math::SlewRateLimiter rotLimiter{3 / 1_s}; Drivetrain drive; wpi::math::DrivetrainSplineTrajectory trajectory; diff --git a/wpilibcExamples/src/main/cpp/examples/SimpleDifferentialDriveSimulation/include/Drivetrain.hpp b/wpilibcExamples/src/main/cpp/examples/SimpleDifferentialDriveSimulation/include/Drivetrain.hpp index c87ab945444..789717766f8 100644 --- a/wpilibcExamples/src/main/cpp/examples/SimpleDifferentialDriveSimulation/include/Drivetrain.hpp +++ b/wpilibcExamples/src/main/cpp/examples/SimpleDifferentialDriveSimulation/include/Drivetrain.hpp @@ -51,15 +51,15 @@ class Drivetrain { rightLeader.SetInverted(true); } - static constexpr wpi::units::meters_per_second_t MAX_VELOCITY = + static constexpr wpi::units::meters_per_second<> MAX_VELOCITY = 3.0_mps; // 3 meters per second - static constexpr wpi::units::radians_per_second_t MAX_ANGULAR_VELOCITY{ + static constexpr wpi::units::radians_per_second<> MAX_ANGULAR_VELOCITY{ std::numbers::pi}; // 1/2 rotation per second void SetVelocities( const wpi::math::DifferentialDriveWheelVelocities& velocities); - void Drive(wpi::units::meters_per_second_t xVelocity, - wpi::units::radians_per_second_t rot); + void Drive(wpi::units::meters_per_second<> xVelocity, + wpi::units::radians_per_second<> rot); void UpdateOdometry(); void ResetOdometry(const wpi::math::Pose2d& pose); @@ -69,7 +69,7 @@ class Drivetrain { void Periodic(); private: - static constexpr wpi::units::meter_t TRACKWIDTH = 0.381_m * 2; + static constexpr wpi::units::meters<> TRACKWIDTH = 0.381_m * 2; static constexpr double WHEEL_RADIUS = 0.0508; // meters static constexpr int ENCODER_RESOLUTION = 4096; @@ -88,12 +88,12 @@ class Drivetrain { wpi::math::DifferentialDriveKinematics kinematics{TRACKWIDTH}; wpi::math::DifferentialDriveOdometry odometry{ - imu.GetRotation2d(), wpi::units::meter_t{leftEncoder.GetDistance()}, - wpi::units::meter_t{rightEncoder.GetDistance()}}; + imu.GetRotation2d(), wpi::units::meters<>{leftEncoder.GetDistance()}, + wpi::units::meters<>{rightEncoder.GetDistance()}}; // Gains are for example purposes only - must be determined for your own // robot! - wpi::math::SimpleMotorFeedforward feedforward{ + wpi::math::SimpleMotorFeedforward feedforward{ 1_V, 3_V / 1_mps}; // Simulation classes help us simulate our robot @@ -102,7 +102,7 @@ class Drivetrain { wpi::Field2d fieldSim; wpi::math::LinearSystem<2, 2, 2> drivetrainSystem = wpi::math::Models::DifferentialDriveFromSysId( - 1.98_V / 1_mps, 0.2_V / 1_mps_sq, 1.5_V / 1_mps, 0.3_V / 1_mps_sq); + 1.98_V / 1_mps, 0.2_V / 1_mps2, 1.5_V / 1_mps, 0.3_V / 1_mps2); wpi::sim::DifferentialDrivetrainSim drivetrainSimulator{ drivetrainSystem, TRACKWIDTH, wpi::math::DCMotor::CIM(2), 8, 2_in}; }; diff --git a/wpilibcExamples/src/main/cpp/examples/StateSpaceArm/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/StateSpaceArm/cpp/Robot.cpp index 630928f37b7..3b29feea8ff 100644 --- a/wpilibcExamples/src/main/cpp/examples/StateSpaceArm/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/examples/StateSpaceArm/cpp/Robot.cpp @@ -27,13 +27,13 @@ class Robot : public wpi::TimedRobot { static constexpr int ENCODER_B_CHANNEL = 1; static constexpr int JOYSTICK_PORT = 0; - static constexpr wpi::units::radian_t RAISED_POSITION = 90_deg; - static constexpr wpi::units::radian_t LOWERED_POSITION = 0_deg; + static constexpr wpi::units::radians<> RAISED_POSITION = 90_deg; + static constexpr wpi::units::radians<> LOWERED_POSITION = 0_deg; // Moment of inertia of the arm. Can be estimated with CAD. If finding this // constant is difficult, wpi::math::LinearSystem.identifyPositionSystem may // be better. - static constexpr wpi::units::kilogram_square_meter_t ARM_MOI = 1.2_kg_sq_m; + static constexpr wpi::units::kilogram_square_meters<> ARM_MOI = 1.2_kg_sq_m; // Reduction between motors and encoder, as output over input. If the arm // spins slower than the motors, this number should be greater than one. @@ -87,10 +87,11 @@ class Robot : public wpi::TimedRobot { wpi::PWMSparkMax motor{MOTOR_PORT}; wpi::Gamepad joystick{JOYSTICK_PORT}; - wpi::math::TrapezoidProfile profile{ + wpi::math::TrapezoidProfile profile{ {45_deg_per_s, 90_deg_per_s / 1_s}}; - wpi::math::TrapezoidProfile::State lastProfiledReference; + wpi::math::TrapezoidProfile::State + lastProfiledReference; public: Robot() { @@ -102,14 +103,14 @@ class Robot : public wpi::TimedRobot { loop.Reset(wpi::math::Vectord<2>{encoder.GetDistance(), encoder.GetRate()}); lastProfiledReference = { - wpi::units::radian_t{encoder.GetDistance()}, - wpi::units::radians_per_second_t{encoder.GetRate()}}; + wpi::units::radians<>{encoder.GetDistance()}, + wpi::units::radians_per_second<>{encoder.GetRate()}}; } void TeleopPeriodic() override { // Sets the target position of our arm. This is similar to setting the // setpoint of a PID controller. - wpi::math::TrapezoidProfile::State goal; + wpi::math::TrapezoidProfile::State goal; if (joystick.GetRightBumperButton()) { // We pressed the bumper, so let's set our next reference goal = {RAISED_POSITION, 0_rad_per_s}; @@ -134,7 +135,7 @@ class Robot : public wpi::TimedRobot { // Send the new calculated voltage to the motors. // voltage = duty cycle * battery voltage, so // duty cycle = voltage / battery voltage - motor.SetVoltage(wpi::units::volt_t{loop.U(0)}); + motor.SetVoltage(wpi::units::volts<>{loop.U(0)}); } }; diff --git a/wpilibcExamples/src/main/cpp/examples/StateSpaceElevator/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/StateSpaceElevator/cpp/Robot.cpp index 2f9013bf9e8..9669d09faaf 100644 --- a/wpilibcExamples/src/main/cpp/examples/StateSpaceElevator/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/examples/StateSpaceElevator/cpp/Robot.cpp @@ -29,11 +29,11 @@ class Robot : public wpi::TimedRobot { static constexpr int ENCODER_B_CHANNEL = 1; static constexpr int JOYSTICK_PORT = 0; - static constexpr wpi::units::meter_t RAISED_POSITION = 2_ft; - static constexpr wpi::units::meter_t LOWERED_POSITION = 0_ft; + static constexpr wpi::units::meters<> RAISED_POSITION = 2_ft; + static constexpr wpi::units::meters<> LOWERED_POSITION = 0_ft; - static constexpr wpi::units::meter_t DRUM_RADIUS = 0.75_in; - static constexpr wpi::units::kilogram_t CARRIAGE_MASS = 4.5_kg; + static constexpr wpi::units::meters<> DRUM_RADIUS = 0.75_in; + static constexpr wpi::units::kilograms<> CARRIAGE_MASS = 4.5_kg; static constexpr double GEAR_RATIO = 6.0; // The plant holds a state-space model of our elevator. This system has the @@ -50,8 +50,8 @@ class Robot : public wpi::TimedRobot { // The observer fuses our encoder data and voltage inputs to reject noise. wpi::math::KalmanFilter<2, 1, 1> observer{ elevatorPlant, - {wpi::units::meter_t{2_in}.value(), - wpi::units::meters_per_second_t{40_in / 1_s} + {wpi::units::meters<>{2_in}.value(), + wpi::units::meters_per_second<>{40_in / 1_s} .value()}, // How accurate we think our model is {0.001}, // How accurate we think our encoder position // data is. In this case we very highly trust our encoder position @@ -64,8 +64,8 @@ class Robot : public wpi::TimedRobot { // qelms. State error tolerance, in meters and meters per second. // Decrease this to more heavily penalize state excursion, or make the // controller behave more aggressively. - {wpi::units::meter_t{1_in}.value(), - wpi::units::meters_per_second_t{10_in / 1_s}.value()}, + {wpi::units::meters<>{1_in}.value(), + wpi::units::meters_per_second<>{10_in / 1_s}.value()}, // relms. Control effort (voltage) tolerance. Decrease this to more // heavily penalize control effort, or make the controller less // aggressive. 12 is a good starting point because that is the @@ -86,9 +86,9 @@ class Robot : public wpi::TimedRobot { wpi::PWMSparkMax motor{MOTOR_PORT}; wpi::Gamepad joystick{JOYSTICK_PORT}; - wpi::math::TrapezoidProfile profile{{3_fps, 6_fps_sq}}; + wpi::math::TrapezoidProfile profile{{3_fps, 6_fps2}}; - wpi::math::TrapezoidProfile::State lastProfiledReference; + wpi::math::TrapezoidProfile::State lastProfiledReference; public: Robot() { @@ -102,14 +102,14 @@ class Robot : public wpi::TimedRobot { loop.Reset(wpi::math::Vectord<2>{encoder.GetDistance(), encoder.GetRate()}); lastProfiledReference = { - wpi::units::meter_t{encoder.GetDistance()}, - wpi::units::meters_per_second_t{encoder.GetRate()}}; + wpi::units::meters<>{encoder.GetDistance()}, + wpi::units::meters_per_second<>{encoder.GetRate()}}; } void TeleopPeriodic() override { // Sets the target height of our elevator. This is similar to setting the // setpoint of a PID controller. - wpi::math::TrapezoidProfile::State goal; + wpi::math::TrapezoidProfile::State goal; if (joystick.GetRightBumperButton()) { // We pressed the bumper, so let's set our next reference goal = {RAISED_POSITION, 0_fps}; @@ -134,7 +134,7 @@ class Robot : public wpi::TimedRobot { // Send the new calculated voltage to the motors. // voltage = duty cycle * battery voltage, so // duty cycle = voltage / battery voltage - motor.SetVoltage(wpi::units::volt_t{loop.U(0)}); + motor.SetVoltage(wpi::units::volts<>{loop.U(0)}); } }; diff --git a/wpilibcExamples/src/main/cpp/examples/StateSpaceFlywheel/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/StateSpaceFlywheel/cpp/Robot.cpp index 548fc4ad7ab..5e7e9609d4b 100644 --- a/wpilibcExamples/src/main/cpp/examples/StateSpaceFlywheel/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/examples/StateSpaceFlywheel/cpp/Robot.cpp @@ -24,9 +24,9 @@ class Robot : public wpi::TimedRobot { static constexpr int ENCODER_A_CHANNEL = 0; static constexpr int ENCODER_B_CHANNEL = 1; static constexpr int JOYSTICK_PORT = 0; - static constexpr wpi::units::radians_per_second_t SPINUP = 500_rpm; + static constexpr wpi::units::radians_per_second<> SPINUP = 500_rpm; - static constexpr wpi::units::kilogram_square_meter_t + static constexpr wpi::units::kilogram_square_meters<> FLYWHEEL_MOMENT_OF_INERTIA = 0.00032_kg_sq_m; // Reduction between motors and encoder, as output over input. If the flywheel @@ -109,7 +109,7 @@ class Robot : public wpi::TimedRobot { // Send the new calculated voltage to the motors. // voltage = duty cycle * battery voltage, so // duty cycle = voltage / battery voltage - motor.SetVoltage(wpi::units::volt_t{loop.U(0)}); + motor.SetVoltage(wpi::units::volts<>{loop.U(0)}); } }; diff --git a/wpilibcExamples/src/main/cpp/examples/StateSpaceFlywheelSysId/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/StateSpaceFlywheelSysId/cpp/Robot.cpp index 5692265b2de..553be217d29 100644 --- a/wpilibcExamples/src/main/cpp/examples/StateSpaceFlywheelSysId/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/examples/StateSpaceFlywheelSysId/cpp/Robot.cpp @@ -22,7 +22,7 @@ class Robot : public wpi::TimedRobot { static constexpr int ENCODER_A_CHANNEL = 0; static constexpr int ENCODER_B_CHANNEL = 1; static constexpr int JOYSTICK_PORT = 0; - static constexpr wpi::units::radians_per_second_t SPINUP = 500_rpm; + static constexpr wpi::units::radians_per_second<> SPINUP = 500_rpm; // Volts per (radian per second) static constexpr auto FLYWHEEL_KV = 0.023_V / 1_rad_per_s; @@ -106,7 +106,7 @@ class Robot : public wpi::TimedRobot { // Send the new calculated voltage to the motors. // voltage = duty cycle * battery voltage, so // duty cycle = voltage / battery voltage - motor.SetVoltage(wpi::units::volt_t{loop.U(0)}); + motor.SetVoltage(wpi::units::volts<>{loop.U(0)}); } }; diff --git a/wpilibcExamples/src/main/cpp/examples/SwerveBot/cpp/Drivetrain.cpp b/wpilibcExamples/src/main/cpp/examples/SwerveBot/cpp/Drivetrain.cpp index e60fb8bffb1..2b708ec34c0 100644 --- a/wpilibcExamples/src/main/cpp/examples/SwerveBot/cpp/Drivetrain.cpp +++ b/wpilibcExamples/src/main/cpp/examples/SwerveBot/cpp/Drivetrain.cpp @@ -4,10 +4,10 @@ #include "Drivetrain.hpp" -void Drivetrain::Drive(wpi::units::meters_per_second_t xVelocity, - wpi::units::meters_per_second_t yVelocity, - wpi::units::radians_per_second_t rot, bool fieldRelative, - wpi::units::second_t period) { +void Drivetrain::Drive(wpi::units::meters_per_second<> xVelocity, + wpi::units::meters_per_second<> yVelocity, + wpi::units::radians_per_second<> rot, bool fieldRelative, + wpi::units::seconds<> period) { wpi::math::ChassisVelocities chassisVelocities{xVelocity, yVelocity, rot}; if (fieldRelative) { chassisVelocities = chassisVelocities.ToRobotRelative(imu.GetRotation2d()); diff --git a/wpilibcExamples/src/main/cpp/examples/SwerveBot/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/SwerveBot/cpp/Robot.cpp index 0ab185d023c..027f2361f97 100644 --- a/wpilibcExamples/src/main/cpp/examples/SwerveBot/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/examples/SwerveBot/cpp/Robot.cpp @@ -23,9 +23,11 @@ class Robot : public wpi::TimedRobot { // Slew rate limiters to make joystick inputs more gentle; 1/3 sec from 0 // to 1. - wpi::math::SlewRateLimiter xVelocityLimiter{3 / 1_s}; - wpi::math::SlewRateLimiter yVelocityLimiter{3 / 1_s}; - wpi::math::SlewRateLimiter rotLimiter{3 / 1_s}; + wpi::math::SlewRateLimiter xVelocityLimiter{3 / + 1_s}; + wpi::math::SlewRateLimiter yVelocityLimiter{3 / + 1_s}; + wpi::math::SlewRateLimiter rotLimiter{3 / 1_s}; void DriveWithJoystick(bool fieldRelative) { // Get the x velocity. We are inverting this because gamepads return diff --git a/wpilibcExamples/src/main/cpp/examples/SwerveBot/cpp/SwerveModule.cpp b/wpilibcExamples/src/main/cpp/examples/SwerveBot/cpp/SwerveModule.cpp index c36dd3aae24..e3e67d54c19 100644 --- a/wpilibcExamples/src/main/cpp/examples/SwerveBot/cpp/SwerveModule.cpp +++ b/wpilibcExamples/src/main/cpp/examples/SwerveBot/cpp/SwerveModule.cpp @@ -32,24 +32,24 @@ SwerveModule::SwerveModule(const int driveMotorChannel, // Limit the PID Controller's input range between -pi and pi and set the input // to be continuous. turningPIDController.EnableContinuousInput( - -wpi::units::radian_t{std::numbers::pi}, - wpi::units::radian_t{std::numbers::pi}); + -wpi::units::radians<>{std::numbers::pi}, + wpi::units::radians<>{std::numbers::pi}); } wpi::math::SwerveModulePosition SwerveModule::GetPosition() const { - return {wpi::units::meter_t{driveEncoder.GetDistance()}, - wpi::units::radian_t{turningEncoder.GetDistance()}}; + return {wpi::units::meters<>{driveEncoder.GetDistance()}, + wpi::units::radians<>{turningEncoder.GetDistance()}}; } wpi::math::SwerveModuleVelocity SwerveModule::GetVelocity() const { - return {wpi::units::meters_per_second_t{driveEncoder.GetRate()}, - wpi::units::radian_t{turningEncoder.GetDistance()}}; + return {wpi::units::meters_per_second<>{driveEncoder.GetRate()}, + wpi::units::radians<>{turningEncoder.GetDistance()}}; } void SwerveModule::SetDesiredVelocity( wpi::math::SwerveModuleVelocity& desiredVelocity) { wpi::math::Rotation2d encoderRotation{ - wpi::units::radian_t{turningEncoder.GetDistance()}}; + wpi::units::radians<>{turningEncoder.GetDistance()}}; // Optimize the desired velocity to avoid spinning further than 90 degrees, // then scale velocity by cosine of angle error. This scales down movement @@ -60,15 +60,15 @@ void SwerveModule::SetDesiredVelocity( // Calculate the drive output from the drive PID controller and feedforward. const auto driveOutput = - wpi::units::volt_t{drivePIDController.Calculate( + wpi::units::volts<>{drivePIDController.Calculate( driveEncoder.GetRate(), velocity.velocity.value())} + driveFeedforward.Calculate(velocity.velocity); // Calculate the turning motor output from the turning PID controller and // feedforward. const auto turnOutput = - wpi::units::volt_t{turningPIDController.Calculate( - wpi::units::radian_t{turningEncoder.GetDistance()}, + wpi::units::volts<>{turningPIDController.Calculate( + wpi::units::radians<>{turningEncoder.GetDistance()}, velocity.angle.Radians())} + turnFeedforward.Calculate(turningPIDController.GetSetpoint().velocity); diff --git a/wpilibcExamples/src/main/cpp/examples/SwerveBot/include/Drivetrain.hpp b/wpilibcExamples/src/main/cpp/examples/SwerveBot/include/Drivetrain.hpp index df8c39f0eec..2fe576bb37a 100644 --- a/wpilibcExamples/src/main/cpp/examples/SwerveBot/include/Drivetrain.hpp +++ b/wpilibcExamples/src/main/cpp/examples/SwerveBot/include/Drivetrain.hpp @@ -19,15 +19,15 @@ class Drivetrain { public: Drivetrain() { imu.ResetYaw(); } - void Drive(wpi::units::meters_per_second_t xVelocity, - wpi::units::meters_per_second_t yVelocity, - wpi::units::radians_per_second_t rot, bool fieldRelative, - wpi::units::second_t period); + void Drive(wpi::units::meters_per_second<> xVelocity, + wpi::units::meters_per_second<> yVelocity, + wpi::units::radians_per_second<> rot, bool fieldRelative, + wpi::units::seconds<> period); void UpdateOdometry(); - static constexpr wpi::units::meters_per_second_t MAX_VELOCITY = + static constexpr wpi::units::meters_per_second<> MAX_VELOCITY = 3.0_mps; // 3 meters per second - static constexpr wpi::units::radians_per_second_t MAX_ANGULAR_VELOCITY{ + static constexpr wpi::units::radians_per_second<> MAX_ANGULAR_VELOCITY{ std::numbers::pi}; // 1/2 rotation per second private: diff --git a/wpilibcExamples/src/main/cpp/examples/SwerveBot/include/SwerveModule.hpp b/wpilibcExamples/src/main/cpp/examples/SwerveBot/include/SwerveModule.hpp index e1acde7d46d..a3c8384581a 100644 --- a/wpilibcExamples/src/main/cpp/examples/SwerveBot/include/SwerveModule.hpp +++ b/wpilibcExamples/src/main/cpp/examples/SwerveBot/include/SwerveModule.hpp @@ -43,14 +43,14 @@ class SwerveModule { wpi::Encoder turningEncoder; wpi::math::PIDController drivePIDController{1.0, 0, 0}; - wpi::math::ProfiledPIDController turningPIDController{ + wpi::math::ProfiledPIDController turningPIDController{ 1.0, 0.0, 0.0, {MODULE_MAX_ANGULAR_VELOCITY, MODULE_MAX_ANGULAR_ACCELERATION}}; - wpi::math::SimpleMotorFeedforward driveFeedforward{ + wpi::math::SimpleMotorFeedforward driveFeedforward{ 1_V, 3_V / 1_mps}; - wpi::math::SimpleMotorFeedforward turnFeedforward{ + wpi::math::SimpleMotorFeedforward turnFeedforward{ 1_V, 0.5_V / 1_rad_per_s}; }; diff --git a/wpilibcExamples/src/main/cpp/examples/SwerveDrivePoseEstimator/cpp/Drivetrain.cpp b/wpilibcExamples/src/main/cpp/examples/SwerveDrivePoseEstimator/cpp/Drivetrain.cpp index be45832097c..96aa50716a0 100644 --- a/wpilibcExamples/src/main/cpp/examples/SwerveDrivePoseEstimator/cpp/Drivetrain.cpp +++ b/wpilibcExamples/src/main/cpp/examples/SwerveDrivePoseEstimator/cpp/Drivetrain.cpp @@ -7,10 +7,10 @@ #include "ExampleGlobalMeasurementSensor.hpp" #include "wpi/system/Timer.hpp" -void Drivetrain::Drive(wpi::units::meters_per_second_t xVelocity, - wpi::units::meters_per_second_t yVelocity, - wpi::units::radians_per_second_t rot, bool fieldRelative, - wpi::units::second_t period) { +void Drivetrain::Drive(wpi::units::meters_per_second<> xVelocity, + wpi::units::meters_per_second<> yVelocity, + wpi::units::radians_per_second<> rot, bool fieldRelative, + wpi::units::seconds<> period) { wpi::math::ChassisVelocities chassisVelocities{xVelocity, yVelocity, rot}; if (fieldRelative) { chassisVelocities = chassisVelocities.ToRobotRelative( diff --git a/wpilibcExamples/src/main/cpp/examples/SwerveDrivePoseEstimator/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/SwerveDrivePoseEstimator/cpp/Robot.cpp index 5b289f097c8..081eb8153d9 100644 --- a/wpilibcExamples/src/main/cpp/examples/SwerveDrivePoseEstimator/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/examples/SwerveDrivePoseEstimator/cpp/Robot.cpp @@ -22,9 +22,11 @@ class Robot : public wpi::TimedRobot { // Slew rate limiters to make joystick inputs more gentle; 1/3 sec from 0 // to 1. - wpi::math::SlewRateLimiter xVelocityLimiter{3 / 1_s}; - wpi::math::SlewRateLimiter yVelocityLimiter{3 / 1_s}; - wpi::math::SlewRateLimiter rotLimiter{3 / 1_s}; + wpi::math::SlewRateLimiter xVelocityLimiter{3 / + 1_s}; + wpi::math::SlewRateLimiter yVelocityLimiter{3 / + 1_s}; + wpi::math::SlewRateLimiter rotLimiter{3 / 1_s}; void DriveWithJoystick(bool fieldRelative) { // Get the x velocity. We are inverting this because gamepads return diff --git a/wpilibcExamples/src/main/cpp/examples/SwerveDrivePoseEstimator/cpp/SwerveModule.cpp b/wpilibcExamples/src/main/cpp/examples/SwerveDrivePoseEstimator/cpp/SwerveModule.cpp index 023b92f0bf8..220e1e73fc3 100644 --- a/wpilibcExamples/src/main/cpp/examples/SwerveDrivePoseEstimator/cpp/SwerveModule.cpp +++ b/wpilibcExamples/src/main/cpp/examples/SwerveDrivePoseEstimator/cpp/SwerveModule.cpp @@ -32,24 +32,24 @@ SwerveModule::SwerveModule(const int driveMotorChannel, // Limit the PID Controller's input range between -pi and pi and set the input // to be continuous. turningPIDController.EnableContinuousInput( - -wpi::units::radian_t{std::numbers::pi}, - wpi::units::radian_t{std::numbers::pi}); + -wpi::units::radians<>{std::numbers::pi}, + wpi::units::radians<>{std::numbers::pi}); } wpi::math::SwerveModulePosition SwerveModule::GetPosition() const { - return {wpi::units::meter_t{driveEncoder.GetDistance()}, - wpi::units::radian_t{turningEncoder.GetDistance()}}; + return {wpi::units::meters<>{driveEncoder.GetDistance()}, + wpi::units::radians<>{turningEncoder.GetDistance()}}; } wpi::math::SwerveModuleVelocity SwerveModule::GetVelocity() const { - return {wpi::units::meters_per_second_t{driveEncoder.GetRate()}, - wpi::units::radian_t{turningEncoder.GetDistance()}}; + return {wpi::units::meters_per_second<>{driveEncoder.GetRate()}, + wpi::units::radians<>{turningEncoder.GetDistance()}}; } void SwerveModule::SetDesiredVelocity( wpi::math::SwerveModuleVelocity& desiredVelocity) { wpi::math::Rotation2d encoderRotation{ - wpi::units::radian_t{turningEncoder.GetDistance()}}; + wpi::units::radians<>{turningEncoder.GetDistance()}}; // Optimize the desired velocity to avoid spinning further than 90 degrees, // then scale velocity by cosine of angle error. This scales down movement @@ -60,15 +60,15 @@ void SwerveModule::SetDesiredVelocity( // Calculate the drive output from the drive PID controller and feedforward. const auto driveOutput = - wpi::units::volt_t{drivePIDController.Calculate( + wpi::units::volts<>{drivePIDController.Calculate( driveEncoder.GetRate(), velocity.velocity.value())} + driveFeedforward.Calculate(velocity.velocity); // Calculate the turning motor output from the turning PID controller and // feedforward. const auto turnOutput = - wpi::units::volt_t{turningPIDController.Calculate( - wpi::units::radian_t{turningEncoder.GetDistance()}, + wpi::units::volts<>{turningPIDController.Calculate( + wpi::units::radians<>{turningEncoder.GetDistance()}, velocity.angle.Radians())} + turnFeedforward.Calculate(turningPIDController.GetSetpoint().velocity); diff --git a/wpilibcExamples/src/main/cpp/examples/SwerveDrivePoseEstimator/include/Drivetrain.hpp b/wpilibcExamples/src/main/cpp/examples/SwerveDrivePoseEstimator/include/Drivetrain.hpp index 4431ed738e2..1c78102e2fc 100644 --- a/wpilibcExamples/src/main/cpp/examples/SwerveDrivePoseEstimator/include/Drivetrain.hpp +++ b/wpilibcExamples/src/main/cpp/examples/SwerveDrivePoseEstimator/include/Drivetrain.hpp @@ -19,14 +19,14 @@ class Drivetrain { public: Drivetrain() { imu.ResetYaw(); } - void Drive(wpi::units::meters_per_second_t xVelocity, - wpi::units::meters_per_second_t yVelocity, - wpi::units::radians_per_second_t rot, bool fieldRelative, - wpi::units::second_t period); + void Drive(wpi::units::meters_per_second<> xVelocity, + wpi::units::meters_per_second<> yVelocity, + wpi::units::radians_per_second<> rot, bool fieldRelative, + wpi::units::seconds<> period); void UpdateOdometry(); static constexpr auto MAX_VELOCITY = 3.0_mps; // 3 meters per second - static constexpr wpi::units::radians_per_second_t MAX_ANGULAR_VELOCITY{ + static constexpr wpi::units::radians_per_second<> MAX_ANGULAR_VELOCITY{ std::numbers::pi}; // 1/2 rotation per second private: diff --git a/wpilibcExamples/src/main/cpp/examples/SwerveDrivePoseEstimator/include/ExampleGlobalMeasurementSensor.hpp b/wpilibcExamples/src/main/cpp/examples/SwerveDrivePoseEstimator/include/ExampleGlobalMeasurementSensor.hpp index a004c8e5df1..f8e551d2c1e 100644 --- a/wpilibcExamples/src/main/cpp/examples/SwerveDrivePoseEstimator/include/ExampleGlobalMeasurementSensor.hpp +++ b/wpilibcExamples/src/main/cpp/examples/SwerveDrivePoseEstimator/include/ExampleGlobalMeasurementSensor.hpp @@ -17,9 +17,9 @@ class ExampleGlobalMeasurementSensor { const wpi::math::Pose2d& estimatedRobotPose) { auto randVec = wpi::math::Normal(0.1, 0.1, 0.1); return wpi::math::Pose2d{ - estimatedRobotPose.X() + wpi::units::meter_t{randVec(0)}, - estimatedRobotPose.Y() + wpi::units::meter_t{randVec(1)}, + estimatedRobotPose.X() + wpi::units::meters<>{randVec(0)}, + estimatedRobotPose.Y() + wpi::units::meters<>{randVec(1)}, estimatedRobotPose.Rotation() + - wpi::math::Rotation2d{wpi::units::radian_t{randVec(2)}}}; + wpi::math::Rotation2d{wpi::units::radians<>{randVec(2)}}}; } }; diff --git a/wpilibcExamples/src/main/cpp/examples/SwerveDrivePoseEstimator/include/SwerveModule.hpp b/wpilibcExamples/src/main/cpp/examples/SwerveDrivePoseEstimator/include/SwerveModule.hpp index 17378abdf28..ec7b332456e 100644 --- a/wpilibcExamples/src/main/cpp/examples/SwerveDrivePoseEstimator/include/SwerveModule.hpp +++ b/wpilibcExamples/src/main/cpp/examples/SwerveDrivePoseEstimator/include/SwerveModule.hpp @@ -43,14 +43,14 @@ class SwerveModule { wpi::Encoder turningEncoder; wpi::math::PIDController drivePIDController{1.0, 0, 0}; - wpi::math::ProfiledPIDController turningPIDController{ + wpi::math::ProfiledPIDController turningPIDController{ 1.0, 0.0, 0.0, {MODULE_MAX_ANGULAR_VELOCITY, MODULE_MAX_ANGULAR_ACCELERATION}}; - wpi::math::SimpleMotorFeedforward driveFeedforward{ + wpi::math::SimpleMotorFeedforward driveFeedforward{ 1_V, 3_V / 1_mps}; - wpi::math::SimpleMotorFeedforward turnFeedforward{ + wpi::math::SimpleMotorFeedforward turnFeedforward{ 1_V, 0.5_V / 1_rad_per_s}; }; diff --git a/wpilibcExamples/src/main/cpp/examples/SysIdRoutine/cpp/subsystems/Shooter.cpp b/wpilibcExamples/src/main/cpp/examples/SysIdRoutine/cpp/subsystems/Shooter.cpp index 5451a8fe266..ef43893d7f3 100644 --- a/wpilibcExamples/src/main/cpp/examples/SysIdRoutine/cpp/subsystems/Shooter.cpp +++ b/wpilibcExamples/src/main/cpp/examples/SysIdRoutine/cpp/subsystems/Shooter.cpp @@ -18,10 +18,10 @@ wpi::cmd::CommandPtr Shooter::RunShooterCommand( return wpi::cmd::Run( [this, shooterVelocity] { shooterMotor.SetVoltage( - wpi::units::volt_t{shooterFeedback.Calculate( + wpi::units::volts<>{shooterFeedback.Calculate( shooterEncoder.GetRate(), shooterVelocity())} + shooterFeedforward.Calculate( - wpi::units::turns_per_second_t{shooterVelocity()})); + wpi::units::turns_per_second<>{shooterVelocity()})); feederMotor.SetThrottle(constants::shooter::FEEDER_VELOCITY); }, {this}) diff --git a/wpilibcExamples/src/main/cpp/examples/SysIdRoutine/include/Constants.hpp b/wpilibcExamples/src/main/cpp/examples/SysIdRoutine/include/Constants.hpp index 45287f3e673..0fe5180c257 100644 --- a/wpilibcExamples/src/main/cpp/examples/SysIdRoutine/include/Constants.hpp +++ b/wpilibcExamples/src/main/cpp/examples/SysIdRoutine/include/Constants.hpp @@ -27,40 +27,41 @@ inline constexpr bool LEFT_ENCODER_REVERSED = false; inline constexpr bool RIGHT_ENCODER_REVERSED = true; inline constexpr int ENCODER_CPR = 1024; -inline constexpr wpi::units::meter_t WHEEL_DIAMETER = 6_in; -inline constexpr wpi::units::meter_t ENCODER_DISTANCE_PER_PULSE = +inline constexpr wpi::units::meters<> WHEEL_DIAMETER = 6_in; +inline constexpr wpi::units::meters<> ENCODER_DISTANCE_PER_PULSE = (WHEEL_DIAMETER * std::numbers::pi) / static_cast(ENCODER_CPR); } // namespace drive namespace shooter { -using kv_unit = wpi::units::compound_unit< - wpi::units::compound_unit, - wpi::units::inverse>; -using kv_unit_t = wpi::units::unit_t; +using kv_unit = wpi::units::compound_conversion_factor< + wpi::units::compound_conversion_factor, + wpi::units::inverse>; +using kv_unit_t = wpi::units::unit; -using ka_unit = wpi::units::compound_unit< - wpi::units::volts, - wpi::units::inverse>; -using ka_unit_t = wpi::units::unit_t; +using ka_unit = wpi::units::compound_conversion_factor< + wpi::units::volts_, + wpi::units::inverse>; +using ka_unit_t = wpi::units::unit; inline constexpr std::array ENCODER_PORTS = {4, 5}; inline constexpr bool ENCODER_REVERSED = false; inline constexpr int ENCODER_CPR = 1024; -inline constexpr wpi::units::turn_t ENCODER_DISTANCE_PER_PULSE = +inline constexpr wpi::units::turns<> ENCODER_DISTANCE_PER_PULSE = 1_tr / static_cast(ENCODER_CPR); inline constexpr int SHOOTER_MOTOR_PORT = 4; inline constexpr int FEEDER_MOTOR_PORT = 5; -inline constexpr wpi::units::turns_per_second_t SHOOTER_FREE_SPEED = 5300_tps; -inline constexpr wpi::units::turns_per_second_t SHOOTER_TARGET_VELOCITY = +inline constexpr wpi::units::turns_per_second<> SHOOTER_FREE_SPEED = 5300_tps; +inline constexpr wpi::units::turns_per_second<> SHOOTER_TARGET_VELOCITY = 4000_tps; -inline constexpr wpi::units::turns_per_second_t SHOOTER_TOLERANCE = 50_tps; +inline constexpr wpi::units::turns_per_second<> SHOOTER_TOLERANCE = 50_tps; inline constexpr double kP = 1.0; -inline constexpr wpi::units::volt_t kS = 0.05_V; +inline constexpr wpi::units::volts<> kS = 0.05_V; inline constexpr kv_unit_t kV = 12_V / SHOOTER_FREE_SPEED; inline constexpr ka_unit_t kA = 0_V * 1_s * 1_s / 1_tr; @@ -78,8 +79,8 @@ inline constexpr int BALL_SENSOR_PORT = 6; } // namespace storage namespace autonomous { -inline constexpr wpi::units::second_t TIMEOUT = 3_s; -inline constexpr wpi::units::meter_t DRIVE_DISTANCE = 2_m; +inline constexpr wpi::units::seconds<> TIMEOUT = 3_s; +inline constexpr wpi::units::meters<> DRIVE_DISTANCE = 2_m; inline constexpr double DRIVE_VELOCITY = 0.5; } // namespace autonomous diff --git a/wpilibcExamples/src/main/cpp/examples/SysIdRoutine/include/subsystems/Drive.hpp b/wpilibcExamples/src/main/cpp/examples/SysIdRoutine/include/subsystems/Drive.hpp index c46c31847a9..28baad226b4 100644 --- a/wpilibcExamples/src/main/cpp/examples/SysIdRoutine/include/subsystems/Drive.hpp +++ b/wpilibcExamples/src/main/cpp/examples/SysIdRoutine/include/subsystems/Drive.hpp @@ -42,7 +42,7 @@ class Drive : public wpi::cmd::SubsystemBase { wpi::cmd::sysid::Config{std::nullopt, std::nullopt, std::nullopt, nullptr}, wpi::cmd::sysid::Mechanism{ - [this](wpi::units::volt_t driveVoltage) { + [this](wpi::units::volts<> driveVoltage) { leftMotor.SetVoltage(driveVoltage); rightMotor.SetVoltage(driveVoltage); }, @@ -50,15 +50,15 @@ class Drive : public wpi::cmd::SubsystemBase { log->Motor("drive-left") .voltage(leftMotor.GetThrottle() * wpi::RobotController::GetBatteryVoltage()) - .position(wpi::units::meter_t{leftEncoder.GetDistance()}) + .position(wpi::units::meters<>{leftEncoder.GetDistance()}) .velocity( - wpi::units::meters_per_second_t{leftEncoder.GetRate()}); + wpi::units::meters_per_second<>{leftEncoder.GetRate()}); log->Motor("drive-right") .voltage(rightMotor.GetThrottle() * wpi::RobotController::GetBatteryVoltage()) - .position(wpi::units::meter_t{rightEncoder.GetDistance()}) + .position(wpi::units::meters<>{rightEncoder.GetDistance()}) .velocity( - wpi::units::meters_per_second_t{rightEncoder.GetRate()}); + wpi::units::meters_per_second<>{rightEncoder.GetRate()}); }, this}}; }; diff --git a/wpilibcExamples/src/main/cpp/examples/SysIdRoutine/include/subsystems/Shooter.hpp b/wpilibcExamples/src/main/cpp/examples/SysIdRoutine/include/subsystems/Shooter.hpp index 66df0c0ab2c..5cf0705a80b 100644 --- a/wpilibcExamples/src/main/cpp/examples/SysIdRoutine/include/subsystems/Shooter.hpp +++ b/wpilibcExamples/src/main/cpp/examples/SysIdRoutine/include/subsystems/Shooter.hpp @@ -36,19 +36,19 @@ class Shooter : public wpi::cmd::SubsystemBase { wpi::cmd::sysid::Config{std::nullopt, std::nullopt, std::nullopt, nullptr}, wpi::cmd::sysid::Mechanism{ - [this](wpi::units::volt_t driveVoltage) { + [this](wpi::units::volts<> driveVoltage) { shooterMotor.SetVoltage(driveVoltage); }, [this](wpi::sysid::SysIdRoutineLog* log) { log->Motor("shooter-wheel") .voltage(shooterMotor.GetThrottle() * wpi::RobotController::GetBatteryVoltage()) - .position(wpi::units::turn_t{shooterEncoder.GetDistance()}) + .position(wpi::units::turns<>{shooterEncoder.GetDistance()}) .velocity( - wpi::units::turns_per_second_t{shooterEncoder.GetRate()}); + wpi::units::turns_per_second<>{shooterEncoder.GetRate()}); }, this}}; wpi::math::PIDController shooterFeedback{constants::shooter::kP, 0, 0}; - wpi::math::SimpleMotorFeedforward shooterFeedforward{ + wpi::math::SimpleMotorFeedforward shooterFeedforward{ constants::shooter::kS, constants::shooter::kV, constants::shooter::kA}; }; diff --git a/wpilibcExamples/src/main/cpp/examples/XRPReference/cpp/commands/DriveDistance.cpp b/wpilibcExamples/src/main/cpp/examples/XRPReference/cpp/commands/DriveDistance.cpp index d3d186cff2d..ba6fbcbf6e2 100644 --- a/wpilibcExamples/src/main/cpp/examples/XRPReference/cpp/commands/DriveDistance.cpp +++ b/wpilibcExamples/src/main/cpp/examples/XRPReference/cpp/commands/DriveDistance.cpp @@ -4,8 +4,6 @@ #include "commands/DriveDistance.hpp" -#include "wpi/units/math.hpp" - void DriveDistance::Initialize() { drive->ArcadeDrive(0, 0); drive->ResetEncoders(); @@ -20,5 +18,5 @@ void DriveDistance::End(bool interrupted) { } bool DriveDistance::IsFinished() { - return wpi::units::math::abs(drive->GetAverageDistance()) >= distance; + return wpi::units::abs(drive->GetAverageDistance()) >= distance; } diff --git a/wpilibcExamples/src/main/cpp/examples/XRPReference/cpp/commands/TurnDegrees.cpp b/wpilibcExamples/src/main/cpp/examples/XRPReference/cpp/commands/TurnDegrees.cpp index b2e09655f5a..54afeec6689 100644 --- a/wpilibcExamples/src/main/cpp/examples/XRPReference/cpp/commands/TurnDegrees.cpp +++ b/wpilibcExamples/src/main/cpp/examples/XRPReference/cpp/commands/TurnDegrees.cpp @@ -6,8 +6,6 @@ #include -#include "wpi/units/math.hpp" - void TurnDegrees::Initialize() { // Set motors to stop, read encoder values for starting point drive->ArcadeDrive(0, 0); @@ -33,8 +31,8 @@ bool TurnDegrees::IsFinished() { return GetAverageTurningDistance() >= inchPerDegree * angle; } -wpi::units::meter_t TurnDegrees::GetAverageTurningDistance() { - auto l = wpi::units::math::abs(drive->GetLeftDistance()); - auto r = wpi::units::math::abs(drive->GetRightDistance()); +wpi::units::meters<> TurnDegrees::GetAverageTurningDistance() { + auto l = wpi::units::abs(drive->GetLeftDistance()); + auto r = wpi::units::abs(drive->GetRightDistance()); return (l + r) / 2; } diff --git a/wpilibcExamples/src/main/cpp/examples/XRPReference/cpp/subsystems/Arm.cpp b/wpilibcExamples/src/main/cpp/examples/XRPReference/cpp/subsystems/Arm.cpp index 4dcd1d5d37b..e56902deb27 100644 --- a/wpilibcExamples/src/main/cpp/examples/XRPReference/cpp/subsystems/Arm.cpp +++ b/wpilibcExamples/src/main/cpp/examples/XRPReference/cpp/subsystems/Arm.cpp @@ -8,6 +8,6 @@ void Arm::Periodic() { // This method will be called once per scheduler run. } -void Arm::SetAngle(wpi::units::radian_t angle) { +void Arm::SetAngle(wpi::units::radians<> angle) { armServo.SetAngle(angle); } diff --git a/wpilibcExamples/src/main/cpp/examples/XRPReference/cpp/subsystems/Drivetrain.cpp b/wpilibcExamples/src/main/cpp/examples/XRPReference/cpp/subsystems/Drivetrain.cpp index fb70b5e2c10..f30b58f328a 100644 --- a/wpilibcExamples/src/main/cpp/examples/XRPReference/cpp/subsystems/Drivetrain.cpp +++ b/wpilibcExamples/src/main/cpp/examples/XRPReference/cpp/subsystems/Drivetrain.cpp @@ -48,27 +48,27 @@ int Drivetrain::GetRightEncoderCount() { return rightEncoder.Get(); } -wpi::units::meter_t Drivetrain::GetLeftDistance() { - return wpi::units::meter_t{leftEncoder.GetDistance()}; +wpi::units::meters<> Drivetrain::GetLeftDistance() { + return wpi::units::meters<>{leftEncoder.GetDistance()}; } -wpi::units::meter_t Drivetrain::GetRightDistance() { - return wpi::units::meter_t{rightEncoder.GetDistance()}; +wpi::units::meters<> Drivetrain::GetRightDistance() { + return wpi::units::meters<>{rightEncoder.GetDistance()}; } -wpi::units::meter_t Drivetrain::GetAverageDistance() { +wpi::units::meters<> Drivetrain::GetAverageDistance() { return (GetLeftDistance() + GetRightDistance()) / 2.0; } -wpi::units::radian_t Drivetrain::GetGyroAngleX() { +wpi::units::radians<> Drivetrain::GetGyroAngleX() { return gyro.GetAngleX(); } -wpi::units::radian_t Drivetrain::GetGyroAngleY() { +wpi::units::radians<> Drivetrain::GetGyroAngleY() { return gyro.GetAngleY(); } -wpi::units::radian_t Drivetrain::GetGyroAngleZ() { +wpi::units::radians<> Drivetrain::GetGyroAngleZ() { return gyro.GetAngleZ(); } diff --git a/wpilibcExamples/src/main/cpp/examples/XRPReference/include/commands/DriveDistance.hpp b/wpilibcExamples/src/main/cpp/examples/XRPReference/include/commands/DriveDistance.hpp index 9b2a3f33790..c99dada5072 100644 --- a/wpilibcExamples/src/main/cpp/examples/XRPReference/include/commands/DriveDistance.hpp +++ b/wpilibcExamples/src/main/cpp/examples/XRPReference/include/commands/DriveDistance.hpp @@ -20,7 +20,7 @@ class DriveDistance * @param distance The distance the robot will drive * @param drive The drivetrain subsystem on which this command will run */ - DriveDistance(double velocity, wpi::units::meter_t distance, + DriveDistance(double velocity, wpi::units::meters<> distance, Drivetrain* drive) : velocity(velocity), distance(distance), drive(drive) { AddRequirements(drive); @@ -33,6 +33,6 @@ class DriveDistance private: double velocity; - wpi::units::meter_t distance; + wpi::units::meters<> distance; Drivetrain* drive; }; diff --git a/wpilibcExamples/src/main/cpp/examples/XRPReference/include/commands/DriveTime.hpp b/wpilibcExamples/src/main/cpp/examples/XRPReference/include/commands/DriveTime.hpp index fc3a458268d..b881143e6e6 100644 --- a/wpilibcExamples/src/main/cpp/examples/XRPReference/include/commands/DriveTime.hpp +++ b/wpilibcExamples/src/main/cpp/examples/XRPReference/include/commands/DriveTime.hpp @@ -21,7 +21,7 @@ class DriveTime : public wpi::cmd::CommandHelper { * @param time How much time to drive * @param drive The drivetrain subsystem on which this command will run */ - DriveTime(double velocity, wpi::units::second_t time, Drivetrain* drive) + DriveTime(double velocity, wpi::units::seconds<> time, Drivetrain* drive) : velocity(velocity), duration(time), drive(drive) { AddRequirements(drive); } @@ -33,7 +33,7 @@ class DriveTime : public wpi::cmd::CommandHelper { private: double velocity; - wpi::units::second_t duration; + wpi::units::seconds<> duration; Drivetrain* drive; wpi::Timer timer; }; diff --git a/wpilibcExamples/src/main/cpp/examples/XRPReference/include/commands/TurnDegrees.hpp b/wpilibcExamples/src/main/cpp/examples/XRPReference/include/commands/TurnDegrees.hpp index 42d1add8e43..896fc6d8173 100644 --- a/wpilibcExamples/src/main/cpp/examples/XRPReference/include/commands/TurnDegrees.hpp +++ b/wpilibcExamples/src/main/cpp/examples/XRPReference/include/commands/TurnDegrees.hpp @@ -22,7 +22,7 @@ class TurnDegrees * @param angle Degrees to turn. Leverages encoders to compare distance. * @param drive The drive subsystem on which this command will run */ - TurnDegrees(double velocity, wpi::units::degree_t angle, Drivetrain* drive) + TurnDegrees(double velocity, wpi::units::degrees<> angle, Drivetrain* drive) : velocity(velocity), angle(angle), drive(drive) { AddRequirements(drive); } @@ -34,8 +34,8 @@ class TurnDegrees private: double velocity; - wpi::units::degree_t angle; + wpi::units::degrees<> angle; Drivetrain* drive; - wpi::units::meter_t GetAverageTurningDistance(); + wpi::units::meters<> GetAverageTurningDistance(); }; diff --git a/wpilibcExamples/src/main/cpp/examples/XRPReference/include/commands/TurnTime.hpp b/wpilibcExamples/src/main/cpp/examples/XRPReference/include/commands/TurnTime.hpp index 24e179c8c66..85ca1cacec4 100644 --- a/wpilibcExamples/src/main/cpp/examples/XRPReference/include/commands/TurnTime.hpp +++ b/wpilibcExamples/src/main/cpp/examples/XRPReference/include/commands/TurnTime.hpp @@ -20,7 +20,7 @@ class TurnTime : public wpi::cmd::CommandHelper { * @param time How much time to turn * @param drive The drive subsystem on which this command will run */ - TurnTime(double velocity, wpi::units::second_t time, Drivetrain* drive) + TurnTime(double velocity, wpi::units::seconds<> time, Drivetrain* drive) : velocity(velocity), duration(time), drive(drive) { AddRequirements(drive); } @@ -32,7 +32,7 @@ class TurnTime : public wpi::cmd::CommandHelper { private: double velocity; - wpi::units::second_t duration; + wpi::units::seconds<> duration; Drivetrain* drive; wpi::Timer timer; }; diff --git a/wpilibcExamples/src/main/cpp/examples/XRPReference/include/subsystems/Arm.hpp b/wpilibcExamples/src/main/cpp/examples/XRPReference/include/subsystems/Arm.hpp index d7b11493fa8..bd68b301e6d 100644 --- a/wpilibcExamples/src/main/cpp/examples/XRPReference/include/subsystems/Arm.hpp +++ b/wpilibcExamples/src/main/cpp/examples/XRPReference/include/subsystems/Arm.hpp @@ -20,7 +20,7 @@ class Arm : public wpi::cmd::SubsystemBase { * * @param angle the commanded angle */ - void SetAngle(wpi::units::radian_t angle); + void SetAngle(wpi::units::radians<> angle); private: wpi::xrp::XRPServo armServo{4}; diff --git a/wpilibcExamples/src/main/cpp/examples/XRPReference/include/subsystems/Drivetrain.hpp b/wpilibcExamples/src/main/cpp/examples/XRPReference/include/subsystems/Drivetrain.hpp index 82e8c225dbb..9d15bab5314 100644 --- a/wpilibcExamples/src/main/cpp/examples/XRPReference/include/subsystems/Drivetrain.hpp +++ b/wpilibcExamples/src/main/cpp/examples/XRPReference/include/subsystems/Drivetrain.hpp @@ -20,7 +20,7 @@ class Drivetrain : public wpi::cmd::SubsystemBase { static constexpr double COUNTS_PER_MOTOR_SHAFT_REV = 12.0; static constexpr double COUNTS_PER_REVOLUTION = COUNTS_PER_MOTOR_SHAFT_REV * GEAR_RATIO; // 585.0 - static constexpr wpi::units::meter_t WHEEL_DIAMETER = 60_mm; + static constexpr wpi::units::meters<> WHEEL_DIAMETER = 60_mm; Drivetrain(); @@ -61,42 +61,42 @@ class Drivetrain : public wpi::cmd::SubsystemBase { * * @return the left-side distance driven */ - wpi::units::meter_t GetLeftDistance(); + wpi::units::meters<> GetLeftDistance(); /** * Gets the right distance driven. * * @return the right-side distance driven */ - wpi::units::meter_t GetRightDistance(); + wpi::units::meters<> GetRightDistance(); /** * Returns the average distance traveled by the left and right encoders. * * @return The average distance traveled by the left and right encoders. */ - wpi::units::meter_t GetAverageDistance(); + wpi::units::meters<> GetAverageDistance(); /** * Current angle of the XRP around the X-axis. * * @return The current angle of the XRP. */ - wpi::units::radian_t GetGyroAngleX(); + wpi::units::radians<> GetGyroAngleX(); /** * Current angle of the XRP around the Y-axis. * * @return The current angle of the XRP. */ - wpi::units::radian_t GetGyroAngleY(); + wpi::units::radians<> GetGyroAngleY(); /** * Current angle of the XRP around the Z-axis. * * @return The current angle of the XRP. */ - wpi::units::radian_t GetGyroAngleZ(); + wpi::units::radians<> GetGyroAngleZ(); /** * Reset the gyro. diff --git a/wpilibcExamples/src/main/cpp/snippets/AccelerometerCollision/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/snippets/AccelerometerCollision/cpp/Robot.cpp index ba094d8b6c8..d1c0ea7a8d4 100644 --- a/wpilibcExamples/src/main/cpp/snippets/AccelerometerCollision/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/snippets/AccelerometerCollision/cpp/Robot.cpp @@ -28,8 +28,8 @@ class Robot : public wpi::TimedRobot { } private: - wpi::units::meters_per_second_squared_t prevXAccel = 0.0_mps_sq; - wpi::units::meters_per_second_squared_t prevYAccel = 0.0_mps_sq; + wpi::units::meters_per_second_squared<> prevXAccel = 0.0_mps2; + wpi::units::meters_per_second_squared<> prevYAccel = 0.0_mps2; wpi::OnboardIMU accelerometer{wpi::OnboardIMU::MountOrientation::FLAT}; }; diff --git a/wpilibcExamples/src/main/cpp/snippets/AccelerometerFilter/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/snippets/AccelerometerFilter/cpp/Robot.cpp index 58371377506..b2d3b6b3be2 100644 --- a/wpilibcExamples/src/main/cpp/snippets/AccelerometerFilter/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/snippets/AccelerometerFilter/cpp/Robot.cpp @@ -15,9 +15,9 @@ class Robot : public wpi::TimedRobot { public: void RobotPeriodic() override { - wpi::units::meters_per_second_squared_t XAccel = accelerometer.GetAccelX(); + wpi::units::meters_per_second_squared<> XAccel = accelerometer.GetAccelX(); // Get the filtered X acceleration - wpi::units::meters_per_second_squared_t filteredXAccel = + wpi::units::meters_per_second_squared<> filteredXAccel = xAccelFilter.Calculate(XAccel); wpi::telemetry::Log("X Acceleration", XAccel); @@ -26,9 +26,9 @@ class Robot : public wpi::TimedRobot { private: wpi::OnboardIMU accelerometer{wpi::OnboardIMU::MountOrientation::FLAT}; - wpi::math::LinearFilter + wpi::math::LinearFilter> xAccelFilter = wpi::math::LinearFilter< - wpi::units::meters_per_second_squared_t>::MovingAverage(10); + wpi::units::meters_per_second_squared<>>::MovingAverage(10); }; #ifndef RUNNING_WPILIB_TESTS diff --git a/wpilibcExamples/src/main/cpp/snippets/AddressableLED/include/Robot.hpp b/wpilibcExamples/src/main/cpp/snippets/AddressableLED/include/Robot.hpp index 63316d96060..9ea6281d183 100644 --- a/wpilibcExamples/src/main/cpp/snippets/AddressableLED/include/Robot.hpp +++ b/wpilibcExamples/src/main/cpp/snippets/AddressableLED/include/Robot.hpp @@ -24,7 +24,7 @@ class Robot : public wpi::TimedRobot { ledBuffer; // Reuse the buffer // Our LED strip has a density of 120 LEDs per meter - wpi::units::meter_t LED_SPACING{1 / 120.0}; + wpi::units::meters<> LED_SPACING{1 / 120.0}; // Create an LED pattern that will display a rainbow across // all hues at maximum saturation and half brightness diff --git a/wpilibcExamples/src/main/cpp/snippets/EventLoop/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/snippets/EventLoop/cpp/Robot.cpp index 505a75a4e0d..0a4928b3914 100644 --- a/wpilibcExamples/src/main/cpp/snippets/EventLoop/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/snippets/EventLoop/cpp/Robot.cpp @@ -54,9 +54,9 @@ class Robot : public wpi::TimedRobot { .IfHigh([&shooter = shooter, &controller = controller, &ff = ff, &encoder = shooterEncoder] { shooter.SetVoltage( - wpi::units::volt_t{controller.Calculate(encoder.GetRate(), - SHOT_VELOCITY.value())} + - ff.Calculate(wpi::units::radians_per_second_t{SHOT_VELOCITY})); + wpi::units::volts<>{controller.Calculate(encoder.GetRate(), + SHOT_VELOCITY.value())} + + ff.Calculate(wpi::units::radians_per_second<>{SHOT_VELOCITY})); }); // if not, stop (!shootTrigger).IfHigh([&shooter = shooter] { shooter.SetThrottle(0.0); }); @@ -84,8 +84,8 @@ class Robot : public wpi::TimedRobot { wpi::PWMSparkMax shooter{0}; wpi::Encoder shooterEncoder{0, 1}; wpi::math::PIDController controller{0.3, 0, 0}; - wpi::math::SimpleMotorFeedforward ff{0.1_V, - 0.065_V / 1_rpm}; + wpi::math::SimpleMotorFeedforward ff{0.1_V, + 0.065_V / 1_rpm}; wpi::PWMSparkMax kicker{1}; diff --git a/wpilibcExamples/src/main/cpp/snippets/FlywheelBangBangController/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/snippets/FlywheelBangBangController/cpp/Robot.cpp index a15f0a2b501..723ca76d14b 100644 --- a/wpilibcExamples/src/main/cpp/snippets/FlywheelBangBangController/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/snippets/FlywheelBangBangController/cpp/Robot.cpp @@ -27,11 +27,11 @@ class Robot : public wpi::TimedRobot { */ void TeleopPeriodic() override { // Scale setpoint value between 0 and maxSetpointValue - wpi::units::radians_per_second_t setpoint = wpi::units::math::max( - 0_rpm, joystick.GetRawAxis(0) * MAX_SETPOINT_VALUE); + wpi::units::radians_per_second<> setpoint = + wpi::units::max(0_rpm, joystick.GetRawAxis(0) * MAX_SETPOINT_VALUE); // Set setpoint and measurement of the bang-bang controller - wpi::units::volt_t bangOutput = + wpi::units::volts<> bangOutput = bangBangController.Calculate(encoder.GetRate(), setpoint.value()) * 12_V; @@ -57,7 +57,7 @@ class Robot : public wpi::TimedRobot { // simulation, and write the simulated velocities to our simulated encoder flywheelSim.SetInputVoltage( flywheelMotor.GetThrottle() * - wpi::units::volt_t{wpi::RobotController::GetInputVoltage()}); + wpi::units::volts<>{wpi::RobotController::GetInputVoltage()}); flywheelSim.Update(20_ms); encoderSim.SetRate(flywheelSim.GetAngularVelocity().value()); } @@ -68,7 +68,7 @@ class Robot : public wpi::TimedRobot { static constexpr int ENCODER_B_CHANNEL = 1; // Max setpoint for joystick control - static constexpr wpi::units::radians_per_second_t MAX_SETPOINT_VALUE = + static constexpr wpi::units::radians_per_second<> MAX_SETPOINT_VALUE = 6000_rpm; // Joystick to control setpoint @@ -81,11 +81,11 @@ class Robot : public wpi::TimedRobot { // Gains are for example purposes only - must be determined for your own // robot! - static constexpr wpi::units::volt_t FLYWHEEL_KS = 0.0001_V; + static constexpr wpi::units::volts<> FLYWHEEL_KS = 0.0001_V; static constexpr decltype(1_V / 1_rad_per_s) FLYWHEEL_KV = 0.000195_V / 1_rpm; static constexpr decltype(1_V / 1_rad_per_s_sq) FLYWHEEL_KA = 0.0003_V / 1_rev_per_m_per_s; - wpi::math::SimpleMotorFeedforward feedforward{ + wpi::math::SimpleMotorFeedforward feedforward{ FLYWHEEL_KS, FLYWHEEL_KV, FLYWHEEL_KA}; // Simulation classes help us simulate our robot @@ -95,7 +95,7 @@ class Robot : public wpi::TimedRobot { static constexpr double FLYWHEEL_GEARING = 1.0; // 1/2 MR² - static constexpr wpi::units::kilogram_square_meter_t + static constexpr wpi::units::kilogram_square_meters<> FLYWHEEL_MOMENT_OF_INERTIA = 0.5 * 1.5_lb * 4_in * 4_in; wpi::math::DCMotor gearbox = wpi::math::DCMotor::NEO(1); diff --git a/wpilibcExamples/src/main/cpp/snippets/ProfiledPIDFeedforward/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/snippets/ProfiledPIDFeedforward/cpp/Robot.cpp index 037c223b363..48c9aad3c1f 100644 --- a/wpilibcExamples/src/main/cpp/snippets/ProfiledPIDFeedforward/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/snippets/ProfiledPIDFeedforward/cpp/Robot.cpp @@ -22,11 +22,11 @@ class Robot : public wpi::TimedRobot { // Controls a simple motor's position using a // wpi::math::SimpleMotorFeedforward and a wpi::math::ProfiledPIDController - void GoToPosition(wpi::units::meter_t goalPosition) { + void GoToPosition(wpi::units::meters<> goalPosition) { auto pidVal = controller.Calculate( - wpi::units::meter_t{encoder.GetDistance()}, goalPosition); + wpi::units::meters<>{encoder.GetDistance()}, goalPosition); motor.SetVoltage( - wpi::units::volt_t{pidVal} + + wpi::units::volts<>{pidVal} + feedforward.Calculate(lastVelocity, controller.GetSetpoint().velocity)); lastVelocity = controller.GetSetpoint().velocity; } @@ -37,14 +37,14 @@ class Robot : public wpi::TimedRobot { } private: - wpi::math::ProfiledPIDController controller{ - 1.0, 0.0, 0.0, {5_mps, 10_mps_sq}}; - wpi::math::SimpleMotorFeedforward feedforward{ - 0.5_V, 1.5_V / 1_mps, 0.3_V / 1_mps_sq}; + wpi::math::ProfiledPIDController controller{ + 1.0, 0.0, 0.0, {5_mps, 10_mps2}}; + wpi::math::SimpleMotorFeedforward feedforward{ + 0.5_V, 1.5_V / 1_mps, 0.3_V / 1_mps2}; wpi::Encoder encoder{0, 1}; wpi::PWMSparkMax motor{0}; - wpi::units::meters_per_second_t lastVelocity = 0_mps; + wpi::units::meters_per_second<> lastVelocity = 0_mps; }; #ifndef RUNNING_WPILIB_TESTS diff --git a/wpilibcExamples/src/test/cpp/examples/ArmSimulation/cpp/ArmSimulationTest.cpp b/wpilibcExamples/src/test/cpp/examples/ArmSimulation/cpp/ArmSimulationTest.cpp index 9022628f520..42e7e59008d 100644 --- a/wpilibcExamples/src/test/cpp/examples/ArmSimulation/cpp/ArmSimulationTest.cpp +++ b/wpilibcExamples/src/test/cpp/examples/ArmSimulation/cpp/ArmSimulationTest.cpp @@ -50,7 +50,7 @@ class ArmSimulationTest { TEST_CASE_METHOD(ArmSimulationTest, "ArmSimulationTest teleop", "[wpilibcExamples][examples][simulation][arm]") { - wpi::units::degree_t setpoint = + wpi::units::degrees<> setpoint = GENERATE(DEFAULT_ARM_SETPOINT, 25.0_deg, 50.0_deg); CHECK(wpi::Preferences::ContainsKey(ARM_POSITION_KEY)); @@ -83,16 +83,16 @@ TEST_CASE_METHOD(ArmSimulationTest, "ArmSimulationTest teleop", wpi::sim::StepTiming(1.5_s); - CHECK_THAT(wpi::units::radian_t{encoderSim.GetDistance()} - .convert() + CHECK_THAT(wpi::units::radians<>{encoderSim.GetDistance()} + .convert() .value(), Catch::Matchers::WithinAbs(setpoint.value(), 2.0)); // see setpoint is held. wpi::sim::StepTiming(0.5_s); - CHECK_THAT(wpi::units::radian_t{encoderSim.GetDistance()} - .convert() + CHECK_THAT(wpi::units::radians<>{encoderSim.GetDistance()} + .convert() .value(), Catch::Matchers::WithinAbs(setpoint.value(), 2.0)); } @@ -116,16 +116,16 @@ TEST_CASE_METHOD(ArmSimulationTest, "ArmSimulationTest teleop", // advance 75 timesteps wpi::sim::StepTiming(1.5_s); - CHECK_THAT(wpi::units::radian_t{encoderSim.GetDistance()} - .convert() + CHECK_THAT(wpi::units::radians<>{encoderSim.GetDistance()} + .convert() .value(), Catch::Matchers::WithinAbs(setpoint.value(), 2.0)); // advance 25 timesteps to see setpoint is held. wpi::sim::StepTiming(0.5_s); - CHECK_THAT(wpi::units::radian_t{encoderSim.GetDistance()} - .convert() + CHECK_THAT(wpi::units::radians<>{encoderSim.GetDistance()} + .convert() .value(), Catch::Matchers::WithinAbs(setpoint.value(), 2.0)); } diff --git a/wpimath/BUILD.bazel b/wpimath/BUILD.bazel index 53e9a164e23..371d4844eb8 100644 --- a/wpimath/BUILD.bazel +++ b/wpimath/BUILD.bazel @@ -28,6 +28,7 @@ filegroup( "src/main/native/include/**/*", "src/main/native/thirdparty/gcem/include/**/*", "src/main/native/thirdparty/sleipnir/include/**/*", + "src/main/native/thirdparty/units/include/**/*", ]) + [":generated-native-include-files"], visibility = ["//visibility:public"], ) @@ -139,6 +140,11 @@ third_party_cc_lib_helper( src_root = "src/main/native/thirdparty/sleipnir/src", ) +third_party_cc_lib_helper( + name = "units", + include_root = "src/main/native/thirdparty/units/include", +) + cc_library( name = "nanopb-generated-headers", hdrs = glob(["src/generated/main/native/cpp/**/*.h"]), @@ -178,6 +184,7 @@ wpilib_cc_library( third_party_header_only_libraries = [ ":eigen", ":gcem", + ":units", ], third_party_libraries = [ ":sleipnir", @@ -297,6 +304,7 @@ cc_test( size = "medium", srcs = glob([ "src/test/native/cpp/**/*.cpp", + "src/test/native/cpp/**/*.h", "src/test/native/cpp/**/*.hpp", ]), tags = [ @@ -365,6 +373,7 @@ generate_robotpy_native_wrapper_build_info( third_party_dirs = [ "gcem", "sleipnir", + "units", ], ) diff --git a/wpimath/CMakeLists.txt b/wpimath/CMakeLists.txt index 4eeedefd01f..ce093d5a367 100644 --- a/wpimath/CMakeLists.txt +++ b/wpimath/CMakeLists.txt @@ -91,11 +91,16 @@ else() target_link_libraries(wpimath Eigen3::Eigen) endif() -install(DIRECTORY src/main/native/thirdparty/gcem/include/ DESTINATION "${include_dest}/wpimath") +install( + DIRECTORY src/main/native/thirdparty/gcem/include/ src/main/native/thirdparty/units/include/ + DESTINATION "${include_dest}/wpimath" +) target_include_directories( wpimath SYSTEM - PUBLIC $ + PUBLIC + $ + $ ) if(NOT WPILIB_USE_SYSTEM_SLEIPNIR) diff --git a/wpimath/build.gradle b/wpimath/build.gradle index 797bb048927..d3c28634449 100644 --- a/wpimath/build.gradle +++ b/wpimath/build.gradle @@ -43,6 +43,9 @@ cppHeadersZip { from('src/main/native/thirdparty/gcem/include') { into '/' } + from('src/main/native/thirdparty/units/include') { + into '/' + } from("src/generated/main/native/cpp/wpimath/protobuf") { into '/wpimath/protobuf' include '**/*.h' @@ -67,6 +70,7 @@ model { 'src/main/native/thirdparty/eigen/include', 'src/main/native/thirdparty/gcem/include', 'src/main/native/thirdparty/sleipnir/include', + 'src/main/native/thirdparty/units/include', 'src/generated/main/native/cpp' } } diff --git a/wpimath/robotpy_native_build_info.bzl b/wpimath/robotpy_native_build_info.bzl index 6d5982f9074..21b5f71cc94 100644 --- a/wpimath/robotpy_native_build_info.bzl +++ b/wpimath/robotpy_native_build_info.bzl @@ -9,6 +9,7 @@ def define_native_wrapper(name, pyproject_toml = None): srcs = native.glob(["src/main/native/include/**"]) + ["//wpimath:generated-native-include-files"] + native.glob([ "src/main/native/thirdparty/gcem/include/**", "src/main/native/thirdparty/sleipnir/include/**", + "src/main/native/thirdparty/units/include/**", ]), out = "native/wpimath/include", root_paths = ["src/main/native/include/"], @@ -17,6 +18,7 @@ def define_native_wrapper(name, pyproject_toml = None): "wpimath/src/main/native/include": "", "wpimath/src/main/native/thirdparty/gcem/include": "", "wpimath/src/main/native/thirdparty/sleipnir/include": "", + "wpimath/src/main/native/thirdparty/units/include": "", }, verbose = False, visibility = ["//visibility:public"], diff --git a/wpimath/src/main/native/cpp/controller/ArmFeedforward.cpp b/wpimath/src/main/native/cpp/controller/ArmFeedforward.cpp index a63922e3159..749e18e701f 100644 --- a/wpimath/src/main/native/cpp/controller/ArmFeedforward.cpp +++ b/wpimath/src/main/native/cpp/controller/ArmFeedforward.cpp @@ -17,24 +17,23 @@ #include "wpi/math/linalg/EigenCore.hpp" #include "wpi/math/system/NumericalIntegration.hpp" -#include "wpi/units/base.hpp" -#include "wpi/units/math.hpp" +#include "wpi/units/core.hpp" #include "wpi/units/voltage.hpp" #include "wpi/util/MathExtras.hpp" using namespace wpi::math; -wpi::units::volt_t ArmFeedforward::Calculate( - wpi::units::unit_t currentAngle, - wpi::units::unit_t currentVelocity, - wpi::units::unit_t nextVelocity) const { +wpi::units::volts<> ArmFeedforward::Calculate( + wpi::units::unit currentAngle, + wpi::units::unit currentVelocity, + wpi::units::unit nextVelocity) const { using VarMat = slp::VariableMatrix; // Small kₐ values make the solver ill-conditioned - if (kA < wpi::units::unit_t{1e-1}) { + if (kA < wpi::units::unit{1e-1}) { auto acceleration = (nextVelocity - currentVelocity) / m_dt; return kS * wpi::util::sgn(currentVelocity.value()) + kV * currentVelocity + - kA * acceleration + kG * wpi::units::math::cos(currentAngle); + kA * acceleration + kG * wpi::units::cos(currentAngle); } // Arm dynamics @@ -55,7 +54,7 @@ wpi::units::volt_t ArmFeedforward::Calculate( auto acceleration = (nextVelocity - currentVelocity) / m_dt; u_k.set_value((kS * wpi::util::sgn(currentVelocity.value()) + kV * currentVelocity + kA * acceleration + - kG * wpi::units::math::cos(currentAngle)) + kG * wpi::units::cos(currentAngle)) .value()); auto r_k1 = RK4(f, r_k, u_k, m_dt); @@ -118,5 +117,5 @@ wpi::units::volt_t ArmFeedforward::Calculate( } } - return wpi::units::volt_t{u_k.value()}; + return wpi::units::volts<>{u_k.value()}; } diff --git a/wpimath/src/main/native/cpp/controller/DifferentialDriveAccelerationLimiter.cpp b/wpimath/src/main/native/cpp/controller/DifferentialDriveAccelerationLimiter.cpp index 367c6bfa77d..3affd136851 100644 --- a/wpimath/src/main/native/cpp/controller/DifferentialDriveAccelerationLimiter.cpp +++ b/wpimath/src/main/native/cpp/controller/DifferentialDriveAccelerationLimiter.cpp @@ -14,9 +14,9 @@ using namespace wpi::math; DifferentialDriveWheelVoltages DifferentialDriveAccelerationLimiter::Calculate( - wpi::units::meters_per_second_t leftVelocity, - wpi::units::meters_per_second_t rightVelocity, - wpi::units::volt_t leftVoltage, wpi::units::volt_t rightVoltage) { + wpi::units::meters_per_second<> leftVelocity, + wpi::units::meters_per_second<> rightVelocity, + wpi::units::volts<> leftVoltage, wpi::units::volts<> rightVoltage) { Vectord<2> u{leftVoltage.value(), rightVoltage.value()}; // Find unconstrained wheel accelerations @@ -61,5 +61,5 @@ DifferentialDriveWheelVoltages DifferentialDriveAccelerationLimiter::Calculate( // u = B⁻¹(dx/dt - Ax) u = m_system.B().householderQr().solve(dxdt - m_system.A() * x); - return {wpi::units::volt_t{u(0)}, wpi::units::volt_t{u(1)}}; + return {wpi::units::volts<>{u(0)}, wpi::units::volts<>{u(1)}}; } diff --git a/wpimath/src/main/native/cpp/controller/DifferentialDriveFeedforward.cpp b/wpimath/src/main/native/cpp/controller/DifferentialDriveFeedforward.cpp index 7ca65871188..a023b3b9a32 100644 --- a/wpimath/src/main/native/cpp/controller/DifferentialDriveFeedforward.cpp +++ b/wpimath/src/main/native/cpp/controller/DifferentialDriveFeedforward.cpp @@ -15,15 +15,15 @@ using namespace wpi::math; DifferentialDriveWheelVoltages DifferentialDriveFeedforward::Calculate( - wpi::units::meters_per_second_t currentLeftVelocity, - wpi::units::meters_per_second_t nextLeftVelocity, - wpi::units::meters_per_second_t currentRightVelocity, - wpi::units::meters_per_second_t nextRightVelocity, - wpi::units::second_t dt) { + wpi::units::meters_per_second<> currentLeftVelocity, + wpi::units::meters_per_second<> nextLeftVelocity, + wpi::units::meters_per_second<> currentRightVelocity, + wpi::units::meters_per_second<> nextRightVelocity, + wpi::units::seconds<> dt) { wpi::math::LinearPlantInversionFeedforward<2, 2> feedforward{m_plant, dt}; Eigen::Vector2d r{currentLeftVelocity, currentRightVelocity}; Eigen::Vector2d nextR{nextLeftVelocity, nextRightVelocity}; auto u = feedforward.Calculate(r, nextR); - return {wpi::units::volt_t{u(0)}, wpi::units::volt_t{u(1)}}; + return {wpi::units::volts<>{u(0)}, wpi::units::volts<>{u(1)}}; } diff --git a/wpimath/src/main/native/cpp/controller/LTVDifferentialDriveController.cpp b/wpimath/src/main/native/cpp/controller/LTVDifferentialDriveController.cpp index a32a5c06870..c7cef6bc2f3 100644 --- a/wpimath/src/main/native/cpp/controller/LTVDifferentialDriveController.cpp +++ b/wpimath/src/main/native/cpp/controller/LTVDifferentialDriveController.cpp @@ -14,17 +14,16 @@ #include "wpi/math/system/Discretization.hpp" #include "wpi/math/util/MathUtil.hpp" #include "wpi/units/angle.hpp" -#include "wpi/units/math.hpp" #include "wpi/units/velocity.hpp" #include "wpi/units/voltage.hpp" using namespace wpi::math; DifferentialDriveWheelVoltages LTVDifferentialDriveController::Calculate( - const Pose2d& currentPose, wpi::units::meters_per_second_t leftVelocity, - wpi::units::meters_per_second_t rightVelocity, const Pose2d& poseRef, - wpi::units::meters_per_second_t leftVelocityRef, - wpi::units::meters_per_second_t rightVelocityRef) { + const Pose2d& currentPose, wpi::units::meters_per_second<> leftVelocity, + wpi::units::meters_per_second<> rightVelocity, const Pose2d& poseRef, + wpi::units::meters_per_second<> leftVelocityRef, + wpi::units::meters_per_second<> rightVelocityRef) { // This implements the linear time-varying differential drive controller in // theorem 8.7.4 of https://controls-in-frc.link/ // @@ -34,12 +33,12 @@ DifferentialDriveWheelVoltages LTVDifferentialDriveController::Calculate( // [vₗ] // [vᵣ] - wpi::units::meters_per_second_t velocity{(leftVelocity + rightVelocity) / + wpi::units::meters_per_second<> velocity{(leftVelocity + rightVelocity) / 2.0}; // The DARE is ill-conditioned if the velocity is close to zero, so don't // let the system stop. - if (wpi::units::math::abs(velocity) < 1e-4_mps) { + if (wpi::units::abs(velocity) < 1e-4_mps) { velocity = 1e-4_mps; } @@ -52,7 +51,7 @@ DifferentialDriveWheelVoltages LTVDifferentialDriveController::Calculate( m_error = r - x; m_error(2) = - wpi::math::AngleModulus(wpi::units::radian_t{m_error(2)}).value(); + wpi::math::AngleModulus(wpi::units::radians<>{m_error(2)}).value(); Eigen::Matrix A{ {0.0, 0.0, 0.0, 0.5, 0.5}, @@ -86,6 +85,6 @@ DifferentialDriveWheelVoltages LTVDifferentialDriveController::Calculate( Eigen::Vector2d u = K * inRobotFrame * m_error; - return DifferentialDriveWheelVoltages{wpi::units::volt_t{u(0)}, - wpi::units::volt_t{u(1)}}; + return DifferentialDriveWheelVoltages{wpi::units::volts<>{u(0)}, + wpi::units::volts<>{u(1)}}; } diff --git a/wpimath/src/main/native/cpp/controller/LTVUnicycleController.cpp b/wpimath/src/main/native/cpp/controller/LTVUnicycleController.cpp index e262cdc031c..1d4d5a58695 100644 --- a/wpimath/src/main/native/cpp/controller/LTVUnicycleController.cpp +++ b/wpimath/src/main/native/cpp/controller/LTVUnicycleController.cpp @@ -11,15 +11,14 @@ #include "wpi/math/linalg/DARE.hpp" #include "wpi/math/system/Discretization.hpp" #include "wpi/units/angular_velocity.hpp" -#include "wpi/units/math.hpp" #include "wpi/units/velocity.hpp" using namespace wpi::math; ChassisVelocities LTVUnicycleController::Calculate( const Pose2d& currentPose, const Pose2d& poseRef, - wpi::units::meters_per_second_t linearVelocityRef, - wpi::units::radians_per_second_t angularVelocityRef) { + wpi::units::meters_per_second<> linearVelocityRef, + wpi::units::radians_per_second<> angularVelocityRef) { // The change in global pose for a unicycle is defined by the following three // equations. // @@ -59,7 +58,7 @@ ChassisVelocities LTVUnicycleController::Calculate( // The DARE is ill-conditioned if the velocity is close to zero, so don't // let the system stop. - if (wpi::units::math::abs(linearVelocityRef) < 1e-4_mps) { + if (wpi::units::abs(linearVelocityRef) < 1e-4_mps) { linearVelocityRef = 1e-4_mps; } @@ -85,6 +84,6 @@ ChassisVelocities LTVUnicycleController::Calculate( Eigen::Vector2d u = K * e; return ChassisVelocities{ - linearVelocityRef + wpi::units::meters_per_second_t{u(0)}, 0_mps, - angularVelocityRef + wpi::units::radians_per_second_t{u(1)}}; + linearVelocityRef + wpi::units::meters_per_second<>{u(0)}, 0_mps, + angularVelocityRef + wpi::units::radians_per_second<>{u(1)}}; } diff --git a/wpimath/src/main/native/cpp/controller/proto/ArmFeedforwardProto.cpp b/wpimath/src/main/native/cpp/controller/proto/ArmFeedforwardProto.cpp index 7f66c6f7992..0227421d093 100644 --- a/wpimath/src/main/native/cpp/controller/proto/ArmFeedforwardProto.cpp +++ b/wpimath/src/main/native/cpp/controller/proto/ArmFeedforwardProto.cpp @@ -16,10 +16,10 @@ wpi::util::Protobuf::Unpack(InputStream& stream) { } return wpi::math::ArmFeedforward{ - wpi::units::volt_t{msg.ks}, - wpi::units::volt_t{msg.kg}, - wpi::units::unit_t{msg.kv}, - wpi::units::unit_t{msg.ka}, + wpi::units::volts<>{msg.ks}, + wpi::units::volts<>{msg.kg}, + wpi::units::unit{msg.kv}, + wpi::units::unit{msg.ka}, }; } diff --git a/wpimath/src/main/native/cpp/controller/proto/DifferentialDriveFeedforwardProto.cpp b/wpimath/src/main/native/cpp/controller/proto/DifferentialDriveFeedforwardProto.cpp index 5bd5ea0f48c..aacaa562736 100644 --- a/wpimath/src/main/native/cpp/controller/proto/DifferentialDriveFeedforwardProto.cpp +++ b/wpimath/src/main/native/cpp/controller/proto/DifferentialDriveFeedforwardProto.cpp @@ -15,9 +15,9 @@ std::optional wpi::util::Protobuf< return wpi::math::DifferentialDriveFeedforward{ decltype(1_V / 1_mps){msg.kvLinear}, - decltype(1_V / 1_mps_sq){msg.kaLinear}, + decltype(1_V / 1_mps2){msg.kaLinear}, decltype(1_V / 1_mps){msg.kvAngular}, - decltype(1_V / 1_mps_sq){msg.kaAngular}, + decltype(1_V / 1_mps2){msg.kaAngular}, }; } diff --git a/wpimath/src/main/native/cpp/controller/proto/DifferentialDriveWheelVoltagesProto.cpp b/wpimath/src/main/native/cpp/controller/proto/DifferentialDriveWheelVoltagesProto.cpp index 7429e646609..61703e714aa 100644 --- a/wpimath/src/main/native/cpp/controller/proto/DifferentialDriveWheelVoltagesProto.cpp +++ b/wpimath/src/main/native/cpp/controller/proto/DifferentialDriveWheelVoltagesProto.cpp @@ -16,8 +16,8 @@ std::optional wpi::util::Protobuf< } return wpi::math::DifferentialDriveWheelVoltages{ - wpi::units::volt_t{msg.left}, - wpi::units::volt_t{msg.right}, + wpi::units::volts<>{msg.left}, + wpi::units::volts<>{msg.right}, }; } diff --git a/wpimath/src/main/native/cpp/controller/proto/ElevatorFeedforwardProto.cpp b/wpimath/src/main/native/cpp/controller/proto/ElevatorFeedforwardProto.cpp index dd0c7665055..359cffe8ea5 100644 --- a/wpimath/src/main/native/cpp/controller/proto/ElevatorFeedforwardProto.cpp +++ b/wpimath/src/main/native/cpp/controller/proto/ElevatorFeedforwardProto.cpp @@ -16,10 +16,10 @@ std::optional wpi::util::Protobuf< } return wpi::math::ElevatorFeedforward{ - wpi::units::volt_t{msg.ks}, - wpi::units::volt_t{msg.kg}, - wpi::units::unit_t{msg.kv}, - wpi::units::unit_t{msg.ka}, + wpi::units::volts<>{msg.ks}, + wpi::units::volts<>{msg.kg}, + wpi::units::unit{msg.kv}, + wpi::units::unit{msg.ka}, }; } diff --git a/wpimath/src/main/native/cpp/controller/struct/ArmFeedforwardStruct.cpp b/wpimath/src/main/native/cpp/controller/struct/ArmFeedforwardStruct.cpp index f51bac90ebc..e41ea6ad984 100644 --- a/wpimath/src/main/native/cpp/controller/struct/ArmFeedforwardStruct.cpp +++ b/wpimath/src/main/native/cpp/controller/struct/ArmFeedforwardStruct.cpp @@ -15,11 +15,11 @@ using StructType = wpi::util::Struct; wpi::math::ArmFeedforward StructType::Unpack(std::span data) { return wpi::math::ArmFeedforward{ - wpi::units::volt_t{wpi::util::UnpackStruct(data)}, - wpi::units::volt_t{wpi::util::UnpackStruct(data)}, - wpi::units::unit_t{ + wpi::units::volts<>{wpi::util::UnpackStruct(data)}, + wpi::units::volts<>{wpi::util::UnpackStruct(data)}, + wpi::units::unit{ wpi::util::UnpackStruct(data)}, - wpi::units::unit_t{ + wpi::units::unit{ wpi::util::UnpackStruct(data)}, }; } diff --git a/wpimath/src/main/native/cpp/controller/struct/DifferentialDriveFeedforwardStruct.cpp b/wpimath/src/main/native/cpp/controller/struct/DifferentialDriveFeedforwardStruct.cpp index 18d7d9f5e73..427f6d46a94 100644 --- a/wpimath/src/main/native/cpp/controller/struct/DifferentialDriveFeedforwardStruct.cpp +++ b/wpimath/src/main/native/cpp/controller/struct/DifferentialDriveFeedforwardStruct.cpp @@ -16,11 +16,11 @@ wpi::util::Struct::Unpack( std::span data) { return {decltype(1_V / 1_mps){wpi::util::UnpackStruct(data)}, - decltype(1_V / 1_mps_sq){ + decltype(1_V / 1_mps2){ wpi::util::UnpackStruct(data)}, decltype(1_V / 1_mps){ wpi::util::UnpackStruct(data)}, - decltype(1_V / 1_mps_sq){ + decltype(1_V / 1_mps2){ wpi::util::UnpackStruct(data)}}; } diff --git a/wpimath/src/main/native/cpp/controller/struct/DifferentialDriveWheelVoltagesStruct.cpp b/wpimath/src/main/native/cpp/controller/struct/DifferentialDriveWheelVoltagesStruct.cpp index 5a2c73deafb..994bea53180 100644 --- a/wpimath/src/main/native/cpp/controller/struct/DifferentialDriveWheelVoltagesStruct.cpp +++ b/wpimath/src/main/native/cpp/controller/struct/DifferentialDriveWheelVoltagesStruct.cpp @@ -14,8 +14,8 @@ using StructType = wpi::util::Struct; wpi::math::DifferentialDriveWheelVoltages StructType::Unpack( std::span data) { return wpi::math::DifferentialDriveWheelVoltages{ - wpi::units::volt_t{wpi::util::UnpackStruct(data)}, - wpi::units::volt_t{wpi::util::UnpackStruct(data)}, + wpi::units::volts<>{wpi::util::UnpackStruct(data)}, + wpi::units::volts<>{wpi::util::UnpackStruct(data)}, }; } diff --git a/wpimath/src/main/native/cpp/controller/struct/ElevatorFeedforwardStruct.cpp b/wpimath/src/main/native/cpp/controller/struct/ElevatorFeedforwardStruct.cpp index ebec3d64fda..80bc037cbe5 100644 --- a/wpimath/src/main/native/cpp/controller/struct/ElevatorFeedforwardStruct.cpp +++ b/wpimath/src/main/native/cpp/controller/struct/ElevatorFeedforwardStruct.cpp @@ -16,11 +16,11 @@ using StructType = wpi::util::Struct; wpi::math::ElevatorFeedforward StructType::Unpack( std::span data) { return wpi::math::ElevatorFeedforward{ - wpi::units::volt_t{wpi::util::UnpackStruct(data)}, - wpi::units::volt_t{wpi::util::UnpackStruct(data)}, - wpi::units::unit_t{ + wpi::units::volts<>{wpi::util::UnpackStruct(data)}, + wpi::units::volts<>{wpi::util::UnpackStruct(data)}, + wpi::units::unit{ wpi::util::UnpackStruct(data)}, - wpi::units::unit_t{ + wpi::units::unit{ wpi::util::UnpackStruct(data)}, }; } diff --git a/wpimath/src/main/native/cpp/estimator/DifferentialDrivePoseEstimator.cpp b/wpimath/src/main/native/cpp/estimator/DifferentialDrivePoseEstimator.cpp index 229a4e9ec83..b8e35e0294e 100644 --- a/wpimath/src/main/native/cpp/estimator/DifferentialDrivePoseEstimator.cpp +++ b/wpimath/src/main/native/cpp/estimator/DifferentialDrivePoseEstimator.cpp @@ -14,15 +14,15 @@ using namespace wpi::math; DifferentialDrivePoseEstimator::DifferentialDrivePoseEstimator( - const Rotation2d& gyroAngle, wpi::units::meter_t leftDistance, - wpi::units::meter_t rightDistance, const Pose2d& initialPose) + const Rotation2d& gyroAngle, wpi::units::meters<> leftDistance, + wpi::units::meters<> rightDistance, const Pose2d& initialPose) : DifferentialDrivePoseEstimator{gyroAngle, leftDistance, rightDistance, initialPose, {0.02, 0.02, 0.01}, {0.1, 0.1, 0.1}} {} DifferentialDrivePoseEstimator::DifferentialDrivePoseEstimator( - const Rotation2d& gyroAngle, wpi::units::meter_t leftDistance, - wpi::units::meter_t rightDistance, const Pose2d& initialPose, + const Rotation2d& gyroAngle, wpi::units::meters<> leftDistance, + wpi::units::meters<> rightDistance, const Pose2d& initialPose, const wpi::util::array& stateStdDevs, const wpi::util::array& visionMeasurementStdDevs) : PoseEstimator(m_odometryImpl, stateStdDevs, visionMeasurementStdDevs), diff --git a/wpimath/src/main/native/cpp/estimator/DifferentialDrivePoseEstimator3d.cpp b/wpimath/src/main/native/cpp/estimator/DifferentialDrivePoseEstimator3d.cpp index 4f9a00aee73..49f54e3046f 100644 --- a/wpimath/src/main/native/cpp/estimator/DifferentialDrivePoseEstimator3d.cpp +++ b/wpimath/src/main/native/cpp/estimator/DifferentialDrivePoseEstimator3d.cpp @@ -14,8 +14,8 @@ using namespace wpi::math; DifferentialDrivePoseEstimator3d::DifferentialDrivePoseEstimator3d( - const Rotation3d& gyroAngle, wpi::units::meter_t leftDistance, - wpi::units::meter_t rightDistance, const Pose3d& initialPose) + const Rotation3d& gyroAngle, wpi::units::meters<> leftDistance, + wpi::units::meters<> rightDistance, const Pose3d& initialPose) : DifferentialDrivePoseEstimator3d{gyroAngle, leftDistance, rightDistance, @@ -24,8 +24,8 @@ DifferentialDrivePoseEstimator3d::DifferentialDrivePoseEstimator3d( {0.1, 0.1, 0.1, 0.1}} {} DifferentialDrivePoseEstimator3d::DifferentialDrivePoseEstimator3d( - const Rotation3d& gyroAngle, wpi::units::meter_t leftDistance, - wpi::units::meter_t rightDistance, const Pose3d& initialPose, + const Rotation3d& gyroAngle, wpi::units::meters<> leftDistance, + wpi::units::meters<> rightDistance, const Pose3d& initialPose, const wpi::util::array& stateStdDevs, const wpi::util::array& visionMeasurementStdDevs) : PoseEstimator3d(m_odometryImpl, stateStdDevs, visionMeasurementStdDevs), diff --git a/wpimath/src/main/native/cpp/filter/BiquadFilterDesign.cpp b/wpimath/src/main/native/cpp/filter/BiquadFilterDesign.cpp index 00460eb20d1..95dcac24bc8 100644 --- a/wpimath/src/main/native/cpp/filter/BiquadFilterDesign.cpp +++ b/wpimath/src/main/native/cpp/filter/BiquadFilterDesign.cpp @@ -82,8 +82,8 @@ void RejectLpHpKindForBandOverload(const char* factoryName, } // namespace BiquadFilter BiquadFilter::Butterworth(Kind kind, int order, - wpi::units::hertz_t sampleRate, - wpi::units::hertz_t cutoff) { + wpi::units::hertz<> sampleRate, + wpi::units::hertz<> cutoff) { RejectBandKindForLpHpOverload("Butterworth", kind); ValidateClassicalArgs(kind, order, sampleRate.value(), cutoff.value(), 0.0); return BiquadFilter{filter::internal::DesignFromAnalogLp( @@ -92,9 +92,9 @@ BiquadFilter BiquadFilter::Butterworth(Kind kind, int order, } BiquadFilter BiquadFilter::Butterworth(Kind kind, int order, - wpi::units::hertz_t sampleRate, - wpi::units::hertz_t lowCutoff, - wpi::units::hertz_t highCutoff) { + wpi::units::hertz<> sampleRate, + wpi::units::hertz<> lowCutoff, + wpi::units::hertz<> highCutoff) { RejectLpHpKindForBandOverload("Butterworth", kind); ValidateClassicalArgs(kind, order, sampleRate.value(), lowCutoff.value(), highCutoff.value()); @@ -104,9 +104,9 @@ BiquadFilter BiquadFilter::Butterworth(Kind kind, int order, } BiquadFilter BiquadFilter::ChebyshevI(Kind kind, int order, - wpi::units::hertz_t sampleRate, - wpi::units::hertz_t lowCutoff, - wpi::units::hertz_t highCutoff, + wpi::units::hertz<> sampleRate, + wpi::units::hertz<> lowCutoff, + wpi::units::hertz<> highCutoff, double rippleDb) { RejectLpHpKindForBandOverload("ChebyshevI", kind); ValidateClassicalArgs(kind, order, sampleRate.value(), lowCutoff.value(), @@ -121,8 +121,8 @@ BiquadFilter BiquadFilter::ChebyshevI(Kind kind, int order, } BiquadFilter BiquadFilter::ChebyshevI(Kind kind, int order, - wpi::units::hertz_t sampleRate, - wpi::units::hertz_t cutoff, + wpi::units::hertz<> sampleRate, + wpi::units::hertz<> cutoff, double rippleDb) { RejectBandKindForLpHpOverload("ChebyshevI", kind); ValidateClassicalArgs(kind, order, sampleRate.value(), cutoff.value(), 0.0); @@ -136,9 +136,9 @@ BiquadFilter BiquadFilter::ChebyshevI(Kind kind, int order, } BiquadFilter BiquadFilter::ChebyshevII(Kind kind, int order, - wpi::units::hertz_t sampleRate, - wpi::units::hertz_t lowCutoff, - wpi::units::hertz_t highCutoff, + wpi::units::hertz<> sampleRate, + wpi::units::hertz<> lowCutoff, + wpi::units::hertz<> highCutoff, double stopAttenDb) { RejectLpHpKindForBandOverload("ChebyshevII", kind); ValidateClassicalArgs(kind, order, sampleRate.value(), lowCutoff.value(), @@ -154,8 +154,8 @@ BiquadFilter BiquadFilter::ChebyshevII(Kind kind, int order, } BiquadFilter BiquadFilter::ChebyshevII(Kind kind, int order, - wpi::units::hertz_t sampleRate, - wpi::units::hertz_t cutoff, + wpi::units::hertz<> sampleRate, + wpi::units::hertz<> cutoff, double stopAttenDb) { RejectBandKindForLpHpOverload("ChebyshevII", kind); ValidateClassicalArgs(kind, order, sampleRate.value(), cutoff.value(), 0.0); @@ -170,9 +170,9 @@ BiquadFilter BiquadFilter::ChebyshevII(Kind kind, int order, } BiquadFilter BiquadFilter::Elliptic(Kind kind, int order, - wpi::units::hertz_t sampleRate, - wpi::units::hertz_t lowCutoff, - wpi::units::hertz_t highCutoff, + wpi::units::hertz<> sampleRate, + wpi::units::hertz<> lowCutoff, + wpi::units::hertz<> highCutoff, double rippleDb, double stopAttenDb) { RejectLpHpKindForBandOverload("Elliptic", kind); ValidateClassicalArgs(kind, order, sampleRate.value(), lowCutoff.value(), @@ -192,8 +192,8 @@ BiquadFilter BiquadFilter::Elliptic(Kind kind, int order, } BiquadFilter BiquadFilter::Elliptic(Kind kind, int order, - wpi::units::hertz_t sampleRate, - wpi::units::hertz_t cutoff, double rippleDb, + wpi::units::hertz<> sampleRate, + wpi::units::hertz<> cutoff, double rippleDb, double stopAttenDb) { RejectBandKindForLpHpOverload("Elliptic", kind); ValidateClassicalArgs(kind, order, sampleRate.value(), cutoff.value(), 0.0); @@ -211,8 +211,8 @@ BiquadFilter BiquadFilter::Elliptic(Kind kind, int order, sampleRate.value(), cutoff.value(), 0.0)}; } -BiquadFilter BiquadFilter::Notch(wpi::units::hertz_t sampleRate, - wpi::units::hertz_t centerFrequency, +BiquadFilter BiquadFilter::Notch(wpi::units::hertz<> sampleRate, + wpi::units::hertz<> centerFrequency, double qualityFactor) { const double fs = sampleRate.value(); const double f0 = centerFrequency.value(); diff --git a/wpimath/src/main/native/cpp/filter/Debouncer.cpp b/wpimath/src/main/native/cpp/filter/Debouncer.cpp index c4383c0ff42..8ea5dd99403 100644 --- a/wpimath/src/main/native/cpp/filter/Debouncer.cpp +++ b/wpimath/src/main/native/cpp/filter/Debouncer.cpp @@ -9,7 +9,7 @@ using namespace wpi::math; -Debouncer::Debouncer(wpi::units::second_t debounceTime, DebounceType type) +Debouncer::Debouncer(wpi::units::seconds<> debounceTime, DebounceType type) : m_debounceTime(debounceTime), m_debounceType(type) { m_baseline = m_debounceType == DebounceType::FALLING; ResetTimer(); diff --git a/wpimath/src/main/native/cpp/filter/EdgeCounterFilter.cpp b/wpimath/src/main/native/cpp/filter/EdgeCounterFilter.cpp index 3a1098eb706..87ae29066dc 100644 --- a/wpimath/src/main/native/cpp/filter/EdgeCounterFilter.cpp +++ b/wpimath/src/main/native/cpp/filter/EdgeCounterFilter.cpp @@ -9,7 +9,7 @@ using namespace wpi::math; -EdgeCounterFilter::EdgeCounterFilter(int requiredEdges, units::second_t window) +EdgeCounterFilter::EdgeCounterFilter(int requiredEdges, units::seconds<> window) : m_requiredEdges(requiredEdges), m_windowTime(window) { ResetTimer(); } diff --git a/wpimath/src/main/native/cpp/geometry/Rotation2d.cpp b/wpimath/src/main/native/cpp/geometry/Rotation2d.cpp index 58136b2c45c..57b190bcc03 100644 --- a/wpimath/src/main/native/cpp/geometry/Rotation2d.cpp +++ b/wpimath/src/main/native/cpp/geometry/Rotation2d.cpp @@ -12,5 +12,5 @@ void wpi::math::to_json(wpi::util::json& json, const Rotation2d& rotation) { } void wpi::math::from_json(const wpi::util::json& json, Rotation2d& rotation) { - rotation = Rotation2d{wpi::units::radian_t{json.at("radians").get_number()}}; + rotation = Rotation2d{wpi::units::radians<>{json.at("radians").get_number()}}; } diff --git a/wpimath/src/main/native/cpp/geometry/Translation2d.cpp b/wpimath/src/main/native/cpp/geometry/Translation2d.cpp index a9dfb7ba2bc..47772340efb 100644 --- a/wpimath/src/main/native/cpp/geometry/Translation2d.cpp +++ b/wpimath/src/main/native/cpp/geometry/Translation2d.cpp @@ -16,6 +16,6 @@ void wpi::math::to_json(wpi::util::json& json, void wpi::math::from_json(const wpi::util::json& json, Translation2d& translation) { - translation = Translation2d{wpi::units::meter_t{json.at("x").get_number()}, - wpi::units::meter_t{json.at("y").get_number()}}; + translation = Translation2d{wpi::units::meters<>{json.at("x").get_number()}, + wpi::units::meters<>{json.at("y").get_number()}}; } diff --git a/wpimath/src/main/native/cpp/geometry/Translation3d.cpp b/wpimath/src/main/native/cpp/geometry/Translation3d.cpp index c9b509f5619..05fa7eb0be4 100644 --- a/wpimath/src/main/native/cpp/geometry/Translation3d.cpp +++ b/wpimath/src/main/native/cpp/geometry/Translation3d.cpp @@ -17,7 +17,7 @@ void wpi::math::to_json(wpi::util::json& json, void wpi::math::from_json(const wpi::util::json& json, Translation3d& translation) { - translation = Translation3d{wpi::units::meter_t{json.at("x").get_number()}, - wpi::units::meter_t{json.at("y").get_number()}, - wpi::units::meter_t{json.at("z").get_number()}}; + translation = Translation3d{wpi::units::meters<>{json.at("x").get_number()}, + wpi::units::meters<>{json.at("y").get_number()}, + wpi::units::meters<>{json.at("z").get_number()}}; } diff --git a/wpimath/src/main/native/cpp/geometry/proto/Rotation2dProto.cpp b/wpimath/src/main/native/cpp/geometry/proto/Rotation2dProto.cpp index ee5217c82e6..5f502ac6dc7 100644 --- a/wpimath/src/main/native/cpp/geometry/proto/Rotation2dProto.cpp +++ b/wpimath/src/main/native/cpp/geometry/proto/Rotation2dProto.cpp @@ -14,7 +14,7 @@ wpi::util::Protobuf::Unpack(InputStream& stream) { } return wpi::math::Rotation2d{ - wpi::units::radian_t{msg.value}, + wpi::units::radians<>{msg.value}, }; } diff --git a/wpimath/src/main/native/cpp/geometry/proto/Translation2dProto.cpp b/wpimath/src/main/native/cpp/geometry/proto/Translation2dProto.cpp index 15736254b79..581db65dcfd 100644 --- a/wpimath/src/main/native/cpp/geometry/proto/Translation2dProto.cpp +++ b/wpimath/src/main/native/cpp/geometry/proto/Translation2dProto.cpp @@ -14,8 +14,8 @@ wpi::util::Protobuf::Unpack(InputStream& stream) { } return wpi::math::Translation2d{ - wpi::units::meter_t{msg.x}, - wpi::units::meter_t{msg.y}, + wpi::units::meters<>{msg.x}, + wpi::units::meters<>{msg.y}, }; } diff --git a/wpimath/src/main/native/cpp/geometry/proto/Translation3dProto.cpp b/wpimath/src/main/native/cpp/geometry/proto/Translation3dProto.cpp index d86443be01c..67d191d6e03 100644 --- a/wpimath/src/main/native/cpp/geometry/proto/Translation3dProto.cpp +++ b/wpimath/src/main/native/cpp/geometry/proto/Translation3dProto.cpp @@ -14,9 +14,9 @@ wpi::util::Protobuf::Unpack(InputStream& stream) { } return wpi::math::Translation3d{ - wpi::units::meter_t{msg.x}, - wpi::units::meter_t{msg.y}, - wpi::units::meter_t{msg.z}, + wpi::units::meters<>{msg.x}, + wpi::units::meters<>{msg.y}, + wpi::units::meters<>{msg.z}, }; } diff --git a/wpimath/src/main/native/cpp/geometry/proto/Twist2dProto.cpp b/wpimath/src/main/native/cpp/geometry/proto/Twist2dProto.cpp index 87c324fe9be..c2a142290c2 100644 --- a/wpimath/src/main/native/cpp/geometry/proto/Twist2dProto.cpp +++ b/wpimath/src/main/native/cpp/geometry/proto/Twist2dProto.cpp @@ -14,9 +14,9 @@ wpi::util::Protobuf::Unpack(InputStream& stream) { } return wpi::math::Twist2d{ - wpi::units::meter_t{msg.dx}, - wpi::units::meter_t{msg.dy}, - wpi::units::radian_t{msg.dtheta}, + wpi::units::meters<>{msg.dx}, + wpi::units::meters<>{msg.dy}, + wpi::units::radians<>{msg.dtheta}, }; } diff --git a/wpimath/src/main/native/cpp/geometry/proto/Twist3dProto.cpp b/wpimath/src/main/native/cpp/geometry/proto/Twist3dProto.cpp index 3526181d579..77ab07eaabb 100644 --- a/wpimath/src/main/native/cpp/geometry/proto/Twist3dProto.cpp +++ b/wpimath/src/main/native/cpp/geometry/proto/Twist3dProto.cpp @@ -14,9 +14,9 @@ wpi::util::Protobuf::Unpack(InputStream& stream) { } return wpi::math::Twist3d{ - wpi::units::meter_t{msg.dx}, wpi::units::meter_t{msg.dy}, - wpi::units::meter_t{msg.dz}, wpi::units::radian_t{msg.rx}, - wpi::units::radian_t{msg.ry}, wpi::units::radian_t{msg.rz}, + wpi::units::meters<>{msg.dx}, wpi::units::meters<>{msg.dy}, + wpi::units::meters<>{msg.dz}, wpi::units::radians<>{msg.rx}, + wpi::units::radians<>{msg.ry}, wpi::units::radians<>{msg.rz}, }; } diff --git a/wpimath/src/main/native/cpp/geometry/struct/Rotation2dStruct.cpp b/wpimath/src/main/native/cpp/geometry/struct/Rotation2dStruct.cpp index e52bb4b8e1d..783832ec4fa 100644 --- a/wpimath/src/main/native/cpp/geometry/struct/Rotation2dStruct.cpp +++ b/wpimath/src/main/native/cpp/geometry/struct/Rotation2dStruct.cpp @@ -12,7 +12,7 @@ using StructType = wpi::util::Struct; wpi::math::Rotation2d StructType::Unpack(std::span data) { return wpi::math::Rotation2d{ - wpi::units::radian_t{wpi::util::UnpackStruct(data)}, + wpi::units::radians<>{wpi::util::UnpackStruct(data)}, }; } diff --git a/wpimath/src/main/native/cpp/geometry/struct/Translation2dStruct.cpp b/wpimath/src/main/native/cpp/geometry/struct/Translation2dStruct.cpp index 0291d5c559f..ed067a77d31 100644 --- a/wpimath/src/main/native/cpp/geometry/struct/Translation2dStruct.cpp +++ b/wpimath/src/main/native/cpp/geometry/struct/Translation2dStruct.cpp @@ -13,8 +13,8 @@ using StructType = wpi::util::Struct; wpi::math::Translation2d StructType::Unpack(std::span data) { return wpi::math::Translation2d{ - wpi::units::meter_t{wpi::util::UnpackStruct(data)}, - wpi::units::meter_t{wpi::util::UnpackStruct(data)}, + wpi::units::meters<>{wpi::util::UnpackStruct(data)}, + wpi::units::meters<>{wpi::util::UnpackStruct(data)}, }; } diff --git a/wpimath/src/main/native/cpp/geometry/struct/Translation3dStruct.cpp b/wpimath/src/main/native/cpp/geometry/struct/Translation3dStruct.cpp index 7ce3153eca6..0f95da6e361 100644 --- a/wpimath/src/main/native/cpp/geometry/struct/Translation3dStruct.cpp +++ b/wpimath/src/main/native/cpp/geometry/struct/Translation3dStruct.cpp @@ -14,9 +14,9 @@ using StructType = wpi::util::Struct; wpi::math::Translation3d StructType::Unpack(std::span data) { return wpi::math::Translation3d{ - wpi::units::meter_t{wpi::util::UnpackStruct(data)}, - wpi::units::meter_t{wpi::util::UnpackStruct(data)}, - wpi::units::meter_t{wpi::util::UnpackStruct(data)}, + wpi::units::meters<>{wpi::util::UnpackStruct(data)}, + wpi::units::meters<>{wpi::util::UnpackStruct(data)}, + wpi::units::meters<>{wpi::util::UnpackStruct(data)}, }; } diff --git a/wpimath/src/main/native/cpp/geometry/struct/Twist2dStruct.cpp b/wpimath/src/main/native/cpp/geometry/struct/Twist2dStruct.cpp index 98f3fe36903..1f5251f7c8c 100644 --- a/wpimath/src/main/native/cpp/geometry/struct/Twist2dStruct.cpp +++ b/wpimath/src/main/native/cpp/geometry/struct/Twist2dStruct.cpp @@ -14,9 +14,9 @@ using StructType = wpi::util::Struct; wpi::math::Twist2d StructType::Unpack(std::span data) { return wpi::math::Twist2d{ - wpi::units::meter_t{wpi::util::UnpackStruct(data)}, - wpi::units::meter_t{wpi::util::UnpackStruct(data)}, - wpi::units::radian_t{wpi::util::UnpackStruct(data)}, + wpi::units::meters<>{wpi::util::UnpackStruct(data)}, + wpi::units::meters<>{wpi::util::UnpackStruct(data)}, + wpi::units::radians<>{wpi::util::UnpackStruct(data)}, }; } diff --git a/wpimath/src/main/native/cpp/geometry/struct/Twist3dStruct.cpp b/wpimath/src/main/native/cpp/geometry/struct/Twist3dStruct.cpp index c3552ec4822..e6d110abeed 100644 --- a/wpimath/src/main/native/cpp/geometry/struct/Twist3dStruct.cpp +++ b/wpimath/src/main/native/cpp/geometry/struct/Twist3dStruct.cpp @@ -17,12 +17,12 @@ using StructType = wpi::util::Struct; wpi::math::Twist3d StructType::Unpack(std::span data) { return wpi::math::Twist3d{ - wpi::units::meter_t{wpi::util::UnpackStruct(data)}, - wpi::units::meter_t{wpi::util::UnpackStruct(data)}, - wpi::units::meter_t{wpi::util::UnpackStruct(data)}, - wpi::units::radian_t{wpi::util::UnpackStruct(data)}, - wpi::units::radian_t{wpi::util::UnpackStruct(data)}, - wpi::units::radian_t{wpi::util::UnpackStruct(data)}, + wpi::units::meters<>{wpi::util::UnpackStruct(data)}, + wpi::units::meters<>{wpi::util::UnpackStruct(data)}, + wpi::units::meters<>{wpi::util::UnpackStruct(data)}, + wpi::units::radians<>{wpi::util::UnpackStruct(data)}, + wpi::units::radians<>{wpi::util::UnpackStruct(data)}, + wpi::units::radians<>{wpi::util::UnpackStruct(data)}, }; } diff --git a/wpimath/src/main/native/cpp/jni/Transform3dJNI.cpp b/wpimath/src/main/native/cpp/jni/Transform3dJNI.cpp index b46fe916f07..6901bf2f887 100644 --- a/wpimath/src/main/native/cpp/jni/Transform3dJNI.cpp +++ b/wpimath/src/main/native/cpp/jni/Transform3dJNI.cpp @@ -28,8 +28,8 @@ Java_org_wpilib_math_jni_Transform3dJNI_log jdouble relQx, jdouble relQy, jdouble relQz) { wpi::math::Transform3d transform3d{ - wpi::units::meter_t{relX}, wpi::units::meter_t{relY}, - wpi::units::meter_t{relZ}, + wpi::units::meters<>{relX}, wpi::units::meters<>{relY}, + wpi::units::meters<>{relZ}, wpi::math::Rotation3d{wpi::math::Quaternion{relQw, relQx, relQy, relQz}}}; wpi::math::Twist3d result = transform3d.Log(); diff --git a/wpimath/src/main/native/cpp/jni/Twist3dJNI.cpp b/wpimath/src/main/native/cpp/jni/Twist3dJNI.cpp index 23fd35bc7dc..bc4491b7cc4 100644 --- a/wpimath/src/main/native/cpp/jni/Twist3dJNI.cpp +++ b/wpimath/src/main/native/cpp/jni/Twist3dJNI.cpp @@ -26,9 +26,9 @@ Java_org_wpilib_math_jni_Twist3dJNI_exp jdouble twistRx, jdouble twistRy, jdouble twistRz) { wpi::math::Twist3d twist{ - wpi::units::meter_t{twistDx}, wpi::units::meter_t{twistDy}, - wpi::units::meter_t{twistDz}, wpi::units::radian_t{twistRx}, - wpi::units::radian_t{twistRy}, wpi::units::radian_t{twistRz}}; + wpi::units::meters<>{twistDx}, wpi::units::meters<>{twistDy}, + wpi::units::meters<>{twistDz}, wpi::units::radians<>{twistRx}, + wpi::units::radians<>{twistRy}, wpi::units::radians<>{twistRz}}; wpi::math::Transform3d result = twist.Exp(); diff --git a/wpimath/src/main/native/cpp/kinematics/ChassisAccelerations.cpp b/wpimath/src/main/native/cpp/kinematics/ChassisAccelerations.cpp index 5ed1db49cc8..e64e1f81d96 100644 --- a/wpimath/src/main/native/cpp/kinematics/ChassisAccelerations.cpp +++ b/wpimath/src/main/native/cpp/kinematics/ChassisAccelerations.cpp @@ -17,7 +17,7 @@ void wpi::math::to_json(wpi::util::json& json, void wpi::math::from_json(const wpi::util::json& json, ChassisAccelerations& accel) { accel = ChassisAccelerations{ - units::meters_per_second_squared_t{json.at("ax").get_number()}, - units::meters_per_second_squared_t{json.at("ay").get_number()}, - units::radians_per_second_squared_t{json.at("alpha").get_number()}}; + units::meters_per_second_squared<>{json.at("ax").get_number()}, + units::meters_per_second_squared<>{json.at("ay").get_number()}, + units::radians_per_second_squared<>{json.at("alpha").get_number()}}; } diff --git a/wpimath/src/main/native/cpp/kinematics/ChassisVelocities.cpp b/wpimath/src/main/native/cpp/kinematics/ChassisVelocities.cpp index 1a5dabebafd..c2c9893d110 100644 --- a/wpimath/src/main/native/cpp/kinematics/ChassisVelocities.cpp +++ b/wpimath/src/main/native/cpp/kinematics/ChassisVelocities.cpp @@ -18,7 +18,7 @@ void wpi::math::to_json(wpi::util::json& json, void wpi::math::from_json(const wpi::util::json& json, ChassisVelocities& velocities) { velocities = ChassisVelocities{ - wpi::units::meters_per_second_t{json.at("vx").get_number()}, - wpi::units::meters_per_second_t{json.at("vy").get_number()}, - wpi::units::radians_per_second_t{json.at("omega").get_number()}}; + wpi::units::meters_per_second<>{json.at("vx").get_number()}, + wpi::units::meters_per_second<>{json.at("vy").get_number()}, + wpi::units::radians_per_second<>{json.at("omega").get_number()}}; } diff --git a/wpimath/src/main/native/cpp/kinematics/DifferentialDriveOdometry.cpp b/wpimath/src/main/native/cpp/kinematics/DifferentialDriveOdometry.cpp index 4070563d8fb..908d21cde70 100644 --- a/wpimath/src/main/native/cpp/kinematics/DifferentialDriveOdometry.cpp +++ b/wpimath/src/main/native/cpp/kinematics/DifferentialDriveOdometry.cpp @@ -15,8 +15,8 @@ using namespace wpi::math; DifferentialDriveOdometry::DifferentialDriveOdometry( - const Rotation2d& gyroAngle, wpi::units::meter_t leftDistance, - wpi::units::meter_t rightDistance, const Pose2d& initialPose) + const Rotation2d& gyroAngle, wpi::units::meters<> leftDistance, + wpi::units::meters<> rightDistance, const Pose2d& initialPose) : Odometry(DifferentialDriveKinematics{1_m}, gyroAngle, {leftDistance, rightDistance}, initialPose) { wpi::util::ReportUsage("DifferentialDriveOdometry", ""); diff --git a/wpimath/src/main/native/cpp/kinematics/DifferentialDriveOdometry3d.cpp b/wpimath/src/main/native/cpp/kinematics/DifferentialDriveOdometry3d.cpp index 2982b8393c8..a20b5893b6d 100644 --- a/wpimath/src/main/native/cpp/kinematics/DifferentialDriveOdometry3d.cpp +++ b/wpimath/src/main/native/cpp/kinematics/DifferentialDriveOdometry3d.cpp @@ -15,8 +15,8 @@ using namespace wpi::math; DifferentialDriveOdometry3d::DifferentialDriveOdometry3d( - const Rotation3d& gyroAngle, wpi::units::meter_t leftDistance, - wpi::units::meter_t rightDistance, const Pose3d& initialPose) + const Rotation3d& gyroAngle, wpi::units::meters<> leftDistance, + wpi::units::meters<> rightDistance, const Pose3d& initialPose) : Odometry3d(DifferentialDriveKinematics{1_m}, gyroAngle, {leftDistance, rightDistance}, initialPose) { wpi::util::ReportUsage("DifferentialDriveOdometry3d", ""); diff --git a/wpimath/src/main/native/cpp/kinematics/MecanumDriveKinematics.cpp b/wpimath/src/main/native/cpp/kinematics/MecanumDriveKinematics.cpp index b91972af341..146dc4a889b 100644 --- a/wpimath/src/main/native/cpp/kinematics/MecanumDriveKinematics.cpp +++ b/wpimath/src/main/native/cpp/kinematics/MecanumDriveKinematics.cpp @@ -45,10 +45,10 @@ MecanumDriveWheelVelocities MecanumDriveKinematics::ToWheelVelocities( Eigen::Vector4d wheelsVector = m_inverseKinematics * chassisVelocitiesVector; MecanumDriveWheelVelocities wheelVelocities; - wheelVelocities.frontLeft = wpi::units::meters_per_second_t{wheelsVector(0)}; - wheelVelocities.frontRight = wpi::units::meters_per_second_t{wheelsVector(1)}; - wheelVelocities.rearLeft = wpi::units::meters_per_second_t{wheelsVector(2)}; - wheelVelocities.rearRight = wpi::units::meters_per_second_t{wheelsVector(3)}; + wheelVelocities.frontLeft = wpi::units::meters_per_second<>{wheelsVector(0)}; + wheelVelocities.frontRight = wpi::units::meters_per_second<>{wheelsVector(1)}; + wheelVelocities.rearLeft = wpi::units::meters_per_second<>{wheelsVector(2)}; + wheelVelocities.rearRight = wpi::units::meters_per_second<>{wheelsVector(3)}; return wheelVelocities; } @@ -62,9 +62,9 @@ ChassisVelocities MecanumDriveKinematics::ToChassisVelocities( m_forwardKinematics.solve(wheelVelocitiesVector); return { - wpi::units::meters_per_second_t{chassisVelocitiesVector(0)}, // NOLINT - wpi::units::meters_per_second_t{chassisVelocitiesVector(1)}, - wpi::units::radians_per_second_t{chassisVelocitiesVector(2)}}; + wpi::units::meters_per_second<>{chassisVelocitiesVector(0)}, // NOLINT + wpi::units::meters_per_second<>{chassisVelocitiesVector(1)}, + wpi::units::radians_per_second<>{chassisVelocitiesVector(2)}}; } Twist2d MecanumDriveKinematics::ToTwist2d( @@ -78,9 +78,9 @@ Twist2d MecanumDriveKinematics::ToTwist2d( Eigen::Vector3d twistVector = m_forwardKinematics.solve(wheelDeltasVector); - return {wpi::units::meter_t{twistVector(0)}, - wpi::units::meter_t{twistVector(1)}, - wpi::units::radian_t{twistVector(2)}}; + return {wpi::units::meters<>{twistVector(0)}, + wpi::units::meters<>{twistVector(1)}, + wpi::units::radians<>{twistVector(2)}}; } Twist2d MecanumDriveKinematics::ToTwist2d( @@ -91,9 +91,9 @@ Twist2d MecanumDriveKinematics::ToTwist2d( Eigen::Vector3d twistVector = m_forwardKinematics.solve(wheelDeltasVector); - return {wpi::units::meter_t{twistVector(0)}, - wpi::units::meter_t{twistVector(1)}, - wpi::units::radian_t{twistVector(2)}}; + return {wpi::units::meters<>{twistVector(0)}, + wpi::units::meters<>{twistVector(1)}, + wpi::units::radians<>{twistVector(2)}}; } void MecanumDriveKinematics::SetInverseKinematics(Translation2d fl, @@ -118,9 +118,9 @@ ChassisAccelerations MecanumDriveKinematics::ToChassisAccelerations( m_forwardKinematics.solve(wheelAccelerationsVector); return { - wpi::units::meters_per_second_squared_t{chassisAccelerationsVector(0)}, - wpi::units::meters_per_second_squared_t{chassisAccelerationsVector(1)}, - wpi::units::radians_per_second_squared_t{chassisAccelerationsVector(2)}}; + wpi::units::meters_per_second_squared<>{chassisAccelerationsVector(0)}, + wpi::units::meters_per_second_squared<>{chassisAccelerationsVector(1)}, + wpi::units::radians_per_second_squared<>{chassisAccelerationsVector(2)}}; } MecanumDriveWheelAccelerations MecanumDriveKinematics::ToWheelAccelerations( @@ -147,12 +147,12 @@ MecanumDriveWheelAccelerations MecanumDriveKinematics::ToWheelAccelerations( MecanumDriveWheelAccelerations wheelAccelerations; wheelAccelerations.frontLeft = - wpi::units::meters_per_second_squared_t{wheelsVector(0)}; + wpi::units::meters_per_second_squared<>{wheelsVector(0)}; wheelAccelerations.frontRight = - wpi::units::meters_per_second_squared_t{wheelsVector(1)}; + wpi::units::meters_per_second_squared<>{wheelsVector(1)}; wheelAccelerations.rearLeft = - wpi::units::meters_per_second_squared_t{wheelsVector(2)}; + wpi::units::meters_per_second_squared<>{wheelsVector(2)}; wheelAccelerations.rearRight = - wpi::units::meters_per_second_squared_t{wheelsVector(3)}; + wpi::units::meters_per_second_squared<>{wheelsVector(3)}; return wheelAccelerations; } diff --git a/wpimath/src/main/native/cpp/kinematics/proto/ChassisAccelerationsProto.cpp b/wpimath/src/main/native/cpp/kinematics/proto/ChassisAccelerationsProto.cpp index b573d60ff5e..6d0560e7673 100644 --- a/wpimath/src/main/native/cpp/kinematics/proto/ChassisAccelerationsProto.cpp +++ b/wpimath/src/main/native/cpp/kinematics/proto/ChassisAccelerationsProto.cpp @@ -14,9 +14,9 @@ std::optional wpi::util::Protobuf< } return wpi::math::ChassisAccelerations{ - units::meters_per_second_squared_t{msg.ax}, - units::meters_per_second_squared_t{msg.ay}, - units::radians_per_second_squared_t{msg.alpha}, + units::meters_per_second_squared<>{msg.ax}, + units::meters_per_second_squared<>{msg.ay}, + units::radians_per_second_squared<>{msg.alpha}, }; } diff --git a/wpimath/src/main/native/cpp/kinematics/proto/ChassisVelocitiesProto.cpp b/wpimath/src/main/native/cpp/kinematics/proto/ChassisVelocitiesProto.cpp index 61f1d33d21f..8610f1c4e38 100644 --- a/wpimath/src/main/native/cpp/kinematics/proto/ChassisVelocitiesProto.cpp +++ b/wpimath/src/main/native/cpp/kinematics/proto/ChassisVelocitiesProto.cpp @@ -14,9 +14,9 @@ wpi::util::Protobuf::Unpack(InputStream& stream) { } return wpi::math::ChassisVelocities{ - wpi::units::meters_per_second_t{msg.vx}, - wpi::units::meters_per_second_t{msg.vy}, - wpi::units::radians_per_second_t{msg.omega}, + wpi::units::meters_per_second<>{msg.vx}, + wpi::units::meters_per_second<>{msg.vy}, + wpi::units::radians_per_second<>{msg.omega}, }; } diff --git a/wpimath/src/main/native/cpp/kinematics/proto/DifferentialDriveKinematicsProto.cpp b/wpimath/src/main/native/cpp/kinematics/proto/DifferentialDriveKinematicsProto.cpp index ff165c6d065..dc5e00dd8f6 100644 --- a/wpimath/src/main/native/cpp/kinematics/proto/DifferentialDriveKinematicsProto.cpp +++ b/wpimath/src/main/native/cpp/kinematics/proto/DifferentialDriveKinematicsProto.cpp @@ -14,7 +14,7 @@ std::optional wpi::util::Protobuf< } return wpi::math::DifferentialDriveKinematics{ - wpi::units::meter_t{msg.trackwidth}, + wpi::units::meters<>{msg.trackwidth}, }; } diff --git a/wpimath/src/main/native/cpp/kinematics/proto/DifferentialDriveWheelAccelerationsProto.cpp b/wpimath/src/main/native/cpp/kinematics/proto/DifferentialDriveWheelAccelerationsProto.cpp index b39542fdc32..7927aaf4677 100644 --- a/wpimath/src/main/native/cpp/kinematics/proto/DifferentialDriveWheelAccelerationsProto.cpp +++ b/wpimath/src/main/native/cpp/kinematics/proto/DifferentialDriveWheelAccelerationsProto.cpp @@ -15,8 +15,8 @@ wpi::util::Protobuf::Unpack( } return wpi::math::DifferentialDriveWheelAccelerations{ - units::meters_per_second_squared_t{msg.left}, - units::meters_per_second_squared_t{msg.right}, + units::meters_per_second_squared<>{msg.left}, + units::meters_per_second_squared<>{msg.right}, }; } diff --git a/wpimath/src/main/native/cpp/kinematics/proto/DifferentialDriveWheelPositionsProto.cpp b/wpimath/src/main/native/cpp/kinematics/proto/DifferentialDriveWheelPositionsProto.cpp index c143144c4cd..23d675b781d 100644 --- a/wpimath/src/main/native/cpp/kinematics/proto/DifferentialDriveWheelPositionsProto.cpp +++ b/wpimath/src/main/native/cpp/kinematics/proto/DifferentialDriveWheelPositionsProto.cpp @@ -14,8 +14,8 @@ std::optional wpi::util::Protobuf< } return wpi::math::DifferentialDriveWheelPositions{ - wpi::units::meter_t{msg.left}, - wpi::units::meter_t{msg.right}, + wpi::units::meters<>{msg.left}, + wpi::units::meters<>{msg.right}, }; } diff --git a/wpimath/src/main/native/cpp/kinematics/proto/DifferentialDriveWheelVelocitiesProto.cpp b/wpimath/src/main/native/cpp/kinematics/proto/DifferentialDriveWheelVelocitiesProto.cpp index e742c21b023..f63499d58bf 100644 --- a/wpimath/src/main/native/cpp/kinematics/proto/DifferentialDriveWheelVelocitiesProto.cpp +++ b/wpimath/src/main/native/cpp/kinematics/proto/DifferentialDriveWheelVelocitiesProto.cpp @@ -14,8 +14,8 @@ std::optional wpi::util::Protobuf< } return wpi::math::DifferentialDriveWheelVelocities{ - wpi::units::meters_per_second_t{msg.left}, - wpi::units::meters_per_second_t{msg.right}, + wpi::units::meters_per_second<>{msg.left}, + wpi::units::meters_per_second<>{msg.right}, }; } diff --git a/wpimath/src/main/native/cpp/kinematics/proto/MecanumDriveWheelAccelerationsProto.cpp b/wpimath/src/main/native/cpp/kinematics/proto/MecanumDriveWheelAccelerationsProto.cpp index 7311ac426fc..10f484a9d04 100644 --- a/wpimath/src/main/native/cpp/kinematics/proto/MecanumDriveWheelAccelerationsProto.cpp +++ b/wpimath/src/main/native/cpp/kinematics/proto/MecanumDriveWheelAccelerationsProto.cpp @@ -14,10 +14,10 @@ std::optional wpi::util::Protobuf< } return wpi::math::MecanumDriveWheelAccelerations{ - units::meters_per_second_squared_t{msg.front_left}, - units::meters_per_second_squared_t{msg.front_right}, - units::meters_per_second_squared_t{msg.rear_left}, - units::meters_per_second_squared_t{msg.rear_right}, + units::meters_per_second_squared<>{msg.front_left}, + units::meters_per_second_squared<>{msg.front_right}, + units::meters_per_second_squared<>{msg.rear_left}, + units::meters_per_second_squared<>{msg.rear_right}, }; } diff --git a/wpimath/src/main/native/cpp/kinematics/proto/MecanumDriveWheelPositionsProto.cpp b/wpimath/src/main/native/cpp/kinematics/proto/MecanumDriveWheelPositionsProto.cpp index 7ad215be42c..28bb0be39c7 100644 --- a/wpimath/src/main/native/cpp/kinematics/proto/MecanumDriveWheelPositionsProto.cpp +++ b/wpimath/src/main/native/cpp/kinematics/proto/MecanumDriveWheelPositionsProto.cpp @@ -14,10 +14,10 @@ std::optional wpi::util::Protobuf< } return wpi::math::MecanumDriveWheelPositions{ - wpi::units::meter_t{msg.front_left}, - wpi::units::meter_t{msg.front_right}, - wpi::units::meter_t{msg.rear_left}, - wpi::units::meter_t{msg.rear_right}, + wpi::units::meters<>{msg.front_left}, + wpi::units::meters<>{msg.front_right}, + wpi::units::meters<>{msg.rear_left}, + wpi::units::meters<>{msg.rear_right}, }; } diff --git a/wpimath/src/main/native/cpp/kinematics/proto/MecanumDriveWheelVelocitiesProto.cpp b/wpimath/src/main/native/cpp/kinematics/proto/MecanumDriveWheelVelocitiesProto.cpp index b4fc7306963..a3aa8aea4a2 100644 --- a/wpimath/src/main/native/cpp/kinematics/proto/MecanumDriveWheelVelocitiesProto.cpp +++ b/wpimath/src/main/native/cpp/kinematics/proto/MecanumDriveWheelVelocitiesProto.cpp @@ -14,10 +14,10 @@ std::optional wpi::util::Protobuf< } return wpi::math::MecanumDriveWheelVelocities{ - wpi::units::meters_per_second_t{msg.front_left}, - wpi::units::meters_per_second_t{msg.front_right}, - wpi::units::meters_per_second_t{msg.rear_left}, - wpi::units::meters_per_second_t{msg.rear_right}, + wpi::units::meters_per_second<>{msg.front_left}, + wpi::units::meters_per_second<>{msg.front_right}, + wpi::units::meters_per_second<>{msg.rear_left}, + wpi::units::meters_per_second<>{msg.rear_right}, }; } diff --git a/wpimath/src/main/native/cpp/kinematics/proto/SwerveModuleAccelerationProto.cpp b/wpimath/src/main/native/cpp/kinematics/proto/SwerveModuleAccelerationProto.cpp index b8954fe0180..ecccc289b54 100644 --- a/wpimath/src/main/native/cpp/kinematics/proto/SwerveModuleAccelerationProto.cpp +++ b/wpimath/src/main/native/cpp/kinematics/proto/SwerveModuleAccelerationProto.cpp @@ -25,7 +25,7 @@ std::optional wpi::util::Protobuf< } return wpi::math::SwerveModuleAcceleration{ - units::meters_per_second_squared_t{msg.acceleration}, + units::meters_per_second_squared<>{msg.acceleration}, iangle[0], }; } diff --git a/wpimath/src/main/native/cpp/kinematics/proto/SwerveModulePositionProto.cpp b/wpimath/src/main/native/cpp/kinematics/proto/SwerveModulePositionProto.cpp index be049a2de12..f42577057f8 100644 --- a/wpimath/src/main/native/cpp/kinematics/proto/SwerveModulePositionProto.cpp +++ b/wpimath/src/main/native/cpp/kinematics/proto/SwerveModulePositionProto.cpp @@ -25,7 +25,7 @@ std::optional wpi::util::Protobuf< } return wpi::math::SwerveModulePosition{ - wpi::units::meter_t{msg.distance}, + wpi::units::meters<>{msg.distance}, iangle[0], }; } diff --git a/wpimath/src/main/native/cpp/kinematics/proto/SwerveModuleVelocityProto.cpp b/wpimath/src/main/native/cpp/kinematics/proto/SwerveModuleVelocityProto.cpp index 3a6f8a3bdc8..a4a20270e22 100644 --- a/wpimath/src/main/native/cpp/kinematics/proto/SwerveModuleVelocityProto.cpp +++ b/wpimath/src/main/native/cpp/kinematics/proto/SwerveModuleVelocityProto.cpp @@ -25,7 +25,7 @@ std::optional wpi::util::Protobuf< } return wpi::math::SwerveModuleVelocity{ - wpi::units::meters_per_second_t{msg.velocity}, + wpi::units::meters_per_second<>{msg.velocity}, iangle[0], }; } diff --git a/wpimath/src/main/native/cpp/kinematics/struct/ChassisAccelerationsStruct.cpp b/wpimath/src/main/native/cpp/kinematics/struct/ChassisAccelerationsStruct.cpp index 68a442b36d0..8b4806ba36b 100644 --- a/wpimath/src/main/native/cpp/kinematics/struct/ChassisAccelerationsStruct.cpp +++ b/wpimath/src/main/native/cpp/kinematics/struct/ChassisAccelerationsStruct.cpp @@ -13,11 +13,11 @@ wpi::math::ChassisAccelerations wpi::util::Struct< constexpr size_t AY_OFF = AX_OFF + 8; constexpr size_t ALPHA_OFF = AY_OFF + 8; return wpi::math::ChassisAccelerations{ - units::meters_per_second_squared_t{ + units::meters_per_second_squared<>{ wpi::util::UnpackStruct(data)}, - units::meters_per_second_squared_t{ + units::meters_per_second_squared<>{ wpi::util::UnpackStruct(data)}, - units::radians_per_second_squared_t{ + units::radians_per_second_squared<>{ wpi::util::UnpackStruct(data)}, }; } diff --git a/wpimath/src/main/native/cpp/kinematics/struct/ChassisVelocitiesStruct.cpp b/wpimath/src/main/native/cpp/kinematics/struct/ChassisVelocitiesStruct.cpp index 0bafd427e52..c1980af0af0 100644 --- a/wpimath/src/main/native/cpp/kinematics/struct/ChassisVelocitiesStruct.cpp +++ b/wpimath/src/main/native/cpp/kinematics/struct/ChassisVelocitiesStruct.cpp @@ -14,11 +14,11 @@ using StructType = wpi::util::Struct; wpi::math::ChassisVelocities StructType::Unpack(std::span data) { return wpi::math::ChassisVelocities{ - wpi::units::meters_per_second_t{ + wpi::units::meters_per_second<>{ wpi::util::UnpackStruct(data)}, - wpi::units::meters_per_second_t{ + wpi::units::meters_per_second<>{ wpi::util::UnpackStruct(data)}, - wpi::units::radians_per_second_t{ + wpi::units::radians_per_second<>{ wpi::util::UnpackStruct(data)}, }; } diff --git a/wpimath/src/main/native/cpp/kinematics/struct/DifferentialDriveKinematicsStruct.cpp b/wpimath/src/main/native/cpp/kinematics/struct/DifferentialDriveKinematicsStruct.cpp index 774a64651bf..d17abb06d54 100644 --- a/wpimath/src/main/native/cpp/kinematics/struct/DifferentialDriveKinematicsStruct.cpp +++ b/wpimath/src/main/native/cpp/kinematics/struct/DifferentialDriveKinematicsStruct.cpp @@ -13,7 +13,7 @@ using StructType = wpi::util::Struct; wpi::math::DifferentialDriveKinematics StructType::Unpack( std::span data) { return wpi::math::DifferentialDriveKinematics{ - wpi::units::meter_t{ + wpi::units::meters<>{ wpi::util::UnpackStruct(data)}, }; } diff --git a/wpimath/src/main/native/cpp/kinematics/struct/DifferentialDriveWheelAccelerationsStruct.cpp b/wpimath/src/main/native/cpp/kinematics/struct/DifferentialDriveWheelAccelerationsStruct.cpp index 486e8a2f613..a0efdb72d5a 100644 --- a/wpimath/src/main/native/cpp/kinematics/struct/DifferentialDriveWheelAccelerationsStruct.cpp +++ b/wpimath/src/main/native/cpp/kinematics/struct/DifferentialDriveWheelAccelerationsStruct.cpp @@ -13,9 +13,9 @@ wpi::util::Struct::Unpack( constexpr size_t LEFT_OFF = 0; constexpr size_t RIGHT_OFF = LEFT_OFF + 8; return wpi::math::DifferentialDriveWheelAccelerations{ - units::meters_per_second_squared_t{ + units::meters_per_second_squared<>{ wpi::util::UnpackStruct(data)}, - units::meters_per_second_squared_t{ + units::meters_per_second_squared<>{ wpi::util::UnpackStruct(data)}, }; } diff --git a/wpimath/src/main/native/cpp/kinematics/struct/DifferentialDriveWheelPositionsStruct.cpp b/wpimath/src/main/native/cpp/kinematics/struct/DifferentialDriveWheelPositionsStruct.cpp index 2317db6e238..db8f8979cc0 100644 --- a/wpimath/src/main/native/cpp/kinematics/struct/DifferentialDriveWheelPositionsStruct.cpp +++ b/wpimath/src/main/native/cpp/kinematics/struct/DifferentialDriveWheelPositionsStruct.cpp @@ -15,8 +15,8 @@ using StructType = wpi::math::DifferentialDriveWheelPositions StructType::Unpack( std::span data) { return wpi::math::DifferentialDriveWheelPositions{ - wpi::units::meter_t{wpi::util::UnpackStruct(data)}, - wpi::units::meter_t{wpi::util::UnpackStruct(data)}, + wpi::units::meters<>{wpi::util::UnpackStruct(data)}, + wpi::units::meters<>{wpi::util::UnpackStruct(data)}, }; } diff --git a/wpimath/src/main/native/cpp/kinematics/struct/DifferentialDriveWheelVelocitiesStruct.cpp b/wpimath/src/main/native/cpp/kinematics/struct/DifferentialDriveWheelVelocitiesStruct.cpp index 7694223fd9d..b4eec5a653b 100644 --- a/wpimath/src/main/native/cpp/kinematics/struct/DifferentialDriveWheelVelocitiesStruct.cpp +++ b/wpimath/src/main/native/cpp/kinematics/struct/DifferentialDriveWheelVelocitiesStruct.cpp @@ -15,9 +15,9 @@ using StructType = wpi::math::DifferentialDriveWheelVelocities StructType::Unpack( std::span data) { return wpi::math::DifferentialDriveWheelVelocities{ - wpi::units::meters_per_second_t{ + wpi::units::meters_per_second<>{ wpi::util::UnpackStruct(data)}, - wpi::units::meters_per_second_t{ + wpi::units::meters_per_second<>{ wpi::util::UnpackStruct(data)}, }; } diff --git a/wpimath/src/main/native/cpp/kinematics/struct/MecanumDriveWheelAccelerationsStruct.cpp b/wpimath/src/main/native/cpp/kinematics/struct/MecanumDriveWheelAccelerationsStruct.cpp index 68f27fa89d6..f0fa82627b7 100644 --- a/wpimath/src/main/native/cpp/kinematics/struct/MecanumDriveWheelAccelerationsStruct.cpp +++ b/wpimath/src/main/native/cpp/kinematics/struct/MecanumDriveWheelAccelerationsStruct.cpp @@ -15,13 +15,13 @@ wpi::util::Struct::Unpack( constexpr size_t REAR_LEFT_OFF = FRONT_RIGHT_OFF + 8; constexpr size_t REAR_RIGHT_OFF = REAR_LEFT_OFF + 8; return wpi::math::MecanumDriveWheelAccelerations{ - units::meters_per_second_squared_t{ + units::meters_per_second_squared<>{ wpi::util::UnpackStruct(data)}, - units::meters_per_second_squared_t{ + units::meters_per_second_squared<>{ wpi::util::UnpackStruct(data)}, - units::meters_per_second_squared_t{ + units::meters_per_second_squared<>{ wpi::util::UnpackStruct(data)}, - units::meters_per_second_squared_t{ + units::meters_per_second_squared<>{ wpi::util::UnpackStruct(data)}, }; } diff --git a/wpimath/src/main/native/cpp/kinematics/struct/MecanumDriveWheelPositionsStruct.cpp b/wpimath/src/main/native/cpp/kinematics/struct/MecanumDriveWheelPositionsStruct.cpp index fca8719b4a6..e0318819492 100644 --- a/wpimath/src/main/native/cpp/kinematics/struct/MecanumDriveWheelPositionsStruct.cpp +++ b/wpimath/src/main/native/cpp/kinematics/struct/MecanumDriveWheelPositionsStruct.cpp @@ -16,12 +16,13 @@ using StructType = wpi::util::Struct; wpi::math::MecanumDriveWheelPositions StructType::Unpack( std::span data) { return wpi::math::MecanumDriveWheelPositions{ - wpi::units::meter_t{ + wpi::units::meters<>{ wpi::util::UnpackStruct(data)}, - wpi::units::meter_t{ + wpi::units::meters<>{ wpi::util::UnpackStruct(data)}, - wpi::units::meter_t{wpi::util::UnpackStruct(data)}, - wpi::units::meter_t{ + wpi::units::meters<>{ + wpi::util::UnpackStruct(data)}, + wpi::units::meters<>{ wpi::util::UnpackStruct(data)}, }; } diff --git a/wpimath/src/main/native/cpp/kinematics/struct/MecanumDriveWheelVelocitiesStruct.cpp b/wpimath/src/main/native/cpp/kinematics/struct/MecanumDriveWheelVelocitiesStruct.cpp index 7b7d72e912b..11f6c4871f0 100644 --- a/wpimath/src/main/native/cpp/kinematics/struct/MecanumDriveWheelVelocitiesStruct.cpp +++ b/wpimath/src/main/native/cpp/kinematics/struct/MecanumDriveWheelVelocitiesStruct.cpp @@ -16,13 +16,13 @@ using StructType = wpi::util::Struct; wpi::math::MecanumDriveWheelVelocities StructType::Unpack( std::span data) { return wpi::math::MecanumDriveWheelVelocities{ - wpi::units::meters_per_second_t{ + wpi::units::meters_per_second<>{ wpi::util::UnpackStruct(data)}, - wpi::units::meters_per_second_t{ + wpi::units::meters_per_second<>{ wpi::util::UnpackStruct(data)}, - wpi::units::meters_per_second_t{ + wpi::units::meters_per_second<>{ wpi::util::UnpackStruct(data)}, - wpi::units::meters_per_second_t{ + wpi::units::meters_per_second<>{ wpi::util::UnpackStruct(data)}, }; } diff --git a/wpimath/src/main/native/cpp/kinematics/struct/SwerveModuleAccelerationStruct.cpp b/wpimath/src/main/native/cpp/kinematics/struct/SwerveModuleAccelerationStruct.cpp index f3dbcc093a6..9c4c4cbbea2 100644 --- a/wpimath/src/main/native/cpp/kinematics/struct/SwerveModuleAccelerationStruct.cpp +++ b/wpimath/src/main/native/cpp/kinematics/struct/SwerveModuleAccelerationStruct.cpp @@ -13,7 +13,7 @@ wpi::util::Struct::Unpack( constexpr size_t ACCELERATION_OFF = 0; constexpr size_t ANGLE_OFF = ACCELERATION_OFF + 8; return wpi::math::SwerveModuleAcceleration{ - units::meters_per_second_squared_t{ + units::meters_per_second_squared<>{ wpi::util::UnpackStruct(data)}, wpi::util::UnpackStruct(data)}; } diff --git a/wpimath/src/main/native/cpp/kinematics/struct/SwerveModulePositionStruct.cpp b/wpimath/src/main/native/cpp/kinematics/struct/SwerveModulePositionStruct.cpp index f3330645265..bcb19363de7 100644 --- a/wpimath/src/main/native/cpp/kinematics/struct/SwerveModulePositionStruct.cpp +++ b/wpimath/src/main/native/cpp/kinematics/struct/SwerveModulePositionStruct.cpp @@ -14,7 +14,7 @@ using StructType = wpi::util::Struct; wpi::math::SwerveModulePosition StructType::Unpack( std::span data) { return wpi::math::SwerveModulePosition{ - wpi::units::meter_t{wpi::util::UnpackStruct(data)}, + wpi::units::meters<>{wpi::util::UnpackStruct(data)}, wpi::util::UnpackStruct(data), }; } diff --git a/wpimath/src/main/native/cpp/kinematics/struct/SwerveModuleVelocityStruct.cpp b/wpimath/src/main/native/cpp/kinematics/struct/SwerveModuleVelocityStruct.cpp index 23334196cc2..17b0ad15823 100644 --- a/wpimath/src/main/native/cpp/kinematics/struct/SwerveModuleVelocityStruct.cpp +++ b/wpimath/src/main/native/cpp/kinematics/struct/SwerveModuleVelocityStruct.cpp @@ -14,7 +14,7 @@ using StructType = wpi::util::Struct; wpi::math::SwerveModuleVelocity StructType::Unpack( std::span data) { return wpi::math::SwerveModuleVelocity{ - wpi::units::meters_per_second_t{ + wpi::units::meters_per_second<>{ wpi::util::UnpackStruct(data)}, wpi::util::UnpackStruct(data), }; diff --git a/wpimath/src/main/native/cpp/shape/Ellipse2d.cpp b/wpimath/src/main/native/cpp/shape/Ellipse2d.cpp index 02dc7c60f54..d7b1b748569 100644 --- a/wpimath/src/main/native/cpp/shape/Ellipse2d.cpp +++ b/wpimath/src/main/native/cpp/shape/Ellipse2d.cpp @@ -45,8 +45,8 @@ Translation2d Ellipse2d::Nearest(const Translation2d& point) const { problem.solve(); - rotPoint = wpi::math::Translation2d{wpi::units::meter_t{x.value()}, - wpi::units::meter_t{y.value()}}; + rotPoint = wpi::math::Translation2d{wpi::units::meters<>{x.value()}, + wpi::units::meters<>{y.value()}}; } // Undo rotation diff --git a/wpimath/src/main/native/cpp/shape/proto/Ellipse2dProto.cpp b/wpimath/src/main/native/cpp/shape/proto/Ellipse2dProto.cpp index d8e230d3700..7e8b33576d9 100644 --- a/wpimath/src/main/native/cpp/shape/proto/Ellipse2dProto.cpp +++ b/wpimath/src/main/native/cpp/shape/proto/Ellipse2dProto.cpp @@ -27,8 +27,8 @@ wpi::util::Protobuf::Unpack(InputStream& stream) { return wpi::math::Ellipse2d{ ipose[0], - wpi::units::meter_t{msg.xSemiAxis}, - wpi::units::meter_t{msg.ySemiAxis}, + wpi::units::meters<>{msg.xSemiAxis}, + wpi::units::meters<>{msg.ySemiAxis}, }; } diff --git a/wpimath/src/main/native/cpp/shape/proto/Rectangle2dProto.cpp b/wpimath/src/main/native/cpp/shape/proto/Rectangle2dProto.cpp index c128416abe7..b50069e0671 100644 --- a/wpimath/src/main/native/cpp/shape/proto/Rectangle2dProto.cpp +++ b/wpimath/src/main/native/cpp/shape/proto/Rectangle2dProto.cpp @@ -27,8 +27,8 @@ wpi::util::Protobuf::Unpack(InputStream& stream) { return wpi::math::Rectangle2d{ ipose[0], - wpi::units::meter_t{msg.xWidth}, - wpi::units::meter_t{msg.yWidth}, + wpi::units::meters<>{msg.xWidth}, + wpi::units::meters<>{msg.yWidth}, }; } diff --git a/wpimath/src/main/native/cpp/shape/struct/Ellipse2dStruct.cpp b/wpimath/src/main/native/cpp/shape/struct/Ellipse2dStruct.cpp index b58a409bc26..e07a2981fba 100644 --- a/wpimath/src/main/native/cpp/shape/struct/Ellipse2dStruct.cpp +++ b/wpimath/src/main/native/cpp/shape/struct/Ellipse2dStruct.cpp @@ -16,9 +16,9 @@ using StructType = wpi::util::Struct; wpi::math::Ellipse2d StructType::Unpack(std::span data) { return wpi::math::Ellipse2d{ wpi::util::UnpackStruct(data), - wpi::units::meter_t{ + wpi::units::meters<>{ wpi::util::UnpackStruct(data)}, - wpi::units::meter_t{ + wpi::units::meters<>{ wpi::util::UnpackStruct(data)}, }; } diff --git a/wpimath/src/main/native/cpp/shape/struct/Rectangle2dStruct.cpp b/wpimath/src/main/native/cpp/shape/struct/Rectangle2dStruct.cpp index 71d1dcc2df8..3456cf0732e 100644 --- a/wpimath/src/main/native/cpp/shape/struct/Rectangle2dStruct.cpp +++ b/wpimath/src/main/native/cpp/shape/struct/Rectangle2dStruct.cpp @@ -16,8 +16,8 @@ using StructType = wpi::util::Struct; wpi::math::Rectangle2d StructType::Unpack(std::span data) { return wpi::math::Rectangle2d{ wpi::util::UnpackStruct(data), - wpi::units::meter_t{wpi::util::UnpackStruct(data)}, - wpi::units::meter_t{wpi::util::UnpackStruct(data)}, + wpi::units::meters<>{wpi::util::UnpackStruct(data)}, + wpi::units::meters<>{wpi::util::UnpackStruct(data)}, }; } diff --git a/wpimath/src/main/native/cpp/system/proto/DCMotorProto.cpp b/wpimath/src/main/native/cpp/system/proto/DCMotorProto.cpp index 901e2a873e5..195a7f38237 100644 --- a/wpimath/src/main/native/cpp/system/proto/DCMotorProto.cpp +++ b/wpimath/src/main/native/cpp/system/proto/DCMotorProto.cpp @@ -16,11 +16,11 @@ wpi::util::Protobuf::Unpack(InputStream& stream) { } return wpi::math::DCMotor{ - wpi::units::volt_t{msg.nominal_voltage}, - wpi::units::newton_meter_t{msg.stall_torque}, - wpi::units::ampere_t{msg.stall_current}, - wpi::units::ampere_t{msg.free_current}, - wpi::units::radians_per_second_t{msg.free_speed}, + wpi::units::volts<>{msg.nominal_voltage}, + wpi::units::newton_meters<>{msg.stall_torque}, + wpi::units::amperes<>{msg.stall_current}, + wpi::units::amperes<>{msg.free_current}, + wpi::units::radians_per_second<>{msg.free_speed}, }; } diff --git a/wpimath/src/main/native/cpp/system/struct/DCMotorStruct.cpp b/wpimath/src/main/native/cpp/system/struct/DCMotorStruct.cpp index e3e09475c9c..e43511a8295 100644 --- a/wpimath/src/main/native/cpp/system/struct/DCMotorStruct.cpp +++ b/wpimath/src/main/native/cpp/system/struct/DCMotorStruct.cpp @@ -16,15 +16,15 @@ using StructType = wpi::util::Struct; wpi::math::DCMotor StructType::Unpack(std::span data) { return wpi::math::DCMotor{ - wpi::units::volt_t{ + wpi::units::volts<>{ wpi::util::UnpackStruct(data)}, - wpi::units::newton_meter_t{ + wpi::units::newton_meters<>{ wpi::util::UnpackStruct(data)}, - wpi::units::ampere_t{ + wpi::units::amperes<>{ wpi::util::UnpackStruct(data)}, - wpi::units::ampere_t{ + wpi::units::amperes<>{ wpi::util::UnpackStruct(data)}, - wpi::units::radians_per_second_t{ + wpi::units::radians_per_second<>{ wpi::util::UnpackStruct(data)}, }; } diff --git a/wpimath/src/main/native/cpp/trajectory/DifferentialSample.cpp b/wpimath/src/main/native/cpp/trajectory/DifferentialSample.cpp index 415ba30a3a8..81d8df39f6c 100644 --- a/wpimath/src/main/native/cpp/trajectory/DifferentialSample.cpp +++ b/wpimath/src/main/native/cpp/trajectory/DifferentialSample.cpp @@ -25,12 +25,12 @@ void wpi::math::to_json(wpi::util::json& json, void wpi::math::from_json(const wpi::util::json& json, DifferentialSample& sample) { sample = DifferentialSample{ - wpi::units::second_t{json.at("time").get_number()}, + wpi::units::seconds<>{json.at("time").get_number()}, json.at("pose").get(), json.at("velocity").get(), json.at("acceleration").get(), - wpi::units::meters_per_second_t{json.at("leftVelocity").get_number()}, - wpi::units::meters_per_second_t{json.at("rightVelocity").get_number()}}; + wpi::units::meters_per_second<>{json.at("leftVelocity").get_number()}, + wpi::units::meters_per_second<>{json.at("rightVelocity").get_number()}}; } void wpi::math::to_json(wpi::util::json& json, diff --git a/wpimath/src/main/native/cpp/trajectory/DifferentialTrajectory.cpp b/wpimath/src/main/native/cpp/trajectory/DifferentialTrajectory.cpp index 225cec0107f..de66cdd4d66 100644 --- a/wpimath/src/main/native/cpp/trajectory/DifferentialTrajectory.cpp +++ b/wpimath/src/main/native/cpp/trajectory/DifferentialTrajectory.cpp @@ -32,7 +32,7 @@ using namespace wpi::math; DifferentialSample DifferentialTrajectory::Interpolate( const DifferentialSample& start, const DifferentialSample& end, double t) const { - wpi::units::second_t interpTime = wpi::util::Lerp(start.time, end.time, t); + wpi::units::seconds<> interpTime = wpi::util::Lerp(start.time, end.time, t); auto interpDt = interpTime - start.time; // The integration state holds wheel velocities (vₗ, vᵣ), which are @@ -102,23 +102,23 @@ DifferentialSample DifferentialTrajectory::Interpolate( auto alpha = wpi::util::Lerp(start.acceleration.alpha, end.acceleration.alpha, t); - Rotation2d heading{wpi::units::radian_t{theta}}; + Rotation2d heading{wpi::units::radians<>{theta}}; // Reconstruct the field-relative velocity from robot-relative forward // velocity. ChassisVelocities fieldVelocity = ChassisVelocities{ - wpi::units::meters_per_second_t{vx}, 0_mps, - wpi::units::radians_per_second_t{ + wpi::units::meters_per_second<>{vx}, 0_mps, + wpi::units::radians_per_second<>{ omega}}.ToFieldRelative(heading); return {interpTime, - Pose2d{wpi::units::meter_t{x}, wpi::units::meter_t{y}, heading}, + Pose2d{wpi::units::meters<>{x}, wpi::units::meters<>{y}, heading}, fieldVelocity, - ChassisAccelerations{wpi::units::meters_per_second_squared_t{ax}, - wpi::units::meters_per_second_squared_t{ay}, - wpi::units::radians_per_second_squared_t{alpha}}, - wpi::units::meters_per_second_t{vl}, - wpi::units::meters_per_second_t{vr}}; + ChassisAccelerations{wpi::units::meters_per_second_squared<>{ax}, + wpi::units::meters_per_second_squared<>{ay}, + wpi::units::radians_per_second_squared<>{alpha}}, + wpi::units::meters_per_second<>{vl}, + wpi::units::meters_per_second<>{vr}}; } DifferentialTrajectory DifferentialTrajectory::TransformBy( diff --git a/wpimath/src/main/native/cpp/trajectory/DrivetrainSplineTrajectory.cpp b/wpimath/src/main/native/cpp/trajectory/DrivetrainSplineTrajectory.cpp index aba49975b9e..3690801390e 100644 --- a/wpimath/src/main/native/cpp/trajectory/DrivetrainSplineTrajectory.cpp +++ b/wpimath/src/main/native/cpp/trajectory/DrivetrainSplineTrajectory.cpp @@ -13,7 +13,6 @@ #include "wpi/math/trajectory/DrivetrainSplineSample.hpp" #include "wpi/units/acceleration.hpp" #include "wpi/units/curvature.hpp" -#include "wpi/units/math.hpp" #include "wpi/units/time.hpp" #include "wpi/units/velocity.hpp" #include "wpi/util/MathExtras.hpp" @@ -41,8 +40,8 @@ DrivetrainSplineSample DrivetrainSplineTrajectory::Interpolate( // Check whether the robot is reversing at this stage. const bool reversing = startForwardVelocity < 0_mps || - (units::math::abs(startForwardVelocity) < 1e-9_mps && - startForwardAccel < 0_mps_sq); + (units::abs(startForwardVelocity) < 1e-9_mps && + startForwardAccel < 0_mps2); // Calculate the new velocity // v_f = v_0 + at @@ -61,7 +60,8 @@ DrivetrainSplineSample DrivetrainSplineTrajectory::Interpolate( const auto interpolationFrac = newS / end.pose.Translation().Distance(start.pose.Translation()); - Pose2d newPose = start.pose + (end.pose - start.pose) * interpolationFrac; + Pose2d newPose = + start.pose + (end.pose - start.pose) * interpolationFrac.value(); auto newAccel = wpi::util::Lerp(startForwardAccel, end.ForwardAcceleration(), t); auto newCurvature = wpi::util::Lerp(start.curvature, end.curvature, t); diff --git a/wpimath/src/main/native/cpp/trajectory/DrivetrainSplineTrajectoryParameterizer.cpp b/wpimath/src/main/native/cpp/trajectory/DrivetrainSplineTrajectoryParameterizer.cpp index 3e624e583c7..10547115722 100644 --- a/wpimath/src/main/native/cpp/trajectory/DrivetrainSplineTrajectoryParameterizer.cpp +++ b/wpimath/src/main/native/cpp/trajectory/DrivetrainSplineTrajectoryParameterizer.cpp @@ -38,9 +38,8 @@ #include "wpi/math/trajectory/DrivetrainSplineTrajectory.hpp" #include "wpi/math/trajectory/constraint/TrajectoryConstraint.hpp" #include "wpi/units/acceleration.hpp" -#include "wpi/units/base.hpp" +#include "wpi/units/core.hpp" #include "wpi/units/length.hpp" -#include "wpi/units/math.hpp" #include "wpi/units/time.hpp" #include "wpi/units/velocity.hpp" @@ -50,10 +49,10 @@ DrivetrainSplineTrajectory DrivetrainSplineTrajectoryParameterizer::Parameterize( const std::vector& points, const std::vector>& constraints, - wpi::units::meters_per_second_t startVelocity, - wpi::units::meters_per_second_t endVelocity, - wpi::units::meters_per_second_t maxVelocity, - wpi::units::meters_per_second_squared_t maxAcceleration, bool reversed) { + wpi::units::meters_per_second<> startVelocity, + wpi::units::meters_per_second<> endVelocity, + wpi::units::meters_per_second<> maxVelocity, + wpi::units::meters_per_second_squared<> maxAcceleration, bool reversed) { std::vector constrainedStates(points.size()); ConstrainedState predecessor{points.front(), 0_m, startVelocity, @@ -67,8 +66,9 @@ DrivetrainSplineTrajectoryParameterizer::Parameterize( constrainedState.pose = points[i]; // Begin constraining based on predecessor - wpi::units::meter_t ds = constrainedState.pose.first.Translation().Distance( - predecessor.pose.first.Translation()); + wpi::units::meters<> ds = + constrainedState.pose.first.Translation().Distance( + predecessor.pose.first.Translation()); constrainedState.distance = ds + predecessor.distance; // We may need to iterate to find the maximum end velocity and common @@ -77,9 +77,9 @@ DrivetrainSplineTrajectoryParameterizer::Parameterize( // Enforce global max velocity and max reachable velocity by global // acceleration limit. v_f = √(v_i² + 2ad). - constrainedState.maxVelocity = wpi::units::math::min( - maxVelocity, wpi::units::math::sqrt( - predecessor.maxVelocity * predecessor.maxVelocity + + constrainedState.maxVelocity = wpi::units::min( + maxVelocity, + wpi::units::sqrt(predecessor.maxVelocity * predecessor.maxVelocity + predecessor.maxAcceleration * ds * 2.0)); constrainedState.minAcceleration = -maxAcceleration; @@ -88,7 +88,7 @@ DrivetrainSplineTrajectoryParameterizer::Parameterize( // At this point, the constrained state is fully constructed apart from // all the custom-defined user constraints. for (const auto& constraint : constraints) { - constrainedState.maxVelocity = wpi::units::math::min( + constrainedState.maxVelocity = wpi::units::min( constrainedState.maxVelocity, constraint->MaxVelocity(constrainedState.pose.first, constrainedState.pose.second, @@ -105,19 +105,19 @@ DrivetrainSplineTrajectoryParameterizer::Parameterize( // If the actual acceleration for this state is higher than the max // acceleration that we applied, then we need to reduce the max // acceleration of the predecessor and try again. - wpi::units::meters_per_second_squared_t actualAcceleration = + wpi::units::meters_per_second_squared<> actualAcceleration = (constrainedState.maxVelocity * constrainedState.maxVelocity - predecessor.maxVelocity * predecessor.maxVelocity) / (ds * 2.0); // If we violate the max acceleration constraint, let's modify the // predecessor. - if (constrainedState.maxAcceleration < actualAcceleration - 1E-6_mps_sq) { + if (constrainedState.maxAcceleration < actualAcceleration - 1E-6_mps2) { predecessor.maxAcceleration = constrainedState.maxAcceleration; } else { // Constrain the predecessor's max acceleration to the current // acceleration. - if (actualAcceleration > predecessor.minAcceleration + 1E-6_mps_sq) { + if (actualAcceleration > predecessor.minAcceleration + 1E-6_mps2) { predecessor.maxAcceleration = actualAcceleration; } // If the actual acceleration is less than the predecessor's min @@ -134,15 +134,15 @@ DrivetrainSplineTrajectoryParameterizer::Parameterize( // Backward pass for (int i = points.size() - 1; i >= 0; i--) { auto& constrainedState = constrainedStates[i]; - wpi::units::meter_t ds = + wpi::units::meters<> ds = constrainedState.distance - successor.distance; // negative while (true) { // Enforce max velocity limit (reverse) // v_f = √(v_i² + 2ad), where v_i = successor. - wpi::units::meters_per_second_t newMaxVelocity = - wpi::units::math::sqrt(successor.maxVelocity * successor.maxVelocity + - successor.minAcceleration * ds * 2.0); + wpi::units::meters_per_second<> newMaxVelocity = + wpi::units::sqrt(successor.maxVelocity * successor.maxVelocity + + successor.minAcceleration * ds * 2.0); // No more limits to impose! This state can be finalized. if (newMaxVelocity >= constrainedState.maxVelocity) { @@ -161,11 +161,11 @@ DrivetrainSplineTrajectoryParameterizer::Parameterize( // If the actual acceleration for this state is lower than the min // acceleration, then we need to lower the min acceleration of the // successor and try again. - wpi::units::meters_per_second_squared_t actualAcceleration = + wpi::units::meters_per_second_squared<> actualAcceleration = (constrainedState.maxVelocity * constrainedState.maxVelocity - successor.maxVelocity * successor.maxVelocity) / (ds * 2.0); - if (constrainedState.minAcceleration > actualAcceleration + 1E-6_mps_sq) { + if (constrainedState.minAcceleration > actualAcceleration + 1E-6_mps2) { successor.minAcceleration = constrainedState.minAcceleration; } else { successor.minAcceleration = actualAcceleration; @@ -179,38 +179,38 @@ DrivetrainSplineTrajectoryParameterizer::Parameterize( // trajectory samples. const size_t numStates = constrainedStates.size(); - std::vector velocities(numStates); - std::vector times(numStates); + std::vector> velocities(numStates); + std::vector> times(numStates); // segAccel[i] is the (forward, path-relative) acceleration on the segment // arriving at state i (from state i - 1). - std::vector segAccel(numStates); + std::vector> segAccel(numStates); - wpi::units::second_t t = 0_s; - wpi::units::meter_t s = 0_m; - wpi::units::meters_per_second_t v = 0_mps; + wpi::units::seconds<> t = 0_s; + wpi::units::meters<> s = 0_m; + wpi::units::meters_per_second<> v = 0_mps; for (unsigned int i = 0; i < numStates; i++) { auto state = constrainedStates[i]; // Calculate the change in position between the current state and the // previous state. - wpi::units::meter_t ds = state.distance - s; + wpi::units::meters<> ds = state.distance - s; // Calculate the acceleration between the current state and the previous // state. ds is zero at the first state, where there is no preceding // segment, so the acceleration there is left at zero. - wpi::units::meters_per_second_squared_t accel = - ds == 0_m ? 0_mps_sq + wpi::units::meters_per_second_squared<> accel = + ds == 0_m ? 0_mps2 : (state.maxVelocity * state.maxVelocity - v * v) / (ds * 2); segAccel[i] = accel; // Calculate dt. - wpi::units::second_t dt = 0_s; + wpi::units::seconds<> dt = 0_s; if (i > 0) { - if (wpi::units::math::abs(accel) > 1E-6_mps_sq) { + if (wpi::units::abs(accel) > 1E-6_mps2) { // v_f = v_0 + at dt = (state.maxVelocity - v) / accel; - } else if (wpi::units::math::abs(v) > 1E-6_mps) { + } else if (wpi::units::abs(v) > 1E-6_mps) { // delta_x = vt dt = ds / v; } else { @@ -237,7 +237,7 @@ DrivetrainSplineTrajectoryParameterizer::Parameterize( samples.reserve(numStates); for (size_t i = 0; i < numStates; i++) { const auto& state = constrainedStates[i]; - wpi::units::meters_per_second_squared_t accel = + wpi::units::meters_per_second_squared<> accel = i + 1 < numStates ? segAccel[i + 1] : segAccel[i]; samples.emplace_back(times[i], state.pose.first, (reversed ? -velocities[i] : velocities[i]), @@ -264,11 +264,11 @@ void DrivetrainSplineTrajectoryParameterizer::EnforceAccelerationLimits( "back one-by-one."); } - state->minAcceleration = wpi::units::math::max( + state->minAcceleration = wpi::units::max( state->minAcceleration, reverse ? -minMaxAccel.maxAcceleration : minMaxAccel.minAcceleration); - state->maxAcceleration = wpi::units::math::min( + state->maxAcceleration = wpi::units::min( state->maxAcceleration, reverse ? -minMaxAccel.minAcceleration : minMaxAccel.maxAcceleration); } diff --git a/wpimath/src/main/native/cpp/trajectory/HolonomicSample.cpp b/wpimath/src/main/native/cpp/trajectory/HolonomicSample.cpp index c518993dc41..2cdeb1be162 100644 --- a/wpimath/src/main/native/cpp/trajectory/HolonomicSample.cpp +++ b/wpimath/src/main/native/cpp/trajectory/HolonomicSample.cpp @@ -20,7 +20,7 @@ void wpi::math::to_json(wpi::util::json& json, const HolonomicSample& sample) { void wpi::math::from_json(const wpi::util::json& json, HolonomicSample& sample) { - sample = HolonomicSample{wpi::units::second_t{json.at("time").get_number()}, + sample = HolonomicSample{wpi::units::seconds<>{json.at("time").get_number()}, json.at("pose").get(), json.at("velocity").get(), json.at("acceleration").get()}; diff --git a/wpimath/src/main/native/cpp/trajectory/TrajectorySample.cpp b/wpimath/src/main/native/cpp/trajectory/TrajectorySample.cpp index 3633bfa42b7..eb5dbe9826d 100644 --- a/wpimath/src/main/native/cpp/trajectory/TrajectorySample.cpp +++ b/wpimath/src/main/native/cpp/trajectory/TrajectorySample.cpp @@ -15,7 +15,8 @@ void wpi::math::to_json(wpi::util::json& json, const TrajectorySample& sample) { void wpi::math::from_json(const wpi::util::json& json, TrajectorySample& sample) { - sample = TrajectorySample{wpi::units::second_t{json.at("time").get_number()}}; + sample = + TrajectorySample{wpi::units::seconds<>{json.at("time").get_number()}}; } void wpi::math::to_json(wpi::util::json& json, diff --git a/wpimath/src/main/native/cpp/trajectory/proto/DifferentialSampleProto.cpp b/wpimath/src/main/native/cpp/trajectory/proto/DifferentialSampleProto.cpp index 68fc0654a40..318f64d1e86 100644 --- a/wpimath/src/main/native/cpp/trajectory/proto/DifferentialSampleProto.cpp +++ b/wpimath/src/main/native/cpp/trajectory/proto/DifferentialSampleProto.cpp @@ -36,12 +36,12 @@ std::optional wpi::util::Protobuf< } return wpi::math::DifferentialSample{ - wpi::units::second_t{msg.time}, + wpi::units::seconds<>{msg.time}, iPose[0], iVel[0], iAccel[0], - wpi::units::meters_per_second_t{msg.left_velocity}, - wpi::units::meters_per_second_t{msg.right_velocity}, + wpi::units::meters_per_second<>{msg.left_velocity}, + wpi::units::meters_per_second<>{msg.right_velocity}, }; } diff --git a/wpimath/src/main/native/cpp/trajectory/proto/HolonomicSampleProto.cpp b/wpimath/src/main/native/cpp/trajectory/proto/HolonomicSampleProto.cpp index 2f3d121bc21..c1eaa8a9fe7 100644 --- a/wpimath/src/main/native/cpp/trajectory/proto/HolonomicSampleProto.cpp +++ b/wpimath/src/main/native/cpp/trajectory/proto/HolonomicSampleProto.cpp @@ -34,7 +34,7 @@ wpi::util::Protobuf::Unpack(InputStream& stream) { } return wpi::math::HolonomicSample{ - wpi::units::second_t{msg.time}, + wpi::units::seconds<>{msg.time}, iPose[0], iVel[0], iAccel[0], diff --git a/wpimath/src/main/native/cpp/trajectory/proto/TrajectorySampleProto.cpp b/wpimath/src/main/native/cpp/trajectory/proto/TrajectorySampleProto.cpp index 5e950ce66a4..2328f291f39 100644 --- a/wpimath/src/main/native/cpp/trajectory/proto/TrajectorySampleProto.cpp +++ b/wpimath/src/main/native/cpp/trajectory/proto/TrajectorySampleProto.cpp @@ -13,7 +13,7 @@ wpi::util::Protobuf::Unpack(InputStream& stream) { return {}; } - return wpi::math::TrajectorySample{wpi::units::second_t{msg.time}}; + return wpi::math::TrajectorySample{wpi::units::seconds<>{msg.time}}; } bool wpi::util::Protobuf::Pack( diff --git a/wpimath/src/main/native/cpp/trajectory/struct/DifferentialSampleStruct.cpp b/wpimath/src/main/native/cpp/trajectory/struct/DifferentialSampleStruct.cpp index b877bf901b2..d976d1dd4d9 100644 --- a/wpimath/src/main/native/cpp/trajectory/struct/DifferentialSampleStruct.cpp +++ b/wpimath/src/main/native/cpp/trajectory/struct/DifferentialSampleStruct.cpp @@ -18,15 +18,15 @@ using StructType = wpi::util::Struct; wpi::math::DifferentialSample StructType::Unpack( std::span data) { return wpi::math::DifferentialSample{ - wpi::units::second_t{ + wpi::units::seconds<>{ wpi::util::UnpackStruct(data)}, wpi::util::UnpackStruct(data), wpi::util::UnpackStruct(data), wpi::util::UnpackStruct(data), - wpi::units::meters_per_second_t{ + wpi::units::meters_per_second<>{ wpi::util::UnpackStruct(data)}, - wpi::units::meters_per_second_t{ + wpi::units::meters_per_second<>{ wpi::util::UnpackStruct(data)}, }; } diff --git a/wpimath/src/main/native/cpp/trajectory/struct/HolonomicSampleStruct.cpp b/wpimath/src/main/native/cpp/trajectory/struct/HolonomicSampleStruct.cpp index 7a2054f7364..0c32d532bae 100644 --- a/wpimath/src/main/native/cpp/trajectory/struct/HolonomicSampleStruct.cpp +++ b/wpimath/src/main/native/cpp/trajectory/struct/HolonomicSampleStruct.cpp @@ -15,7 +15,7 @@ using StructType = wpi::util::Struct; wpi::math::HolonomicSample StructType::Unpack(std::span data) { return wpi::math::HolonomicSample{ - wpi::units::second_t{ + wpi::units::seconds<>{ wpi::util::UnpackStruct(data)}, wpi::util::UnpackStruct(data), wpi::util::UnpackStruct(data), diff --git a/wpimath/src/main/native/cpp/trajectory/struct/TrajectorySampleStruct.cpp b/wpimath/src/main/native/cpp/trajectory/struct/TrajectorySampleStruct.cpp index 30ec6938a9b..57592f32055 100644 --- a/wpimath/src/main/native/cpp/trajectory/struct/TrajectorySampleStruct.cpp +++ b/wpimath/src/main/native/cpp/trajectory/struct/TrajectorySampleStruct.cpp @@ -11,7 +11,7 @@ constexpr size_t TIMESTAMP_OFF = 0; using StructType = wpi::util::Struct; wpi::math::TrajectorySample StructType::Unpack(std::span data) { - return wpi::math::TrajectorySample{wpi::units::second_t{ + return wpi::math::TrajectorySample{wpi::units::seconds<>{ wpi::util::UnpackStruct(data)}}; } diff --git a/wpimath/src/main/native/cpp/util/MathShared.cpp b/wpimath/src/main/native/cpp/util/MathShared.cpp index 484711cd331..4cfd3058602 100644 --- a/wpimath/src/main/native/cpp/util/MathShared.cpp +++ b/wpimath/src/main/native/cpp/util/MathShared.cpp @@ -22,8 +22,8 @@ class DefaultMathShared : public MathShared { void ReportErrorV(std::string_view format, std::format_args args) override {} void ReportWarningV(std::string_view format, std::format_args args) override { } - wpi::units::second_t GetTimestamp() override { - return wpi::units::second_t{wpi::util::Now() * 1.0e-9}; + wpi::units::seconds<> GetTimestamp() override { + return wpi::units::seconds<>{wpi::util::Now() * 1.0e-9}; } }; } // namespace diff --git a/wpimath/src/main/native/include/wpi/math/controller/AntiTipping.hpp b/wpimath/src/main/native/include/wpi/math/controller/AntiTipping.hpp index 7b1d4452239..11273275e83 100644 --- a/wpimath/src/main/native/include/wpi/math/controller/AntiTipping.hpp +++ b/wpimath/src/main/native/include/wpi/math/controller/AntiTipping.hpp @@ -12,7 +12,7 @@ #include "wpi/math/kinematics/ChassisVelocities.hpp" #include "wpi/units/angle.hpp" #include "wpi/units/angular_velocity.hpp" -#include "wpi/units/base.hpp" +#include "wpi/units/core.hpp" #include "wpi/units/length.hpp" #include "wpi/units/velocity.hpp" #include "wpi/util/SymbolExports.hpp" @@ -58,9 +58,9 @@ namespace wpi::math { class WPILIB_DLLEXPORT AntiTipping { public: /// Proportional gain unit: meters per second per radian of inclination. - using kp_unit = - wpi::units::compound_unit>; + using kp_unit = wpi::units::compound_conversion_factor< + wpi::units::meters_per_second_, + wpi::units::inverse>; /** * Creates a new AntiTipping instance. @@ -71,9 +71,9 @@ class WPILIB_DLLEXPORT AntiTipping { * @param tippingThreshold Tipping detection threshold. * @param maxCorrectionSpeed Maximum correction velocity. */ - constexpr AntiTipping(wpi::units::unit_t kp, - wpi::units::radian_t tippingThreshold, - wpi::units::meters_per_second_t maxCorrectionSpeed) + constexpr AntiTipping(wpi::units::unit kp, + wpi::units::radians<> tippingThreshold, + wpi::units::meters_per_second<> maxCorrectionSpeed) : m_kp{kp}, m_tippingThreshold{tippingThreshold}, m_maxCorrectionSpeed{maxCorrectionSpeed} {} @@ -83,21 +83,21 @@ class WPILIB_DLLEXPORT AntiTipping { * * @param kp The proportional coefficient in meters per second per radian. */ - constexpr void SetP(wpi::units::unit_t kp) { m_kp = kp; } + constexpr void SetP(wpi::units::unit kp) { m_kp = kp; } /** * Gets the proportional coefficient. * * @return The proportional coefficient in meters per second per radian. */ - constexpr wpi::units::unit_t GetP() const { return m_kp; } + constexpr wpi::units::unit GetP() const { return m_kp; } /** * Sets the tipping detection threshold. * * @param threshold The tipping threshold. */ - constexpr void SetTippingThreshold(wpi::units::radian_t threshold) { + constexpr void SetTippingThreshold(wpi::units::radians<> threshold) { m_tippingThreshold = threshold; } @@ -106,7 +106,7 @@ class WPILIB_DLLEXPORT AntiTipping { * * @return The tipping threshold. */ - constexpr wpi::units::radian_t GetTippingThreshold() const { + constexpr wpi::units::radians<> GetTippingThreshold() const { return m_tippingThreshold; } @@ -115,7 +115,7 @@ class WPILIB_DLLEXPORT AntiTipping { * * @param speed The maximum correction speed. */ - constexpr void SetMaxCorrectionSpeed(wpi::units::meters_per_second_t speed) { + constexpr void SetMaxCorrectionSpeed(wpi::units::meters_per_second<> speed) { m_maxCorrectionSpeed = speed; } @@ -124,7 +124,7 @@ class WPILIB_DLLEXPORT AntiTipping { * * @return The maximum correction speed. */ - constexpr wpi::units::meters_per_second_t GetMaxCorrectionSpeed() const { + constexpr wpi::units::meters_per_second<> GetMaxCorrectionSpeed() const { return m_maxCorrectionSpeed; } @@ -139,10 +139,10 @@ class WPILIB_DLLEXPORT AntiTipping { // To find the correction, we rotate the z axis (scaled by the P gain) by // the attitude, then project onto the x-y plane. Translation2d correction = - Translation3d{0_m, 0_m, wpi::units::meter_t{m_kp.value()}} + Translation3d{0_m, 0_m, wpi::units::meters<>{m_kp.value()}} .RotateBy(attitude) .ToTranslation2d(); - wpi::units::meters_per_second_t speed{correction.Norm().value()}; + wpi::units::meters_per_second<> speed{correction.Norm().value()}; // Let inclination angle of 3D correction be θ. // @@ -155,7 +155,7 @@ class WPILIB_DLLEXPORT AntiTipping { // // sinθ = o/h // θ = asin(speed / m_kp) - wpi::units::radian_t inclinationAngle{ + wpi::units::radians<> inclinationAngle{ gcem::asin(speed.value() / m_kp.value())}; if (inclinationAngle < m_tippingThreshold) { @@ -164,15 +164,15 @@ class WPILIB_DLLEXPORT AntiTipping { correction = correction * (m_maxCorrectionSpeed.value() / speed.value()); } - return {wpi::units::meters_per_second_t{correction.X().value()}, - wpi::units::meters_per_second_t{correction.Y().value()}, + return {wpi::units::meters_per_second<>{correction.X().value()}, + wpi::units::meters_per_second<>{correction.Y().value()}, 0_rad_per_s}; } private: - wpi::units::unit_t m_kp; - wpi::units::radian_t m_tippingThreshold; - wpi::units::meters_per_second_t m_maxCorrectionSpeed; + wpi::units::unit m_kp; + wpi::units::radians<> m_tippingThreshold; + wpi::units::meters_per_second<> m_maxCorrectionSpeed; }; } // namespace wpi::math diff --git a/wpimath/src/main/native/include/wpi/math/controller/ArmFeedforward.hpp b/wpimath/src/main/native/include/wpi/math/controller/ArmFeedforward.hpp index 5abda58b137..34fa8cda4cd 100644 --- a/wpimath/src/main/native/include/wpi/math/controller/ArmFeedforward.hpp +++ b/wpimath/src/main/native/include/wpi/math/controller/ArmFeedforward.hpp @@ -6,9 +6,9 @@ #include "wpi/math/util/MathShared.hpp" #include "wpi/units/angle.hpp" +#include "wpi/units/angular_acceleration.hpp" #include "wpi/units/angular_velocity.hpp" -#include "wpi/units/base.hpp" -#include "wpi/units/math.hpp" +#include "wpi/units/core.hpp" #include "wpi/units/time.hpp" #include "wpi/units/voltage.hpp" #include "wpi/util/MathExtras.hpp" @@ -21,15 +21,14 @@ namespace wpi::math { */ class WPILIB_DLLEXPORT ArmFeedforward { public: - using Angle = wpi::units::radians; - using Velocity = wpi::units::radians_per_second; - using Acceleration = - wpi::units::compound_unit>; - using kv_unit = wpi::units::compound_unit< - wpi::units::volts, wpi::units::inverse>; - using ka_unit = wpi::units::compound_unit>; + using Angle = wpi::units::radians_; + using Velocity = wpi::units::radians_per_second_; + using Acceleration = wpi::units::radians_per_second_squared_; + using kv_unit = wpi::units::compound_conversion_factor< + wpi::units::volts_, wpi::units::inverse>; + using ka_unit = + wpi::units::compound_conversion_factor>; /** * Creates a new ArmFeedforward with the specified gains. @@ -44,21 +43,21 @@ class WPILIB_DLLEXPORT ArmFeedforward { * @throws IllegalArgumentException for period ≤ zero. */ constexpr ArmFeedforward( - wpi::units::volt_t kS, wpi::units::volt_t kG, - wpi::units::unit_t kV, - wpi::units::unit_t kA = wpi::units::unit_t(0), - wpi::units::second_t dt = 20_ms) + wpi::units::volts<> kS, wpi::units::volts<> kG, + wpi::units::unit kV, + wpi::units::unit kA = wpi::units::unit(0), + wpi::units::seconds<> dt = 20_ms) : kS(kS), kG(kG), kV(kV), kA(kA), m_dt(dt) { if (kV.value() < 0) { wpi::math::MathSharedStore::ReportError( "kV must be a non-negative number, got {}!", kV.value()); - this->kV = wpi::units::unit_t{0}; + this->kV = wpi::units::unit{0}; wpi::math::MathSharedStore::ReportWarning("kV defaulted to 0."); } if (kA.value() < 0) { wpi::math::MathSharedStore::ReportError( "kA must be a non-negative number, got {}!", kA.value()); - this->kA = wpi::units::unit_t{0}; + this->kA = wpi::units::unit{0}; wpi::math::MathSharedStore::ReportWarning("kA defaulted to 0;"); } if (dt <= 0_ms) { @@ -80,11 +79,11 @@ class WPILIB_DLLEXPORT ArmFeedforward { * @param currentVelocity The current velocity. * @return The computed feedforward in volts. */ - constexpr wpi::units::volt_t Calculate( - wpi::units::unit_t currentAngle, - wpi::units::unit_t currentVelocity) const { + constexpr wpi::units::volts<> Calculate( + wpi::units::unit currentAngle, + wpi::units::unit currentVelocity) const { return kS * wpi::util::sgn(currentVelocity) + - kG * wpi::units::math::cos(currentAngle) + kV * currentVelocity; + kG * wpi::units::cos(currentAngle) + kV * currentVelocity; } /** @@ -99,9 +98,9 @@ class WPILIB_DLLEXPORT ArmFeedforward { * @param nextVelocity The next velocity. * @return The computed feedforward in volts. */ - wpi::units::volt_t Calculate(wpi::units::unit_t currentAngle, - wpi::units::unit_t currentVelocity, - wpi::units::unit_t nextVelocity) const; + wpi::units::volts<> Calculate(wpi::units::unit currentAngle, + wpi::units::unit currentVelocity, + wpi::units::unit nextVelocity) const; // Rearranging the main equation from the calculate() method yields the // formulas for the methods below: @@ -122,12 +121,11 @@ class WPILIB_DLLEXPORT ArmFeedforward { * @param acceleration The acceleration of the arm. * @return The maximum possible velocity at the given acceleration and angle. */ - constexpr wpi::units::unit_t MaxAchievableVelocity( - wpi::units::volt_t maxVoltage, wpi::units::unit_t angle, - wpi::units::unit_t acceleration) { + constexpr wpi::units::unit MaxAchievableVelocity( + wpi::units::volts<> maxVoltage, wpi::units::unit angle, + wpi::units::unit acceleration) { // Assume max velocity is positive - return (maxVoltage - kS - kG * wpi::units::math::cos(angle) - - kA * acceleration) / + return (maxVoltage - kS - kG * wpi::units::cos(angle) - kA * acceleration) / kV; } @@ -147,11 +145,11 @@ class WPILIB_DLLEXPORT ArmFeedforward { * @param acceleration The acceleration of the arm. * @return The minimum possible velocity at the given acceleration and angle. */ - constexpr wpi::units::unit_t MinAchievableVelocity( - wpi::units::volt_t maxVoltage, wpi::units::unit_t angle, - wpi::units::unit_t acceleration) { + constexpr wpi::units::unit MinAchievableVelocity( + wpi::units::volts<> maxVoltage, wpi::units::unit angle, + wpi::units::unit acceleration) { // Assume min velocity is negative, ks flips sign - return (-maxVoltage + kS - kG * wpi::units::math::cos(angle) - + return (-maxVoltage + kS - kG * wpi::units::cos(angle) - kA * acceleration) / kV; } @@ -172,11 +170,11 @@ class WPILIB_DLLEXPORT ArmFeedforward { * @param velocity The velocity of the arm. * @return The maximum possible acceleration at the given velocity and angle. */ - constexpr wpi::units::unit_t MaxAchievableAcceleration( - wpi::units::volt_t maxVoltage, wpi::units::unit_t angle, - wpi::units::unit_t velocity) { + constexpr wpi::units::unit MaxAchievableAcceleration( + wpi::units::volts<> maxVoltage, wpi::units::unit angle, + wpi::units::unit velocity) { return (maxVoltage - kS * wpi::util::sgn(velocity) - - kG * wpi::units::math::cos(angle) - kV * velocity) / + kG * wpi::units::cos(angle) - kV * velocity) / kA; } @@ -196,9 +194,9 @@ class WPILIB_DLLEXPORT ArmFeedforward { * @param velocity The velocity of the arm. * @return The minimum possible acceleration at the given velocity and angle. */ - constexpr wpi::units::unit_t MinAchievableAcceleration( - wpi::units::volt_t maxVoltage, wpi::units::unit_t angle, - wpi::units::unit_t velocity) { + constexpr wpi::units::unit MinAchievableAcceleration( + wpi::units::volts<> maxVoltage, wpi::units::unit angle, + wpi::units::unit velocity) { return MaxAchievableAcceleration(-maxVoltage, angle, velocity); } @@ -211,7 +209,7 @@ class WPILIB_DLLEXPORT ArmFeedforward { * * @param kS The static gain. */ - constexpr void SetKs(wpi::units::volt_t kS) { this->kS = kS; } + constexpr void SetKs(wpi::units::volts<> kS) { this->kS = kS; } /** * Sets the gravity gain. @@ -222,7 +220,7 @@ class WPILIB_DLLEXPORT ArmFeedforward { * * @param kG The gravity gain. */ - constexpr void SetKg(wpi::units::volt_t kG) { this->kG = kG; } + constexpr void SetKg(wpi::units::volts<> kG) { this->kG = kG; } /** * Sets the velocity gain. @@ -233,7 +231,7 @@ class WPILIB_DLLEXPORT ArmFeedforward { * * @param kV The velocity gain. */ - constexpr void SetKv(wpi::units::unit_t kV) { this->kV = kV; } + constexpr void SetKv(wpi::units::unit kV) { this->kV = kV; } /** * Sets the acceleration gain. @@ -244,51 +242,51 @@ class WPILIB_DLLEXPORT ArmFeedforward { * * @param kA The acceleration gain. */ - constexpr void SetKa(wpi::units::unit_t kA) { this->kA = kA; } + constexpr void SetKa(wpi::units::unit kA) { this->kA = kA; } /** * Returns the static gain. * * @return The static gain. */ - constexpr wpi::units::volt_t GetKs() const { return kS; } + constexpr wpi::units::volts<> GetKs() const { return kS; } /** * Returns the gravity gain. * * @return The gravity gain. */ - constexpr wpi::units::volt_t GetKg() const { return kG; } + constexpr wpi::units::volts<> GetKg() const { return kG; } /** * Returns the velocity gain. * * @return The velocity gain. */ - constexpr wpi::units::unit_t GetKv() const { return kV; } + constexpr wpi::units::unit GetKv() const { return kV; } /** * Returns the acceleration gain. * * @return The acceleration gain. */ - constexpr wpi::units::unit_t GetKa() const { return kA; } + constexpr wpi::units::unit GetKa() const { return kA; } private: /// The static gain, in volts. - wpi::units::volt_t kS; + wpi::units::volts<> kS; /// The gravity gain, in volts. - wpi::units::volt_t kG; + wpi::units::volts<> kG; /// The velocity gain, in V/(rad/s)volt seconds per radian. - wpi::units::unit_t kV; + wpi::units::unit kV; /// The acceleration gain, in V/(rad/s²). - wpi::units::unit_t kA; + wpi::units::unit kA; /** The period. */ - wpi::units::second_t m_dt; + wpi::units::seconds<> m_dt; }; } // namespace wpi::math diff --git a/wpimath/src/main/native/include/wpi/math/controller/ControlAffinePlantInversionFeedforward.hpp b/wpimath/src/main/native/include/wpi/math/controller/ControlAffinePlantInversionFeedforward.hpp index f4ce1059092..668068c8784 100644 --- a/wpimath/src/main/native/include/wpi/math/controller/ControlAffinePlantInversionFeedforward.hpp +++ b/wpimath/src/main/native/include/wpi/math/controller/ControlAffinePlantInversionFeedforward.hpp @@ -54,7 +54,7 @@ class ControlAffinePlantInversionFeedforward { */ ControlAffinePlantInversionFeedforward( std::function f, - wpi::units::second_t dt) + wpi::units::seconds<> dt) : m_dt(dt), m_f(f) { m_B = NumericalJacobianU(f, StateVector::Zero(), InputVector::Zero()); @@ -73,7 +73,7 @@ class ControlAffinePlantInversionFeedforward { */ ControlAffinePlantInversionFeedforward( std::function f, - const Matrixd& B, wpi::units::second_t dt) + const Matrixd& B, wpi::units::seconds<> dt) : m_B(B), m_dt(dt) { m_f = [=](const StateVector& x, const InputVector& u) -> StateVector { return f(x); @@ -177,7 +177,7 @@ class ControlAffinePlantInversionFeedforward { private: Matrixd m_B; - wpi::units::second_t m_dt; + wpi::units::seconds<> m_dt; /** * The model dynamics. diff --git a/wpimath/src/main/native/include/wpi/math/controller/DifferentialDriveAccelerationLimiter.hpp b/wpimath/src/main/native/include/wpi/math/controller/DifferentialDriveAccelerationLimiter.hpp index f82b3f27b58..6e62706170d 100644 --- a/wpimath/src/main/native/include/wpi/math/controller/DifferentialDriveAccelerationLimiter.hpp +++ b/wpimath/src/main/native/include/wpi/math/controller/DifferentialDriveAccelerationLimiter.hpp @@ -38,9 +38,9 @@ class WPILIB_DLLEXPORT DifferentialDriveAccelerationLimiter { * @param maxAngularAccel The maximum angular acceleration. */ DifferentialDriveAccelerationLimiter( - LinearSystem<2, 2, 2> system, wpi::units::meter_t trackwidth, - wpi::units::meters_per_second_squared_t maxLinearAccel, - wpi::units::radians_per_second_squared_t maxAngularAccel) + LinearSystem<2, 2, 2> system, wpi::units::meters<> trackwidth, + wpi::units::meters_per_second_squared<> maxLinearAccel, + wpi::units::radians_per_second_squared<> maxAngularAccel) : DifferentialDriveAccelerationLimiter(system, trackwidth, -maxLinearAccel, maxLinearAccel, maxAngularAccel) {} @@ -58,10 +58,10 @@ class WPILIB_DLLEXPORT DifferentialDriveAccelerationLimiter { * than maximum linear acceleration */ DifferentialDriveAccelerationLimiter( - LinearSystem<2, 2, 2> system, wpi::units::meter_t trackwidth, - wpi::units::meters_per_second_squared_t minLinearAccel, - wpi::units::meters_per_second_squared_t maxLinearAccel, - wpi::units::radians_per_second_squared_t maxAngularAccel) + LinearSystem<2, 2, 2> system, wpi::units::meters<> trackwidth, + wpi::units::meters_per_second_squared<> minLinearAccel, + wpi::units::meters_per_second_squared<> maxLinearAccel, + wpi::units::radians_per_second_squared<> maxAngularAccel) : m_system{std::move(system)}, m_trackwidth{trackwidth}, m_minLinearAccel{minLinearAccel}, @@ -83,16 +83,16 @@ class WPILIB_DLLEXPORT DifferentialDriveAccelerationLimiter { * @return The constrained wheel voltages. */ DifferentialDriveWheelVoltages Calculate( - wpi::units::meters_per_second_t leftVelocity, - wpi::units::meters_per_second_t rightVelocity, - wpi::units::volt_t leftVoltage, wpi::units::volt_t rightVoltage); + wpi::units::meters_per_second<> leftVelocity, + wpi::units::meters_per_second<> rightVelocity, + wpi::units::volts<> leftVoltage, wpi::units::volts<> rightVoltage); private: LinearSystem<2, 2, 2> m_system; - wpi::units::meter_t m_trackwidth; - wpi::units::meters_per_second_squared_t m_minLinearAccel; - wpi::units::meters_per_second_squared_t m_maxLinearAccel; - wpi::units::radians_per_second_squared_t m_maxAngularAccel; + wpi::units::meters<> m_trackwidth; + wpi::units::meters_per_second_squared<> m_minLinearAccel; + wpi::units::meters_per_second_squared<> m_maxLinearAccel; + wpi::units::radians_per_second_squared<> m_maxAngularAccel; }; } // namespace wpi::math diff --git a/wpimath/src/main/native/include/wpi/math/controller/DifferentialDriveFeedforward.hpp b/wpimath/src/main/native/include/wpi/math/controller/DifferentialDriveFeedforward.hpp index 89c908e5148..f64a7d2c8a8 100644 --- a/wpimath/src/main/native/include/wpi/math/controller/DifferentialDriveFeedforward.hpp +++ b/wpimath/src/main/native/include/wpi/math/controller/DifferentialDriveFeedforward.hpp @@ -40,11 +40,11 @@ class WPILIB_DLLEXPORT DifferentialDriveFeedforward { * right wheels, in meters. */ constexpr DifferentialDriveFeedforward( - decltype(1_V / 1_mps) kvLinear, decltype(1_V / 1_mps_sq) kaLinear, + decltype(1_V / 1_mps) kvLinear, decltype(1_V / 1_mps2) kaLinear, decltype(1_V / 1_rad_per_s) kvAngular, - decltype(1_V / 1_rad_per_s_sq) kaAngular, wpi::units::meter_t trackwidth) + decltype(1_V / 1_rad_per_s_sq) kaAngular, wpi::units::meters<> trackwidth) // See Models::DifferentialDriveFromSysId(decltype(1_V / 1_mps), - // decltype(1_V / 1_mps_sq), decltype(1_V / 1_rad_per_s), decltype(1_V / + // decltype(1_V / 1_mps2), decltype(1_V / 1_rad_per_s), decltype(1_V / // 1_rad_per_s_sq)) : DifferentialDriveFeedforward{kvLinear, kaLinear, kvAngular * 2.0 / trackwidth * 1_rad, @@ -62,9 +62,9 @@ class WPILIB_DLLEXPORT DifferentialDriveFeedforward { * second squared). */ constexpr DifferentialDriveFeedforward(decltype(1_V / 1_mps) kvLinear, - decltype(1_V / 1_mps_sq) kaLinear, + decltype(1_V / 1_mps2) kaLinear, decltype(1_V / 1_mps) kvAngular, - decltype(1_V / 1_mps_sq) kaAngular) + decltype(1_V / 1_mps2) kaAngular) : m_plant{wpi::math::Models::DifferentialDriveFromSysId( kvLinear, kaLinear, kvAngular, kaAngular)}, kvLinear{kvLinear}, @@ -87,16 +87,16 @@ class WPILIB_DLLEXPORT DifferentialDriveFeedforward { * @param dt Discretization timestep. */ DifferentialDriveWheelVoltages Calculate( - wpi::units::meters_per_second_t currentLeftVelocity, - wpi::units::meters_per_second_t nextLeftVelocity, - wpi::units::meters_per_second_t currentRightVelocity, - wpi::units::meters_per_second_t nextRightVelocity, - wpi::units::second_t dt); + wpi::units::meters_per_second<> currentLeftVelocity, + wpi::units::meters_per_second<> nextLeftVelocity, + wpi::units::meters_per_second<> currentRightVelocity, + wpi::units::meters_per_second<> nextRightVelocity, + wpi::units::seconds<> dt); decltype(1_V / 1_mps) kvLinear; - decltype(1_V / 1_mps_sq) kaLinear; + decltype(1_V / 1_mps2) kaLinear; decltype(1_V / 1_mps) kvAngular; - decltype(1_V / 1_mps_sq) kaAngular; + decltype(1_V / 1_mps2) kaAngular; }; } // namespace wpi::math diff --git a/wpimath/src/main/native/include/wpi/math/controller/DifferentialDriveWheelVoltages.hpp b/wpimath/src/main/native/include/wpi/math/controller/DifferentialDriveWheelVoltages.hpp index dfc4fed6649..fba9ce8287c 100644 --- a/wpimath/src/main/native/include/wpi/math/controller/DifferentialDriveWheelVoltages.hpp +++ b/wpimath/src/main/native/include/wpi/math/controller/DifferentialDriveWheelVoltages.hpp @@ -13,10 +13,10 @@ namespace wpi::math { */ struct DifferentialDriveWheelVoltages { /// Left wheel voltage. - wpi::units::volt_t left = 0_V; + wpi::units::volts<> left = 0_V; /// Right wheel voltage. - wpi::units::volt_t right = 0_V; + wpi::units::volts<> right = 0_V; }; } // namespace wpi::math diff --git a/wpimath/src/main/native/include/wpi/math/controller/ElevatorFeedforward.hpp b/wpimath/src/main/native/include/wpi/math/controller/ElevatorFeedforward.hpp index 3af8413a67e..bda7734bc4a 100644 --- a/wpimath/src/main/native/include/wpi/math/controller/ElevatorFeedforward.hpp +++ b/wpimath/src/main/native/include/wpi/math/controller/ElevatorFeedforward.hpp @@ -7,9 +7,11 @@ #include #include "wpi/math/util/MathShared.hpp" -#include "wpi/units/base.hpp" +#include "wpi/units/acceleration.hpp" +#include "wpi/units/core.hpp" #include "wpi/units/length.hpp" #include "wpi/units/time.hpp" +#include "wpi/units/velocity.hpp" #include "wpi/units/voltage.hpp" #include "wpi/util/MathExtras.hpp" @@ -20,17 +22,15 @@ namespace wpi::math { */ class ElevatorFeedforward { public: - using Distance = wpi::units::meters; - using Velocity = - wpi::units::compound_unit>; - using Acceleration = - wpi::units::compound_unit>; - using kv_unit = wpi::units::compound_unit>; - using ka_unit = wpi::units::compound_unit>; + using Distance = wpi::units::meters_; + using Velocity = wpi::units::meters_per_second_; + using Acceleration = wpi::units::meters_per_second_squared_; + using kv_unit = + wpi::units::compound_conversion_factor>; + using ka_unit = + wpi::units::compound_conversion_factor>; /** * Creates a new ElevatorFeedforward with the specified gains. @@ -45,21 +45,21 @@ class ElevatorFeedforward { * @throws IllegalArgumentException for period ≤ zero. */ constexpr ElevatorFeedforward( - wpi::units::volt_t kS, wpi::units::volt_t kG, - wpi::units::unit_t kV, - wpi::units::unit_t kA = wpi::units::unit_t(0), - wpi::units::second_t dt = 20_ms) + wpi::units::volts<> kS, wpi::units::volts<> kG, + wpi::units::unit kV, + wpi::units::unit kA = wpi::units::unit(0), + wpi::units::seconds<> dt = 20_ms) : kS(kS), kG(kG), kV(kV), kA(kA), m_dt(dt) { if (kV.value() < 0) { wpi::math::MathSharedStore::ReportError( "kV must be a non-negative number, got {}!", kV.value()); - this->kV = wpi::units::unit_t{0}; + this->kV = wpi::units::unit{0}; wpi::math::MathSharedStore::ReportWarning("kV defaulted to 0."); } if (kA.value() < 0) { wpi::math::MathSharedStore::ReportError( "kA must be a non-negative number, got {}!", kA.value()); - this->kA = wpi::units::unit_t{0}; + this->kA = wpi::units::unit{0}; wpi::math::MathSharedStore::ReportWarning("kA defaulted to 0;"); } if (dt <= 0_ms) { @@ -77,8 +77,8 @@ class ElevatorFeedforward { * @param currentVelocity The velocity reference. * @return The computed feedforward, in volts. */ - constexpr wpi::units::volt_t Calculate( - wpi::units::unit_t currentVelocity) const { + constexpr wpi::units::volts<> Calculate( + wpi::units::unit currentVelocity) const { return Calculate(currentVelocity, currentVelocity); } @@ -92,9 +92,9 @@ class ElevatorFeedforward { * @param nextVelocity The next velocity reference. * @return The computed feedforward, in volts. */ - constexpr wpi::units::volt_t Calculate( - wpi::units::unit_t currentVelocity, - wpi::units::unit_t nextVelocity) const { + constexpr wpi::units::volts<> Calculate( + wpi::units::unit currentVelocity, + wpi::units::unit nextVelocity) const { // See wpimath/docs/ElevatorFeedforward.md for derivation if (kA < decltype(kA)(1e-9)) { return kS * wpi::util::sgn(nextVelocity) + kG + kV * nextVelocity; @@ -104,7 +104,7 @@ class ElevatorFeedforward { double A_d = gcem::exp(A * m_dt.value()); double B_d = A > -1e-9 ? B * m_dt.value() : 1.0 / A * (A_d - 1.0) * B; return kG + kS * wpi::util::sgn(currentVelocity) + - wpi::units::volt_t{ + wpi::units::volts<>{ 1.0 / B_d * (nextVelocity.value() - A_d * currentVelocity.value())}; } @@ -124,9 +124,9 @@ class ElevatorFeedforward { * @param acceleration The acceleration of the elevator. * @return The maximum possible velocity at the given acceleration. */ - constexpr wpi::units::unit_t MaxAchievableVelocity( - wpi::units::volt_t maxVoltage, - wpi::units::unit_t acceleration) { + constexpr wpi::units::unit MaxAchievableVelocity( + wpi::units::volts<> maxVoltage, + wpi::units::unit acceleration) { // Assume max velocity is positive return (maxVoltage - kS - kG - kA * acceleration) / kV; } @@ -142,9 +142,9 @@ class ElevatorFeedforward { * @param acceleration The acceleration of the elevator. * @return The minimum possible velocity at the given acceleration. */ - constexpr wpi::units::unit_t MinAchievableVelocity( - wpi::units::volt_t maxVoltage, - wpi::units::unit_t acceleration) { + constexpr wpi::units::unit MinAchievableVelocity( + wpi::units::volts<> maxVoltage, + wpi::units::unit acceleration) { // Assume min velocity is negative, ks flips sign return (-maxVoltage + kS - kG - kA * acceleration) / kV; } @@ -160,8 +160,8 @@ class ElevatorFeedforward { * @param velocity The velocity of the elevator. * @return The maximum possible acceleration at the given velocity. */ - constexpr wpi::units::unit_t MaxAchievableAcceleration( - wpi::units::volt_t maxVoltage, wpi::units::unit_t velocity) { + constexpr wpi::units::unit MaxAchievableAcceleration( + wpi::units::volts<> maxVoltage, wpi::units::unit velocity) { return (maxVoltage - kS * wpi::util::sgn(velocity) - kG - kV * velocity) / kA; } @@ -177,8 +177,8 @@ class ElevatorFeedforward { * @param velocity The velocity of the elevator. * @return The minimum possible acceleration at the given velocity. */ - constexpr wpi::units::unit_t MinAchievableAcceleration( - wpi::units::volt_t maxVoltage, wpi::units::unit_t velocity) { + constexpr wpi::units::unit MinAchievableAcceleration( + wpi::units::volts<> maxVoltage, wpi::units::unit velocity) { return MaxAchievableAcceleration(-maxVoltage, velocity); } @@ -191,7 +191,7 @@ class ElevatorFeedforward { * * @param kS The static gain. */ - constexpr void SetKs(wpi::units::volt_t kS) { this->kS = kS; } + constexpr void SetKs(wpi::units::volts<> kS) { this->kS = kS; } /** * Sets the gravity gain. @@ -202,7 +202,7 @@ class ElevatorFeedforward { * * @param kG The gravity gain. */ - constexpr void SetKg(wpi::units::volt_t kG) { this->kG = kG; } + constexpr void SetKg(wpi::units::volts<> kG) { this->kG = kG; } /** * Sets the velocity gain. @@ -213,7 +213,7 @@ class ElevatorFeedforward { * * @param kV The velocity gain. */ - constexpr void SetKv(wpi::units::unit_t kV) { this->kV = kV; } + constexpr void SetKv(wpi::units::unit kV) { this->kV = kV; } /** * Sets the acceleration gain. @@ -224,51 +224,51 @@ class ElevatorFeedforward { * * @param kA The acceleration gain. */ - constexpr void SetKa(wpi::units::unit_t kA) { this->kA = kA; } + constexpr void SetKa(wpi::units::unit kA) { this->kA = kA; } /** * Returns the static gain. * * @return The static gain. */ - constexpr wpi::units::volt_t GetKs() const { return kS; } + constexpr wpi::units::volts<> GetKs() const { return kS; } /** * Returns the gravity gain. * * @return The gravity gain. */ - constexpr wpi::units::volt_t GetKg() const { return kG; } + constexpr wpi::units::volts<> GetKg() const { return kG; } /** * Returns the velocity gain. * * @return The velocity gain. */ - constexpr wpi::units::unit_t GetKv() const { return kV; } + constexpr wpi::units::unit GetKv() const { return kV; } /** * Returns the acceleration gain. * * @return The acceleration gain. */ - constexpr wpi::units::unit_t GetKa() const { return kA; } + constexpr wpi::units::unit GetKa() const { return kA; } private: /// The static gain. - wpi::units::volt_t kS; + wpi::units::volts<> kS; /// The gravity gain. - wpi::units::volt_t kG; + wpi::units::volts<> kG; /// The velocity gain. - wpi::units::unit_t kV; + wpi::units::unit kV; /// The acceleration gain. - wpi::units::unit_t kA; + wpi::units::unit kA; /** The period. */ - wpi::units::second_t m_dt; + wpi::units::seconds<> m_dt; }; } // namespace wpi::math diff --git a/wpimath/src/main/native/include/wpi/math/controller/LTVDifferentialDriveController.hpp b/wpimath/src/main/native/include/wpi/math/controller/LTVDifferentialDriveController.hpp index 8759b658af1..078de7d87fe 100644 --- a/wpimath/src/main/native/include/wpi/math/controller/LTVDifferentialDriveController.hpp +++ b/wpimath/src/main/native/include/wpi/math/controller/LTVDifferentialDriveController.hpp @@ -55,10 +55,10 @@ class WPILIB_DLLEXPORT LTVDifferentialDriveController { * @param dt Discretization timestep. */ LTVDifferentialDriveController(const wpi::math::LinearSystem<2, 2, 2>& plant, - wpi::units::meter_t trackwidth, + wpi::units::meters<> trackwidth, const wpi::util::array& Qelems, const wpi::util::array& Relems, - wpi::units::second_t dt) + wpi::units::seconds<> dt) : m_trackwidth{trackwidth}, m_A{plant.A()}, m_B{plant.B()}, @@ -97,8 +97,8 @@ class WPILIB_DLLEXPORT LTVDifferentialDriveController { * @param rightVelocityTolerance Right velocity error which is tolerable. */ void SetTolerance(const Pose2d& poseTolerance, - wpi::units::meters_per_second_t leftVelocityTolerance, - wpi::units::meters_per_second_t rightVelocityTolerance) { + wpi::units::meters_per_second<> leftVelocityTolerance, + wpi::units::meters_per_second<> rightVelocityTolerance) { m_tolerance = Eigen::Vector{ poseTolerance.X().value(), poseTolerance.Y().value(), poseTolerance.Rotation().Radians().value(), @@ -119,10 +119,10 @@ class WPILIB_DLLEXPORT LTVDifferentialDriveController { * @param rightVelocityRef The desired right velocity. */ DifferentialDriveWheelVoltages Calculate( - const Pose2d& currentPose, wpi::units::meters_per_second_t leftVelocity, - wpi::units::meters_per_second_t rightVelocity, const Pose2d& poseRef, - wpi::units::meters_per_second_t leftVelocityRef, - wpi::units::meters_per_second_t rightVelocityRef); + const Pose2d& currentPose, wpi::units::meters_per_second<> leftVelocity, + wpi::units::meters_per_second<> rightVelocity, const Pose2d& poseRef, + wpi::units::meters_per_second<> leftVelocityRef, + wpi::units::meters_per_second<> rightVelocityRef); /** * Returns the left and right output voltages of the LTV controller. @@ -137,8 +137,8 @@ class WPILIB_DLLEXPORT LTVDifferentialDriveController { * from a trajectory. */ DifferentialDriveWheelVoltages Calculate( - const Pose2d& currentPose, wpi::units::meters_per_second_t leftVelocity, - wpi::units::meters_per_second_t rightVelocity, + const Pose2d& currentPose, wpi::units::meters_per_second<> leftVelocity, + wpi::units::meters_per_second<> rightVelocity, const DifferentialSample& desiredState) { return Calculate(currentPose, leftVelocity, rightVelocity, desiredState.pose, desiredState.leftVelocity, @@ -146,7 +146,7 @@ class WPILIB_DLLEXPORT LTVDifferentialDriveController { } private: - wpi::units::meter_t m_trackwidth; + wpi::units::meters<> m_trackwidth; // Continuous velocity dynamics Eigen::Matrix m_A; @@ -156,7 +156,7 @@ class WPILIB_DLLEXPORT LTVDifferentialDriveController { Eigen::Matrix m_Q; Eigen::Matrix m_R; - wpi::units::second_t m_dt; + wpi::units::seconds<> m_dt; Eigen::Vector m_error; Eigen::Vector m_tolerance; diff --git a/wpimath/src/main/native/include/wpi/math/controller/LTVUnicycleController.hpp b/wpimath/src/main/native/include/wpi/math/controller/LTVUnicycleController.hpp index fcfd1f578d6..4f334105b86 100644 --- a/wpimath/src/main/native/include/wpi/math/controller/LTVUnicycleController.hpp +++ b/wpimath/src/main/native/include/wpi/math/controller/LTVUnicycleController.hpp @@ -11,7 +11,6 @@ #include "wpi/math/trajectory/HolonomicSample.hpp" #include "wpi/math/util/StateSpaceUtil.hpp" #include "wpi/units/angular_velocity.hpp" -#include "wpi/units/math.hpp" #include "wpi/units/time.hpp" #include "wpi/units/velocity.hpp" #include "wpi/util/SymbolExports.hpp" @@ -37,7 +36,7 @@ class WPILIB_DLLEXPORT LTVUnicycleController { * * @param dt Discretization timestep. */ - explicit LTVUnicycleController(wpi::units::second_t dt) + explicit LTVUnicycleController(wpi::units::seconds<> dt) : LTVUnicycleController{{0.0625, 0.125, 2.0}, {1.0, 2.0}, dt} {} /** @@ -55,7 +54,7 @@ class WPILIB_DLLEXPORT LTVUnicycleController { */ LTVUnicycleController(const wpi::util::array& Qelems, const wpi::util::array& Relems, - wpi::units::second_t dt) + wpi::units::seconds<> dt) : m_Q{wpi::math::CostMatrix(Qelems)}, m_R{wpi::math::CostMatrix(Relems)}, m_dt{dt} {} @@ -78,9 +77,9 @@ class WPILIB_DLLEXPORT LTVUnicycleController { const auto& eRotate = m_poseError.Rotation(); const auto& tolTranslate = m_poseTolerance.Translation(); const auto& tolRotate = m_poseTolerance.Rotation(); - return wpi::units::math::abs(eTranslate.X()) < tolTranslate.X() && - wpi::units::math::abs(eTranslate.Y()) < tolTranslate.Y() && - wpi::units::math::abs(eRotate.Radians()) < tolRotate.Radians(); + return wpi::units::abs(eTranslate.X()) < tolTranslate.X() && + wpi::units::abs(eTranslate.Y()) < tolTranslate.Y() && + wpi::units::abs(eRotate.Radians()) < tolRotate.Radians(); } /** @@ -106,8 +105,8 @@ class WPILIB_DLLEXPORT LTVUnicycleController { */ ChassisVelocities Calculate( const Pose2d& currentPose, const Pose2d& poseRef, - wpi::units::meters_per_second_t linearVelocityRef, - wpi::units::radians_per_second_t angularVelocityRef); + wpi::units::meters_per_second<> linearVelocityRef, + wpi::units::radians_per_second<> angularVelocityRef); /** * Returns the linear and angular velocity outputs of the LTV controller. @@ -141,7 +140,7 @@ class WPILIB_DLLEXPORT LTVUnicycleController { Eigen::Matrix m_Q; Eigen::Matrix m_R; - wpi::units::second_t m_dt; + wpi::units::seconds<> m_dt; Pose2d m_poseError; Pose2d m_poseTolerance; diff --git a/wpimath/src/main/native/include/wpi/math/controller/LinearPlantInversionFeedforward.hpp b/wpimath/src/main/native/include/wpi/math/controller/LinearPlantInversionFeedforward.hpp index bfb8c516a42..6479b5d4060 100644 --- a/wpimath/src/main/native/include/wpi/math/controller/LinearPlantInversionFeedforward.hpp +++ b/wpimath/src/main/native/include/wpi/math/controller/LinearPlantInversionFeedforward.hpp @@ -42,7 +42,7 @@ class LinearPlantInversionFeedforward { template LinearPlantInversionFeedforward( const LinearSystem& plant, - wpi::units::second_t dt) + wpi::units::seconds<> dt) : LinearPlantInversionFeedforward(plant.A(), plant.B(), dt) {} /** @@ -54,7 +54,7 @@ class LinearPlantInversionFeedforward { */ LinearPlantInversionFeedforward(const Matrixd& A, const Matrixd& B, - wpi::units::second_t dt) + wpi::units::seconds<> dt) : m_dt(dt) { DiscretizeAB(A, B, dt, &m_A, &m_B); Reset(); @@ -148,7 +148,7 @@ class LinearPlantInversionFeedforward { Matrixd m_A; Matrixd m_B; - wpi::units::second_t m_dt; + wpi::units::seconds<> m_dt; // Current reference StateVector m_r; diff --git a/wpimath/src/main/native/include/wpi/math/controller/LinearQuadraticRegulator.hpp b/wpimath/src/main/native/include/wpi/math/controller/LinearQuadraticRegulator.hpp index c042dfb6151..f6bcfc1f527 100644 --- a/wpimath/src/main/native/include/wpi/math/controller/LinearQuadraticRegulator.hpp +++ b/wpimath/src/main/native/include/wpi/math/controller/LinearQuadraticRegulator.hpp @@ -63,7 +63,7 @@ class LinearQuadraticRegulator { template LinearQuadraticRegulator(const LinearSystem& plant, const StateArray& Qelems, const InputArray& Relems, - wpi::units::second_t dt) + wpi::units::seconds<> dt) : LinearQuadraticRegulator(plant.A(), plant.B(), Qelems, Relems, dt) {} /** @@ -83,7 +83,7 @@ class LinearQuadraticRegulator { LinearQuadraticRegulator(const Matrixd& A, const Matrixd& B, const StateArray& Qelems, const InputArray& Relems, - wpi::units::second_t dt) + wpi::units::seconds<> dt) : LinearQuadraticRegulator(A, B, CostMatrix(Qelems), CostMatrix(Relems), dt) {} @@ -101,7 +101,7 @@ class LinearQuadraticRegulator { const Matrixd& B, const Matrixd& Q, const Matrixd& R, - wpi::units::second_t dt) { + wpi::units::seconds<> dt) { Matrixd discA; Matrixd discB; DiscretizeAB(A, B, dt, &discA, &discB); @@ -157,7 +157,7 @@ class LinearQuadraticRegulator { const Matrixd& Q, const Matrixd& R, const Matrixd& N, - wpi::units::second_t dt) { + wpi::units::seconds<> dt) { Matrixd discA; Matrixd discB; DiscretizeAB(A, B, dt, &discA, &discB); @@ -318,8 +318,8 @@ class LinearQuadraticRegulator { */ template void LatencyCompensate(const LinearSystem& plant, - wpi::units::second_t dt, - wpi::units::second_t inputDelay) { + wpi::units::seconds<> dt, + wpi::units::seconds<> inputDelay) { Matrixd discA; Matrixd discB; DiscretizeAB(plant.A(), plant.B(), dt, &discA, &discB); diff --git a/wpimath/src/main/native/include/wpi/math/controller/PIDController.hpp b/wpimath/src/main/native/include/wpi/math/controller/PIDController.hpp index 3957a545274..26bd354e706 100644 --- a/wpimath/src/main/native/include/wpi/math/controller/PIDController.hpp +++ b/wpimath/src/main/native/include/wpi/math/controller/PIDController.hpp @@ -38,7 +38,7 @@ class WPILIB_DLLEXPORT PIDController : public wpi::telemetry::TelemetryLoggable, * default is 20 milliseconds. Must be positive. */ constexpr PIDController(double Kp, double Ki, double Kd, - wpi::units::second_t period = 20_ms) + wpi::units::seconds<> period = 20_ms) : m_Kp(Kp), m_Ki(Ki), m_Kd(Kd), m_period(period) { bool invalidGains = false; if (Kp < 0.0) { @@ -181,7 +181,7 @@ class WPILIB_DLLEXPORT PIDController : public wpi::telemetry::TelemetryLoggable, * * @return The period of the controller. */ - constexpr wpi::units::second_t GetPeriod() const { return m_period; } + constexpr wpi::units::seconds<> GetPeriod() const { return m_period; } /** * Gets the error tolerance of this controller. Defaults to 0.05. @@ -392,7 +392,7 @@ class WPILIB_DLLEXPORT PIDController : public wpi::telemetry::TelemetryLoggable, std::numeric_limits::infinity()}; // The period (in seconds) of the control loop running this controller - wpi::units::second_t m_period; + wpi::units::seconds<> m_period; double m_maximumIntegral = 1.0; diff --git a/wpimath/src/main/native/include/wpi/math/controller/ProfiledPIDController.hpp b/wpimath/src/main/native/include/wpi/math/controller/ProfiledPIDController.hpp index 5cb66ea632e..d380887b827 100644 --- a/wpimath/src/main/native/include/wpi/math/controller/ProfiledPIDController.hpp +++ b/wpimath/src/main/native/include/wpi/math/controller/ProfiledPIDController.hpp @@ -18,7 +18,7 @@ #include "wpi/tunables/Tunable.hpp" #include "wpi/tunables/TunableConfig.hpp" #include "wpi/tunables/TunableTable.hpp" -#include "wpi/units/base.hpp" +#include "wpi/units/core.hpp" #include "wpi/units/time.hpp" #include "wpi/util/SymbolExports.hpp" #include "wpi/util/UsageReporting.hpp" @@ -37,15 +37,13 @@ template class ProfiledPIDController : public wpi::telemetry::TelemetryLoggable, public wpi::tunables::ComplexTunable { public: - using Distance_t = wpi::units::unit_t; - using Velocity = - wpi::units::compound_unit>; - using Velocity_t = wpi::units::unit_t; - using Acceleration = - wpi::units::compound_unit>; - using Acceleration_t = wpi::units::unit_t; + using Distance_t = wpi::units::unit; + using Velocity = wpi::units::compound_conversion_factor< + Distance, wpi::units::inverse>; + using Velocity_t = wpi::units::unit; + using Acceleration = wpi::units::compound_conversion_factor< + Velocity, wpi::units::inverse>; + using Acceleration_t = wpi::units::unit; using State = typename TrapezoidProfile::State; using Constraints = typename TrapezoidProfile::Constraints; @@ -63,7 +61,7 @@ class ProfiledPIDController : public wpi::telemetry::TelemetryLoggable, */ constexpr ProfiledPIDController(double Kp, double Ki, double Kd, Constraints constraints, - wpi::units::second_t period = 20_ms) + wpi::units::seconds<> period = 20_ms) : m_controller{Kp, Ki, Kd, period}, m_constraints{constraints}, m_profile{m_constraints} { @@ -170,7 +168,7 @@ class ProfiledPIDController : public wpi::telemetry::TelemetryLoggable, * * @return The period of the controller. */ - constexpr wpi::units::second_t GetPeriod() const { + constexpr wpi::units::seconds<> GetPeriod() const { return m_controller.GetPeriod(); } @@ -489,10 +487,9 @@ class ProfiledPIDController : public wpi::telemetry::TelemetryLoggable, } private: - using BaseDistance = - wpi::units::unit, - wpi::units::traits::base_unit_of>; - using BaseDistance_t = wpi::units::unit_t; + using BaseDistance = wpi::units::conversion_factor< + std::ratio<1>, wpi::units::traits::dimension_of_t>; + using BaseDistance_t = wpi::units::unit; static constexpr double ToBaseGoalPosition(Distance_t position) { return BaseDistance_t{position}.value(); diff --git a/wpimath/src/main/native/include/wpi/math/controller/SimpleMotorFeedforward.hpp b/wpimath/src/main/native/include/wpi/math/controller/SimpleMotorFeedforward.hpp index ed662a1c719..d6d92121abd 100644 --- a/wpimath/src/main/native/include/wpi/math/controller/SimpleMotorFeedforward.hpp +++ b/wpimath/src/main/native/include/wpi/math/controller/SimpleMotorFeedforward.hpp @@ -8,7 +8,7 @@ #include "wpi/math/util/MathShared.hpp" #include "wpi/units/angle.hpp" -#include "wpi/units/base.hpp" +#include "wpi/units/core.hpp" #include "wpi/units/length.hpp" #include "wpi/units/time.hpp" #include "wpi/units/voltage.hpp" @@ -21,21 +21,20 @@ namespace wpi::math { * permanent-magnet DC motor. */ template - requires wpi::units::length_unit || - wpi::units::angle_unit || - wpi::units::dimensionless_unit + requires wpi::units::Length || wpi::units::Angle || + wpi::units::Dimensionless class SimpleMotorFeedforward { public: - using Velocity = - wpi::units::compound_unit>; - using Acceleration = - wpi::units::compound_unit>; - using kv_unit = wpi::units::compound_unit>; - using ka_unit = wpi::units::compound_unit>; + using Velocity = wpi::units::compound_conversion_factor< + Distance, wpi::units::inverse>; + using Acceleration = wpi::units::compound_conversion_factor< + Velocity, wpi::units::inverse>; + using kv_unit = + wpi::units::compound_conversion_factor>; + using ka_unit = + wpi::units::compound_conversion_factor>; /** * Creates a new SimpleMotorFeedforward with the specified gains. @@ -49,20 +48,20 @@ class SimpleMotorFeedforward { * @throws IllegalArgumentException for period ≤ zero. */ constexpr SimpleMotorFeedforward( - wpi::units::volt_t kS, wpi::units::unit_t kV, - wpi::units::unit_t kA = wpi::units::unit_t(0), - wpi::units::second_t dt = 20_ms) + wpi::units::volts<> kS, wpi::units::unit kV, + wpi::units::unit kA = wpi::units::unit(0), + wpi::units::seconds<> dt = 20_ms) : kS(kS), kV(kV), kA(kA), m_dt(dt) { if (kV.value() < 0) { wpi::math::MathSharedStore::ReportError( "kV must be a non-negative number, got {}!", kV.value()); - this->kV = wpi::units::unit_t{0}; + this->kV = wpi::units::unit{0}; wpi::math::MathSharedStore::ReportWarning("kV defaulted to 0."); } if (kA.value() < 0) { wpi::math::MathSharedStore::ReportError( "kA must be a non-negative number, got {}!", kA.value()); - this->kA = wpi::units::unit_t{0}; + this->kA = wpi::units::unit{0}; wpi::math::MathSharedStore::ReportWarning("kA defaulted to 0."); } if (dt <= 0_ms) { @@ -81,8 +80,8 @@ class SimpleMotorFeedforward { * @param velocity The velocity reference. * @return The computed feedforward, in volts. */ - constexpr wpi::units::volt_t Calculate( - wpi::units::unit_t velocity) const { + constexpr wpi::units::volts<> Calculate( + wpi::units::unit velocity) const { return Calculate(velocity, velocity); } @@ -96,9 +95,9 @@ class SimpleMotorFeedforward { * @param nextVelocity The next velocity reference. * @return The computed feedforward, in volts. */ - constexpr wpi::units::volt_t Calculate( - wpi::units::unit_t currentVelocity, - wpi::units::unit_t nextVelocity) const { + constexpr wpi::units::volts<> Calculate( + wpi::units::unit currentVelocity, + wpi::units::unit nextVelocity) const { // See wpimath/docs/SimpleMotorFeedforward.md for derivation if (kA < decltype(kA)(1e-9)) { return kS * wpi::util::sgn(nextVelocity) + kV * nextVelocity; @@ -108,7 +107,7 @@ class SimpleMotorFeedforward { double A_d = gcem::exp(A * m_dt.value()); double B_d = A > -1e-9 ? B * m_dt.value() : 1.0 / A * (A_d - 1.0) * B; return kS * wpi::util::sgn(currentVelocity) + - wpi::units::volt_t{ + wpi::units::volts<>{ 1.0 / B_d * (nextVelocity.value() - A_d * currentVelocity.value())}; } @@ -128,9 +127,9 @@ class SimpleMotorFeedforward { * @param acceleration The acceleration of the motor. * @return The maximum possible velocity at the given acceleration. */ - constexpr wpi::units::unit_t MaxAchievableVelocity( - wpi::units::volt_t maxVoltage, - wpi::units::unit_t acceleration) const { + constexpr wpi::units::unit MaxAchievableVelocity( + wpi::units::volts<> maxVoltage, + wpi::units::unit acceleration) const { // Assume max velocity is positive return (maxVoltage - kS - kA * acceleration) / kV; } @@ -146,9 +145,9 @@ class SimpleMotorFeedforward { * @param acceleration The acceleration of the motor. * @return The minimum possible velocity at the given acceleration. */ - constexpr wpi::units::unit_t MinAchievableVelocity( - wpi::units::volt_t maxVoltage, - wpi::units::unit_t acceleration) const { + constexpr wpi::units::unit MinAchievableVelocity( + wpi::units::volts<> maxVoltage, + wpi::units::unit acceleration) const { // Assume min velocity is positive, ks flips sign return (-maxVoltage + kS - kA * acceleration) / kV; } @@ -164,9 +163,9 @@ class SimpleMotorFeedforward { * @param velocity The velocity of the motor. * @return The maximum possible acceleration at the given velocity. */ - constexpr wpi::units::unit_t MaxAchievableAcceleration( - wpi::units::volt_t maxVoltage, - wpi::units::unit_t velocity) const { + constexpr wpi::units::unit MaxAchievableAcceleration( + wpi::units::volts<> maxVoltage, + wpi::units::unit velocity) const { return (maxVoltage - kS * wpi::util::sgn(velocity) - kV * velocity) / kA; } @@ -181,9 +180,9 @@ class SimpleMotorFeedforward { * @param velocity The velocity of the motor. * @return The minimum possible acceleration at the given velocity. */ - constexpr wpi::units::unit_t MinAchievableAcceleration( - wpi::units::volt_t maxVoltage, - wpi::units::unit_t velocity) const { + constexpr wpi::units::unit MinAchievableAcceleration( + wpi::units::volts<> maxVoltage, + wpi::units::unit velocity) const { return MaxAchievableAcceleration(-maxVoltage, velocity); } @@ -196,7 +195,7 @@ class SimpleMotorFeedforward { * * @param kS The static gain. */ - constexpr void SetKs(wpi::units::volt_t kS) { this->kS = kS; } + constexpr void SetKs(wpi::units::volts<> kS) { this->kS = kS; } /** * Sets the velocity gain. @@ -207,7 +206,7 @@ class SimpleMotorFeedforward { * * @param kV The velocity gain. */ - constexpr void SetKv(wpi::units::unit_t kV) { this->kV = kV; } + constexpr void SetKv(wpi::units::unit kV) { this->kV = kV; } /** * Sets the acceleration gain. @@ -218,48 +217,48 @@ class SimpleMotorFeedforward { * * @param kA The acceleration gain. */ - constexpr void SetKa(wpi::units::unit_t kA) { this->kA = kA; } + constexpr void SetKa(wpi::units::unit kA) { this->kA = kA; } /** * Returns the static gain. * * @return The static gain. */ - constexpr wpi::units::volt_t GetKs() const { return kS; } + constexpr wpi::units::volts<> GetKs() const { return kS; } /** * Returns the velocity gain. * * @return The velocity gain. */ - constexpr wpi::units::unit_t GetKv() const { return kV; } + constexpr wpi::units::unit GetKv() const { return kV; } /** * Returns the acceleration gain. * * @return The acceleration gain. */ - constexpr wpi::units::unit_t GetKa() const { return kA; } + constexpr wpi::units::unit GetKa() const { return kA; } /** * Returns the period. * * @return The period. */ - constexpr wpi::units::second_t GetDt() const { return m_dt; } + constexpr wpi::units::seconds<> GetDt() const { return m_dt; } private: /** The static gain. */ - wpi::units::volt_t kS; + wpi::units::volts<> kS; /** The velocity gain. */ - wpi::units::unit_t kV; + wpi::units::unit kV; /** The acceleration gain. */ - wpi::units::unit_t kA; + wpi::units::unit kA; /** The period. */ - wpi::units::second_t m_dt; + wpi::units::seconds<> m_dt; }; } // namespace wpi::math diff --git a/wpimath/src/main/native/include/wpi/math/controller/proto/SimpleMotorFeedforwardProto.hpp b/wpimath/src/main/native/include/wpi/math/controller/proto/SimpleMotorFeedforwardProto.hpp index 64dd44d89cd..08f04913e93 100644 --- a/wpimath/src/main/native/include/wpi/math/controller/proto/SimpleMotorFeedforwardProto.hpp +++ b/wpimath/src/main/native/include/wpi/math/controller/proto/SimpleMotorFeedforwardProto.hpp @@ -11,13 +11,12 @@ #include "wpimath/protobuf/controller.npb.h" // Everything is converted into units for -// wpi::math::SimpleMotorFeedforward or -// wpi::math::SimpleMotorFeedforward +// wpi::math::SimpleMotorFeedforward or +// wpi::math::SimpleMotorFeedforward template - requires wpi::units::length_unit || - wpi::units::angle_unit || - wpi::units::dimensionless_unit + requires wpi::units::Length || wpi::units::Angle || + wpi::units::Dimensionless struct wpi::util::Protobuf> { using MessageStruct = wpi_proto_ProtobufSimpleMotorFeedforward; using InputStream = @@ -27,9 +26,8 @@ struct wpi::util::Protobuf> { static std::optional> Unpack( InputStream& stream) { - using BaseUnit = - wpi::units::unit, - wpi::units::traits::base_unit_of>; + using BaseUnit = wpi::units::conversion_factor< + std::ratio<1>, wpi::units::traits::dimension_of_t>; using BaseFeedforward = wpi::math::SimpleMotorFeedforward; wpi_proto_ProtobufSimpleMotorFeedforward msg; if (!stream.Decode(msg)) { @@ -37,28 +35,25 @@ struct wpi::util::Protobuf> { } return wpi::math::SimpleMotorFeedforward{ - wpi::units::volt_t{msg.ks}, - wpi::units::unit_t{msg.kv}, - wpi::units::unit_t{msg.ka}, - wpi::units::second_t{msg.dt}, + wpi::units::volts<>{msg.ks}, + wpi::units::unit{msg.kv}, + wpi::units::unit{msg.ka}, + wpi::units::seconds<>{msg.dt}, }; } static bool Pack(OutputStream& stream, const wpi::math::SimpleMotorFeedforward& value) { - using BaseUnit = - wpi::units::unit, - wpi::units::traits::base_unit_of>; + using BaseUnit = wpi::units::conversion_factor< + std::ratio<1>, wpi::units::traits::dimension_of_t>; using BaseFeedforward = wpi::math::SimpleMotorFeedforward; wpi_proto_ProtobufSimpleMotorFeedforward msg{ .ks = value.GetKs().value(), - .kv = - wpi::units::unit_t{value.GetKv()} - .value(), - .ka = - wpi::units::unit_t{value.GetKa()} - .value(), - .dt = wpi::units::second_t{value.GetDt()}.value(), + .kv = wpi::units::unit{value.GetKv()} + .value(), + .ka = wpi::units::unit{value.GetKa()} + .value(), + .dt = wpi::units::seconds<>{value.GetDt()}.value(), }; return stream.Encode(msg); } diff --git a/wpimath/src/main/native/include/wpi/math/controller/struct/SimpleMotorFeedforwardStruct.hpp b/wpimath/src/main/native/include/wpi/math/controller/struct/SimpleMotorFeedforwardStruct.hpp index 5a1cb2bc1b5..a138f1b4e6e 100644 --- a/wpimath/src/main/native/include/wpi/math/controller/struct/SimpleMotorFeedforwardStruct.hpp +++ b/wpimath/src/main/native/include/wpi/math/controller/struct/SimpleMotorFeedforwardStruct.hpp @@ -9,13 +9,12 @@ #include "wpi/util/struct/Struct.hpp" // Everything is converted into units for -// wpi::math::SimpleMotorFeedforward or -// wpi::math::SimpleMotorFeedforward +// wpi::math::SimpleMotorFeedforward or +// wpi::math::SimpleMotorFeedforward template - requires wpi::units::length_unit || - wpi::units::angle_unit || - wpi::units::dimensionless_unit + requires wpi::units::Length || wpi::units::Angle || + wpi::units::Dimensionless struct wpi::util::Struct> { static constexpr std::string_view GetTypeName() { return "SimpleMotorFeedforward"; @@ -27,28 +26,26 @@ struct wpi::util::Struct> { static wpi::math::SimpleMotorFeedforward Unpack( std::span data) { - using BaseUnit = - wpi::units::unit, - wpi::units::traits::base_unit_of>; + using BaseUnit = wpi::units::conversion_factor< + std::ratio<1>, wpi::units::traits::dimension_of_t>; using BaseFeedforward = wpi::math::SimpleMotorFeedforward; constexpr size_t KS_OFF = 0; constexpr size_t KV_OFF = KS_OFF + 8; constexpr size_t KA_OFF = KV_OFF + 8; constexpr size_t DT_OFF = KA_OFF + 8; return { - wpi::units::volt_t{wpi::util::UnpackStruct(data)}, - wpi::units::unit_t{ + wpi::units::volts<>{wpi::util::UnpackStruct(data)}, + wpi::units::unit{ wpi::util::UnpackStruct(data)}, - wpi::units::unit_t{ + wpi::units::unit{ wpi::util::UnpackStruct(data)}, - wpi::units::second_t{wpi::util::UnpackStruct(data)}}; + wpi::units::seconds<>{wpi::util::UnpackStruct(data)}}; } static void Pack(std::span data, const wpi::math::SimpleMotorFeedforward& value) { - using BaseUnit = - wpi::units::unit, - wpi::units::traits::base_unit_of>; + using BaseUnit = wpi::units::conversion_factor< + std::ratio<1>, wpi::units::traits::dimension_of_t>; using BaseFeedforward = wpi::math::SimpleMotorFeedforward; constexpr size_t KS_OFF = 0; constexpr size_t KV_OFF = KS_OFF + 8; @@ -56,21 +53,19 @@ struct wpi::util::Struct> { constexpr size_t DT_OFF = KA_OFF + 8; wpi::util::PackStruct(data, value.GetKs().value()); wpi::util::PackStruct( - data, - wpi::units::unit_t{value.GetKv()} - .value()); + data, wpi::units::unit{value.GetKv()} + .value()); wpi::util::PackStruct( - data, - wpi::units::unit_t{value.GetKa()} - .value()); + data, wpi::units::unit{value.GetKa()} + .value()); wpi::util::PackStruct(data, - wpi::units::second_t{value.GetDt()}.value()); + wpi::units::seconds<>{value.GetDt()}.value()); } }; static_assert(wpi::util::StructSerializable< - wpi::math::SimpleMotorFeedforward>); + wpi::math::SimpleMotorFeedforward>); static_assert(wpi::util::StructSerializable< - wpi::math::SimpleMotorFeedforward>); + wpi::math::SimpleMotorFeedforward>); static_assert(wpi::util::StructSerializable< - wpi::math::SimpleMotorFeedforward>); + wpi::math::SimpleMotorFeedforward>); diff --git a/wpimath/src/main/native/include/wpi/math/estimator/AngleStatistics.hpp b/wpimath/src/main/native/include/wpi/math/estimator/AngleStatistics.hpp index 1ff3d6329ab..989653ebd45 100644 --- a/wpimath/src/main/native/include/wpi/math/estimator/AngleStatistics.hpp +++ b/wpimath/src/main/native/include/wpi/math/estimator/AngleStatistics.hpp @@ -28,7 +28,7 @@ Vectord AngleResidual(const Vectord& a, const Vectord& b, int angleStateIdx) { Vectord ret = a - b; ret[angleStateIdx] = - AngleModulus(wpi::units::radian_t{ret[angleStateIdx]}).value(); + AngleModulus(wpi::units::radians<>{ret[angleStateIdx]}).value(); return ret; } diff --git a/wpimath/src/main/native/include/wpi/math/estimator/DifferentialDrivePoseEstimator.hpp b/wpimath/src/main/native/include/wpi/math/estimator/DifferentialDrivePoseEstimator.hpp index 5600f584a72..62d8092dc57 100644 --- a/wpimath/src/main/native/include/wpi/math/estimator/DifferentialDrivePoseEstimator.hpp +++ b/wpimath/src/main/native/include/wpi/math/estimator/DifferentialDrivePoseEstimator.hpp @@ -55,8 +55,8 @@ class WPILIB_DLLEXPORT DifferentialDrivePoseEstimator * @param initialPose The estimated initial pose. */ DifferentialDrivePoseEstimator(const Rotation2d& gyroAngle, - wpi::units::meter_t leftDistance, - wpi::units::meter_t rightDistance, + wpi::units::meters<> leftDistance, + wpi::units::meters<> rightDistance, const Pose2d& initialPose); /** @@ -76,8 +76,8 @@ class WPILIB_DLLEXPORT DifferentialDrivePoseEstimator * less. */ DifferentialDrivePoseEstimator( - const Rotation2d& gyroAngle, wpi::units::meter_t leftDistance, - wpi::units::meter_t rightDistance, const Pose2d& initialPose, + const Rotation2d& gyroAngle, wpi::units::meters<> leftDistance, + wpi::units::meters<> rightDistance, const Pose2d& initialPose, const wpi::util::array& stateStdDevs, const wpi::util::array& visionMeasurementStdDevs); @@ -90,8 +90,8 @@ class WPILIB_DLLEXPORT DifferentialDrivePoseEstimator * @param pose The estimated pose of the robot on the field. */ void ResetPosition(const Rotation2d& gyroAngle, - wpi::units::meter_t leftDistance, - wpi::units::meter_t rightDistance, const Pose2d& pose) { + wpi::units::meters<> leftDistance, + wpi::units::meters<> rightDistance, const Pose2d& pose) { PoseEstimator::ResetPosition(gyroAngle, {leftDistance, rightDistance}, pose); } @@ -106,8 +106,8 @@ class WPILIB_DLLEXPORT DifferentialDrivePoseEstimator * * @return The estimated pose of the robot. */ - Pose2d Update(const Rotation2d& gyroAngle, wpi::units::meter_t leftDistance, - wpi::units::meter_t rightDistance) { + Pose2d Update(const Rotation2d& gyroAngle, wpi::units::meters<> leftDistance, + wpi::units::meters<> rightDistance) { return PoseEstimator::Update(gyroAngle, {leftDistance, rightDistance}); } @@ -122,10 +122,10 @@ class WPILIB_DLLEXPORT DifferentialDrivePoseEstimator * * @return The estimated pose of the robot. */ - Pose2d UpdateWithTime(wpi::units::second_t currentTime, + Pose2d UpdateWithTime(wpi::units::seconds<> currentTime, const Rotation2d& gyroAngle, - wpi::units::meter_t leftDistance, - wpi::units::meter_t rightDistance) { + wpi::units::meters<> leftDistance, + wpi::units::meters<> rightDistance) { return PoseEstimator::UpdateWithTime(currentTime, gyroAngle, {leftDistance, rightDistance}); } diff --git a/wpimath/src/main/native/include/wpi/math/estimator/DifferentialDrivePoseEstimator3d.hpp b/wpimath/src/main/native/include/wpi/math/estimator/DifferentialDrivePoseEstimator3d.hpp index 223b95382d9..638954b31c4 100644 --- a/wpimath/src/main/native/include/wpi/math/estimator/DifferentialDrivePoseEstimator3d.hpp +++ b/wpimath/src/main/native/include/wpi/math/estimator/DifferentialDrivePoseEstimator3d.hpp @@ -60,8 +60,8 @@ class WPILIB_DLLEXPORT DifferentialDrivePoseEstimator3d * @param initialPose The estimated initial pose. */ DifferentialDrivePoseEstimator3d(const Rotation3d& gyroAngle, - wpi::units::meter_t leftDistance, - wpi::units::meter_t rightDistance, + wpi::units::meters<> leftDistance, + wpi::units::meters<> rightDistance, const Pose3d& initialPose); /** @@ -81,8 +81,8 @@ class WPILIB_DLLEXPORT DifferentialDrivePoseEstimator3d * pose measurement less. */ DifferentialDrivePoseEstimator3d( - const Rotation3d& gyroAngle, wpi::units::meter_t leftDistance, - wpi::units::meter_t rightDistance, const Pose3d& initialPose, + const Rotation3d& gyroAngle, wpi::units::meters<> leftDistance, + wpi::units::meters<> rightDistance, const Pose3d& initialPose, const wpi::util::array& stateStdDevs, const wpi::util::array& visionMeasurementStdDevs); @@ -96,8 +96,8 @@ class WPILIB_DLLEXPORT DifferentialDrivePoseEstimator3d * @param pose The estimated pose of the robot on the field. */ void ResetPosition(const Rotation3d& gyroAngle, - wpi::units::meter_t leftDistance, - wpi::units::meter_t rightDistance, const Pose3d& pose) { + wpi::units::meters<> leftDistance, + wpi::units::meters<> rightDistance, const Pose3d& pose) { PoseEstimator3d::ResetPosition(gyroAngle, {leftDistance, rightDistance}, pose); } @@ -113,8 +113,8 @@ class WPILIB_DLLEXPORT DifferentialDrivePoseEstimator3d * * @return The estimated pose of the robot. */ - Pose3d Update(const Rotation3d& gyroAngle, wpi::units::meter_t leftDistance, - wpi::units::meter_t rightDistance) { + Pose3d Update(const Rotation3d& gyroAngle, wpi::units::meters<> leftDistance, + wpi::units::meters<> rightDistance) { return PoseEstimator3d::Update(gyroAngle, {leftDistance, rightDistance}); } @@ -130,10 +130,10 @@ class WPILIB_DLLEXPORT DifferentialDrivePoseEstimator3d * * @return The estimated pose of the robot. */ - Pose3d UpdateWithTime(wpi::units::second_t currentTime, + Pose3d UpdateWithTime(wpi::units::seconds<> currentTime, const Rotation3d& gyroAngle, - wpi::units::meter_t leftDistance, - wpi::units::meter_t rightDistance) { + wpi::units::meters<> leftDistance, + wpi::units::meters<> rightDistance) { return PoseEstimator3d::UpdateWithTime(currentTime, gyroAngle, {leftDistance, rightDistance}); } diff --git a/wpimath/src/main/native/include/wpi/math/estimator/ExtendedKalmanFilter.hpp b/wpimath/src/main/native/include/wpi/math/estimator/ExtendedKalmanFilter.hpp index ec37f7dfd13..44bc9152c7c 100644 --- a/wpimath/src/main/native/include/wpi/math/estimator/ExtendedKalmanFilter.hpp +++ b/wpimath/src/main/native/include/wpi/math/estimator/ExtendedKalmanFilter.hpp @@ -81,7 +81,7 @@ class ExtendedKalmanFilter { std::function f, std::function h, const StateArray& stateStdDevs, const OutputArray& measurementStdDevs, - wpi::units::second_t dt) + wpi::units::seconds<> dt) : m_f(std::move(f)), m_h(std::move(h)) { m_contQ = CovarianceMatrix(stateStdDevs); m_contR = CovarianceMatrix(measurementStdDevs); @@ -170,7 +170,7 @@ class ExtendedKalmanFilter { residualFuncY, std::function addFuncX, - wpi::units::second_t dt) + wpi::units::seconds<> dt) : m_f(std::move(f)), m_h(std::move(h)), m_residualFuncY(std::move(residualFuncY)), @@ -290,7 +290,7 @@ class ExtendedKalmanFilter { * @param u New control input from controller. * @param dt Timestep for prediction. */ - void Predict(const InputVector& u, wpi::units::second_t dt) { + void Predict(const InputVector& u, wpi::units::seconds<> dt) { // Find continuous A StateMatrix contA = NumericalJacobianX(m_f, m_xHat, u); @@ -420,7 +420,7 @@ class ExtendedKalmanFilter { StateMatrix m_P; StateMatrix m_contQ; Matrixd m_contR; - wpi::units::second_t m_dt; + wpi::units::seconds<> m_dt; StateMatrix m_initP; }; diff --git a/wpimath/src/main/native/include/wpi/math/estimator/KalmanFilter.hpp b/wpimath/src/main/native/include/wpi/math/estimator/KalmanFilter.hpp index 7872729b2db..082e8c3791a 100644 --- a/wpimath/src/main/native/include/wpi/math/estimator/KalmanFilter.hpp +++ b/wpimath/src/main/native/include/wpi/math/estimator/KalmanFilter.hpp @@ -71,7 +71,8 @@ class KalmanFilter { */ KalmanFilter(LinearSystem& plant, const StateArray& stateStdDevs, - const OutputArray& measurementStdDevs, wpi::units::second_t dt) { + const OutputArray& measurementStdDevs, + wpi::units::seconds<> dt) { m_plant = &plant; m_contQ = CovarianceMatrix(stateStdDevs); @@ -184,7 +185,7 @@ class KalmanFilter { * @param u New control input from controller. * @param dt Timestep for prediction. */ - void Predict(const InputVector& u, wpi::units::second_t dt) { + void Predict(const InputVector& u, wpi::units::seconds<> dt) { // Find discrete A and Q StateMatrix discA; StateMatrix discQ; @@ -251,7 +252,7 @@ class KalmanFilter { StateMatrix m_P; StateMatrix m_contQ; Matrixd m_contR; - wpi::units::second_t m_dt; + wpi::units::seconds<> m_dt; StateMatrix m_initP; }; diff --git a/wpimath/src/main/native/include/wpi/math/estimator/KalmanFilterLatencyCompensator.hpp b/wpimath/src/main/native/include/wpi/math/estimator/KalmanFilterLatencyCompensator.hpp index be5a52b15d7..bf2c239c135 100644 --- a/wpimath/src/main/native/include/wpi/math/estimator/KalmanFilterLatencyCompensator.hpp +++ b/wpimath/src/main/native/include/wpi/math/estimator/KalmanFilterLatencyCompensator.hpp @@ -11,7 +11,6 @@ #include #include "wpi/math/linalg/EigenCore.hpp" -#include "wpi/units/math.hpp" #include "wpi/units/time.hpp" namespace wpi::math { @@ -63,7 +62,7 @@ class KalmanFilterLatencyCompensator { */ void AddObserverState(const KalmanFilterType& observer, Vectord u, Vectord localY, - wpi::units::second_t timestamp) { + wpi::units::seconds<> timestamp) { // Add the new state into the vector. m_pastObserverSnapshots.emplace_back(timestamp, ObserverSnapshot{observer, u, localY}); @@ -87,11 +86,11 @@ class KalmanFilterLatencyCompensator { */ template void ApplyPastGlobalMeasurement( - KalmanFilterType* observer, wpi::units::second_t nominalDt, + KalmanFilterType* observer, wpi::units::seconds<> nominalDt, Vectord y, std::function& u, const Vectord& y)> globalMeasurementCorrect, - wpi::units::second_t timestamp) { + wpi::units::seconds<> timestamp) { if (m_pastObserverSnapshots.size() == 0) { // State map was empty, which means that we got a measurement right at // startup. The only thing we can do is ignore the measurement. @@ -132,14 +131,14 @@ class KalmanFilterLatencyCompensator { int prevIdx = nextIdx - 1; // Find the snapshot closest in time to global measurement - wpi::units::second_t prevTimeDiff = wpi::units::math::abs( - timestamp - m_pastObserverSnapshots[prevIdx].first); - wpi::units::second_t nextTimeDiff = wpi::units::math::abs( - timestamp - m_pastObserverSnapshots[nextIdx].first); + wpi::units::seconds<> prevTimeDiff = + wpi::units::abs(timestamp - m_pastObserverSnapshots[prevIdx].first); + wpi::units::seconds<> nextTimeDiff = + wpi::units::abs(timestamp - m_pastObserverSnapshots[nextIdx].first); indexOfClosestEntry = prevTimeDiff < nextTimeDiff ? prevIdx : nextIdx; } - wpi::units::second_t lastTimestamp = + wpi::units::seconds<> lastTimestamp = m_pastObserverSnapshots[indexOfClosestEntry].first - nominalDt; // We will now go back in time to the state of the system at the time when @@ -176,7 +175,7 @@ class KalmanFilterLatencyCompensator { private: static constexpr size_t MAX_PAST_OBSERVER_STATES = 300; - std::vector> + std::vector, ObserverSnapshot>> m_pastObserverSnapshots; }; } // namespace wpi::math diff --git a/wpimath/src/main/native/include/wpi/math/estimator/PoseEstimator.hpp b/wpimath/src/main/native/include/wpi/math/estimator/PoseEstimator.hpp index 6fa9893436e..2d5eccf9f94 100644 --- a/wpimath/src/main/native/include/wpi/math/estimator/PoseEstimator.hpp +++ b/wpimath/src/main/native/include/wpi/math/estimator/PoseEstimator.hpp @@ -150,7 +150,7 @@ class WPILIB_DLLEXPORT PoseEstimator { void ResetTranslation(const Translation2d& translation) { m_odometry.ResetTranslation(translation); - const std::optional> + const std::optional, VisionUpdate>> latestVisionUpdate = m_visionUpdates.empty() ? std::nullopt : std::optional{*m_visionUpdates.crbegin()}; @@ -178,7 +178,7 @@ class WPILIB_DLLEXPORT PoseEstimator { void ResetRotation(const Rotation2d& rotation) { m_odometry.ResetRotation(rotation); - const std::optional> + const std::optional, VisionUpdate>> latestVisionUpdate = m_visionUpdates.empty() ? std::nullopt : std::optional{*m_visionUpdates.crbegin()}; @@ -212,7 +212,7 @@ class WPILIB_DLLEXPORT PoseEstimator { * @return The pose at the given timestamp (or std::nullopt if the buffer is * empty). */ - std::optional SampleAt(wpi::units::second_t timestamp) const { + std::optional SampleAt(wpi::units::seconds<> timestamp) const { // Step 0: If there are no odometry updates to sample, skip. if (m_odometryPoseBuffer.GetInternalBuffer().empty()) { return std::nullopt; @@ -221,9 +221,9 @@ class WPILIB_DLLEXPORT PoseEstimator { // Step 1: Make sure timestamp matches the sample from the odometry pose // buffer. (When sampling, the buffer will always use a timestamp // between the first and last timestamps) - wpi::units::second_t oldestOdometryTimestamp = + wpi::units::seconds<> oldestOdometryTimestamp = m_odometryPoseBuffer.GetInternalBuffer().front().first; - wpi::units::second_t newestOdometryTimestamp = + wpi::units::seconds<> newestOdometryTimestamp = m_odometryPoseBuffer.GetInternalBuffer().back().first; timestamp = std::clamp(timestamp, oldestOdometryTimestamp, newestOdometryTimestamp); @@ -271,7 +271,7 @@ class WPILIB_DLLEXPORT PoseEstimator { * wpi::Timer::GetMonotonicTimestamp() as your time source in this case. */ void AddVisionMeasurement(const Pose2d& visionRobotPose, - wpi::units::second_t timestamp) { + wpi::units::seconds<> timestamp) { // Step 0: If this measurement is old enough to be outside the pose buffer's // timespan, skip. if (m_odometryPoseBuffer.GetInternalBuffer().empty() || @@ -314,9 +314,9 @@ class WPILIB_DLLEXPORT PoseEstimator { // Step 6: Convert back to Transform2d. Transform2d scaledTransform{ - wpi::units::meter_t{k_times_transform(0)}, - wpi::units::meter_t{k_times_transform(1)}, - Rotation2d{wpi::units::radian_t{k_times_transform(2)}}}; + wpi::units::meters<>{k_times_transform(0)}, + wpi::units::meters<>{k_times_transform(1)}, + Rotation2d{wpi::units::radians<>{k_times_transform(2)}}}; // Step 7: Calculate and record the vision update. VisionUpdate visionUpdate{*visionSample + scaledTransform, *odometrySample}; @@ -359,7 +359,7 @@ class WPILIB_DLLEXPORT PoseEstimator { * less. */ void AddVisionMeasurement( - const Pose2d& visionRobotPose, wpi::units::second_t timestamp, + const Pose2d& visionRobotPose, wpi::units::seconds<> timestamp, const wpi::util::array& visionMeasurementStdDevs) { SetVisionMeasurementStdDevs(visionMeasurementStdDevs); AddVisionMeasurement(visionRobotPose, timestamp); @@ -392,7 +392,7 @@ class WPILIB_DLLEXPORT PoseEstimator { * * @return The estimated pose of the robot in meters. */ - Pose2d UpdateWithTime(wpi::units::second_t currentTime, + Pose2d UpdateWithTime(wpi::units::seconds<> currentTime, const Rotation2d& gyroAngle, const WheelPositions& wheelPositions) { auto odometryEstimate = m_odometry.Update(gyroAngle, wheelPositions); @@ -420,7 +420,7 @@ class WPILIB_DLLEXPORT PoseEstimator { } // Step 1: Find the oldest timestamp that needs a vision update. - wpi::units::second_t oldestOdometryTimestamp = + wpi::units::seconds<> oldestOdometryTimestamp = m_odometryPoseBuffer.GetInternalBuffer().front().first; // Step 2: If there are no vision updates before that timestamp, skip. @@ -463,7 +463,7 @@ class WPILIB_DLLEXPORT PoseEstimator { } }; - static constexpr wpi::units::second_t BUFFER_DURATION = 1.5_s; + static constexpr wpi::units::seconds<> BUFFER_DURATION = 1.5_s; Odometry& m_odometry; @@ -482,7 +482,7 @@ class WPILIB_DLLEXPORT PoseEstimator { // unless there have been no vision measurements after the last reset. May // contain one entry while m_odometryPoseBuffer is empty to correct for // translation/rotation after a call to ResetRotation/ResetTranslation. - std::map m_visionUpdates; + std::map, VisionUpdate> m_visionUpdates; Pose2d m_poseEstimate; }; diff --git a/wpimath/src/main/native/include/wpi/math/estimator/PoseEstimator3d.hpp b/wpimath/src/main/native/include/wpi/math/estimator/PoseEstimator3d.hpp index fd52a0c1218..c63afc908d2 100644 --- a/wpimath/src/main/native/include/wpi/math/estimator/PoseEstimator3d.hpp +++ b/wpimath/src/main/native/include/wpi/math/estimator/PoseEstimator3d.hpp @@ -158,7 +158,7 @@ class WPILIB_DLLEXPORT PoseEstimator3d { void ResetTranslation(const Translation3d& translation) { m_odometry.ResetTranslation(translation); - const std::optional> + const std::optional, VisionUpdate>> latestVisionUpdate = m_visionUpdates.empty() ? std::nullopt : std::optional{*m_visionUpdates.crbegin()}; @@ -186,7 +186,7 @@ class WPILIB_DLLEXPORT PoseEstimator3d { void ResetRotation(const Rotation3d& rotation) { m_odometry.ResetRotation(rotation); - const std::optional> + const std::optional, VisionUpdate>> latestVisionUpdate = m_visionUpdates.empty() ? std::nullopt : std::optional{*m_visionUpdates.crbegin()}; @@ -220,7 +220,7 @@ class WPILIB_DLLEXPORT PoseEstimator3d { * @return The pose at the given timestamp (or std::nullopt if the buffer is * empty). */ - std::optional SampleAt(wpi::units::second_t timestamp) const { + std::optional SampleAt(wpi::units::seconds<> timestamp) const { // Step 0: If there are no odometry updates to sample, skip. if (m_odometryPoseBuffer.GetInternalBuffer().empty()) { return std::nullopt; @@ -229,9 +229,9 @@ class WPILIB_DLLEXPORT PoseEstimator3d { // Step 1: Make sure timestamp matches the sample from the odometry pose // buffer. (When sampling, the buffer will always use a timestamp // between the first and last timestamps) - wpi::units::second_t oldestOdometryTimestamp = + wpi::units::seconds<> oldestOdometryTimestamp = m_odometryPoseBuffer.GetInternalBuffer().front().first; - wpi::units::second_t newestOdometryTimestamp = + wpi::units::seconds<> newestOdometryTimestamp = m_odometryPoseBuffer.GetInternalBuffer().back().first; timestamp = std::clamp(timestamp, oldestOdometryTimestamp, newestOdometryTimestamp); @@ -279,7 +279,7 @@ class WPILIB_DLLEXPORT PoseEstimator3d { * wpi::Timer::GetMonotonicTimestamp() as your time source in this case. */ void AddVisionMeasurement(const Pose3d& visionRobotPose, - wpi::units::second_t timestamp) { + wpi::units::seconds<> timestamp) { // Step 0: If this measurement is old enough to be outside the pose buffer's // timespan, skip. if (m_odometryPoseBuffer.GetInternalBuffer().empty() || @@ -325,12 +325,12 @@ class WPILIB_DLLEXPORT PoseEstimator3d { // Step 6: Convert back to Transform3d. Transform3d scaledTransform{ - wpi::units::meter_t{k_times_transform(0)}, - wpi::units::meter_t{k_times_transform(1)}, - wpi::units::meter_t{k_times_transform(2)}, - Rotation3d{wpi::units::radian_t{k_times_transform(3)}, - wpi::units::radian_t{k_times_transform(4)}, - wpi::units::radian_t{k_times_transform(5)}}}; + wpi::units::meters<>{k_times_transform(0)}, + wpi::units::meters<>{k_times_transform(1)}, + wpi::units::meters<>{k_times_transform(2)}, + Rotation3d{wpi::units::radians<>{k_times_transform(3)}, + wpi::units::radians<>{k_times_transform(4)}, + wpi::units::radians<>{k_times_transform(5)}}}; // Step 7: Calculate and record the vision update. VisionUpdate visionUpdate{*visionSample + scaledTransform, *odometrySample}; @@ -373,7 +373,7 @@ class WPILIB_DLLEXPORT PoseEstimator3d { * less. */ void AddVisionMeasurement( - const Pose3d& visionRobotPose, wpi::units::second_t timestamp, + const Pose3d& visionRobotPose, wpi::units::seconds<> timestamp, const wpi::util::array& visionMeasurementStdDevs) { SetVisionMeasurementStdDevs(visionMeasurementStdDevs); AddVisionMeasurement(visionRobotPose, timestamp); @@ -406,7 +406,7 @@ class WPILIB_DLLEXPORT PoseEstimator3d { * * @return The estimated pose of the robot in meters. */ - Pose3d UpdateWithTime(wpi::units::second_t currentTime, + Pose3d UpdateWithTime(wpi::units::seconds<> currentTime, const Rotation3d& gyroAngle, const WheelPositions& wheelPositions) { auto odometryEstimate = m_odometry.Update(gyroAngle, wheelPositions); @@ -434,7 +434,7 @@ class WPILIB_DLLEXPORT PoseEstimator3d { } // Step 1: Find the oldest timestamp that needs a vision update. - wpi::units::second_t oldestOdometryTimestamp = + wpi::units::seconds<> oldestOdometryTimestamp = m_odometryPoseBuffer.GetInternalBuffer().front().first; // Step 2: If there are no vision updates before that timestamp, skip. @@ -477,7 +477,7 @@ class WPILIB_DLLEXPORT PoseEstimator3d { } }; - static constexpr wpi::units::second_t BUFFER_DURATION = 1.5_s; + static constexpr wpi::units::seconds<> BUFFER_DURATION = 1.5_s; Odometry3d& m_odometry; @@ -496,7 +496,7 @@ class WPILIB_DLLEXPORT PoseEstimator3d { // unless there have been no vision measurements after the last reset. May // contain one entry while m_odometryPoseBuffer is empty to correct for // translation/rotation after a call to ResetRotation/ResetTranslation. - std::map m_visionUpdates; + std::map, VisionUpdate> m_visionUpdates; Pose3d m_poseEstimate; }; diff --git a/wpimath/src/main/native/include/wpi/math/estimator/SteadyStateKalmanFilter.hpp b/wpimath/src/main/native/include/wpi/math/estimator/SteadyStateKalmanFilter.hpp index 1f5527e946d..1f1861a74e3 100644 --- a/wpimath/src/main/native/include/wpi/math/estimator/SteadyStateKalmanFilter.hpp +++ b/wpimath/src/main/native/include/wpi/math/estimator/SteadyStateKalmanFilter.hpp @@ -74,7 +74,7 @@ class SteadyStateKalmanFilter { SteadyStateKalmanFilter(LinearSystem& plant, const StateArray& stateStdDevs, const OutputArray& measurementStdDevs, - wpi::units::second_t dt) { + wpi::units::seconds<> dt) { m_plant = &plant; auto contQ = CovarianceMatrix(stateStdDevs); @@ -197,7 +197,7 @@ class SteadyStateKalmanFilter { * @param u New control input from controller. * @param dt Timestep for prediction. */ - void Predict(const InputVector& u, wpi::units::second_t dt) { + void Predict(const InputVector& u, wpi::units::seconds<> dt) { m_xHat = m_plant->CalculateX(m_xHat, u, dt); } diff --git a/wpimath/src/main/native/include/wpi/math/estimator/UnscentedKalmanFilter.hpp b/wpimath/src/main/native/include/wpi/math/estimator/UnscentedKalmanFilter.hpp index d9053398fa0..9922837686e 100644 --- a/wpimath/src/main/native/include/wpi/math/estimator/UnscentedKalmanFilter.hpp +++ b/wpimath/src/main/native/include/wpi/math/estimator/UnscentedKalmanFilter.hpp @@ -93,7 +93,7 @@ class UnscentedKalmanFilter { std::function f, std::function h, const StateArray& stateStdDevs, const OutputArray& measurementStdDevs, - wpi::units::second_t dt) + wpi::units::seconds<> dt) : m_f(std::move(f)), m_h(std::move(h)) { m_contQ = CovarianceMatrix(stateStdDevs); m_contR = CovarianceMatrix(measurementStdDevs); @@ -164,7 +164,7 @@ class UnscentedKalmanFilter { residualFuncY, std::function addFuncX, - wpi::units::second_t dt) + wpi::units::seconds<> dt) : m_f(std::move(f)), m_h(std::move(h)), m_meanFuncX(std::move(meanFuncX)), @@ -255,7 +255,7 @@ class UnscentedKalmanFilter { * @param u New control input from controller. * @param dt Timestep for prediction. */ - void Predict(const InputVector& u, wpi::units::second_t dt) { + void Predict(const InputVector& u, wpi::units::seconds<> dt) { m_dt = dt; // Discretize Q before projecting mean and covariance forward @@ -494,7 +494,7 @@ class UnscentedKalmanFilter { StateMatrix m_contQ; Matrixd m_contR; Matrixd m_sigmasF; - wpi::units::second_t m_dt; + wpi::units::seconds<> m_dt; SigmaPoints m_pts; }; diff --git a/wpimath/src/main/native/include/wpi/math/filter/BiquadFilter.hpp b/wpimath/src/main/native/include/wpi/math/filter/BiquadFilter.hpp index 21ef14e447c..cbbc84e5885 100644 --- a/wpimath/src/main/native/include/wpi/math/filter/BiquadFilter.hpp +++ b/wpimath/src/main/native/include/wpi/math/filter/BiquadFilter.hpp @@ -212,8 +212,8 @@ class WPILIB_DLLEXPORT BiquadFilter { * is BandPass / BandStop. */ static BiquadFilter Butterworth(Kind kind, int order, - wpi::units::hertz_t sampleRate, - wpi::units::hertz_t cutoff); + wpi::units::hertz<> sampleRate, + wpi::units::hertz<> cutoff); /** * Designs a Butterworth IIR band-pass or band-stop filter as a cascade of @@ -233,9 +233,9 @@ class WPILIB_DLLEXPORT BiquadFilter { * is LowPass / HighPass. */ static BiquadFilter Butterworth(Kind kind, int order, - wpi::units::hertz_t sampleRate, - wpi::units::hertz_t lowCutoff, - wpi::units::hertz_t highCutoff); + wpi::units::hertz<> sampleRate, + wpi::units::hertz<> lowCutoff, + wpi::units::hertz<> highCutoff); /** * Designs a Chebyshev type-I IIR filter as a cascade of biquad sections. @@ -254,9 +254,9 @@ class WPILIB_DLLEXPORT BiquadFilter { * is LowPass / HighPass. */ static BiquadFilter ChebyshevI(Kind kind, int order, - wpi::units::hertz_t sampleRate, - wpi::units::hertz_t lowCutoff, - wpi::units::hertz_t highCutoff, + wpi::units::hertz<> sampleRate, + wpi::units::hertz<> lowCutoff, + wpi::units::hertz<> highCutoff, double rippleDb); /** @@ -274,8 +274,8 @@ class WPILIB_DLLEXPORT BiquadFilter { * is BandPass / BandStop. */ static BiquadFilter ChebyshevI(Kind kind, int order, - wpi::units::hertz_t sampleRate, - wpi::units::hertz_t cutoff, double rippleDb); + wpi::units::hertz<> sampleRate, + wpi::units::hertz<> cutoff, double rippleDb); /** * Designs a Chebyshev type-II (inverse Chebyshev) IIR filter as a cascade of @@ -295,9 +295,9 @@ class WPILIB_DLLEXPORT BiquadFilter { * is LowPass / HighPass. */ static BiquadFilter ChebyshevII(Kind kind, int order, - wpi::units::hertz_t sampleRate, - wpi::units::hertz_t lowCutoff, - wpi::units::hertz_t highCutoff, + wpi::units::hertz<> sampleRate, + wpi::units::hertz<> lowCutoff, + wpi::units::hertz<> highCutoff, double stopAttenDb); /** @@ -315,8 +315,8 @@ class WPILIB_DLLEXPORT BiquadFilter { * is BandPass / BandStop. */ static BiquadFilter ChebyshevII(Kind kind, int order, - wpi::units::hertz_t sampleRate, - wpi::units::hertz_t cutoff, + wpi::units::hertz<> sampleRate, + wpi::units::hertz<> cutoff, double stopAttenDb); /** @@ -337,9 +337,9 @@ class WPILIB_DLLEXPORT BiquadFilter { * is LowPass / HighPass. */ static BiquadFilter Elliptic(Kind kind, int order, - wpi::units::hertz_t sampleRate, - wpi::units::hertz_t lowCutoff, - wpi::units::hertz_t highCutoff, double rippleDb, + wpi::units::hertz<> sampleRate, + wpi::units::hertz<> lowCutoff, + wpi::units::hertz<> highCutoff, double rippleDb, double stopAttenDb); /** @@ -358,8 +358,8 @@ class WPILIB_DLLEXPORT BiquadFilter { * is BandPass / BandStop. */ static BiquadFilter Elliptic(Kind kind, int order, - wpi::units::hertz_t sampleRate, - wpi::units::hertz_t cutoff, double rippleDb, + wpi::units::hertz<> sampleRate, + wpi::units::hertz<> cutoff, double rippleDb, double stopAttenDb); /** @@ -373,8 +373,8 @@ class WPILIB_DLLEXPORT BiquadFilter { * notch. Must be positive. * @throws std::invalid_argument if any argument is out of range. */ - static BiquadFilter Notch(wpi::units::hertz_t sampleRate, - wpi::units::hertz_t centerFrequency, + static BiquadFilter Notch(wpi::units::hertz<> sampleRate, + wpi::units::hertz<> centerFrequency, double qualityFactor); /** diff --git a/wpimath/src/main/native/include/wpi/math/filter/Debouncer.hpp b/wpimath/src/main/native/include/wpi/math/filter/Debouncer.hpp index 0295f02157d..f146e72eb9e 100644 --- a/wpimath/src/main/native/include/wpi/math/filter/Debouncer.hpp +++ b/wpimath/src/main/native/include/wpi/math/filter/Debouncer.hpp @@ -35,7 +35,7 @@ class WPILIB_DLLEXPORT Debouncer { * @param type Which type of state change the debouncing will be * performed on. */ - explicit Debouncer(wpi::units::second_t debounceTime, + explicit Debouncer(wpi::units::seconds<> debounceTime, DebounceType type = DebounceType::RISING); /** @@ -52,7 +52,7 @@ class WPILIB_DLLEXPORT Debouncer { * @param time The number of seconds the value must change from baseline * for the filtered value to change. */ - constexpr void SetDebounceTime(wpi::units::second_t time) { + constexpr void SetDebounceTime(wpi::units::seconds<> time) { m_debounceTime = time; } @@ -62,7 +62,7 @@ class WPILIB_DLLEXPORT Debouncer { * @return The number of seconds the value must change from baseline * for the filtered value to change. */ - constexpr wpi::units::second_t GetDebounceTime() const { + constexpr wpi::units::seconds<> GetDebounceTime() const { return m_debounceTime; } @@ -85,11 +85,11 @@ class WPILIB_DLLEXPORT Debouncer { constexpr DebounceType GetDebounceType() const { return m_debounceType; } private: - wpi::units::second_t m_debounceTime; + wpi::units::seconds<> m_debounceTime; bool m_baseline; DebounceType m_debounceType; - wpi::units::second_t m_prevTime; + wpi::units::seconds<> m_prevTime; void ResetTimer(); diff --git a/wpimath/src/main/native/include/wpi/math/filter/EdgeCounterFilter.hpp b/wpimath/src/main/native/include/wpi/math/filter/EdgeCounterFilter.hpp index ce4dbed6b39..8489fdd981e 100644 --- a/wpimath/src/main/native/include/wpi/math/filter/EdgeCounterFilter.hpp +++ b/wpimath/src/main/native/include/wpi/math/filter/EdgeCounterFilter.hpp @@ -32,7 +32,7 @@ class WPILIB_DLLEXPORT EdgeCounterFilter { * occur after the first rising edge. */ explicit EdgeCounterFilter(int requiredEdges, - wpi::units::second_t windowTime); + wpi::units::seconds<> windowTime); /** * Applies the edge counter filter to the input stream. @@ -49,7 +49,7 @@ class WPILIB_DLLEXPORT EdgeCounterFilter { * @param windowTime The maximum time window in which all required edges must * occur after the first rising edge. */ - constexpr void SetWindowTime(wpi::units::second_t windowTime) { + constexpr void SetWindowTime(wpi::units::seconds<> windowTime) { m_windowTime = windowTime; } @@ -59,7 +59,7 @@ class WPILIB_DLLEXPORT EdgeCounterFilter { * @return The maximum time window in which all required edges must occur * after the first rising edge. */ - constexpr wpi::units::second_t GetWindowTime() const { return m_windowTime; } + constexpr wpi::units::seconds<> GetWindowTime() const { return m_windowTime; } /** * Sets the required number of edges. @@ -80,9 +80,9 @@ class WPILIB_DLLEXPORT EdgeCounterFilter { private: int m_requiredEdges; - wpi::units::second_t m_windowTime; + wpi::units::seconds<> m_windowTime; - wpi::units::second_t m_firstEdgeTime; + wpi::units::seconds<> m_firstEdgeTime; int m_currentCount = 0; bool m_lastInput = false; diff --git a/wpimath/src/main/native/include/wpi/math/filter/LinearFilter.hpp b/wpimath/src/main/native/include/wpi/math/filter/LinearFilter.hpp index d276f982858..5d1650b5830 100644 --- a/wpimath/src/main/native/include/wpi/math/filter/LinearFilter.hpp +++ b/wpimath/src/main/native/include/wpi/math/filter/LinearFilter.hpp @@ -134,7 +134,7 @@ class LinearFilter { * user. */ static constexpr LinearFilter SinglePoleIIR(double timeConstant, - wpi::units::second_t period) { + wpi::units::seconds<> period) { double gain = gcem::exp(-period.value() / timeConstant); return LinearFilter({1.0 - gain}, {-gain}); } @@ -154,7 +154,7 @@ class LinearFilter { * user. */ static constexpr LinearFilter HighPass(double timeConstant, - wpi::units::second_t period) { + wpi::units::seconds<> period) { double gain = gcem::exp(-period.value() / timeConstant); return LinearFilter({gain, -gain}, {-gain}); } @@ -198,7 +198,7 @@ class LinearFilter { template static LinearFilter FiniteDifference( const wpi::util::array& stencil, - wpi::units::second_t period) { + wpi::units::seconds<> period) { // See // https://en.wikipedia.org/wiki/Finite_difference_coefficient#Arbitrary_stencil_points // @@ -264,7 +264,8 @@ class LinearFilter { * @param period The period in seconds between samples taken by the user. */ template - static LinearFilter BackwardFiniteDifference(wpi::units::second_t period) { + static LinearFilter BackwardFiniteDifference( + wpi::units::seconds<> period) { // Generate stencil points from -(samples - 1) to 0 wpi::util::array stencil{wpi::util::empty_array}; for (int i = 0; i < Samples; ++i) { diff --git a/wpimath/src/main/native/include/wpi/math/filter/SlewRateLimiter.hpp b/wpimath/src/main/native/include/wpi/math/filter/SlewRateLimiter.hpp index bf7dc973181..a12a207c342 100644 --- a/wpimath/src/main/native/include/wpi/math/filter/SlewRateLimiter.hpp +++ b/wpimath/src/main/native/include/wpi/math/filter/SlewRateLimiter.hpp @@ -7,7 +7,7 @@ #include #include "wpi/math/util/MathShared.hpp" -#include "wpi/units/base.hpp" +#include "wpi/units/core.hpp" #include "wpi/units/time.hpp" namespace wpi::math { @@ -23,10 +23,10 @@ namespace wpi::math { template class SlewRateLimiter { public: - using Unit_t = wpi::units::unit_t; - using Rate = - wpi::units::compound_unit>; - using Rate_t = wpi::units::unit_t; + using Unit_t = wpi::units::unit; + using Rate = wpi::units::compound_conversion_factor< + Unit, wpi::units::inverse>; + using Rate_t = wpi::units::unit; /** * Creates a new SlewRateLimiter with the given positive and negative rate @@ -64,12 +64,12 @@ class SlewRateLimiter { * rate. */ Unit_t Calculate(Unit_t input) { - wpi::units::second_t currentTime = + wpi::units::seconds<> currentTime = wpi::math::MathSharedStore::GetTimestamp(); - wpi::units::second_t elapsedTime = currentTime - m_prevTime; + wpi::units::seconds<> elapsedTime = currentTime - m_prevTime; m_prevVal += - std::clamp(input - m_prevVal, m_negativeRateLimit * elapsedTime, - m_positiveRateLimit * elapsedTime); + std::clamp(input - m_prevVal, m_negativeRateLimit * elapsedTime, + m_positiveRateLimit * elapsedTime); m_prevTime = currentTime; return m_prevVal; } @@ -122,6 +122,6 @@ class SlewRateLimiter { Rate_t m_positiveRateLimit; Rate_t m_negativeRateLimit; Unit_t m_prevVal; - wpi::units::second_t m_prevTime; + wpi::units::seconds<> m_prevTime; }; } // namespace wpi::math diff --git a/wpimath/src/main/native/include/wpi/math/geometry/Pose2d.hpp b/wpimath/src/main/native/include/wpi/math/geometry/Pose2d.hpp index d87d9863a91..c4fa2c2c09c 100644 --- a/wpimath/src/main/native/include/wpi/math/geometry/Pose2d.hpp +++ b/wpimath/src/main/native/include/wpi/math/geometry/Pose2d.hpp @@ -54,7 +54,7 @@ class WPILIB_DLLEXPORT Pose2d final { * @param y The y component of the translational component of the pose. * @param rotation The rotational component of the pose. */ - constexpr Pose2d(wpi::units::meter_t x, wpi::units::meter_t y, + constexpr Pose2d(wpi::units::meters<> x, wpi::units::meters<> y, Rotation2d rotation) : m_translation{x, y}, m_rotation{std::move(rotation)} {} @@ -116,14 +116,14 @@ class WPILIB_DLLEXPORT Pose2d final { * * @return The x component of the pose's translation. */ - constexpr wpi::units::meter_t X() const { return m_translation.X(); } + constexpr wpi::units::meters<> X() const { return m_translation.X(); } /** * Returns the Y component of the pose's translation. * * @return The y component of the pose's translation. */ - constexpr wpi::units::meter_t Y() const { return m_translation.Y(); } + constexpr wpi::units::meters<> Y() const { return m_translation.Y(); } /** * Returns the underlying rotation. diff --git a/wpimath/src/main/native/include/wpi/math/geometry/Pose3d.hpp b/wpimath/src/main/native/include/wpi/math/geometry/Pose3d.hpp index c1ed8eb018c..b070d76472d 100644 --- a/wpimath/src/main/native/include/wpi/math/geometry/Pose3d.hpp +++ b/wpimath/src/main/native/include/wpi/math/geometry/Pose3d.hpp @@ -57,8 +57,8 @@ class WPILIB_DLLEXPORT Pose3d final { * @param z The z component of the translational component of the pose. * @param rotation The rotational component of the pose. */ - constexpr Pose3d(wpi::units::meter_t x, wpi::units::meter_t y, - wpi::units::meter_t z, Rotation3d rotation) + constexpr Pose3d(wpi::units::meters<> x, wpi::units::meters<> y, + wpi::units::meters<> z, Rotation3d rotation) : m_translation{x, y, z}, m_rotation{std::move(rotation)} {} /** @@ -130,21 +130,21 @@ class WPILIB_DLLEXPORT Pose3d final { * * @return The x component of the pose's translation. */ - constexpr wpi::units::meter_t X() const { return m_translation.X(); } + constexpr wpi::units::meters<> X() const { return m_translation.X(); } /** * Returns the Y component of the pose's translation. * * @return The y component of the pose's translation. */ - constexpr wpi::units::meter_t Y() const { return m_translation.Y(); } + constexpr wpi::units::meters<> Y() const { return m_translation.Y(); } /** * Returns the Z component of the pose's translation. * * @return The z component of the pose's translation. */ - constexpr wpi::units::meter_t Z() const { return m_translation.Z(); } + constexpr wpi::units::meters<> Z() const { return m_translation.Z(); } /** * Returns the underlying rotation. diff --git a/wpimath/src/main/native/include/wpi/math/geometry/Rotation2d.hpp b/wpimath/src/main/native/include/wpi/math/geometry/Rotation2d.hpp index 52ed0447ddf..32fff423ab2 100644 --- a/wpimath/src/main/native/include/wpi/math/geometry/Rotation2d.hpp +++ b/wpimath/src/main/native/include/wpi/math/geometry/Rotation2d.hpp @@ -38,10 +38,9 @@ class WPILIB_DLLEXPORT Rotation2d final { * * @param value The value of the angle. */ - constexpr Rotation2d(wpi::units::angle_unit auto value) // NOLINT - : m_cos{gcem::cos(value.template convert().value())}, - m_sin{gcem::sin(value.template convert().value())} { - } + constexpr Rotation2d(wpi::units::Angle auto value) // NOLINT + : m_cos{gcem::cos(wpi::units::radians<>(value).value())}, + m_sin{gcem::sin(wpi::units::radians<>(value).value())} {} /** * Constructs a Rotation2d with the given x and y (cosine and sine) @@ -110,7 +109,7 @@ class WPILIB_DLLEXPORT Rotation2d final { * π. * * For example, Rotation2d{30_deg} + Rotation2d{60_deg} equals - * Rotation2d{wpi::units::radian_t{std::numbers::pi/2.0}} + * Rotation2d{wpi::units::radians<>{std::numbers::pi/2.0}} * * @param other The rotation to add. * @@ -124,7 +123,7 @@ class WPILIB_DLLEXPORT Rotation2d final { * Returns this rotation relative to another rotation. * * For example, Rotation2d{10_deg} - Rotation2d{100_deg} equals - * Rotation2d{wpi::units::radian_t{-std::numbers::pi/2.0}} + * Rotation2d{wpi::units::radians<>{-std::numbers::pi/2.0}} * * @param other The rotation to subtract. * @@ -219,8 +218,8 @@ class WPILIB_DLLEXPORT Rotation2d final { * * @return The radian value of the rotation constrained within [-π, π]. */ - constexpr wpi::units::radian_t Radians() const { - return wpi::units::radian_t{gcem::atan2(m_sin, m_cos)}; + constexpr wpi::units::radians<> Radians() const { + return wpi::units::radians<>{gcem::atan2(m_sin, m_cos)}; } /** @@ -228,7 +227,7 @@ class WPILIB_DLLEXPORT Rotation2d final { * * @return The degree value of the rotation constrained within [-180, 180]. */ - constexpr wpi::units::degree_t Degrees() const { return Radians(); } + constexpr wpi::units::degrees<> Degrees() const { return Radians(); } /** * Returns the cosine of the rotation. diff --git a/wpimath/src/main/native/include/wpi/math/geometry/Rotation3d.hpp b/wpimath/src/main/native/include/wpi/math/geometry/Rotation3d.hpp index 1cb2e616320..dea015c5655 100644 --- a/wpimath/src/main/native/include/wpi/math/geometry/Rotation3d.hpp +++ b/wpimath/src/main/native/include/wpi/math/geometry/Rotation3d.hpp @@ -15,7 +15,6 @@ #include "wpi/math/linalg/ct_matrix.hpp" #include "wpi/units/angle.hpp" #include "wpi/units/angular_velocity.hpp" -#include "wpi/units/math.hpp" #include "wpi/units/time.hpp" #include "wpi/util/MathExtras.hpp" #include "wpi/util/SymbolExports.hpp" @@ -99,17 +98,17 @@ class WPILIB_DLLEXPORT Rotation3d final { * @param pitch The counterclockwise rotation angle around the Y axis (pitch). * @param yaw The counterclockwise rotation angle around the Z axis (yaw). */ - constexpr Rotation3d(wpi::units::radian_t roll, wpi::units::radian_t pitch, - wpi::units::radian_t yaw) { + constexpr Rotation3d(wpi::units::radians<> roll, wpi::units::radians<> pitch, + wpi::units::radians<> yaw) { // https://en.wikipedia.org/wiki/Conversion_between_quaternions_and_Euler_angles#Euler_angles_to_quaternion_conversion - double cr = wpi::units::math::cos(roll * 0.5); - double sr = wpi::units::math::sin(roll * 0.5); + double cr = wpi::units::cos(roll * 0.5); + double sr = wpi::units::sin(roll * 0.5); - double cp = wpi::units::math::cos(pitch * 0.5); - double sp = wpi::units::math::sin(pitch * 0.5); + double cp = wpi::units::cos(pitch * 0.5); + double sp = wpi::units::sin(pitch * 0.5); - double cy = wpi::units::math::cos(yaw * 0.5); - double sy = wpi::units::math::sin(yaw * 0.5); + double cy = wpi::units::cos(yaw * 0.5); + double sy = wpi::units::sin(yaw * 0.5); m_q = Quaternion{cr * cp * cy + sr * sp * sy, sr * cp * cy - cr * sp * sy, cr * sp * cy + sr * cp * sy, cr * cp * sy - sr * sp * cy}; @@ -123,17 +122,17 @@ class WPILIB_DLLEXPORT Rotation3d final { * @param angle The rotation around the axis. */ constexpr Rotation3d(const Eigen::Vector3d& axis, - wpi::units::radian_t angle) { + wpi::units::radians<> angle) { double norm = ct_matrix{axis}.norm(); if (norm == 0.0) { return; } // https://en.wikipedia.org/wiki/Conversion_between_quaternions_and_Euler_angles#Definition - Eigen::Vector3d v{{axis(0) / norm * wpi::units::math::sin(angle / 2.0), - axis(1) / norm * wpi::units::math::sin(angle / 2.0), - axis(2) / norm * wpi::units::math::sin(angle / 2.0)}}; - m_q = Quaternion{wpi::units::math::cos(angle / 2.0), v(0), v(1), v(2)}; + Eigen::Vector3d v{{axis(0) / norm * wpi::units::sin(angle / 2.0), + axis(1) / norm * wpi::units::sin(angle / 2.0), + axis(2) / norm * wpi::units::sin(angle / 2.0)}}; + m_q = Quaternion{wpi::units::cos(angle / 2.0), v(0), v(1), v(2)}; } /** @@ -144,7 +143,7 @@ class WPILIB_DLLEXPORT Rotation3d final { * @param rvec The rotation vector. */ constexpr explicit Rotation3d(const Eigen::Vector3d& rvec) - : Rotation3d{rvec, wpi::units::radian_t{ct_matrix{rvec}.norm()}} {} + : Rotation3d{rvec, wpi::units::radians<>{ct_matrix{rvec}.norm()}} {} /** * Constructs a Rotation3d from a rotation matrix. @@ -394,10 +393,10 @@ class WPILIB_DLLEXPORT Rotation3d final { * @param dt The time over which to integrate. * @return The rotation in the world frame projected forward. */ - constexpr Rotation3d Integrate(units::radians_per_second_t rollRate, - units::radians_per_second_t pitchRate, - units::radians_per_second_t yawRate, - units::second_t dt) const { + constexpr Rotation3d Integrate(units::radians_per_second<> rollRate, + units::radians_per_second<> pitchRate, + units::radians_per_second<> yawRate, + units::seconds<> dt) const { // qₖ₊₁ = qₖ exp(1/2 W dt) where W = 0 + ω_x î + ω_y ĵ + ω_z k̂ // // https://math.stackexchange.com/a/2099673 @@ -413,7 +412,7 @@ class WPILIB_DLLEXPORT Rotation3d final { /** * Returns the counterclockwise rotation angle around the X axis (roll). */ - constexpr wpi::units::radian_t X() const { + constexpr wpi::units::radians<> X() const { double w = m_q.W(); double x = m_q.X(); double y = m_q.Y(); @@ -424,7 +423,7 @@ class WPILIB_DLLEXPORT Rotation3d final { double sxcy = 2.0 * (w * x + y * z); double cy_sq = cxcy * cxcy + sxcy * sxcy; if (cy_sq > 1e-20) { - return wpi::units::radian_t{gcem::atan2(sxcy, cxcy)}; + return wpi::units::radians<>{gcem::atan2(sxcy, cxcy)}; } else { return 0_rad; } @@ -433,7 +432,7 @@ class WPILIB_DLLEXPORT Rotation3d final { /** * Returns the counterclockwise rotation angle around the Y axis (pitch). */ - constexpr wpi::units::radian_t Y() const { + constexpr wpi::units::radians<> Y() const { double w = m_q.W(); double x = m_q.X(); double y = m_q.Y(); @@ -442,17 +441,17 @@ class WPILIB_DLLEXPORT Rotation3d final { // https://en.wikipedia.org/wiki/Conversion_between_quaternions_and_Euler_angles#Quaternion_to_Euler_angles_(in_3-2-1_sequence)_conversion double ratio = 2.0 * (w * y - z * x); if (gcem::abs(ratio) >= 1.0) { - return wpi::units::radian_t{ + return wpi::units::radians<>{ gcem::copysign(std::numbers::pi / 2.0, ratio)}; } else { - return wpi::units::radian_t{gcem::asin(ratio)}; + return wpi::units::radians<>{gcem::asin(ratio)}; } } /** * Returns the counterclockwise rotation angle around the Z axis (yaw). */ - constexpr wpi::units::radian_t Z() const { + constexpr wpi::units::radians<> Z() const { double w = m_q.W(); double x = m_q.X(); double y = m_q.Y(); @@ -463,9 +462,9 @@ class WPILIB_DLLEXPORT Rotation3d final { double cysz = 2.0 * (w * z + x * y); double cy_sq = cycz * cycz + cysz * cysz; if (cy_sq > 1e-20) { - return wpi::units::radian_t{gcem::atan2(cysz, cycz)}; + return wpi::units::radians<>{gcem::atan2(cysz, cycz)}; } else { - return wpi::units::radian_t{gcem::atan2(2.0 * w * z, w * w - z * z)}; + return wpi::units::radians<>{gcem::atan2(2.0 * w * z, w * w - z * z)}; } } @@ -484,9 +483,9 @@ class WPILIB_DLLEXPORT Rotation3d final { /** * Returns the angle in the axis-angle representation of this rotation. */ - constexpr wpi::units::radian_t Angle() const { + constexpr wpi::units::radians<> Angle() const { double norm = gcem::hypot(m_q.X(), m_q.Y(), m_q.Z()); - return wpi::units::radian_t{2.0 * gcem::atan2(norm, m_q.W())}; + return wpi::units::radians<>{2.0 * gcem::atan2(norm, m_q.W())}; } /** diff --git a/wpimath/src/main/native/include/wpi/math/geometry/Transform2d.hpp b/wpimath/src/main/native/include/wpi/math/geometry/Transform2d.hpp index 9865d5c5bad..75ad1e009c1 100644 --- a/wpimath/src/main/native/include/wpi/math/geometry/Transform2d.hpp +++ b/wpimath/src/main/native/include/wpi/math/geometry/Transform2d.hpp @@ -56,7 +56,7 @@ class WPILIB_DLLEXPORT Transform2d final { * @param y The y component of the translational component of the transform. * @param rotation The rotational component of the transform. */ - constexpr Transform2d(wpi::units::meter_t x, wpi::units::meter_t y, + constexpr Transform2d(wpi::units::meters<> x, wpi::units::meters<> y, Rotation2d rotation) : m_translation{x, y}, m_rotation{std::move(rotation)} {} @@ -92,14 +92,14 @@ class WPILIB_DLLEXPORT Transform2d final { * * @return The x component of the transformation's translation. */ - constexpr wpi::units::meter_t X() const { return m_translation.X(); } + constexpr wpi::units::meters<> X() const { return m_translation.X(); } /** * Returns the Y component of the transformation's translation. * * @return The y component of the transformation's translation. */ - constexpr wpi::units::meter_t Y() const { return m_translation.Y(); } + constexpr wpi::units::meters<> Y() const { return m_translation.Y(); } /** * Returns an affine transformation matrix representation of this @@ -218,7 +218,7 @@ constexpr Twist2d Transform2d::Log() const { gcem::hypot(halfThetaByTanOfHalfDtheta, halfDtheta); return {translationPart.X(), translationPart.Y(), - wpi::units::radian_t{dtheta}}; + wpi::units::radians<>{dtheta}}; } } // namespace wpi::math diff --git a/wpimath/src/main/native/include/wpi/math/geometry/Transform3d.hpp b/wpimath/src/main/native/include/wpi/math/geometry/Transform3d.hpp index 66be5c49ebd..90087ce8ad6 100644 --- a/wpimath/src/main/native/include/wpi/math/geometry/Transform3d.hpp +++ b/wpimath/src/main/native/include/wpi/math/geometry/Transform3d.hpp @@ -61,8 +61,8 @@ class WPILIB_DLLEXPORT Transform3d final { * @param z The z component of the translational component of the transform. * @param rotation The rotational component of the transform. */ - constexpr Transform3d(wpi::units::meter_t x, wpi::units::meter_t y, - wpi::units::meter_t z, Rotation3d rotation) + constexpr Transform3d(wpi::units::meters<> x, wpi::units::meters<> y, + wpi::units::meters<> z, Rotation3d rotation) : m_translation{x, y, z}, m_rotation{std::move(rotation)} {} /** @@ -112,21 +112,21 @@ class WPILIB_DLLEXPORT Transform3d final { * * @return The x component of the transformation's translation. */ - constexpr wpi::units::meter_t X() const { return m_translation.X(); } + constexpr wpi::units::meters<> X() const { return m_translation.X(); } /** * Returns the Y component of the transformation's translation. * * @return The y component of the transformation's translation. */ - constexpr wpi::units::meter_t Y() const { return m_translation.Y(); } + constexpr wpi::units::meters<> Y() const { return m_translation.Y(); } /** * Returns the Z component of the transformation's translation. * * @return The z component of the transformation's translation. */ - constexpr wpi::units::meter_t Z() const { return m_translation.Z(); } + constexpr wpi::units::meters<> Z() const { return m_translation.Z(); } /** * Returns an affine transformation matrix representation of this @@ -268,12 +268,12 @@ constexpr Twist3d Transform3d::Log() const { Vector3d translation_component = V_inv * u; - return Twist3d{wpi::units::meter_t{translation_component(0)}, - wpi::units::meter_t{translation_component(1)}, - wpi::units::meter_t{translation_component(2)}, - wpi::units::radian_t{rvec(0)}, - wpi::units::radian_t{rvec(1)}, - wpi::units::radian_t{rvec(2)}}; + return Twist3d{wpi::units::meters<>{translation_component(0)}, + wpi::units::meters<>{translation_component(1)}, + wpi::units::meters<>{translation_component(2)}, + wpi::units::radians<>{rvec(0)}, + wpi::units::radians<>{rvec(1)}, + wpi::units::radians<>{rvec(2)}}; }; if consteval { diff --git a/wpimath/src/main/native/include/wpi/math/geometry/Translation2d.hpp b/wpimath/src/main/native/include/wpi/math/geometry/Translation2d.hpp index f410351a478..0f6ec85be93 100644 --- a/wpimath/src/main/native/include/wpi/math/geometry/Translation2d.hpp +++ b/wpimath/src/main/native/include/wpi/math/geometry/Translation2d.hpp @@ -13,9 +13,8 @@ #include "wpi/math/geometry/Rotation2d.hpp" #include "wpi/units/area.hpp" -#include "wpi/units/base.hpp" +#include "wpi/units/core.hpp" #include "wpi/units/length.hpp" -#include "wpi/units/math.hpp" #include "wpi/util/SymbolExports.hpp" namespace wpi::util { @@ -46,7 +45,7 @@ class WPILIB_DLLEXPORT Translation2d final { * @param x The x component of the translation. * @param y The y component of the translation. */ - constexpr Translation2d(wpi::units::meter_t x, wpi::units::meter_t y) + constexpr Translation2d(wpi::units::meters<> x, wpi::units::meters<> y) : m_x{x}, m_y{y} {} /** @@ -56,7 +55,8 @@ class WPILIB_DLLEXPORT Translation2d final { * @param distance The distance from the origin to the end of the translation. * @param angle The angle between the x-axis and the translation vector. */ - constexpr Translation2d(wpi::units::meter_t distance, const Rotation2d& angle) + constexpr Translation2d(wpi::units::meters<> distance, + const Rotation2d& angle) : m_x{distance * angle.Cos()}, m_y{distance * angle.Sin()} {} /** @@ -66,8 +66,8 @@ class WPILIB_DLLEXPORT Translation2d final { * @param vector The translation vector. */ constexpr explicit Translation2d(const Eigen::Vector2d& vector) - : m_x{wpi::units::meter_t{vector.x()}}, - m_y{wpi::units::meter_t{vector.y()}} {} + : m_x{wpi::units::meters<>{vector.x()}}, + m_y{wpi::units::meters<>{vector.y()}} {} /** * Calculates the distance between two translations in 2D space. @@ -78,8 +78,8 @@ class WPILIB_DLLEXPORT Translation2d final { * * @return The distance between the two translations. */ - constexpr wpi::units::meter_t Distance(const Translation2d& other) const { - return wpi::units::math::hypot(other.m_x - m_x, other.m_y - m_y); + constexpr wpi::units::meters<> Distance(const Translation2d& other) const { + return wpi::units::hypot(other.m_x - m_x, other.m_y - m_y); } /** @@ -93,10 +93,10 @@ class WPILIB_DLLEXPORT Translation2d final { * @param other The translation to compute the squared distance to. * @return The square of the distance between the two translations. */ - constexpr wpi::units::square_meter_t SquaredDistance( + constexpr wpi::units::square_meters<> SquaredDistance( const Translation2d& other) const { - return wpi::units::math::pow<2>(other.m_x - m_x) + - wpi::units::math::pow<2>(other.m_y - m_y); + return wpi::units::pow<2>(other.m_x - m_x) + + wpi::units::pow<2>(other.m_y - m_y); } /** @@ -104,14 +104,14 @@ class WPILIB_DLLEXPORT Translation2d final { * * @return The X component of the translation. */ - constexpr wpi::units::meter_t X() const { return m_x; } + constexpr wpi::units::meters<> X() const { return m_x; } /** * Returns the Y component of the translation. * * @return The Y component of the translation. */ - constexpr wpi::units::meter_t Y() const { return m_y; } + constexpr wpi::units::meters<> Y() const { return m_y; } /** * Returns a 2D translation vector representation of this translation. @@ -127,8 +127,8 @@ class WPILIB_DLLEXPORT Translation2d final { * * @return The norm of the translation. */ - constexpr wpi::units::meter_t Norm() const { - return wpi::units::math::hypot(m_x, m_y); + constexpr wpi::units::meters<> Norm() const { + return wpi::units::hypot(m_x, m_y); } /** @@ -138,8 +138,8 @@ class WPILIB_DLLEXPORT Translation2d final { * * @return The squared norm of the translation. */ - constexpr wpi::units::square_meter_t SquaredNorm() const { - return wpi::units::math::pow<2>(m_x) + wpi::units::math::pow<2>(m_y); + constexpr wpi::units::square_meters<> SquaredNorm() const { + return wpi::units::pow<2>(m_x) + wpi::units::pow<2>(m_y); } /** @@ -149,7 +149,7 @@ class WPILIB_DLLEXPORT Translation2d final { * undefined. */ constexpr std::optional Angle() const { - if (wpi::units::math::hypot(m_x, m_y) > 1e-6_m) { + if (wpi::units::hypot(m_x, m_y) > 1e-6_m) { return Rotation2d{m_x.value(), m_y.value()}; } else { return {}; @@ -208,7 +208,7 @@ class WPILIB_DLLEXPORT Translation2d final { * @param other The translation to compute the dot product with. * @return The dot product between the two translations. */ - constexpr wpi::units::square_meter_t Dot(const Translation2d& other) const { + constexpr wpi::units::square_meters<> Dot(const Translation2d& other) const { return m_x * other.X() + m_y * other.Y(); } @@ -221,7 +221,8 @@ class WPILIB_DLLEXPORT Translation2d final { * @param other The translation to compute the cross product with. * @return The cross product between the two translations. */ - constexpr wpi::units::square_meter_t Cross(const Translation2d& other) const { + constexpr wpi::units::square_meters<> Cross( + const Translation2d& other) const { return m_x * other.Y() - m_y * other.X(); } @@ -295,8 +296,8 @@ class WPILIB_DLLEXPORT Translation2d final { * @return Whether the two objects are equal. */ constexpr bool operator==(const Translation2d& other) const { - return wpi::units::math::abs(m_x - other.m_x) < 1E-9_m && - wpi::units::math::abs(m_y - other.m_y) < 1E-9_m; + return wpi::units::abs(m_x - other.m_x) < 1E-9_m && + wpi::units::abs(m_y - other.m_y) < 1E-9_m; } /** @@ -328,8 +329,8 @@ class WPILIB_DLLEXPORT Translation2d final { } private: - wpi::units::meter_t m_x = 0_m; - wpi::units::meter_t m_y = 0_m; + wpi::units::meters<> m_x = 0_m; + wpi::units::meters<> m_y = 0_m; }; WPILIB_DLLEXPORT diff --git a/wpimath/src/main/native/include/wpi/math/geometry/Translation3d.hpp b/wpimath/src/main/native/include/wpi/math/geometry/Translation3d.hpp index 4e1f85d7773..71bc1f14788 100644 --- a/wpimath/src/main/native/include/wpi/math/geometry/Translation3d.hpp +++ b/wpimath/src/main/native/include/wpi/math/geometry/Translation3d.hpp @@ -14,9 +14,8 @@ #include "wpi/math/geometry/Rotation3d.hpp" #include "wpi/math/geometry/Translation2d.hpp" #include "wpi/units/area.hpp" -#include "wpi/units/base.hpp" +#include "wpi/units/core.hpp" #include "wpi/units/length.hpp" -#include "wpi/units/math.hpp" #include "wpi/util/SymbolExports.hpp" namespace wpi::util { @@ -48,8 +47,8 @@ class WPILIB_DLLEXPORT Translation3d final { * @param y The y component of the translation. * @param z The z component of the translation. */ - constexpr Translation3d(wpi::units::meter_t x, wpi::units::meter_t y, - wpi::units::meter_t z) + constexpr Translation3d(wpi::units::meters<> x, wpi::units::meters<> y, + wpi::units::meters<> z) : m_x{x}, m_y{y}, m_z{z} {} /** @@ -59,7 +58,7 @@ class WPILIB_DLLEXPORT Translation3d final { * @param distance The distance from the origin to the end of the translation. * @param angle The angle between the x-axis and the translation vector. */ - constexpr Translation3d(wpi::units::meter_t distance, + constexpr Translation3d(wpi::units::meters<> distance, const Rotation3d& angle) { auto rectangular = Translation3d{distance, 0_m, 0_m}.RotateBy(angle); m_x = rectangular.X(); @@ -74,9 +73,9 @@ class WPILIB_DLLEXPORT Translation3d final { * @param vector The translation vector. */ constexpr explicit Translation3d(const Eigen::Vector3d& vector) - : m_x{wpi::units::meter_t{vector.x()}}, - m_y{wpi::units::meter_t{vector.y()}}, - m_z{wpi::units::meter_t{vector.z()}} {} + : m_x{wpi::units::meters<>{vector.x()}}, + m_y{wpi::units::meters<>{vector.y()}}, + m_z{wpi::units::meters<>{vector.z()}} {} /** * Constructs a 3D translation from a 2D translation in the X-Y plane. @@ -98,10 +97,10 @@ class WPILIB_DLLEXPORT Translation3d final { * * @return The distance between the two translations. */ - constexpr wpi::units::meter_t Distance(const Translation3d& other) const { - return wpi::units::math::sqrt(wpi::units::math::pow<2>(other.m_x - m_x) + - wpi::units::math::pow<2>(other.m_y - m_y) + - wpi::units::math::pow<2>(other.m_z - m_z)); + constexpr wpi::units::meters<> Distance(const Translation3d& other) const { + return wpi::units::sqrt(wpi::units::pow<2>(other.m_x - m_x) + + wpi::units::pow<2>(other.m_y - m_y) + + wpi::units::pow<2>(other.m_z - m_z)); } /** @@ -115,11 +114,11 @@ class WPILIB_DLLEXPORT Translation3d final { * @param other The translation to compute the squared distance to. * @return The squared distance between the two translations. */ - constexpr wpi::units::square_meter_t SquaredDistance( + constexpr wpi::units::square_meters<> SquaredDistance( const Translation3d& other) const { - return wpi::units::math::pow<2>(other.m_x - m_x) + - wpi::units::math::pow<2>(other.m_y - m_y) + - wpi::units::math::pow<2>(other.m_z - m_z); + return wpi::units::pow<2>(other.m_x - m_x) + + wpi::units::pow<2>(other.m_y - m_y) + + wpi::units::pow<2>(other.m_z - m_z); } /** @@ -127,21 +126,21 @@ class WPILIB_DLLEXPORT Translation3d final { * * @return The X component of the translation. */ - constexpr wpi::units::meter_t X() const { return m_x; } + constexpr wpi::units::meters<> X() const { return m_x; } /** * Returns the Y component of the translation. * * @return The Y component of the translation. */ - constexpr wpi::units::meter_t Y() const { return m_y; } + constexpr wpi::units::meters<> Y() const { return m_y; } /** * Returns the Z component of the translation. * * @return The Z component of the translation. */ - constexpr wpi::units::meter_t Z() const { return m_z; } + constexpr wpi::units::meters<> Z() const { return m_z; } /** * Returns a 3D translation vector representation of this translation. @@ -157,8 +156,8 @@ class WPILIB_DLLEXPORT Translation3d final { * * @return The norm of the translation. */ - constexpr wpi::units::meter_t Norm() const { - return wpi::units::math::sqrt(m_x * m_x + m_y * m_y + m_z * m_z); + constexpr wpi::units::meters<> Norm() const { + return wpi::units::sqrt(m_x * m_x + m_y * m_y + m_z * m_z); } /** @@ -168,7 +167,7 @@ class WPILIB_DLLEXPORT Translation3d final { * * @return The squared norm of the translation. */ - constexpr wpi::units::square_meter_t SquaredNorm() const { + constexpr wpi::units::square_meters<> SquaredNorm() const { return m_x * m_x + m_y * m_y + m_z * m_z; } @@ -185,9 +184,9 @@ class WPILIB_DLLEXPORT Translation3d final { constexpr Translation3d RotateBy(const Rotation3d& other) const { Quaternion p{0.0, m_x.value(), m_y.value(), m_z.value()}; auto qprime = other.GetQuaternion() * p * other.GetQuaternion().Inverse(); - return Translation3d{wpi::units::meter_t{qprime.X()}, - wpi::units::meter_t{qprime.Y()}, - wpi::units::meter_t{qprime.Z()}}; + return Translation3d{wpi::units::meters<>{qprime.X()}, + wpi::units::meters<>{qprime.Y()}, + wpi::units::meters<>{qprime.Z()}}; } /** @@ -211,7 +210,7 @@ class WPILIB_DLLEXPORT Translation3d final { * @param other The translation to compute the dot product with. * @return The dot product between the two translations. */ - constexpr wpi::units::square_meter_t Dot(const Translation3d& other) const { + constexpr wpi::units::square_meters<> Dot(const Translation3d& other) const { return m_x * other.X() + m_y * other.Y() + m_z * other.Z(); } @@ -226,9 +225,9 @@ class WPILIB_DLLEXPORT Translation3d final { * @param other The translation to compute the cross product with. * @return The cross product between the two translations. */ - constexpr Eigen::Vector Cross( + constexpr Eigen::Vector, 3> Cross( const Translation3d& other) const { - return Eigen::Vector{ + return Eigen::Vector, 3>{ {m_y * other.Z() - other.Y() * m_z}, {m_z * other.X() - other.Z() * m_x}, {m_x * other.Y() - other.X() * m_y}}; @@ -313,9 +312,9 @@ class WPILIB_DLLEXPORT Translation3d final { * @return Whether the two objects are equal. */ constexpr bool operator==(const Translation3d& other) const { - return wpi::units::math::abs(m_x - other.m_x) < 1E-9_m && - wpi::units::math::abs(m_y - other.m_y) < 1E-9_m && - wpi::units::math::abs(m_z - other.m_z) < 1E-9_m; + return wpi::units::abs(m_x - other.m_x) < 1E-9_m && + wpi::units::abs(m_y - other.m_y) < 1E-9_m && + wpi::units::abs(m_z - other.m_z) < 1E-9_m; } /** @@ -347,9 +346,9 @@ class WPILIB_DLLEXPORT Translation3d final { } private: - wpi::units::meter_t m_x = 0_m; - wpi::units::meter_t m_y = 0_m; - wpi::units::meter_t m_z = 0_m; + wpi::units::meters<> m_x = 0_m; + wpi::units::meters<> m_y = 0_m; + wpi::units::meters<> m_z = 0_m; }; WPILIB_DLLEXPORT diff --git a/wpimath/src/main/native/include/wpi/math/geometry/Twist2d.hpp b/wpimath/src/main/native/include/wpi/math/geometry/Twist2d.hpp index 8250b5f86ea..96704fe0c7c 100644 --- a/wpimath/src/main/native/include/wpi/math/geometry/Twist2d.hpp +++ b/wpimath/src/main/native/include/wpi/math/geometry/Twist2d.hpp @@ -10,7 +10,6 @@ #include "wpi/math/geometry/Translation2d.hpp" #include "wpi/units/angle.hpp" #include "wpi/units/length.hpp" -#include "wpi/units/math.hpp" #include "wpi/util/SymbolExports.hpp" namespace wpi::math { @@ -28,17 +27,17 @@ struct WPILIB_DLLEXPORT Twist2d final { /** * Linear "dx" component */ - wpi::units::meter_t dx = 0_m; + wpi::units::meters<> dx = 0_m; /** * Linear "dy" component */ - wpi::units::meter_t dy = 0_m; + wpi::units::meters<> dy = 0_m; /** * Angular "dtheta" component (radians) */ - wpi::units::radian_t dtheta = 0_rad; + wpi::units::radians<> dtheta = 0_rad; /** * Obtain a new Transform2d from a (constant curvature) velocity. @@ -65,9 +64,9 @@ struct WPILIB_DLLEXPORT Twist2d final { * @return Whether the two objects are equal. */ constexpr bool operator==(const Twist2d& other) const { - return wpi::units::math::abs(dx - other.dx) < 1E-9_m && - wpi::units::math::abs(dy - other.dy) < 1E-9_m && - wpi::units::math::abs(dtheta - other.dtheta) < 1E-9_rad; + return wpi::units::abs(dx - other.dx) < 1E-9_m && + wpi::units::abs(dy - other.dy) < 1E-9_m && + wpi::units::abs(dtheta - other.dtheta) < 1E-9_rad; } /** diff --git a/wpimath/src/main/native/include/wpi/math/geometry/Twist3d.hpp b/wpimath/src/main/native/include/wpi/math/geometry/Twist3d.hpp index d37a980ae77..79d69c0b261 100644 --- a/wpimath/src/main/native/include/wpi/math/geometry/Twist3d.hpp +++ b/wpimath/src/main/native/include/wpi/math/geometry/Twist3d.hpp @@ -12,7 +12,6 @@ #include "wpi/math/linalg/ct_matrix.hpp" #include "wpi/units/angle.hpp" #include "wpi/units/length.hpp" -#include "wpi/units/math.hpp" #include "wpi/util/SymbolExports.hpp" namespace wpi::math { @@ -30,32 +29,32 @@ struct WPILIB_DLLEXPORT Twist3d final { /** * Linear "dx" component */ - wpi::units::meter_t dx = 0_m; + wpi::units::meters<> dx = 0_m; /** * Linear "dy" component */ - wpi::units::meter_t dy = 0_m; + wpi::units::meters<> dy = 0_m; /** * Linear "dz" component */ - wpi::units::meter_t dz = 0_m; + wpi::units::meters<> dz = 0_m; /** * Rotation vector x component. */ - wpi::units::radian_t rx = 0_rad; + wpi::units::radians<> rx = 0_rad; /** * Rotation vector y component. */ - wpi::units::radian_t ry = 0_rad; + wpi::units::radians<> ry = 0_rad; /** * Rotation vector z component. */ - wpi::units::radian_t rz = 0_rad; + wpi::units::radians<> rz = 0_rad; /** * Obtain a new Transform3d from a (constant curvature) velocity. @@ -82,12 +81,12 @@ struct WPILIB_DLLEXPORT Twist3d final { * @return Whether the two objects are equal. */ constexpr bool operator==(const Twist3d& other) const { - return wpi::units::math::abs(dx - other.dx) < 1E-9_m && - wpi::units::math::abs(dy - other.dy) < 1E-9_m && - wpi::units::math::abs(dz - other.dz) < 1E-9_m && - wpi::units::math::abs(rx - other.rx) < 1E-9_rad && - wpi::units::math::abs(ry - other.ry) < 1E-9_rad && - wpi::units::math::abs(rz - other.rz) < 1E-9_rad; + return wpi::units::abs(dx - other.dx) < 1E-9_m && + wpi::units::abs(dy - other.dy) < 1E-9_m && + wpi::units::abs(dz - other.dz) < 1E-9_m && + wpi::units::abs(rx - other.rx) < 1E-9_rad && + wpi::units::abs(ry - other.ry) < 1E-9_rad && + wpi::units::abs(rz - other.rz) < 1E-9_rad; } /** @@ -153,9 +152,9 @@ constexpr Transform3d Twist3d::Exp() const { Vector3d translation_component = V * u; const Transform3d transform{ - Translation3d{wpi::units::meter_t{translation_component(0)}, - wpi::units::meter_t{translation_component(1)}, - wpi::units::meter_t{translation_component(2)}}, + Translation3d{wpi::units::meters<>{translation_component(0)}, + wpi::units::meters<>{translation_component(1)}, + wpi::units::meters<>{translation_component(2)}}, Rotation3d{R}}; return transform; diff --git a/wpimath/src/main/native/include/wpi/math/interpolation/TimeInterpolatableBuffer.hpp b/wpimath/src/main/native/include/wpi/math/interpolation/TimeInterpolatableBuffer.hpp index e2bf9fc5b11..a4f0b365b0f 100644 --- a/wpimath/src/main/native/include/wpi/math/interpolation/TimeInterpolatableBuffer.hpp +++ b/wpimath/src/main/native/include/wpi/math/interpolation/TimeInterpolatableBuffer.hpp @@ -40,7 +40,7 @@ class TimeInterpolatableBuffer { * @param historySize The history size of the buffer. * @param func The function used to interpolate between values. */ - TimeInterpolatableBuffer(wpi::units::second_t historySize, + TimeInterpolatableBuffer(wpi::units::seconds<> historySize, std::function func) : m_historySize(historySize), m_interpolatingFunc(func) {} @@ -52,7 +52,7 @@ class TimeInterpolatableBuffer { * * @param historySize The history size of the buffer. */ - explicit TimeInterpolatableBuffer(wpi::units::second_t historySize) + explicit TimeInterpolatableBuffer(wpi::units::seconds<> historySize) : m_historySize(historySize), m_interpolatingFunc([](const T& start, const T& end, double t) { if constexpr (requires(T a, T b, double t) { a + (b - a) * t; }) { @@ -68,7 +68,7 @@ class TimeInterpolatableBuffer { * @param time The timestamp of the sample. * @param sample The sample object. */ - void AddSample(wpi::units::second_t time, T sample) { + void AddSample(wpi::units::seconds<> time, T sample) { // Add the new state into the vector if (m_pastSnapshots.size() == 0 || time > m_pastSnapshots.back().first) { m_pastSnapshots.emplace_back(time, sample); @@ -105,7 +105,7 @@ class TimeInterpolatableBuffer { * * @param time The time at which to sample the buffer. */ - std::optional Sample(wpi::units::second_t time) const { + std::optional Sample(wpi::units::seconds<> time) const { if (m_pastSnapshots.empty()) { return {}; } @@ -145,21 +145,21 @@ class TimeInterpolatableBuffer { * Grant access to the internal sample buffer. Used in Pose Estimation to * replay odometry inputs stored within this buffer. */ - std::vector>& GetInternalBuffer() { + std::vector, T>>& GetInternalBuffer() { return m_pastSnapshots; } /** * Grant access to the internal sample buffer. */ - const std::vector>& GetInternalBuffer() + const std::vector, T>>& GetInternalBuffer() const { return m_pastSnapshots; } private: - wpi::units::second_t m_historySize; - std::vector> m_pastSnapshots; + wpi::units::seconds<> m_historySize; + std::vector, T>> m_pastSnapshots; std::function m_interpolatingFunc; }; @@ -167,7 +167,7 @@ class TimeInterpolatableBuffer { // exponential template <> inline TimeInterpolatableBuffer::TimeInterpolatableBuffer( - wpi::units::second_t historySize) + wpi::units::seconds<> historySize) : m_historySize(historySize), m_interpolatingFunc([](const Pose2d& start, const Pose2d& end, double t) { if (t < 0) { @@ -183,7 +183,7 @@ inline TimeInterpolatableBuffer::TimeInterpolatableBuffer( template <> inline TimeInterpolatableBuffer::TimeInterpolatableBuffer( - wpi::units::second_t historySize) + wpi::units::seconds<> historySize) : m_historySize(historySize), m_interpolatingFunc([](const Pose3d& start, const Pose3d& end, double t) { if (t < 0) { diff --git a/wpimath/src/main/native/include/wpi/math/kinematics/ChassisAccelerations.hpp b/wpimath/src/main/native/include/wpi/math/kinematics/ChassisAccelerations.hpp index 479d49be24b..39afd28912b 100644 --- a/wpimath/src/main/native/include/wpi/math/kinematics/ChassisAccelerations.hpp +++ b/wpimath/src/main/native/include/wpi/math/kinematics/ChassisAccelerations.hpp @@ -27,17 +27,17 @@ struct WPILIB_DLLEXPORT ChassisAccelerations { /** * Acceleration along the x-axis. (Fwd is +) */ - units::meters_per_second_squared_t ax = 0_mps_sq; + units::meters_per_second_squared<> ax = 0_mps2; /** * Acceleration along the y-axis. (Left is +) */ - units::meters_per_second_squared_t ay = 0_mps_sq; + units::meters_per_second_squared<> ay = 0_mps2; /** * Angular acceleration of the robot frame. (CCW is +) */ - units::radians_per_second_squared_t alpha = 0_rad_per_s_sq; + units::radians_per_second_squared<> alpha = 0_rad_per_s_sq; /** * Converts this field-relative set of accelerations into a robot-relative @@ -54,10 +54,10 @@ struct WPILIB_DLLEXPORT ChassisAccelerations { const Rotation2d& robotAngle) const { // CW rotation into chassis frame auto rotated = - Translation2d{units::meter_t{ax.value()}, units::meter_t{ay.value()}} + Translation2d{units::meters<>{ax.value()}, units::meters<>{ay.value()}} .RotateBy(-robotAngle); - return {units::meters_per_second_squared_t{rotated.X().value()}, - units::meters_per_second_squared_t{rotated.Y().value()}, alpha}; + return {units::meters_per_second_squared<>{rotated.X().value()}, + units::meters_per_second_squared<>{rotated.Y().value()}, alpha}; } /** @@ -75,10 +75,10 @@ struct WPILIB_DLLEXPORT ChassisAccelerations { const Rotation2d& robotAngle) const { // CCW rotation out of chassis frame auto rotated = - Translation2d{units::meter_t{ax.value()}, units::meter_t{ay.value()}} + Translation2d{units::meters<>{ax.value()}, units::meters<>{ay.value()}} .RotateBy(robotAngle); - return {units::meters_per_second_squared_t{rotated.X().value()}, - units::meters_per_second_squared_t{rotated.Y().value()}, alpha}; + return {units::meters_per_second_squared<>{rotated.X().value()}, + units::meters_per_second_squared<>{rotated.Y().value()}, alpha}; } /** diff --git a/wpimath/src/main/native/include/wpi/math/kinematics/ChassisVelocities.hpp b/wpimath/src/main/native/include/wpi/math/kinematics/ChassisVelocities.hpp index 341278485c1..6896b7e49d3 100644 --- a/wpimath/src/main/native/include/wpi/math/kinematics/ChassisVelocities.hpp +++ b/wpimath/src/main/native/include/wpi/math/kinematics/ChassisVelocities.hpp @@ -35,17 +35,17 @@ struct WPILIB_DLLEXPORT ChassisVelocities { /** * Velocity along the x-axis. (Fwd is +) */ - wpi::units::meters_per_second_t vx = 0_mps; + wpi::units::meters_per_second<> vx = 0_mps; /** * Velocity along the y-axis. (Left is +) */ - wpi::units::meters_per_second_t vy = 0_mps; + wpi::units::meters_per_second<> vy = 0_mps; /** * Represents the angular velocity of the robot frame. (CCW is +) */ - wpi::units::radians_per_second_t omega = 0_rad_per_s; + wpi::units::radians_per_second<> omega = 0_rad_per_s; /** * Creates a Twist2d from ChassisVelocities. @@ -54,7 +54,7 @@ struct WPILIB_DLLEXPORT ChassisVelocities { * * @return Twist2d. */ - constexpr Twist2d ToTwist2d(wpi::units::second_t dt) const { + constexpr Twist2d ToTwist2d(wpi::units::seconds<> dt) const { return Twist2d{vx * dt, vy * dt, omega * dt}; } @@ -78,7 +78,7 @@ struct WPILIB_DLLEXPORT ChassisVelocities { * for. * @return Discretized ChassisVelocities. */ - constexpr ChassisVelocities Discretize(wpi::units::second_t dt) const { + constexpr ChassisVelocities Discretize(wpi::units::seconds<> dt) const { // Construct the desired pose after a timestep, relative to the current // pose. The desired pose has decoupled translation and rotation. Transform2d desiredTransform{vx * dt, vy * dt, omega * dt}; @@ -105,11 +105,11 @@ struct WPILIB_DLLEXPORT ChassisVelocities { constexpr ChassisVelocities ToRobotRelative( const Rotation2d& robotAngle) const { // CW rotation into chassis frame - auto rotated = Translation2d{wpi::units::meter_t{vx.value()}, - wpi::units::meter_t{vy.value()}} + auto rotated = Translation2d{wpi::units::meters<>{vx.value()}, + wpi::units::meters<>{vy.value()}} .RotateBy(-robotAngle); - return {wpi::units::meters_per_second_t{rotated.X().value()}, - wpi::units::meters_per_second_t{rotated.Y().value()}, omega}; + return {wpi::units::meters_per_second<>{rotated.X().value()}, + wpi::units::meters_per_second<>{rotated.Y().value()}, omega}; } /** @@ -126,11 +126,11 @@ struct WPILIB_DLLEXPORT ChassisVelocities { constexpr ChassisVelocities ToFieldRelative( const Rotation2d& robotAngle) const { // CCW rotation out of chassis frame - auto rotated = Translation2d{wpi::units::meter_t{vx.value()}, - wpi::units::meter_t{vy.value()}} + auto rotated = Translation2d{wpi::units::meters<>{vx.value()}, + wpi::units::meters<>{vy.value()}} .RotateBy(robotAngle); - return {wpi::units::meters_per_second_t{rotated.X().value()}, - wpi::units::meters_per_second_t{rotated.Y().value()}, omega}; + return {wpi::units::meters_per_second<>{rotated.X().value()}, + wpi::units::meters_per_second<>{rotated.Y().value()}, omega}; } /** diff --git a/wpimath/src/main/native/include/wpi/math/kinematics/DifferentialDriveKinematics.hpp b/wpimath/src/main/native/include/wpi/math/kinematics/DifferentialDriveKinematics.hpp index 880170bbd8f..27dee7e5542 100644 --- a/wpimath/src/main/native/include/wpi/math/kinematics/DifferentialDriveKinematics.hpp +++ b/wpimath/src/main/native/include/wpi/math/kinematics/DifferentialDriveKinematics.hpp @@ -41,7 +41,8 @@ class WPILIB_DLLEXPORT DifferentialDriveKinematics * empirical value may be larger than the physical measured value due to * scrubbing effects. */ - constexpr explicit DifferentialDriveKinematics(wpi::units::meter_t trackwidth) + constexpr explicit DifferentialDriveKinematics( + wpi::units::meters<> trackwidth) : trackwidth(trackwidth) { if !consteval { wpi::util::ReportUsage("DifferentialDriveKinematics", ""); @@ -86,8 +87,8 @@ class WPILIB_DLLEXPORT DifferentialDriveKinematics * @param rightDistance The distance measured by the right encoder. * @return The resulting Twist2d. */ - constexpr Twist2d ToTwist2d(const wpi::units::meter_t leftDistance, - const wpi::units::meter_t rightDistance) const { + constexpr Twist2d ToTwist2d(const wpi::units::meters<> leftDistance, + const wpi::units::meters<> rightDistance) const { return {(leftDistance + rightDistance) / 2, 0_m, (rightDistance - leftDistance) / trackwidth * 1_rad}; } @@ -107,8 +108,7 @@ class WPILIB_DLLEXPORT DifferentialDriveKinematics constexpr ChassisAccelerations ToChassisAccelerations( const DifferentialDriveWheelAccelerations& wheelAccelerations) const override { - return {(wheelAccelerations.left + wheelAccelerations.right) / 2.0, - 0_mps_sq, + return {(wheelAccelerations.left + wheelAccelerations.right) / 2.0, 0_mps2, (wheelAccelerations.right - wheelAccelerations.left) / trackwidth * 1_rad}; } @@ -122,7 +122,7 @@ class WPILIB_DLLEXPORT DifferentialDriveKinematics } /// Differential drive trackwidth. - wpi::units::meter_t trackwidth; + wpi::units::meters<> trackwidth; }; } // namespace wpi::math diff --git a/wpimath/src/main/native/include/wpi/math/kinematics/DifferentialDriveOdometry.hpp b/wpimath/src/main/native/include/wpi/math/kinematics/DifferentialDriveOdometry.hpp index 14278e57d14..8c70151d775 100644 --- a/wpimath/src/main/native/include/wpi/math/kinematics/DifferentialDriveOdometry.hpp +++ b/wpimath/src/main/native/include/wpi/math/kinematics/DifferentialDriveOdometry.hpp @@ -43,8 +43,8 @@ class WPILIB_DLLEXPORT DifferentialDriveOdometry * @param initialPose The starting position of the robot on the field. */ explicit DifferentialDriveOdometry(const Rotation2d& gyroAngle, - wpi::units::meter_t leftDistance, - wpi::units::meter_t rightDistance, + wpi::units::meters<> leftDistance, + wpi::units::meters<> rightDistance, const Pose2d& initialPose = Pose2d{}); /** @@ -63,8 +63,8 @@ class WPILIB_DLLEXPORT DifferentialDriveOdometry * @param rightDistance The distance traveled by the right encoder. */ void ResetPosition(const Rotation2d& gyroAngle, - wpi::units::meter_t leftDistance, - wpi::units::meter_t rightDistance, const Pose2d& pose) { + wpi::units::meters<> leftDistance, + wpi::units::meters<> rightDistance, const Pose2d& pose) { Odometry::ResetPosition(gyroAngle, {leftDistance, rightDistance}, pose); } @@ -79,8 +79,8 @@ class WPILIB_DLLEXPORT DifferentialDriveOdometry * @return The new pose of the robot. */ const Pose2d& Update(const Rotation2d& gyroAngle, - wpi::units::meter_t leftDistance, - wpi::units::meter_t rightDistance) { + wpi::units::meters<> leftDistance, + wpi::units::meters<> rightDistance) { return Odometry::Update(gyroAngle, {leftDistance, rightDistance}); } }; diff --git a/wpimath/src/main/native/include/wpi/math/kinematics/DifferentialDriveOdometry3d.hpp b/wpimath/src/main/native/include/wpi/math/kinematics/DifferentialDriveOdometry3d.hpp index 09873499c71..e7630e70bb3 100644 --- a/wpimath/src/main/native/include/wpi/math/kinematics/DifferentialDriveOdometry3d.hpp +++ b/wpimath/src/main/native/include/wpi/math/kinematics/DifferentialDriveOdometry3d.hpp @@ -43,8 +43,8 @@ class WPILIB_DLLEXPORT DifferentialDriveOdometry3d * @param initialPose The starting position of the robot on the field. */ explicit DifferentialDriveOdometry3d(const Rotation3d& gyroAngle, - wpi::units::meter_t leftDistance, - wpi::units::meter_t rightDistance, + wpi::units::meters<> leftDistance, + wpi::units::meters<> rightDistance, const Pose3d& initialPose = Pose3d{}); /** @@ -63,8 +63,8 @@ class WPILIB_DLLEXPORT DifferentialDriveOdometry3d * @param rightDistance The distance traveled by the right encoder. */ void ResetPosition(const Rotation3d& gyroAngle, - wpi::units::meter_t leftDistance, - wpi::units::meter_t rightDistance, const Pose3d& pose) { + wpi::units::meters<> leftDistance, + wpi::units::meters<> rightDistance, const Pose3d& pose) { Odometry3d::ResetPosition(gyroAngle, {leftDistance, rightDistance}, pose); } @@ -79,8 +79,8 @@ class WPILIB_DLLEXPORT DifferentialDriveOdometry3d * @return The new pose of the robot. */ const Pose3d& Update(const Rotation3d& gyroAngle, - wpi::units::meter_t leftDistance, - wpi::units::meter_t rightDistance) { + wpi::units::meters<> leftDistance, + wpi::units::meters<> rightDistance) { return Odometry3d::Update(gyroAngle, {leftDistance, rightDistance}); } }; diff --git a/wpimath/src/main/native/include/wpi/math/kinematics/DifferentialDriveWheelAccelerations.hpp b/wpimath/src/main/native/include/wpi/math/kinematics/DifferentialDriveWheelAccelerations.hpp index 0f307d3e4a2..372d8f7d866 100644 --- a/wpimath/src/main/native/include/wpi/math/kinematics/DifferentialDriveWheelAccelerations.hpp +++ b/wpimath/src/main/native/include/wpi/math/kinematics/DifferentialDriveWheelAccelerations.hpp @@ -15,12 +15,12 @@ struct WPILIB_DLLEXPORT DifferentialDriveWheelAccelerations { /** * Acceleration of the left side of the robot. */ - units::meters_per_second_squared_t left = 0_mps_sq; + units::meters_per_second_squared<> left = 0_mps2; /** * Acceleration of the right side of the robot. */ - units::meters_per_second_squared_t right = 0_mps_sq; + units::meters_per_second_squared<> right = 0_mps2; /** * Adds two DifferentialDriveWheelAccelerations and returns the sum. diff --git a/wpimath/src/main/native/include/wpi/math/kinematics/DifferentialDriveWheelPositions.hpp b/wpimath/src/main/native/include/wpi/math/kinematics/DifferentialDriveWheelPositions.hpp index e5c9e9a6435..cbd73fc7f70 100644 --- a/wpimath/src/main/native/include/wpi/math/kinematics/DifferentialDriveWheelPositions.hpp +++ b/wpimath/src/main/native/include/wpi/math/kinematics/DifferentialDriveWheelPositions.hpp @@ -16,12 +16,12 @@ struct WPILIB_DLLEXPORT DifferentialDriveWheelPositions { /** * Distance driven by the left side. */ - wpi::units::meter_t left = 0_m; + wpi::units::meters<> left = 0_m; /** * Distance driven by the right side. */ - wpi::units::meter_t right = 0_m; + wpi::units::meters<> right = 0_m; /** * Checks equality between this DifferentialDriveWheelPositions and another diff --git a/wpimath/src/main/native/include/wpi/math/kinematics/DifferentialDriveWheelVelocities.hpp b/wpimath/src/main/native/include/wpi/math/kinematics/DifferentialDriveWheelVelocities.hpp index 9a1e7e2852e..a743d0f7783 100644 --- a/wpimath/src/main/native/include/wpi/math/kinematics/DifferentialDriveWheelVelocities.hpp +++ b/wpimath/src/main/native/include/wpi/math/kinematics/DifferentialDriveWheelVelocities.hpp @@ -4,8 +4,7 @@ #pragma once -#include "wpi/units/base.hpp" -#include "wpi/units/math.hpp" +#include "wpi/units/core.hpp" #include "wpi/units/velocity.hpp" #include "wpi/util/SymbolExports.hpp" @@ -17,12 +16,12 @@ struct WPILIB_DLLEXPORT DifferentialDriveWheelVelocities { /** * Velocity of the left side of the robot. */ - wpi::units::meters_per_second_t left = 0_mps; + wpi::units::meters_per_second<> left = 0_mps; /** * Velocity of the right side of the robot. */ - wpi::units::meters_per_second_t right = 0_mps; + wpi::units::meters_per_second<> right = 0_mps; /** * Renormalizes the wheel velocities if either side is above the specified @@ -41,9 +40,9 @@ struct WPILIB_DLLEXPORT DifferentialDriveWheelVelocities { */ [[nodiscard]] constexpr DifferentialDriveWheelVelocities Desaturate( - wpi::units::meters_per_second_t attainableMaxVelocity) { - auto realMaxVelocity = wpi::units::math::max(wpi::units::math::abs(left), - wpi::units::math::abs(right)); + wpi::units::meters_per_second<> attainableMaxVelocity) { + auto realMaxVelocity = + wpi::units::max(wpi::units::abs(left), wpi::units::abs(right)); if (realMaxVelocity > attainableMaxVelocity) { return {left / realMaxVelocity * attainableMaxVelocity, diff --git a/wpimath/src/main/native/include/wpi/math/kinematics/MecanumDriveWheelAccelerations.hpp b/wpimath/src/main/native/include/wpi/math/kinematics/MecanumDriveWheelAccelerations.hpp index 602432f9d80..d5ecdc3ef34 100644 --- a/wpimath/src/main/native/include/wpi/math/kinematics/MecanumDriveWheelAccelerations.hpp +++ b/wpimath/src/main/native/include/wpi/math/kinematics/MecanumDriveWheelAccelerations.hpp @@ -15,22 +15,22 @@ struct WPILIB_DLLEXPORT MecanumDriveWheelAccelerations { /** * Acceleration of the front-left wheel. */ - units::meters_per_second_squared_t frontLeft = 0_mps_sq; + units::meters_per_second_squared<> frontLeft = 0_mps2; /** * Acceleration of the front-right wheel. */ - units::meters_per_second_squared_t frontRight = 0_mps_sq; + units::meters_per_second_squared<> frontRight = 0_mps2; /** * Acceleration of the rear-left wheel. */ - units::meters_per_second_squared_t rearLeft = 0_mps_sq; + units::meters_per_second_squared<> rearLeft = 0_mps2; /** * Acceleration of the rear-right wheel. */ - units::meters_per_second_squared_t rearRight = 0_mps_sq; + units::meters_per_second_squared<> rearRight = 0_mps2; /** * Adds two MecanumDriveWheelAccelerations and returns the sum. diff --git a/wpimath/src/main/native/include/wpi/math/kinematics/MecanumDriveWheelPositions.hpp b/wpimath/src/main/native/include/wpi/math/kinematics/MecanumDriveWheelPositions.hpp index 2cf7c025e2b..442d3d335df 100644 --- a/wpimath/src/main/native/include/wpi/math/kinematics/MecanumDriveWheelPositions.hpp +++ b/wpimath/src/main/native/include/wpi/math/kinematics/MecanumDriveWheelPositions.hpp @@ -16,22 +16,22 @@ struct WPILIB_DLLEXPORT MecanumDriveWheelPositions { /** * Distance driven by the front-left wheel. */ - wpi::units::meter_t frontLeft = 0_m; + wpi::units::meters<> frontLeft = 0_m; /** * Distance driven by the front-right wheel. */ - wpi::units::meter_t frontRight = 0_m; + wpi::units::meters<> frontRight = 0_m; /** * Distance driven by the rear-left wheel. */ - wpi::units::meter_t rearLeft = 0_m; + wpi::units::meters<> rearLeft = 0_m; /** * Distance driven by the rear-right wheel. */ - wpi::units::meter_t rearRight = 0_m; + wpi::units::meters<> rearRight = 0_m; /** * Checks equality between this MecanumDriveWheelPositions and another object. diff --git a/wpimath/src/main/native/include/wpi/math/kinematics/MecanumDriveWheelVelocities.hpp b/wpimath/src/main/native/include/wpi/math/kinematics/MecanumDriveWheelVelocities.hpp index 6f9b23c32c0..8867f54c10b 100644 --- a/wpimath/src/main/native/include/wpi/math/kinematics/MecanumDriveWheelVelocities.hpp +++ b/wpimath/src/main/native/include/wpi/math/kinematics/MecanumDriveWheelVelocities.hpp @@ -7,7 +7,6 @@ #include #include -#include "wpi/units/math.hpp" #include "wpi/units/velocity.hpp" #include "wpi/util/SymbolExports.hpp" @@ -19,22 +18,22 @@ struct WPILIB_DLLEXPORT MecanumDriveWheelVelocities { /** * Velocity of the front-left wheel. */ - wpi::units::meters_per_second_t frontLeft = 0_mps; + wpi::units::meters_per_second<> frontLeft = 0_mps; /** * Velocity of the front-right wheel. */ - wpi::units::meters_per_second_t frontRight = 0_mps; + wpi::units::meters_per_second<> frontRight = 0_mps; /** * Velocity of the rear-left wheel. */ - wpi::units::meters_per_second_t rearLeft = 0_mps; + wpi::units::meters_per_second<> rearLeft = 0_mps; /** * Velocity of the rear-right wheel. */ - wpi::units::meters_per_second_t rearRight = 0_mps; + wpi::units::meters_per_second<> rearRight = 0_mps; /** * Renormalizes the wheel velocities if any individual velocity is above the @@ -53,15 +52,14 @@ struct WPILIB_DLLEXPORT MecanumDriveWheelVelocities { */ [[nodiscard]] constexpr MecanumDriveWheelVelocities Desaturate( - wpi::units::meters_per_second_t attainableMaxVelocity) const { - std::array wheelVelocities{ + wpi::units::meters_per_second<> attainableMaxVelocity) const { + std::array, 4> wheelVelocities{ frontLeft, frontRight, rearLeft, rearRight}; - wpi::units::meters_per_second_t realMaxVelocity = - wpi::units::math::abs(*std::max_element( - wheelVelocities.begin(), wheelVelocities.end(), - [](const auto& a, const auto& b) { - return wpi::units::math::abs(a) < wpi::units::math::abs(b); - })); + wpi::units::meters_per_second<> realMaxVelocity = wpi::units::abs( + *std::max_element(wheelVelocities.begin(), wheelVelocities.end(), + [](const auto& a, const auto& b) { + return wpi::units::abs(a) < wpi::units::abs(b); + })); if (realMaxVelocity > attainableMaxVelocity) { for (int i = 0; i < 4; ++i) { diff --git a/wpimath/src/main/native/include/wpi/math/kinematics/Odometry3d.hpp b/wpimath/src/main/native/include/wpi/math/kinematics/Odometry3d.hpp index 08b8d3b4b4a..a4db49b88fc 100644 --- a/wpimath/src/main/native/include/wpi/math/kinematics/Odometry3d.hpp +++ b/wpimath/src/main/native/include/wpi/math/kinematics/Odometry3d.hpp @@ -121,9 +121,9 @@ class WPILIB_DLLEXPORT Odometry3d { Twist3d twist{twist2d.dx, twist2d.dy, 0_m, - wpi::units::radian_t{angle_difference(0)}, - wpi::units::radian_t{angle_difference(1)}, - wpi::units::radian_t{angle_difference(2)}}; + wpi::units::radians<>{angle_difference(0)}, + wpi::units::radians<>{angle_difference(1)}, + wpi::units::radians<>{angle_difference(2)}}; m_pose = m_pose + twist.Exp(); diff --git a/wpimath/src/main/native/include/wpi/math/kinematics/SwerveDriveKinematics.hpp b/wpimath/src/main/native/include/wpi/math/kinematics/SwerveDriveKinematics.hpp index 71ec6b73834..d3f3d3267a3 100644 --- a/wpimath/src/main/native/include/wpi/math/kinematics/SwerveDriveKinematics.hpp +++ b/wpimath/src/main/native/include/wpi/math/kinematics/SwerveDriveKinematics.hpp @@ -26,10 +26,8 @@ #include "wpi/units/angle.hpp" #include "wpi/units/angular_acceleration.hpp" #include "wpi/units/angular_velocity.hpp" -#include "wpi/units/base.hpp" -#include "wpi/units/dimensionless.hpp" +#include "wpi/units/core.hpp" #include "wpi/units/length.hpp" -#include "wpi/units/math.hpp" #include "wpi/units/velocity.hpp" #include "wpi/util/SymbolExports.hpp" #include "wpi/util/UsageReporting.hpp" @@ -177,7 +175,7 @@ class SwerveDriveKinematics * module states are not normalized. Sometimes, a user input may cause one * of the module velocities to go above the attainable max velocity. Use * the DesaturateWheelVelocities(wpi::util::array, wpi::units::meters_per_second_t) function to rectify this + * NumModules>, wpi::units::meters_per_second<>) function to rectify this * issue. In addition, you can leverage the power of C++17 to directly * assign the module states to variables: * @@ -214,10 +212,10 @@ class SwerveDriveKinematics m_firstOrderInverseKinematics * chassisVelocitiesVector; for (size_t i = 0; i < NumModules; i++) { - wpi::units::meters_per_second_t x{moduleVelocityMatrix(i * 2, 0)}; - wpi::units::meters_per_second_t y{moduleVelocityMatrix(i * 2 + 1, 0)}; + wpi::units::meters_per_second<> x{moduleVelocityMatrix(i * 2, 0)}; + wpi::units::meters_per_second<> y{moduleVelocityMatrix(i * 2 + 1, 0)}; - auto velocity = wpi::units::math::hypot(x, y); + auto velocity = wpi::units::hypot(x, y); auto rotation = velocity > 1e-6_mps ? Rotation2d{x.value(), y.value()} : m_moduleHeadings[i]; @@ -282,9 +280,9 @@ class SwerveDriveKinematics Eigen::Vector3d chassisVelocitiesVector = m_firstOrderForwardKinematics.solve(moduleVelocityMatrix); - return {wpi::units::meters_per_second_t{chassisVelocitiesVector(0)}, - wpi::units::meters_per_second_t{chassisVelocitiesVector(1)}, - wpi::units::radians_per_second_t{chassisVelocitiesVector(2)}}; + return {wpi::units::meters_per_second<>{chassisVelocitiesVector(0)}, + wpi::units::meters_per_second<>{chassisVelocitiesVector(1)}, + wpi::units::radians_per_second<>{chassisVelocitiesVector(2)}}; } /** @@ -333,9 +331,9 @@ class SwerveDriveKinematics Eigen::Vector3d chassisDeltaVector = m_firstOrderForwardKinematics.solve(moduleDeltaMatrix); - return {wpi::units::meter_t{chassisDeltaVector(0)}, - wpi::units::meter_t{chassisDeltaVector(1)}, - wpi::units::radian_t{chassisDeltaVector(2)}}; + return {wpi::units::meters<>{chassisDeltaVector(0)}, + wpi::units::meters<>{chassisDeltaVector(1)}, + wpi::units::radians<>{chassisDeltaVector(2)}}; } Twist2d ToTwist2d( @@ -375,12 +373,12 @@ class SwerveDriveKinematics static wpi::util::array DesaturateWheelVelocities( wpi::util::array moduleVelocities, - wpi::units::meters_per_second_t attainableMaxVelocity) { - auto realMaxVelocity = wpi::units::math::abs( + wpi::units::meters_per_second<> attainableMaxVelocity) { + auto realMaxVelocity = wpi::units::abs( std::max_element(moduleVelocities.begin(), moduleVelocities.end(), [](const auto& a, const auto& b) { - return wpi::units::math::abs(a.velocity) < - wpi::units::math::abs(b.velocity); + return wpi::units::abs(a.velocity) < + wpi::units::abs(b.velocity); }) ->velocity); @@ -429,14 +427,14 @@ class SwerveDriveKinematics DesaturateWheelVelocities( wpi::util::array moduleVelocities, ChassisVelocities desiredChassisVelocity, - wpi::units::meters_per_second_t attainableMaxModuleVelocity, - wpi::units::meters_per_second_t attainableMaxRobotTranslationVelocity, - wpi::units::radians_per_second_t attainableMaxRobotRotationVelocity) { - auto realMaxVelocity = wpi::units::math::abs( + wpi::units::meters_per_second<> attainableMaxModuleVelocity, + wpi::units::meters_per_second<> attainableMaxRobotTranslationVelocity, + wpi::units::radians_per_second<> attainableMaxRobotRotationVelocity) { + auto realMaxVelocity = wpi::units::abs( std::max_element(moduleVelocities.begin(), moduleVelocities.end(), [](const auto& a, const auto& b) { - return wpi::units::math::abs(a.velocity) < - wpi::units::math::abs(b.velocity); + return wpi::units::abs(a.velocity) < + wpi::units::abs(b.velocity); }) ->velocity); @@ -446,18 +444,18 @@ class SwerveDriveKinematics return moduleVelocities; } - auto translationalK = wpi::units::math::hypot(desiredChassisVelocity.vx, - desiredChassisVelocity.vy) / + auto translationalK = wpi::units::hypot(desiredChassisVelocity.vx, + desiredChassisVelocity.vy) / attainableMaxRobotTranslationVelocity; - auto rotationalK = wpi::units::math::abs(desiredChassisVelocity.omega) / + auto rotationalK = wpi::units::abs(desiredChassisVelocity.omega) / attainableMaxRobotRotationVelocity; - auto k = wpi::units::math::max(translationalK, rotationalK); + auto k = wpi::units::max(translationalK, rotationalK); auto scale = - wpi::units::math::min(k * attainableMaxModuleVelocity / realMaxVelocity, - wpi::units::scalar_t{1}); + wpi::units::min(k * attainableMaxModuleVelocity / realMaxVelocity, + wpi::units::dimensionless<>{1}); wpi::util::array velocities( wpi::util::empty_array); for (size_t i = 0; i < NumModules; ++i) { @@ -506,7 +504,7 @@ class SwerveDriveKinematics wpi::util::array ToSwerveModuleAccelerations( const ChassisAccelerations& chassisAccelerations, - const units::radians_per_second_t angularVelocity = 0.0_rad_per_s, + const units::radians_per_second<> angularVelocity = 0.0_rad_per_s, const Translation2d& centerOfRotation = Translation2d{}) const { // Derivation for second-order kinematics from "Swerve Drive Second Order // Kinematics" by FRC Team 449 - The Blair Robot Project, Rafi Pedersen @@ -515,11 +513,11 @@ class SwerveDriveKinematics wpi::util::array moduleAccelerations( wpi::util::empty_array); - if (chassisAccelerations.ax == 0.0_mps_sq && - chassisAccelerations.ay == 0.0_mps_sq && + if (chassisAccelerations.ax == 0.0_mps2 && + chassisAccelerations.ay == 0.0_mps2 && chassisAccelerations.alpha == 0.0_rad_per_s_sq) { for (size_t i = 0; i < NumModules; i++) { - moduleAccelerations[i] = {0.0_mps_sq, Rotation2d{0.0_rad}}; + moduleAccelerations[i] = {0.0_mps2, Rotation2d{0.0_rad}}; } return moduleAccelerations; } @@ -537,15 +535,15 @@ class SwerveDriveKinematics m_secondOrderInverseKinematics * chassisAccelerationsVector; for (size_t i = 0; i < NumModules; i++) { - units::meters_per_second_squared_t x{moduleAccelerationsMatrix(i * 2, 0)}; - units::meters_per_second_squared_t y{ + units::meters_per_second_squared<> x{moduleAccelerationsMatrix(i * 2, 0)}; + units::meters_per_second_squared<> y{ moduleAccelerationsMatrix(i * 2 + 1, 0)}; // For swerve modules, we need to compute both linear acceleration and // angular acceleration The linear acceleration is the magnitude of the // acceleration vector - units::meters_per_second_squared_t linearAcceleration = - units::math::hypot(x, y); + units::meters_per_second_squared<> linearAcceleration = + units::hypot(x, y); if (linearAcceleration.value() < 1e-6) { moduleAccelerations[i] = {linearAcceleration, {}}; @@ -629,9 +627,9 @@ class SwerveDriveKinematics // the second order kinematics equation for swerve drive yields a state // vector [aₓ, a_y, ω², α] - return {units::meters_per_second_squared_t{chassisAccelerationsVector(0)}, - units::meters_per_second_squared_t{chassisAccelerationsVector(1)}, - units::radians_per_second_squared_t{chassisAccelerationsVector(3)}}; + return {units::meters_per_second_squared<>{chassisAccelerationsVector(0)}, + units::meters_per_second_squared<>{chassisAccelerationsVector(1)}, + units::radians_per_second_squared<>{chassisAccelerationsVector(3)}}; } private: diff --git a/wpimath/src/main/native/include/wpi/math/kinematics/SwerveModuleAcceleration.hpp b/wpimath/src/main/native/include/wpi/math/kinematics/SwerveModuleAcceleration.hpp index 0b15da3cb93..74a513661d1 100644 --- a/wpimath/src/main/native/include/wpi/math/kinematics/SwerveModuleAcceleration.hpp +++ b/wpimath/src/main/native/include/wpi/math/kinematics/SwerveModuleAcceleration.hpp @@ -7,7 +7,6 @@ #include "wpi/math/geometry/Rotation2d.hpp" #include "wpi/units/acceleration.hpp" #include "wpi/units/angle.hpp" -#include "wpi/units/math.hpp" #include "wpi/util/SymbolExports.hpp" namespace wpi::math { @@ -18,7 +17,7 @@ struct WPILIB_DLLEXPORT SwerveModuleAcceleration { /** * Acceleration of the wheel of the module. */ - units::meters_per_second_squared_t acceleration = 0_mps_sq; + units::meters_per_second_squared<> acceleration = 0_mps2; /** * Angle of the acceleration vector. @@ -32,7 +31,7 @@ struct WPILIB_DLLEXPORT SwerveModuleAcceleration { * @return Whether the two objects are equal. */ constexpr bool operator==(const SwerveModuleAcceleration& other) const { - return units::math::abs(acceleration - other.acceleration) < 1E-9_mps_sq && + return units::abs(acceleration - other.acceleration) < 1E-9_mps2 && angle == other.angle; } @@ -54,7 +53,7 @@ struct WPILIB_DLLEXPORT SwerveModuleAcceleration { auto sumX = thisX + otherX; auto sumY = thisY + otherY; - auto resultAcceleration = units::math::hypot(sumX, sumY); + auto resultAcceleration = units::hypot(sumX, sumY); auto resultAngle = Rotation2d{sumX.value(), sumY.value()}; return {resultAcceleration, resultAngle}; diff --git a/wpimath/src/main/native/include/wpi/math/kinematics/SwerveModulePosition.hpp b/wpimath/src/main/native/include/wpi/math/kinematics/SwerveModulePosition.hpp index 032fab1a519..d953b46bcdc 100644 --- a/wpimath/src/main/native/include/wpi/math/kinematics/SwerveModulePosition.hpp +++ b/wpimath/src/main/native/include/wpi/math/kinematics/SwerveModulePosition.hpp @@ -6,7 +6,6 @@ #include "wpi/math/geometry/Rotation2d.hpp" #include "wpi/units/length.hpp" -#include "wpi/units/math.hpp" #include "wpi/util/MathExtras.hpp" #include "wpi/util/SymbolExports.hpp" @@ -18,7 +17,7 @@ struct WPILIB_DLLEXPORT SwerveModulePosition { /** * Distance the wheel of a module has traveled */ - wpi::units::meter_t distance = 0_m; + wpi::units::meters<> distance = 0_m; /** * Angle of the module. @@ -32,7 +31,7 @@ struct WPILIB_DLLEXPORT SwerveModulePosition { * @return Whether the two objects are equal. */ constexpr bool operator==(const SwerveModulePosition& other) const { - return wpi::units::math::abs(distance - other.distance) < 1E-9_m && + return wpi::units::abs(distance - other.distance) < 1E-9_m && angle == other.angle; } diff --git a/wpimath/src/main/native/include/wpi/math/kinematics/SwerveModuleVelocity.hpp b/wpimath/src/main/native/include/wpi/math/kinematics/SwerveModuleVelocity.hpp index 7b09c86f96d..546ee46c26e 100644 --- a/wpimath/src/main/native/include/wpi/math/kinematics/SwerveModuleVelocity.hpp +++ b/wpimath/src/main/native/include/wpi/math/kinematics/SwerveModuleVelocity.hpp @@ -6,7 +6,6 @@ #include "wpi/math/geometry/Rotation2d.hpp" #include "wpi/units/angle.hpp" -#include "wpi/units/math.hpp" #include "wpi/units/velocity.hpp" #include "wpi/util/SymbolExports.hpp" @@ -18,7 +17,7 @@ struct WPILIB_DLLEXPORT SwerveModuleVelocity { /** * Velocity of the wheel of the module. */ - wpi::units::meters_per_second_t velocity = 0_mps; + wpi::units::meters_per_second<> velocity = 0_mps; /** * Angle of the module. @@ -32,7 +31,7 @@ struct WPILIB_DLLEXPORT SwerveModuleVelocity { * @return Whether the two objects are equal. */ constexpr bool operator==(const SwerveModuleVelocity& other) const { - return wpi::units::math::abs(velocity - other.velocity) < 1E-9_mps && + return wpi::units::abs(velocity - other.velocity) < 1E-9_mps && angle == other.angle; } @@ -49,7 +48,7 @@ struct WPILIB_DLLEXPORT SwerveModuleVelocity { constexpr SwerveModuleVelocity Optimize( const Rotation2d& currentAngle) const { auto delta = angle - currentAngle; - if (wpi::units::math::abs(delta.Degrees()) > 90_deg) { + if (wpi::units::abs(delta.Degrees()) > 90_deg) { return {-velocity, angle + Rotation2d{180_deg}}; } else { return {velocity, angle}; diff --git a/wpimath/src/main/native/include/wpi/math/path/TravelingSalesman.hpp b/wpimath/src/main/native/include/wpi/math/path/TravelingSalesman.hpp index 33c225dc1c2..8a00b68f9ec 100644 --- a/wpimath/src/main/native/include/wpi/math/path/TravelingSalesman.hpp +++ b/wpimath/src/main/native/include/wpi/math/path/TravelingSalesman.hpp @@ -17,7 +17,6 @@ #include "wpi/math/geometry/Pose2d.hpp" #include "wpi/math/linalg/EigenCore.hpp" #include "wpi/math/optimization/SimulatedAnnealing.hpp" -#include "wpi/units/math.hpp" #include "wpi/util/array.hpp" namespace wpi::math { @@ -142,7 +141,7 @@ class TravelingSalesman { // Default cost is distance between poses std::function m_cost = [](const Pose2d& a, const Pose2d& b) -> double { - return wpi::units::math::hypot(a.X() - b.X(), a.Y() - b.Y()).value(); + return wpi::units::hypot(a.X() - b.X(), a.Y() - b.Y()).value(); }; /** diff --git a/wpimath/src/main/native/include/wpi/math/shape/Ellipse2d.hpp b/wpimath/src/main/native/include/wpi/math/shape/Ellipse2d.hpp index 5de1e4d122a..7b9ed76eb3e 100644 --- a/wpimath/src/main/native/include/wpi/math/shape/Ellipse2d.hpp +++ b/wpimath/src/main/native/include/wpi/math/shape/Ellipse2d.hpp @@ -12,9 +12,8 @@ #include "wpi/math/geometry/Rotation2d.hpp" #include "wpi/math/geometry/Transform2d.hpp" #include "wpi/math/geometry/Translation2d.hpp" -#include "wpi/units/base.hpp" +#include "wpi/units/core.hpp" #include "wpi/units/length.hpp" -#include "wpi/units/math.hpp" #include "wpi/util/SymbolExports.hpp" #include "wpi/util/array.hpp" @@ -34,8 +33,8 @@ class WPILIB_DLLEXPORT Ellipse2d final { * @param xSemiAxis The x semi-axis. * @param ySemiAxis The y semi-axis. */ - constexpr Ellipse2d(const Pose2d& center, wpi::units::meter_t xSemiAxis, - wpi::units::meter_t ySemiAxis) + constexpr Ellipse2d(const Pose2d& center, wpi::units::meters<> xSemiAxis, + wpi::units::meters<> ySemiAxis) : m_center{center}, m_xSemiAxis{xSemiAxis}, m_ySemiAxis{ySemiAxis} { if (xSemiAxis <= 0_m || ySemiAxis <= 0_m) { throw std::invalid_argument("Ellipse2d semi-axes must be positive"); @@ -72,14 +71,14 @@ class WPILIB_DLLEXPORT Ellipse2d final { * * @return The x semi-axis. */ - constexpr wpi::units::meter_t XSemiAxis() const { return m_xSemiAxis; } + constexpr wpi::units::meters<> XSemiAxis() const { return m_xSemiAxis; } /** * Returns the y semi-axis. * * @return The y semi-axis. */ - constexpr wpi::units::meter_t YSemiAxis() const { return m_ySemiAxis; } + constexpr wpi::units::meters<> YSemiAxis() const { return m_ySemiAxis; } /** * Returns the focal points of the ellipse. In a perfect circle, this will @@ -89,12 +88,12 @@ class WPILIB_DLLEXPORT Ellipse2d final { */ constexpr wpi::util::array FocalPoints() const { // Major semi-axis - auto a = wpi::units::math::max(m_xSemiAxis, m_ySemiAxis); + auto a = wpi::units::max(m_xSemiAxis, m_ySemiAxis); // Minor semi-axis - auto b = wpi::units::math::min(m_xSemiAxis, m_ySemiAxis); + auto b = wpi::units::min(m_xSemiAxis, m_ySemiAxis); - auto c = wpi::units::math::sqrt(a * a - b * b); + auto c = wpi::units::sqrt(a * a - b * b); if (m_xSemiAxis > m_ySemiAxis) { return wpi::util::array{ @@ -154,7 +153,7 @@ class WPILIB_DLLEXPORT Ellipse2d final { * @param point The point to check. * @return The distance (0, if the point is contained by the ellipse) */ - wpi::units::meter_t Distance(const Translation2d& point) const { + wpi::units::meters<> Distance(const Translation2d& point) const { return Nearest(point).Distance(point); } @@ -175,14 +174,14 @@ class WPILIB_DLLEXPORT Ellipse2d final { */ constexpr bool operator==(const Ellipse2d& other) const { return m_center == other.m_center && - wpi::units::math::abs(m_xSemiAxis - other.m_xSemiAxis) < 1E-9_m && - wpi::units::math::abs(m_ySemiAxis - other.m_ySemiAxis) < 1E-9_m; + wpi::units::abs(m_xSemiAxis - other.m_xSemiAxis) < 1E-9_m && + wpi::units::abs(m_ySemiAxis - other.m_ySemiAxis) < 1E-9_m; } private: Pose2d m_center; - wpi::units::meter_t m_xSemiAxis; - wpi::units::meter_t m_ySemiAxis; + wpi::units::meters<> m_xSemiAxis; + wpi::units::meters<> m_ySemiAxis; /** * Solves the equation of an ellipse from the given point. This is a helper diff --git a/wpimath/src/main/native/include/wpi/math/shape/Rectangle2d.hpp b/wpimath/src/main/native/include/wpi/math/shape/Rectangle2d.hpp index 2bc98ed611e..67fd691e6c8 100644 --- a/wpimath/src/main/native/include/wpi/math/shape/Rectangle2d.hpp +++ b/wpimath/src/main/native/include/wpi/math/shape/Rectangle2d.hpp @@ -12,7 +12,6 @@ #include "wpi/math/geometry/Transform2d.hpp" #include "wpi/math/geometry/Translation2d.hpp" #include "wpi/units/length.hpp" -#include "wpi/units/math.hpp" #include "wpi/util/SymbolExports.hpp" namespace wpi::math { @@ -33,8 +32,8 @@ class WPILIB_DLLEXPORT Rectangle2d final { * @param yWidth The y size component of the rectangle, in unrotated * coordinate frame. */ - constexpr Rectangle2d(const Pose2d& center, wpi::units::meter_t xWidth, - wpi::units::meter_t yWidth) + constexpr Rectangle2d(const Pose2d& center, wpi::units::meters<> xWidth, + wpi::units::meters<> yWidth) : m_center{center}, m_xWidth{xWidth}, m_yWidth{yWidth} { if (xWidth < 0_m || yWidth < 0_m) { throw std::invalid_argument( @@ -52,8 +51,8 @@ class WPILIB_DLLEXPORT Rectangle2d final { constexpr Rectangle2d(const Translation2d& cornerA, const Translation2d& cornerB) : m_center{(cornerA + cornerB) / 2.0, Rotation2d{}}, - m_xWidth{wpi::units::math::abs(cornerA.X() - cornerB.X())}, - m_yWidth{wpi::units::math::abs(cornerA.Y() - cornerB.Y())} {} + m_xWidth{wpi::units::abs(cornerA.X() - cornerB.X())}, + m_yWidth{wpi::units::abs(cornerA.Y() - cornerB.Y())} {} /** * Returns the center of the rectangle. @@ -74,14 +73,14 @@ class WPILIB_DLLEXPORT Rectangle2d final { * * @return The x size component of the rectangle. */ - constexpr wpi::units::meter_t XWidth() const { return m_xWidth; } + constexpr wpi::units::meters<> XWidth() const { return m_xWidth; } /** * Returns the y size component of the rectangle. * * @return The y size component of the rectangle. */ - constexpr wpi::units::meter_t YWidth() const { return m_yWidth; } + constexpr wpi::units::meters<> YWidth() const { return m_yWidth; } /** * Transforms the center of the rectangle and returns the new rectangle. @@ -114,14 +113,14 @@ class WPILIB_DLLEXPORT Rectangle2d final { auto pointInRect = point - m_center.Translation(); pointInRect = pointInRect.RotateBy(-m_center.Rotation()); - if (wpi::units::math::abs(wpi::units::math::abs(pointInRect.X()) - - m_xWidth / 2.0) <= 1E-9_m) { + if (wpi::units::abs(wpi::units::abs(pointInRect.X()) - m_xWidth / 2.0) <= + 1E-9_m) { // Point rests on left/right perimeter - return wpi::units::math::abs(pointInRect.Y()) <= m_yWidth / 2.0; - } else if (wpi::units::math::abs(wpi::units::math::abs(pointInRect.Y()) - - m_yWidth / 2.0) <= 1E-9_m) { + return wpi::units::abs(pointInRect.Y()) <= m_yWidth / 2.0; + } else if (wpi::units::abs(wpi::units::abs(pointInRect.Y()) - + m_yWidth / 2.0) <= 1E-9_m) { // Point rests on top/bottom perimeter - return wpi::units::math::abs(pointInRect.X()) <= m_xWidth / 2.0; + return wpi::units::abs(pointInRect.X()) <= m_xWidth / 2.0; } return false; @@ -153,7 +152,7 @@ class WPILIB_DLLEXPORT Rectangle2d final { * @param point The point to check. * @return The distance (0, if the point is contained by the rectangle) */ - constexpr wpi::units::meter_t Distance(const Translation2d& point) const { + constexpr wpi::units::meters<> Distance(const Translation2d& point) const { return Nearest(point).Distance(point); } @@ -193,14 +192,14 @@ class WPILIB_DLLEXPORT Rectangle2d final { */ constexpr bool operator==(const Rectangle2d& other) const { return m_center == other.m_center && - wpi::units::math::abs(m_xWidth - other.m_xWidth) < 1E-9_m && - wpi::units::math::abs(m_yWidth - other.m_yWidth) < 1E-9_m; + wpi::units::abs(m_xWidth - other.m_xWidth) < 1E-9_m && + wpi::units::abs(m_yWidth - other.m_yWidth) < 1E-9_m; } private: Pose2d m_center; - wpi::units::meter_t m_xWidth; - wpi::units::meter_t m_yWidth; + wpi::units::meters<> m_xWidth; + wpi::units::meters<> m_yWidth; }; } // namespace wpi::math diff --git a/wpimath/src/main/native/include/wpi/math/spline/Spline.hpp b/wpimath/src/main/native/include/wpi/math/spline/Spline.hpp index 77b677641c2..7f5ea94a19c 100644 --- a/wpimath/src/main/native/include/wpi/math/spline/Spline.hpp +++ b/wpimath/src/main/native/include/wpi/math/spline/Spline.hpp @@ -146,8 +146,8 @@ class Spline { * @return The Translation2d. */ static constexpr Translation2d FromVector(const Eigen::Vector2d& vector) { - return Translation2d{wpi::units::meter_t{vector(0)}, - wpi::units::meter_t{vector(1)}}; + return Translation2d{wpi::units::meters<>{vector(0)}, + wpi::units::meters<>{vector(1)}}; } }; diff --git a/wpimath/src/main/native/include/wpi/math/spline/SplineHelper.hpp b/wpimath/src/main/native/include/wpi/math/spline/SplineHelper.hpp index 5f1e817fd39..e4d25bc89fd 100644 --- a/wpimath/src/main/native/include/wpi/math/spline/SplineHelper.hpp +++ b/wpimath/src/main/native/include/wpi/math/spline/SplineHelper.hpp @@ -110,10 +110,10 @@ class WPILIB_DLLEXPORT SplineHelper { if (waypoints.size() > 1) { waypoints.emplace(waypoints.begin(), - Translation2d{wpi::units::meter_t{xInitial[0]}, - wpi::units::meter_t{yInitial[0]}}); - waypoints.emplace_back(Translation2d{wpi::units::meter_t{xFinal[0]}, - wpi::units::meter_t{yFinal[0]}}); + Translation2d{wpi::units::meters<>{xInitial[0]}, + wpi::units::meters<>{yInitial[0]}}); + waypoints.emplace_back(Translation2d{wpi::units::meters<>{xFinal[0]}, + wpi::units::meters<>{yFinal[0]}}); // Populate tridiagonal system for clamped cubic /* See: diff --git a/wpimath/src/main/native/include/wpi/math/spline/SplineParameterizer.hpp b/wpimath/src/main/native/include/wpi/math/spline/SplineParameterizer.hpp index 8ec810ab68f..45252a729dc 100644 --- a/wpimath/src/main/native/include/wpi/math/spline/SplineParameterizer.hpp +++ b/wpimath/src/main/native/include/wpi/math/spline/SplineParameterizer.hpp @@ -38,7 +38,6 @@ #include "wpi/units/angle.hpp" #include "wpi/units/curvature.hpp" #include "wpi/units/length.hpp" -#include "wpi/units/math.hpp" #include "wpi/util/SymbolExports.hpp" namespace wpi::math { @@ -108,9 +107,9 @@ class WPILIB_DLLEXPORT SplineParameterizer { const auto twist = (end.value().first - start.value().first).Log(); - if (wpi::units::math::abs(twist.dy) > MAX_DY || - wpi::units::math::abs(twist.dx) > MAX_DX || - wpi::units::math::abs(twist.dtheta) > MAX_DTHETA) { + if (wpi::units::abs(twist.dy) > MAX_DY || + wpi::units::abs(twist.dx) > MAX_DX || + wpi::units::abs(twist.dtheta) > MAX_DTHETA) { stack.emplace(StackContents{(current.t0 + current.t1) / 2, current.t1}); stack.emplace(StackContents{current.t0, (current.t0 + current.t1) / 2}); } else { @@ -127,9 +126,9 @@ class WPILIB_DLLEXPORT SplineParameterizer { private: // Constraints for spline parameterization. - static inline constexpr wpi::units::meter_t MAX_DX = 5_in; - static inline constexpr wpi::units::meter_t MAX_DY = 0.05_in; - static inline constexpr wpi::units::radian_t MAX_DTHETA = 0.0872_rad; + static inline constexpr wpi::units::meters<> MAX_DX = 5_in; + static inline constexpr wpi::units::meters<> MAX_DY = 0.05_in; + static inline constexpr wpi::units::radians<> MAX_DTHETA = 0.0872_rad; struct StackContents { double t0; diff --git a/wpimath/src/main/native/include/wpi/math/system/DCMotor.hpp b/wpimath/src/main/native/include/wpi/math/system/DCMotor.hpp index 0ea7ad48f51..54ffa03d6c6 100644 --- a/wpimath/src/main/native/include/wpi/math/system/DCMotor.hpp +++ b/wpimath/src/main/native/include/wpi/math/system/DCMotor.hpp @@ -5,7 +5,7 @@ #pragma once #include "wpi/units/angular_velocity.hpp" -#include "wpi/units/base.hpp" +#include "wpi/units/core.hpp" #include "wpi/units/current.hpp" #include "wpi/units/impedance.hpp" #include "wpi/units/torque.hpp" @@ -19,30 +19,32 @@ namespace wpi::math { */ class WPILIB_DLLEXPORT DCMotor { public: - using radians_per_second_per_volt_t = wpi::units::unit_t< - wpi::units::compound_unit>>; + using radians_per_second_per_volt_t = + wpi::units::unit>>; using newton_meters_per_ampere_t = - wpi::units::unit_t>>; + wpi::units::unit>>; /// Voltage at which the motor constants were measured. - wpi::units::volt_t nominalVoltage; + wpi::units::volts<> nominalVoltage; /// Torque when stalled. - wpi::units::newton_meter_t stallTorque; + wpi::units::newton_meters<> stallTorque; /// Current draw when stalled. - wpi::units::ampere_t stallCurrent; + wpi::units::amperes<> stallCurrent; /// Current draw under no load. - wpi::units::ampere_t freeCurrent; + wpi::units::amperes<> freeCurrent; /// Angular velocity under no load. - wpi::units::radians_per_second_t freeSpeed; + wpi::units::radians_per_second<> freeSpeed; /// Motor internal resistance. - wpi::units::ohm_t R; + wpi::units::ohms<> R; /// Motor velocity constant. radians_per_second_per_volt_t Kv; @@ -60,11 +62,11 @@ class WPILIB_DLLEXPORT DCMotor { * @param freeSpeed Angular velocity under no load. * @param numMotors Number of motors in a gearbox. */ - constexpr DCMotor(wpi::units::volt_t nominalVoltage, - wpi::units::newton_meter_t stallTorque, - wpi::units::ampere_t stallCurrent, - wpi::units::ampere_t freeCurrent, - wpi::units::radians_per_second_t freeSpeed, + constexpr DCMotor(wpi::units::volts<> nominalVoltage, + wpi::units::newton_meters<> stallTorque, + wpi::units::amperes<> stallCurrent, + wpi::units::amperes<> freeCurrent, + wpi::units::radians_per_second<> freeSpeed, int numMotors = 1) : nominalVoltage(nominalVoltage), stallTorque(stallTorque * numMotors), @@ -81,9 +83,9 @@ class WPILIB_DLLEXPORT DCMotor { * @param velocity The current angular velocity of the motor. * @param inputVoltage The voltage being applied to the motor. */ - constexpr wpi::units::ampere_t Current( - wpi::units::radians_per_second_t velocity, - wpi::units::volt_t inputVoltage) const { + constexpr wpi::units::amperes<> Current( + wpi::units::radians_per_second<> velocity, + wpi::units::volts<> inputVoltage) const { return -1.0 / Kv / R * velocity + 1.0 / R * inputVoltage; } @@ -92,8 +94,8 @@ class WPILIB_DLLEXPORT DCMotor { * * @param torque The torque produced by the motor. */ - constexpr wpi::units::ampere_t Current( - wpi::units::newton_meter_t torque) const { + constexpr wpi::units::amperes<> Current( + wpi::units::newton_meters<> torque) const { return torque / Kt; } @@ -102,8 +104,8 @@ class WPILIB_DLLEXPORT DCMotor { * * @param current The current drawn by the motor. */ - constexpr wpi::units::newton_meter_t Torque( - wpi::units::ampere_t current) const { + constexpr wpi::units::newton_meters<> Torque( + wpi::units::amperes<> current) const { return current * Kt; } @@ -114,9 +116,9 @@ class WPILIB_DLLEXPORT DCMotor { * @param torque The torque produced by the motor. * @param velocity The current angular velocity of the motor. */ - constexpr wpi::units::volt_t Voltage( - wpi::units::newton_meter_t torque, - wpi::units::radians_per_second_t velocity) const { + constexpr wpi::units::volts<> Voltage( + wpi::units::newton_meters<> torque, + wpi::units::radians_per_second<> velocity) const { return 1.0 / Kv * velocity + 1.0 / Kt * R * torque; } @@ -127,9 +129,9 @@ class WPILIB_DLLEXPORT DCMotor { * @param torque The torque produced by the motor. * @param inputVoltage The input voltage provided to the motor. */ - constexpr wpi::units::radians_per_second_t Velocity( - wpi::units::newton_meter_t torque, - wpi::units::volt_t inputVoltage) const { + constexpr wpi::units::radians_per_second<> Velocity( + wpi::units::newton_meters<> torque, + wpi::units::volts<> inputVoltage) const { return inputVoltage * Kv - 1.0 / Kt * torque * R * Kv; } diff --git a/wpimath/src/main/native/include/wpi/math/system/Discretization.hpp b/wpimath/src/main/native/include/wpi/math/system/Discretization.hpp index 7b59f481e84..6d6a1b9f190 100644 --- a/wpimath/src/main/native/include/wpi/math/system/Discretization.hpp +++ b/wpimath/src/main/native/include/wpi/math/system/Discretization.hpp @@ -20,7 +20,7 @@ namespace wpi::math { * @param discA Storage for discrete system matrix. */ template -void DiscretizeA(const Matrixd& contA, wpi::units::second_t dt, +void DiscretizeA(const Matrixd& contA, wpi::units::seconds<> dt, Matrixd* discA) { // A_d = eᴬᵀ *discA = (contA * dt.value()).exp(); @@ -39,8 +39,8 @@ void DiscretizeA(const Matrixd& contA, wpi::units::second_t dt, */ template void DiscretizeAB(const Matrixd& contA, - const Matrixd& contB, wpi::units::second_t dt, - Matrixd* discA, + const Matrixd& contB, + wpi::units::seconds<> dt, Matrixd* discA, Matrixd* discB) { // M = [A B] // [0 0] @@ -69,8 +69,8 @@ void DiscretizeAB(const Matrixd& contA, */ template void DiscretizeAQ(const Matrixd& contA, - const Matrixd& contQ, wpi::units::second_t dt, - Matrixd* discA, + const Matrixd& contQ, + wpi::units::seconds<> dt, Matrixd* discA, Matrixd* discQ) { // Make continuous Q symmetric if it isn't already Matrixd Q = (contQ + contQ.transpose()) / 2.0; @@ -111,7 +111,7 @@ void DiscretizeAQ(const Matrixd& contA, */ template Matrixd DiscretizeR(const Matrixd& R, - wpi::units::second_t dt) { + wpi::units::seconds<> dt) { // R_d = 1/T R return R / dt.value(); } diff --git a/wpimath/src/main/native/include/wpi/math/system/LinearSystem.hpp b/wpimath/src/main/native/include/wpi/math/system/LinearSystem.hpp index 28962fb5e2a..8f9ca95b245 100644 --- a/wpimath/src/main/native/include/wpi/math/system/LinearSystem.hpp +++ b/wpimath/src/main/native/include/wpi/math/system/LinearSystem.hpp @@ -162,7 +162,7 @@ class LinearSystem { * @param dt Timestep for model update. */ StateVector CalculateX(const StateVector& x, const InputVector& clampedU, - wpi::units::second_t dt) const { + wpi::units::seconds<> dt) const { Matrixd discA; Matrixd discB; DiscretizeAB(m_A, m_B, dt, &discA, &discB); diff --git a/wpimath/src/main/native/include/wpi/math/system/LinearSystemLoop.hpp b/wpimath/src/main/native/include/wpi/math/system/LinearSystemLoop.hpp index 253df778406..aee0deb21c0 100644 --- a/wpimath/src/main/native/include/wpi/math/system/LinearSystemLoop.hpp +++ b/wpimath/src/main/native/include/wpi/math/system/LinearSystemLoop.hpp @@ -59,7 +59,7 @@ class LinearSystemLoop { LinearSystemLoop(LinearSystem& plant, LinearQuadraticRegulator& controller, KalmanFilter& observer, - wpi::units::volt_t maxVoltage, wpi::units::second_t dt) + wpi::units::volts<> maxVoltage, wpi::units::seconds<> dt) : LinearSystemLoop( plant, controller, observer, [=](const InputVector& u) { @@ -84,7 +84,7 @@ class LinearSystemLoop { LinearQuadraticRegulator& controller, KalmanFilter& observer, std::function clampFunction, - wpi::units::second_t dt) + wpi::units::seconds<> dt) : LinearSystemLoop( controller, LinearPlantInversionFeedforward{plant, dt}, @@ -105,7 +105,7 @@ class LinearSystemLoop { LinearQuadraticRegulator& controller, const LinearPlantInversionFeedforward& feedforward, KalmanFilter& observer, - wpi::units::volt_t maxVoltage) + wpi::units::volts<> maxVoltage) : LinearSystemLoop(controller, feedforward, observer, [=](const InputVector& u) { return wpi::math::DesaturateInputVector( @@ -272,7 +272,7 @@ class LinearSystemLoop { * * @param dt Timestep for model update. */ - void Predict(wpi::units::second_t dt) { + void Predict(wpi::units::seconds<> dt) { InputVector u = ClampInput(m_controller->Calculate(m_observer->Xhat(), m_nextR) + m_feedforward.Calculate(m_nextR)); diff --git a/wpimath/src/main/native/include/wpi/math/system/Models.hpp b/wpimath/src/main/native/include/wpi/math/system/Models.hpp index 5e322e4a712..64d3aed37de 100644 --- a/wpimath/src/main/native/include/wpi/math/system/Models.hpp +++ b/wpimath/src/main/native/include/wpi/math/system/Models.hpp @@ -16,7 +16,7 @@ #include "wpi/units/angle.hpp" #include "wpi/units/angular_acceleration.hpp" #include "wpi/units/angular_velocity.hpp" -#include "wpi/units/base.hpp" +#include "wpi/units/core.hpp" #include "wpi/units/length.hpp" #include "wpi/units/mass.hpp" #include "wpi/units/moment_of_inertia.hpp" @@ -32,14 +32,15 @@ namespace wpi::math { class WPILIB_DLLEXPORT Models { public: template - using Velocity_t = wpi::units::unit_t>>; + using Velocity_t = wpi::units::unit>>; template - using Acceleration_t = wpi::units::unit_t>, - wpi::units::inverse>>; + using Acceleration_t = + wpi::units::unit>, + wpi::units::inverse>>; /** * Creates a flywheel state-space model from physical constants. @@ -54,7 +55,7 @@ class WPILIB_DLLEXPORT Models { * @throws std::domain_error if J <= 0 or gearing <= 0. */ static constexpr LinearSystem<1, 1, 1> FlywheelFromPhysicalConstants( - DCMotor motor, wpi::units::kilogram_square_meter_t J, double gearing) { + DCMotor motor, wpi::units::kilogram_square_meters<> J, double gearing) { if (J <= 0_kg_sq_m) { throw std::domain_error("J must be greater than zero."); } @@ -116,7 +117,7 @@ class WPILIB_DLLEXPORT Models { * @throws std::domain_error if mass <= 0, radius <= 0, or gearing <= 0. */ static constexpr LinearSystem<2, 1, 2> ElevatorFromPhysicalConstants( - DCMotor motor, wpi::units::kilogram_t mass, wpi::units::meter_t radius, + DCMotor motor, wpi::units::kilograms<> mass, wpi::units::meters<> radius, double gearing) { if (mass <= 0_kg) { throw std::domain_error("mass must be greater than zero."); @@ -131,7 +132,7 @@ class WPILIB_DLLEXPORT Models { Matrixd<2, 2> A{ {0.0, 1.0}, {0.0, (-gcem::pow(gearing, 2) * motor.Kt / - (motor.R * wpi::units::math::pow<2>(radius) * mass * motor.Kv)) + (motor.R * wpi::units::pow<2>(radius) * mass * motor.Kv)) .value()}}; Matrixd<2, 1> B{{0.0}, {(gearing * motor.Kt / (motor.R * radius * mass)).value()}}; @@ -156,7 +157,7 @@ class WPILIB_DLLEXPORT Models { * href="https://github.com/wpilibsuite/allwpilib/tree/main/sysid">https://github.com/wpilibsuite/allwpilib/tree/main/sysid */ static constexpr LinearSystem<2, 1, 2> ElevatorFromSysId( - decltype(1_V / 1_mps) kV, decltype(1_V / 1_mps_sq) kA) { + decltype(1_V / 1_mps) kV, decltype(1_V / 1_mps2) kA) { if (kV < decltype(kV){0}) { throw std::domain_error("Kv must be greater than or equal to zero."); } @@ -185,7 +186,7 @@ class WPILIB_DLLEXPORT Models { * @throws std::domain_error if J <= 0 or gearing <= 0. */ static constexpr LinearSystem<2, 1, 2> SingleJointedArmFromPhysicalConstants( - DCMotor motor, wpi::units::kilogram_square_meter_t J, double gearing) { + DCMotor motor, wpi::units::kilogram_square_meters<> J, double gearing) { if (J <= 0_kg_sq_m) { throw std::domain_error("J must be greater than zero."); } @@ -253,9 +254,9 @@ class WPILIB_DLLEXPORT Models { * gearing <= 0. */ static constexpr LinearSystem<2, 2, 2> DifferentialDriveFromPhysicalConstants( - const DCMotor& motor, wpi::units::kilogram_t mass, wpi::units::meter_t r, - wpi::units::meter_t rb, wpi::units::kilogram_square_meter_t J, - double gearing) { + const DCMotor& motor, wpi::units::kilograms<> mass, + wpi::units::meters<> r, wpi::units::meters<> rb, + wpi::units::kilogram_square_meters<> J, double gearing) { if (mass <= 0_kg) { throw std::domain_error("mass must be greater than zero."); } @@ -273,19 +274,17 @@ class WPILIB_DLLEXPORT Models { } auto C1 = -gcem::pow(gearing, 2) * motor.Kt / - (motor.Kv * motor.R * wpi::units::math::pow<2>(r)); + (motor.Kv * motor.R * wpi::units::pow<2>(r)); auto C2 = gearing * motor.Kt / (motor.R * r); - Matrixd<2, 2> A{ - {((1 / mass + wpi::units::math::pow<2>(rb) / J) * C1).value(), - ((1 / mass - wpi::units::math::pow<2>(rb) / J) * C1).value()}, - {((1 / mass - wpi::units::math::pow<2>(rb) / J) * C1).value(), - ((1 / mass + wpi::units::math::pow<2>(rb) / J) * C1).value()}}; - Matrixd<2, 2> B{ - {((1 / mass + wpi::units::math::pow<2>(rb) / J) * C2).value(), - ((1 / mass - wpi::units::math::pow<2>(rb) / J) * C2).value()}, - {((1 / mass - wpi::units::math::pow<2>(rb) / J) * C2).value(), - ((1 / mass + wpi::units::math::pow<2>(rb) / J) * C2).value()}}; + Matrixd<2, 2> A{{((1 / mass + wpi::units::pow<2>(rb) / J) * C1).value(), + ((1 / mass - wpi::units::pow<2>(rb) / J) * C1).value()}, + {((1 / mass - wpi::units::pow<2>(rb) / J) * C1).value(), + ((1 / mass + wpi::units::pow<2>(rb) / J) * C1).value()}}; + Matrixd<2, 2> B{{((1 / mass + wpi::units::pow<2>(rb) / J) * C2).value(), + ((1 / mass - wpi::units::pow<2>(rb) / J) * C2).value()}, + {((1 / mass - wpi::units::pow<2>(rb) / J) * C2).value(), + ((1 / mass + wpi::units::pow<2>(rb) / J) * C2).value()}}; Matrixd<2, 2> C{{1.0, 0.0}, {0.0, 1.0}}; Matrixd<2, 2> D{{0.0, 0.0}, {0.0, 0.0}}; @@ -315,8 +314,8 @@ class WPILIB_DLLEXPORT Models { * href="https://github.com/wpilibsuite/allwpilib/tree/main/sysid">https://github.com/wpilibsuite/allwpilib/tree/main/sysid */ static constexpr LinearSystem<2, 2, 2> DifferentialDriveFromSysId( - decltype(1_V / 1_mps) kvLinear, decltype(1_V / 1_mps_sq) kaLinear, - decltype(1_V / 1_mps) kvAngular, decltype(1_V / 1_mps_sq) kaAngular) { + decltype(1_V / 1_mps) kvLinear, decltype(1_V / 1_mps2) kaLinear, + decltype(1_V / 1_mps) kvAngular, decltype(1_V / 1_mps2) kaAngular) { if (kvLinear <= decltype(kvLinear){0}) { throw std::domain_error("Kv,linear must be greater than zero."); } @@ -370,10 +369,10 @@ class WPILIB_DLLEXPORT Models { * href="https://github.com/wpilibsuite/allwpilib/tree/main/sysid">https://github.com/wpilibsuite/allwpilib/tree/main/sysid */ static constexpr LinearSystem<2, 2, 2> DifferentialDriveFromSysId( - decltype(1_V / 1_mps) kvLinear, decltype(1_V / 1_mps_sq) kaLinear, + decltype(1_V / 1_mps) kvLinear, decltype(1_V / 1_mps2) kaLinear, decltype(1_V / 1_rad_per_s) kvAngular, decltype(1_V / 1_rad_per_s_sq) kaAngular, - wpi::units::meter_t trackwidth) { + wpi::units::meters<> trackwidth) { if (kvLinear <= decltype(kvLinear){0}) { throw std::domain_error("Kv,linear must be greater than zero."); } diff --git a/wpimath/src/main/native/include/wpi/math/system/NumericalIntegration.hpp b/wpimath/src/main/native/include/wpi/math/system/NumericalIntegration.hpp index 1f5a849052e..848629a6b65 100644 --- a/wpimath/src/main/native/include/wpi/math/system/NumericalIntegration.hpp +++ b/wpimath/src/main/native/include/wpi/math/system/NumericalIntegration.hpp @@ -20,7 +20,7 @@ namespace wpi::math { * @param dt The time over which to integrate. */ template -T RK4(F&& f, T x, wpi::units::second_t dt) { +T RK4(F&& f, T x, wpi::units::seconds<> dt) { const auto h = dt.value(); T k1 = f(x); @@ -40,7 +40,7 @@ T RK4(F&& f, T x, wpi::units::second_t dt) { * @param dt The time over which to integrate. */ template -T RK4(F&& f, T x, U u, wpi::units::second_t dt) { +T RK4(F&& f, T x, U u, wpi::units::seconds<> dt) { const auto h = dt.value(); T k1 = f(x, u); @@ -60,7 +60,7 @@ T RK4(F&& f, T x, U u, wpi::units::second_t dt) { * @param dt The time over which to integrate. */ template -T RK4(F&& f, wpi::units::second_t t, T y, wpi::units::second_t dt) { +T RK4(F&& f, wpi::units::seconds<> t, T y, wpi::units::seconds<> dt) { const auto h = dt.value(); T k1 = f(t, y); @@ -83,7 +83,7 @@ T RK4(F&& f, wpi::units::second_t t, T y, wpi::units::second_t dt) { * number like 1e-6. */ template -T RKDP(F&& f, T x, U u, wpi::units::second_t dt, double maxError = 1e-6) { +T RKDP(F&& f, T x, U u, wpi::units::seconds<> dt, double maxError = 1e-6) { // See https://en.wikipedia.org/wiki/Dormand%E2%80%93Prince_method for the // Butcher tableau the following arrays came from. @@ -161,7 +161,7 @@ T RKDP(F&& f, T x, U u, wpi::units::second_t dt, double maxError = 1e-6) { * number like 1e-6. */ template -T RKDP(F&& f, wpi::units::second_t t, T y, wpi::units::second_t dt, +T RKDP(F&& f, wpi::units::seconds<> t, T y, wpi::units::seconds<> dt, double maxError = 1e-6) { // See https://en.wikipedia.org/wiki/Dormand%E2%80%93Prince_method for the // Butcher tableau the following arrays came from. @@ -195,18 +195,18 @@ T RKDP(F&& f, wpi::units::second_t t, T y, wpi::units::second_t dt, while (dtElapsed < dt.value()) { // clang-format off T k1 = f(t, y); - T k2 = f(t + wpi::units::second_t{h} * c[0], y + h * (A[0][0] * k1)); - T k3 = f(t + wpi::units::second_t{h} * c[1], y + h * (A[1][0] * k1 + A[1][1] * k2)); - T k4 = f(t + wpi::units::second_t{h} * c[2], y + h * (A[2][0] * k1 + A[2][1] * k2 + A[2][2] * k3)); - T k5 = f(t + wpi::units::second_t{h} * c[3], y + h * (A[3][0] * k1 + A[3][1] * k2 + A[3][2] * k3 + A[3][3] * k4)); - T k6 = f(t + wpi::units::second_t{h} * c[4], y + h * (A[4][0] * k1 + A[4][1] * k2 + A[4][2] * k3 + A[4][3] * k4 + A[4][4] * k5)); + T k2 = f(t + wpi::units::seconds<>{h} * c[0], y + h * (A[0][0] * k1)); + T k3 = f(t + wpi::units::seconds<>{h} * c[1], y + h * (A[1][0] * k1 + A[1][1] * k2)); + T k4 = f(t + wpi::units::seconds<>{h} * c[2], y + h * (A[2][0] * k1 + A[2][1] * k2 + A[2][2] * k3)); + T k5 = f(t + wpi::units::seconds<>{h} * c[3], y + h * (A[3][0] * k1 + A[3][1] * k2 + A[3][2] * k3 + A[3][3] * k4)); + T k6 = f(t + wpi::units::seconds<>{h} * c[4], y + h * (A[4][0] * k1 + A[4][1] * k2 + A[4][2] * k3 + A[4][3] * k4 + A[4][4] * k5)); // clang-format on // Since the final row of A and the array b1 have the same coefficients and // k7 has no effect on newY, we can reuse the calculation. T newY = y + h * (A[5][0] * k1 + A[5][1] * k2 + A[5][2] * k3 + A[5][3] * k4 + A[5][4] * k5 + A[5][5] * k6); - T k7 = f(t + wpi::units::second_t{h} * c[5], newY); + T k7 = f(t + wpi::units::seconds<>{h} * c[5], newY); double truncationError = (h * ((b1[0] - b2[0]) * k1 + (b1[1] - b2[1]) * k2 + (b1[2] - b2[2]) * k3 + (b1[3] - b2[3]) * k4 + diff --git a/wpimath/src/main/native/include/wpi/math/trajectory/DifferentialSample.hpp b/wpimath/src/main/native/include/wpi/math/trajectory/DifferentialSample.hpp index 68f0d363633..2c5ca81ccb6 100644 --- a/wpimath/src/main/native/include/wpi/math/trajectory/DifferentialSample.hpp +++ b/wpimath/src/main/native/include/wpi/math/trajectory/DifferentialSample.hpp @@ -28,12 +28,12 @@ class DifferentialSample : public HolonomicSample { /** * The left wheel velocity at this sample. */ - wpi::units::meters_per_second_t leftVelocity{0_mps}; + wpi::units::meters_per_second<> leftVelocity{0_mps}; /** * The right wheel velocity at this sample. */ - wpi::units::meters_per_second_t rightVelocity{0_mps}; + wpi::units::meters_per_second<> rightVelocity{0_mps}; /** Constructs a default DifferentialSample with all zero values. */ constexpr DifferentialSample() = default; @@ -50,11 +50,11 @@ class DifferentialSample : public HolonomicSample { * @param leftVelocity The left wheel velocity at this sample. * @param rightVelocity The right wheel velocity at this sample. */ - constexpr DifferentialSample(wpi::units::second_t time, const Pose2d& pose, + constexpr DifferentialSample(wpi::units::seconds<> time, const Pose2d& pose, const ChassisVelocities& velocity, const ChassisAccelerations& acceleration, - wpi::units::meters_per_second_t leftVelocity, - wpi::units::meters_per_second_t rightVelocity) + wpi::units::meters_per_second<> leftVelocity, + wpi::units::meters_per_second<> rightVelocity) : HolonomicSample{time, pose, velocity, acceleration}, leftVelocity{leftVelocity}, rightVelocity{rightVelocity} {} @@ -70,7 +70,7 @@ class DifferentialSample : public HolonomicSample { * reference frame). * @param kinematics The kinematics of the drivetrain. */ - constexpr DifferentialSample(wpi::units::second_t time, const Pose2d& pose, + constexpr DifferentialSample(wpi::units::seconds<> time, const Pose2d& pose, const ChassisVelocities& velocity, const ChassisAccelerations& acceleration, const DifferentialDriveKinematics& kinematics) @@ -90,8 +90,8 @@ class DifferentialSample : public HolonomicSample { * @param rightVelocity The right wheel velocity at this sample. */ constexpr DifferentialSample(const HolonomicSample& sample, - wpi::units::meters_per_second_t leftVelocity, - wpi::units::meters_per_second_t rightVelocity) + wpi::units::meters_per_second<> leftVelocity, + wpi::units::meters_per_second<> rightVelocity) : DifferentialSample{sample.time, sample.pose, sample.velocity, sample.acceleration, leftVelocity, rightVelocity} {} diff --git a/wpimath/src/main/native/include/wpi/math/trajectory/DrivetrainSplineSample.hpp b/wpimath/src/main/native/include/wpi/math/trajectory/DrivetrainSplineSample.hpp index 495892092c4..8ddf53532f4 100644 --- a/wpimath/src/main/native/include/wpi/math/trajectory/DrivetrainSplineSample.hpp +++ b/wpimath/src/main/native/include/wpi/math/trajectory/DrivetrainSplineSample.hpp @@ -47,16 +47,16 @@ class DrivetrainSplineSample : public HolonomicSample { * @param curvature The curvature of the path at this sample. */ constexpr DrivetrainSplineSample( - wpi::units::second_t time, const Pose2d& pose, - wpi::units::meters_per_second_t velocity, - wpi::units::meters_per_second_squared_t acceleration, + wpi::units::seconds<> time, const Pose2d& pose, + wpi::units::meters_per_second<> velocity, + wpi::units::meters_per_second_squared<> acceleration, wpi::units::curvature_t curvature) - : HolonomicSample{time, pose, - ChassisVelocities{velocity, 0_mps, velocity * curvature} - .ToFieldRelative(pose.Rotation()), - ChassisAccelerations{acceleration, 0_mps_sq, - acceleration * curvature} - .ToFieldRelative(pose.Rotation())}, + : HolonomicSample{ + time, pose, + ChassisVelocities{velocity, 0_mps, velocity * curvature} + .ToFieldRelative(pose.Rotation()), + ChassisAccelerations{acceleration, 0_mps2, acceleration * curvature} + .ToFieldRelative(pose.Rotation())}, curvature{curvature} {} /** @@ -70,7 +70,7 @@ class DrivetrainSplineSample : public HolonomicSample { * reference frame). * @param curvature The curvature of the path at this sample. */ - constexpr DrivetrainSplineSample(wpi::units::second_t time, + constexpr DrivetrainSplineSample(wpi::units::seconds<> time, const Pose2d& pose, const ChassisVelocities& velocity, const ChassisAccelerations& acceleration, @@ -98,7 +98,7 @@ class DrivetrainSplineSample : public HolonomicSample { * * @return The forward velocity. */ - constexpr wpi::units::meters_per_second_t ForwardVelocity() const { + constexpr wpi::units::meters_per_second<> ForwardVelocity() const { return velocity.ToRobotRelative(pose.Rotation()).vx; } @@ -109,7 +109,7 @@ class DrivetrainSplineSample : public HolonomicSample { * * @return The forward acceleration. */ - constexpr wpi::units::meters_per_second_squared_t ForwardAcceleration() + constexpr wpi::units::meters_per_second_squared<> ForwardAcceleration() const { return acceleration.ToRobotRelative(pose.Rotation()).ax; } diff --git a/wpimath/src/main/native/include/wpi/math/trajectory/DrivetrainSplineTrajectoryParameterizer.hpp b/wpimath/src/main/native/include/wpi/math/trajectory/DrivetrainSplineTrajectoryParameterizer.hpp index c565dcdee84..4648cfbdac9 100644 --- a/wpimath/src/main/native/include/wpi/math/trajectory/DrivetrainSplineTrajectoryParameterizer.hpp +++ b/wpimath/src/main/native/include/wpi/math/trajectory/DrivetrainSplineTrajectoryParameterizer.hpp @@ -71,10 +71,10 @@ class WPILIB_DLLEXPORT DrivetrainSplineTrajectoryParameterizer { static DrivetrainSplineTrajectory Parameterize( const std::vector& points, const std::vector>& constraints, - wpi::units::meters_per_second_t startVelocity, - wpi::units::meters_per_second_t endVelocity, - wpi::units::meters_per_second_t maxVelocity, - wpi::units::meters_per_second_squared_t maxAcceleration, bool reversed); + wpi::units::meters_per_second<> startVelocity, + wpi::units::meters_per_second<> endVelocity, + wpi::units::meters_per_second<> maxVelocity, + wpi::units::meters_per_second_squared<> maxAcceleration, bool reversed); private: constexpr static double EPSILON = 1E-6; @@ -86,10 +86,10 @@ class WPILIB_DLLEXPORT DrivetrainSplineTrajectoryParameterizer { */ struct ConstrainedState { PoseWithCurvature pose = {Pose2d{}, wpi::units::curvature_t{0.0}}; - wpi::units::meter_t distance = 0_m; - wpi::units::meters_per_second_t maxVelocity = 0_mps; - wpi::units::meters_per_second_squared_t minAcceleration = 0_mps_sq; - wpi::units::meters_per_second_squared_t maxAcceleration = 0_mps_sq; + wpi::units::meters<> distance = 0_m; + wpi::units::meters_per_second<> maxVelocity = 0_mps; + wpi::units::meters_per_second_squared<> minAcceleration = 0_mps2; + wpi::units::meters_per_second_squared<> maxAcceleration = 0_mps2; }; /** diff --git a/wpimath/src/main/native/include/wpi/math/trajectory/ExponentialProfile.hpp b/wpimath/src/main/native/include/wpi/math/trajectory/ExponentialProfile.hpp index 3915f29c145..f1dd6606583 100644 --- a/wpimath/src/main/native/include/wpi/math/trajectory/ExponentialProfile.hpp +++ b/wpimath/src/main/native/include/wpi/math/trajectory/ExponentialProfile.hpp @@ -4,8 +4,8 @@ #pragma once -#include "wpi/units/base.hpp" -#include "wpi/units/math.hpp" +#include "wpi/units/core.hpp" +#include "wpi/units/frequency.hpp" #include "wpi/units/time.hpp" namespace wpi::math { @@ -41,23 +41,24 @@ namespace wpi::math { template class ExponentialProfile { public: - using Distance_t = wpi::units::unit_t; - using Velocity = - wpi::units::compound_unit>; - using Velocity_t = wpi::units::unit_t; - using Acceleration = - wpi::units::compound_unit>; - using Input_t = wpi::units::unit_t; - using A_t = wpi::units::unit_t>; - using B_t = wpi::units::unit_t< - wpi::units::compound_unit>>; - using KV = wpi::units::compound_unit>; - using kV_t = wpi::units::unit_t; + using Distance_t = wpi::units::unit; + using Velocity = wpi::units::compound_conversion_factor< + Distance, wpi::units::inverse>; + using Velocity_t = wpi::units::unit; + using Acceleration = wpi::units::compound_conversion_factor< + Velocity, wpi::units::inverse>; + using Input_t = wpi::units::unit; + using A_t = wpi::units::hertz<>; + using B_t = wpi::units::unit>>; + using KV = + wpi::units::compound_conversion_factor>; + using kV_t = wpi::units::unit; using KA = - wpi::units::compound_unit>; - using kA_t = wpi::units::unit_t; + wpi::units::compound_conversion_factor>; + using kA_t = wpi::units::unit; /** * Profile timing. @@ -65,10 +66,10 @@ class ExponentialProfile { class ProfileTiming { public: /// Profile inflection time. - wpi::units::second_t inflectionTime; + wpi::units::seconds<> inflectionTime; /// Total profile time. - wpi::units::second_t totalTime; + wpi::units::seconds<> totalTime; /** * Decides if the profile is finished by time t. @@ -76,7 +77,7 @@ class ExponentialProfile { * @param t The time since the beginning of the profile. * @return if the profile is finished at time t. */ - constexpr bool IsFinished(const wpi::units::second_t& t) const { + constexpr bool IsFinished(const wpi::units::seconds<>& t) const { return t >= totalTime; } }; @@ -158,8 +159,8 @@ class ExponentialProfile { * @param goal The desired state when the profile is complete. * @return The position and velocity of the profile at time t. */ - constexpr State Calculate(const wpi::units::second_t& t, const State& current, - const State& goal) const { + constexpr State Calculate(const wpi::units::seconds<>& t, + const State& current, const State& goal) const { auto direction = ShouldFlipInput(current, goal) ? -1 : 1; auto u = direction * m_constraints.maxInput; @@ -202,8 +203,8 @@ class ExponentialProfile { * @param goal The desired state when the profile is complete. * @return The total duration of this profile. */ - constexpr wpi::units::second_t TimeLeftUntil(const State& current, - const State& goal) const { + constexpr wpi::units::seconds<> TimeLeftUntil(const State& current, + const State& goal) const { auto timing = CalculateProfileTiming(current, goal); return timing.totalTime; @@ -269,9 +270,9 @@ class ExponentialProfile { const State& goal, const Input_t& input) const { auto u = input; - auto u_dir = wpi::units::math::abs(u) / u; + auto u_dir = wpi::units::abs(u) / u; - wpi::units::second_t inflectionT_forward; + wpi::units::seconds<> inflectionT_forward; // We need to handle 5 cases here: // @@ -285,18 +286,17 @@ class ExponentialProfile { // velocity For cases 2 and 4, we want to add epsilon to the inflection // point velocity. For case 5, we have reached inflection point velocity. auto epsilon = Velocity_t(1e-9); - if (wpi::units::math::abs(u_dir * m_constraints.MaxVelocity() - - inflectionPoint.velocity) < epsilon) { + if (wpi::units::abs(u_dir * m_constraints.MaxVelocity() - + inflectionPoint.velocity) < epsilon) { auto solvableV = inflectionPoint.velocity; - wpi::units::second_t t_to_solvable_v; + wpi::units::seconds<> t_to_solvable_v; Distance_t x_at_solvable_v; - if (wpi::units::math::abs(current.velocity - inflectionPoint.velocity) < + if (wpi::units::abs(current.velocity - inflectionPoint.velocity) < epsilon) { t_to_solvable_v = 0_s; x_at_solvable_v = current.position; } else { - if (wpi::units::math::abs(current.velocity) > - m_constraints.MaxVelocity()) { + if (wpi::units::abs(current.velocity) > m_constraints.MaxVelocity()) { solvableV += u_dir * epsilon; } else { solvableV -= u_dir * epsilon; @@ -332,16 +332,16 @@ class ExponentialProfile { * @param initial The initial state. * @return The distance travelled by this profile. */ - constexpr Distance_t ComputeDistanceFromTime(const wpi::units::second_t& time, - const Input_t& input, - const State& initial) const { + constexpr Distance_t ComputeDistanceFromTime( + const wpi::units::seconds<>& time, const Input_t& input, + const State& initial) const { auto A = m_constraints.A; auto B = m_constraints.B; auto u = input; return initial.position + - (-B * u * time + (initial.velocity + B * u / A) * - (wpi::units::math::exp(A * time) - 1)) / + (-B * u * time + + (initial.velocity + B * u / A) * (wpi::units::exp(A * time) - 1)) / A; } @@ -355,14 +355,14 @@ class ExponentialProfile { * @param initial The initial state. * @return The distance travelled by this profile. */ - constexpr Velocity_t ComputeVelocityFromTime(const wpi::units::second_t& time, - const Input_t& input, - const State& initial) const { + constexpr Velocity_t ComputeVelocityFromTime( + const wpi::units::seconds<>& time, const Input_t& input, + const State& initial) const { auto A = m_constraints.A; auto B = m_constraints.B; auto u = input; - return (initial.velocity + B * u / A) * wpi::units::math::exp(A * time) - + return (initial.velocity + B * u / A) * wpi::units::exp(A * time) - B * u / A; } @@ -376,16 +376,14 @@ class ExponentialProfile { * @param initial The initial velocity. * @return The time required to reach the goal velocity. */ - constexpr wpi::units::second_t ComputeTimeFromVelocity( + constexpr wpi::units::seconds<> ComputeTimeFromVelocity( const Velocity_t& velocity, const Input_t& input, const Velocity_t& initial) const { auto A = m_constraints.A; auto B = m_constraints.B; auto u = input; - return wpi::units::math::log((A * velocity + B * u) / - (A * initial + B * u)) / - A; + return wpi::units::log((A * velocity + B * u) / (A * initial + B * u)) / A; } /** @@ -407,8 +405,8 @@ class ExponentialProfile { return initial.position + (velocity - initial.velocity) / A - B * u / (A * A) * - wpi::units::math::log((A * velocity + B * u) / - (A * initial.velocity + B * u)); + wpi::units::log((A * velocity + B * u) / + (A * initial.velocity + B * u)); } /** @@ -428,7 +426,7 @@ class ExponentialProfile { auto B = m_constraints.B; auto u = input; - auto u_dir = u / wpi::units::math::abs(u); + auto u_dir = u / wpi::units::abs(u); auto position_delta = goal.position - current.position; auto velocity_delta = goal.velocity - current.velocity; @@ -437,7 +435,7 @@ class ExponentialProfile { auto power = -A / B / u * (A * position_delta - velocity_delta); auto a = -A * A; - auto c = B * B * u * u + scalar * wpi::units::math::exp(power); + auto c = B * B * u * u + scalar * wpi::units::exp(power); if (-1e-9 < c.value() && c.value() < 0) { // numeric instability - the heuristic gets it right but c is around @@ -445,7 +443,7 @@ class ExponentialProfile { return Velocity_t(0); } - return u_dir * wpi::units::math::sqrt(-c / a); + return u_dir * wpi::units::sqrt(-c / a); } /** diff --git a/wpimath/src/main/native/include/wpi/math/trajectory/HolonomicSample.hpp b/wpimath/src/main/native/include/wpi/math/trajectory/HolonomicSample.hpp index 0d8da5b99a5..398e5042d1b 100644 --- a/wpimath/src/main/native/include/wpi/math/trajectory/HolonomicSample.hpp +++ b/wpimath/src/main/native/include/wpi/math/trajectory/HolonomicSample.hpp @@ -49,7 +49,7 @@ class HolonomicSample : public TrajectorySample { * @param a The robot acceleration at this sample (in the field reference * frame). */ - constexpr HolonomicSample(wpi::units::second_t time, const Pose2d& p, + constexpr HolonomicSample(wpi::units::seconds<> time, const Pose2d& p, const ChassisVelocities& v, const ChassisAccelerations& a) : TrajectorySample{time}, pose{p}, velocity{v}, acceleration{a} {} diff --git a/wpimath/src/main/native/include/wpi/math/trajectory/Trajectory.hpp b/wpimath/src/main/native/include/wpi/math/trajectory/Trajectory.hpp index 04608523dcd..aad7bcfc28c 100644 --- a/wpimath/src/main/native/include/wpi/math/trajectory/Trajectory.hpp +++ b/wpimath/src/main/native/include/wpi/math/trajectory/Trajectory.hpp @@ -65,7 +65,7 @@ class Trajectory { * * @return The duration of the trajectory. */ - wpi::units::second_t Duration() const { return m_duration; } + wpi::units::seconds<> Duration() const { return m_duration; } /** * Returns the samples of the trajectory. @@ -95,7 +95,7 @@ class Trajectory { * @return The sample at that point in time. * @throws std::runtime_error if the trajectory has no samples. */ - SampleType SampleAt(wpi::units::second_t t) const { + SampleType SampleAt(wpi::units::seconds<> t) const { if (m_samples.empty()) { throw std::runtime_error( "Trajectory cannot be sampled if it has no samples."); @@ -131,7 +131,7 @@ class Trajectory { * @return The sample at that point in time. */ SampleType SampleAt(double t) const { - return SampleAt(wpi::units::second_t{t}); + return SampleAt(wpi::units::seconds<>{t}); } /** @@ -202,8 +202,8 @@ class Trajectory { } std::vector m_samples; - std::map m_sampleMap; - wpi::units::second_t m_duration{0}; + std::map, SampleType> m_sampleMap; + wpi::units::seconds<> m_duration{0}; }; } // namespace wpi::math diff --git a/wpimath/src/main/native/include/wpi/math/trajectory/TrajectoryConfig.hpp b/wpimath/src/main/native/include/wpi/math/trajectory/TrajectoryConfig.hpp index 4ec8621d0c8..2734a054bda 100644 --- a/wpimath/src/main/native/include/wpi/math/trajectory/TrajectoryConfig.hpp +++ b/wpimath/src/main/native/include/wpi/math/trajectory/TrajectoryConfig.hpp @@ -38,8 +38,8 @@ class WPILIB_DLLEXPORT TrajectoryConfig { * @param maxVelocity The max velocity of the trajectory. * @param maxAcceleration The max acceleration of the trajectory. */ - TrajectoryConfig(wpi::units::meters_per_second_t maxVelocity, - wpi::units::meters_per_second_squared_t maxAcceleration) + TrajectoryConfig(wpi::units::meters_per_second<> maxVelocity, + wpi::units::meters_per_second_squared<> maxAcceleration) : m_maxVelocity(maxVelocity), m_maxAcceleration(maxAcceleration) {} TrajectoryConfig(const TrajectoryConfig&) = delete; @@ -52,7 +52,7 @@ class WPILIB_DLLEXPORT TrajectoryConfig { * Sets the start velocity of the trajectory. * @param startVelocity The start velocity of the trajectory. */ - void SetStartVelocity(wpi::units::meters_per_second_t startVelocity) { + void SetStartVelocity(wpi::units::meters_per_second<> startVelocity) { m_startVelocity = startVelocity; } @@ -60,7 +60,7 @@ class WPILIB_DLLEXPORT TrajectoryConfig { * Sets the end velocity of the trajectory. * @param endVelocity The end velocity of the trajectory. */ - void SetEndVelocity(wpi::units::meters_per_second_t endVelocity) { + void SetEndVelocity(wpi::units::meters_per_second<> endVelocity) { m_endVelocity = endVelocity; } @@ -115,7 +115,7 @@ class WPILIB_DLLEXPORT TrajectoryConfig { * Returns the starting velocity of the trajectory. * @return The starting velocity of the trajectory. */ - wpi::units::meters_per_second_t StartVelocity() const { + wpi::units::meters_per_second<> StartVelocity() const { return m_startVelocity; } @@ -123,19 +123,19 @@ class WPILIB_DLLEXPORT TrajectoryConfig { * Returns the ending velocity of the trajectory. * @return The ending velocity of the trajectory. */ - wpi::units::meters_per_second_t EndVelocity() const { return m_endVelocity; } + wpi::units::meters_per_second<> EndVelocity() const { return m_endVelocity; } /** * Returns the maximum velocity of the trajectory. * @return The maximum velocity of the trajectory. */ - wpi::units::meters_per_second_t MaxVelocity() const { return m_maxVelocity; } + wpi::units::meters_per_second<> MaxVelocity() const { return m_maxVelocity; } /** * Returns the maximum acceleration of the trajectory. * @return The maximum acceleration of the trajectory. */ - wpi::units::meters_per_second_squared_t MaxAcceleration() const { + wpi::units::meters_per_second_squared<> MaxAcceleration() const { return m_maxAcceleration; } @@ -155,10 +155,10 @@ class WPILIB_DLLEXPORT TrajectoryConfig { bool IsReversed() const { return m_reversed; } private: - wpi::units::meters_per_second_t m_startVelocity = 0_mps; - wpi::units::meters_per_second_t m_endVelocity = 0_mps; - wpi::units::meters_per_second_t m_maxVelocity; - wpi::units::meters_per_second_squared_t m_maxAcceleration; + wpi::units::meters_per_second<> m_startVelocity = 0_mps; + wpi::units::meters_per_second<> m_endVelocity = 0_mps; + wpi::units::meters_per_second<> m_maxVelocity; + wpi::units::meters_per_second_squared<> m_maxAcceleration; std::vector> m_constraints; bool m_reversed = false; }; diff --git a/wpimath/src/main/native/include/wpi/math/trajectory/TrajectorySample.hpp b/wpimath/src/main/native/include/wpi/math/trajectory/TrajectorySample.hpp index 5ddc2b6f389..6652d90fcef 100644 --- a/wpimath/src/main/native/include/wpi/math/trajectory/TrajectorySample.hpp +++ b/wpimath/src/main/native/include/wpi/math/trajectory/TrajectorySample.hpp @@ -21,7 +21,7 @@ namespace wpi::math { class TrajectorySample { public: /** The time of the sample relative to the trajectory start. */ - wpi::units::second_t time{0.0}; + wpi::units::seconds<> time{0.0}; /** Constructs a default TrajectorySample with all zero values. */ constexpr TrajectorySample() = default; @@ -33,7 +33,8 @@ class TrajectorySample { * * @param time The time of the sample relative to the trajectory start. */ - explicit constexpr TrajectorySample(wpi::units::second_t time) : time{time} {} + explicit constexpr TrajectorySample(wpi::units::seconds<> time) + : time{time} {} /** * Checks equality between this TrajectorySample and another. diff --git a/wpimath/src/main/native/include/wpi/math/trajectory/TrapezoidProfile.hpp b/wpimath/src/main/native/include/wpi/math/trajectory/TrapezoidProfile.hpp index 497f990e046..339752d1c5a 100644 --- a/wpimath/src/main/native/include/wpi/math/trajectory/TrapezoidProfile.hpp +++ b/wpimath/src/main/native/include/wpi/math/trajectory/TrapezoidProfile.hpp @@ -9,8 +9,7 @@ #include #include "wpi/math/util/MathShared.hpp" -#include "wpi/units/base.hpp" -#include "wpi/units/math.hpp" +#include "wpi/units/core.hpp" #include "wpi/units/time.hpp" #include "wpi/util/UsageReporting.hpp" @@ -23,14 +22,12 @@ namespace detail { template class TrapezoidProfileConstraints { public: - using Velocity = - wpi::units::compound_unit>; - using Velocity_t = wpi::units::unit_t; - using Acceleration = - wpi::units::compound_unit>; - using Acceleration_t = wpi::units::unit_t; + using Velocity = wpi::units::compound_conversion_factor< + Distance, wpi::units::inverse>; + using Velocity_t = wpi::units::unit; + using Acceleration = wpi::units::compound_conversion_factor< + Velocity, wpi::units::inverse>; + using Acceleration_t = wpi::units::unit; /// Maximum velocity. Velocity_t maxVelocity{0}; @@ -91,15 +88,13 @@ class TrapezoidProfileConstraints { template class TrapezoidProfile { public: - using Distance_t = wpi::units::unit_t; - using Velocity = - wpi::units::compound_unit>; - using Velocity_t = wpi::units::unit_t; - using Acceleration = - wpi::units::compound_unit>; - using Acceleration_t = wpi::units::unit_t; + using Distance_t = wpi::units::unit; + using Velocity = wpi::units::compound_conversion_factor< + Distance, wpi::units::inverse>; + using Velocity_t = wpi::units::unit; + using Acceleration = wpi::units::compound_conversion_factor< + Velocity, wpi::units::inverse>; + using Acceleration_t = wpi::units::unit; using Constraints = detail::TrapezoidProfileConstraints; @@ -123,11 +118,11 @@ class TrapezoidProfile { class ProfileTiming { public: /// The time the profile spends in the first leg. - wpi::units::second_t t_1; + wpi::units::seconds<> t_1; /// The time the profile spends at the velocity limit. - wpi::units::second_t t_2; + wpi::units::seconds<> t_2; /// The time the profile spends in the last leg. - wpi::units::second_t t_3; + wpi::units::seconds<> t_3; constexpr bool operator==(const ProfileTiming&) const = default; }; @@ -155,14 +150,15 @@ class TrapezoidProfile { * @param goal The desired state when the profile is complete. * @return The position and velocity of the profile at time t. */ - constexpr State Calculate(wpi::units::second_t t, State current, State goal) { + constexpr State Calculate(wpi::units::seconds<> t, State current, + State goal) { // Sampled trajectory should start at the current state, regardless of // validity. State sample{current}; // Adjust states so that they are within the constraints and get the time // required for the current state to return to a valid state. - wpi::units::second_t recoveryTime = AdjustStates(current, goal); + wpi::units::seconds<> recoveryTime = AdjustStates(current, goal); double sign = GetSign(current, goal); m_profile = GenerateProfile(sign, current, goal); @@ -174,7 +170,7 @@ class TrapezoidProfile { // proper recovery. m_profile.t_1 += recoveryTime; - auto advance = [](wpi::units::second_t time, Acceleration_t acceleration, + auto advance = [](wpi::units::seconds<> time, Acceleration_t acceleration, State& state) { // x = x_i + v_i t + at² / 2 (2) state.position += @@ -184,7 +180,7 @@ class TrapezoidProfile { }; Acceleration_t acceleration = sign * m_constraints.maxAcceleration; - advance(wpi::units::math::min(t, m_profile.t_1), + advance(wpi::units::min(t, m_profile.t_1), // Handle recovery to a feasible state if necessary. recoveryTime > 0.0_s && sample.velocity * sign > Velocity_t{0.0} ? -acceleration @@ -193,12 +189,11 @@ class TrapezoidProfile { if (t > m_profile.t_1) { t -= m_profile.t_1; - advance(wpi::units::math::min(t, m_profile.t_2), Acceleration_t{0.0}, - sample); + advance(wpi::units::min(t, m_profile.t_2), Acceleration_t{0.0}, sample); if (t > m_profile.t_2) { t -= m_profile.t_2; - advance(wpi::units::math::min(t, m_profile.t_3), -acceleration, sample); + advance(wpi::units::min(t, m_profile.t_3), -acceleration, sample); if (t > m_profile.t_3) { sample = goal; @@ -218,11 +213,11 @@ class TrapezoidProfile { * @param goal The goal state. * @return The time left until the target state. */ - constexpr wpi::units::second_t TimeLeftUntil(State current, - State goal) const { + constexpr wpi::units::seconds<> TimeLeftUntil(State current, + State goal) const { // Adjust states so that they are within the constraints and get the time // required for the current state to return to a valid state. - wpi::units::second_t recoveryTime = AdjustStates(current, goal); + wpi::units::seconds<> recoveryTime = AdjustStates(current, goal); double sign = GetSign(current, goal); ProfileTiming profile = GenerateProfile(sign, current, goal); @@ -236,7 +231,7 @@ class TrapezoidProfile { * * @return The duration of the profile, or zero if no goal was set. */ - constexpr wpi::units::second_t Duration() const { + constexpr wpi::units::seconds<> Duration() const { return m_profile.t_1 + m_profile.t_2 + m_profile.t_3; } @@ -249,7 +244,7 @@ class TrapezoidProfile { * @param t The time since the beginning of the profile. * @return True if the profile has reached the goal. */ - constexpr bool IsFinished(wpi::units::second_t t) const { + constexpr bool IsFinished(wpi::units::seconds<> t) const { return t >= Duration(); } @@ -268,28 +263,27 @@ class TrapezoidProfile { * @param goal The goal state state to be adjusted. * @return The time taken to make the current state valid. */ - constexpr wpi::units::second_t AdjustStates(State& current, - State& goal) const { - if (wpi::units::math::abs(goal.velocity) > m_constraints.maxVelocity) { + constexpr wpi::units::seconds<> AdjustStates(State& current, + State& goal) const { + if (wpi::units::abs(goal.velocity) > m_constraints.maxVelocity) { goal.velocity = - wpi::units::math::copysign(m_constraints.maxVelocity, goal.velocity); + wpi::units::copysign(m_constraints.maxVelocity, goal.velocity); } - wpi::units::second_t recoveryTime{0.0}; + wpi::units::seconds<> recoveryTime{0.0}; Velocity_t violationAmount = - wpi::units::math::abs(current.velocity) - m_constraints.maxVelocity; + wpi::units::abs(current.velocity) - m_constraints.maxVelocity; if (violationAmount > Velocity_t{0.0}) { recoveryTime = violationAmount / m_constraints.maxAcceleration; // x = x_i + v_i t + at² / 2 (2) - current.position += - current.velocity * recoveryTime + - wpi::units::math::copysign(m_constraints.maxAcceleration, - -current.velocity) * - recoveryTime * recoveryTime / 2.0; + current.position += current.velocity * recoveryTime + + wpi::units::copysign(m_constraints.maxAcceleration, + -current.velocity) * + recoveryTime * recoveryTime / 2.0; // The closest valid velocity will have the magnitude of the max velocity. - current.velocity = wpi::units::math::copysign(m_constraints.maxVelocity, - current.velocity); + current.velocity = + wpi::units::copysign(m_constraints.maxVelocity, current.velocity); } return recoveryTime; @@ -310,7 +304,7 @@ class TrapezoidProfile { // Calculate threshold displacement // d = |v_t - v_i|(v_t + v_i) / (2 a_m) (9) - Distance_t d = wpi::units::math::abs(goal.velocity - current.velocity) * + Distance_t d = wpi::units::abs(goal.velocity - current.velocity) * (goal.velocity + current.velocity) / (2.0 * m_constraints.maxAcceleration); @@ -323,7 +317,7 @@ class TrapezoidProfile { // calculated. We do not have control over the floating point precision // error from previous calculations, and as such, it is difficult to bound // the possible error. 1e-12 should be good enough for FRC though. - if (wpi::units::math::abs(dx - d) < Distance_t{1e-12}) { + if (wpi::units::abs(dx - d) < Distance_t{1e-12}) { return std::copysign(1.0, goal.velocity.value()); } else { if (dx > d) { @@ -356,11 +350,11 @@ class TrapezoidProfile { // Calculate the peak velocity to compare to velocity constraint. // v_p = √(aΔx + (v_t² + v_i²) / 2) (8) Velocity_t peakVelocity = - sign * wpi::units::math::sqrt(wpi::units::math::max( + sign * wpi::units::sqrt(wpi::units::max( acceleration * dx + (goal.velocity * goal.velocity + current.velocity * current.velocity) / 2, - wpi::units::math::pow<2>(Velocity_t{0.0}))); + wpi::units::pow<2>(Velocity_t{0.0}))); // Handle the case where we hit maximum velocity. if (sign * peakVelocity > m_constraints.maxVelocity) { diff --git a/wpimath/src/main/native/include/wpi/math/trajectory/constraint/CentripetalAccelerationConstraint.hpp b/wpimath/src/main/native/include/wpi/math/trajectory/constraint/CentripetalAccelerationConstraint.hpp index eee3fc97334..ffede911066 100644 --- a/wpimath/src/main/native/include/wpi/math/trajectory/constraint/CentripetalAccelerationConstraint.hpp +++ b/wpimath/src/main/native/include/wpi/math/trajectory/constraint/CentripetalAccelerationConstraint.hpp @@ -7,7 +7,6 @@ #include "wpi/math/trajectory/constraint/TrajectoryConstraint.hpp" #include "wpi/units/acceleration.hpp" #include "wpi/units/curvature.hpp" -#include "wpi/units/math.hpp" #include "wpi/units/velocity.hpp" #include "wpi/util/SymbolExports.hpp" @@ -26,12 +25,12 @@ class WPILIB_DLLEXPORT CentripetalAccelerationConstraint : public TrajectoryConstraint { public: constexpr explicit CentripetalAccelerationConstraint( - wpi::units::meters_per_second_squared_t maxCentripetalAcceleration) + wpi::units::meters_per_second_squared<> maxCentripetalAcceleration) : m_maxCentripetalAcceleration(maxCentripetalAcceleration) {} - constexpr wpi::units::meters_per_second_t MaxVelocity( + constexpr wpi::units::meters_per_second<> MaxVelocity( const Pose2d& pose, wpi::units::curvature_t curvature, - wpi::units::meters_per_second_t velocity) const override { + wpi::units::meters_per_second<> velocity) const override { // ac = v²/r // k (curvature) = 1/r @@ -42,19 +41,19 @@ class WPILIB_DLLEXPORT CentripetalAccelerationConstraint // We have to multiply by 1_rad here to get the units to cancel out nicely. // The units library defines a unit for radians although it is technically // unitless. - return wpi::units::math::sqrt(m_maxCentripetalAcceleration / - wpi::units::math::abs(curvature) * 1_rad); + return wpi::units::sqrt(m_maxCentripetalAcceleration / + wpi::units::abs(curvature) * 1_rad); } constexpr MinMax MinMaxAcceleration( const Pose2d& pose, wpi::units::curvature_t curvature, - wpi::units::meters_per_second_t velocity) const override { + wpi::units::meters_per_second<> velocity) const override { // The acceleration of the robot has no impact on the centripetal // acceleration of the robot. return {}; } private: - wpi::units::meters_per_second_squared_t m_maxCentripetalAcceleration; + wpi::units::meters_per_second_squared<> m_maxCentripetalAcceleration; }; } // namespace wpi::math diff --git a/wpimath/src/main/native/include/wpi/math/trajectory/constraint/DifferentialDriveKinematicsConstraint.hpp b/wpimath/src/main/native/include/wpi/math/trajectory/constraint/DifferentialDriveKinematicsConstraint.hpp index 0e7429ab4ec..c17bb1de59c 100644 --- a/wpimath/src/main/native/include/wpi/math/trajectory/constraint/DifferentialDriveKinematicsConstraint.hpp +++ b/wpimath/src/main/native/include/wpi/math/trajectory/constraint/DifferentialDriveKinematicsConstraint.hpp @@ -23,12 +23,12 @@ class WPILIB_DLLEXPORT DifferentialDriveKinematicsConstraint public: constexpr DifferentialDriveKinematicsConstraint( DifferentialDriveKinematics kinematics, - wpi::units::meters_per_second_t maxVelocity) + wpi::units::meters_per_second<> maxVelocity) : m_kinematics(std::move(kinematics)), m_maxVelocity(maxVelocity) {} - constexpr wpi::units::meters_per_second_t MaxVelocity( + constexpr wpi::units::meters_per_second<> MaxVelocity( const Pose2d& pose, wpi::units::curvature_t curvature, - wpi::units::meters_per_second_t velocity) const override { + wpi::units::meters_per_second<> velocity) const override { auto wheelVelocities = m_kinematics.ToWheelVelocities({velocity, 0_mps, velocity * curvature}) .Desaturate(m_maxVelocity); @@ -38,12 +38,12 @@ class WPILIB_DLLEXPORT DifferentialDriveKinematicsConstraint constexpr MinMax MinMaxAcceleration( const Pose2d& pose, wpi::units::curvature_t curvature, - wpi::units::meters_per_second_t velocity) const override { + wpi::units::meters_per_second<> velocity) const override { return {}; } private: DifferentialDriveKinematics m_kinematics; - wpi::units::meters_per_second_t m_maxVelocity; + wpi::units::meters_per_second<> m_maxVelocity; }; } // namespace wpi::math diff --git a/wpimath/src/main/native/include/wpi/math/trajectory/constraint/DifferentialDriveVoltageConstraint.hpp b/wpimath/src/main/native/include/wpi/math/trajectory/constraint/DifferentialDriveVoltageConstraint.hpp index 786b3316209..42f93490a62 100644 --- a/wpimath/src/main/native/include/wpi/math/trajectory/constraint/DifferentialDriveVoltageConstraint.hpp +++ b/wpimath/src/main/native/include/wpi/math/trajectory/constraint/DifferentialDriveVoltageConstraint.hpp @@ -12,7 +12,6 @@ #include "wpi/math/kinematics/DifferentialDriveKinematics.hpp" #include "wpi/math/trajectory/constraint/TrajectoryConstraint.hpp" #include "wpi/units/length.hpp" -#include "wpi/units/math.hpp" #include "wpi/units/voltage.hpp" #include "wpi/util/MathExtras.hpp" #include "wpi/util/SymbolExports.hpp" @@ -38,21 +37,21 @@ class WPILIB_DLLEXPORT DifferentialDriveVoltageConstraint * voltage (12V) to account for "voltage sag" due to current draw. */ constexpr DifferentialDriveVoltageConstraint( - const SimpleMotorFeedforward& feedforward, - DifferentialDriveKinematics kinematics, wpi::units::volt_t maxVoltage) + const SimpleMotorFeedforward& feedforward, + DifferentialDriveKinematics kinematics, wpi::units::volts<> maxVoltage) : m_feedforward(feedforward), m_kinematics(std::move(kinematics)), m_maxVoltage(maxVoltage) {} - constexpr wpi::units::meters_per_second_t MaxVelocity( + constexpr wpi::units::meters_per_second<> MaxVelocity( const Pose2d& pose, wpi::units::curvature_t curvature, - wpi::units::meters_per_second_t velocity) const override { - return wpi::units::meters_per_second_t{std::numeric_limits::max()}; + wpi::units::meters_per_second<> velocity) const override { + return wpi::units::meters_per_second<>{std::numeric_limits::max()}; } constexpr MinMax MinMaxAcceleration( const Pose2d& pose, wpi::units::curvature_t curvature, - wpi::units::meters_per_second_t velocity) const override { + wpi::units::meters_per_second<> velocity) const override { auto wheelVelocities = m_kinematics.ToWheelVelocities({velocity, 0_mps, velocity * curvature}); @@ -85,26 +84,24 @@ class WPILIB_DLLEXPORT DifferentialDriveVoltageConstraint // case, as it breaks the signum function. Both max and min acceleration // are *reduced in magnitude* in this case. - wpi::units::meters_per_second_squared_t maxChassisAcceleration; - wpi::units::meters_per_second_squared_t minChassisAcceleration; + wpi::units::meters_per_second_squared<> maxChassisAcceleration; + wpi::units::meters_per_second_squared<> minChassisAcceleration; if (velocity == 0_mps) { maxChassisAcceleration = maxWheelAcceleration / - (1 + m_kinematics.trackwidth * wpi::units::math::abs(curvature) / - (2_rad)); + (1 + m_kinematics.trackwidth * wpi::units::abs(curvature) / (2_rad)); minChassisAcceleration = minWheelAcceleration / - (1 + m_kinematics.trackwidth * wpi::units::math::abs(curvature) / - (2_rad)); + (1 + m_kinematics.trackwidth * wpi::units::abs(curvature) / (2_rad)); } else { maxChassisAcceleration = maxWheelAcceleration / - (1 + m_kinematics.trackwidth * wpi::units::math::abs(curvature) * + (1 + m_kinematics.trackwidth * wpi::units::abs(curvature) * wpi::util::sgn(velocity) / (2_rad)); minChassisAcceleration = minWheelAcceleration / - (1 - m_kinematics.trackwidth * wpi::units::math::abs(curvature) * + (1 - m_kinematics.trackwidth * wpi::units::abs(curvature) * wpi::util::sgn(velocity) / (2_rad)); } @@ -114,8 +111,7 @@ class WPILIB_DLLEXPORT DifferentialDriveVoltageConstraint // wheel when this happens. We can accurately account for this by simply // negating the inner wheel. - if ((m_kinematics.trackwidth / 2) > - 1_rad / wpi::units::math::abs(curvature)) { + if ((m_kinematics.trackwidth / 2) > 1_rad / wpi::units::abs(curvature)) { if (velocity > 0_mps) { minChassisAcceleration = -minChassisAcceleration; } else if (velocity < 0_mps) { @@ -127,8 +123,8 @@ class WPILIB_DLLEXPORT DifferentialDriveVoltageConstraint } private: - SimpleMotorFeedforward m_feedforward; + SimpleMotorFeedforward m_feedforward; DifferentialDriveKinematics m_kinematics; - wpi::units::volt_t m_maxVoltage; + wpi::units::volts<> m_maxVoltage; }; } // namespace wpi::math diff --git a/wpimath/src/main/native/include/wpi/math/trajectory/constraint/EllipticalRegionConstraint.hpp b/wpimath/src/main/native/include/wpi/math/trajectory/constraint/EllipticalRegionConstraint.hpp index ca1b444704e..507ea4a99d2 100644 --- a/wpimath/src/main/native/include/wpi/math/trajectory/constraint/EllipticalRegionConstraint.hpp +++ b/wpimath/src/main/native/include/wpi/math/trajectory/constraint/EllipticalRegionConstraint.hpp @@ -32,20 +32,20 @@ class EllipticalRegionConstraint : public TrajectoryConstraint { const Constraint& constraint) : m_ellipse{ellipse}, m_constraint{constraint} {} - constexpr wpi::units::meters_per_second_t MaxVelocity( + constexpr wpi::units::meters_per_second<> MaxVelocity( const Pose2d& pose, wpi::units::curvature_t curvature, - wpi::units::meters_per_second_t velocity) const override { + wpi::units::meters_per_second<> velocity) const override { if (m_ellipse.Contains(pose.Translation())) { return m_constraint.MaxVelocity(pose, curvature, velocity); } else { - return wpi::units::meters_per_second_t{ + return wpi::units::meters_per_second<>{ std::numeric_limits::infinity()}; } } constexpr MinMax MinMaxAcceleration( const Pose2d& pose, wpi::units::curvature_t curvature, - wpi::units::meters_per_second_t velocity) const override { + wpi::units::meters_per_second<> velocity) const override { if (m_ellipse.Contains(pose.Translation())) { return m_constraint.MinMaxAcceleration(pose, curvature, velocity); } else { diff --git a/wpimath/src/main/native/include/wpi/math/trajectory/constraint/MaxVelocityConstraint.hpp b/wpimath/src/main/native/include/wpi/math/trajectory/constraint/MaxVelocityConstraint.hpp index 5f2c9022731..0ef4d4d1934 100644 --- a/wpimath/src/main/native/include/wpi/math/trajectory/constraint/MaxVelocityConstraint.hpp +++ b/wpimath/src/main/native/include/wpi/math/trajectory/constraint/MaxVelocityConstraint.hpp @@ -5,7 +5,6 @@ #pragma once #include "wpi/math/trajectory/constraint/TrajectoryConstraint.hpp" -#include "wpi/units/math.hpp" #include "wpi/units/velocity.hpp" #include "wpi/util/SymbolExports.hpp" @@ -24,23 +23,23 @@ class WPILIB_DLLEXPORT MaxVelocityConstraint : public TrajectoryConstraint { * @param maxVelocity The max velocity. */ constexpr explicit MaxVelocityConstraint( - wpi::units::meters_per_second_t maxVelocity) - : m_maxVelocity(wpi::units::math::abs(maxVelocity)) {} + wpi::units::meters_per_second<> maxVelocity) + : m_maxVelocity(wpi::units::abs(maxVelocity)) {} - constexpr wpi::units::meters_per_second_t MaxVelocity( + constexpr wpi::units::meters_per_second<> MaxVelocity( const Pose2d& pose, wpi::units::curvature_t curvature, - wpi::units::meters_per_second_t velocity) const override { + wpi::units::meters_per_second<> velocity) const override { return m_maxVelocity; } constexpr MinMax MinMaxAcceleration( const Pose2d& pose, wpi::units::curvature_t curvature, - wpi::units::meters_per_second_t velocity) const override { + wpi::units::meters_per_second<> velocity) const override { return {}; } private: - wpi::units::meters_per_second_t m_maxVelocity; + wpi::units::meters_per_second<> m_maxVelocity; }; } // namespace wpi::math diff --git a/wpimath/src/main/native/include/wpi/math/trajectory/constraint/MecanumDriveKinematicsConstraint.hpp b/wpimath/src/main/native/include/wpi/math/trajectory/constraint/MecanumDriveKinematicsConstraint.hpp index ae92283cec2..769d01f3e46 100644 --- a/wpimath/src/main/native/include/wpi/math/trajectory/constraint/MecanumDriveKinematicsConstraint.hpp +++ b/wpimath/src/main/native/include/wpi/math/trajectory/constraint/MecanumDriveKinematicsConstraint.hpp @@ -6,7 +6,6 @@ #include "wpi/math/kinematics/MecanumDriveKinematics.hpp" #include "wpi/math/trajectory/constraint/TrajectoryConstraint.hpp" -#include "wpi/units/math.hpp" #include "wpi/units/velocity.hpp" #include "wpi/util/SymbolExports.hpp" @@ -21,12 +20,12 @@ class WPILIB_DLLEXPORT MecanumDriveKinematicsConstraint : public TrajectoryConstraint { public: MecanumDriveKinematicsConstraint(const MecanumDriveKinematics& kinematics, - wpi::units::meters_per_second_t maxVelocity) + wpi::units::meters_per_second<> maxVelocity) : m_kinematics(kinematics), m_maxVelocity(maxVelocity) {} - wpi::units::meters_per_second_t MaxVelocity( + wpi::units::meters_per_second<> MaxVelocity( const Pose2d& pose, wpi::units::curvature_t curvature, - wpi::units::meters_per_second_t velocity) const override { + wpi::units::meters_per_second<> velocity) const override { auto xVelocity = velocity * pose.Rotation().Cos(); auto yVelocity = velocity * pose.Rotation().Sin(); auto wheelVelocities = @@ -36,17 +35,17 @@ class WPILIB_DLLEXPORT MecanumDriveKinematicsConstraint auto normVelocities = m_kinematics.ToChassisVelocities(wheelVelocities); - return wpi::units::math::hypot(normVelocities.vx, normVelocities.vy); + return wpi::units::hypot(normVelocities.vx, normVelocities.vy); } MinMax MinMaxAcceleration( const Pose2d& pose, wpi::units::curvature_t curvature, - wpi::units::meters_per_second_t velocity) const override { + wpi::units::meters_per_second<> velocity) const override { return {}; } private: MecanumDriveKinematics m_kinematics; - wpi::units::meters_per_second_t m_maxVelocity; + wpi::units::meters_per_second<> m_maxVelocity; }; } // namespace wpi::math diff --git a/wpimath/src/main/native/include/wpi/math/trajectory/constraint/RectangularRegionConstraint.hpp b/wpimath/src/main/native/include/wpi/math/trajectory/constraint/RectangularRegionConstraint.hpp index 59c9cd10dfc..649b0547ecb 100644 --- a/wpimath/src/main/native/include/wpi/math/trajectory/constraint/RectangularRegionConstraint.hpp +++ b/wpimath/src/main/native/include/wpi/math/trajectory/constraint/RectangularRegionConstraint.hpp @@ -30,20 +30,20 @@ class RectangularRegionConstraint : public TrajectoryConstraint { const Constraint& constraint) : m_rectangle{rectangle}, m_constraint{constraint} {} - constexpr wpi::units::meters_per_second_t MaxVelocity( + constexpr wpi::units::meters_per_second<> MaxVelocity( const Pose2d& pose, wpi::units::curvature_t curvature, - wpi::units::meters_per_second_t velocity) const override { + wpi::units::meters_per_second<> velocity) const override { if (m_rectangle.Contains(pose.Translation())) { return m_constraint.MaxVelocity(pose, curvature, velocity); } else { - return wpi::units::meters_per_second_t{ + return wpi::units::meters_per_second<>{ std::numeric_limits::infinity()}; } } constexpr MinMax MinMaxAcceleration( const Pose2d& pose, wpi::units::curvature_t curvature, - wpi::units::meters_per_second_t velocity) const override { + wpi::units::meters_per_second<> velocity) const override { if (m_rectangle.Contains(pose.Translation())) { return m_constraint.MinMaxAcceleration(pose, curvature, velocity); } else { diff --git a/wpimath/src/main/native/include/wpi/math/trajectory/constraint/SwerveDriveKinematicsConstraint.hpp b/wpimath/src/main/native/include/wpi/math/trajectory/constraint/SwerveDriveKinematicsConstraint.hpp index a24b344014a..f70e2de3ac3 100644 --- a/wpimath/src/main/native/include/wpi/math/trajectory/constraint/SwerveDriveKinematicsConstraint.hpp +++ b/wpimath/src/main/native/include/wpi/math/trajectory/constraint/SwerveDriveKinematicsConstraint.hpp @@ -6,7 +6,6 @@ #include "wpi/math/kinematics/SwerveDriveKinematics.hpp" #include "wpi/math/trajectory/constraint/TrajectoryConstraint.hpp" -#include "wpi/units/math.hpp" #include "wpi/units/velocity.hpp" namespace wpi::math { @@ -21,12 +20,12 @@ class SwerveDriveKinematicsConstraint : public TrajectoryConstraint { public: SwerveDriveKinematicsConstraint( const wpi::math::SwerveDriveKinematics& kinematics, - wpi::units::meters_per_second_t maxVelocity) + wpi::units::meters_per_second<> maxVelocity) : m_kinematics(kinematics), m_maxVelocity(maxVelocity) {} - wpi::units::meters_per_second_t MaxVelocity( + wpi::units::meters_per_second<> MaxVelocity( const Pose2d& pose, wpi::units::curvature_t curvature, - wpi::units::meters_per_second_t velocity) const override { + wpi::units::meters_per_second<> velocity) const override { auto xVelocity = velocity * pose.Rotation().Cos(); auto yVelocity = velocity * pose.Rotation().Sin(); auto wheelVelocities = m_kinematics.ToSwerveModuleVelocities( @@ -35,18 +34,18 @@ class SwerveDriveKinematicsConstraint : public TrajectoryConstraint { auto normVelocities = m_kinematics.ToChassisVelocities( m_kinematics.DesaturateWheelVelocities(wheelVelocities, m_maxVelocity)); - return wpi::units::math::hypot(normVelocities.vx, normVelocities.vy); + return wpi::units::hypot(normVelocities.vx, normVelocities.vy); } MinMax MinMaxAcceleration( const Pose2d& pose, wpi::units::curvature_t curvature, - wpi::units::meters_per_second_t velocity) const override { + wpi::units::meters_per_second<> velocity) const override { return {}; } private: wpi::math::SwerveDriveKinematics m_kinematics; - wpi::units::meters_per_second_t m_maxVelocity; + wpi::units::meters_per_second<> m_maxVelocity; }; } // namespace wpi::math diff --git a/wpimath/src/main/native/include/wpi/math/trajectory/constraint/TrajectoryConstraint.hpp b/wpimath/src/main/native/include/wpi/math/trajectory/constraint/TrajectoryConstraint.hpp index d127baea3d4..88364cb4f63 100644 --- a/wpimath/src/main/native/include/wpi/math/trajectory/constraint/TrajectoryConstraint.hpp +++ b/wpimath/src/main/native/include/wpi/math/trajectory/constraint/TrajectoryConstraint.hpp @@ -37,13 +37,13 @@ class WPILIB_DLLEXPORT TrajectoryConstraint { /** * The minimum acceleration. */ - wpi::units::meters_per_second_squared_t minAcceleration{ + wpi::units::meters_per_second_squared<> minAcceleration{ -std::numeric_limits::max()}; /** * The maximum acceleration. */ - wpi::units::meters_per_second_squared_t maxAcceleration{ + wpi::units::meters_per_second_squared<> maxAcceleration{ std::numeric_limits::max()}; }; @@ -57,9 +57,9 @@ class WPILIB_DLLEXPORT TrajectoryConstraint { * * @return The absolute maximum velocity. */ - constexpr virtual wpi::units::meters_per_second_t MaxVelocity( + constexpr virtual wpi::units::meters_per_second<> MaxVelocity( const Pose2d& pose, wpi::units::curvature_t curvature, - wpi::units::meters_per_second_t velocity) const = 0; + wpi::units::meters_per_second<> velocity) const = 0; /** * Returns the minimum and maximum allowable acceleration for the trajectory @@ -73,6 +73,6 @@ class WPILIB_DLLEXPORT TrajectoryConstraint { */ constexpr virtual MinMax MinMaxAcceleration( const Pose2d& pose, wpi::units::curvature_t curvature, - wpi::units::meters_per_second_t velocity) const = 0; + wpi::units::meters_per_second<> velocity) const = 0; }; } // namespace wpi::math diff --git a/wpimath/src/main/native/include/wpi/math/trajectory/struct/TrapezoidProfileStruct.hpp b/wpimath/src/main/native/include/wpi/math/trajectory/struct/TrapezoidProfileStruct.hpp index d043dff8d14..d6d7f873b40 100644 --- a/wpimath/src/main/native/include/wpi/math/trajectory/struct/TrapezoidProfileStruct.hpp +++ b/wpimath/src/main/native/include/wpi/math/trajectory/struct/TrapezoidProfileStruct.hpp @@ -5,23 +5,23 @@ #pragma once #include "wpi/math/trajectory/TrapezoidProfile.hpp" +#include "wpi/units/angle.hpp" #include "wpi/units/length.hpp" #include "wpi/util/struct/Struct.hpp" // Everything is converted into units for -// wpi::math::TrapezoidProfile or -// wpi::math::TrapezoidProfile +// wpi::math::TrapezoidProfile or +// wpi::math::TrapezoidProfile template - requires wpi::units::length_unit || - wpi::units::angle_unit || + requires wpi::units::Length || wpi::units::Angle || wpi::units::traits::is_dimensionless_unit::value struct wpi::util::Struct< wpi::math::detail::TrapezoidProfileConstraints> { static constexpr std::string_view GetTypeName() { - if constexpr (wpi::units::length_unit) { + if constexpr (wpi::units::Length) { return "TrapezoidProfileConstraintsMeters"; - } else if constexpr (wpi::units::angle_unit) { + } else if constexpr (wpi::units::Angle) { return "TrapezoidProfileConstraintsRadians"; } else { return "TrapezoidProfileConstraints"; @@ -34,9 +34,8 @@ struct wpi::util::Struct< static wpi::math::detail::TrapezoidProfileConstraints Unpack( std::span data) { - using BaseUnit = - wpi::units::unit, - wpi::units::traits::base_unit_of>; + using BaseUnit = wpi::units::conversion_factor< + std::ratio<1>, wpi::units::traits::dimension_of_t>; using BaseConstraints = wpi::math::detail::TrapezoidProfileConstraints; constexpr size_t MAX_VELOCITY_OFF = 0; @@ -50,9 +49,8 @@ struct wpi::util::Struct< static void Pack( std::span data, const wpi::math::detail::TrapezoidProfileConstraints& value) { - using BaseUnit = - wpi::units::unit, - wpi::units::traits::base_unit_of>; + using BaseUnit = wpi::units::conversion_factor< + std::ratio<1>, wpi::units::traits::dimension_of_t>; using BaseConstraints = wpi::math::detail::TrapezoidProfileConstraints; constexpr size_t MAX_VELOCITY_OFF = 0; @@ -66,10 +64,11 @@ struct wpi::util::Struct< }; static_assert(wpi::util::StructSerializable< - wpi::math::TrapezoidProfile::Constraints>); + wpi::math::TrapezoidProfile::Constraints>); static_assert(wpi::util::StructSerializable< - wpi::math::TrapezoidProfile::Constraints>); + wpi::math::TrapezoidProfile::Constraints>); static_assert(wpi::util::StructSerializable< - wpi::math::TrapezoidProfile::Constraints>); -static_assert(wpi::util::StructSerializable::Constraints>); + wpi::math::TrapezoidProfile::Constraints>); +static_assert( + wpi::util::StructSerializable< + wpi::math::TrapezoidProfile::Constraints>); diff --git a/wpimath/src/main/native/include/wpi/math/util/MathShared.hpp b/wpimath/src/main/native/include/wpi/math/util/MathShared.hpp index 533abb5d447..0daaa156e95 100644 --- a/wpimath/src/main/native/include/wpi/math/util/MathShared.hpp +++ b/wpimath/src/main/native/include/wpi/math/util/MathShared.hpp @@ -19,7 +19,7 @@ class WPILIB_DLLEXPORT MathShared { virtual void ReportErrorV(std::string_view format, std::format_args args) = 0; virtual void ReportWarningV(std::string_view format, std::format_args args) = 0; - virtual wpi::units::second_t GetTimestamp() = 0; + virtual wpi::units::seconds<> GetTimestamp() = 0; template inline void ReportError(const S& format, Args&&... args) { @@ -56,7 +56,7 @@ class WPILIB_DLLEXPORT MathSharedStore { ReportWarningV(format, std::make_format_args(args...)); } - static wpi::units::second_t GetTimestamp() { + static wpi::units::seconds<> GetTimestamp() { return GetMathShared().GetTimestamp(); } }; diff --git a/wpimath/src/main/native/include/wpi/math/util/MathUtil.hpp b/wpimath/src/main/native/include/wpi/math/util/MathUtil.hpp index 8a32c72becc..97a43245614 100644 --- a/wpimath/src/main/native/include/wpi/math/util/MathUtil.hpp +++ b/wpimath/src/main/native/include/wpi/math/util/MathUtil.hpp @@ -15,9 +15,8 @@ #include "wpi/math/geometry/Translation3d.hpp" #include "wpi/math/util/MathShared.hpp" #include "wpi/units/angle.hpp" -#include "wpi/units/base.hpp" +#include "wpi/units/core.hpp" #include "wpi/units/length.hpp" -#include "wpi/units/math.hpp" #include "wpi/units/time.hpp" #include "wpi/units/velocity.hpp" #include "wpi/util/SymbolExports.hpp" @@ -36,13 +35,13 @@ namespace wpi::math { * @return The value after the deadband is applied. */ template - requires std::is_arithmetic_v || wpi::units::traits::is_unit_t_v + requires std::is_arithmetic_v || wpi::units::DimensionedUnitType constexpr T ApplyDeadband(T value, T deadband, T maxMagnitude = T{1.0}) { T magnitude; if constexpr (std::is_arithmetic_v) { magnitude = gcem::abs(value); } else { - magnitude = wpi::units::math::abs(value); + magnitude = wpi::units::abs(value); } if (magnitude < deadband) { @@ -96,6 +95,24 @@ constexpr T ApplyDeadband(T value, T deadband, T maxMagnitude = T{1.0}) { } } +/** + * Returns 0.0 if the given value is within the specified range around zero. The + * remaining range between the deadband and the maximum magnitude is scaled from + * 0.0 to the maximum magnitude. + * + * @param value Value to clip. + * @param deadband Range around zero. + * @param maxMagnitude The maximum magnitude of the input (defaults to 1). Can + * be infinite. + * @return The value after the deadband is applied. + */ +template + requires wpi::units::DimensionlessUnitType +constexpr T ApplyDeadband(T value, T deadband, + T maxMagnitude = wpi::units::dimensionless<>{1.0}) { + return ApplyDeadband(value.raw(), deadband.raw(), maxMagnitude.raw()); +} + /** * Returns a zero vector if the given vector is within the specified * distance from the origin. The remaining distance between the deadband and the @@ -108,7 +125,7 @@ constexpr T ApplyDeadband(T value, T deadband, T maxMagnitude = T{1.0}) { * @return The value after the deadband is applied. */ template - requires std::is_arithmetic_v || wpi::units::traits::is_unit_t_v + requires std::is_arithmetic_v || wpi::units::DimensionedUnitType Eigen::Vector ApplyDeadband(const Eigen::Vector& value, T deadband, T maxMagnitude = T{1.0}) { if constexpr (std::is_arithmetic_v) { @@ -144,7 +161,7 @@ Eigen::Vector ApplyDeadband(const Eigen::Vector& value, T deadband, * range. */ template - requires std::is_arithmetic_v || wpi::units::traits::is_unit_t_v + requires std::is_arithmetic_v || wpi::units::DimensionedUnitType constexpr T CopyDirectionPow(T value, double exponent, T maxMagnitude = T{1.0}) { if constexpr (std::is_arithmetic_v) { @@ -152,14 +169,38 @@ constexpr T CopyDirectionPow(T value, double exponent, gcem::pow(gcem::abs(value) / maxMagnitude, exponent) * maxMagnitude, value); } else { - return wpi::units::math::copysign( - gcem::pow((wpi::units::math::abs(value) / maxMagnitude).value(), - exponent) * + return wpi::units::copysign( + gcem::pow((wpi::units::abs(value) / maxMagnitude).raw(), exponent) * maxMagnitude, value); } } +/** + * Raises the input to the power of the given exponent while preserving its + * sign. + * + * The function normalizes the input value to the range [0, 1] based on the + * maximum magnitude so that the output stays in the range. + * + * This is useful for applying smoother or more aggressive control response + * curves (e.g. joystick input shaping). + * + * @param value The input value to transform. + * @param exponent The exponent to apply (e.g. 1.0 = linear, 2.0 = squared + * curve). Must be positive. + * @param maxMagnitude The maximum expected absolute value of input (defaults to + * 1). Must be positive. + * @return The transformed value with the same sign and scaled to the input + * range. + */ +template + requires wpi::units::DimensionlessUnitType +constexpr T CopyDirectionPow(T value, double exponent, + T maxMagnitude = wpi::units::dimensionless{1.0}) { + return CopyDirectionPow(value.raw(), exponent, maxMagnitude.raw()); +} + /** * Raises the norm of the input to the power of the given exponent while * preserving its direction. @@ -179,7 +220,7 @@ constexpr T CopyDirectionPow(T value, double exponent, * the input range. */ template - requires std::is_arithmetic_v || wpi::units::traits::is_unit_t_v + requires std::is_arithmetic_v || wpi::units::DimensionedUnitType Eigen::Vector CopyDirectionPow(const Eigen::Vector& value, double exponent, T maxMagnitude = T{1.0}) { if constexpr (std::is_arithmetic_v) { @@ -229,12 +270,12 @@ constexpr T InputModulus(T input, T minimumInput, T maximumInput) { * @return Whether or not the actual value is within the allowed tolerance */ template - requires std::is_arithmetic_v || wpi::units::traits::is_unit_t_v + requires std::is_arithmetic_v || wpi::units::traits::is_unit_v constexpr bool IsNear(T expected, T actual, T tolerance) { if constexpr (std::is_arithmetic_v) { return std::abs(expected - actual) < tolerance; } else { - return wpi::units::math::abs(expected - actual) < tolerance; + return wpi::units::abs(expected - actual) < tolerance; } } @@ -258,7 +299,7 @@ constexpr bool IsNear(T expected, T actual, T tolerance) { * @return Whether or not the actual value is within the allowed tolerance */ template - requires std::is_arithmetic_v || wpi::units::traits::is_unit_t_v + requires std::is_arithmetic_v || wpi::units::traits::is_unit_v constexpr bool IsNear(T expected, T actual, T tolerance, T min, T max) { T errorBound = (max - min) / 2.0; T error = @@ -267,7 +308,7 @@ constexpr bool IsNear(T expected, T actual, T tolerance, T min, T max) { if constexpr (std::is_arithmetic_v) { return std::abs(error) < tolerance; } else { - return wpi::units::math::abs(error) < tolerance; + return wpi::units::abs(error) < tolerance; } } @@ -277,10 +318,10 @@ constexpr bool IsNear(T expected, T actual, T tolerance, T min, T max) { * @param angle Angle to wrap. */ WPILIB_DLLEXPORT -constexpr wpi::units::radian_t AngleModulus(wpi::units::radian_t angle) { - return InputModulus( - angle, wpi::units::radian_t{-std::numbers::pi}, - wpi::units::radian_t{std::numbers::pi}); +constexpr wpi::units::radians<> AngleModulus(wpi::units::radians<> angle) { + return InputModulus>( + angle, wpi::units::radians<>{-std::numbers::pi}, + wpi::units::radians<>{std::numbers::pi}); } // floorDiv and floorMod algorithms taken from Java @@ -332,21 +373,20 @@ constexpr std::signed_integral auto FloorMod(std::signed_integral auto x, */ constexpr Translation2d SlewRateLimit( const Translation2d& current, const Translation2d& next, - wpi::units::second_t dt, wpi::units::meters_per_second_t maxVelocity) { + wpi::units::seconds<> dt, wpi::units::meters_per_second<> maxVelocity) { if (maxVelocity < 0_mps) { wpi::math::MathSharedStore::ReportError( "maxVelocity must be a non-negative number, got {}!", maxVelocity); return next; } Translation2d diff = next - current; - wpi::units::meter_t dist = diff.Norm(); + wpi::units::meters<> dist = diff.Norm(); if (dist < 1e-9_m) { return next; } if (dist > maxVelocity * dt) { // Move maximum allowed amount in direction of the difference - // NOLINTNEXTLINE(bugprone-integer-division) - return current + diff * (maxVelocity * dt / dist); + return current + diff * double{maxVelocity * dt / dist}; } return next; } @@ -362,21 +402,20 @@ constexpr Translation2d SlewRateLimit( */ constexpr Translation3d SlewRateLimit( const Translation3d& current, const Translation3d& next, - wpi::units::second_t dt, wpi::units::meters_per_second_t maxVelocity) { + wpi::units::seconds<> dt, wpi::units::meters_per_second<> maxVelocity) { if (maxVelocity < 0_mps) { wpi::math::MathSharedStore::ReportError( "maxVelocity must be a non-negative number, got {}!", maxVelocity); return next; } Translation3d diff = next - current; - wpi::units::meter_t dist = diff.Norm(); + wpi::units::meters<> dist = diff.Norm(); if (dist < 1e-9_m) { return next; } if (dist > maxVelocity * dt) { // Move maximum allowed amount in direction of the difference - // NOLINTNEXTLINE(bugprone-integer-division) - return current + diff * (maxVelocity * dt / dist); + return current + diff * double{maxVelocity * dt / dist}; } return next; } diff --git a/wpimath/src/main/native/include/wpi/units/acceleration.hpp b/wpimath/src/main/native/include/wpi/units/acceleration.hpp deleted file mode 100644 index b6057e5d54d..00000000000 --- a/wpimath/src/main/native/include/wpi/units/acceleration.hpp +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright (c) FIRST and other WPILib contributors. -// Open Source Software; you can modify and/or share it under the terms of -// the WPILib BSD license file in the root directory of this project. - -// Copyright (c) 2016 Nic Holthaus -// -// The MIT License (MIT) -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. - -#pragma once - -#include "wpi/units/base.hpp" -#include "wpi/units/length.hpp" -#include "wpi/units/time.hpp" - -namespace wpi::units { -/** - * @namespace wpi::units::acceleration - * @brief namespace for unit types and containers representing acceleration - * values - * @details The SI unit for acceleration is `meters_per_second_squared`, and the - * corresponding `base_unit` category is `acceleration_unit`. - * @anchor accelerationContainers - * @sa See unit_t for more information on unit type containers. - */ -#if !defined(DISABLE_PREDEFINED_UNITS) || \ - defined(ENABLE_PREDEFINED_ACCELERATION_UNITS) -UNIT_ADD(acceleration, meters_per_second_squared, meters_per_second_squared, - mps_sq, unit, wpi::units::category::acceleration_unit>) -UNIT_ADD(acceleration, feet_per_second_squared, feet_per_second_squared, fps_sq, - compound_unit>>) -UNIT_ADD(acceleration, standard_gravity, standard_gravity, SG, - unit, meters_per_second_squared>) - -UNIT_ADD_CATEGORY_TRAIT(acceleration) -#endif - -using namespace acceleration; -} // namespace wpi::units diff --git a/wpimath/src/main/native/include/wpi/units/angle.hpp b/wpimath/src/main/native/include/wpi/units/angle.hpp deleted file mode 100644 index 0b9e2a41684..00000000000 --- a/wpimath/src/main/native/include/wpi/units/angle.hpp +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright (c) FIRST and other WPILib contributors. -// Open Source Software; you can modify and/or share it under the terms of -// the WPILib BSD license file in the root directory of this project. - -// Copyright (c) 2016 Nic Holthaus -// -// The MIT License (MIT) -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. - -#pragma once - -#include "wpi/units/base.hpp" - -namespace wpi::units { -/** - * @namespace wpi::units::angle - * @brief namespace for unit types and containers representing angle values - * @details The SI unit for angle is `radians`, and the corresponding - * `base_unit` category is`angle_unit`. - * @anchor angleContainers - * @sa See unit_t for more information on unit type containers. - */ -#if !defined(DISABLE_PREDEFINED_UNITS) || defined(ENABLE_PREDEFINED_ANGLE_UNITS) -UNIT_ADD_WITH_METRIC_PREFIXES( - angle, radian, radians, rad, - unit, wpi::units::category::angle_unit>) -UNIT_ADD(angle, degree, degrees, deg, - unit, radians, std::ratio<1>>) -UNIT_ADD(angle, arcminute, arcminutes, arcmin, unit, degrees>) -UNIT_ADD(angle, arcsecond, arcseconds, arcsec, - unit, arcminutes>) -UNIT_ADD(angle, milliarcsecond, milliarcseconds, mas, milli) -UNIT_ADD(angle, turn, turns, tr, unit, radians, std::ratio<1>>) -UNIT_ADD(angle, gradian, gradians, gon, unit, turns>) - -UNIT_ADD_CATEGORY_TRAIT(angle) -#endif - -using namespace angle; -} // namespace wpi::units diff --git a/wpimath/src/main/native/include/wpi/units/angular_acceleration.hpp b/wpimath/src/main/native/include/wpi/units/angular_acceleration.hpp deleted file mode 100644 index b5cd4e7ed5d..00000000000 --- a/wpimath/src/main/native/include/wpi/units/angular_acceleration.hpp +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright (c) FIRST and other WPILib contributors. -// Open Source Software; you can modify and/or share it under the terms of -// the WPILib BSD license file in the root directory of this project. - -#pragma once - -#include "wpi/units/angle.hpp" -#include "wpi/units/base.hpp" -#include "wpi/units/time.hpp" - -namespace wpi::units { -/** - * @namespace wpi::units::angular_acceleration - * @brief namespace for unit types and containers representing angular - * acceleration values - * @details The SI unit for angular acceleration is - * `radians_per_second_squared`, and the corresponding `base_unit` - * category is`angular_acceleration_unit`. - * @anchor angularAccelerationContainers - * @sa See unit_t for more information on unit type containers. - */ -UNIT_ADD(angular_acceleration, radians_per_second_squared, - radians_per_second_squared, rad_per_s_sq, - unit, wpi::units::category::angular_acceleration_unit>) -UNIT_ADD(angular_acceleration, degrees_per_second_squared, - degrees_per_second_squared, deg_per_s_sq, - compound_unit>>) -UNIT_ADD(angular_acceleration, turns_per_second_squared, - turns_per_second_squared, tr_per_s_sq, - compound_unit>>) -UNIT_ADD(angular_acceleration, revolutions_per_minute_squared, - revolutions_per_minute_squared, rev_per_m_sq, - compound_unit>>) -UNIT_ADD(angular_acceleration, revolutions_per_minute_per_second, - revolutions_per_minute_per_second, rev_per_m_per_s, - compound_unit, - inverse>>) - -UNIT_ADD_CATEGORY_TRAIT(angular_acceleration) - -using namespace angular_acceleration; -} // namespace wpi::units diff --git a/wpimath/src/main/native/include/wpi/units/angular_jerk.hpp b/wpimath/src/main/native/include/wpi/units/angular_jerk.hpp deleted file mode 100644 index 5de4937f067..00000000000 --- a/wpimath/src/main/native/include/wpi/units/angular_jerk.hpp +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright (c) FIRST and other WPILib contributors. -// Open Source Software; you can modify and/or share it under the terms of -// the WPILib BSD license file in the root directory of this project. - -#pragma once - -#include "wpi/units/angle.hpp" -#include "wpi/units/base.hpp" -#include "wpi/units/time.hpp" - -namespace wpi::units { -/** - * @namespace wpi::units::angular_jerk - * @brief namespace for unit types and containers representing angular - * jerk values - * @details The SI unit for angular jerk is - * `radians_per_second_cubed`, and the corresponding `base_unit` - * category is`angular_jerk_unit`. - * @anchor angularJerkContainers - * @sa See unit_t for more information on unit type containers. - */ -UNIT_ADD(angular_jerk, radians_per_second_cubed, radians_per_second_cubed, - rad_per_s_cu, - unit, wpi::units::category::angular_jerk_unit>) -UNIT_ADD(angular_jerk, degrees_per_second_cubed, degrees_per_second_cubed, - deg_per_s_cu, - compound_unit>>) -UNIT_ADD(angular_jerk, turns_per_second_cubed, turns_per_second_cubed, - tr_per_s_cu, - compound_unit>>) - -UNIT_ADD_CATEGORY_TRAIT(angular_jerk) - -using namespace angular_jerk; -} // namespace wpi::units diff --git a/wpimath/src/main/native/include/wpi/units/angular_velocity.hpp b/wpimath/src/main/native/include/wpi/units/angular_velocity.hpp deleted file mode 100644 index 518cc45b262..00000000000 --- a/wpimath/src/main/native/include/wpi/units/angular_velocity.hpp +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright (c) FIRST and other WPILib contributors. -// Open Source Software; you can modify and/or share it under the terms of -// the WPILib BSD license file in the root directory of this project. - -// Copyright (c) 2016 Nic Holthaus -// -// The MIT License (MIT) -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. - -#pragma once - -#include "wpi/units/angle.hpp" -#include "wpi/units/base.hpp" -#include "wpi/units/time.hpp" - -namespace wpi::units { -/** - * @namespace wpi::units::angular_velocity - * @brief namespace for unit types and containers representing angular velocity - * values - * @details The SI unit for angular velocity is `radians_per_second`, and the - * corresponding `base_unit` category is`angular_velocity_unit`. - * @anchor angularVelocityContainers - * @sa See unit_t for more information on unit type containers. - */ -#if !defined(DISABLE_PREDEFINED_UNITS) || \ - defined(ENABLE_PREDEFINED_ANGULAR_VELOCITY_UNITS) -UNIT_ADD(angular_velocity, radians_per_second, radians_per_second, rad_per_s, - unit, wpi::units::category::angular_velocity_unit>) -UNIT_ADD(angular_velocity, degrees_per_second, degrees_per_second, deg_per_s, - compound_unit>) -UNIT_ADD(angular_velocity, turns_per_second, turns_per_second, tps, - compound_unit>) -UNIT_ADD(angular_velocity, revolutions_per_minute, revolutions_per_minute, rpm, - unit, radians_per_second, std::ratio<1>>) -UNIT_ADD(angular_velocity, milliarcseconds_per_year, milliarcseconds_per_year, - mas_per_yr, compound_unit>) - -UNIT_ADD_CATEGORY_TRAIT(angular_velocity) -#endif - -using namespace angular_velocity; -} // namespace wpi::units diff --git a/wpimath/src/main/native/include/wpi/units/area.hpp b/wpimath/src/main/native/include/wpi/units/area.hpp deleted file mode 100644 index 85ccbfec876..00000000000 --- a/wpimath/src/main/native/include/wpi/units/area.hpp +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright (c) FIRST and other WPILib contributors. -// Open Source Software; you can modify and/or share it under the terms of -// the WPILib BSD license file in the root directory of this project. - -// Copyright (c) 2016 Nic Holthaus -// -// The MIT License (MIT) -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. - -#pragma once - -#include "wpi/units/base.hpp" -#include "wpi/units/length.hpp" - -namespace wpi::units { -/** - * @namespace wpi::units::area - * @brief namespace for unit types and containers representing area values - * @details The SI unit for area is `square_meters`, and the corresponding - * `base_unit` category is `area_unit`. - * @anchor areaContainers - * @sa See unit_t for more information on unit type containers. - */ -#if !defined(DISABLE_PREDEFINED_UNITS) || defined(ENABLE_PREDEFINED_AREA_UNITS) -UNIT_ADD(area, square_meter, square_meters, sq_m, - unit, wpi::units::category::area_unit>) -UNIT_ADD(area, square_foot, square_feet, sq_ft, squared) -UNIT_ADD(area, square_inch, square_inches, sq_in, squared) -UNIT_ADD(area, square_mile, square_miles, sq_mi, squared) -UNIT_ADD(area, square_kilometer, square_kilometers, sq_km, - squared) -UNIT_ADD(area, hectare, hectares, ha, unit, square_meters>) -UNIT_ADD(area, acre, acres, acre, unit, square_feet>) - -UNIT_ADD_CATEGORY_TRAIT(area) -#endif - -using namespace area; -} // namespace wpi::units diff --git a/wpimath/src/main/native/include/wpi/units/base.hpp b/wpimath/src/main/native/include/wpi/units/base.hpp deleted file mode 100644 index fd8d249be6e..00000000000 --- a/wpimath/src/main/native/include/wpi/units/base.hpp +++ /dev/null @@ -1,3541 +0,0 @@ -// Copyright (c) FIRST and other WPILib contributors. -// Open Source Software; you can modify and/or share it under the terms of -// the WPILib BSD license file in the root directory of this project. - -// Copyright (c) 2016 Nic Holthaus -// -// The MIT License (MIT) -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. -// -// ATTRIBUTION: -// Parts of this work have been adapted from: -// http://stackoverflow.com/questions/35069778/create-comparison-trait-for-template-classes-whose-parameters-are-in-a-different -// http://stackoverflow.com/questions/28253399/check-traits-for-all-variadic-template-arguments/28253503 -// http://stackoverflow.com/questions/36321295/rational-approximation-of-square-root-of-stdratio-at-compile-time?noredirect=1#comment60266601_36321295 -// - -/// @file units.h -/// @brief Complete implementation of `units` - a compile-time, header-only, -/// unit conversion library built on c++14 with no dependencies. - -#pragma once - -#ifdef _MSC_VER -# pragma push_macro("pascal") -# undef pascal -# if _MSC_VER <= 1800 -# define _ALLOW_KEYWORD_MACROS -# pragma warning(push) -# pragma warning(disable : 4520) -# pragma push_macro("constexpr") -# define constexpr /*constexpr*/ -# pragma push_macro("noexcept") -# define noexcept throw() -# endif // _MSC_VER < 1800 -#endif // _MSC_VER - -#if !defined(_MSC_VER) || _MSC_VER > 1800 -# define UNIT_HAS_LITERAL_SUPPORT -#endif - -#ifndef UNIT_LIB_DEFAULT_TYPE -# define UNIT_LIB_DEFAULT_TYPE double -#endif - -//-------------------- -// INCLUDES -//-------------------- - -#include -#include -#include -#include -#include -#include - -#if defined(UNIT_LIB_ENABLE_IOSTREAM) - #include - #include - #include -#endif -#if __has_include() && !defined(UNIT_LIB_DISABLE_FMT) - #include - #include - #include -#endif -#if __has_include() && !defined(UNIT_LIB_DISABLE_TELEMETRY) - #include - #include - #include -#endif - -#include - -//------------------------------ -// STRING FORMATTER -//------------------------------ - -namespace wpi::units -{ - namespace detail - { - template std::string to_string(const T& t) - { - std::string str{ std::to_string(t) }; - int offset{ 1 }; - - // remove trailing decimal points for integer value units. Locale aware! - struct lconv * lc; - lc = localeconv(); - char decimalPoint = *lc->decimal_point; - if (str.find_last_not_of('0') == str.find(decimalPoint)) { offset = 0; } - str.erase(str.find_last_not_of('0') + offset, std::string::npos); - return str; - } - } -} - -namespace wpi::units -{ - template constexpr const char* name(const T&); - template constexpr const char* abbreviation(const T&); -} - -//------------------------------ -// MACROS -//------------------------------ - -/** - * @def UNIT_ADD_UNIT_TAGS(namespaceName,nameSingular, namePlural, abbreviation, definition) - * @brief Helper macro for generating the boiler-plate code generating the tags of a new unit. - * @details The macro generates singular, plural, and abbreviated forms - * of the unit definition (e.g. `meter`, `meters`, and `m`), as aliases for the - * unit tag. - * @param namespaceName namespace in which the new units will be encapsulated. - * @param nameSingular singular version of the unit name, e.g. 'meter' - * @param namePlural - plural version of the unit name, e.g. 'meters' - * @param abbreviation - abbreviated unit name, e.g. 'm' - * @param definition - the variadic parameter is used for the definition of the unit - * (e.g. `unit, wpi::units::category::length_unit>`) - * @note a variadic template is used for the definition to allow templates with - * commas to be easily expanded. All the variadic 'arguments' should together - * comprise the unit definition. - */ -#define UNIT_ADD_UNIT_TAGS(namespaceName,nameSingular, namePlural, abbreviation, /*definition*/...)\ - namespace namespaceName\ - {\ - /** @name Units (full names plural) */ /** @{ */ typedef __VA_ARGS__ namePlural; /** @} */\ - /** @name Units (full names singular) */ /** @{ */ typedef namePlural nameSingular; /** @} */\ - /** @name Units (abbreviated) */ /** @{ */ typedef namePlural abbreviation; /** @} */\ - } - -/** - * @def UNIT_ADD_UNIT_DEFINITION(namespaceName,nameSingular) - * @brief Macro for generating the boiler-plate code for the unit_t type definition. - * @details The macro generates the definition of the unit container types, e.g. `meter_t` - * @param namespaceName namespace in which the new units will be encapsulated. - * @param nameSingular singular version of the unit name, e.g. 'meter' - */ -#define UNIT_ADD_UNIT_DEFINITION(namespaceName,nameSingular)\ - namespace namespaceName\ - {\ - /** @name Unit Containers */ /** @{ */ typedef unit_t nameSingular ## _t; /** @} */\ - } - -/** - * @def UNIT_ADD_CUSTOM_TYPE_UNIT_DEFINITION(namespaceName,nameSingular,underlyingType) - * @brief Macro for generating the boiler-plate code for a unit_t type definition with a non-default underlying type. - * @details The macro generates the definition of the unit container types, e.g. `meter_t` - * @param namespaceName namespace in which the new units will be encapsulated. - * @param nameSingular singular version of the unit name, e.g. 'meter' - * @param underlyingType the underlying type - */ -#define UNIT_ADD_CUSTOM_TYPE_UNIT_DEFINITION(namespaceName,nameSingular, underlyingType)\ - namespace namespaceName\ - {\ - /** @name Unit Containers */ /** @{ */ typedef unit_t nameSingular ## _t; /** @} */\ - } -/** - * @def UNIT_ADD_IO(namespaceName,nameSingular, abbreviation) - * @brief Macro for generating the boiler-plate code needed for I/O for a new unit. - * @details The macro generates the code to insert units into an ostream. It - * prints both the value and abbreviation of the unit when invoked. - * @param namespaceName namespace in which the new units will be encapsulated. - * @param nameSingular singular version of the unit name, e.g. 'meter' - * @param abbrev - abbreviated unit name, e.g. 'm' - * @note When UNIT_LIB_DISABLE_FMT is defined and UNIT_LIB_ENABLE_IOSTREAM isn't defined, the macro does not generate any code - */ -#if __has_include() && !defined(UNIT_LIB_DISABLE_FMT) - #define UNIT_ADD_IO(namespaceName, nameSingular, abbrev)\ - }\ - template <>\ - struct std::formatter \ - : std::formatter \ - {\ - template \ - auto format(\ - const wpi::units::namespaceName::nameSingular ## _t& obj,\ - FmtContext& ctx) const\ - {\ - auto out = ctx.out();\ - out = std::formatter::format(obj(), ctx);\ - return std::format_to(out, " " #abbrev);\ - }\ - };\ - namespace wpi::units\ - {\ - namespace namespaceName\ - {\ - inline std::string to_string(const nameSingular ## _t& obj)\ - {\ - return wpi::units::detail::to_string(obj()) + std::string(" "#abbrev);\ - }\ - } -#elif defined(UNIT_LIB_ENABLE_IOSTREAM) - #define UNIT_ADD_IO(namespaceName, nameSingular, abbrev)\ - namespace namespaceName\ - {\ - inline std::ostream& operator<<(std::ostream& os, const nameSingular ## _t& obj) \ - {\ - os << obj() << " "#abbrev; return os; \ - }\ - inline std::string to_string(const nameSingular ## _t& obj)\ - {\ - return wpi::units::detail::to_string(obj()) + std::string(" "#abbrev);\ - }\ - } -#else - #define UNIT_ADD_IO(namespaceName, nameSingular, abbrev) -#endif -/** - * @def UNIT_ADD_TELEMETRY(namespaceName,nameSingular, abbreviation) - * @brief Macro for generating the boiler-plate code needed for telemetry for a new unit. - * @details The macro generates the code to insert units into a wpi::telemetry::TelemetryTable - * @param namespaceName namespace in which the new units will be encapsulated. - * @param nameSingular singular version of the unit name, e.g. 'meter' - * @param abbrev - abbreviated unit name, e.g. 'm' - * @note When UNIT_LIB_DISABLE_TELEMETRY is defined, the macro does not generate any code - */ -#if __has_include() && !defined(UNIT_LIB_DISABLE_TELEMETRY) - #define UNIT_ADD_TELEMETRY(namespaceName, nameSingular, abbrev)\ - namespace namespaceName\ - {\ - inline void LogValueTo(wpi::telemetry::TelemetryTable& table, std::string_view name, const nameSingular ## _t& value)\ - {\ - table.SetProperty(name, "unit", "\"" #abbrev "\"");\ - table.Log(name, value());\ - }\ - } -#else - #define UNIT_ADD_TELEMETRY(namespaceName, nameSingular, abbrev) -#endif - - /** - * @def UNIT_ADD_NAME(namespaceName,nameSingular,abbreviation) - * @brief Macro for generating constexpr names/abbreviations for units. - * @details The macro generates names for units. E.g. name() of 1_m would be "meter", and - * abbreviation would be "m". - * @param namespaceName namespace in which the new units will be encapsulated. All literal values - * are placed in the `wpi::units::literals` namespace. - * @param nameSingular singular version of the unit name, e.g. 'meter' - * @param abbreviation - abbreviated unit name, e.g. 'm' - */ -#define UNIT_ADD_NAME(namespaceName, nameSingular, abbrev)\ -template<> constexpr const char* name(const namespaceName::nameSingular ## _t&)\ -{\ - return #nameSingular;\ -}\ -template<> constexpr const char* abbreviation(const namespaceName::nameSingular ## _t&)\ -{\ - return #abbrev;\ -} - -/** - * @def UNIT_ADD_LITERALS(namespaceName,nameSingular,abbreviation) - * @brief Macro for generating user-defined literals for units. - * @details The macro generates user-defined literals for units. A literal suffix is created - * using the abbreviation (e.g. `10.0_m`). - * @param namespaceName namespace in which the new units will be encapsulated. All literal values - * are placed in the `wpi::units::literals` namespace. - * @param nameSingular singular version of the unit name, e.g. 'meter' - * @param abbreviation - abbreviated unit name, e.g. 'm' - * @note When UNIT_HAS_LITERAL_SUPPORT is not defined, the macro does not generate any code - */ -#if defined(UNIT_HAS_LITERAL_SUPPORT) - #define UNIT_ADD_LITERALS(namespaceName, nameSingular, abbreviation)\ - namespace literals\ - {\ - constexpr namespaceName::nameSingular ## _t operator""_ ## abbreviation(long double d)\ - {\ - return namespaceName::nameSingular ## _t(static_cast(d));\ - }\ - constexpr namespaceName::nameSingular ## _t operator""_ ## abbreviation (unsigned long long d)\ - {\ - return namespaceName::nameSingular ## _t(static_cast(d));\ - }\ - } -#else - #define UNIT_ADD_LITERALS(namespaceName, nameSingular, abbreviation) -#endif - -/** - * @def UNIT_ADD(namespaceName,nameSingular, namePlural, abbreviation, definition) - * @brief Macro for generating the boiler-plate code needed for a new unit. - * @details The macro generates singular, plural, and abbreviated forms - * of the unit definition (e.g. `meter`, `meters`, and `m`), as well as the - * appropriately named unit container (e.g. `meter_t`). A literal suffix is created - * using the abbreviation (e.g. `10.0_m`). It also defines a class-specific - * cout function which prints both the value and abbreviation of the unit when invoked. - * @param namespaceName namespace in which the new units will be encapsulated. All literal values - * are placed in the `wpi::units::literals` namespace. - * @param nameSingular singular version of the unit name, e.g. 'meter' - * @param namePlural - plural version of the unit name, e.g. 'meters' - * @param abbreviation - abbreviated unit name, e.g. 'm' - * @param definition - the variadic parameter is used for the definition of the unit - * (e.g. `unit, wpi::units::category::length_unit>`) - * @note a variadic template is used for the definition to allow templates with - * commas to be easily expanded. All the variadic 'arguments' should together - * comprise the unit definition. - */ -#define UNIT_ADD(namespaceName, nameSingular, namePlural, abbreviation, /*definition*/...)\ - UNIT_ADD_UNIT_TAGS(namespaceName,nameSingular, namePlural, abbreviation, __VA_ARGS__)\ - UNIT_ADD_UNIT_DEFINITION(namespaceName,nameSingular)\ - UNIT_ADD_NAME(namespaceName,nameSingular, abbreviation)\ - UNIT_ADD_IO(namespaceName,nameSingular, abbreviation)\ - UNIT_ADD_TELEMETRY(namespaceName,nameSingular, abbreviation)\ - UNIT_ADD_LITERALS(namespaceName,nameSingular, abbreviation) - -/** - * @def UNIT_ADD_WITH_CUSTOM_TYPE(namespaceName,nameSingular, namePlural, abbreviation, underlyingType, definition) - * @brief Macro for generating the boiler-plate code needed for a new unit with a non-default underlying type. - * @details The macro generates singular, plural, and abbreviated forms - * of the unit definition (e.g. `meter`, `meters`, and `m`), as well as the - * appropriately named unit container (e.g. `meter_t`). A literal suffix is created - * using the abbreviation (e.g. `10.0_m`). It also defines a class-specific - * cout function which prints both the value and abbreviation of the unit when invoked. - * @param namespaceName namespace in which the new units will be encapsulated. All literal values - * are placed in the `wpi::units::literals` namespace. - * @param nameSingular singular version of the unit name, e.g. 'meter' - * @param namePlural - plural version of the unit name, e.g. 'meters' - * @param abbreviation - abbreviated unit name, e.g. 'm' - * @param underlyingType - the underlying type, e.g. 'int' or 'float' - * @param definition - the variadic parameter is used for the definition of the unit - * (e.g. `unit, wpi::units::category::length_unit>`) - * @note a variadic template is used for the definition to allow templates with - * commas to be easily expanded. All the variadic 'arguments' should together - * comprise the unit definition. - */ -#define UNIT_ADD_WITH_CUSTOM_TYPE(namespaceName, nameSingular, namePlural, abbreviation, underlyingType, /*definition*/...)\ - UNIT_ADD_UNIT_TAGS(namespaceName,nameSingular, namePlural, abbreviation, __VA_ARGS__)\ - UNIT_ADD_CUSTOM_TYPE_UNIT_DEFINITION(namespaceName,nameSingular,underlyingType)\ - UNIT_ADD_IO(namespaceName,nameSingular, abbreviation)\ - UNIT_ADD_TELEMETRY(namespaceName,nameSingular, abbreviation)\ - UNIT_ADD_LITERALS(namespaceName,nameSingular, abbreviation) - -/** - * @def UNIT_ADD_DECIBEL(namespaceName, nameSingular, abbreviation) - * @brief Macro to create decibel container and literals for an existing unit type. - * @details This macro generates the decibel unit container, cout overload, and literal definitions. - * @param namespaceName namespace in which the new units will be encapsulated. All literal values - * are placed in the `wpi::units::literals` namespace. - * @param nameSingular singular version of the base unit name, e.g. 'watt' - * @param abbreviation - abbreviated decibel unit name, e.g. 'dBW' - */ -#define UNIT_ADD_DECIBEL(namespaceName, nameSingular, abbreviation)\ - namespace namespaceName\ - {\ - /** @name Unit Containers */ /** @{ */ typedef unit_t abbreviation ## _t; /** @} */\ - }\ - UNIT_ADD_IO(namespaceName, abbreviation, abbreviation)\ - UNIT_ADD_TELEMETRY(namespaceName, abbreviation, abbreviation)\ - UNIT_ADD_LITERALS(namespaceName, abbreviation, abbreviation) - -/** - * @def UNIT_ADD_CATEGORY_TRAIT(unitCategory, baseUnit) - * @brief Macro to create the `is_category_unit` type trait. - * @details This trait allows users to test whether a given type matches - * an intended category. This macro comprises all the boiler-plate - * code necessary to do so. - * @param unitCategory The name of the category of unit, e.g. length or mass. - */ - -#define UNIT_ADD_CATEGORY_TRAIT_DETAIL(unitCategory)\ - namespace traits\ - {\ - /** @cond */\ - namespace detail\ - {\ - template struct is_ ## unitCategory ## _unit_impl : std::false_type {};\ - template\ - struct is_ ## unitCategory ## _unit_impl> : std::is_same>::base_unit_type>, wpi::units::category::unitCategory ## _unit>::type {};\ - template class N>\ - struct is_ ## unitCategory ## _unit_impl> : std::is_same>::unit_type>, wpi::units::category::unitCategory ## _unit>::type {};\ - }\ - /** @endcond */\ - } - -#define UNIT_ADD_IS_UNIT_CATEGORY_TRAIT(unitCategory)\ - namespace traits\ - {\ - template struct is_ ## unitCategory ## _unit : std::integral_constant>::value...>::value> {};\ - template constexpr bool is_ ## unitCategory ## _unit_v = is_ ## unitCategory ## _unit::value;\ - }\ - template \ - concept unitCategory ## _unit = traits::is_ ## unitCategory ## _unit_v; - -#define UNIT_ADD_CATEGORY_TRAIT(unitCategory)\ - UNIT_ADD_CATEGORY_TRAIT_DETAIL(unitCategory)\ - /** @ingroup TypeTraits*/\ - /** @brief Trait which tests whether a type represents a unit of unitCategory*/\ - /** @details Inherits from `std::true_type` or `std::false_type`. Use `is_ ## unitCategory ## _unit::value` to test the unit represents a unitCategory quantity.*/\ - /** @tparam T one or more types to test*/\ - UNIT_ADD_IS_UNIT_CATEGORY_TRAIT(unitCategory) - -/** - * @def UNIT_ADD_WITH_METRIC_PREFIXES(nameSingular, namePlural, abbreviation, definition) - * @brief Macro for generating the boiler-plate code needed for a new unit, including its metric - * prefixes from femto to peta. - * @details See UNIT_ADD. In addition to generating the unit definition and containers '(e.g. `meters` and 'meter_t', - * it also creates corresponding units with metric suffixes such as `millimeters`, and `millimeter_t`), as well as the - * literal suffixes (e.g. `10.0_mm`). - * @param namespaceName namespace in which the new units will be encapsulated. All literal values - * are placed in the `wpi::units::literals` namespace. - * @param nameSingular singular version of the unit name, e.g. 'meter' - * @param namePlural - plural version of the unit name, e.g. 'meters' - * @param abbreviation - abbreviated unit name, e.g. 'm' - * @param definition - the variadic parameter is used for the definition of the unit - * (e.g. `unit, wpi::units::category::length_unit>`) - * @note a variadic template is used for the definition to allow templates with - * commas to be easily expanded. All the variadic 'arguments' should together - * comprise the unit definition. - */ -#define UNIT_ADD_WITH_METRIC_PREFIXES(namespaceName, nameSingular, namePlural, abbreviation, /*definition*/...)\ - UNIT_ADD(namespaceName, nameSingular, namePlural, abbreviation, __VA_ARGS__)\ - UNIT_ADD(namespaceName, femto ## nameSingular, femto ## namePlural, f ## abbreviation, femto)\ - UNIT_ADD(namespaceName, pico ## nameSingular, pico ## namePlural, p ## abbreviation, pico)\ - UNIT_ADD(namespaceName, nano ## nameSingular, nano ## namePlural, n ## abbreviation, nano)\ - UNIT_ADD(namespaceName, micro ## nameSingular, micro ## namePlural, u ## abbreviation, micro)\ - UNIT_ADD(namespaceName, milli ## nameSingular, milli ## namePlural, m ## abbreviation, milli)\ - UNIT_ADD(namespaceName, centi ## nameSingular, centi ## namePlural, c ## abbreviation, centi)\ - UNIT_ADD(namespaceName, deci ## nameSingular, deci ## namePlural, d ## abbreviation, deci)\ - UNIT_ADD(namespaceName, deca ## nameSingular, deca ## namePlural, da ## abbreviation, deca)\ - UNIT_ADD(namespaceName, hecto ## nameSingular, hecto ## namePlural, h ## abbreviation, hecto)\ - UNIT_ADD(namespaceName, kilo ## nameSingular, kilo ## namePlural, k ## abbreviation, kilo)\ - UNIT_ADD(namespaceName, mega ## nameSingular, mega ## namePlural, M ## abbreviation, mega)\ - UNIT_ADD(namespaceName, giga ## nameSingular, giga ## namePlural, G ## abbreviation, giga)\ - UNIT_ADD(namespaceName, tera ## nameSingular, tera ## namePlural, T ## abbreviation, tera)\ - UNIT_ADD(namespaceName, peta ## nameSingular, peta ## namePlural, P ## abbreviation, peta)\ - - /** - * @def UNIT_ADD_WITH_METRIC_AND_BINARY_PREFIXES(nameSingular, namePlural, abbreviation, definition) - * @brief Macro for generating the boiler-plate code needed for a new unit, including its metric - * prefixes from femto to peta, and binary prefixes from kibi to exbi. - * @details See UNIT_ADD. In addition to generating the unit definition and containers '(e.g. `bytes` and 'byte_t', - * it also creates corresponding units with metric suffixes such as `millimeters`, and `millimeter_t`), as well as the - * literal suffixes (e.g. `10.0_B`). - * @param namespaceName namespace in which the new units will be encapsulated. All literal values - * are placed in the `wpi::units::literals` namespace. - * @param nameSingular singular version of the unit name, e.g. 'byte' - * @param namePlural - plural version of the unit name, e.g. 'bytes' - * @param abbreviation - abbreviated unit name, e.g. 'B' - * @param definition - the variadic parameter is used for the definition of the unit - * (e.g. `unit, wpi::units::category::data_unit>`) - * @note a variadic template is used for the definition to allow templates with - * commas to be easily expanded. All the variadic 'arguments' should together - * comprise the unit definition. - */ -#define UNIT_ADD_WITH_METRIC_AND_BINARY_PREFIXES(namespaceName, nameSingular, namePlural, abbreviation, /*definition*/...)\ - UNIT_ADD_WITH_METRIC_PREFIXES(namespaceName, nameSingular, namePlural, abbreviation, __VA_ARGS__)\ - UNIT_ADD(namespaceName, kibi ## nameSingular, kibi ## namePlural, Ki ## abbreviation, kibi)\ - UNIT_ADD(namespaceName, mebi ## nameSingular, mebi ## namePlural, Mi ## abbreviation, mebi)\ - UNIT_ADD(namespaceName, gibi ## nameSingular, gibi ## namePlural, Gi ## abbreviation, gibi)\ - UNIT_ADD(namespaceName, tebi ## nameSingular, tebi ## namePlural, Ti ## abbreviation, tebi)\ - UNIT_ADD(namespaceName, pebi ## nameSingular, pebi ## namePlural, Pi ## abbreviation, pebi)\ - UNIT_ADD(namespaceName, exbi ## nameSingular, exbi ## namePlural, Ei ## abbreviation, exbi) - -//-------------------- -// UNITS NAMESPACE -//-------------------- - -/** - * @namespace wpi::units - * @brief Unit Conversion Library namespace - */ -namespace wpi::units -{ - //---------------------------------- - // DOXYGEN - //---------------------------------- - - /** - * @defgroup Units Unit API - */ - - /** - * @defgroup UnitContainers Unit Containers - * @ingroup Units - * @brief Defines a series of classes which contain dimensioned values. Unit containers - * store a value, and support various arithmetic operations. - */ - - /** - * @defgroup UnitTypes Unit Types - * @ingroup Units - * @brief Defines a series of classes which represent units. These types are tags used by - * the conversion function, to create compound units, or to create `unit_t` types. - * By themselves, they are not containers and have no stored value. - */ - - /** - * @defgroup UnitManipulators Unit Manipulators - * @ingroup Units - * @brief Defines a series of classes used to manipulate unit types, such as `inverse<>`, `squared<>`, and metric prefixes. - * Unit manipulators can be chained together, e.g. `inverse>>` to - * represent picoseconds^-2. - */ - - /** - * @defgroup CompileTimeUnitManipulators Compile-time Unit Manipulators - * @ingroup Units - * @brief Defines a series of classes used to manipulate `unit_value_t` types at compile-time, such as `unit_value_add<>`, `unit_value_sqrt<>`, etc. - * Compile-time manipulators can be chained together, e.g. `unit_value_sqrt, unit_value_power>>` to - * represent `c = sqrt(a^2 + b^2). - */ - - /** - * @defgroup UnitMath Unit Math - * @ingroup Units - * @brief Defines a collection of unit-enabled, strongly-typed versions of `` functions. - * @details Includes most c++11 extensions. - */ - - /** - * @defgroup Conversion Explicit Conversion - * @ingroup Units - * @brief Functions used to convert values of one logical type to another. - */ - - /** - * @defgroup TypeTraits Type Traits - * @ingroup Units - * @brief Defines a series of classes to obtain unit type information at compile-time. - */ - - //------------------------------ - // FORWARD DECLARATIONS - //------------------------------ - - /** @cond */ // DOXYGEN IGNORE - namespace constants - { - namespace detail - { - static constexpr const UNIT_LIB_DEFAULT_TYPE PI_VAL = 3.14159265358979323846264338327950288419716939937510; - } - } - /** @endcond */ // END DOXYGEN IGNORE - - //------------------------------ - // RATIO TRAITS - //------------------------------ - - /** - * @ingroup TypeTraits - * @{ - */ - - /** @cond */ // DOXYGEN IGNORE - namespace detail - { - /// has_num implementation. - template - struct has_num_impl - { - template - static constexpr auto test(U*)->std::is_integral {return std::is_integral{}; } - template - static constexpr std::false_type test(...) { return std::false_type{}; } - - using type = decltype(test(0)); - }; - } - - /** - * @brief Trait which checks for the existence of a static numerator. - * @details Inherits from `std::true_type` or `std::false_type`. Use `has_num::value` to test - * whether `class T` has a numerator static member. - */ - template - struct has_num : wpi::units::detail::has_num_impl::type {}; - - namespace detail - { - /// has_den implementation. - template - struct has_den_impl - { - template - static constexpr auto test(U*)->std::is_integral { return std::is_integral{}; } - template - static constexpr std::false_type test(...) { return std::false_type{}; } - - using type = decltype(test(0)); - }; - } - - /** - * @brief Trait which checks for the existence of a static denominator. - * @details Inherits from `std::true_type` or `std::false_type`. Use `has_den::value` to test - * whether `class T` has a denominator static member. - */ - template - struct has_den : wpi::units::detail::has_den_impl::type {}; - - /** @endcond */ // END DOXYGEN IGNORE - - namespace traits - { - /** - * @brief Trait that tests whether a type represents a std::ratio. - * @details Inherits from `std::true_type` or `std::false_type`. Use `is_ratio::value` to test - * whether `class T` implements a std::ratio. - */ - template - struct is_ratio : std::integral_constant::value && - has_den::value> - {}; - template - constexpr bool is_ratio_v = is_ratio::value; - } - - //------------------------------ - // UNIT TRAITS - //------------------------------ - - /** @cond */ // DOXYGEN IGNORE - /** - * @brief void type. - * @details Helper class for creating type traits. - */ - template - struct void_t { typedef void type; }; - - /** - * @brief parameter pack for boolean arguments. - */ - template struct bool_pack {}; - - /** - * @brief Trait which tests that a set of other traits are all true. - */ - template - struct all_true : std::is_same, wpi::units::bool_pack> {}; - template - constexpr bool all_true_t_v = all_true::type::value; - /** @endcond */ // DOXYGEN IGNORE - - /** - * @brief namespace representing type traits which can access the properties of types provided by the units library. - */ - namespace traits - { -#ifdef FOR_DOXYGEN_PURPOSES_ONLY - /** - * @ingroup TypeTraits - * @brief Traits class defining the properties of units. - * @details The units library determines certain properties of the units passed to - * them and what they represent by using the members of the corresponding - * unit_traits instantiation. - */ - template - struct unit_traits - { - typedef typename T::base_unit_type base_unit_type; ///< Unit type that the unit was derived from. May be a `base_unit` or another `unit`. Use the `base_unit_of` trait to find the SI base unit type. This will be `void` if type `T` is not a unit. - typedef typename T::conversion_ratio conversion_ratio; ///< `std::ratio` representing the conversion factor to the `base_unit_type`. This will be `void` if type `T` is not a unit. - typedef typename T::pi_exponent_ratio pi_exponent_ratio; ///< `std::ratio` representing the exponent of pi to be used in the conversion. This will be `void` if type `T` is not a unit. - typedef typename T::translation_ratio translation_ratio; ///< `std::ratio` representing a datum translation to the base unit (i.e. degrees C to degrees F conversion). This will be `void` if type `T` is not a unit. - }; -#endif - /** @cond */ // DOXYGEN IGNORE - /** - * @brief unit traits implementation for classes which are not units. - */ - template - struct unit_traits - { - typedef void base_unit_type; - typedef void conversion_ratio; - typedef void pi_exponent_ratio; - typedef void translation_ratio; - }; - - template - struct unit_traits - ::type> - { - typedef typename T::base_unit_type base_unit_type; ///< Unit type that the unit was derived from. May be a `base_unit` or another `unit`. Use the `base_unit_of` trait to find the SI base unit type. This will be `void` if type `T` is not a unit. - typedef typename T::conversion_ratio conversion_ratio; ///< `std::ratio` representing the conversion factor to the `base_unit_type`. This will be `void` if type `T` is not a unit. - typedef typename T::pi_exponent_ratio pi_exponent_ratio; ///< `std::ratio` representing the exponent of pi to be used in the conversion. This will be `void` if type `T` is not a unit. - typedef typename T::translation_ratio translation_ratio; ///< `std::ratio` representing a datum translation to the base unit (i.e. degrees C to degrees F conversion). This will be `void` if type `T` is not a unit. - }; - /** @endcond */ // END DOXYGEN IGNORE - } - - /** @cond */ // DOXYGEN IGNORE - namespace detail - { - /** - * @brief helper type to identify base units. - * @details A non-templated base class for `base_unit` which enables RTTI testing. - */ - struct _base_unit_t {}; - } - /** @endcond */ // END DOXYGEN IGNORE - - namespace traits - { - /** - * @ingroup TypeTraits - * @brief Trait which tests if a class is a `base_unit` type. - * @details Inherits from `std::true_type` or `std::false_type`. Use `is_base_unit::value` to test - * whether `class T` implements a `base_unit`. - */ - template - struct is_base_unit : std::is_base_of {}; - } - - /** @cond */ // DOXYGEN IGNORE - namespace detail - { - /** - * @brief helper type to identify units. - * @details A non-templated base class for `unit` which enables RTTI testing. - */ - struct _unit {}; - - template - using meter_ratio = std::ratio; - } - /** @endcond */ // END DOXYGEN IGNORE - - namespace traits - { - /** - * @ingroup TypeTraits - * @brief Traits which tests if a class is a `unit` - * @details Inherits from `std::true_type` or `std::false_type`. Use `is_unit::value` to test - * whether `class T` implements a `unit`. - */ - template - struct is_unit : std::is_base_of::type {}; - template - constexpr bool is_unit_v = is_unit::value; - } - - /** @} */ // end of TypeTraits - - //------------------------------ - // BASE UNIT CLASS - //------------------------------ - - /** - * @ingroup UnitTypes - * @brief Class representing SI base unit types. - * @details Base units are represented by a combination of `std::ratio` template parameters, each - * describing the exponent of the type of unit they represent. Example: meters per second - * would be described by a +1 exponent for meters, and a -1 exponent for seconds, thus: - * `base_unit, std::ratio<0>, std::ratio<-1>>` - * @tparam Meter `std::ratio` representing the exponent value for meters. - * @tparam Kilogram `std::ratio` representing the exponent value for kilograms. - * @tparam Second `std::ratio` representing the exponent value for seconds. - * @tparam Radian `std::ratio` representing the exponent value for radians. Although radians are not SI base units, they are included because radians are described by the SI as m * m^-1, which would make them indistinguishable from scalars. - * @tparam Ampere `std::ratio` representing the exponent value for amperes. - * @tparam Kelvin `std::ratio` representing the exponent value for Kelvin. - * @tparam Mole `std::ratio` representing the exponent value for moles. - * @tparam Candela `std::ratio` representing the exponent value for candelas. - * @tparam Byte `std::ratio` representing the exponent value for bytes. - * @sa category for type aliases for SI base_unit types. - */ - template, - class Kilogram = std::ratio<0>, - class Second = std::ratio<0>, - class Radian = std::ratio<0>, - class Ampere = std::ratio<0>, - class Kelvin = std::ratio<0>, - class Mole = std::ratio<0>, - class Candela = std::ratio<0>, - class Byte = std::ratio<0>> - struct base_unit : wpi::units::detail::_base_unit_t - { - static_assert(traits::is_ratio::value, "Template parameter `Meter` must be a `std::ratio` representing the exponent of meters the unit has"); - static_assert(traits::is_ratio::value, "Template parameter `Kilogram` must be a `std::ratio` representing the exponent of kilograms the unit has"); - static_assert(traits::is_ratio::value, "Template parameter `Second` must be a `std::ratio` representing the exponent of seconds the unit has"); - static_assert(traits::is_ratio::value, "Template parameter `Ampere` must be a `std::ratio` representing the exponent of amperes the unit has"); - static_assert(traits::is_ratio::value, "Template parameter `Kelvin` must be a `std::ratio` representing the exponent of kelvin the unit has"); - static_assert(traits::is_ratio::value, "Template parameter `Candela` must be a `std::ratio` representing the exponent of candelas the unit has"); - static_assert(traits::is_ratio::value, "Template parameter `Mole` must be a `std::ratio` representing the exponent of moles the unit has"); - static_assert(traits::is_ratio::value, "Template parameter `Radian` must be a `std::ratio` representing the exponent of radians the unit has"); - static_assert(traits::is_ratio::value, "Template parameter `Byte` must be a `std::ratio` representing the exponent of bytes the unit has"); - - typedef Meter meter_ratio; - typedef Kilogram kilogram_ratio; - typedef Second second_ratio; - typedef Radian radian_ratio; - typedef Ampere ampere_ratio; - typedef Kelvin kelvin_ratio; - typedef Mole mole_ratio; - typedef Candela candela_ratio; - typedef Byte byte_ratio; - }; - - //------------------------------ - // UNIT CATEGORIES - //------------------------------ - - /** - * @brief namespace representing the implemented base and derived unit types. These will not generally be needed by library users. - * @sa base_unit for the definition of the category parameters. - */ - namespace category - { - // SCALAR (DIMENSIONLESS) TYPES - typedef base_unit<> scalar_unit; ///< Represents a quantity with no dimension. - typedef base_unit<> dimensionless_unit; ///< Represents a quantity with no dimension. - - // SI BASE UNIT TYPES - // METERS KILOGRAMS SECONDS RADIANS AMPERES KELVIN MOLE CANDELA BYTE --- CATEGORY - typedef base_unit> length_unit; ///< Represents an SI base unit of length - typedef base_unit, std::ratio<1>> mass_unit; ///< Represents an SI base unit of mass - typedef base_unit, std::ratio<0>, std::ratio<1>> time_unit; ///< Represents an SI base unit of time - typedef base_unit, std::ratio<0>, std::ratio<0>, std::ratio<1>> angle_unit; ///< Represents an SI base unit of angle - typedef base_unit, std::ratio<0>, std::ratio<0>, std::ratio<0>, std::ratio<1>> current_unit; ///< Represents an SI base unit of current - typedef base_unit, std::ratio<0>, std::ratio<0>, std::ratio<0>, std::ratio<0>, std::ratio<1>> temperature_unit; ///< Represents an SI base unit of temperature - typedef base_unit, std::ratio<0>, std::ratio<0>, std::ratio<0>, std::ratio<0>, std::ratio<0>, std::ratio<1>> substance_unit; ///< Represents an SI base unit of amount of substance - typedef base_unit, std::ratio<0>, std::ratio<0>, std::ratio<0>, std::ratio<0>, std::ratio<0>, std::ratio<0>, std::ratio<1>> luminous_intensity_unit; ///< Represents an SI base unit of luminous intensity - - // SI DERIVED UNIT TYPES - // METERS KILOGRAMS SECONDS RADIANS AMPERES KELVIN MOLE CANDELA BYTE --- CATEGORY - typedef base_unit, std::ratio<0>, std::ratio<0>, std::ratio<2>, std::ratio<0>, std::ratio<0>, std::ratio<0>, std::ratio<0>> solid_angle_unit; ///< Represents an SI derived unit of solid angle - typedef base_unit, std::ratio<0>, std::ratio<-1>> frequency_unit; ///< Represents an SI derived unit of frequency - typedef base_unit, std::ratio<0>, std::ratio<-1>> velocity_unit; ///< Represents an SI derived unit of velocity - typedef base_unit, std::ratio<0>, std::ratio<-1>, std::ratio<1>> angular_velocity_unit; ///< Represents an SI derived unit of angular velocity - typedef base_unit, std::ratio<0>, std::ratio<-2>> acceleration_unit; ///< Represents an SI derived unit of acceleration - typedef base_unit, std::ratio<0>, std::ratio<-2>, std::ratio<1>> angular_acceleration_unit; ///< Represents an SI derived unit of angular acceleration - typedef base_unit, std::ratio<0>, std::ratio<-3>, std::ratio<1>> angular_jerk_unit; ///< Represents an SI derived unit of angular jerk - typedef base_unit, std::ratio<1>, std::ratio<-2>> force_unit; ///< Represents an SI derived unit of force - typedef base_unit, std::ratio<1>, std::ratio<-2>> pressure_unit; ///< Represents an SI derived unit of pressure - typedef base_unit, std::ratio<0>, std::ratio<1>, std::ratio<0>, std::ratio<1>> charge_unit; ///< Represents an SI derived unit of charge - typedef base_unit, std::ratio<1>, std::ratio<-2>> energy_unit; ///< Represents an SI derived unit of energy - typedef base_unit, std::ratio<1>, std::ratio<-3>> power_unit; ///< Represents an SI derived unit of power - typedef base_unit, std::ratio<1>, std::ratio<-3>, std::ratio<0>, std::ratio<-1>> voltage_unit; ///< Represents an SI derived unit of voltage - typedef base_unit, std::ratio<-1>, std::ratio<4>, std::ratio<0>, std::ratio<2>> capacitance_unit; ///< Represents an SI derived unit of capacitance - typedef base_unit, std::ratio<1>, std::ratio<-3>, std::ratio<0>, std::ratio<-2>> impedance_unit; ///< Represents an SI derived unit of impedance - typedef base_unit, std::ratio<-1>, std::ratio<3>, std::ratio<0>, std::ratio<2>> conductance_unit; ///< Represents an SI derived unit of conductance - typedef base_unit, std::ratio<1>, std::ratio<-2>, std::ratio<0>, std::ratio<-1>> magnetic_flux_unit; ///< Represents an SI derived unit of magnetic flux - typedef base_unit, std::ratio<1>, std::ratio<-2>, std::ratio<0>, std::ratio<-1>> magnetic_field_strength_unit; ///< Represents an SI derived unit of magnetic field strength - typedef base_unit, std::ratio<1>, std::ratio<-2>, std::ratio<0>, std::ratio<-2>> inductance_unit; ///< Represents an SI derived unit of inductance - typedef base_unit, std::ratio<0>, std::ratio<0>, std::ratio<2>, std::ratio<0>, std::ratio<0>, std::ratio<0>, std::ratio<1>> luminous_flux_unit; ///< Represents an SI derived unit of luminous flux - typedef base_unit, std::ratio<0>, std::ratio<0>, std::ratio<2>, std::ratio<0>, std::ratio<0>, std::ratio<0>, std::ratio<1>> illuminance_unit; ///< Represents an SI derived unit of illuminance - typedef base_unit, std::ratio<0>, std::ratio<-1>> radioactivity_unit; ///< Represents an SI derived unit of radioactivity - - // OTHER UNIT TYPES - // METERS KILOGRAMS SECONDS RADIANS AMPERES KELVIN MOLE CANDELA BYTE --- CATEGORY - typedef base_unit, std::ratio<1>, std::ratio<-2>> torque_unit; ///< Represents an SI derived unit of torque - typedef base_unit> area_unit; ///< Represents an SI derived unit of area - typedef base_unit> volume_unit; ///< Represents an SI derived unit of volume - typedef base_unit, std::ratio<1>> density_unit; ///< Represents an SI derived unit of density - typedef base_unit<> concentration_unit; ///< Represents a unit of concentration - typedef base_unit, std::ratio<0>, std::ratio<0>, std::ratio<0>, std::ratio<0>, std::ratio<0>, std::ratio<0>, std::ratio<0>, std::ratio<1>> data_unit; ///< Represents a unit of data size - typedef base_unit, std::ratio<0>, std::ratio<-1>, std::ratio<0>, std::ratio<0>, std::ratio<0>, std::ratio<0>, std::ratio<0>, std::ratio<1>> data_transfer_rate_unit; ///< Represents a unit of data transfer rate - } - - //------------------------------ - // UNIT CLASSES - //------------------------------ - - /** @cond */ // DOXYGEN IGNORE - /** - * @brief unit type template specialization for units derived from base units. - */ - template struct unit; - template - struct unit, PiExponent, Translation> : wpi::units::detail::_unit - { - static_assert(traits::is_ratio::value, "Template parameter `Conversion` must be a `std::ratio` representing the conversion factor to `BaseUnit`."); - static_assert(traits::is_ratio::value, "Template parameter `PiExponent` must be a `std::ratio` representing the exponents of Pi the unit has."); - static_assert(traits::is_ratio::value, "Template parameter `Translation` must be a `std::ratio` representing an additive translation required by the unit conversion."); - - typedef typename wpi::units::base_unit base_unit_type; - typedef Conversion conversion_ratio; - typedef Translation translation_ratio; - typedef PiExponent pi_exponent_ratio; - }; - /** @endcond */ // END DOXYGEN IGNORE - - /** - * @brief Type representing an arbitrary unit. - * @ingroup UnitTypes - * @details `unit` types are used as tags for the `conversion` function. They are *not* containers - * (see `unit_t` for a container class). Each unit is defined by: - * - * - A `std::ratio` defining the conversion factor to the base unit type. (e.g. `std::ratio<1,12>` for inches to feet) - * - A base unit that the unit is derived from (or a unit category. Must be of type `unit` or `base_unit`) - * - An exponent representing factors of PI required by the conversion. (e.g. `std::ratio<-1>` for a radians to degrees conversion) - * - a ratio representing a datum translation required for the conversion (e.g. `std::ratio<32>` for a fahrenheit to celsius conversion) - * - * Typically, a specific unit, like `meters`, would be implemented as a type alias - * of `unit`, i.e. `using meters = unit, wpi::units::category::length_unit`, or - * `using inches = unit, feet>`. - * @tparam Conversion std::ratio representing scalar multiplication factor. - * @tparam BaseUnit Unit type which this unit is derived from. May be a `base_unit`, or another `unit`. - * @tparam PiExponent std::ratio representing the exponent of pi required by the conversion. - * @tparam Translation std::ratio representing any datum translation required by the conversion. - */ - template, class Translation = std::ratio<0>> - struct unit : wpi::units::detail::_unit - { - static_assert(traits::is_unit::value, "Template parameter `BaseUnit` must be a `unit` type."); - static_assert(traits::is_ratio::value, "Template parameter `Conversion` must be a `std::ratio` representing the conversion factor to `BaseUnit`."); - static_assert(traits::is_ratio::value, "Template parameter `PiExponent` must be a `std::ratio` representing the exponents of Pi the unit has."); - - typedef typename wpi::units::traits::unit_traits::base_unit_type base_unit_type; - typedef typename std::ratio_multiply conversion_ratio; - typedef typename std::ratio_add pi_exponent_ratio; - typedef typename std::ratio_add, typename BaseUnit::translation_ratio> translation_ratio; - }; - - //------------------------------ - // BASE UNIT MANIPULATORS - //------------------------------ - - /** @cond */ // DOXYGEN IGNORE - namespace detail - { - /** - * @brief base_unit_of trait implementation - * @details recursively seeks base_unit type that a unit is derived from. Since units can be - * derived from other units, the `base_unit_type` typedef may not represent this value. - */ - template struct base_unit_of_impl; - template - struct base_unit_of_impl> : base_unit_of_impl {}; - template - struct base_unit_of_impl> - { - typedef base_unit type; - }; - template<> - struct base_unit_of_impl - { - typedef void type; - }; - } - /** @endcond */ // END DOXYGEN IGNORE - - namespace traits - { - /** - * @brief Trait which returns the `base_unit` type that a unit is originally derived from. - * @details Since units can be derived from other `unit` types in addition to `base_unit` types, - * the `base_unit_type` typedef will not always be a `base_unit` (or unit category). - * Since compatible - */ - template - using base_unit_of = typename wpi::units::detail::base_unit_of_impl::type; - } - - /** @cond */ // DOXYGEN IGNORE - namespace detail - { - /** - * @brief implementation of base_unit_multiply - * @details 'multiples' (adds exponent ratios of) two base unit types. Base units can be found - * using `base_unit_of`. - */ - template struct base_unit_multiply_impl; - template - struct base_unit_multiply_impl, base_unit> { - using type = base_unit...>; - }; - - /** - * @brief represents type of two base units multiplied together - */ - template - using base_unit_multiply = typename base_unit_multiply_impl::type; - - /** - * @brief implementation of base_unit_divide - * @details 'dived' (subtracts exponent ratios of) two base unit types. Base units can be found - * using `base_unit_of`. - */ - template struct base_unit_divide_impl; - template - struct base_unit_divide_impl, base_unit> { - using type = base_unit...>; - }; - - /** - * @brief represents the resulting type of `base_unit` U1 divided by U2. - */ - template - using base_unit_divide = typename base_unit_divide_impl::type; - - /** - * @brief implementation of inverse_base - * @details multiplies all `base_unit` exponent ratios by -1. The resulting type represents - * the inverse base unit of the given `base_unit` type. - */ - template struct inverse_base_impl; - - template - struct inverse_base_impl> { - using type = base_unit>...>; - }; - - /** - * @brief represent the inverse type of `class U` - * @details E.g. if `U` is `length_unit`, then `inverse` will represent `length_unit^-1`. - */ - template using inverse_base = typename inverse_base_impl::type; - - /** - * @brief implementation of `squared_base` - * @details multiplies all the exponent ratios of the given class by 2. The resulting type is - * equivalent to the given type squared. - */ - template struct squared_base_impl; - template - struct squared_base_impl> { - using type = base_unit>...>; - }; - - /** - * @brief represents the type of a `base_unit` squared. - * @details E.g. `squared` will represent `length_unit^2`. - */ - template using squared_base = typename squared_base_impl::type; - - /** - * @brief implementation of `cubed_base` - * @details multiplies all the exponent ratios of the given class by 3. The resulting type is - * equivalent to the given type cubed. - */ - template struct cubed_base_impl; - template - struct cubed_base_impl> { - using type = base_unit>...>; - }; - - /** - * @brief represents the type of a `base_unit` cubed. - * @details E.g. `cubed` will represent `length_unit^3`. - */ - template using cubed_base = typename cubed_base_impl::type; - - /** - * @brief implementation of `sqrt_base` - * @details divides all the exponent ratios of the given class by 2. The resulting type is - * equivalent to the square root of the given type. - */ - template struct sqrt_base_impl; - template - struct sqrt_base_impl> { - using type = base_unit>...>; - }; - - /** - * @brief represents the square-root type of a `base_unit`. - * @details E.g. `sqrt` will represent `length_unit^(1/2)`. - */ - template using sqrt_base = typename sqrt_base_impl::type; - - /** - * @brief implementation of `cbrt_base` - * @details divides all the exponent ratios of the given class by 3. The resulting type is - * equivalent to the given type's cube-root. - */ - template struct cbrt_base_impl; - template - struct cbrt_base_impl> { - using type = base_unit>...>; - }; - - /** - * @brief represents the cube-root type of a `base_unit` . - * @details E.g. `cbrt` will represent `length_unit^(1/3)`. - */ - template using cbrt_base = typename cbrt_base_impl::type; - } - /** @endcond */ // END DOXYGEN IGNORE - - //------------------------------ - // UNIT MANIPULATORS - //------------------------------ - - /** @cond */ // DOXYGEN IGNORE - namespace detail - { - /** - * @brief implementation of `unit_multiply`. - * @details multiplies two units. The base unit becomes the base units of each with their exponents - * added together. The conversion factors of each are multiplied by each other. Pi exponent ratios - * are added, and datum translations are removed. - */ - template - struct unit_multiply_impl - { - using type = unit < std::ratio_multiply, - base_unit_multiply , traits::base_unit_of>, - std::ratio_add, - std::ratio < 0 >> ; - }; - - /** - * @brief represents the type of two units multiplied together. - * @details recalculates conversion and exponent ratios at compile-time. - */ - template - using unit_multiply = typename unit_multiply_impl::type; - - /** - * @brief implementation of `unit_divide`. - * @details divides two units. The base unit becomes the base units of each with their exponents - * subtracted from each other. The conversion factors of each are divided by each other. Pi exponent ratios - * are subtracted, and datum translations are removed. - */ - template - struct unit_divide_impl - { - using type = unit < std::ratio_divide, - base_unit_divide, traits::base_unit_of>, - std::ratio_subtract, - std::ratio < 0 >> ; - }; - - /** - * @brief represents the type of two units divided by each other. - * @details recalculates conversion and exponent ratios at compile-time. - */ - template - using unit_divide = typename unit_divide_impl::type; - - /** - * @brief implementation of `inverse` - * @details inverts a unit (equivalent to 1/unit). The `base_unit` and pi exponents are all multiplied by - * -1. The conversion ratio numerator and denominator are swapped. Datum translation - * ratios are removed. - */ - template - struct inverse_impl - { - using type = unit < std::ratio, - inverse_base::base_unit_type>>, - std::ratio_multiply::pi_exponent_ratio, std::ratio<-1>>, - std::ratio < 0 >> ; // inverses are rates or change, the translation factor goes away. - }; - } - /** @endcond */ // END DOXYGEN IGNORE - - /** - * @brief represents the inverse unit type of `class U`. - * @ingroup UnitManipulators - * @tparam U `unit` type to invert. - * @details E.g. `inverse` will represent meters^-1 (i.e. 1/meters). - */ - template using inverse = typename wpi::units::detail::inverse_impl::type; - - /** @cond */ // DOXYGEN IGNORE - namespace detail - { - /** - * @brief implementation of `squared` - * @details Squares the conversion ratio, `base_unit` exponents, pi exponents, and removes - * datum translation ratios. - */ - template - struct squared_impl - { - static_assert(traits::is_unit::value, "Template parameter `Unit` must be a `unit` type."); - using Conversion = typename Unit::conversion_ratio; - using type = unit < std::ratio_multiply, - squared_base>, - std::ratio_multiply>, - typename Unit::translation_ratio - > ; - }; - } - /** @endcond */ // END DOXYGEN IGNORE - - /** - * @brief represents the unit type of `class U` squared - * @ingroup UnitManipulators - * @tparam U `unit` type to square. - * @details E.g. `square` will represent meters^2. - */ - template - using squared = typename wpi::units::detail::squared_impl::type; - - /** @cond */ // DOXYGEN IGNORE - namespace detail - { - /** - * @brief implementation of `cubed` - * @details Cubes the conversion ratio, `base_unit` exponents, pi exponents, and removes - * datum translation ratios. - */ - template - struct cubed_impl - { - static_assert(traits::is_unit::value, "Template parameter `Unit` must be a `unit` type."); - using Conversion = typename Unit::conversion_ratio; - using type = unit < std::ratio_multiply>, - cubed_base>, - std::ratio_multiply>, - typename Unit::translation_ratio> ; - }; - } - /** @endcond */ // END DOXYGEN IGNORE - - /** - * @brief represents the type of `class U` cubed. - * @ingroup UnitManipulators - * @tparam U `unit` type to cube. - * @details E.g. `cubed` will represent meters^3. - */ - template - using cubed = typename wpi::units::detail::cubed_impl::type; - - /** @cond */ // DOXYGEN IGNORE - namespace detail - { - //---------------------------------- - // RATIO_SQRT IMPLEMENTATION - //---------------------------------- - - using Zero = std::ratio<0>; - using One = std::ratio<1>; - template using Square = std::ratio_multiply; - - // Find the largest std::integer N such that Predicate::value is true. - template