def test_trip(force_recompute=False, filename='/home/poine/tmp/glider_opty_4d_wp{}.npz', exp='0'):
    if   exp == '0': atm = go_u.AtmosphereCalmSym()
    elif exp == '1': atm = go_u.AtmosphereHorizFieldSym(-5.)
    else: atm = go_u.AtmosphereHorizFieldSym(-7.5)
    _p = sgo4d.Planner( #_obj_fun=sgo4d.obj_sum_z, _obj_grad=sgo4d.obj_grad_sum_z,
                        #_obj_fun=sgo4d.obj_final_z, _obj_grad=sgo4d.obj_grad_final_z,
                        _obj_fun=obj_wp, _obj_grad=obj_grad_wp,
                        #_obj_fun=obj_cc, _obj_grad=obj_grad_cc,
                        _atm=atm, e0=-50, n0=0, u0=25, psi0=0,
                        _v_constraint = (7., 12.),
                        _e_constraint = (-75, 175),
                        _n_constraint = (-50, 100),
                        #_u_constraint = (   25, 100),
                        duration=20, hz=50.)

    sgo4d.compute_or_load(atm, _p, force_recompute, filename.format(exp), tol=1e-5, max_iter=2000, initial_guess=None)

    dists_to_wp = np.linalg.norm(np.vstack((_p.sol_e, _p.sol_n)).T - [ewp, nwp], axis=1)
    arrival_idx = np.argmax(dists_to_wp<20)
    
    go_u.plot_solution_chronogram(_p, max_idx=arrival_idx); plt.savefig(f'plots/glider_4d_wp{exp}_chrono.png')
    go_u.plot_solution_2D_en(_p, max_idx=arrival_idx); plt.savefig(f'plots/glider_4d_wp{exp}_en.png')
    #go_u.plot_solution_2D_nu(_p, n0=-40, n1=50, dn=5., e0=0., h0=0., h1=70, dh=2.5)
    go_u.plot_solution_3D(_p, max_idx=arrival_idx); plt.savefig(f'plots/glider_4d_wp{exp}_3D.png')
    plt.show()
def main(force_recompute=False, filename='/tmp/glider_opty.pkl'):
    #atm = go_u.AtmosphereWharingtonSym(radius=40., strength=-1)
    #atm = go_u.AtmosphereCalmSym()
    #atm = go_u.atm2() # broken?
    atm = go_u.AtmosphereRidgeSym()
    _p = Planner(  #_obj_fun=obj_final_z, _obj_grad=obj_grad_final_z,
        _obj_fun=obj_sum_z,
        _obj_grad=obj_grad_sum_z,
        _atm=atm,
        x0=10,
        y0=0,
        z0=25,
        psi0=np.pi,
        duration=50,
        hz=50.)

    compute_or_load(atm,
                    _p,
                    force_recompute,
                    filename,
                    tol=1e-5,
                    max_iter=1500,
                    initial_guess=None)
    go_u.plot_solution_chronogram(_p)
    go_u.plot_solution_2D_en(_p)
    go_u.plot_solution_2D_nu(_p,
                             n0=-40,
                             n1=50,
                             dn=5.,
                             e0=0.,
                             h0=0.,
                             h1=70,
                             dh=2.5)
    go_u.plot_solution_3D(_p)
    plt.show()
예제 #3
0
def test_thermal(force_recompute=False, filename='/home/poine/tmp/glider_opty_4d_thermal_{}.npz', exp_id='2'):
    if exp_id == '0':
        atm = go_u.AtmosphereWharingtonSym(radius=40., strength=-1)
    elif exp_id == '1':
        atm = go_u.AtmosphereWharingtonOval(radius=60., strength=-0.8)
    elif exp_id == '2':
        atm = go_u.atm2()
    #atm = go_u.AtmosphereArrayTest()

    _p = sgo4d.Planner( _obj_fun=sgo4d.obj_sum_z, _obj_grad=sgo4d.obj_grad_sum_z,
                        #_obj_fun=sgo4d.obj_final_z, _obj_grad=sgo4d.obj_grad_final_z,
                        _atm=atm, e0=-100, n0=0, u0=25, psi0=0,
                        _v_constraint = (7., 15.),
                        _e_constraint = (-120, 120),
                        _n_constraint = (-120, 120),
                        #_u_constraint = (   25, 100),
                        duration=40, hz=50., obj_scale=1.)

    #sgo4d.compute_or_load(atm, _p, force_recompute, filename, tol=1e-5, max_iter=4000, initial_guess=None)
    sgo4d.compute_or_load(atm, _p, force_recompute, filename.format(exp_id), tol=1e-4, max_iter=4000, initial_guess=None)
    print(f'last altitude {_p.sol_u[-1]} m')
    go_u.plot_solution_chronogram(_p); plt.savefig('plots/glider_4d_thermal_chrono.png')
    go_u.plot_solution_2D_en(_p); plt.savefig('plots/glider_4d_thermal_en.png')
    go_u.plot_solution_2D_nu(_p, n0=-40, n1=50, dn=5., e0=0., h0=0., h1=70, dh=2.5); plt.savefig('plots/glider_4d_thermal_nu.png')
    go_u.plot_solution_2D_eu(_p, contour_wz=True, e0=-40, e1=50, de=5., n0=0., h0=0., h1=70, dh=2.5); plt.savefig('plots/glider_4d_thermal_eu.png')
    go_u.plot_solution_3D(_p); plt.savefig('plots/glider_4d_thermal_3D.png')
    plt.show()
