1+ import os
12import threading
23import time
34
2223from spot_executor .fake_spot import FakeSpot
2324from spot_executor .spot import Spot
2425from spot_skills .detection_utils import YOLODetector
25- from std_msgs .msg import Bool
26+ from std_msgs .msg import Bool , String
2627from visualization_msgs .msg import Marker , MarkerArray
2728
2829from robot_executor_interface .mid_level_planner import (
@@ -73,13 +74,15 @@ def build_markers(pts, namespaces, frames, colors):
7374
7475
7576class RosFeedbackCollector :
76- def __init__ (self , odom_frame ):
77+ def __init__ (self , odom_frame : str , output_dir : str ):
7778 self .pick_confirmation_event = threading .Event ()
7879 self .pick_confirmation_response = False
7980
8081 self .break_out_of_waiting_loop = False
8182 self .odom_frame = odom_frame
8283
84+ self .output_dir = output_dir
85+
8386 def bounding_box_detection_feedback (
8487 self , annotated_img , centroid_x , centroid_y , semantic_class
8588 ):
@@ -217,13 +220,25 @@ def register_publishers(self, node):
217220 Image , "~/annotated_image" , qos_profile = latching_qos
218221 )
219222
223+ self .lease_takeover_publisher = node .create_publisher (String , "~/takeover" , 10 )
224+
220225 node .create_subscription (
221226 Bool ,
222227 "~/pick_confirmation" ,
223228 self .pick_confirmation_callback ,
224229 10 ,
225230 )
226231
232+ # TODO(aaron): Once we switch logging to python logger,
233+ # should move into init
234+ self .logger .info (f"Logging to: { self .output_dir } " )
235+ if not os .path .exists (self .output_dir ):
236+ self .logger .info (f"Making { self .output_dir } " )
237+ os .mkdir (self .output_dir )
238+ log_fn = os .path .join (self .output_dir , "lease_log.txt" )
239+ with open (log_fn , "w" ) as fo :
240+ fo .write ("time,event\n " )
241+
227242 def pick_confirmation_callback (self , msg ):
228243 if msg .data :
229244 self .logger .info ("Detection is valid. Continuing pick action!" )
@@ -234,6 +249,16 @@ def pick_confirmation_callback(self, msg):
234249
235250 self .pick_confirmation_event .set ()
236251
252+ def log_lease_takeover (self , event : str ):
253+ log_fn = os .path .join (self .output_dir , "lease_log.txt" )
254+ t = time .time ()
255+ with open (log_fn , "a" ) as fo :
256+ fo .write (f"{ t } ,{ event } \n " )
257+
258+ msg = String ()
259+ msg .data = f"{ t } ,{ event } "
260+ self .lease_takeover_publisher .publish (msg )
261+
237262
238263class SpotExecutorRos (Node ):
239264 def __init__ (self ):
@@ -292,7 +317,11 @@ def __init__(self):
292317 assert body_frame != ""
293318 self .body_frame = body_frame
294319
295- self .feedback_collector = RosFeedbackCollector (self .odom_frame )
320+ self .declare_parameter ("output_dir" , "" )
321+ output_dir = self .get_parameter ("output_dir" ).value
322+ assert output_dir != ""
323+
324+ self .feedback_collector = RosFeedbackCollector (self .odom_frame , output_dir )
296325 self .feedback_collector .register_publishers (self )
297326
298327 self .tf_buffer = tf2_ros .Buffer ()
0 commit comments