Formula Student Autonomous Systems
The code for the main driverless system
Loading...
Searching...
No Matches
onground_adapter.py
Go to the documentation of this file.
1from evaluator.adapter import Adapter
2import message_filters
3import numpy as np
4from sensor_msgs.msg import PointCloud2
5from evaluator.formats import format_cone_array_msg
6from custom_interfaces.msg import ConeArray, PathPointArray
7from visualization_msgs.msg import MarkerArray
8from evaluator.formats import (
9 format_cone_array_msg,
10 format_marker_array_msg,
11 format_path_point_array_msg,
12)
13import rclpy
14
15
17 """Adapater class to manage the use of OnGround topics."""
18
19 def __init__(self, node: rclpy.node.Node):
20 """
21 Initializes the OnGroundAdapter class.
22 Args:
23 node (rclpy.node.Node): The ROS2 node object.
24 """
25
26 super().__init__(node)
27
28 self.blue_cones = None
29 self.yellow_cones = None
30
31 self.node.blue_cones_subscription_ = self.node.create_subscription(
32 MarkerArray,
33 "/path_planning/blue_cones",
35 10,
36 )
37
38 self.node.yellow_cones_subscription_ = self.node.create_subscription(
39 MarkerArray,
40 "/path_planning/yellow_cones",
42 10,
43 )
44
45 self.node.planning_subscription_ = self.node.create_subscription(
46 PathPointArray,
47 "/path_planning/path",
49 10,
50 )
51
52 def blue_cones_callback(self, blue_cones_msg: MarkerArray):
53 """Callback for blue cones."""
54 self.blue_cones = format_marker_array_msg(blue_cones_msg)
55 self.node.get_logger().info("Updated blue cones")
56
57 def yellow_cones_callback(self, yellow_cones_msg: MarkerArray):
58 """Callback for yellow cones."""
59 self.yellow_cones = format_marker_array_msg(yellow_cones_msg)
60 self.node.get_logger().info("Updated yellow cones")
61
62 def planning_callback(self, planning_output_msg: PathPointArray):
63 """Callback for planning output."""
64 # Ensure blue and yellow cones have been received before processing
65 if self.blue_cones is None or self.yellow_cones is None:
66 self.node.get_logger().warn("Waiting for cone data...")
67 return
68
69 # Process the planning output
70 planning_output_treated = format_path_point_array_msg(planning_output_msg)
71
72 self.node.get_logger().info("Processing planning output")
73 # Publish the planning results using the stored cones
74 self.node.compute_and_publish_planning(
75 planning_output_treated,
76 planning_output_treated,
77 self.blue_cones,
78 self.yellow_cones,
79 )
Class for subscribing to a point cloud topic and synchronizing messages with a ROS2 node.
Definition adapter.py:7
blue_cones_callback(self, MarkerArray blue_cones_msg)
yellow_cones_callback(self, MarkerArray yellow_cones_msg)
planning_callback(self, PathPointArray planning_output_msg)