예제 #4
0
def plot_all(_p, n0, n1, dn, e0, e1, de, h0, h1, dh):
    go_u.plot_solution_chronogram(_p)
    go_u.plot_solution_2D_en(_p)
    go_u.plot_solution_2D_nu(_p,
                             n0=n0,
                             n1=n1,
                             dn=dn,
                             e0=e0,
                             h0=h0,
                             h1=h1,
                             dh=dh)
    go_u.plot_solution_3D(_p)
def main(force_recompute=False, filename='/tmp/glider2_opty.pkl'):
    atm = go_u.AtmosphereWharingtonSym(center=[0, 0, 0],
                                       radius=40,
                                       strength=1.)
    _p = Planner(_atm=atm, x0=-100, y0=-100, z0=5)
    _p.configure(tol=1e-7, max_iter=2000)
    _p.run()
    go_u.plot_solution_chronogram(_p)
    go_u.plot_solution_2D_en(_p)
    go_u.plot_solution_2D_nu(_p)
    go_u.plot_solution_3D(_p)
    plt.show()
def test_cc(force_recompute=False, filename='/home/poine/tmp/glider_opty_4d_cc{}.npz', exp='0'):
     if exp == '0': atm = go_u.atm4(strengths=(-0.6, -1.4, -0.8, -1.9))
     else: atm = go_u.atm4(strengths=(-0.6, -1.4, -0.8, -0.6))
     _p = sgo4d.Planner(_obj_fun=obj_cc, _obj_grad=obj_grad_cc,
                        _atm=atm, e0=-100, n0=0, u0=25, psi0=0,
                        _v_constraint = (7., 15.),
                        _e_constraint = (-150, 300),
                        _n_constraint = (-100, 100),
                        _u_constraint = (   23, 100),
                        duration=60, hz=20.)
     #sgo4d.compute_or_load(atm, _p, force_recompute, filename, tol=1e-5, max_iter=2000, initial_guess=None)
     sgo4d.compute_or_load(atm, _p, force_recompute, filename.format(exp), tol=1e-4, max_iter=1500, initial_guess=None)
     dists_to_wp = np.linalg.norm(np.vstack((_p.sol_e, _p.sol_n)).T - [ccg_e, ccg_n], axis=1)
     arrival_idx = np.argmax(dists_to_wp<10)
     go_u.plot_solution_chronogram(_p, max_idx=arrival_idx); plt.savefig(f'plots/glider_4d_cc{exp}_chrono.png')
     go_u.plot_solution_2D_en(_p, max_idx=arrival_idx); plt.savefig(f'plots/glider_4d_cc{exp}_en.png')
     go_u.plot_solution_3D(_p, max_idx=arrival_idx); plt.savefig(f'plots/glider_4d_cc{exp}_3D.png')
     plt.show()
예제 #7
0
def test_slope(force_recompute=False, filename='/home/poine/tmp/glider_opty_4d_slope.npz'):
    atm = go_u.AtmosphereRidgeSym()
    _p = sgo4d.Planner( #_obj_fun=sgo4d.obj_sum_z, _obj_grad=sgo4d.obj_grad_sum_z,
                        _obj_fun=sgo4d.obj_final_z, _obj_grad=sgo4d.obj_grad_final_z,
                        _atm=atm, e0=0, n0=0, u0=25, psi0=-np.pi/6,
                        _v_constraint = (7., 15.),
                        _n_constraint = (-100, 100),
                        _e_constraint = (-100, 100),
                        duration=50, hz=50.)
    sgo4d.compute_or_load(atm, _p, force_recompute, filename, tol=1e-4, max_iter=3000, initial_guess=None)
    #sgo4d.compute_or_load(atm, _p, force_recompute, filename, tol=1e-5, max_iter=2000, initial_guess=None)
    print(f'last altitude {_p.sol_u[-1]} m')
    go_u.plot_solution_chronogram(_p); plt.savefig('plots/glider_4d_slope_chrono.png')
    go_u.plot_solution_2D_en(_p, contour_wz=True) ; plt.savefig('plots/glider_4d_slope_en.png')#, n0=-40, n1=50, dn=5., e0=0., h0=0., h1=70, dh=2.5)
    go_u.plot_solution_2D_nu(_p, contour_wz=True, n0=-40, n1=50, dn=5., e0=0., h0=0., h1=70, dh=2.5); plt.savefig('plots/glider_4d_slope_nu.png')
    go_u.plot_solution_2D_eu(_p, contour_wz=True, e0=-40, e1=50, de=5., n0=0., h0=0., h1=70, dh=2.5); plt.savefig('plots/glider_4d_slope_eu.png')
    go_u.plot_solution_3D(_p); plt.savefig('plots/glider_4d_slope_3D.png') 
    plt.show()
