Formula Student Autonomous Systems
The code for the main driverless system
Loading...
Searching...
No Matches
eufs.cpp
Go to the documentation of this file.
2
3#include <algorithm>
4
7
8EufsAdapter::EufsAdapter(std::shared_ptr<SENode> se_node) : Adapter(se_node) {
9 this->eufs_state_subscription_ = this->node_->create_subscription<eufs_msgs::msg::CanState>(
10 "/ros_can/state", 10,
11 std::bind(&EufsAdapter::mission_state_callback, this, std::placeholders::_1));
12
14 this->node_->create_client<eufs_msgs::srv::SetCanState>("/ros_can/set_mission");
15
16 this->eufs_ebs_client_ = this->node_->create_client<eufs_msgs::srv::SetCanState>("/ros_can/ebs");
17
19 this->node_->create_subscription<eufs_msgs::msg::WheelSpeedsStamped>(
20 "/ros_can/wheel_speeds",
21 rclcpp::QoS(1).reliability(RMW_QOS_POLICY_RELIABILITY_BEST_EFFORT),
22 std::bind(&EufsAdapter::wheel_speeds_subscription_callback, this, std::placeholders::_1));
23
24 this->_imu_subscription_ = this->node_->create_subscription<sensor_msgs::msg::Imu>(
25 "/imu/data", rclcpp::QoS(1).reliability(RMW_QOS_POLICY_RELIABILITY_BEST_EFFORT),
26 std::bind(&Adapter::imu_subscription_callback, this, std::placeholders::_1));
27
28 if (this->node_->_use_simulated_perception_) { // TODO: make this topic a editable parameter
30 this->node_->create_subscription<eufs_msgs::msg::ConeArrayWithCovariance>(
31 "/cones", 1,
33 std::placeholders::_1));
34 }
35}
36
37void EufsAdapter::mission_state_callback(const eufs_msgs::msg::CanState& msg) const {
38 RCLCPP_DEBUG(this->node_->get_logger(), "Mission state received: %d", msg.ami_state);
39 this->node_->_mission_ = common_lib::competition_logic::get_mission_from_eufs(msg.ami_state);
40 if (msg.as_state == 2) {
41 this->node_->_go_ = true;
42 } else {
43 this->node_->_go_ = false;
44 }
45}
46
48 RCLCPP_WARN(this->node_->get_logger(), "TODO: implement mission finished in SE\n");
49}
50
52 const eufs_msgs::msg::ConeArrayWithCovariance& msg) const {
53 custom_interfaces::msg::ConeArray cone_array_msg;
54 unsigned int largest_size = static_cast<unsigned int>(
55 std::max({msg.big_orange_cones.size(), msg.blue_cones.size(), msg.yellow_cones.size(),
56 msg.orange_cones.size(), msg.unknown_color_cones.size()}));
57 for (unsigned int i = 0; i < largest_size; i++) {
58 if (i < msg.big_orange_cones.size()) {
59 auto cone_message = custom_interfaces::msg::Cone();
60 cone_message.position.x = msg.big_orange_cones[i].point.x;
61 cone_message.position.y = msg.big_orange_cones[i].point.y;
62 cone_message.confidence =
63 1.0; // TODO: add confidence to cone message according to covariance
65 common_lib::competition_logic::Color::ORANGE);
66 cone_array_msg.cone_array.push_back(cone_message);
67 }
68 if (i < msg.blue_cones.size()) {
69 auto cone_message = custom_interfaces::msg::Cone();
70 cone_message.position.x = msg.blue_cones[i].point.x;
71 cone_message.position.y = msg.blue_cones[i].point.y;
72 cone_message.confidence = 1.0;
74 common_lib::competition_logic::Color::BLUE);
75 cone_array_msg.cone_array.push_back(cone_message);
76 }
77 if (i < msg.yellow_cones.size()) {
78 auto cone_message = custom_interfaces::msg::Cone();
79 cone_message.position.x = msg.yellow_cones[i].point.x;
80 cone_message.position.y = msg.yellow_cones[i].point.y;
81 cone_message.confidence = 1.0;
83 common_lib::competition_logic::Color::YELLOW);
84 cone_array_msg.cone_array.push_back(cone_message);
85 }
86 if (i < msg.orange_cones.size()) {
87 auto cone_message = custom_interfaces::msg::Cone();
88 cone_message.position.x = msg.orange_cones[i].point.x;
89 cone_message.position.y = msg.orange_cones[i].point.y;
90 cone_message.confidence = 1.0;
92 common_lib::competition_logic::Color::ORANGE);
93 cone_array_msg.cone_array.push_back(cone_message);
94 }
95 if (i < msg.unknown_color_cones.size()) {
96 auto cone_message = custom_interfaces::msg::Cone();
97 cone_message.position.x = msg.unknown_color_cones[i].point.x;
98 cone_message.position.y = msg.unknown_color_cones[i].point.y;
99 cone_message.confidence = 1.0;
101 common_lib::competition_logic::Color::UNKNOWN);
102 cone_array_msg.cone_array.push_back(cone_message);
103 }
104 }
105 cone_array_msg.header.stamp = msg.header.stamp;
106 this->node_->_perception_subscription_callback(cone_array_msg);
107}
108
110 const eufs_msgs::msg::WheelSpeedsStamped& msg) const {
111 this->node_->_wheel_speeds_subscription_callback(msg.speeds.lb_speed, msg.speeds.lf_speed,
112 msg.speeds.rb_speed, msg.speeds.rf_speed,
113 msg.speeds.steering, msg.header.stamp);
114}
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
rclcpp::Subscription< sensor_msgs::msg::Imu >::SharedPtr _imu_subscription_
Definition adapter.hpp:25
std::shared_ptr< SENode > node_
Definition adapter.hpp:23
void wheel_speeds_subscription_callback(const eufs_msgs::msg::WheelSpeedsStamped &msg) const
Definition eufs.cpp:109
rclcpp::Client< eufs_msgs::srv::SetCanState >::SharedPtr eufs_ebs_client_
Definition eufs.hpp:15
rclcpp::Client< eufs_msgs::srv::SetCanState >::SharedPtr eufs_mission_state_client_
Definition eufs.hpp:14
void finish() final
Function that sends the finish signal to the respective node.
Definition eufs.cpp:47
void mission_state_callback(const eufs_msgs::msg::CanState &msg) const
Definition eufs.cpp:37
rclcpp::Subscription< eufs_msgs::msg::ConeArrayWithCovariance >::SharedPtr _perception_detections_subscription_
Subscriber for simulated perception detections.
Definition eufs.hpp:10
rclcpp::Subscription< eufs_msgs::msg::WheelSpeedsStamped >::SharedPtr _eufs_wheel_speeds_subscription_
Subscriber for wheel speeds and steering angle.
Definition eufs.hpp:12
void perception_detections_subscription_callback(const eufs_msgs::msg::ConeArrayWithCovariance &msg) const
Definition eufs.cpp:51
rclcpp::Subscription< eufs_msgs::msg::CanState >::SharedPtr eufs_state_subscription_
Definition eufs.hpp:13
friend class EufsAdapter
Definition planning.hpp:86
std::string get_color_string(int color)
Definition color.cpp:16
Mission get_mission_from_eufs(unsigned short eufs_mission)