Formula Student Autonomous Systems
The code for the main driverless system
Loading...
Searching...
No Matches
eufs.cpp
Go to the documentation of this file.
1#include "adapter/eufs.hpp"
2
4 : ControlNode(params),
5 control_pub_(create_publisher<ackermann_msgs::msg::AckermannDriveStamped>("/cmd", 10)) {
6 // No topic for eufs, just set the go_signal to true
7 go_signal_ = true;
8
10 RCLCPP_INFO(this->get_logger(), "Eufs using simulated State Estimation\n");
11 vehicle_pose_sub_ = this->create_subscription<eufs_msgs::msg::CarState>(
12 "/odometry_integration/car_state", 10,
13 std::bind(&EufsAdapter::vehicle_state_callback, this, std::placeholders::_1));
14 }
15
16 RCLCPP_INFO(this->get_logger(), "EUFS adapter created");
17}
18
19void EufsAdapter::vehicle_state_callback(const eufs_msgs::msg::CarState& msg) {
20 // Update the vehicle state
21 custom_interfaces::msg::Pose vehicle_state;
22 vehicle_state.x = msg.pose.pose.position.x;
23 vehicle_state.y = msg.pose.pose.position.y;
24 vehicle_state.theta = atan2(2.0f * (msg.pose.pose.orientation.w * msg.pose.pose.orientation.z +
25 msg.pose.pose.orientation.x * msg.pose.pose.orientation.y),
26 msg.pose.pose.orientation.w * msg.pose.pose.orientation.w +
27 msg.pose.pose.orientation.x * msg.pose.pose.orientation.x -
28 msg.pose.pose.orientation.y * msg.pose.pose.orientation.y -
29 msg.pose.pose.orientation.z * msg.pose.pose.orientation.z);
30
31 this->vehicle_pose_callback(vehicle_state);
32}
33
35 auto control_msg = ackermann_msgs::msg::AckermannDriveStamped();
36
37 // Maybe normalize values if needed??
38 control_msg.drive.acceleration = (cmd.throttle_rr + cmd.throttle_rl) / 2.0;
39 control_msg.drive.steering_angle = cmd.steering_angle;
40 // control_msg.drive.jerk and control_msg.drive.steering_angle_velocity
41 // should maybe be filled as well based on PID
42
43 this->control_pub_->publish(control_msg);
44}
Class responsible for the ROS2 communication of the control module.
Definition ros_node.hpp:26
bool go_signal_
Definition ros_node.hpp:28
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::Subscription< eufs_msgs::msg::CarState >::SharedPtr vehicle_pose_sub_
Definition eufs.hpp:17
void publish_command(common_lib::structures::ControlCommand cmd) override
Adapters override this function to publish control commands in their environment.
Definition eufs.cpp:34
rclcpp::Publisher< ackermann_msgs::msg::AckermannDriveStamped >::SharedPtr control_pub_
Definition eufs.hpp:16
void vehicle_state_callback(const eufs_msgs::msg::CarState &msg)
Callback function for velocities and poses, which are coupled in EUFS.
Definition eufs.cpp:19
friend class EufsAdapter
Definition planning.hpp:86