Skip to content

Commit

Permalink
Don't test constexpr on GCC 11 and below
Browse files Browse the repository at this point in the history
  • Loading branch information
calcmogul committed Jan 13, 2025
1 parent f9766cc commit 53fb1d0
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
5 changes: 5 additions & 0 deletions wpimath/src/test/native/cpp/geometry/Rotation2dTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,13 @@ TEST(Rotation2dTest, Inequality) {
}

TEST(Rotation2dTest, ToMatrix) {
#if __GNUC__ <= 11
Rotation2d before{20_deg};
Rotation2d after{before.ToMatrix()};
#else
constexpr Rotation2d before{20_deg};
constexpr Rotation2d after{before.ToMatrix()};
#endif

EXPECT_EQ(before, after);
}
Expand Down
5 changes: 5 additions & 0 deletions wpimath/src/test/native/cpp/geometry/Rotation3dTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,8 +308,13 @@ TEST(Rotation3dTest, Inequality) {
}

TEST(Rotation3dTest, ToMatrix) {
#if __GNUC__ <= 11
Rotation3d before{10_deg, 20_deg, 30_deg};
Rotation3d after{before.ToMatrix()};
#else
constexpr Rotation3d before{10_deg, 20_deg, 30_deg};
constexpr Rotation3d after{before.ToMatrix()};
#endif

EXPECT_EQ(before, after);
}
Expand Down
29 changes: 29 additions & 0 deletions wpimath/src/test/native/cpp/system/LinearSystemIDTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,13 @@
#include "units/mass.h"

TEST(LinearSystemIDTest, IdentifyDrivetrainVelocitySystem) {
#if __GNUC__ <= 11
auto model = frc::LinearSystemId::DrivetrainVelocitySystem(
frc::DCMotor::NEO(4), 70_kg, 0.05_m, 0.4_m, 6.0_kg_sq_m, 6.0);
#else
constexpr auto model = frc::LinearSystemId::DrivetrainVelocitySystem(
frc::DCMotor::NEO(4), 70_kg, 0.05_m, 0.4_m, 6.0_kg_sq_m, 6.0);
#endif

ASSERT_TRUE(model.A().isApprox(
frc::Matrixd<2, 2>{{-10.14132, 3.06598}, {3.06598, -10.14132}}, 0.001));
Expand All @@ -37,17 +42,29 @@ TEST(LinearSystemIDTest, ElevatorSystem) {
}

TEST(LinearSystemIDTest, FlywheelSystem) {
#if __GNUC__ <= 11
auto model = frc::LinearSystemId::FlywheelSystem(frc::DCMotor::NEO(2),
0.00032_kg_sq_m, 1.0);
#else
constexpr auto model = frc::LinearSystemId::FlywheelSystem(
frc::DCMotor::NEO(2), 0.00032_kg_sq_m, 1.0);
#endif

ASSERT_TRUE(model.A().isApprox(frc::Matrixd<1, 1>{-26.87032}, 0.001));
ASSERT_TRUE(model.B().isApprox(frc::Matrixd<1, 1>{1354.166667}, 0.001));
ASSERT_TRUE(model.C().isApprox(frc::Matrixd<1, 1>{1.0}, 0.001));
ASSERT_TRUE(model.D().isApprox(frc::Matrixd<1, 1>{0.0}, 0.001));
}

TEST(LinearSystemIDTest, DCMotorSystem) {
#if __GNUC__ <= 11
auto model = frc::LinearSystemId::DCMotorSystem(frc::DCMotor::NEO(2),
0.00032_kg_sq_m, 1.0);
#else
constexpr auto model = frc::LinearSystemId::DCMotorSystem(
frc::DCMotor::NEO(2), 0.00032_kg_sq_m, 1.0);
#endif

ASSERT_TRUE(
model.A().isApprox(frc::Matrixd<2, 2>{{0, 1}, {0, -26.87032}}, 0.001));
ASSERT_TRUE(model.B().isApprox(frc::Matrixd<2, 1>{0, 1354.166667}, 0.001));
Expand All @@ -61,9 +78,15 @@ TEST(LinearSystemIDTest, IdentifyPositionSystem) {
// x-dot = [0 1 | 0 -kv/ka] x = [0 | 1/ka] u
constexpr double kv = 1.0;
constexpr double ka = 0.5;

#if __GNUC__ <= 11
auto model = frc::LinearSystemId::IdentifyPositionSystem<units::meter>(
kv * 1_V / 1_mps, ka * 1_V / 1_mps_sq);
#else
constexpr auto model =
frc::LinearSystemId::IdentifyPositionSystem<units::meter>(
kv * 1_V / 1_mps, ka * 1_V / 1_mps_sq);
#endif

ASSERT_TRUE(model.A().isApprox(
frc::Matrixd<2, 2>{{0.0, 1.0}, {0.0, -kv / ka}}, 0.001));
Expand All @@ -76,9 +99,15 @@ TEST(LinearSystemIDTest, IdentifyVelocitySystem) {
// x-dot = -kv/ka * v + 1/ka \cdot V
constexpr double kv = 1.0;
constexpr double ka = 0.5;

#if __GNUC__ <= 11
auto model = frc::LinearSystemId::IdentifyVelocitySystem<units::meter>(
kv * 1_V / 1_mps, ka * 1_V / 1_mps_sq);
#else
constexpr auto model =
frc::LinearSystemId::IdentifyVelocitySystem<units::meter>(
kv * 1_V / 1_mps, ka * 1_V / 1_mps_sq);
#endif

ASSERT_TRUE(model.A().isApprox(frc::Matrixd<1, 1>{-kv / ka}, 0.001));
ASSERT_TRUE(model.B().isApprox(frc::Matrixd<1, 1>{1.0 / ka}, 0.001));
Expand Down

0 comments on commit 53fb1d0

Please sign in to comment.