Ejemplo n.º 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( )    
Ejemplo n.º 2
0
Archivo: run.py Proyecto: jgrot/grotlib
    s1.loadJSON("TestLFE1.json")
    s1.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)
        #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))
Ejemplo n.º 3
0
    args = parser.parse_args()

    if args.command == "inst":
        for line in instructions:
            print(line)
        exit(0)

    if args.command == "test":

        case_data = None
        with open(args.case_file, "rt") as f:
            case_data = json.load(f)

        stage = ksp.Stage()
        stage.loadJSON(ksp.pthdat("drag_tests/" + case_data["stage file"]))
        flyer = ksp.FlyingStage(stage, "stage", "Kerbin", fthrottle, falpha)

        htarget = case_data["htarget"]
        crash_time = case_data["crash time"]

        itrial = 1

        def trial(X):
            global itrial

            if X[0] < 1.0 or \
               X[0] > 10.0 or \
               X[1] < 5.0 or \
               X[1] > 200.0 or \
               X[2] < 0.01 or \
               X[2] > 100.0 :
Ejemplo n.º 4
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()
Ejemplo n.º 5
0
Archivo: run.py Proyecto: jgrot/grotlib
    t2 = 400.0
    t3 = 10000.0

    def fthrottle_s1(t, y):
        return 1.0

    def falpha_s1(t, y, flyer):
        m, r, th, vr, om = y
        # vth = om/r
        #if r < (flyer.R+7.5E3) :
        n = (1.0, 0.0)
        #else :
        #    v,n = mpm.v_and_dir(y)
        return n

    flyer_s1 = ksp.FlyingStage(s1, "Stage 1", "Kerbin", fthrottle_s1,
                               falpha_s1)
    flyer_s1.launch()
    flyer_s1.flyTo(t1)

    def fthrottle_s2(t, y):
        return 1.0

    def falpha_s2(t, y, flyer):
        m, r, th, vr, om = y
        # vth = om/r
        v, n = mpm.v_and_dir(y)

        return n

    flyer_s2 = ksp.FlyingStage(s2, "Stage 2", "Kerbin", fthrottle_s2,
                               falpha_s2)
Ejemplo n.º 6
0
        h = r - 200E3

        vtarget = h / 10.0

        if t < 5.0:
            # Initial kick out of circ orbit
            return 0.1
        else:
            return min(1.0, 0.01 * (max(v - vtarget, 0.0)))

    def fthustdir(t, y, fs):
        v, n = mpm.v_and_dir(y)
        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])
Ejemplo n.º 7
0
        if args.nodd:
            # Put transition at Mach 100 effectively turning this off.
            ksp.dd = ksp.DragDivergence(3.0, 10.0, 100.0)

        case_data = None
        with open(args.case_file, "rt") as f:
            case_data = json.load(f)

        stage = ksp.Stage()
        try:
            stage.loadJSON(case_data["stage file"])
        except:
            stage.loadJSON(ksp.pthdat("drag_tests/" + case_data["stage file"]))

        flyer = ksp.FlyingStage(stage, "stage", "Kerbin", fthrottle,
                                fthrustdir)

        htarget = case_data["htarget"]
        crash_time = case_data["crash time"]

        itrial = 1

        def trial(X):

            global itrial

            if X[0] < 1E-3:
                return math.inf

            stage.dragco = X[0]
            # flyer.launch([flyer.stage.me_kg, flyer.R + htarget, 0.0, 0.0, flyer.body_omega])