Skip to content

Commit

Permalink
fixing logs in lifecycles callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
mgonzs13 committed Aug 29, 2024
1 parent dabdb90 commit 7f936e0
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 23 deletions.
2 changes: 1 addition & 1 deletion yolov8_bringup/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<name>yolov8_bringup</name>
<version>3.3.0</version>
<version>3.3.2</version>
<description>YOLOv8 for ROS 2</description>
<maintainer email="[email protected]">Miguel Ángel González Santamarta</maintainer>
<license>GPL-3</license>
Expand Down
2 changes: 1 addition & 1 deletion yolov8_msgs/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<name>yolov8_msgs</name>
<version>3.3.0</version>
<version>3.3.2</version>
<description>Msgs for YOLOv8</description>
<maintainer email="[email protected]">Miguel Ángel González Santamarta</maintainer>
<license>GPL-3</license>
Expand Down
2 changes: 1 addition & 1 deletion yolov8_ros/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<name>yolov8_ros</name>
<version>3.3.0</version>
<version>3.3.2</version>
<description>YOLOv8 for ROS 2</description>
<maintainer email="[email protected]">Miguel Ángel González Santamarta</maintainer>
<license>GPL-3</license>
Expand Down
28 changes: 22 additions & 6 deletions yolov8_ros/yolov8_ros/debug_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -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:
Expand Down
24 changes: 20 additions & 4 deletions yolov8_ros/yolov8_ros/detect_3d_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand All @@ -112,26 +115,39 @@ 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)
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...")

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(
Expand Down
26 changes: 22 additions & 4 deletions yolov8_ros/yolov8_ros/tracking_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -84,24 +87,39 @@ 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)

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:
Expand Down
24 changes: 18 additions & 6 deletions yolov8_ros/yolov8_ros/yolov8_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand All @@ -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:
Expand All @@ -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:
Expand Down

0 comments on commit 7f936e0

Please sign in to comment.