Formula Student Autonomous Systems
The code for the main driverless system
Loading...
Searching...
No Matches
ros_node.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <chrono>
4#include <functional>
5#include <memory>
6#include <string>
7
8#include "config/parameters.hpp"
9#include "custom_interfaces/msg/operational_status.hpp"
10#include "custom_interfaces/msg/path_point_array.hpp"
11#include "custom_interfaces/msg/pose.hpp"
12#include "custom_interfaces/msg/velocities.hpp"
13#include "utils/utils.hpp"
14#include "rclcpp/rclcpp.hpp"
16#include "std_msgs/msg/float64_multi_array.hpp"
17
18
26class ControlNode : public rclcpp::Node {
27protected:
28 bool go_signal_{false};
30
35 void vehicle_pose_callback(const custom_interfaces::msg::Pose &msg);
36
41 void path_callback(const custom_interfaces::msg::PathPointArray &msg);
42
47 void vehicle_state_callback(const custom_interfaces::msg::Velocities &msg);
48private:
49 // Vector of execution times for different parts of the control loop
50 // Currently just the first element is used, which is the total execution time
51 std::shared_ptr<std::vector<double>> _execution_times_;
52
53 // Map of topic to publisher pointers
54 std::map<std::string, std::shared_ptr<rclcpp::PublisherBase>> publisher_map_;
55
56 // Control solver (lateral + longitudinal)
57 std::shared_ptr<ControlSolver> control_solver_;
58
59 // Publishers
60 rclcpp::Publisher<std_msgs::msg::Float64MultiArray>::SharedPtr execution_time_pub_;
61
62 // Timers
63 rclcpp::TimerBase::SharedPtr control_timer_;
64
65 // Subscriptions
66 rclcpp::Subscription<custom_interfaces::msg::PathPointArray>::SharedPtr path_point_array_sub_;
67 rclcpp::Subscription<custom_interfaces::msg::Pose>::SharedPtr vehicle_pose_sub_;
68 rclcpp::Subscription<custom_interfaces::msg::Velocities>::SharedPtr velocity_sub_;
69
74
81
82public:
83 explicit ControlNode(const ControlParameters &params);
84};
Class responsible for the ROS2 communication of the control module.
Definition ros_node.hpp:26
std::shared_ptr< std::vector< double > > _execution_times_
Definition ros_node.hpp:51
std::shared_ptr< ControlSolver > control_solver_
Definition ros_node.hpp:57
bool go_signal_
Definition ros_node.hpp:28
void vehicle_state_callback(const custom_interfaces::msg::Velocities &msg)
Called when a new velocity is received.
Definition ros_node.cpp:55
rclcpp::Subscription< custom_interfaces::msg::PathPointArray >::SharedPtr path_point_array_sub_
Definition ros_node.hpp:66
virtual void publish_command(common_lib::structures::ControlCommand cmd)=0
Adapters override this function to publish control commands in their environment.
std::map< std::string, std::shared_ptr< rclcpp::PublisherBase > > publisher_map_
Definition ros_node.hpp:54
ControlParameters params_
Definition ros_node.hpp:29
void vehicle_pose_callback(const custom_interfaces::msg::Pose &msg)
Called when a new vehicle pose is received.
Definition ros_node.cpp:47
rclcpp::Publisher< std_msgs::msg::Float64MultiArray >::SharedPtr execution_time_pub_
Definition ros_node.hpp:60
void path_callback(const custom_interfaces::msg::PathPointArray &msg)
Called when a new path is received.
Definition ros_node.cpp:51
rclcpp::TimerBase::SharedPtr control_timer_
Definition ros_node.hpp:63
rclcpp::Subscription< custom_interfaces::msg::Pose >::SharedPtr vehicle_pose_sub_
Definition ros_node.hpp:67
rclcpp::Subscription< custom_interfaces::msg::Velocities >::SharedPtr velocity_sub_
Definition ros_node.hpp:68
void control_timer_callback()
Function that publishes control commands on timer ticks.
Definition ros_node.cpp:30