mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-04 03:11:43 +00:00
[wpiutil] Deprecate wpi::math constants in favor of wpi::numbers (#3383)
The constants were moved from std::math to std::numbers before ratification in C++20.
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
#include <cmath>
|
||||
|
||||
#include <hal/FRCUsageReporting.h>
|
||||
#include <wpi/math>
|
||||
#include <wpi/numbers>
|
||||
|
||||
using namespace frc;
|
||||
|
||||
@@ -114,5 +114,5 @@ double Joystick::GetDirectionRadians() const {
|
||||
}
|
||||
|
||||
double Joystick::GetDirectionDegrees() const {
|
||||
return (180 / wpi::math::pi) * GetDirectionRadians();
|
||||
return (180 / wpi::numbers::pi) * GetDirectionRadians();
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#include <cmath>
|
||||
|
||||
#include <hal/FRCUsageReporting.h>
|
||||
#include <wpi/math>
|
||||
#include <wpi/numbers>
|
||||
|
||||
#include "frc/SpeedController.h"
|
||||
#include "frc/smartdashboard/SendableBuilder.h"
|
||||
@@ -37,12 +37,12 @@ KilloughDrive::KilloughDrive(SpeedController& leftMotor,
|
||||
: m_leftMotor(&leftMotor),
|
||||
m_rightMotor(&rightMotor),
|
||||
m_backMotor(&backMotor) {
|
||||
m_leftVec = {std::cos(leftMotorAngle * (wpi::math::pi / 180.0)),
|
||||
std::sin(leftMotorAngle * (wpi::math::pi / 180.0))};
|
||||
m_rightVec = {std::cos(rightMotorAngle * (wpi::math::pi / 180.0)),
|
||||
std::sin(rightMotorAngle * (wpi::math::pi / 180.0))};
|
||||
m_backVec = {std::cos(backMotorAngle * (wpi::math::pi / 180.0)),
|
||||
std::sin(backMotorAngle * (wpi::math::pi / 180.0))};
|
||||
m_leftVec = {std::cos(leftMotorAngle * (wpi::numbers::pi / 180.0)),
|
||||
std::sin(leftMotorAngle * (wpi::numbers::pi / 180.0))};
|
||||
m_rightVec = {std::cos(rightMotorAngle * (wpi::numbers::pi / 180.0)),
|
||||
std::sin(rightMotorAngle * (wpi::numbers::pi / 180.0))};
|
||||
m_backVec = {std::cos(backMotorAngle * (wpi::numbers::pi / 180.0)),
|
||||
std::sin(backMotorAngle * (wpi::numbers::pi / 180.0))};
|
||||
auto& registry = SendableRegistry::GetInstance();
|
||||
registry.AddChild(this, m_leftMotor);
|
||||
registry.AddChild(this, m_rightMotor);
|
||||
@@ -81,8 +81,8 @@ void KilloughDrive::DrivePolar(double magnitude, double angle,
|
||||
reported = true;
|
||||
}
|
||||
|
||||
DriveCartesian(magnitude * std::sin(angle * (wpi::math::pi / 180.0)),
|
||||
magnitude * std::cos(angle * (wpi::math::pi / 180.0)),
|
||||
DriveCartesian(magnitude * std::sin(angle * (wpi::numbers::pi / 180.0)),
|
||||
magnitude * std::cos(angle * (wpi::numbers::pi / 180.0)),
|
||||
zRotation, 0.0);
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#include <cmath>
|
||||
|
||||
#include <hal/FRCUsageReporting.h>
|
||||
#include <wpi/math>
|
||||
#include <wpi/numbers>
|
||||
|
||||
#include "frc/SpeedController.h"
|
||||
#include "frc/drive/Vector2d.h"
|
||||
@@ -73,8 +73,8 @@ void MecanumDrive::DrivePolar(double magnitude, double angle,
|
||||
reported = true;
|
||||
}
|
||||
|
||||
DriveCartesian(magnitude * std::cos(angle * (wpi::math::pi / 180.0)),
|
||||
magnitude * std::sin(angle * (wpi::math::pi / 180.0)),
|
||||
DriveCartesian(magnitude * std::cos(angle * (wpi::numbers::pi / 180.0)),
|
||||
magnitude * std::sin(angle * (wpi::numbers::pi / 180.0)),
|
||||
zRotation, 0.0);
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
#include <cmath>
|
||||
|
||||
#include <wpi/math>
|
||||
#include <wpi/numbers>
|
||||
|
||||
using namespace frc;
|
||||
|
||||
@@ -16,8 +16,8 @@ Vector2d::Vector2d(double x, double y) {
|
||||
}
|
||||
|
||||
void Vector2d::Rotate(double angle) {
|
||||
double cosA = std::cos(angle * (wpi::math::pi / 180.0));
|
||||
double sinA = std::sin(angle * (wpi::math::pi / 180.0));
|
||||
double cosA = std::cos(angle * (wpi::numbers::pi / 180.0));
|
||||
double sinA = std::sin(angle * (wpi::numbers::pi / 180.0));
|
||||
double out[2];
|
||||
out[0] = x * cosA - y * sinA;
|
||||
out[1] = x * sinA + y * cosA;
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
#include <units/math.h>
|
||||
#include <units/time.h>
|
||||
#include <wpi/math>
|
||||
#include <wpi/numbers>
|
||||
|
||||
#include "frc/MathUtil.h"
|
||||
#include "frc/controller/HolonomicDriveController.h"
|
||||
@@ -15,7 +15,8 @@
|
||||
EXPECT_LE(units::math::abs(val1 - val2), eps)
|
||||
|
||||
static constexpr units::meter_t kTolerance{1 / 12.0};
|
||||
static constexpr units::radian_t kAngularTolerance{2.0 * wpi::math::pi / 180.0};
|
||||
static constexpr units::radian_t kAngularTolerance{2.0 * wpi::numbers::pi /
|
||||
180.0};
|
||||
|
||||
TEST(HolonomicDriveControllerTest, ReachesReference) {
|
||||
frc::HolonomicDriveController controller{
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#include <units/angle.h>
|
||||
#include <units/angular_acceleration.h>
|
||||
#include <units/angular_velocity.h>
|
||||
#include <wpi/math>
|
||||
#include <wpi/numbers>
|
||||
|
||||
#include "frc/controller/ProfiledPIDController.h"
|
||||
#include "gtest/gtest.h"
|
||||
@@ -40,8 +40,8 @@ TEST_F(ProfiledPIDInputOutputTest, ContinuousInputTest1) {
|
||||
|
||||
TEST_F(ProfiledPIDInputOutputTest, ContinuousInputTest2) {
|
||||
controller->SetP(1);
|
||||
controller->EnableContinuousInput(-units::radian_t{wpi::math::pi},
|
||||
units::radian_t{wpi::math::pi});
|
||||
controller->EnableContinuousInput(-units::radian_t{wpi::numbers::pi},
|
||||
units::radian_t{wpi::numbers::pi});
|
||||
|
||||
static constexpr units::radian_t kSetpoint{-3.4826633343199735};
|
||||
static constexpr units::radian_t kMeasurement{-3.1352207333939606};
|
||||
@@ -52,13 +52,13 @@ TEST_F(ProfiledPIDInputOutputTest, ContinuousInputTest2) {
|
||||
|
||||
// Error must be less than half the input range at all times
|
||||
EXPECT_LT(units::math::abs(controller->GetSetpoint().position - kMeasurement),
|
||||
units::radian_t{wpi::math::pi});
|
||||
units::radian_t{wpi::numbers::pi});
|
||||
}
|
||||
|
||||
TEST_F(ProfiledPIDInputOutputTest, ContinuousInputTest3) {
|
||||
controller->SetP(1);
|
||||
controller->EnableContinuousInput(-units::radian_t{wpi::math::pi},
|
||||
units::radian_t{wpi::math::pi});
|
||||
controller->EnableContinuousInput(-units::radian_t{wpi::numbers::pi},
|
||||
units::radian_t{wpi::numbers::pi});
|
||||
|
||||
static constexpr units::radian_t kSetpoint{-3.5176604690006377};
|
||||
static constexpr units::radian_t kMeasurement{3.1191729343822456};
|
||||
@@ -69,13 +69,13 @@ TEST_F(ProfiledPIDInputOutputTest, ContinuousInputTest3) {
|
||||
|
||||
// Error must be less than half the input range at all times
|
||||
EXPECT_LT(units::math::abs(controller->GetSetpoint().position - kMeasurement),
|
||||
units::radian_t{wpi::math::pi});
|
||||
units::radian_t{wpi::numbers::pi});
|
||||
}
|
||||
|
||||
TEST_F(ProfiledPIDInputOutputTest, ContinuousInputTest4) {
|
||||
controller->SetP(1);
|
||||
controller->EnableContinuousInput(0_rad,
|
||||
units::radian_t{2.0 * wpi::math::pi});
|
||||
units::radian_t{2.0 * wpi::numbers::pi});
|
||||
|
||||
static constexpr units::radian_t kSetpoint{2.78};
|
||||
static constexpr units::radian_t kMeasurement{3.12};
|
||||
@@ -86,7 +86,7 @@ TEST_F(ProfiledPIDInputOutputTest, ContinuousInputTest4) {
|
||||
|
||||
// Error must be less than half the input range at all times
|
||||
EXPECT_LT(units::math::abs(controller->GetSetpoint().position - kMeasurement),
|
||||
units::radian_t{wpi::math::pi});
|
||||
units::radian_t{wpi::numbers::pi});
|
||||
}
|
||||
|
||||
TEST_F(ProfiledPIDInputOutputTest, ProportionalGainOutputTest) {
|
||||
|
||||
@@ -13,7 +13,8 @@
|
||||
EXPECT_LE(units::math::abs(val1 - val2), eps)
|
||||
|
||||
static constexpr units::meter_t kTolerance{1 / 12.0};
|
||||
static constexpr units::radian_t kAngularTolerance{2.0 * wpi::math::pi / 180.0};
|
||||
static constexpr units::radian_t kAngularTolerance{2.0 * wpi::numbers::pi /
|
||||
180.0};
|
||||
|
||||
TEST(RamseteControllerTest, ReachesReference) {
|
||||
frc::RamseteController controller{2.0, 0.7};
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
#include <hal/HAL.h>
|
||||
#include <units/math.h>
|
||||
#include <wpi/math>
|
||||
#include <wpi/numbers>
|
||||
|
||||
#include "frc/AnalogEncoder.h"
|
||||
#include "frc/AnalogInput.h"
|
||||
@@ -22,6 +22,6 @@ TEST(AnalogEncoderSimTest, TestBasic) {
|
||||
encoderSim.SetPosition(180_deg);
|
||||
EXPECT_NEAR(encoder.Get().to<double>(), 0.5, 1E-8);
|
||||
EXPECT_NEAR(encoderSim.GetTurns().to<double>(), 0.5, 1E-8);
|
||||
EXPECT_NEAR(encoderSim.GetPosition().Radians().to<double>(), wpi::math::pi,
|
||||
EXPECT_NEAR(encoderSim.GetPosition().Radians().to<double>(), wpi::numbers::pi,
|
||||
1E-8);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// 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.
|
||||
|
||||
#include <wpi/math>
|
||||
#include <wpi/numbers>
|
||||
|
||||
#include "frc/simulation/SingleJointedArmSim.h"
|
||||
#include "gtest/gtest.h"
|
||||
@@ -18,5 +18,5 @@ TEST(SingleJointedArmTest, Disabled) {
|
||||
}
|
||||
|
||||
// The arm should swing down.
|
||||
EXPECT_NEAR(sim.GetAngle().to<double>(), -wpi::math::pi / 2, 0.01);
|
||||
EXPECT_NEAR(sim.GetAngle().to<double>(), -wpi::numbers::pi / 2, 0.01);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user