2024-11-16 07:56:14 -08:00
|
|
|
// 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.
|
|
|
|
|
|
|
|
|
|
#include <numbers>
|
|
|
|
|
|
|
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
|
2025-11-07 19:56:21 -05:00
|
|
|
#include "wpi/math/kinematics/DifferentialDriveKinematics.hpp"
|
|
|
|
|
#include "wpi/math/kinematics/DifferentialDriveOdometry3d.hpp"
|
2024-11-16 07:56:14 -08:00
|
|
|
|
|
|
|
|
static constexpr double kEpsilon = 1E-9;
|
|
|
|
|
|
2025-11-07 20:00:05 -05:00
|
|
|
using namespace wpi::math;
|
2024-11-16 07:56:14 -08:00
|
|
|
|
|
|
|
|
TEST(DifferentialDriveOdometry3dTest, Initialize) {
|
|
|
|
|
DifferentialDriveOdometry3d odometry{
|
2025-11-07 20:00:05 -05:00
|
|
|
wpi::math::Rotation3d{0_deg, 0_deg, 90_deg}, 0_m, 0_m,
|
|
|
|
|
wpi::math::Pose3d{1_m, 2_m, 0_m, wpi::math::Rotation3d{0_deg, 0_deg, 45_deg}}};
|
2024-11-16 07:56:14 -08:00
|
|
|
|
2025-11-07 20:00:05 -05:00
|
|
|
const wpi::math::Pose3d& pose = odometry.GetPose();
|
2024-11-16 07:56:14 -08:00
|
|
|
|
|
|
|
|
EXPECT_NEAR(pose.X().value(), 1, kEpsilon);
|
|
|
|
|
EXPECT_NEAR(pose.Y().value(), 2, kEpsilon);
|
|
|
|
|
EXPECT_NEAR(pose.Z().value(), 0, kEpsilon);
|
|
|
|
|
EXPECT_NEAR(pose.Rotation().ToRotation2d().Degrees().value(), 45, kEpsilon);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(DifferentialDriveOdometry3dTest, EncoderDistances) {
|
2025-11-07 20:00:05 -05:00
|
|
|
DifferentialDriveOdometry3d odometry{wpi::math::Rotation3d{0_deg, 0_deg, 45_deg},
|
2024-11-16 07:56:14 -08:00
|
|
|
0_m, 0_m};
|
|
|
|
|
|
2025-11-07 20:00:05 -05:00
|
|
|
const auto& pose = odometry.Update(wpi::math::Rotation3d{0_deg, 0_deg, 135_deg},
|
|
|
|
|
0_m, wpi::units::meter_t{5 * std::numbers::pi});
|
2024-11-16 07:56:14 -08:00
|
|
|
|
|
|
|
|
EXPECT_NEAR(pose.X().value(), 5.0, kEpsilon);
|
|
|
|
|
EXPECT_NEAR(pose.Y().value(), 5.0, kEpsilon);
|
|
|
|
|
EXPECT_NEAR(pose.Z().value(), 0.0, kEpsilon);
|
|
|
|
|
EXPECT_NEAR(pose.Rotation().ToRotation2d().Degrees().value(), 90.0, kEpsilon);
|
|
|
|
|
}
|