Formula Student Autonomous Systems
The code for the main driverless system
Loading...
Searching...
No Matches
pacsim.cpp
Go to the documentation of this file.
2
4#include "custom_interfaces/msg/cone.hpp"
5#include "custom_interfaces/msg/cone_array.hpp"
6#include "custom_interfaces/msg/point2d.hpp"
7#include "pacsim/msg/wheels.hpp"
9
10PacsimAdapter::PacsimAdapter(std::shared_ptr<SENode> se_node) : Adapter(se_node) {
11 this->_imu_subscription_ = this->node_->create_subscription<sensor_msgs::msg::Imu>(
12 "/pacsim/imu/cog_imu", 3,
13 std::bind(&Adapter::imu_subscription_callback, this, std::placeholders::_1));
14
15 this->_pacsim_wheel_speeds_subscription_.subscribe(this->node_, "/pacsim/wheelspeeds");
16 this->_steering_angle_subscription_.subscribe(this->node_, "/pacsim/steeringFront");
17 const WheelSteerPolicy policy(1);
18 this->_sync_ = std::make_shared<message_filters::Synchronizer<WheelSteerPolicy>>(
20 this->_sync_->registerCallback(&PacsimAdapter::wheel_speeds_subscription_callback, this);
21
22 if (this->node_->_use_simulated_perception_) {
24 this->node_->create_subscription<pacsim::msg::PerceptionDetections>(
25 "/pacsim/perception/lidar/landmarks", 1,
27 std::placeholders::_1));
28 }
29
30 this->_finished_client_ =
31 this->node_->create_client<std_srvs::srv::Empty>("/pacsim/finish_signal");
32}
33
35 const pacsim::msg::Wheels& wheels_msg, const pacsim::msg::StampedScalar& steering_angle_msg) {
36 this->node_->_wheel_speeds_subscription_callback(wheels_msg.rl, wheels_msg.fl, wheels_msg.rr,
37 wheels_msg.fr, steering_angle_msg.value,
38 steering_angle_msg.stamp);
39}
40
42 this->_finished_client_->async_send_request(
43 std::make_shared<std_srvs::srv::Empty::Request>(),
44 [this](rclcpp::Client<std_srvs::srv::Empty>::SharedFuture) {
45 RCLCPP_INFO(this->node_->get_logger(), "Finished signal sent");
46 });
47}
48
50 const pacsim::msg::PerceptionDetections& msg) {
51 custom_interfaces::msg::ConeArray cone_array_msg;
52 for (const pacsim::msg::PerceptionDetection& detection : msg.detections) {
53 custom_interfaces::msg::Point2d position = custom_interfaces::msg::Point2d();
54 position.x = detection.pose.pose.position.x;
55 position.y = detection.pose.pose.position.y;
56 auto cone_message = custom_interfaces::msg::Cone();
57 cone_message.position = position;
58 cone_message.confidence = detection.detection_probability;
60 common_lib::competition_logic::Color::UNKNOWN);
61 cone_array_msg.cone_array.push_back(cone_message);
62 }
63 cone_array_msg.header.stamp = msg.header.stamp;
64 this->node_->_perception_subscription_callback(cone_array_msg);
65}
Class that handles the communication between the SpeedEstimation node and the other nodes in the syst...
Definition adapter.hpp:21
void imu_subscription_callback(const sensor_msgs::msg::Imu &msg)
Function that parses the message sent from the ros IMU topic and calls the respective node's function...
Definition adapter.cpp:8
std::shared_ptr< SENode > node_
Definition adapter.hpp:23
rclcpp::Subscription< pacsim::msg::PerceptionDetections >::SharedPtr _perception_detections_subscription_
Subscriber for simulated perception detections.
Definition pacsim.hpp:30
rclcpp::Subscription< sensor_msgs::msg::Imu >::SharedPtr _imu_subscription_
Subscriber for simulated IMU data.
Definition pacsim.hpp:24
message_filters::Subscriber< pacsim::msg::Wheels > _pacsim_wheel_speeds_subscription_
Subscriber for wheel speeds.
Definition pacsim.hpp:19
message_filters::sync_policies::ApproximateTime< pacsim::msg::Wheels, pacsim::msg::StampedScalar > WheelSteerPolicy
Policy for synchronizing wheel speeds and steering angle.
Definition pacsim.hpp:25
std::shared_ptr< message_filters::Synchronizer< WheelSteerPolicy > > _sync_
Synchronizer for wheel speeds and steering angle.
Definition pacsim.hpp:27
PacsimAdapter(std::shared_ptr< SENode > se_node)
Definition pacsim.cpp:10
void perception_detections_subscription_callback(const pacsim::msg::PerceptionDetections &msg)
Callback for simulated perception detections from pacsim.
Definition pacsim.cpp:49
void wheel_speeds_subscription_callback(const pacsim::msg::Wheels &wheels_msg, const pacsim::msg::StampedScalar &steering_angle_msg)
Wheel speed subscription callback, which receives both wheel speeds and steering angle through a sync...
Definition pacsim.cpp:34
void finish() final
Function that sends the finish signal to the respective node.
Definition pacsim.cpp:41
rclcpp::Client< std_srvs::srv::Empty >::SharedPtr _finished_client_
Client for finished signal.
Definition pacsim.hpp:33
message_filters::Subscriber< pacsim::msg::StampedScalar > _steering_angle_subscription_
Subscriber for steering angle.
Definition pacsim.hpp:21
std::string get_color_string(int color)
Definition color.cpp:16