def main(force_recompute=False, filename='/tmp/glider3_opty.pkl'):
    atm = go_u.AtmosphereCalmSym()
    _p = Planner( _obj_fun=obj_final_z, _obj_grad=obj_grad_final_z,
                  #_obj_fun=obj_sum_z, _obj_grad=obj_grad_sum_z,
                  #_atm=atm, x0=20, y0=0, z0=-35, psi0=np.pi,
                  _atm=atm, x0=10, y0=0, z0=-25, psi0=np.pi,
                  duration=120, hz=50.)
    filename = '/tmp/glider_better_opty.npz'
    if force_recompute:
        _p.configure(tol=1e-5, max_iter=200)
        _p.run()
        _p.prob.plot_objective_value()
        _p.prob.plot_trajectories(_p.solution)
        #_p.prob.plot_constraint_violations(_p.solution)
        _p.save_solution(filename)
    else:
        _p.load_solution(filename)

    go_u.plot_solution_2D_en(_p)
    go_u.plot_solution_2D_nu(_p, n0=-40, n1=50, dn=5., e0=0., h0=0., h1=70, dh=2.5)
    go_u.plot_solution_3D(_p)
    plt.show()
def main(force_recompute=False, filename='/tmp/glider_opty.pkl'):
    if 1:
        _atm = go_u.AtmosphereWharingtonSym(center=[0, 0, 0],
                                            radius=40,
                                            strength=1.)
        _atm.center = np.array([-20, 0, 0])
        _atm.strength = 2.
        _atm.radius = 20.
    else:
        _atm = go_u.AtmosphereRidgeSym()

    _p = Planner(_atm=_atm, x0=0, z0=20., psi0=np.pi /
                 2)  #obj_cc, obj_grad_cc)#_min_bank=np.deg2rad(-10))
    _p.configure(tol=1e-8, max_iter=1000)
    _p.run_or_load(filename, force_recompute)
    plot_run(_p)
    alt_final, alt_mean = _p.sol_z[-1], np.mean(_p.sol_z)
    txt = 'alt: final {:.1f} m, mean {:.1f}'.format(alt_final, alt_mean)
    go_u.plot_solution_chronogram(_p)
    go_u.plot_solution_2D_en(_p, title=txt)
    go_u.plot_solution_2D_nu(_p, title=txt)
    go_u.plot_solution_3D(_p, title=txt)
    plt.show()
예제 #10
0
def test_cst_wind(force_recompute=False,
                  filename='/tmp/glider_opty_4d_cst_wind.npz'):
    atm = go_u.AtmosphereCstWindSym([4, 0, 0])
    #obj_f, obj_grad = obj_circle, obj_grad_circle
    #obj_f, obj_grad = obj_min_bank, obj_grad_min_bank
    obj_f, obj_grad = obj_sum_z, obj_grad_sum_z
    _p = go4.Planner(_obj_fun=obj_f,
                     _obj_grad=obj_grad,
                     _atm=atm,
                     _n_constraint=(-40, 40),
                     _e_constraint=(-40, 40),
                     x0=10,
                     y0=0,
                     z0=-25,
                     psi0=np.pi,
                     duration=30,
                     hz=50.,
                     obj_scale=100.)
    initial_guess = initial_guess_circle(_p)
    go4.compute_or_load(atm,
                        _p,
                        force_recompute,
                        filename,
                        tol=1e-5,
                        max_iter=500,
                        initial_guess=initial_guess)
    go_u.plot_solution_chronogram(_p)
    go_u.plot_solution_2D_en(_p)
    go_u.plot_solution_2D_nu(_p,
                             n0=-40,
                             n1=50,
                             dn=5.,
                             e0=0.,
                             h0=0.,
                             h1=70,
                             dh=2.5)
    go_u.plot_solution_3D(_p)