Skip to content

Commit

Permalink
Fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaeyoung-Lim committed Aug 2, 2024
1 parent c69fbc1 commit 3f76c22
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/modules/mc_pos_control/PositionControl/ControlMathTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,28 +108,31 @@ TEST(ControlMathTest, ThrottleAttitudeMapping)
float yaw = 0.f;
vehicle_attitude_setpoint_s att{};
thrustToAttitude(thr, yaw, att);
EXPECT_FLOAT_EQ(att.roll_body, 0.f);
EXPECT_FLOAT_EQ(att.pitch_body, 0.f);
EXPECT_FLOAT_EQ(att.yaw_body, 0.f);
EXPECT_FLOAT_EQ(att.q_d[0], 1.0);
EXPECT_FLOAT_EQ(att.q_d[1], 0.0);
EXPECT_FLOAT_EQ(att.q_d[2], 0.0);
EXPECT_FLOAT_EQ(att.q_d[3], 0.0);
EXPECT_FLOAT_EQ(att.thrust_body[2], -1.f);

/* expected: same as before but with 90 yaw
* reason: only yaw changed */
yaw = M_PI_2_F;
thrustToAttitude(thr, yaw, att);
EXPECT_FLOAT_EQ(att.roll_body, 0.f);
EXPECT_FLOAT_EQ(att.pitch_body, 0.f);
EXPECT_FLOAT_EQ(att.yaw_body, M_PI_2_F);
EXPECT_FLOAT_EQ(att.q_d[0], std::cos(0.5 * M_PI_2_F));
EXPECT_FLOAT_EQ(att.q_d[1], 0.0);
EXPECT_FLOAT_EQ(att.q_d[2], 0.0);
EXPECT_FLOAT_EQ(att.q_d[3], std::sin(0.5 * M_PI_2_F));
EXPECT_FLOAT_EQ(att.thrust_body[2], -1.f);

/* expected: same as before but roll 180
* reason: thrust points straight down and order Euler
* order is: 1. roll, 2. pitch, 3. yaw */
thr = Vector3f(0.f, 0.f, 1.f);
thrustToAttitude(thr, yaw, att);
EXPECT_FLOAT_EQ(att.roll_body, -M_PI_F);
EXPECT_FLOAT_EQ(att.pitch_body, 0.f);
EXPECT_FLOAT_EQ(att.yaw_body, M_PI_2_F);
Quatf quat_att(att.q_d);
EXPECT_FLOAT_EQ(quat_att.phi(), -M_PI_F);
EXPECT_FLOAT_EQ(quat_att.theta(), 0.f);
EXPECT_FLOAT_EQ(quat_att.yaw(), M_PI_2_F);
EXPECT_FLOAT_EQ(att.thrust_body[2], -1.f);
}

Expand Down

0 comments on commit 3f76c22

Please sign in to comment.