Formula Student Autonomous Systems
The code for the main driverless system
Loading...
Searching...
No Matches
utils_test.cpp
Go to the documentation of this file.
1#include "utils/utils.hpp"
2
3#include <gtest/gtest.h>
4#include <memory>
5
6#include <cmath>
7
8/* ----------------------- ODOMETRY MODEL -------------------------*/
9
15TEST(ODOMETRY_SUBSCRIBER, CONVERSION_TEST) {
16 // Straight Line
17 std::shared_ptr<common_lib::car_parameters::CarParameters> params = std::make_shared<common_lib::car_parameters::CarParameters>(0.516, 1.6, 1.2, 0.791, 4.0);
18 double rl_speed = 60;
19 double rr_speed = 60;
20 double fl_speed = 60;
21 double fr_speed = 60;
22 double steering_angle = 0;
23 std::pair<double, double> velocity_data =
24 wheels_velocities_to_cg(params, rl_speed, rr_speed, fl_speed, fr_speed, steering_angle);
25 EXPECT_NEAR(velocity_data.first, 1.6210, 0.0001);
26 EXPECT_DOUBLE_EQ(velocity_data.second, 0);
27
28 // Curving left
29 rl_speed = 60;
30 rr_speed = 60;
31 fl_speed = 60;
32 fr_speed = 60;
33 steering_angle = M_PI / 8;
34 velocity_data =
35 wheels_velocities_to_cg(params, rl_speed, rr_speed, fl_speed, fr_speed, steering_angle);
36 EXPECT_GE(velocity_data.first, 1.6210);
37 EXPECT_LE(velocity_data.first, 1.6210 * 2);
38 EXPECT_LE(velocity_data.second, M_PI);
39 EXPECT_GE(velocity_data.second, M_PI / 8);
40
41 // Curving right
42 rl_speed = 60;
43 rr_speed = 60;
44 fl_speed = 60;
45 fr_speed = 60;
46 steering_angle = -M_PI / 8;
47 velocity_data =
48 wheels_velocities_to_cg(params, rl_speed, rr_speed, fl_speed, fr_speed, steering_angle);
49 EXPECT_GE(velocity_data.first, 1.6210);
50 EXPECT_LE(velocity_data.first, 1.6210 * 2);
51 EXPECT_GE(velocity_data.second, -M_PI);
52 EXPECT_LE(velocity_data.second, -M_PI / 8);
53}
std::pair< double, double > wheels_velocities_to_cg(std::shared_ptr< common_lib::car_parameters::CarParameters > car_parameters, double rl_rpm, double fl_rpm, double rr_rpm, double fr_rpm, double steering_angle)
Calculates the translational and rotational velocities of the vehicle from wheel rotations and steeri...
Definition utils.cpp:3
TEST(ODOMETRY_SUBSCRIBER, CONVERSION_TEST)
Tests the conversion from wheel revolutions to velocities using the bycicle model.