-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathopenAI_planarCraneContinuous_episodeDataProcessing.py
executable file
·169 lines (125 loc) · 5.14 KB
/
openAI_planarCraneContinuous_episodeDataProcessing.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#! /usr/bin/env python
###############################################################################
# openAI_planarCrane_episodeDataProcessing.py
#
# script to process the episode data saved in the CRAWLAB planar_crane
# OpenAI gym environment
#
# NOTE: Any plotting is set up for output, not viewing on screen.
# So, it will likely be ugly on screen. The saved PDFs should look
# better.
#
# Created: 07/13/17
# - Joshua Vaughan
# - http://www.ucs.louisiana.edu/~jev9637
#
# Modified:
# *
#
# TODO:
# *
###############################################################################
import numpy as np
import matplotlib.pyplot as plt
FILENAME = 'example_data/EpisodeData_2017-07-15_110856.csv'
CABLE_LENGTH = 2.0
# Files have data saved as:
# Time (s), Angle (rad), Angle (rad/s), Trolley Pos (m), Trolly Vel (m/s), Trolley Accel (m/s^2), Reward
#
# We'll unpack that data inline with opening the data file
t, theta, theta_dot, x, x_dot, x_ddot, reward = np.loadtxt(FILENAME, delimiter=',', unpack=True)
# ---- Plot the payload angle -------------------------------------------------
# Set the plot size - 3x2 aspect ratio is best
fig = plt.figure(figsize=(6,4))
ax = plt.gca()
plt.subplots_adjust(bottom=0.17, left=0.17, top=0.96, right=0.96)
# Change the axis units font
plt.setp(ax.get_ymajorticklabels(),fontsize=18)
plt.setp(ax.get_xmajorticklabels(),fontsize=18)
ax.spines['right'].set_color('none')
ax.spines['top'].set_color('none')
ax.xaxis.set_ticks_position('bottom')
ax.yaxis.set_ticks_position('left')
# Turn on the plot grid and set appropriate linestyle and color
ax.grid(True,linestyle=':', color='0.75')
ax.set_axisbelow(True)
# Define the X and Y axis labels
plt.xlabel('Time (s)', fontsize=22, weight='bold', labelpad=5)
plt.ylabel('Angle (deg)', fontsize=22, weight='bold', labelpad=10)
plt.plot(t, theta*180/np.pi, linewidth=2, linestyle='-', label=r'Data 1')
# plt.plot(t, y2, linewidth=2, linestyle='--', label=r'Data 2')
# uncomment below and set limits if needed
# plt.xlim(0,5)
# plt.ylim(0,10)
# Create the legend, then fix the fontsize
# leg = plt.legend(loc='upper right', ncol = 1, fancybox=True)
# ltext = leg.get_texts()
# plt.setp(ltext,fontsize=18)
# Adjust the page layout filling the page using the new tight_layout command
plt.tight_layout(pad=0.5)
# save the figure as a high-res pdf in the current folder
# plt.savefig('OpenAI_planarCrane_angle.pdf')
# ----- Plot the position of the payload --------------------------------------
# Set the plot size - 3x2 aspect ratio is best
fig = plt.figure(figsize=(6,4))
ax = plt.gca()
plt.subplots_adjust(bottom=0.17, left=0.17, top=0.96, right=0.96)
# Change the axis units font
plt.setp(ax.get_ymajorticklabels(),fontsize=18)
plt.setp(ax.get_xmajorticklabels(),fontsize=18)
ax.spines['right'].set_color('none')
ax.spines['top'].set_color('none')
ax.xaxis.set_ticks_position('bottom')
ax.yaxis.set_ticks_position('left')
# Turn on the plot grid and set appropriate linestyle and color
ax.grid(True,linestyle=':', color='0.75')
ax.set_axisbelow(True)
# Define the X and Y axis labels
plt.xlabel('Time (s)', fontsize=22, weight='bold', labelpad=5)
plt.ylabel('Position (m)', fontsize=22, weight='bold', labelpad=10)
plt.plot(t, x, linewidth=2, linestyle='--', label=r'Trolley')
plt.plot(t, x - CABLE_LENGTH * np.sin(theta), linewidth=2, linestyle='-', label=r'Payload')
# uncomment below and set limits if needed
# plt.xlim(0,5)
# plt.ylim(0,10)
# Create the legend, then fix the fontsize
leg = plt.legend(ncol = 1, fancybox=True) #, loc='upper right')
ltext = leg.get_texts()
plt.setp(ltext,fontsize=18)
# Adjust the page layout filling the page using the new tight_layout command
plt.tight_layout(pad=0.5)
# save the figure as a high-res pdf in the current folder
# plt.savefig('OpenAI_planarCrane_position.pdf')
# ----- Plot the acceleration input -------------------------------------------
# Set the plot size - 3x2 aspect ratio is best
fig = plt.figure(figsize=(6,4))
ax = plt.gca()
plt.subplots_adjust(bottom=0.17, left=0.17, top=0.96, right=0.96)
# Change the axis units font
plt.setp(ax.get_ymajorticklabels(),fontsize=18)
plt.setp(ax.get_xmajorticklabels(),fontsize=18)
ax.spines['right'].set_color('none')
ax.spines['top'].set_color('none')
ax.xaxis.set_ticks_position('bottom')
ax.yaxis.set_ticks_position('left')
# Turn on the plot grid and set appropriate linestyle and color
ax.grid(True,linestyle=':', color='0.75')
ax.set_axisbelow(True)
# Define the X and Y axis labels
plt.xlabel('Time (s)', fontsize=22, weight='bold', labelpad=5)
plt.ylabel('Accel. (m/s$^2$)', fontsize=22, weight='bold', labelpad=10)
plt.plot(t, x_ddot, linewidth=2, linestyle='-', label=r'Accel. Input')
# uncomment below and set limits if needed
# plt.xlim(0,5)
# plt.ylim(0,10)
# Create the legend, then fix the fontsize
# leg = plt.legend(loc='upper right', ncol = 1, fancybox=True)
# ltext = leg.get_texts()
# plt.setp(ltext,fontsize=18)
# Adjust the page layout filling the page using the new tight_layout command
plt.tight_layout(pad=0.5)
# save the figure as a high-res pdf in the current folder
# plt.savefig('OpenAI_planarCrane_Accelcommand.pdf')
# show the figure
plt.show()