-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmapRecorder.py
More file actions
39 lines (31 loc) · 1.12 KB
/
Copy pathmapRecorder.py
File metadata and controls
39 lines (31 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import rospy
import sys
from nav_msgs.msg import Odometry
class ScriptToMap(object):
def __init__(self, fileName="data"):
self.x = self.y = 0
self.distance = 0.01 #Update the map every 20 mm
self.fileName = fileName + ".txt"
self.sub = rospy.Subscriber("/odom_reframer/odom_chassis", Odometry, self.handle_pose)
def handle_pose(self,msg):
with open(self.fileName,'a') as f:
x = msg.pose.pose.position.x
y = msg.pose.pose.position.y
dist = ((x-self.x)**2+(y-self.y)**2)**0.5
if dist >= self.distance:
self.x = x
self.y = y
newLine = str(x)+", "+str(y)+'\n'
f.write(newLine)
print("Current position: "+str(x)+", "+ str(y))
def usage():
print("USAGE: python mapRecorder.py <mapOutputFile>")
if __name__ == '__main__':
if len(sys.argv) != 2:
usage()
else:
rospy.init_node("mapRecorder", anonymous = True)
f = open(sys.argv[1]+".txt",'w')
f.close()
mapper = ScriptToMap(sys.argv[1])
rospy.spin()