5 from nav_msgs.msg
import OccupancyGrid, Path
6 from nav_msgs.msg
import Odometry
7 from geometry_msgs.msg
import PoseWithCovarianceStamped
8 import oculusprimesocket
9 from move_base_msgs.msg
import MoveBaseActionGoal, MoveBaseAction, MoveBaseGoal, MoveBaseActionFeedback
10 from sensor_msgs.msg
import LaserScan
13 from std_srvs.srv
import Empty
14 import dynamic_reconfigure.client
18 rosmapinfo (origin, size, resolution) on callback 19 rosamcl (x,y,th) on callback 20 -also sending global path, scan data at this time, if exists 21 roscurrentgoal (x,y,th) on callback 24 send amcl on callback, + latest odom << change to amcloffset only??? 25 roscurrentgoal, rosmapinfo unchanged 27 send global path (without amcl offset), scan data, odom every 0.5 sec 32 lockfilepath =
"/run/shm/map.raw.lock" 47 recoveryrotate =
False 57 lockfilepath =
"/run/shm/map.raw.lock" 58 framefilepath =
"/run/shm/map.raw" 60 if os.path.exists(lockfilepath):
63 open(lockfilepath,
'w')
65 framefile = open(framefilepath,
'w')
66 packeddata = struct.pack(
'%sb' %len(data.data), *data.data)
67 framefile.write(packeddata)
70 if os.path.exists(lockfilepath):
71 os.remove(lockfilepath)
73 quaternion = ( data.info.origin.orientation.x, data.info.origin.orientation.y,
74 data.info.origin.orientation.z, data.info.origin.orientation.w )
75 th = tf.transformations.euler_from_quaternion(quaternion)[2]
78 s =
"state rosmapinfo "+str(data.info.width)+
","+str(data.info.height)+
"," 79 s += str(data.info.resolution)+
","+str(data.info.origin.position.x)+
"," 80 s += str(data.info.origin.position.y)+
","+str(th)+
","+str(rospy.get_time())
86 global odomx, odomy, odomth
87 odomx = data.pose.pose.position.x
88 odomy = data.pose.pose.position.y
89 quaternion = ( data.pose.pose.orientation.x, data.pose.pose.orientation.y,
90 data.pose.pose.orientation.z, data.pose.pose.orientation.w )
91 odomth = tf.transformations.euler_from_quaternion(quaternion)[2]
94 global odomx, odomy, odomth, goalseek, xoffst, yoffst, thoffst
97 amclx = data.pose.pose.position.x
98 amcly = data.pose.pose.position.y
99 quaternion = ( data.pose.pose.orientation.x, data.pose.pose.orientation.y,
100 data.pose.pose.orientation.z, data.pose.pose.orientation.w )
101 amclth = tf.transformations.euler_from_quaternion(quaternion)[2]
103 xoffst = amclx - odomx
104 yoffst = amcly - odomy
105 thoffst = amclth - odomth
109 global odomx, odomy, odomth, xoffst, yoffst, thoffst
110 data = d.feedback.base_position.pose
111 amclx = data.position.x
112 amcly = data.position.y
113 quaternion = ( data.orientation.x, data.orientation.y,
114 data.orientation.z, data.orientation.w )
115 amclth = tf.transformations.euler_from_quaternion(quaternion)[2]
117 xoffst = amclx - odomx
118 yoffst = amcly - odomy
119 thoffst = amclth - odomth
122 data = d.goal.target_pose
123 x = data.pose.position.x
124 y = data.pose.position.y
125 quaternion = ( data.pose.orientation.x, data.pose.orientation.y,
126 data.pose.orientation.z, data.pose.orientation.w )
127 th = tf.transformations.euler_from_quaternion(quaternion)[2]
134 globalpath = data.poses
135 recoveryrotate =
False 138 s =
"state rosglobalpath " 143 while i < size - step:
144 s = s + str(round(path[i].pose.position.x,2))+
"," 145 s = s + str(round(path[i].pose.position.y,2))+
"," 148 s = s + str(round(path[size-1].pose.position.x,2))
149 s = s + str(round(path[size-1].pose.position.y,2))
161 pose = PoseWithCovarianceStamped()
162 pose.header.stamp = rospy.Time.now()
163 pose.header.frame_id =
"map" 165 pose.pose.pose.position.x = x
166 pose.pose.pose.position.y = y
167 pose.pose.pose.position.z = 0.0
169 quat = tf.transformations.quaternion_from_euler(0, 0, th)
170 pose.pose.pose.orientation.x = quat[0]
171 pose.pose.pose.orientation.y = quat[1]
172 pose.pose.pose.orientation.z = quat[2]
173 pose.pose.pose.orientation.w = quat[3]
183 initpose_pub.publish(pose)
186 global move_base, goal
193 goal = MoveBaseGoal()
194 goal.target_pose.header.stamp = rospy.Time.now()
195 goal.target_pose.header.frame_id =
"map" 197 goal.target_pose.pose.position.x = x
198 goal.target_pose.pose.position.y = y
199 goal.target_pose.pose.position.z = 0.0
201 quat = tf.transformations.quaternion_from_euler(0, 0, th)
202 goal.target_pose.pose.orientation.x = quat[0]
203 goal.target_pose.pose.orientation.y = quat[1]
204 goal.target_pose.pose.orientation.z = quat[2]
205 goal.target_pose.pose.orientation.w = quat[3]
207 move_base.send_goal(goal)
210 global scannum, scanpoints
215 scanpoints = data.ranges
221 size = len(scanpoints)
230 s += str(round(scanpoints[i],3))+
"," 234 s += str(round(scanpoints[size-1],3))
248 global goalseek, recoveryrotate
250 move_base.cancel_goal()
256 recoveryrotate =
False 261 if lidarclient ==
None:
262 lidarclient = dynamic_reconfigure.client.Client(
"lidarbroadcast")
264 if (str ==
"disabled"):
266 params = {
'lidar_enable' :
'false' }
267 lidarclient.update_configuration(params)
268 elif (str==
"enabled"):
270 params = {
'lidar_enable' :
'true' }
271 lidarclient.update_configuration(params)
278 rospy.init_node(
'remote_nav', anonymous=
False)
280 if os.path.exists(lockfilepath):
281 os.remove(lockfilepath)
295 rospy.Subscriber(
"map", OccupancyGrid, mapcallBack)
296 rospy.Subscriber(
"odom", Odometry, odomCallback)
297 rospy.Subscriber(
"amcl_pose", PoseWithCovarianceStamped, amclPoseCallback)
298 rospy.Subscriber(
"move_base/goal", MoveBaseActionGoal, goalCallback)
299 rospy.Subscriber(
"move_base/DWAPlannerROS/global_plan", Path, globalPathCallback)
300 rospy.Subscriber(
"scan", LaserScan, scanCallback)
301 rospy.Subscriber(
"move_base/feedback", MoveBaseActionFeedback, feedbackCallback)
302 initpose_pub = rospy.Publisher(
'initialpose', PoseWithCovarianceStamped, queue_size=10)
303 rospy.on_shutdown(cleanup)
306 move_base.wait_for_server()
308 if not rospy.is_shutdown():
314 while not rospy.is_shutdown():
317 if re.search(
"rosinitialpose", s):
320 recoveryrotate =
False 322 elif re.search(
"rossetgoal", s):
327 recoveryrotate =
False 329 elif re.search(
"rosgoalcancel true", s):
332 elif re.search(
"lidar", s):
337 if t - lastsendinfo > sendinfodelay:
340 if len(scanpoints) > 0:
345 s += str(round(xoffst, 3))+
","+str(round(yoffst,3))+
","+str(round(thoffst,3))+
"," 346 s += str(round(odomx,3))+
","+str(round(odomy,3))+
","+str(round(odomth,3))
350 if len(globalpath) > 0:
354 state = move_base.get_state()
355 if state == GoalStatus.SUCCEEDED:
360 elif state == GoalStatus.ABORTED:
361 if not recoveryrotate:
362 recoveryrotate =
True 370 move_base.cancel_goal()
371 rospy.wait_for_service(
'/move_base/clear_costmaps')
372 rospy.ServiceProxy(
'/move_base/clear_costmaps', Empty)()
382 if re.search(
"rosgoalcancel true", s):
404 if re.search(
"rosgoalcancel true", s):
409 move_base.send_goal(goal)
def amclPoseCallback(data)
def waitForReplySearch(pattern)
def replyBufferSearch(pattern)
def globalPathCallback(data)
def publishinitialpose(str)