generate_graph_from_config_task.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 from argparse import ArgumentParser
00004 import numpy as np
00005 import matplotlib.pyplot as plt
00006 from matplotlib.backends.backend_pdf import PdfPages
00007 
00008 
00009 def plot_data(ax,
00010               title,
00011               ylabel,
00012               data_filename=None,
00013               time_list=None):
00014     if data_filename is None:
00015         data_filename =title+'.dat'
00016     data = np.genfromtxt(args.data_dirname+'/'+data_filename,
00017                          dtype=np.float32, delimiter=' ', names=True)
00018     t = data['time']
00019     for name in data.dtype.names[1:]:
00020         d = data[name]
00021         ax.plot(t, d, linewidth=2, label=name)
00022         ax.set_ylabel(ylabel)
00023 
00024     ax.set_title(title, fontsize=18)
00025     ax.set_xlabel('time')
00026     ax.legend(loc='upper center', bbox_to_anchor=(0.5, -0.05), ncol=4)
00027     ax.set_xlim(t[0], t[-1])
00028     ax.grid(True)
00029 
00030     if time_list is not None:
00031         for t in time_list:
00032             ax.axvline(x=t, linewidth=0.8, color='k', linestyle='--')
00033 
00034 
00035 if __name__ == '__main__':
00036     global args
00037 
00038     parser = ArgumentParser()
00039 
00040     parser.add_argument('--data-dirname', type=str, dest="data_dirname", required=True)
00041     parser.add_argument('--output-filename', type=str, dest="output_filename", required=True)
00042 
00043     parser.add_argument('--kin-task-time-list', nargs="*", type=float, dest="kin_task_time_list", default=None)
00044     parser.add_argument('--eom-task-time-list', nargs="*", type=float, dest="eom_task_time_list", default=None)
00045     parser.add_argument('--centroid-task-time-list', nargs="*", type=float, dest="centroid_task_time_list", default=None)
00046     parser.add_argument('--posture-task-time-list', nargs="*", type=float, dest="posture_task_time_list", default=None)
00047 
00048     args = parser.parse_args()
00049 
00050     fig,axes = plt.subplots(nrows=10,ncols=1,figsize=(10,100))
00051 
00052     plot_data(axes[0], title='theta', ylabel='joint position [rad] [m]')
00053     plot_data(axes[1], title='cog', ylabel='position [m]')
00054     plot_data(axes[2], title='angular_momentum', ylabel='angular momentum [kg m^2 / s]')
00055     plot_data(axes[3], title='wrench', ylabel='force [N] / moment [Nm]')
00056 
00057     plot_data(axes[4], title="kinematics_task", ylabel='position [m] / orientation [rad]', time_list=args.kin_task_time_list)
00058     plot_data(axes[5], title="translational_eom_task", ylabel='force [N]', time_list=args.eom_task_time_list)
00059     plot_data(axes[6], title="rotational_eom_task", ylabel='moment [Nm]', time_list=args.eom_task_time_list)
00060     plot_data(axes[7], title="cog_task", ylabel='position [m]', time_list=args.centroid_task_time_list)
00061     plot_data(axes[8], title="angular_momentum_task", ylabel='angular momentum [kg m^2 / s]', time_list=args.centroid_task_time_list)
00062     plot_data(axes[9], title="posture_task", ylabel='joint position [rad] [m]', time_list=args.posture_task_time_list)
00063 
00064     plt.tight_layout()
00065     fig.show()
00066 
00067     pdf = PdfPages(args.output_filename)
00068     pdf.savefig()
00069     pdf.close()


eus_qp
Author(s):
autogenerated on Fri Apr 19 2019 03:45:20