Example #1
0
def T2DS1ME() :
    
    print("Testing traj2d with one stage with mixed engines (T2DS1ME)")
    
    tname = "T2DS1ME"
    tfile = ksp.pthut(tname + ".pkl")
    do_generate = not os.access(tfile, os.F_OK)

    stage_1 = ksp.Stage()
    stage_1.loadJSON(ksp.pthut(tname + "_stage1.json"))
    # stage_1.dumpInfo( )

    def fthrottle( t, y ) :
        return 1.0
    def falpha( t, y, flyer ) :
        m, r, th, vr, om = y
        vth = om/r
        if r < (flyer.R+7.5E3) :
            n = (1.0, 0.0)
        elif vth == 0.0 :
            n = (1.0, 0.0)
        else :
            v,n = mpm.v_and_dir(y)
        return n
    
    flyer = ksp.FlyingStage(stage_1, "Stage 1", "Kerbin", fthrottle, falpha)
    flyer.launch( )
    # Fly until crash
    flyer.flyTo( 30000 )

    if do_generate :
        with open( tfile, 'wb' ) as f :
            pickle.dump( flyer.soln, f )
    else :
        with open( tfile, 'rb' ) as f :
            soln_compare = pickle.load( f )
            cmp.compare_datasets(flyer.soln, soln_compare, tolfrac=1E-8)
        print("SUCCESS")

    if True :
        import matplotlib
        import matplotlib.pyplot as plt

        fig, ax = plt.subplots()

        plots = [flyer.sample()]
        plot_opts = [{"marker":"o"}]

        bbox = mpt.square_plot_bounds(plots)
        
        plots.append(mpt.sample_circle(flyer.R, 100))
        plot_opts.append(None)
        plots.append(mpt.sample_circle(flyer.R+70, 100))
        plot_opts.append(None)

        mpt.square_plots(ax, plots, bbox, plot_opts)
        
        plt.show()

        flyer.dumpTraj( )    
Example #2
0
File: run.py Project: jgrot/grotlib
        n = (1.0, 0.0)
        #else :
        #    v,n = mpm.v_and_dir(y)
        return n

    flyer = ksp.FlyingStage(s1, "Stage 1", "Kerbin", fthrottle, falpha)
    flyer.launch()
    # Fly until crash
    flyer.flyTo(30000)

    import matplotlib
    import matplotlib.pyplot as plt

    fig, ax = plt.subplots()

    plots = [flyer.sample()]
    plot_opts = [{"marker": "o"}]

    bbox = mpt.square_plot_bounds(plots)

    plots.append(mpt.sample_circle(flyer.R, 100))
    plot_opts.append(None)
    plots.append(mpt.sample_circle(flyer.R + 70, 100))
    plot_opts.append(None)

    mpt.square_plots(ax, plots, bbox, plot_opts)

    plt.show()

    flyer.dumpTraj()
Example #3
0
def T2DS2ME() :
    # KSP Flight
    #
    # 50s stage
    # 30km track orbit
    #
    # Max alt:
    # Crash Time:
    #
    print("Testing traj2d with two stages with mixed engines (T2DS2ME)")
    
    tname = "T2DS2ME"
    tfile = ksp.pthut(tname + ".pkl")
    do_generate = not os.access(tfile, os.F_OK)

    stage_1 = ksp.Stage()
    stage_1.loadJSON(ksp.pthut(tname + "_stage1.json"))
    # stage_1.dumpInfo( )

    stage_2 = ksp.Stage()
    stage_2.loadJSON(ksp.pthut(tname + "_stage2.json"))
    # stage_2.dumpInfo( )
    
    def fthrottle( t, y ) :
        return 1.0
    def falpha( t, y, flyer ) :
        r = y[1]
        if r < (flyer.R+30.0E3) :
            n = (1.0, 0.0)
        else :
            v, n = mpm.v_and_dir(y)
        return n
    
    fly_s1 = ksp.FlyingStage( stage_1, "Stage 1", "Kerbin", fthrottle, falpha )
    fly_s1.launch( )
    fly_s1.flyTo( 84.00 )

    fly_s2 = ksp.FlyingStage( stage_2, "Stage 2",  "Kerbin", fthrottle, falpha )
    fly_s2.launch( sm1 = fly_s1, t0 = 84.00 )
    fly_s2.flyTo( 30000 )

    t = 0.0
    DV = []
    while t <= fly_s2.solnt[-1] :
        Y, crashed, flyer = fly_s2.flyTo( t )
        m, r, th, vr, om = Y
        craft_asl_dvremain = flyer.dv_at_m( m, ksp.C_p0 )
        craft_dvremain = flyer.dv_at_m( m, flyer.fpress.call(r-flyer.R)[0] )
        stage_asl_dvremain = flyer.stage.dv_at_m( m, ksp.C_p0 )
        DV.append( (craft_asl_dvremain, craft_dvremain, stage_asl_dvremain) )
        t += 10
    
    if do_generate :
        with open( tfile, 'wb' ) as f :
            data = {
                "stage1" : fly_s1.soln,
                "stage2" : fly_s2.soln,
                "DV"     : DV
            }
            pickle.dump( data, f )
    else :
        with open( tfile, 'rb' ) as f :
            soln_compare = pickle.load( f )
            cmp.compare_datasets( fly_s1.soln, soln_compare["stage1"], tolfrac=1E-3 )
            cmp.compare_datasets( fly_s2.soln, soln_compare["stage2"], tolfrac=1E-3 )
            cmp.compare_datasets( DV, soln_compare["DV"], tolfrac=1E-3 )
        print("SUCCESS")

    if True :
        import matplotlib
        import matplotlib.pyplot as plt

        fig, ax = plt.subplots()
        
        plots = [fly_s2.sample(t0=0.0, dt=10.0)]
        plot_opts = [{"marker":"o"}]
        
        bbox = mpt.square_plot_bounds(plots)
        
        plots.append(mpt.sample_circle(fly_s2.R, 100))
        plot_opts.append(None)
        plots.append(mpt.sample_circle(fly_s2.R+70, 100))
        plot_opts.append(None)

        mpt.square_plots(ax, plots, bbox, plot_opts)
        
        plt.show()

        flyer.dumpTraj()
Example #4
0
        retro = (-n[0], -n[1])
        return retro

    fs2 = ksp.FlyingStage(s2, "fs2", "Mun", fthrottle, fthustdir)
    fs2_h0 = 30000.0  # meters
    fs2_r0 = mun_r_m + fs2_h0
    fs2_v0 = ksp.orbitV("Mun", (fs2_h0, "m"))
    y_init = [s2.m0_kg, fs2_r0, 0.0, 0.0, fs2_v0 / fs2_r0]
    fs2.launch(y_init)

    tend = 100 * 60.0
    dt = 5.0

    # Plot trajectory
    fs2_XY = fs2.sample(0.0, tend, dt)
    plots.append(fs2_XY)
    plot_opts.append({"marker": "o"})
    # Bbox surrounds fs2 traj
    bbox = mpt.square_plot_bounds([fs2_XY])

    # Dump trajectory
    fs2.dumpTraj(0.0, tend, dt)

    # Plot everything
    if len(plots) > 0:
        fig, ax = plt.subplots()
        # bbox = mpt.square_plot_bounds(plots)
        mpt.square_plots(ax, plots, bbox, plot_opts)

        plt.show()