def simulate(): 'sim system and return res' ### Initial Conditions ### power = 9 # engine power level (0-10) # Default alpha & beta alpha = deg2rad(2.1215) # Trim Angle of Attack (rad) beta = 0 # Side slip angle (rad) # Initial Attitude alt = 6200 # altitude (ft) vt = 540 # initial velocity (ft/sec) phi = 0 # Roll angle from wings level (rad) theta = (-math.pi / 2) * 0.7 # Pitch angle from nose level (rad) psi = 0.8 * math.pi # Yaw angle from North (rad) # Build Initial Condition Vectors # state = [vt, alpha, beta, phi, theta, psi, P, Q, R, pn, pe, h, pow] init = [vt, alpha, beta, phi, theta, psi, 0, 0, 0, 0, 0, alt, power] tmax = 15 # simulation time ap = GcasAutopilot(init_mode='waiting', stdout=True) ap.waiting_time = 5 ap.waiting_cmd[1] = 2.2 # ps command # custom gains ap.cfg_k_prop = 1.4 ap.cfg_k_der = 0 ap.cfg_eps_p = deg2rad(20) ap.cfg_eps_phi = deg2rad(15) step = 1 / 30 res = run_f16_sim(init, tmax, ap, step=step, extended_states=True, integrator_str='rk45') print(f"Simulation Completed in {round(res['runtime'], 2)} seconds") # Determine whether the GCAS system kept the plane in a safe state # the entire time. safety_limits = SafetyLimits( \ altitude=(0, 45000), #ft \ Nz=(-5, 18), #G's \ v=(300, 2500), # ft/s \ alpha=(-10, 45), # deg \ betaMaxDeg=30,# deg psMaxAccelDeg=500) # deg/s/s verifier = SafetyLimitsVerifier(safety_limits, ap.llc) verifier.verify(res) return res
def main(): 'main function' ### Initial Conditions ### power = 9 # engine power level (0-10) # Default alpha & beta alpha = deg2rad(2.1215) # Trim Angle of Attack (rad) beta = 0 # Side slip angle (rad) # Initial Attitude alt = 1000 # altitude (ft) vt = 540 # initial velocity (ft/sec) phi = -math.pi * 0.9 # Roll angle from wings level (rad) theta = (-math.pi/2)*0.01 # Pitch angle from nose level (rad) psi = 0 # Yaw angle from North (rad) # Build Initial Condition Vectors # state = [vt, alpha, beta, phi, theta, psi, P, Q, R, pn, pe, h, pow] init = [vt, alpha, beta, phi, theta, psi, 0, 0, 0, 0, 0, alt, power] tmax = 10 # simulation time ap = GcasAutopilot(init_mode='roll', stdout=True) step = 1/30 res = run_f16_sim(init, tmax, ap, step=step, extended_states=True, integrator_str='rk45') print(f"Simulation Completed in {round(res['runtime'], 2)} seconds") plot.plot_single(res, 'alt', title='Altitude (ft)') filename = 'alt.png' plt.savefig(filename) print(f"Made {filename}") plot.plot_attitude(res) filename = 'attitude.png' plt.savefig(filename) print(f"Made {filename}") # plot inner loop controls + references plot.plot_inner_loop(res) filename = 'inner_loop.png' plt.savefig(filename) print(f"Made {filename}") # plot outer loop controls + references plot.plot_outer_loop(res) filename = 'outer_loop.png' plt.savefig(filename) print(f"Made {filename}")
def simulate(): 'sim system and return res' ### Initial Conditions ### power = 9 # engine power level (0-10) # Default alpha & beta alpha = deg2rad(2.1215) # Trim Angle of Attack (rad) beta = 0 # Side slip angle (rad) # Initial Attitude alt = 6200 # altitude (ft) vt = 540 # initial velocity (ft/sec) phi = 0 # Roll angle from wings level (rad) theta = (-math.pi / 2) * 0.7 # Pitch angle from nose level (rad) psi = 0.8 * math.pi # Yaw angle from North (rad) # Build Initial Condition Vectors # state = [vt, alpha, beta, phi, theta, psi, P, Q, R, pn, pe, h, pow] init = [vt, alpha, beta, phi, theta, psi, 0, 0, 0, 0, 0, alt, power] tmax = 15 # simulation time ap = GcasAutopilot(init_mode='waiting', stdout=True) ap.waiting_time = 5 ap.waiting_cmd[1] = 2.2 # ps command # custom gains ap.cfg_k_prop = 1.4 ap.cfg_k_der = 0 ap.cfg_eps_p = deg2rad(20) ap.cfg_eps_phi = deg2rad(15) step = 1 / 30 res = run_f16_sim(init, tmax, ap, step=step, extended_states=True, integrator_str='rk45') print(f"Simulation Completed in {round(res['runtime'], 2)} seconds") return res
def main(): 'main function' ### Initial Conditions ### power = 7.6 # engine power level (0-10) # Default alpha & beta alpha = deg2rad(1.8) # Trim Angle of Attack (rad) beta = 0 # Side slip angle (rad) # Initial Attitude alt = 3600 # altitude (ft) vt = 500 # initial velocity (ft/sec) phi = 0 # Roll angle from wings level (rad) theta = 0.03 # Pitch angle from nose level (rad) psi = 0 # Yaw angle from North (rad) # Build Initial Condition Vectors # state = [vt, alpha, beta, phi, theta, psi, P, Q, R, pn, pe, h, pow] init = [vt, alpha, beta, phi, theta, psi, 0, 0, 0, 0, 0, alt, power] tmax = 25 # simulation time ap = StraightAndLevelAutopilot(alt) res = run_f16_sim(init, tmax, ap) print(f"Simulation Completed in {round(res['runtime'], 3)} seconds") plot.plot_overhead(res) filename = 'overhead.png' plt.savefig(filename) print(f"Made {filename}") plot.plot_single(res, 'alt', title='Altitude (ft)') filename = 'alt.png' plt.savefig(filename) print(f"Made {filename}")
def simulate(filename): 'simulate the system, returning waypoints, res' ### Initial Conditions ### power = 9 # engine power level (0-10) # Default alpha & beta alpha = deg2rad(2.1215) # Trim Angle of Attack (rad) beta = 0 # Side slip angle (rad) # Initial Attitude alt = 1500 # altitude (ft) vt = 540 # initial velocity (ft/sec) phi = 0 # Roll angle from wings level (rad) theta = 0 # Pitch angle from nose level (rad) psi = 0 # Yaw angle from North (rad) # Build Initial Condition Vectors # state = [vt, alpha, beta, phi, theta, psi, P, Q, R, pn, pe, h, pow] init = [vt, alpha, beta, phi, theta, psi, 0, 0, 0, 0, 0, alt, power] tmax = 150 # simulation time # make waypoint list waypoints = [[-5000, -7500, alt], [-15000, -7500, alt - 500], [-15000, 5000, alt - 200]] ap = WaypointAutopilot(waypoints, stdout=True) step = 1 / 30 extended_states = True res = run_f16_sim(init, tmax, ap, step=step, extended_states=extended_states, integrator_str='rk45') print( f"Waypoint simulation completed in {round(res['runtime'], 2)} seconds (extended_states={extended_states})" ) if filename.endswith('.mp4'): skip_override = 4 elif filename.endswith('.gif'): skip_override = 15 else: skip_override = 30 anim_lines = [] modes = res['modes'] modes = modes[0::skip_override] def init_extra(ax): 'initialize plot extra shapes' l1, = ax.plot([], [], [], 'bo', ms=8, lw=0, zorder=50) anim_lines.append(l1) l2, = ax.plot([], [], [], 'lime', marker='o', ms=8, lw=0, zorder=50) anim_lines.append(l2) return anim_lines def update_extra(frame): 'update plot extra shapes' mode_names = ['Waypoint 1', 'Waypoint 2', 'Waypoint 3'] done_xs = [] done_ys = [] done_zs = [] blue_xs = [] blue_ys = [] blue_zs = [] for i, mode_name in enumerate(mode_names): if modes[frame] == mode_name: blue_xs.append(waypoints[i][0]) blue_ys.append(waypoints[i][1]) blue_zs.append(waypoints[i][2]) break done_xs.append(waypoints[i][0]) done_ys.append(waypoints[i][1]) done_zs.append(waypoints[i][2]) anim_lines[0].set_data(blue_xs, blue_ys) anim_lines[0].set_3d_properties(blue_zs) anim_lines[1].set_data(done_xs, done_ys) anim_lines[1].set_3d_properties(done_zs) return res, init_extra, update_extra, skip_override, waypoints
def main(): 'main function' ### Initial Conditions ### power = 9 # engine power level (0-10) # Default alpha & beta alpha = deg2rad(2.1215) # Trim Angle of Attack (rad) beta = 0 # Side slip angle (rad) # Initial Attitude alt = 3800 # altitude (ft) vt = 540 # initial velocity (ft/sec) phi = 0 # Roll angle from wings level (rad) theta = 0 # Pitch angle from nose level (rad) psi = math.pi / 8 # Yaw angle from North (rad) # Build Initial Condition Vectors # state = [vt, alpha, beta, phi, theta, psi, P, Q, R, pn, pe, h, pow] init = [vt, alpha, beta, phi, theta, psi, 0, 0, 0, 0, 0, alt, power] tmax = 70 # simulation time # make waypoint list e_pt = 1000 n_pt = 3000 h_pt = 4000 waypoints = [[e_pt, n_pt, h_pt], [e_pt + 2000, n_pt + 5000, h_pt - 100], [e_pt - 2000, n_pt + 15000, h_pt - 250], [e_pt - 500, n_pt + 25000, h_pt]] ap = WaypointAutopilot(waypoints, stdout=True) step = 1 / 30 extended_states = True res = run_f16_sim(init, tmax, ap, step=step, extended_states=extended_states, integrator_str='rk45') print( f"Simulation Completed in {round(res['runtime'], 2)} seconds (extended_states={extended_states})" ) plot.plot_single(res, 'alt', title='Altitude (ft)') filename = 'alt.png' plt.savefig(filename) print(f"Made {filename}") plot.plot_overhead(res, waypoints=waypoints) filename = 'overhead.png' plt.savefig(filename) print(f"Made {filename}") plot.plot_attitude(res) filename = 'attitude.png' plt.savefig(filename) print(f"Made {filename}") # plot inner loop controls + references plot.plot_inner_loop(res) filename = 'inner_loop.png' plt.savefig(filename) print(f"Made {filename}") # plot outer loop controls + references plot.plot_outer_loop(res) filename = 'outer_loop.png' plt.savefig(filename) print(f"Made {filename}")