Beispiel #1
0
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}")
Beispiel #2
0
def main():
    'main function'

    if len(sys.argv) > 1 and (sys.argv[1].endswith('.mp4')
                              or sys.argv[1].endswith('.gif')):
        filename = sys.argv[1]
        print(f"saving result to '{filename}'")
    else:
        filename = ''
        print(
            "Plotting to the screen. To save a video, pass a command-line argument ending with '.mp4' or '.gif'."
        )

    res, init_extra, update_extra, skip_override, waypoints = simulate(
        filename)

    plot.plot_single(res, 'alt', title='Altitude (ft)')
    alt_filename = 'waypoint_altitude.png'
    plt.savefig(alt_filename)
    print(f"Made {alt_filename}")
    plt.close()

    plot.plot_overhead(res, waypoints=waypoints)
    overhead_filename = 'waypoint_overhead.png'
    plt.savefig(overhead_filename)
    print(f"Made {overhead_filename}")
    plt.close()

    anim3d.make_anim(res,
                     filename,
                     f16_scale=70,
                     viewsize=5000,
                     viewsize_z=4000,
                     trail_pts=np.inf,
                     elev=27,
                     azim=-107,
                     skip_frames=skip_override,
                     chase=True,
                     fixed_floor=True,
                     init_extra=init_extra,
                     update_extra=update_extra)
Beispiel #3
0
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 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}")