-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtestscrpt.py
executable file
·41 lines (35 loc) · 1.01 KB
/
testscrpt.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
#!/usr/bin/env python3
import rospy
import sensor_msgs.msg as sensor_msgs
import matplotlib.pyplot as plt
from threading import Thread
positions = None
names = None
def newJS(jsMsg: sensor_msgs.JointState):
global positions, names
if positions is None:
positions = []
names = [name for name in jsMsg.name]
for pos in jsMsg.position:
positions.append([pos])
else:
for l, pos in zip(positions, jsMsg.position):
l.append(pos)
if len(l) > 500:
del l[0]
def plot():
global positions, names
while not rospy.is_shutdown():
if positions is not None and names is not None:
for l in positions:
plt.plot(l)
plt.legend(names)
plt.pause(0.05)
plt.clf()
if __name__=="__main__":
rospy.init_node("testNode")
sub = rospy.Subscriber("/joint_states", sensor_msgs.JointState, newJS)
t1 = Thread(target=plot)
t1.start()
t1.join()
rospy.spin()