From 7f936e099bb9f869dd4a3ba4d19d1e2bf1c22821 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20=C3=81ngel=20Gonz=C3=A1lez=20Santamarta?= Date: Thu, 29 Aug 2024 10:42:49 +0200 Subject: [PATCH] fixing logs in lifecycles callbacks --- yolov8_bringup/package.xml | 2 +- yolov8_msgs/package.xml | 2 +- yolov8_ros/package.xml | 2 +- yolov8_ros/yolov8_ros/debug_node.py | 28 +++++++++++++++++++------ yolov8_ros/yolov8_ros/detect_3d_node.py | 24 +++++++++++++++++---- yolov8_ros/yolov8_ros/tracking_node.py | 26 +++++++++++++++++++---- yolov8_ros/yolov8_ros/yolov8_node.py | 24 +++++++++++++++------ 7 files changed, 85 insertions(+), 23 deletions(-) diff --git a/yolov8_bringup/package.xml b/yolov8_bringup/package.xml index f07a31e..7c6e8c4 100644 --- a/yolov8_bringup/package.xml +++ b/yolov8_bringup/package.xml @@ -2,7 +2,7 @@ yolov8_bringup - 3.3.0 + 3.3.2 YOLOv8 for ROS 2 Miguel Ángel González Santamarta GPL-3 diff --git a/yolov8_msgs/package.xml b/yolov8_msgs/package.xml index dea0657..3f483fa 100644 --- a/yolov8_msgs/package.xml +++ b/yolov8_msgs/package.xml @@ -2,7 +2,7 @@ yolov8_msgs - 3.3.0 + 3.3.2 Msgs for YOLOv8 Miguel Ángel González Santamarta GPL-3 diff --git a/yolov8_ros/package.xml b/yolov8_ros/package.xml index b88e241..13e553a 100644 --- a/yolov8_ros/package.xml +++ b/yolov8_ros/package.xml @@ -2,7 +2,7 @@ yolov8_ros - 3.3.0 + 3.3.2 YOLOv8 for ROS 2 Miguel Ángel González Santamarta GPL-3 diff --git a/yolov8_ros/yolov8_ros/debug_node.py b/yolov8_ros/yolov8_ros/debug_node.py index c689489..419d664 100644 --- a/yolov8_ros/yolov8_ros/debug_node.py +++ b/yolov8_ros/yolov8_ros/debug_node.py @@ -55,10 +55,8 @@ def __init__(self) -> None: self.declare_parameter("image_reliability", QoSReliabilityPolicy.BEST_EFFORT) - self.get_logger().info("Debug node created") - def on_configure(self, state: LifecycleState) -> TransitionCallbackReturn: - self.get_logger().info(f"Configuring {self.get_name()}") + self.get_logger().info(f"[{self.get_name()}] Configuring...") self.image_qos_profile = QoSProfile( reliability=self.get_parameter( @@ -75,10 +73,13 @@ def on_configure(self, state: LifecycleState) -> TransitionCallbackReturn: self._kp_markers_pub = self.create_publisher( MarkerArray, "dgb_kp_markers", 10) + super().on_configure(state) + self.get_logger().info(f"[{self.get_name()}] Configured") + return TransitionCallbackReturn.SUCCESS def on_activate(self, state: LifecycleState) -> TransitionCallbackReturn: - self.get_logger().info(f"Activating {self.get_name()}") + self.get_logger().info(f"[{self.get_name()}] Activating...") # subs self.image_sub = message_filters.Subscriber( @@ -90,25 +91,40 @@ def on_activate(self, state: LifecycleState) -> TransitionCallbackReturn: (self.image_sub, self.detections_sub), 10, 0.5) self._synchronizer.registerCallback(self.detections_cb) + super().on_activate(state) + self.get_logger().info(f"[{self.get_name()}] Activated") + return TransitionCallbackReturn.SUCCESS def on_deactivate(self, state: LifecycleState) -> TransitionCallbackReturn: - self.get_logger().info(f"Deactivating {self.get_name()}") + self.get_logger().info(f"[{self.get_name()}] Deactivating...") self.destroy_subscription(self.image_sub.sub) self.destroy_subscription(self.detections_sub.sub) del self._synchronizer + super().on_deactivate(state) + self.get_logger().info(f"[{self.get_name()}] Deactivated") + return TransitionCallbackReturn.SUCCESS def on_cleanup(self, state: LifecycleState) -> TransitionCallbackReturn: - self.get_logger().info(f"Cleaning up {self.get_name()}") + self.get_logger().info(f"[{self.get_name()}] Cleaning up...") self.destroy_publisher(self._dbg_pub) self.destroy_publisher(self._bb_markers_pub) self.destroy_publisher(self._kp_markers_pub) + super().on_cleanup(state) + self.get_logger().info(f"[{self.get_name()}] Cleaned up") + + return TransitionCallbackReturn.SUCCESS + + def on_shutdown(self, state: LifecycleState) -> TransitionCallbackReturn: + self.get_logger().info(f"[{self.get_name()}] Shutting down...") + super().on_cleanup(state) + self.get_logger().info(f"[{self.get_name()}] Shutted down") return TransitionCallbackReturn.SUCCESS def draw_box(self, cv_image: np.ndarray, detection: Detection, color: Tuple[int]) -> np.ndarray: diff --git a/yolov8_ros/yolov8_ros/detect_3d_node.py b/yolov8_ros/yolov8_ros/detect_3d_node.py index 4dcb2d9..151e705 100644 --- a/yolov8_ros/yolov8_ros/detect_3d_node.py +++ b/yolov8_ros/yolov8_ros/detect_3d_node.py @@ -61,7 +61,7 @@ def __init__(self) -> None: self.cv_bridge = CvBridge() def on_configure(self, state: LifecycleState) -> TransitionCallbackReturn: - self.get_logger().info(f"Configuring {self.get_name()}") + self.get_logger().info(f"[{self.get_name()}] Configuring...") self.target_frame = self.get_parameter( "target_frame").get_parameter_value().string_value @@ -93,10 +93,13 @@ def on_configure(self, state: LifecycleState) -> TransitionCallbackReturn: # pubs self._pub = self.create_publisher(DetectionArray, "detections_3d", 10) + super().on_configure(state) + self.get_logger().info(f"[{self.get_name()}] Configured") + return TransitionCallbackReturn.SUCCESS def on_activate(self, state: LifecycleState) -> TransitionCallbackReturn: - self.get_logger().info(f"Activating {self.get_name()}") + self.get_logger().info(f"[{self.get_name()}] Activating...") # subs self.depth_sub = message_filters.Subscriber( @@ -112,10 +115,13 @@ def on_activate(self, state: LifecycleState) -> TransitionCallbackReturn: (self.depth_sub, self.depth_info_sub, self.detections_sub), 10, 0.5) self._synchronizer.registerCallback(self.on_detections) + super().on_activate(state) + self.get_logger().info(f"[{self.get_name()}] Activated") + return TransitionCallbackReturn.SUCCESS def on_deactivate(self, state: LifecycleState) -> TransitionCallbackReturn: - self.get_logger().info(f"Deactivating {self.get_name()}") + self.get_logger().info(f"[{self.get_name()}] Deactivating...") self.destroy_subscription(self.depth_sub.sub) self.destroy_subscription(self.depth_info_sub.sub) @@ -123,15 +129,25 @@ def on_deactivate(self, state: LifecycleState) -> TransitionCallbackReturn: del self._synchronizer + super().on_deactivate(state) + self.get_logger().info(f"[{self.get_name()}] Deactivated") + return TransitionCallbackReturn.SUCCESS def on_cleanup(self, state: LifecycleState) -> TransitionCallbackReturn: - self.get_logger().info(f"Cleaning up {self.get_name()}") + self.get_logger().info(f"[{self.get_name()}] Cleaning up...") del self.tf_listener self.destroy_publisher(self._pub) + super().on_cleanup(state) + self.get_logger().info(f"[{self.get_name()}] Cleaned up") + + def on_shutdown(self, state: LifecycleState) -> TransitionCallbackReturn: + self.get_logger().info(f"[{self.get_name()}] Shutting down...") + super().on_cleanup(state) + self.get_logger().info(f"[{self.get_name()}] Shutted down") return TransitionCallbackReturn.SUCCESS def on_detections( diff --git a/yolov8_ros/yolov8_ros/tracking_node.py b/yolov8_ros/yolov8_ros/tracking_node.py index 008118b..b1b7774 100644 --- a/yolov8_ros/yolov8_ros/tracking_node.py +++ b/yolov8_ros/yolov8_ros/tracking_node.py @@ -51,7 +51,7 @@ def __init__(self) -> None: self.cv_bridge = CvBridge() def on_configure(self, state: LifecycleState) -> TransitionCallbackReturn: - self.get_logger().info(f"Configuring {self.get_name()}") + self.get_logger().info(f"[{self.get_name()}] Configuring...") tracker_name = self.get_parameter( "tracker").get_parameter_value().string_value @@ -62,10 +62,13 @@ def on_configure(self, state: LifecycleState) -> TransitionCallbackReturn: self.tracker = self.create_tracker(tracker_name) self._pub = self.create_publisher(DetectionArray, "tracking", 10) + super().on_configure(state) + self.get_logger().info(f"[{self.get_name()}] Configured") + return TransitionCallbackReturn.SUCCESS def on_activate(self, state: LifecycleState) -> TransitionCallbackReturn: - self.get_logger().info(f"Activating {self.get_name()}") + self.get_logger().info(f"[{self.get_name()}] Activating...") image_qos_profile = QoSProfile( reliability=self.image_reliability, @@ -84,10 +87,13 @@ def on_activate(self, state: LifecycleState) -> TransitionCallbackReturn: (image_sub, detections_sub), 10, 0.5) self._synchronizer.registerCallback(self.detections_cb) + super().on_activate(state) + self.get_logger().info(f"[{self.get_name()}] Activated") + return TransitionCallbackReturn.SUCCESS def on_deactivate(self, state: LifecycleState) -> TransitionCallbackReturn: - self.get_logger().info(f"Deactivating {self.get_name()}") + self.get_logger().info(f"[{self.get_name()}] Deactivating...") self.destroy_subscription(self.image_sub.sub) self.destroy_subscription(self.detections_sub.sub) @@ -95,13 +101,25 @@ def on_deactivate(self, state: LifecycleState) -> TransitionCallbackReturn: del self._synchronizer self._synchronizer = None + super().on_deactivate(state) + self.get_logger().info(f"[{self.get_name()}] Deactivated") + return TransitionCallbackReturn.SUCCESS def on_cleanup(self, state: LifecycleState) -> TransitionCallbackReturn: - self.get_logger().info(f"Cleaning up {self.get_name()}") + self.get_logger().info(f"[{self.get_name()}] Cleaning up...") del self.tracker + super().on_cleanup(state) + self.get_logger().info(f"[{self.get_name()}] Cleaned up") + + return TransitionCallbackReturn.SUCCESS + + def on_shutdown(self, state: LifecycleState) -> TransitionCallbackReturn: + self.get_logger().info(f"[{self.get_name()}] Shutting down...") + super().on_cleanup(state) + self.get_logger().info(f"[{self.get_name()}] Shutted down") return TransitionCallbackReturn.SUCCESS def create_tracker(self, tracker_yaml: str) -> BaseTrack: diff --git a/yolov8_ros/yolov8_ros/yolov8_node.py b/yolov8_ros/yolov8_ros/yolov8_node.py index 2434c01..2164777 100644 --- a/yolov8_ros/yolov8_ros/yolov8_node.py +++ b/yolov8_ros/yolov8_ros/yolov8_node.py @@ -64,10 +64,8 @@ def __init__(self) -> None: "NAS": NAS } - self.get_logger().info("Yolov8 Node created") - def on_configure(self, state: LifecycleState) -> TransitionCallbackReturn: - self.get_logger().info(f"Configuring {self.get_name()}") + self.get_logger().info(f"[{self.get_name()}] Configuring...") self.model_type = self.get_parameter( "model_type").get_parameter_value().string_value @@ -101,10 +99,13 @@ def on_configure(self, state: LifecycleState) -> TransitionCallbackReturn: ) self.cv_bridge = CvBridge() + super().on_configure(state) + self.get_logger().info(f"[{self.get_name()}] Configured") + return TransitionCallbackReturn.SUCCESS def on_activate(self, state: LifecycleState) -> TransitionCallbackReturn: - self.get_logger().info(f"Activating {self.get_name()}") + self.get_logger().info(f"[{self.get_name()}] Activating...") self.yolo = self.type_to_model[self.model_type](self.model) self.yolo.fuse() @@ -118,11 +119,12 @@ def on_activate(self, state: LifecycleState) -> TransitionCallbackReturn: ) super().on_activate(state) + self.get_logger().info(f"[{self.get_name()}] Activated") return TransitionCallbackReturn.SUCCESS def on_deactivate(self, state: LifecycleState) -> TransitionCallbackReturn: - self.get_logger().info(f"Deactivating {self.get_name()}") + self.get_logger().info(f"[{self.get_name()}] Deactivating...") del self.yolo if "cuda" in self.device: @@ -133,16 +135,26 @@ def on_deactivate(self, state: LifecycleState) -> TransitionCallbackReturn: self._sub = None super().on_deactivate(state) + self.get_logger().info(f"[{self.get_name()}] Deactivated") return TransitionCallbackReturn.SUCCESS def on_cleanup(self, state: LifecycleState) -> TransitionCallbackReturn: - self.get_logger().info(f"Cleaning up {self.get_name()}") + self.get_logger().info(f"[{self.get_name()}] Cleaning up...") self.destroy_publisher(self._pub) del self.image_qos_profile + super().on_cleanup(state) + self.get_logger().info(f"[{self.get_name()}] Cleaned up") + + return TransitionCallbackReturn.SUCCESS + + def on_shutdown(self, state: LifecycleState) -> TransitionCallbackReturn: + self.get_logger().info(f"[{self.get_name()}] Shutting down...") + super().on_cleanup(state) + self.get_logger().info(f"[{self.get_name()}] Shutted down") return TransitionCallbackReturn.SUCCESS def enable_cb(self, request: SetBool.Request, response: SetBool.Response) -> SetBool.Response: