-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpath_maker.py
More file actions
executable file
·83 lines (65 loc) · 1.84 KB
/
path_maker.py
File metadata and controls
executable file
·83 lines (65 loc) · 1.84 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
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/env python2
import rospy
from nav_msgs.msg import Path
from geometry_msgs.msg import PointStamped, PoseStamped
from visualization_msgs.msg import Marker
import sys
if __name__ != '__main__':
sys.exit(0)
FRAME_ID = '/map'
path = Path()
path_pub = rospy.Publisher('path', Path, queue_size=100)
vis_pub = rospy.Publisher('visualization_marker', Marker, queue_size=1)
def clear_all():
m = Marker()
m.header.stamp = rospy.Time.now();
m.header.frame_id = FRAME_ID
# Delete all
m.action = 3
vis_pub.publish(m)
def redraw_path():
m = Marker()
m.header.stamp = rospy.Time.now();
m.header.frame_id = FRAME_ID
m.action = Marker.ADD
m.color.r = 0
m.color.g = 0
m.color.b = 1
m.color.a = 1
# Important!
m.scale.x = 0.1
m.type = Marker.LINE_LIST
prev_point = None
for p in path.poses:
if not prev_point:
prev_point = p
continue
m.points.append(prev_point.pose.position)
m.points.append(p.pose.position)
prev_point = p
vis_pub.publish(m)
# PointStamped
def point_callback(msg):
ps = PoseStamped()
ps.pose.position = msg.point
ps.header = msg.header
path.poses.append(ps)
rospy.loginfo('Got point:')
rospy.loginfo(' x: {0}'.format(msg.point.x))
rospy.loginfo(' y: {0}'.format(msg.point.y))
clear_all()
redraw_path()
# PoseStamped
def goal_callback(msg):
rospy.loginfo('Got goal')
clear_all()
path.poses.append(msg)
path.header.stamp = rospy.Time.now()
path.header.frame_id = FRAME_ID
path_pub.publish(path)
del path.poses[:]
rospy.init_node('path_maker')
rospy.Subscriber('clicked_point', PointStamped, point_callback)
rospy.Subscriber('move_base_simple/goal', PoseStamped, goal_callback)
rospy.loginfo('Waiting for points. Use "Publish Point" in rviz')
rospy.spin()