def plot_derivatives(): # TODO Finish plotting these derivatives if necessary for the report pbar = ProgressBar('Obtaining Stability Derivatives for Entire Flight Envelope') velocities = np.linspace(0, 75, 20) x_u = [] x_w = [] for i, v in enumerate(velocities): trim_case = Trim(v) derivatives = StabilityDerivatives(u=trim_case.u, w=trim_case.w, q=0, theta_f=trim_case.fuselage_tilt, collective_pitch=trim_case.collective_pitch, longitudinal_cyclic=trim_case.longitudinal_cyclic) x_u.append(derivatives.u_derivatives[0]) x_w.append(derivatives.u_derivatives[1]) pbar.update_loop(i, len(velocities)-1, 'V = %1.2f [m/s]' % v) plt.plot(velocities, x_u) plt.plot(velocities, x_w) plt.show() return 'Figure Plotted and Saved'
def plot_response(self): """ Plots the response of the CH-53 to a step input of 1 [deg] longitudinal cyclic. Note that the state-space representation models the change in inputs and state-variables, thus to use the same input vectors the initial condition is set to zero control deflection. This is then compensated by adding the control deflection necessary for trim during the Forward Euler integration for the non-linear equations. """ pbar = ProgressBar('Performing Linear Simulation') time = np.linspace(0, 40, 1000) # Initial Input Conditions cyclic_input = [0] collective_input = [0] # Defining Step Input into the Longitudinal Cyclic for i in range(1, len(time)): if 0.5 < time[i] < 1.0: cyclic_input.append(radians(1.0)) else: cyclic_input.append(cyclic_input[0]) collective_input.append(collective_input[0]) # Input Matrix U for the State-Space Simulation input_matrix = np.array([collective_input, cyclic_input]).T # Simulating the Linear System yout, time, xout = lsim(self.system, U=input_matrix, T=time) pbar.update(100) delta_t = time[1] - time[0] u = [self.stability_derivatives.u] w = [self.stability_derivatives.w] q = [self.stability_derivatives.q] theta_f = [self.stability_derivatives.theta_f] current_case = self.stability_derivatives # Forward Euler Integration pbar = ProgressBar('Performing Forward Euler Integration') for i in range(1, len(time)): u.append(current_case.u + current_case.u_dot * delta_t) w.append(current_case.w + current_case.w_dot * delta_t) q.append(current_case.q + current_case.q_dot * delta_t) theta_f.append(current_case.theta_f + current_case.theta_f_dot * delta_t) current_case = StabilityDerivatives(u=u[i], w=w[i], q=q[i], theta_f=theta_f[i], longitudinal_cyclic=cyclic_input[i] + self.initial_trim_case.longitudinal_cyclic, collective_pitch=self.initial_trim_case.collective_pitch) pbar.update_loop(i, len(time)-1) # Creating First Figure plt.style.use('ggplot') fig, (cyc_plot, vel_plot) = plt.subplots(2, 1, num='EulervsStateVelocities', sharex='all') # Plotting Input cyc_plot.plot(time, [degrees(rad) for rad in cyclic_input]) cyc_plot.set_ylabel(r'Lon. Cyclic [deg]') cyc_plot.set_xlabel('') cyc_plot.yaxis.set_major_formatter(FormatStrFormatter('%.3f')) cyc_plot.set_title(r'Velocity Response as a Function of Time') # Plotting Velocity Response vel_plot.plot(time, u, label='Horizontal') vel_plot.plot(time, w, label='Vertical') vel_plot.plot(time, [num+self.stability_derivatives.u for num in yout[:, 0]], linestyle=':', color='black') vel_plot.plot(time, [num+self.stability_derivatives.w for num in yout[:, 1]], linestyle=':', color='black', label='Lin. Simulation') vel_plot.set_ylabel(r'Velocity [m/s]') vel_plot.set_xlabel('') vel_plot.yaxis.set_major_formatter(FormatStrFormatter('%.2f')) vel_plot.legend(loc='best') # Creating Labels & Saving Figure plt.xlabel(r'Time [s]') plt.show() fig.savefig(fname=os.path.join(working_dir, 'Figures', '%s.pdf' % fig.get_label()), format='pdf') # Creating Second Figure fig, (cyc_plot, q_plot, theta_plot) = plt.subplots(3, 1, num='EulervsStateAngles', sharex='all') cyc_plot.plot(time, [degrees(rad) for rad in cyclic_input]) # Plotting Input cyc_plot.set_ylabel(r'$\theta_{ls}$ [deg]') cyc_plot.yaxis.set_major_formatter(FormatStrFormatter('%.3f')) cyc_plot.set_title(r'Angular Response as a Function of Time') # Plotting Fuselage Pitch-Rate q_plot.plot(time, [degrees(rad) for rad in q]) q_plot.plot(time, [degrees(num+self.stability_derivatives.q) for num in yout[:, 2]], linestyle=':', color='black', label='Lin. Simulation') q_plot.set_ylabel(r'$q$ [deg/s]') q_plot.set_xlabel('') q_plot.yaxis.set_major_formatter(FormatStrFormatter('%.2f')) q_plot.legend(loc='best') # Plotting Fuselage Pitch theta_plot.plot(time, [degrees(rad) for rad in theta_f]) theta_plot.plot(time, [degrees(num+self.stability_derivatives.theta_f) for num in yout[:, 3]], linestyle=':', color='black', label='Lin. Simulation') theta_plot.set_ylabel(r'$\theta_f$ [deg]') theta_plot.set_xlabel('') theta_plot.yaxis.set_major_formatter(FormatStrFormatter('%.2f')) theta_plot.legend(loc='best') # Creating x-label & Saving Figure plt.xlabel(r'Time [s]') plt.show() fig.savefig(fname=os.path.join(working_dir, 'Figures', '%s.pdf' % fig.get_label()), format='pdf') return 'Figures Plotted and Saved'