4 on any new /initialpose, do full rotation, then delay (to hone in amcl) 6 requires dwa_base_controller, global path updated continuously as bot moves 12 import oculusprimesocket
13 from nav_msgs.msg
import Odometry
15 from nav_msgs.msg
import Path
16 from geometry_msgs.msg
import PoseWithCovarianceStamped
18 from move_base_msgs.msg
import MoveBaseActionGoal
38 minturn = math.radians(8)
54 globalpathposenum = 20
59 global goalpose, lastpath, followpath
60 global lptargetx, lptargety
62 lastpath = rospy.get_time()
65 p = data.poses[len(data.poses)-1]
66 lptargetx = p.pose.position.x
67 lptargety = p.pose.position.y
68 quaternion = ( p.pose.orientation.x, p.pose.orientation.y,
69 p.pose.orientation.z, p.pose.orientation.w )
70 lptargetth = tf.transformations.euler_from_quaternion(quaternion)[2]
73 global gptargetx, gptargety, gptargetth, followpath, pathid
79 if n-1 < globalpathposenum:
82 p = data.poses[globalpathposenum]
84 gptargetx = p.pose.position.x
85 gptargety = p.pose.position.y
86 quaternion = ( p.pose.orientation.x, p.pose.orientation.y,
87 p.pose.orientation.z, p.pose.orientation.w )
88 gptargetth = tf.transformations.euler_from_quaternion(quaternion)[2]
90 pathid = data.header.seq
95 global odomx, odomy, odomth
96 odomx = data.pose.pose.position.x
97 odomy = data.pose.pose.position.y
98 quaternion = ( data.pose.pose.orientation.x, data.pose.pose.orientation.y,
99 data.pose.pose.orientation.z, data.pose.pose.orientation.w )
100 odomth = tf.transformations.euler_from_quaternion(quaternion)[2]
104 if data.pose.pose.position.x == 0
and data.pose.pose.position.y == 0:
114 global goalx, goaly, goalth, goalpose, lastpath, initialturn, followpath, nextmove
117 lastpath = rospy.get_time()
121 data = d.goal.target_pose
122 goalx = data.pose.position.x
123 goaly = data.pose.position.y
124 quaternion = ( data.pose.orientation.x, data.pose.orientation.y,
125 data.pose.orientation.z, data.pose.orientation.w )
126 goalth = tf.transformations.euler_from_quaternion(quaternion)[2]
129 nextmove = lastpath + 2
134 if len(data.status_list) == 0:
136 status = data.status_list[len(data.status_list)-1]
137 if status.status == 1:
140 def arcmove(ox, oy, oth, gpx, gpy, gpth, gth, lpx, lpy, lpth):
142 global initialturn, waitonaboutface, nextmove
147 gpdistance = math.sqrt( pow(gpdx,2) + pow(gpdy,2) )
148 if not gpdistance == 0:
149 gpth = math.acos(gpdx/gpdistance)
156 lpdistance = math.sqrt( pow(lpdx,2) + pow(lpdy,2) )
157 if not lpdistance == 0:
158 lpth = math.acos(lpdx/lpdistance)
165 if followpath
and not ox==gpx
and not oy==gpy
and not initialturn:
167 if abs(lpth-gpth) > dpmthreshold:
169 distance = gpdistance/2
174 distance = lpdistance
178 dth = -math.pi*2 + dth
180 dth = math.pi*2 + dth
182 radius = (distance/2)/math.sin(dth/2)
183 arclength = radius * dth
184 if not arclength == 0:
185 if abs(dth/arclength) > dpmthreshold:
191 (trans,rot) = listener.lookupTransform(
'/map',
'/odom', rospy.Time(0))
192 quaternion = (rot[0], rot[1], rot[2], rot[3])
193 dth = (gth - tf.transformations.euler_from_quaternion(quaternion)[2]) - oth
203 dth = -math.pi*2 + dth
205 dth = math.pi*2 + dth
208 if abs(dth) > 1.57
and not goalrotate
and not initialturn
and waitonaboutface < 1:
215 nextmove = rospy.get_time() + listentime
223 if arclength < minlinear:
224 arclength = minlinear
227 rospy.sleep(arclength/0.35)
228 nextmove = rospy.get_time()
235 if dth > 0
and dth < minturn:
237 elif dth < 0
and dth > -minturn:
254 nextmove = rospy.get_time() + listentime
257 def move(ox, oy, oth, tx, ty, tth, gth):
258 global followpath, initialturn, waitonaboutface, nextmove
260 currentpathid = pathid
267 distance = math.sqrt( pow(dx,2) + pow(dy,2) )
271 th = math.acos(dx/distance)
277 (trans,rot) = listener.lookupTransform(
'/map',
'/odom', rospy.Time(0))
278 quaternion = (rot[0], rot[1], rot[2], rot[3])
279 th = gth - tf.transformations.euler_from_quaternion(quaternion)[2]
292 dth = -math.pi*2 + dth
294 dth = math.pi*2 + dth
297 if distance > 0
and distance < minlinear:
300 if distance > maxlinear:
304 if dth < minturn*0.5
and dth > -minturn*0.5:
306 elif dth >= minturn*0.5
and dth < minturn:
308 elif dth <= -minturn*0.5
and dth > -minturn:
314 if abs(dth) > 1.57
and not goalrotate
and not initialturn
and waitonaboutface < 1:
320 nextmove = rospy.get_time() + listentime
326 if not pathid == currentpathid:
327 nextmove = rospy.get_time() + listentime
339 rospy.sleep(distance/meterspersec)
342 nextmove = rospy.get_time() + listentime
348 (trans,rot) = listener.lookupTransform(
'/map',
'/base_link', rospy.Time(0))
352 gdx = goalx - trans[0]
353 gdy = goaly - trans[1]
354 distance = math.sqrt( pow(gdx,2) + pow(gdy,2) )
366 rospy.init_node(
'arcmove_globalpath_follower', anonymous=
False)
369 rospy.on_shutdown(cleanup)
371 rospy.Subscriber(
"odom", Odometry, odomCallback)
372 rospy.Subscriber(
"move_base/DWAPlannerROS/local_plan", Path, pathCallback)
373 rospy.Subscriber(
"move_base/goal", MoveBaseActionGoal, goalCallback)
374 rospy.Subscriber(
"move_base/status", GoalStatusArray, goalStatusCallback)
375 rospy.Subscriber(
"move_base/DWAPlannerROS/global_plan", Path, globalPathCallback)
376 rospy.Subscriber(
"initialpose", PoseWithCovarianceStamped, intialPoseCallback)
381 if re.search(
"true", s):
387 while not rospy.is_shutdown():
391 if goalseek
and (followpath
or goalpose):
395 if re.search(
"true", s):
401 arcmove(odomx, odomy, odomth, gptargetx, gptargety, gptargetth, goalth, lptargetx, lptargety, lptargetth)
404 move(odomx, odomy, odomth, gptargetx, gptargety, gptargetth, goalth)
408 if t - lastpath > 3
and goalseek:
def waitForReplySearch(pattern)
def move(ox, oy, oth, tx, ty, tth, gth)
def goalStatusCallback(data)
def arcmove(ox, oy, oth, gpx, gpy, gpth, gth, lpx, lpy, lpth)
def globalPathCallback(data)
def intialPoseCallback(data)