-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpath_maker.py
More file actions
75 lines (57 loc) · 2.06 KB
/
path_maker.py
File metadata and controls
75 lines (57 loc) · 2.06 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
import sys
import rospy
import rospkg
from morai_msgs.msg import EgoVehicleStatus
from math import pi,cos,sin,pi,sqrt,pow
from nav_msgs.msg import Path
import tf
from geometry_msgs.msg import PoseStamped
class test :
def __init__(self):
rospy.init_node('path_maker', anonymous=True)
arg = rospy.myargv(argv=sys.argv)
self.path_folder_name=arg[1]
self.make_path_name=arg[2]
rospy.Subscriber("/Ego_topic",EgoVehicleStatus, self.status_callback)
self.global_path_pub= rospy.Publisher('/global_path',Path, queue_size=1)
self.is_status=False
self.prev_x = 0
self.prev_y = 0
rospack=rospkg.RosPack()
pkg_path=rospack.get_path('erp_ros')
full_path=pkg_path +'/'+ self.path_folder_name+'/'+self.make_path_name+'.txt'
self.f=open(full_path, 'w')
rate=rospy.Rate(30)
while not rospy.is_shutdown():
if self.is_status==True :
self.path_make()
rate.sleep()
self.f.close()
def path_make(self):
x=self.status_msg.position.x
y=self.status_msg.position.y
z=self.status_msg.position.z
distance=sqrt(pow(x-self.prev_x,2)+pow(y-self.prev_y,2))
if distance > 0.3:
data='{0}\t{1}\t{2}\n'.format(x,y,z)
self.f.write(data)
self.prev_x=x
self.prev_y=y
print(x,y)
def status_callback(self,msg): ## Vehicl Status Subscriber
self.is_status=True
self.status_msg=msg
br = tf.TransformBroadcaster()
br.sendTransform((self.status_msg.position.x, self.status_msg.position.y, self.status_msg.position.z),
tf.transformations.quaternion_from_euler(0, 0, (self.status_msg.heading)/180*pi),
rospy.Time.now(),
"gps",
"map")
if __name__ == '__main__':
try:
test_track=test()
except rospy.ROSInterruptException:
pass