-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpoints.py
61 lines (44 loc) · 1.58 KB
/
points.py
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
#! /usr/bin/env python3
from mimetypes import init
import rospy
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
from geometry_msgs.msg import PoseStamped
from nav_msgs.msg import Path
class Path1:
def __init__(self):
self.x = []
self.y = []
self.fig, self.ax = plt.subplots()
self.line, = self.ax.plot([], [])
self.anim = FuncAnimation(self.fig, self.update_plot, interval=1000)
def update_plot(self, frame):
self.line.set_xdata(self.x) # Update x data
self.line.set_ydata(self.y) # Update y data
self.ax.relim() # Recompute the data limits
self.ax.autoscale_view() # Autoscale the plot
#self.fig.canvas.draw() # Redraw the plot
def Callback(self,data):
#print(len(data.poses))
self.points = []
for i in data.poses:
pt = [0.0, 0.0]
pt[0] = i.pose.position.x
pt[1] = -i.pose.position.y
#print(pt)
self.points.append(pt)
self.points = np.array(self.points)
if len(self.points) > 0:
self.x, self.y = (self.points).T
#self.update_plot()
def path_sub(self):
rospy.init_node('path', anonymous=True)
self.ps_sub = rospy.Subscriber('/move_base/NavfnROS/plan', Path, self.Callback,queue_size=1)
plt.show()
rospy.spin()
if __name__ == '__main__':
try:
path = Path1()
path.path_sub()
except rospy.ROSInterruptException: pass