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