mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-21 01:01: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:
@@ -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/kinematics/ChassisSpeeds.h"
|
||||
#include "frc/kinematics/DifferentialDriveKinematics.h"
|
||||
@@ -55,22 +55,24 @@ TEST(DifferentialDriveKinematics, ForwardKinematicsForStraightLine) {
|
||||
|
||||
TEST(DifferentialDriveKinematics, InverseKinematicsForRotateInPlace) {
|
||||
const DifferentialDriveKinematics kinematics{0.381_m * 2};
|
||||
const ChassisSpeeds chassisSpeeds{0.0_mps, 0.0_mps,
|
||||
units::radians_per_second_t{wpi::math::pi}};
|
||||
const ChassisSpeeds chassisSpeeds{
|
||||
0.0_mps, 0.0_mps, units::radians_per_second_t{wpi::numbers::pi}};
|
||||
const auto wheelSpeeds = kinematics.ToWheelSpeeds(chassisSpeeds);
|
||||
|
||||
EXPECT_NEAR(wheelSpeeds.left.to<double>(), -0.381 * wpi::math::pi, kEpsilon);
|
||||
EXPECT_NEAR(wheelSpeeds.right.to<double>(), +0.381 * wpi::math::pi, kEpsilon);
|
||||
EXPECT_NEAR(wheelSpeeds.left.to<double>(), -0.381 * wpi::numbers::pi,
|
||||
kEpsilon);
|
||||
EXPECT_NEAR(wheelSpeeds.right.to<double>(), +0.381 * wpi::numbers::pi,
|
||||
kEpsilon);
|
||||
}
|
||||
|
||||
TEST(DifferentialDriveKinematics, ForwardKinematicsForRotateInPlace) {
|
||||
const DifferentialDriveKinematics kinematics{0.381_m * 2};
|
||||
const DifferentialDriveWheelSpeeds wheelSpeeds{
|
||||
units::meters_per_second_t(+0.381 * wpi::math::pi),
|
||||
units::meters_per_second_t(-0.381 * wpi::math::pi)};
|
||||
units::meters_per_second_t(+0.381 * wpi::numbers::pi),
|
||||
units::meters_per_second_t(-0.381 * wpi::numbers::pi)};
|
||||
const auto chassisSpeeds = kinematics.ToChassisSpeeds(wheelSpeeds);
|
||||
|
||||
EXPECT_NEAR(chassisSpeeds.vx.to<double>(), 0, kEpsilon);
|
||||
EXPECT_NEAR(chassisSpeeds.vy.to<double>(), 0, kEpsilon);
|
||||
EXPECT_NEAR(chassisSpeeds.omega.to<double>(), -wpi::math::pi, kEpsilon);
|
||||
EXPECT_NEAR(chassisSpeeds.omega.to<double>(), -wpi::numbers::pi, kEpsilon);
|
||||
}
|
||||
|
||||
@@ -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/kinematics/DifferentialDriveKinematics.h"
|
||||
#include "frc/kinematics/DifferentialDriveOdometry.h"
|
||||
@@ -16,7 +16,7 @@ TEST(DifferentialDriveOdometry, EncoderDistances) {
|
||||
DifferentialDriveOdometry odometry{Rotation2d(45_deg)};
|
||||
|
||||
const auto& pose = odometry.Update(Rotation2d(135_deg), 0_m,
|
||||
units::meter_t(5 * wpi::math::pi));
|
||||
units::meter_t(5 * wpi::numbers::pi));
|
||||
|
||||
EXPECT_NEAR(pose.X().to<double>(), 5.0, kEpsilon);
|
||||
EXPECT_NEAR(pose.Y().to<double>(), 5.0, kEpsilon);
|
||||
|
||||
@@ -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/geometry/Translation2d.h"
|
||||
#include "frc/kinematics/MecanumDriveKinematics.h"
|
||||
@@ -61,7 +61,7 @@ TEST_F(MecanumDriveKinematicsTest, StrafeForwardKinematics) {
|
||||
|
||||
TEST_F(MecanumDriveKinematicsTest, RotationInverseKinematics) {
|
||||
ChassisSpeeds speeds{0_mps, 0_mps,
|
||||
units::radians_per_second_t(2 * wpi::math::pi)};
|
||||
units::radians_per_second_t(2 * wpi::numbers::pi)};
|
||||
auto moduleStates = kinematics.ToWheelSpeeds(speeds);
|
||||
|
||||
EXPECT_NEAR(-150.79644737, moduleStates.frontLeft.to<double>(), 0.1);
|
||||
@@ -77,7 +77,7 @@ TEST_F(MecanumDriveKinematicsTest, RotationForwardKinematics) {
|
||||
|
||||
EXPECT_NEAR(0.0, chassisSpeeds.vx.to<double>(), 0.1);
|
||||
EXPECT_NEAR(0.0, chassisSpeeds.vy.to<double>(), 0.1);
|
||||
EXPECT_NEAR(2 * wpi::math::pi, chassisSpeeds.omega.to<double>(), 0.1);
|
||||
EXPECT_NEAR(2 * wpi::numbers::pi, chassisSpeeds.omega.to<double>(), 0.1);
|
||||
}
|
||||
|
||||
TEST_F(MecanumDriveKinematicsTest, MixedRotationTranslationInverseKinematics) {
|
||||
|
||||
@@ -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/geometry/Translation2d.h"
|
||||
#include "frc/kinematics/SwerveDriveKinematics.h"
|
||||
@@ -75,7 +75,7 @@ TEST_F(SwerveDriveKinematicsTest, StraightStrafeForwardKinematics) {
|
||||
|
||||
TEST_F(SwerveDriveKinematicsTest, TurnInPlaceInverseKinematics) {
|
||||
ChassisSpeeds speeds{0_mps, 0_mps,
|
||||
units::radians_per_second_t(2 * wpi::math::pi)};
|
||||
units::radians_per_second_t(2 * wpi::numbers::pi)};
|
||||
auto [fl, fr, bl, br] = m_kinematics.ToSwerveModuleStates(speeds);
|
||||
|
||||
EXPECT_NEAR(fl.speed.to<double>(), 106.63, kEpsilon);
|
||||
@@ -99,12 +99,12 @@ TEST_F(SwerveDriveKinematicsTest, TurnInPlaceForwardKinematics) {
|
||||
|
||||
EXPECT_NEAR(chassisSpeeds.vx.to<double>(), 0.0, kEpsilon);
|
||||
EXPECT_NEAR(chassisSpeeds.vy.to<double>(), 0.0, kEpsilon);
|
||||
EXPECT_NEAR(chassisSpeeds.omega.to<double>(), 2 * wpi::math::pi, kEpsilon);
|
||||
EXPECT_NEAR(chassisSpeeds.omega.to<double>(), 2 * wpi::numbers::pi, kEpsilon);
|
||||
}
|
||||
|
||||
TEST_F(SwerveDriveKinematicsTest, OffCenterCORRotationInverseKinematics) {
|
||||
ChassisSpeeds speeds{0_mps, 0_mps,
|
||||
units::radians_per_second_t(2 * wpi::math::pi)};
|
||||
units::radians_per_second_t(2 * wpi::numbers::pi)};
|
||||
auto [fl, fr, bl, br] = m_kinematics.ToSwerveModuleStates(speeds, m_fl);
|
||||
|
||||
EXPECT_NEAR(fl.speed.to<double>(), 0.0, kEpsilon);
|
||||
@@ -128,7 +128,7 @@ TEST_F(SwerveDriveKinematicsTest, OffCenterCORRotationForwardKinematics) {
|
||||
|
||||
EXPECT_NEAR(chassisSpeeds.vx.to<double>(), 75.398, kEpsilon);
|
||||
EXPECT_NEAR(chassisSpeeds.vy.to<double>(), -75.398, kEpsilon);
|
||||
EXPECT_NEAR(chassisSpeeds.omega.to<double>(), 2 * wpi::math::pi, kEpsilon);
|
||||
EXPECT_NEAR(chassisSpeeds.omega.to<double>(), 2 * wpi::numbers::pi, kEpsilon);
|
||||
}
|
||||
|
||||
TEST_F(SwerveDriveKinematicsTest,
|
||||
|
||||
Reference in New Issue
Block a user