Cheetah Software  1.0
plot_spline.py
Go to the documentation of this file.
1 import numpy as np
2 import matplotlib
3 matplotlib.use('TkAgg')
4 import matplotlib.pyplot as plt
5 import os
6 
7 # Plot configuration
8 PLOT_VERTICALLY = 0
9 PLOT_HORIZONTALLY = 1
10 
11 # number of figures in this plot
12 num_figures = 5
13 
14 def create_figures(subfigure_width=480, subfigure_height=600, starting_figure_no=1, starting_col_index = 0, starting_row_index=0, plot_configuration=PLOT_HORIZONTALLY):
15  figure_number = starting_figure_no
16  col_index = starting_col_index
17  row_index = starting_row_index
18 
19  file_path = os.getcwd() + "/../test_data/"
20 
21  ## read files
22  bezier_pos = np.genfromtxt(file_path+'bezier_pos.txt', delimiter=None, dtype=(float))
23  bezier_vel = np.genfromtxt(file_path+'bezier_vel.txt', delimiter=None, dtype=(float))
24  t = np.genfromtxt(file_path+'bz_time.txt', delimiter='\n', dtype=(float))
25 
26  bspline_pos = np.genfromtxt(file_path+'bspline_pos.txt', delimiter=None, dtype=(float))
27  bspline_vel = np.genfromtxt(file_path+'bspline_vel.txt', delimiter=None, dtype=(float))
28  bspline_acc = np.genfromtxt(file_path+'bspline_acc.txt', delimiter=None, dtype=(float))
29  bs_t = np.genfromtxt(file_path+'bs_time.txt', delimiter='\n', dtype=(float))
30 
31  numeric_bezier_vel = np.copy(bezier_pos)
32  bz_length = len(t)
33  for i in range(bz_length-1):
34  numeric_bezier_vel[i,:] = (bezier_pos[i+1,:] - bezier_pos[i,:])/(t[i+1]-t[i])
35 
36  numeric_bspline_vel = np.copy(bspline_pos)
37  numeric_bspline_acc = np.copy(bspline_pos)
38  bs_length = len(bs_t)
39  for i in range(bs_length-1):
40  numeric_bspline_vel[i,:] = (bspline_pos[i+1,:] - bspline_pos[i,:])/(bs_t[i+1]-bs_t[i])
41  numeric_bspline_acc[i,:] = (bspline_vel[i+1,:] - bspline_vel[i,:])/(bs_t[i+1]-bs_t[i])
42 
43  ## plot bezier pos
44  fig = plt.figure(figure_number)
45  plt.get_current_fig_manager().window.wm_geometry(str(subfigure_width) + "x" + str(subfigure_height) + "+" + str(subfigure_width*col_index) + "+" + str(subfigure_height*row_index))
46  fig.canvas.set_window_title('bezier_pos')
47  for i in range(3):
48  ax1 = plt.subplot(3, 1, i+1)
49  plt.plot(t, bezier_pos[:,i], "b-")
50  plt.grid(True)
51  plt.xlabel('time (sec)')
52  ## increment figure number and index
53  figure_number += 1
54  if plot_configuration == PLOT_HORIZONTALLY:
55  col_index += 1
56  elif plot_configuration == PLOT_VERTICALLY:
57  row_index +=1
58 
59  ## plot bezier_vel
60  fig = plt.figure(figure_number)
61  plt.get_current_fig_manager().window.wm_geometry(str(subfigure_width) + "x" + str(subfigure_height) + "+" + str(subfigure_width*col_index) + "+" + str(subfigure_height*row_index))
62  fig.canvas.set_window_title('bezier_vel')
63  for i in range(3):
64  ax1 = plt.subplot(3, 1, i+1)
65  plt.plot(t, bezier_vel[:,i], "b-")
66  plt.plot(t[:-1], numeric_bezier_vel[:-1,i], "r-")
67  plt.grid(True)
68  plt.xlabel('time (sec)')
69  ## increment figure number and index
70  figure_number += 1
71  if plot_configuration == PLOT_HORIZONTALLY:
72  col_index += 1
73  elif plot_configuration == PLOT_VERTICALLY:
74  row_index +=1
75 
76  ## plot bspline pos
77  fig = plt.figure(figure_number)
78  plt.get_current_fig_manager().window.wm_geometry(str(subfigure_width) + "x" + str(subfigure_height) + "+" + str(subfigure_width*col_index) + "+" + str(subfigure_height*row_index))
79  fig.canvas.set_window_title('bspline_pos')
80  for i in range(3):
81  ax1 = plt.subplot(3, 1, i+1)
82  plt.plot(bs_t, bspline_pos[:,i], "b-")
83  plt.grid(True)
84  plt.xlabel('time (sec)')
85  ## increment figure number and index
86  figure_number += 1
87  if plot_configuration == PLOT_HORIZONTALLY:
88  col_index += 1
89  elif plot_configuration == PLOT_VERTICALLY:
90  row_index +=1
91 
92  ## plot bspline_vel
93  fig = plt.figure(figure_number)
94  plt.get_current_fig_manager().window.wm_geometry(str(subfigure_width) + "x" + str(subfigure_height) + "+" + str(subfigure_width*col_index) + "+" + str(subfigure_height*row_index))
95  fig.canvas.set_window_title('bspline_vel')
96  for i in range(3):
97  ax1 = plt.subplot(3, 1, i+1)
98  plt.plot(bs_t, bspline_vel[:,i], "b-")
99  plt.plot(bs_t[:-1], numeric_bspline_vel[:-1,i], "r-")
100  plt.grid(True)
101  plt.xlabel('time (sec)')
102  ## increment figure number and index
103  figure_number += 1
104  if plot_configuration == PLOT_HORIZONTALLY:
105  col_index += 1
106  elif plot_configuration == PLOT_VERTICALLY:
107  row_index +=1
108 
109  ## plot bspline_acc
110  fig = plt.figure(figure_number)
111  plt.get_current_fig_manager().window.wm_geometry(str(subfigure_width) + "x" + str(subfigure_height) + "+" + str(subfigure_width*col_index) + "+" + str(subfigure_height*row_index))
112  fig.canvas.set_window_title('bspline_acc')
113  for i in range(3):
114  ax1 = plt.subplot(3, 1, i+1)
115  plt.plot(bs_t, bspline_acc[:,i], "b-")
116  plt.plot(bs_t[:-1], numeric_bspline_acc[:-1,i], "r-")
117  plt.grid(True)
118  plt.xlabel('time (sec)')
119  ## increment figure number and index
120  figure_number += 1
121  if plot_configuration == PLOT_HORIZONTALLY:
122  col_index += 1
123  elif plot_configuration == PLOT_VERTICALLY:
124  row_index +=1
125 
126 if __name__ == "__main__":
128  plt.show()
def create_figures(subfigure_width=480, subfigure_height=600, starting_figure_no=1, starting_col_index=0, starting_row_index=0, plot_configuration=PLOT_HORIZONTALLY)
Definition: plot_spline.py:14