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
5 RCLCPP_INFO(this->get_logger(), "Planning : Pacsim using simulated State Estimation");
6 tf_buffer_ = std::make_unique<tf2_ros::Buffer>(this->get_clock());
7 tf_listener_ = std::make_shared<tf2_ros::TransformListener>(*tf_buffer_);
8 timer_ = this->create_wall_timer(std::chrono::milliseconds(60),
9 std::bind(&PacSimAdapter::timer_callback, this));
10
11 this->finished_client_ = this->create_client<std_srvs::srv::Empty>("/pacsim/finish_signal");
12
13 this->path_sub_ = this->create_subscription<visualization_msgs::msg::MarkerArray>(
14 "/pacsim/map", 10, std::bind(&PacSimAdapter::track_callback, this, std::placeholders::_1));
15 }
16 RCLCPP_DEBUG(this->get_logger(), "Planning : Pacsim adapter created");
17 this->mission_ = common_lib::competition_logic::Mission::AUTOCROSS;
18}
19
21 RCLCPP_DEBUG(this->get_logger(), "Planning pacsim timer callback");
22 if (tf_buffer_->canTransform("map", "car", tf2::TimePointZero)) {
23 RCLCPP_DEBUG(this->get_logger(), "Planning recieved already recieved first pose\n");
24 custom_interfaces::msg::Pose pose;
25 geometry_msgs::msg::TransformStamped t =
26 tf_buffer_->lookupTransform("map", "car", tf2::TimePointZero);
27 pose.header = t.header;
28 tf2::Quaternion q(t.transform.rotation.x, t.transform.rotation.y, t.transform.rotation.z,
29 t.transform.rotation.w);
30 tf2::Matrix3x3 m(q);
31 double roll = 0.0;
32 double pitch = 0.0;
33 double yaw = 0.0;
34
35 m.getRPY(roll, pitch, yaw);
36 pose.theta = yaw;
37 pose.x = t.transform.translation.x;
38 pose.y = t.transform.translation.y;
40 }
41}
42
44 RCLCPP_INFO(this->get_logger(), "Planning : Set mission undefined for PacSim");
45}
46
48 (void)this->finished_client_->async_send_request(
49 std::make_shared<std_srvs::srv::Empty::Request>(),
50 [this](rclcpp::Client<std_srvs::srv::Empty>::SharedFuture) {
51 RCLCPP_INFO(this->get_logger(), "Planning : Finished signal sent");
52 });
53}
54
55void PacSimAdapter::track_callback(const visualization_msgs::msg::MarkerArray& msg) {
56 RCLCPP_DEBUG(this->get_logger(), "Planning : Received track map in pacsim adapter");
57 custom_interfaces::msg::ConeArray cones;
58 for (auto c : msg.markers) {
59 if (c.type == 4 || (c.pose.position.x == 0 && c.pose.position.y == 0) ||
60 std::pow(c.pose.position.x - 10.17, 2) + std::pow(c.pose.position.y - 7.02, 2) < 0.5) {
61 continue;
62 }
63 custom_interfaces::msg::Cone cone;
64 cone.position.x = c.pose.position.x;
65 cone.position.y = c.pose.position.y;
66 cones.cone_array.push_back(cone);
67 }
68 this->track_map_callback(cones);
69}
void finish() override
Called when planning mission is completed.
Definition pacsim.cpp:47
void timer_callback()
Definition pacsim.cpp:20
void set_mission_state()
Definition pacsim.cpp:43
rclcpp::TimerBase::SharedPtr timer_
Definition pacsim.hpp:23
void track_callback(const visualization_msgs::msg::MarkerArray &msg)
Definition pacsim.cpp:55
rclcpp::Subscription< visualization_msgs::msg::MarkerArray >::SharedPtr path_sub_
Definition pacsim.hpp:22
std::shared_ptr< tf2_ros::TransformListener > tf_listener_
Definition pacsim.hpp:26
std::unique_ptr< tf2_ros::Buffer > tf_buffer_
Definition pacsim.hpp:25
rclcpp::Client< std_srvs::srv::Empty >::SharedPtr finished_client_
Definition pacsim.hpp:21
Responsible for path planning and trajectory generation for the autonomous vehicle.
Definition planning.hpp:54
void track_map_callback(const custom_interfaces::msg::ConeArray &message)
Callback for track map updates.
Definition planning.cpp:220
void vehicle_localization_callback(const custom_interfaces::msg::Pose &message)
Callback for vehicle localization pose updates.
Definition planning.cpp:203
friend class PacSimAdapter
Definition planning.hpp:85
Mission mission_
Definition planning.hpp:92
bool planning_using_simulated_se_
Flag to enable/disable the use of simulated State Estimation.