2020-12-26 14:12:05 -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.
|
2019-09-08 00:11:49 -04:00
|
|
|
|
|
|
|
|
#include "frc/kinematics/MecanumDriveOdometry.h"
|
|
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
|
|
|
|
|
using namespace frc;
|
|
|
|
|
|
|
|
|
|
class MecanumDriveOdometryTest : public ::testing::Test {
|
|
|
|
|
protected:
|
|
|
|
|
Translation2d m_fl{12_m, 12_m};
|
|
|
|
|
Translation2d m_fr{12_m, -12_m};
|
|
|
|
|
Translation2d m_bl{-12_m, 12_m};
|
|
|
|
|
Translation2d m_br{-12_m, -12_m};
|
|
|
|
|
|
|
|
|
|
MecanumDriveKinematics kinematics{m_fl, m_fr, m_bl, m_br};
|
2019-11-15 20:34:10 -05:00
|
|
|
MecanumDriveOdometry odometry{kinematics, 0_rad};
|
2019-09-08 00:11:49 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
TEST_F(MecanumDriveOdometryTest, MultipleConsecutiveUpdates) {
|
2022-08-17 13:42:36 -07:00
|
|
|
odometry.ResetPosition(Pose2d{}, 0_rad);
|
2019-09-08 00:11:49 -04:00
|
|
|
MecanumDriveWheelSpeeds wheelSpeeds{3.536_mps, 3.536_mps, 3.536_mps,
|
|
|
|
|
3.536_mps};
|
|
|
|
|
|
2022-08-17 13:42:36 -07:00
|
|
|
odometry.UpdateWithTime(0_s, 0_deg, wheelSpeeds);
|
|
|
|
|
auto secondPose = odometry.UpdateWithTime(0.0_s, 0_deg, wheelSpeeds);
|
2019-09-08 00:11:49 -04:00
|
|
|
|
2021-10-25 08:58:12 -07:00
|
|
|
EXPECT_NEAR(secondPose.X().value(), 0.0, 0.01);
|
|
|
|
|
EXPECT_NEAR(secondPose.Y().value(), 0.0, 0.01);
|
|
|
|
|
EXPECT_NEAR(secondPose.Rotation().Radians().value(), 0.0, 0.01);
|
2019-09-08 00:11:49 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(MecanumDriveOdometryTest, TwoIterations) {
|
2022-08-17 13:42:36 -07:00
|
|
|
odometry.ResetPosition(Pose2d{}, 0_rad);
|
2019-09-08 00:11:49 -04:00
|
|
|
MecanumDriveWheelSpeeds speeds{3.536_mps, 3.536_mps, 3.536_mps, 3.536_mps};
|
|
|
|
|
|
2022-08-17 13:42:36 -07:00
|
|
|
odometry.UpdateWithTime(0_s, 0_deg, MecanumDriveWheelSpeeds{});
|
|
|
|
|
auto pose = odometry.UpdateWithTime(0.10_s, 0_deg, speeds);
|
2019-09-08 00:11:49 -04:00
|
|
|
|
2021-10-25 08:58:12 -07:00
|
|
|
EXPECT_NEAR(pose.X().value(), 0.3536, 0.01);
|
|
|
|
|
EXPECT_NEAR(pose.Y().value(), 0.0, 0.01);
|
|
|
|
|
EXPECT_NEAR(pose.Rotation().Radians().value(), 0.0, 0.01);
|
2019-09-08 00:11:49 -04:00
|
|
|
}
|
|
|
|
|
|
2021-09-17 22:51:51 -07:00
|
|
|
TEST_F(MecanumDriveOdometryTest, 90DegreeTurn) {
|
2022-08-17 13:42:36 -07:00
|
|
|
odometry.ResetPosition(Pose2d{}, 0_rad);
|
2019-09-08 00:11:49 -04:00
|
|
|
MecanumDriveWheelSpeeds speeds{-13.328_mps, 39.986_mps, -13.329_mps,
|
|
|
|
|
39.986_mps};
|
2022-08-17 13:42:36 -07:00
|
|
|
odometry.UpdateWithTime(0_s, 0_deg, MecanumDriveWheelSpeeds{});
|
|
|
|
|
auto pose = odometry.UpdateWithTime(1_s, 90_deg, speeds);
|
2019-09-08 00:11:49 -04:00
|
|
|
|
2021-10-25 08:58:12 -07:00
|
|
|
EXPECT_NEAR(pose.X().value(), 8.4855, 0.01);
|
|
|
|
|
EXPECT_NEAR(pose.Y().value(), 8.4855, 0.01);
|
|
|
|
|
EXPECT_NEAR(pose.Rotation().Degrees().value(), 90.0, 0.01);
|
2019-09-08 00:11:49 -04:00
|
|
|
}
|
2019-11-15 20:34:10 -05:00
|
|
|
|
|
|
|
|
TEST_F(MecanumDriveOdometryTest, GyroAngleReset) {
|
2022-08-17 13:42:36 -07:00
|
|
|
odometry.ResetPosition(Pose2d{}, 90_deg);
|
2019-11-15 20:34:10 -05:00
|
|
|
|
|
|
|
|
MecanumDriveWheelSpeeds speeds{3.536_mps, 3.536_mps, 3.536_mps, 3.536_mps};
|
|
|
|
|
|
2022-08-17 13:42:36 -07:00
|
|
|
odometry.UpdateWithTime(0_s, 90_deg, MecanumDriveWheelSpeeds{});
|
|
|
|
|
auto pose = odometry.UpdateWithTime(0.10_s, 90_deg, speeds);
|
2019-11-15 20:34:10 -05:00
|
|
|
|
2021-10-25 08:58:12 -07:00
|
|
|
EXPECT_NEAR(pose.X().value(), 0.3536, 0.01);
|
|
|
|
|
EXPECT_NEAR(pose.Y().value(), 0.0, 0.01);
|
|
|
|
|
EXPECT_NEAR(pose.Rotation().Radians().value(), 0.0, 0.01);
|
2019-11-15 20:34:10 -05:00
|
|
|
}
|