Merge branch 'main' into 2027

This commit is contained in:
Peter Johnson
2025-01-16 23:17:59 -08:00
92 changed files with 2748 additions and 534 deletions

View File

@@ -51,6 +51,17 @@ TEST(Pose2dTest, RelativeTo) {
EXPECT_NEAR(0.0, finalRelativeToInitial.Rotation().Degrees().value(), 1e-9);
}
TEST(Pose2dTest, RotateAround) {
const Pose2d initial{5_m, 0_m, 0_deg};
const Translation2d point{0_m, 0_m};
const auto rotated = initial.RotateAround(point, Rotation2d{180_deg});
EXPECT_NEAR(-5.0, rotated.X().value(), 1e-9);
EXPECT_NEAR(0.0, rotated.Y().value(), 1e-9);
EXPECT_NEAR(180.0, rotated.Rotation().Degrees().value(), 1e-9);
}
TEST(Pose2dTest, Equality) {
const Pose2d a{0_m, 5_m, 43_deg};
const Pose2d b{0_m, 5_m, 43_deg};

View File

@@ -83,6 +83,19 @@ TEST(Pose3dTest, RelativeTo) {
EXPECT_NEAR(0.0, finalRelativeToInitial.Rotation().Z().value(), 1e-9);
}
TEST(Pose3dTest, RotateAround) {
const Pose3d initial{5_m, 0_m, 0_m, Rotation3d{}};
const Translation3d point{0_m, 0_m, 0_m};
const auto rotated =
initial.RotateAround(point, Rotation3d{0_deg, 0_deg, 180_deg});
EXPECT_NEAR(-5.0, rotated.X().value(), 1e-9);
EXPECT_NEAR(0.0, rotated.Y().value(), 1e-9);
EXPECT_NEAR(units::radian_t{180_deg}.value(), rotated.Rotation().Z().value(),
1e-9);
}
TEST(Pose3dTest, Equality) {
Eigen::Vector3d zAxis{0.0, 0.0, 1.0};

View File

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

View File

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

View File

@@ -35,7 +35,16 @@ TEST(Translation2dTest, RotateBy) {
const auto rotated = another.RotateBy(90_deg);
EXPECT_NEAR(0.0, rotated.X().value(), 1e-9);
EXPECT_DOUBLE_EQ(3.0, rotated.Y().value());
EXPECT_NEAR(3.0, rotated.Y().value(), 1e-9);
}
TEST(Translation2dTest, RotateAround) {
const Translation2d translation{2_m, 1_m};
const Translation2d other{3_m, 2_m};
const auto rotated = translation.RotateAround(other, 180_deg);
EXPECT_NEAR(4.0, rotated.X().value(), 1e-9);
EXPECT_NEAR(3.0, rotated.Y().value(), 1e-9);
}
TEST(Translation2dTest, Multiplication) {

View File

@@ -57,6 +57,33 @@ TEST(Translation3dTest, RotateBy) {
EXPECT_NEAR(rotated3.Z().value(), 3.0, kEpsilon);
}
TEST(Translation3dTest, RotateAround) {
Eigen::Vector3d xAxis{1.0, 0.0, 0.0};
Eigen::Vector3d yAxis{0.0, 1.0, 0.0};
Eigen::Vector3d zAxis{0.0, 0.0, 1.0};
const Translation3d translation{1_m, 2_m, 3_m};
const Translation3d around{3_m, 2_m, 1_m};
const auto rotated1 =
translation.RotateAround(around, Rotation3d{xAxis, 90_deg});
EXPECT_NEAR(rotated1.X().value(), 1.0, kEpsilon);
EXPECT_NEAR(rotated1.Y().value(), 0.0, kEpsilon);
EXPECT_NEAR(rotated1.Z().value(), 1.0, kEpsilon);
const auto rotated2 =
translation.RotateAround(around, Rotation3d{yAxis, 90_deg});
EXPECT_NEAR(rotated2.X().value(), 5.0, kEpsilon);
EXPECT_NEAR(rotated2.Y().value(), 2.0, kEpsilon);
EXPECT_NEAR(rotated2.Z().value(), 3.0, kEpsilon);
const auto rotated3 =
translation.RotateAround(around, Rotation3d{zAxis, 90_deg});
EXPECT_NEAR(rotated3.X().value(), 3.0, kEpsilon);
EXPECT_NEAR(rotated3.Y().value(), 0.0, kEpsilon);
EXPECT_NEAR(rotated3.Z().value(), 3.0, kEpsilon);
}
TEST(Translation3dTest, ToTranslation2d) {
Translation3d translation{1_m, 2_m, 3_m};
Translation2d expected{1_m, 2_m};

View File

@@ -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));
@@ -37,8 +42,14 @@ 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));
@@ -46,8 +57,14 @@ TEST(LinearSystemIDTest, FlywheelSystem) {
}
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));
@@ -59,10 +76,17 @@ TEST(LinearSystemIDTest, DCMotorSystem) {
TEST(LinearSystemIDTest, IdentifyPositionSystem) {
// By controls engineering in frc,
// x-dot = [0 1 | 0 -kv/ka] x = [0 | 1/ka] u
double kv = 1.0;
double ka = 0.5;
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));
@@ -73,10 +97,17 @@ TEST(LinearSystemIDTest, IdentifyVelocitySystem) {
// By controls engineering in frc,
// V = kv * velocity + ka * acceleration
// x-dot = -kv/ka * v + 1/ka \cdot V
double kv = 1.0;
double ka = 0.5;
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));