@@ -24,16 +24,19 @@ import numpy as np
2424import tf
2525from enum import Enum
2626from nav_msgs .msg import Odometry
27- from ar_pose .msg import ARMarker
27+ from ar_track_alvar_msgs .msg import AlvarMarkers
28+ # from ar_pose.msg import ARMarker
2829from geometry_msgs .msg import Twist
2930from tf .transformations import euler_from_quaternion , quaternion_from_euler
3031import math
3132import time
3233
34+ MARKER_ID_DETECTION = 17
35+
3336class AutomaticParkingVision ():
3437 def __init__ (self ):
3538 self .sub_odom_robot = rospy .Subscriber ('/odom' , Odometry , self .cbGetRobotOdom , queue_size = 1 )
36- self .sub_info_marker = rospy .Subscriber ('/ar_pose_marker' , ARMarker , self .cbGetMarkerOdom , queue_size = 1 )
39+ self .sub_info_marker = rospy .Subscriber ('/ar_pose_marker' , AlvarMarkers , self .cbGetMarkerOdom , queue_size = 1 )
3740
3841 self .pub_cmd_vel = rospy .Publisher ('/cmd_vel' , Twist , queue_size = 1 )
3942
@@ -90,15 +93,17 @@ class AutomaticParkingVision():
9093
9194 self .robot_2d_theta = self .total_robot_2d_theta
9295
93- def cbGetMarkerOdom (self , marker_odom_msg ):
94- if self .is_marker_pose_received == False :
95- self .is_marker_pose_received = True
96+ def cbGetMarkerOdom (self , markers_odom_msg ):
97+ for marker_odom_msg in markers_odom_msg .markers :
98+ if marker_odom_msg .id == MARKER_ID_DETECTION :
99+ if self .is_marker_pose_received == False :
100+ self .is_marker_pose_received = True
96101
97- pos_x , pos_y , theta = self .fnGet2DMarkerPose (marker_odom_msg )
102+ pos_x , pos_y , theta = self .fnGet2DMarkerPose (marker_odom_msg )
98103
99- self .marker_2d_pose_x = pos_x
100- self .marker_2d_pose_y = pos_y
101- self .marker_2d_theta = theta - math .pi
104+ self .marker_2d_pose_x = pos_x
105+ self .marker_2d_pose_y = pos_y
106+ self .marker_2d_theta = theta - math .pi
102107
103108 def fnParking (self ):
104109 if self .current_parking_sequence == self .ParkingSequence .searching_parking_lot .value :
@@ -150,7 +155,11 @@ class AutomaticParkingVision():
150155 return True
151156
152157 def fnSeqChangingDirection (self ):
153- desired_angle_turn = math .atan2 (self .marker_2d_pose_y - 0 , self .marker_2d_pose_x - 0 )
158+ desired_angle_turn = - 1. * math .atan2 (self .marker_2d_pose_y - 0 , self .marker_2d_pose_x - 0 )
159+
160+ # rospy.loginfo("desired_angle_turn %f self.marker_2d_pose_x %f self.marker_2d_pose_y %f"
161+ # , desired_angle_turn, self.marker_2d_pose_x, self.marker_2d_pose_y)
162+
154163 self .fnTurn (desired_angle_turn )
155164
156165 if abs (desired_angle_turn ) < 0.01 :
@@ -170,13 +179,15 @@ class AutomaticParkingVision():
170179 self .initial_marker_pose_x = self .marker_2d_pose_x
171180
172181 if self .initial_marker_pose_theta < 0.0 :
173- desired_angle_turn = (math .pi / 2.0 ) + self .initial_marker_pose_theta + (self .robot_2d_theta - self .initial_robot_pose_theta )
182+ desired_angle_turn = (math .pi / 2.0 ) + self .initial_marker_pose_theta - (self .robot_2d_theta - self .initial_robot_pose_theta )
174183 elif self .initial_marker_pose_theta > 0.0 :
175- desired_angle_turn = - (math .pi / 2.0 ) + self .initial_marker_pose_theta + (self .robot_2d_theta - self .initial_robot_pose_theta )
184+ desired_angle_turn = - (math .pi / 2.0 ) + self .initial_marker_pose_theta - (self .robot_2d_theta - self .initial_robot_pose_theta )
176185
177186 # rospy.loginfo("desired_angle_turn %f self.initial_marker_pose_theta %f self.robot_2d_theta %f self.initial_robot_pose_theta %f"
178187 # , desired_angle_turn, self.initial_marker_pose_theta, self.robot_2d_theta, self.initial_robot_pose_theta)
179188
189+ desired_angle_turn = - 1. * desired_angle_turn
190+
180191 self .fnTurn (desired_angle_turn )
181192
182193 if abs (desired_angle_turn ) < 0.05 :
@@ -221,10 +232,10 @@ class AutomaticParkingVision():
221232
222233 def fnSeqParking (self ):
223234 desired_angle_turn = math .atan2 (self .marker_2d_pose_y - 0 , self .marker_2d_pose_x - 0 )
224- self .fnTrackMarker (desired_angle_turn )
235+ self .fnTrackMarker (- desired_angle_turn )
225236
226237 print self .marker_2d_pose_x
227- if abs (self .marker_2d_pose_x ) < 0.13 :
238+ if abs (self .marker_2d_pose_x ) < 0.22 :
228239 self .fnStop ()
229240 return True
230241 else :
@@ -293,16 +304,20 @@ class AutomaticParkingVision():
293304 return pos_x , pos_y , theta
294305
295306 def fnGet2DMarkerPose (self , marker_odom_msg ):
296- quaternion = (marker_odom_msg .pose .pose .orientation .z , marker_odom_msg .pose .pose .orientation .x , marker_odom_msg .pose .pose .orientation .y , marker_odom_msg .pose .pose .orientation .w )
307+ quaternion = (marker_odom_msg .pose .pose .orientation .x , marker_odom_msg .pose .pose .orientation .y , marker_odom_msg .pose .pose .orientation .z , marker_odom_msg .pose .pose .orientation .w )
297308 theta = tf .transformations .euler_from_quaternion (quaternion )[2 ]
298309
310+ theta = theta + np .pi / 2.
311+ # rospy.loginfo("theta : %f", theta)
312+
313+
299314 if theta < 0 :
300315 theta = theta + np .pi * 2
301316 if theta > np .pi * 2 :
302317 theta = theta - np .pi * 2
303318
304- pos_x = marker_odom_msg .pose .pose .position .z
305- pos_y = marker_odom_msg .pose .pose .position .x
319+ pos_x = marker_odom_msg .pose .pose .position .x
320+ pos_y = marker_odom_msg .pose .pose .position .y
306321
307322 return pos_x , pos_y , theta
308323
0 commit comments