3from nav_msgs.msg
import Odometry
4from geometry_msgs.msg
import Quaternion
7from sensor_msgs.msg
import PointCloud2
8from custom_interfaces.msg
import ConeArray, VehicleState, PathPointArray
10 format_vehicle_state_msg,
11 format_cone_array_msg,
12 format_nav_odometry_msg,
13 format_path_point_array_msg,
14 get_blue_and_yellow_cones_after_msg_treatment,
21 Adapter class for adapting/synchronizing computations' data with ground truth when using the FSDS simulator.
26 Initializes the FSDSAdapter.
29 node (Node): ROS2 node instance.
30 point_cloud_topic (str): Topic for point cloud data.
35 self.
node.odometry_subscription_ = message_filters.Subscriber(
41 self.
node.odometry_ground_truth_subscription = self.
node.create_subscription(
51 self.
node.perception_subscription_,
52 self.
node.point_cloud_subscription_,
53 self.
node.odometry_subscription_,
60 self.
node.vehicle_state_subscription_,
61 self.
node.map_subscription_,
62 self.
node.odometry_subscription_,
69 self.
node.planning_subscription_,
70 self.
node.planning_gt_subscription_,
84 self.
read_track(
"src/evaluator/evaluator/tracks/track_droneport.csv")
87 self, perception: ConeArray, point_cloud: PointCloud2, odometry: Odometry
90 Callback function to process synchronized messages and compute perception metrics.
93 perception (ConeArray): Cone array perception data.
94 point_cloud (PointCloud2): Point cloud data.
95 odometry (Odometry): Odometry data.
101 perception_output: np.ndarray = format_cone_array_msg(perception)
102 self.
node.compute_and_publish_perception(
103 perception_output, perception_ground_truth
108 Callback function to mark the planning's initial timestamp
111 odometry (Odometry): Behicle's odometry information.
114 if self.
node.use_simulated_se_:
115 self.
node.map_receive_time_ = datetime.datetime.now()
118 self, vehicle_state: VehicleState, map: ConeArray, odometry: Odometry
121 Callback function to process synchronized messages and compute perception metrics.
124 vehicle_state (VehicleState): Vehicle state estimation message.
125 map (ConeArray): Cone array message.
126 odometry (Odometry): Odometry message.
128 pose_treated, velociies_treated = format_vehicle_state_msg(vehicle_state)
129 map_treated: np.ndarray = format_cone_array_msg(map)
130 groundtruth_pose_treated: np.ndarray = format_nav_odometry_msg(odometry)
131 groundtruth_map_treated: np.ndarray = np.array(self.
track)
132 empty_groundtruth_velocity_treated = np.array([0, 0, 0])
133 self.
node.compute_and_publish_state_estimation(
135 groundtruth_pose_treated,
137 empty_groundtruth_velocity_treated,
139 groundtruth_map_treated,
144 planning_output: PathPointArray,
145 path_ground_truth: PathPointArray,
148 Callback function to process synchronized messages and compute planning metrics.
151 planning_output (PathPointArray): Planning output.
152 path_ground_truth (PathPointArray): Groundtruth path message.
154 map_ground_truth_treated: np.ndarray = format_nav_odometry_msg(self.
track)
155 blue_cones, yellow_cones = get_blue_and_yellow_cones_after_msg_treatment(
156 map_ground_truth_treated
158 planning_output_treated: np.ndarray = format_path_point_array_msg(
161 path_ground_truth_treated: np.ndarray = format_path_point_array_msg(
164 self.
node.compute_and_publish_planning(
165 planning_output_treated,
166 path_ground_truth_treated,
173 Creates ground truth from odometry data and a predefined track.
176 odometry (Odometry): Odometry data.
179 list: List of ground truth cone positions (relative positions to the car).
181 rotation_matrix = FSDSAdapter.quaternion_to_rotation_matrix(
182 odometry.pose.pose.orientation
184 perception_ground_truth = []
186 for cone
in self.
track:
187 cone_position = np.array([cone[0], cone[1], 0])
188 transformed_position = np.dot(rotation_matrix, cone_position) + np.array(
189 [odometry.pose.pose.position.x, odometry.pose.pose.position.y, 0]
192 perception_ground_truth.append(np.append(transformed_position[:2], 0))
194 return np.array(perception_ground_truth)
198 Reads track data from a CSV file.
201 filename (str): Path to the CSV file containing track data.
203 with open(filename,
"r")
as file:
210 Parses a line from the track CSV file to extract cone data.
213 line (str): A line from the track CSV file.
216 numpy.ndarray: Array containing cone position data.
218 cone_color_dictionary: dict[str, int] = {
225 words = line.split(
",")
228 color = cone_color_dictionary[words[0]]
229 return np.array([x, y, color, 1])
234 Converts quaternion to a rotation matrix.
237 quaternion (Quaternion): Quaternion representing rotation.
240 numpy.ndarray: Rotation matrix.
242 w, x, y, z = quaternion.w, quaternion.x, quaternion.y, quaternion.z
245 r00 = 1 - 2 * (y**2 + z**2)
246 r01 = 2 * (x * y - z * w)
247 r02 = 2 * (x * z + y * w)
250 r10 = 2 * (x * y + z * w)
251 r11 = 1 - 2 * (x**2 + z**2)
252 r12 = 2 * (y * z - x * w)
255 r20 = 2 * (x * z - z * w)
256 r21 = 2 * (y * z + x * w)
257 r22 = 1 - 2 * (x**2 + y**2)
259 rot_matrix = np.array([[r00, r01, r02], [r10, r11, r12], [r20, r21, r22]])
Class for subscribing to a point cloud topic and synchronizing messages with a ROS2 node.
Adapter class for adapting/synchronizing computations' data with ground truth when using the FSDS sim...
__init__(self, rclpy.node.Node node)
Initializes the FSDSAdapter.
perception_callback(self, ConeArray perception, PointCloud2 point_cloud, Odometry odometry)
Callback function to process synchronized messages and compute perception metrics.
state_estimation_callback(self, VehicleState vehicle_state, ConeArray map, Odometry odometry)
Callback function to process synchronized messages and compute perception metrics.
state_estimation_callback
np.ndarray parse_track_cone(str line)
Parses a line from the track CSV file to extract cone data.
planning_callback(self, PathPointArray planning_output, PathPointArray path_ground_truth)
Callback function to process synchronized messages and compute planning metrics.
list create_perception_ground_truth(self, Odometry odometry)
Creates ground truth from odometry data and a predefined track.
np.ndarray quaternion_to_rotation_matrix(Quaternion quaternion)
Converts quaternion to a rotation matrix.
None read_track(self, str filename)
Reads track data from a CSV file.
odometry_callback(self, Odometry odometry)
Callback function to mark the planning's initial timestamp.