151def format_transform_stamped_msg(msg: TransformStamped) -> np.ndarray:
153 Formats the TransformStamped message into a numpy array.
156 msg (TransformStamped): TransformStamped message.
159 np.ndarray: Numpy array of transform.
161 yaw: float = euler_from_quaternion(
163 msg.transform.rotation.x,
164 msg.transform.rotation.y,
165 msg.transform.rotation.z,
166 msg.transform.rotation.w,
171 msg.transform.translation.x,
172 msg.transform.translation.y,
178def format_twist_with_covariance_stamped_msg(
179 msg: TwistWithCovarianceStamped,
182 Formats the TwistWithCovarianceStamped message into a numpy array.
185 msg (TwistWithCovarianceStamped): TwistWithCovarianceStamped message.
188 np.ndarray: Numpy array of twist (used for velocities).
191 [msg.twist.twist.linear.x, msg.twist.twist.linear.y, msg.twist.twist.angular.z]
195def format_car_state_msg(
197) -> tuple[np.ndarray, np.ndarray]:
200 Formats the CarState message from eufs into a tuple of numpy arrays.
202 Args: msg (CarState): CarState message from eufs
204 Returns: tuple[np.ndarray, np.ndarray]: (state, velocities)
209 msg.pose.pose.position.x,
210 msg.pose.pose.position.y,
211 euler_from_quaternion(
213 msg.pose.pose.orientation.x,
214 msg.pose.pose.orientation.y,
215 msg.pose.pose.orientation.z,
216 msg.pose.pose.orientation.w,
223 msg.twist.twist.linear.x,
224 msg.twist.twist.linear.y,
225 msg.twist.twist.angular.z,
266def format_nav_odometry_msg(msg: Odometry) -> tuple[np.ndarray, np.ndarray]:
268 Formats the Odometry message into a numpy array.
271 msg (Odometry): Odometry message.
274 np.ndarray: Numpy array of odometry.
279 msg.pose.pose.position.x,
280 msg.pose.pose.position.y,
281 euler_from_quaternion(
283 msg.pose.pose.orientation.x,
284 msg.pose.pose.orientation.y,
285 msg.pose.pose.orientation.z,
286 msg.pose.pose.orientation.w,
293 msg.twist.twist.linear.x,
294 msg.twist.twist.linear.y,
295 msg.twist.twist.angular.z,
340def find_closest_elements(arr1: np.ndarray, arr2: np.ndarray) -> np.ndarray:
341 """Find the closest elements in arr2 for each element in arr1.
344 arr1 (np.ndarray): array in which each element's 2 initial values are x and y positions
345 arr2 (np.ndarray): array in which each element's 2 initial values are x and y positions
348 np.ndarray: array of elements from arr2 that are the closest to at least one element in arr1
351 arr1_xy = arr1[:, :2]
352 arr2_xy = arr2[:, :2]
355 distances = np.linalg.norm(
356 arr1_xy[:, np.newaxis, :] - arr2_xy[np.newaxis, :, :], axis=2
360 closest_indices = np.argmin(distances, axis=1)
363 closest_elements = np.unique(arr2[closest_indices], axis=0)
365 return closest_elements
368def get_blue_and_yellow_cones_after_msg_treatment(
370) -> tuple[np.ndarray, np.ndarray]:
372 Divides the result of converting the EUFS or FSDS map message to np.ndarray into blue and yellow cones arrays, attributing orange
373 cones into blue or yellow cones.
376 arr (np.ndarray): Array of cones with the following attributes: x, y, index, confidence, type.
379 tuple[np.ndarray, np.ndarray]: the first array is the array of blue cones and the second contains yellow cones.
385 array1.append(element)
386 elif element[2] == 1:
387 array2.append(element)
388 elif element[2]
in [2, 3]:
389 closest_distance = float(
"inf")
392 for array
in [array1, array2]:
393 for array_element
in array:
394 distance = np.linalg.norm(element[:2] - array_element[:2])
396 if distance < closest_distance:
397 closest_distance = distance
398 closest_array = array
400 if closest_array
is not None:
401 closest_array.append(element)
403 raise ValueError(
"Invalid cone color index: %d" % element[2])
405 return np.array(array1), np.array(array2)