19 #include "Eigen/Geometry" 21 #include "gtest/gtest.h" 28 constexpr
double kPoseQueueDuration = 0.5f;
29 constexpr
double kGravityTimeConstant = 0.1f;
30 constexpr
double kExtrapolateDuration = 0.1f;
31 constexpr
double kPrecision = 1e-8;
32 constexpr
double kExtrapolatePrecision = 1e-2;
34 TEST(PoseExtrapolatorDeathTest, IncompleteInitialization) {
36 kGravityTimeConstant);
38 EXPECT_DEATH(extrapolator.EstimateGravityOrientation(time),
"");
39 EXPECT_DEATH(extrapolator.ExtrapolatePose(time),
"");
40 Eigen::Vector3d acceleration(0, 0, 9);
41 Eigen::Vector3d angular_velocity(0, 0, 0);
42 extrapolator.AddImuData(
43 sensor::ImuData{
time, acceleration, angular_velocity});
44 EXPECT_DEATH(extrapolator.EstimateGravityOrientation(time),
"");
45 EXPECT_DEATH(extrapolator.ExtrapolatePose(time),
"");
48 TEST(PoseExtrapolatorDeathTest, ExtrapolateInPast) {
50 kGravityTimeConstant);
54 extrapolator.AddPose(time_present, pose);
55 extrapolator.EstimateGravityOrientation(time_present);
56 EXPECT_THAT(extrapolator.ExtrapolatePose(time_present),
57 transform::IsNearly(pose, kPrecision));
59 EXPECT_DEATH(extrapolator.EstimateGravityOrientation(time_in_past),
"");
60 EXPECT_DEATH(extrapolator.ExtrapolatePose(time_in_past),
"");
62 extrapolator.ExtrapolatePose(time_in_future);
63 EXPECT_DEATH(extrapolator.ExtrapolatePose(time_present),
"");
66 TEST(PoseExtrapolatorTest, EstimateGravityOrientationWithIMU) {
67 Eigen::Vector3d initial_gravity_acceleration(1.6, 2.0, 8.0);
68 Eigen::Vector3d angular_velocity(0, 0, 0);
70 sensor::ImuData imu_data{current_time, initial_gravity_acceleration,
74 Eigen::Quaterniond expected_orientation;
75 expected_orientation.setFromTwoVectors(initial_gravity_acceleration,
76 Eigen::Vector3d::UnitZ());
78 extrapolator->EstimateGravityOrientation(current_time)
79 .angularDistance(expected_orientation),
81 Eigen::Vector3d gravity_acceleration(1.6, 2.0, 8.0);
82 for (
int i = 0; i < 10; ++i) {
84 extrapolator->AddImuData(
85 sensor::ImuData{current_time, gravity_acceleration, angular_velocity});
87 expected_orientation.setFromTwoVectors(gravity_acceleration,
88 Eigen::Vector3d::UnitZ());
90 extrapolator->EstimateGravityOrientation(current_time)
91 .angularDistance(expected_orientation),
95 TEST(PoseExtrapolatorTest, ExtrapolateWithPoses) {
97 kGravityTimeConstant);
101 Eigen::Vector3d velocity(0, 0.1, 0);
102 Eigen::Vector3d angular_velocity(0.01, 0, 0.1);
104 velocity, Eigen::AngleAxisd(angular_velocity.norm(),
105 angular_velocity.normalized()));
106 extrapolator.AddPose(current_time, current_pose);
109 EXPECT_THAT(extrapolator.ExtrapolatePose(current_time),
110 transform::IsNearly(current_pose, kPrecision));
111 for (
int i = 0; i < 5; ++i) {
113 current_pose = current_pose * motion_per_second;
114 extrapolator.AddPose(current_time, current_pose);
115 EXPECT_THAT(extrapolator.ExtrapolatePose(current_time),
116 transform::IsNearly(current_pose, kPrecision));
120 kExtrapolateDuration * velocity,
121 Eigen::AngleAxisd(kExtrapolateDuration * angular_velocity.norm(),
122 angular_velocity.normalized()));
123 EXPECT_THAT(extrapolator.ExtrapolatePose(
125 transform::IsNearly(expected_pose, kExtrapolatePrecision));
130 Eigen::AngleAxisd gravity_axis(
131 extrapolator.EstimateGravityOrientation(current_time));
133 0.f, (gravity_axis.axis().normalized() - Eigen::Vector3d::UnitZ()).norm(),
134 kExtrapolatePrecision);
137 TEST(PoseExtrapolatorTest, ExtrapolateWithIMU) {
138 Eigen::Vector3d initial_gravity_acceleration(0, 0, 9.8);
139 Eigen::Vector3d initial_angular_velocity(0, 0, 0);
141 sensor::ImuData imu_data{current_time, initial_gravity_acceleration,
142 initial_angular_velocity};
148 for (
int i = 0; i < kPoseQueueDuration + 2; ++i) {
150 extrapolator->AddImuData(sensor::ImuData{
151 current_time, initial_gravity_acceleration, initial_angular_velocity});
152 extrapolator->AddPose(current_time, current_pose);
155 Eigen::Vector3d angular_velocity_yaw(0, 0, 0.1);
157 for (
int i = 0; i < 3; ++i) {
158 for (
int j = 0; j < 10; ++j) {
160 extrapolator->AddImuData(sensor::ImuData{
161 current_time, initial_gravity_acceleration, angular_velocity_yaw});
162 Eigen::Quaterniond expected_rotation(
163 Eigen::AngleAxisd(kGravityTimeConstant * angular_velocity_yaw.norm(),
164 angular_velocity_yaw.normalized()));
168 EXPECT_THAT(extrapolator->ExtrapolatePose(current_time),
169 transform::IsNearly(expected_pose, kExtrapolatePrecision));
170 extrapolator->AddPose(current_time, expected_pose);
172 Eigen::AngleAxisd gravity_axis(
173 extrapolator->EstimateGravityOrientation(current_time));
175 0.f, (gravity_axis.axis().normalized() - Eigen::Vector3d::UnitZ()).norm(),
UniversalTimeScaleClock::time_point Time
Time FromUniversal(const int64 ticks)
Duration FromSeconds(const double seconds)
int64 ToUniversal(const Time time)
TEST(TrajectoryConnectivityStateTest, UnknownTrajectory)