Formula Student Autonomous Systems
The code for the main driverless system
Loading...
Searching...
No Matches
pacsim.cpp
Go to the documentation of this file.
1#include "adapter/pacsim.hpp"
2
4 : ControlNode(params),
5 steering_pub_(create_publisher<pacsim::msg::StampedScalar>("/pacsim/steering_setpoint", 10)),
6 throttle_pub_(create_publisher<pacsim::msg::Wheels>("/pacsim/throttle_setpoint", 10)) {
7 // No topic for pacsim, just set the go_signal to true
8 go_signal_ = true;
9
11 car_pose_sub_ = this->create_subscription<geometry_msgs::msg::TwistWithCovarianceStamped>(
12 "/pacsim/pose", 1,
13 std::bind(&PacSimAdapter::_pacsim_gt_pose_callback, this, std::placeholders::_1));
14 }
15
17 car_velocity_sub_ = this->create_subscription<geometry_msgs::msg::TwistWithCovarianceStamped>(
18 "/pacsim/velocity", 1,
19 std::bind(&PacSimAdapter::_pacsim_gt_velocities_callback, this, std::placeholders::_1));
20 car_state_vector_sub_ = this->create_subscription<custom_interfaces::msg::VehicleStateVector>(
21 "/pacsim/state_vector", 1,
22 std::bind(&PacSimAdapter::_pacsim_gt_state_vector_callback, this, std::placeholders::_1));
23 }
24
25 RCLCPP_INFO(this->get_logger(), "Pacsim adapter created");
26}
27
29 const geometry_msgs::msg::TwistWithCovarianceStamped& msg) {
30 custom_interfaces::msg::Pose pose;
31 pose.header.stamp = msg.header.stamp;
32 pose.theta = msg.twist.twist.angular.z;
33 pose.x = msg.twist.twist.linear.x;
34 pose.y = msg.twist.twist.linear.y;
35
36 this->vehicle_pose_callback(pose);
37}
38
40 const geometry_msgs::msg::TwistWithCovarianceStamped& msg) {
41 custom_interfaces::msg::Velocities vel_msg;
42 vel_msg.header.stamp = msg.header.stamp;
43 vel_msg.velocity_x = msg.twist.twist.linear.x;
44 vel_msg.velocity_y = msg.twist.twist.linear.y;
45 vel_msg.angular_velocity = msg.twist.twist.angular.z;
46 this->vehicle_state_callback(vel_msg);
47}
48
50 const custom_interfaces::msg::VehicleStateVector& msg) {
51 // Currently Velocities is used, not VehicleStateVector, but this is here for future use
52}
53
55 auto steering_msg = pacsim::msg::StampedScalar();
56 auto throttle_msg = pacsim::msg::Wheels();
57
58 throttle_msg.fl = cmd.throttle_fl;
59 throttle_msg.fr = cmd.throttle_fr;
60 throttle_msg.rl = cmd.throttle_rl;
61 throttle_msg.rr = cmd.throttle_rr;
62 steering_msg.value = cmd.steering_angle;
63
64 this->steering_pub_->publish(steering_msg);
65 this->throttle_pub_->publish(throttle_msg);
66}
Class responsible for the ROS2 communication of the control module.
Definition ros_node.hpp:26
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
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
void publish_command(common_lib::structures::ControlCommand cmd) override
Adapters override this function to publish control commands in their environment.
Definition pacsim.cpp:54
rclcpp::Subscription< custom_interfaces::msg::VehicleStateVector >::SharedPtr car_state_vector_sub_
Definition pacsim.hpp:25
rclcpp::Publisher< pacsim::msg::Wheels >::SharedPtr throttle_pub_
Definition pacsim.hpp:20
rclcpp::Subscription< geometry_msgs::msg::TwistWithCovarianceStamped >::SharedPtr car_pose_sub_
Definition pacsim.hpp:24
rclcpp::Subscription< geometry_msgs::msg::TwistWithCovarianceStamped >::SharedPtr car_velocity_sub_
Definition pacsim.hpp:23
rclcpp::Publisher< pacsim::msg::StampedScalar >::SharedPtr steering_pub_
Definition pacsim.hpp:19
void _pacsim_gt_velocities_callback(const geometry_msgs::msg::TwistWithCovarianceStamped &msg)
Callback for the pacsim ground truth velocity topic, used when using simulated velocity estimation.
Definition pacsim.cpp:39
void _pacsim_gt_pose_callback(const geometry_msgs::msg::TwistWithCovarianceStamped &msg)
Callback for the pacsim ground truth pose topic, used when using simulated SLAM.
Definition pacsim.cpp:28
void _pacsim_gt_state_vector_callback(const custom_interfaces::msg::VehicleStateVector &msg)
Callback for the pacsim ground truth state vector topic, used when using simulated full state estimat...
Definition pacsim.cpp:49
friend class PacSimAdapter
Definition planning.hpp:85
bool using_simulated_velocities_