Formula Student Autonomous Systems
The code for the main driverless system
Loading...
Searching...
No Matches
vehicle_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
7from visualization_msgs.msg import MarkerArray
8from evaluator.formats import format_cone_array_msg, format_marker_array_msg
9import rclpy
10
11
13 """Adapater class to manage the use of the vehicle."""
14
15 def __init__(self, node: rclpy.node.Node):
16 """
17 Initializes the VehicleAdapter class.
18 Args:
19 node (rclpy.node.Node): The ROS2 node object.
20 """
21
22 super().__init__(node)
23
25
26 self.node.state_ground_truth_subscription_ = self.node.create_subscription(
27 MarkerArray,
28 "/ground_truth_data",
30 10,
31 )
32
33 self.node.g_truth_subscription_ = self.node.create_subscription(
34 MarkerArray,
35 "/ground_truth_data",
37 10,
38 )
39
40 self._g_truth = np.array([])
41
42 self._perception_sync_ = message_filters.ApproximateTimeSynchronizer(
43 [
44 self.node.perception_subscription_,
45 ],
46 10,
47 0.1,
48 )
49
51
52 self.node.state_estimation_ = self.node.create_subscription(
53 ConeArray,
54 "/state_estimation/map",
56 10,
57 )
58
59 def state_estimation_callback(self, map: ConeArray):
60 """
61 Callback function for state estimation data.
62
63 Args:
64 map (ConeArray): The state estimation output received.
65 Returns: None
66 """
67 map_treated: np.ndarray = format_cone_array_msg(map)
68
69 if self._state_ground_truth is not None:
70 groundtruth_map_treated: np.ndarray = format_marker_array_msg(
72 )
73 else:
74 self.node.get_logger().warn(
75 "State ground truth is not set yet. Skipping processing."
76 )
77 groundtruth_map_treated = np.array([])
78 self.node.compute_and_publish_state_map(
79 map_treated,
80 groundtruth_map_treated,
81 )
82
83 def perception_callback(self, perception: ConeArray):
84 """
85 Callback function for perception data.
86 Args:
87 perception (ConeArray): The perception output received.
88 Returns:
89 None
90 """
91 if self._g_truth.size != 0:
92 perception_output: np.ndarray = format_cone_array_msg(perception)
93 self.node.compute_and_publish_perception(perception_output, self._g_truth)
94
95 def g_truth_callback(self, g_truth: MarkerArray):
96 """
97 Callback function for ground truth data.
98 Args:
99 g_truth (MarkerArray): The ground truth marker array.
100 Returns:
101 None
102 """
103
104 if self._g_truth.size == 0:
105 self._g_truth = format_marker_array_msg(g_truth)
106
107 def state_ground_truth_callback(self, state_ground_truth: MarkerArray):
108 """!
109 Callback function to process ground truth map messages.
110
111 Args:
112 state_ground_truth (MarkerArray): Ground truth map data.
113 """
114 self._state_ground_truth: MarkerArray = state_ground_truth
Class for subscribing to a point cloud topic and synchronizing messages with a ROS2 node.
Definition adapter.py:7
g_truth_callback(self, MarkerArray g_truth)
__init__(self, rclpy.node.Node node)
state_ground_truth_callback(self, MarkerArray state_ground_truth)
Callback function to process ground truth map messages.
perception_callback(self, ConeArray perception)