@@ -35,7 +35,7 @@ def tangent_circle(dist, radius):
3535 return math .radians (100 )
3636
3737
38- def follow_wall_angle (laser_data , radius , right_wall = False ):
38+ def follow_wall_angle (laser_data , radius , right_wall = False , debug = False ):
3939 """
4040 Find the angle to the closest point in laser scan (either on the left or right side).
4141 Then calculate an angle to a free space as tangent to circle of given radius.
@@ -107,12 +107,48 @@ def follow_wall_angle(laser_data, radius, right_wall=False):
107107 else :
108108 tangent_angle = tangent_circle (last_wall_distance , radius )
109109
110+ def deg (index ):
111+ ret = - 135 + index * deg_resolution
112+ return ret if right_wall else - ret
113+
114+ def rad (index ):
115+ return math .radians (deg (index ))
110116
111117 laser_angle = math .radians (- 135 + last_wall_idx * deg_resolution )
112118 total_angle = laser_angle + tangent_angle
113119 if not right_wall :
114120 total_angle = - total_angle
115121
122+ if debug :
123+ from osgar .lib .drawscan import draw_scan
124+ import cv2
125+ img = draw_scan (laser_data , max_obstacle_distance = 4.0 )
126+ width_px , height_px = img .shape [1 ], img .shape [0 ]
127+ scale = 500
128+ dest_x = math .cos (rad (wall_start_idx ))
129+ dest_y = math .sin (rad (wall_start_idx ))
130+ point = (width_px // 2 - int (dest_y * scale ), height_px // 2 - int (dest_x * scale ))
131+ #print(point, f"start {deg(wall_start_idx)})")
132+ cv2 .line (img , (width_px // 2 , height_px // 2 ), point , color = (255 ,255 ,255 ))
133+
134+ dest_x = math .cos (rad (last_wall_idx ))
135+ dest_y = math .sin (rad (last_wall_idx ))
136+ point = (width_px // 2 - int (dest_y * scale ), height_px // 2 - int (dest_x * scale ))
137+ cv2 .line (img , (width_px // 2 , height_px // 2 ), point , color = (120 ,255 ,255 ))
138+
139+ dest_x = math .cos (total_angle )
140+ dest_y = math .sin (total_angle )
141+ point = (width_px // 2 - int (dest_y * scale ), height_px // 2 - int (dest_x * scale ))
142+ cv2 .line (img , (width_px // 2 , height_px // 2 ), point , color = (120 ,120 ,255 ))
143+
144+ point = (width_px // 2 , height_px // 4 )
145+ cv2 .line (img , (width_px // 2 , height_px // 2 ), point , color = (120 ,120 ,120 ))
146+
147+ cv2 .imshow ("follow_wall_angle" , img )
148+ cv2 .waitKey ()
149+
150+ #print("start wall", wall_start_idx, f"deg({deg(wall_start_idx)})", "last wall", last_wall_idx, f"deg({deg(last_wall_idx)})", math.degrees(tangent_angle))
151+
116152 return total_angle
117153
118154
0 commit comments