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.
|
2020-11-28 17:35:35 -05:00
|
|
|
|
2022-10-15 16:33:14 -07:00
|
|
|
#include <numbers>
|
2021-01-01 16:22:00 -08:00
|
|
|
|
2023-08-28 15:13:34 -07:00
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
|
2022-04-29 22:29:20 -07:00
|
|
|
#include "frc/EigenCore.h"
|
2020-11-28 17:35:35 -05:00
|
|
|
#include "frc/estimator/AngleStatistics.h"
|
|
|
|
|
|
2021-09-17 22:51:51 -07:00
|
|
|
TEST(AngleStatisticsTest, Mean) {
|
2022-04-29 22:29:20 -07:00
|
|
|
frc::Matrixd<3, 3> sigmas{
|
2021-08-19 00:23:48 -07:00
|
|
|
{1, 1.2, 0},
|
2022-10-15 16:33:14 -07:00
|
|
|
{359 * std::numbers::pi / 180, 3 * std::numbers::pi / 180, 0},
|
2021-08-19 00:23:48 -07:00
|
|
|
{1, 2, 0}};
|
2020-11-28 17:35:35 -05:00
|
|
|
// Weights need to produce the mean of the sigmas
|
2021-08-19 00:23:48 -07:00
|
|
|
Eigen::Vector3d weights;
|
2020-11-28 17:35:35 -05:00
|
|
|
weights.fill(1.0 / sigmas.cols());
|
|
|
|
|
|
|
|
|
|
EXPECT_TRUE(Eigen::Vector3d(0.7333333, 0.01163323, 1)
|
|
|
|
|
.isApprox(frc::AngleMean<3, 1>(sigmas, weights, 1), 1e-3));
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-17 22:51:51 -07:00
|
|
|
TEST(AngleStatisticsTest, Residual) {
|
2022-10-15 16:33:14 -07:00
|
|
|
Eigen::Vector3d a{1, 1 * std::numbers::pi / 180, 2};
|
|
|
|
|
Eigen::Vector3d b{1, 359 * std::numbers::pi / 180, 1};
|
2020-11-28 17:35:35 -05:00
|
|
|
|
|
|
|
|
EXPECT_TRUE(frc::AngleResidual<3>(a, b, 1).isApprox(
|
2022-10-15 16:33:14 -07:00
|
|
|
Eigen::Vector3d{0, 2 * std::numbers::pi / 180, 1}));
|
2020-11-28 17:35:35 -05:00
|
|
|
}
|
|
|
|
|
|
2021-09-17 22:51:51 -07:00
|
|
|
TEST(AngleStatisticsTest, Add) {
|
2022-10-15 16:33:14 -07:00
|
|
|
Eigen::Vector3d a{1, 1 * std::numbers::pi / 180, 2};
|
|
|
|
|
Eigen::Vector3d b{1, 359 * std::numbers::pi / 180, 1};
|
2020-11-28 17:35:35 -05:00
|
|
|
|
2021-08-19 00:23:48 -07:00
|
|
|
EXPECT_TRUE(frc::AngleAdd<3>(a, b, 1).isApprox(Eigen::Vector3d{2, 0, 3}));
|
2020-11-28 17:35:35 -05:00
|
|
|
}
|