map_remote.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 import rospy, tf
4 import os, struct, re
5 from nav_msgs.msg import OccupancyGrid
6 from sensor_msgs.msg import LaserScan
7 import oculusprimesocket
8 
9 """
10 
11 
12 """
13 
14 lockfilepath = "/run/shm/map.raw.lock"
15 scannum = 0
16 scanpoints = []
17 sendinfodelay = 1.0
18 lastsendinfo = 0
19 
20 def mapcallBack(data):
21  global lockfilepath
22  lockfilepath = "/run/shm/map.raw.lock"
23  framefilepath ="/run/shm/map.raw"
24 
25  if os.path.exists(lockfilepath):
26  return
27 
28  open(lockfilepath, 'w') # creates lockfile
29 
30  framefile = open(framefilepath, 'w')
31  packeddata = struct.pack('%sb' %len(data.data), *data.data)
32  framefile.write(packeddata)
33  framefile.close()
34 
35  if os.path.exists(lockfilepath):
36  os.remove(lockfilepath)
37 
38  quaternion = ( data.info.origin.orientation.x, data.info.origin.orientation.y,
39  data.info.origin.orientation.z, data.info.origin.orientation.w )
40  th = tf.transformations.euler_from_quaternion(quaternion)[2]
41 
42  # width height res originx originy originth updatetime
43  s = "state rosmapinfo "+str(data.info.width)+","+str(data.info.height)+","
44  s += str(data.info.resolution)+","+str(data.info.origin.position.x)+","
45  s += str(data.info.origin.position.y)+","+str(th)+","+str(rospy.get_time())
46 
48  oculusprimesocket.sendString("state rosmapupdated true")
49 
50 def scanCallback(data):
51  global firstscan
52  firstscan.unregister()
53  oculusprimesocket.sendString("state navsystemstatus mapping")
54 
55  # global scannum, scanpoints
56  # scannum += 1
57  # if scannum < 5:
58  # return
59  # scannum=0
60  # scanpoints = data.ranges
61 
62 def sendScan():
63  global scanpoints
64 
65  s = "state rosscan "
66 
67  step = 8
68  size = len(scanpoints)
69  i = 0
70  while i < size-step:
71  s += str(round(scanpoints[i],3))+","
72  i += step
73  s += str(round(scanpoints[size-1],3))
75 
76 # main
77 
79 
80 oculusprimesocket.sendString("state delete roscurrentgoal")
81 oculusprimesocket.sendString("state delete rosamcl")
82 oculusprimesocket.sendString("state delete rosglobalpath")
83 oculusprimesocket.sendString("state delete rosmapinfo")
84 oculusprimesocket.sendString("state delete rosscan")
85 oculusprimesocket.sendString("state delete rosmapupdated")
86 
87 # oculusprimesocket.sendString("state odomturndpms 0.06") # degrees per ms
88 # oculusprimesocket.sendString("state odomturnpwm 65") # measured, approx starting point smooth floor
89 # oculusprimesocket.sendString("speed 150") # linear speed
90 
91 rospy.init_node('map_remote', anonymous=False)
92 
93 if os.path.exists(lockfilepath):
94  os.remove(lockfilepath)
95 
96 rospy.Subscriber("map", OccupancyGrid, mapcallBack)
97 firstscan = rospy.Subscriber("scan", LaserScan, scanCallback)
98 
99 
100 
101 while not rospy.is_shutdown():
102 
103  t = rospy.get_time()
104  if t - lastsendinfo > sendinfodelay:
105  lastsendinfo = t
106 
107  if len(scanpoints) > 0:
108  sendScan()
109 
110  rospy.sleep(0.01) # this really helps with cpu load
111 
def mapcallBack(data)
Definition: map_remote.py:20
def scanCallback(data)
Definition: map_remote.py:50
def sendScan()
Definition: map_remote.py:62


oculusprime
Author(s): Colin Adamson
autogenerated on Wed Mar 10 2021 03:14:59