4 listen to /move_base/TrajectoryPlannerROS/local_plan 5 use rotate and movedistance commands to get there, repeat 6 subscribe to odo so moves relative to current pos 7 assumes robot is stopped before running this 9 rosmsg show nav_msgs/Path 10 rosmsg show nav_msgs/Odometry 11 rosmsg show geometry_msgs/PoseStamped << is in map frame!!! 13 consider polling telnet and broadcasting odom from here, to only update odom between moves 14 /move_base/status 3 = goal reached, 1= accepted (read last in list) 15 rosmsg show actionlib_msgs/GoalStatusArray 17 adding initial pose to goal pose: 18 1st test, initial poseth -90deg: solution would be just ot add initial pose to goal pose 22 dth = -math.pi*2 + dth 25 ^^ works but not if odom gets whacked - need to use odom/map tf and ADD to goal pose diff 29 import oculusprimesocket
30 from nav_msgs.msg
import Odometry
32 from nav_msgs.msg
import Path
33 from geometry_msgs.msg
import PoseStamped
46 minturn = math.radians(6)
59 global targetx, targety, targetth, followpath, lastpath, goalpose
60 lastpath = rospy.get_time()
63 p = data.poses[len(data.poses)-1]
64 targetx = p.pose.position.x
65 targety = p.pose.position.y
66 quaternion = ( p.pose.orientation.x, p.pose.orientation.y,
67 p.pose.orientation.z, p.pose.orientation.w )
68 targetth = tf.transformations.euler_from_quaternion(quaternion)[2]
71 global odomx, odomy, odomth
72 odomx = data.pose.pose.position.x
73 odomy = data.pose.pose.position.y
74 quaternion = ( data.pose.pose.orientation.x, data.pose.pose.orientation.y,
75 data.pose.pose.orientation.z, data.pose.pose.orientation.w )
76 odomth = tf.transformations.euler_from_quaternion(quaternion)[2]
79 global goalth, followpath, lastpath, goalpose, odomx, odomy, odomth, targetx, targety, targetth
96 quaternion = ( data.pose.orientation.x, data.pose.orientation.y,
97 data.pose.orientation.z, data.pose.orientation.w )
98 goalth = tf.transformations.euler_from_quaternion(quaternion)[2]
108 if len(data.status_list) == 0:
110 status = data.status_list[len(data.status_list)-1]
111 if status.status == 1:
131 def move(ox, oy, oth, tx, ty, tth, gth):
132 global followpath, goalpose, tfth
141 distance = math.sqrt( pow(dx,2) + pow(dy,2) )
144 th = math.acos(dx/distance)
158 dth = -math.pi*2 + dth
160 dth = math.pi*2 + dth
163 if distance > 0
and distance < 0.05:
167 if dth < minturn*0.3
and dth > -minturn*0.3:
169 elif dth >= minturn*0.3
and dth < minturn:
171 elif dth <= -minturn*0.3
and dth > -minturn:
178 rospy.sleep(dth/(2.0*math.pi) * secondspertwopi)
184 rospy.sleep(-dth/(2.0*math.pi) * secondspertwopi)
191 rospy.sleep(distance*secondspermeter)
203 rospy.init_node(
'base_controller', anonymous=
False)
204 rospy.Subscriber(
"move_base/TrajectoryPlannerROS/local_plan", Path, pathCallback)
205 rospy.Subscriber(
"odom", Odometry, odomCallback)
206 rospy.Subscriber(
"move_base_simple/goal", PoseStamped, goalCallback)
207 rospy.Subscriber(
"move_base/status", GoalStatusArray, goalStatusCallback)
210 rospy.on_shutdown(cleanup)
213 while not rospy.is_shutdown():
216 if t >= nextmove
and goalseek:
217 move(odomx, odomy, odomth, targetx, targety, targetth, goalth)
218 nextmove = t + listentime
226 (trans,rot) = listener.lookupTransform(
'/map',
'/odom', rospy.Time(0))
229 quaternion = (rot[0], rot[1], rot[2], rot[3])
230 tfth = tf.transformations.euler_from_quaternion(quaternion)[2]
def waitForReplySearch(pattern)
def move(ox, oy, oth, tx, ty, tth, gth)
def goalStatusCallback(data)