Autonomous Racing  1
f1tenth Project Group of Technical University Dortmund, Germany
plotter.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 from PyQt4 import QtGui
4 from topics import TOPIC_EPISODE_RESULT
5 import pyqtgraph as pg
6 import rospy
7 import sys
8 from collections import deque
9 from reinforcement_learning.msg import EpisodeResult
10 
11 
12 def update_plot(msg):
13  global episode_count, plot_window
14  reward_list.append(msg.reward)
15  length_list.append(msg.length)
16  episode_count += 1
17  reward_plot.prepareGeometryChange()
18  reward_plot.setData(range(episode_count)[-plot_window:], reward_list)
19  length_plot.prepareGeometryChange()
20  length_plot.setData(range(episode_count)[-plot_window:], length_list)
21 
22 
23 rospy.init_node('reinforcement_learning_plotter', anonymous=True)
24 
25 plot_window = rospy.get_param("~plot_window")
26 
27 reward_list = deque(maxlen=plot_window)
28 length_list = deque(maxlen=plot_window)
29 episode_count = 0
30 
31 app = QtGui.QApplication(sys.argv)
32 app_window = pg.GraphicsWindow(title='Learning Progress')
33 main_plot = app_window.addPlot(title='Episodes')
34 
35 main_plot.addLegend()
36 
37 length_plot = main_plot.plot(pen='g', name='length')
38 reward_plot = main_plot.plot(pen='r', name='reward')
39 
40 rospy.Subscriber(TOPIC_EPISODE_RESULT, EpisodeResult, update_plot)
41 
42 if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
43  app.exec_()
44 
45 rospy.spin()
def update_plot(msg)
Definition: plotter.py:12