Formula Student Autonomous Systems
The code for the main driverless system
Loading...
Searching...
No Matches
pure_pursuit.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <memory>
4#include <algorithm>
5
11#include "utils/utils.hpp"
12#include "gtest/gtest.h"
13#include "rclcpp/rclcpp.hpp"
14
27private:
28 // Low pass filter to smooth the steering command
29 std::shared_ptr<Filter> lpf_;
30
31 // Last messages received from path planning, velocity estimation and SLAM
32 std::vector<custom_interfaces::msg::PathPoint> last_path_msg_;
33 custom_interfaces::msg::Velocities last_velocity_msg_;
34 custom_interfaces::msg::Pose last_pose_msg_;
35 double absolute_velocity_ = 0.0;
36
37 // Whether the first message has been received for each type of message
41
42 // Points to be used for visualization
45
52 void publish_closest_point(std::shared_ptr<rclcpp::Node> node, std::map<std::string, std::shared_ptr<rclcpp::PublisherBase>>& publisher_map);
53
60 void publish_lookahead_point(std::shared_ptr<rclcpp::Node> node, std::map<std::string, std::shared_ptr<rclcpp::PublisherBase>>& publisher_map);
61
62public:
67 PurePursuit(const ControlParameters& params);
68
69 void path_callback(const custom_interfaces::msg::PathPointArray& msg) override;
70
71 void vehicle_state_callback(const custom_interfaces::msg::Velocities& msg) override;
72
73 void vehicle_pose_callback(const custom_interfaces::msg::Pose& msg) override;
74
75 double get_steering_command() override;
76
77 void publish_solver_data(std::shared_ptr<rclcpp::Node> node, std::map<std::string, std::shared_ptr<rclcpp::PublisherBase>>& publisher_map) override;
78
93 double dist_cg_2_rear_axis);
94
105 double calculate_alpha(common_lib::structures::Position vehicle_rear_wheel,
107 common_lib::structures::Position lookahead_point, double rear_wheel_2_c_g);
108
109 FRIEND_TEST(PurePursuitTests, Test_calculate_alpha_1);
110 FRIEND_TEST(PurePursuitTests, Test_calculate_alpha_2);
111 FRIEND_TEST(PurePursuitTests, Test_calculate_alpha_3);
112 FRIEND_TEST(PurePursuitTests, Test_calculate_alpha_4);
113 FRIEND_TEST(PurePursuitTests, Test_calculate_alpha_5);
114 FRIEND_TEST(PurePursuitTests, Test_pp_steering_control_law_1);
115};
Base (abstract) class for lateral control solvers (that calculate steering command)
Pure Pursuit class.
void publish_solver_data(std::shared_ptr< rclcpp::Node > node, std::map< std::string, std::shared_ptr< rclcpp::PublisherBase > > &publisher_map) override
Publishes solver specific data using the provided ControlNode.
bool received_first_state_
FRIEND_TEST(PurePursuitTests, Test_calculate_alpha_2)
bool received_first_path_
void path_callback(const custom_interfaces::msg::PathPointArray &msg) override
Called when a new path is sent by Path Planning.
std::shared_ptr< Filter > lpf_
std::vector< custom_interfaces::msg::PathPoint > last_path_msg_
FRIEND_TEST(PurePursuitTests, Test_pp_steering_control_law_1)
FRIEND_TEST(PurePursuitTests, Test_calculate_alpha_3)
common_lib::structures::Position lookahead_point_
void vehicle_state_callback(const custom_interfaces::msg::Velocities &msg) override
Called when the car state (currently just velocity) is updated.
custom_interfaces::msg::Velocities last_velocity_msg_
custom_interfaces::msg::Pose last_pose_msg_
FRIEND_TEST(PurePursuitTests, Test_calculate_alpha_4)
double absolute_velocity_
double get_steering_command() override
Returns the steering command calculated by the solver.
double pp_steering_control_law(common_lib::structures::Position rear_axis, common_lib::structures::Position cg, common_lib::structures::Position lookahead_point, double dist_cg_2_rear_axis)
Pure Pursuit control law.
FRIEND_TEST(PurePursuitTests, Test_calculate_alpha_5)
FRIEND_TEST(PurePursuitTests, Test_calculate_alpha_1)
void vehicle_pose_callback(const custom_interfaces::msg::Pose &msg) override
Called when the car pose is updated by SLAM.
double calculate_alpha(common_lib::structures::Position vehicle_rear_wheel, common_lib::structures::Position vehicle_cg, common_lib::structures::Position lookahead_point, double rear_wheel_2_c_g)
Calculate alpha (angle between the vehicle and lookahead point)
void publish_lookahead_point(std::shared_ptr< rclcpp::Node > node, std::map< std::string, std::shared_ptr< rclcpp::PublisherBase > > &publisher_map)
Function that publishes the lookahead point marker.
bool received_first_pose_
common_lib::structures::Position closest_point_
void publish_closest_point(std::shared_ptr< rclcpp::Node > node, std::map< std::string, std::shared_ptr< rclcpp::PublisherBase > > &publisher_map)
Function that publishes the closest point marker.