@@ -146,6 +146,7 @@ class SubTChallenge:
146146 def __init__ (self , config , bus ):
147147 self .bus = bus
148148 bus .register ("desired_speed" , "pose2d" , "artf_xyz" , "pose3d" , "stdout" , "request_origin" )
149+ self .verbose = False
149150 self .start_pose = None
150151 self .traveled_dist = 0.0
151152 self .time = None
@@ -257,7 +258,11 @@ def go_safely(self, desired_direction):
257258 safety , safe_direction = 1.0 , desired_direction
258259 else :
259260 safety , safe_direction = self .local_planner .recommend (desired_direction )
260- #print(self.time,"safety:%f desired:%f safe_direction:%f"%(safety, desired_direction, safe_direction))
261+ if self .verbose :
262+ heading = math .degrees (quaternion .heading (self .orientation ))
263+ desired_deg = math .degrees (desired_direction )
264+ safe_deg = math .degrees (safe_direction )
265+ print (self .time , self .sim_time_sec , f"safety:{ safety :.2f} desired:{ desired_deg :.2f} ° safe_direction: { safe_deg :.2f} °" )
261266 #desired_angular_speed = 1.2 * safe_direction
262267 desired_angular_speed = 0.9 * safe_direction
263268 size = len (self .scan )
@@ -326,7 +331,8 @@ def follow_wall(self, radius, right_wall=False, timeout=timedelta(hours=3), dist
326331 if self .use_center :
327332 desired_direction = 0
328333 else :
329- desired_direction = follow_wall_angle (self .scan , radius = radius , right_wall = right_wall )
334+ debug_callback = debug_follow_wall if self .verbose else None
335+ desired_direction = follow_wall_angle (self .scan , radius = radius , right_wall = right_wall , debug_callback = debug_callback )
330336 self .go_safely (desired_direction )
331337 if dist_limit is not None :
332338 if dist_limit < abs (self .traveled_dist - start_dist ): # robot can return backward -> abs()
@@ -1006,6 +1012,36 @@ def join(self, timeout=None):
10061012 self .thread .join (timeout )
10071013
10081014
1015+ def debug_follow_wall (laser_data , max_obstacle_distance_m , start_rad , last_rad , total_rad ):
1016+ from osgar .lib .drawscan import draw_scan
1017+ import cv2
1018+
1019+ img = draw_scan (laser_data , max_obstacle_distance = max_obstacle_distance_m )
1020+ width_px , height_px = img .shape [1 ], img .shape [0 ]
1021+ scale = 300
1022+ dest_x = math .cos (start_rad )
1023+ dest_y = math .sin (start_rad )
1024+ point = (width_px // 2 - int (dest_y * scale ), height_px // 2 - int (dest_x * scale ))
1025+ cv2 .line (img , (width_px // 2 , height_px // 2 ), point , color = (255 ,255 ,255 ))
1026+
1027+ dest_x = math .cos (last_rad )
1028+ dest_y = math .sin (last_rad )
1029+ point = (width_px // 2 - int (dest_y * scale ), height_px // 2 - int (dest_x * scale ))
1030+ cv2 .line (img , (width_px // 2 , height_px // 2 ), point , color = (120 ,255 ,255 ))
1031+
1032+ dest_x = math .cos (total_rad )
1033+ dest_y = math .sin (total_rad )
1034+ point = (width_px // 2 - int (dest_y * scale ), height_px // 2 - int (dest_x * scale ))
1035+ cv2 .line (img , (width_px // 2 , height_px // 2 ), point , color = (120 ,120 ,255 ))
1036+
1037+ point = (width_px // 2 , height_px // 4 )
1038+ cv2 .line (img , (width_px // 2 , height_px // 2 ), point , color = (120 ,120 ,120 ))
1039+
1040+ #print(f"start {math.degrees(start_rad):.2f}°", f"last wall {math.degrees(last_rad):.2f}°" , f"desired {math.degrees(total_rad):.2f}°")
1041+ cv2 .imshow ("follow_wall_angle" , img )
1042+ cv2 .waitKey ()
1043+
1044+
10091045def main ():
10101046 import argparse
10111047 from osgar .lib .config import config_load
0 commit comments