def __init__(self, rocket):

        self.rocket = rocket

        rocket.lunar_guidance_live() #calculate apollo guidance

        #create the problem instance
        time_init = [0.0, rocket.t[-1]]
        n = 12
        num_states    = self.num_states   = 5
        num_controls  = self.num_controls = 2
        max_iteration = 10

        prob = self.prob = Problem(time_init, [n], [num_states], [num_controls], max_iteration)
        prob.dynamics    = [self._og_dynamics]
        prob.cost        = self._og_cost
        prob.runing_cost = self._og_running_cost
        prob.equality    = self._og_equality
        prob.inequality  = self._og_inequality
        #prob.knot_states_smooth = [True]

        # generate intial guess of trajectory
        self._initial_guess_apollo() #assigns the initial guess trajectory - one with no thrust

        return
Exemple #2
0
# ========================
plt.close("all")
# Program Starting Point
time_init = [0.0, 0.3]
n = [50]
num_states = [3]
num_controls = [1]
max_iteration = 30

flag_savefig = True
savefig_file = "04_Goddard/04_0knot_"

# ------------------------
# set OpenGoddard class for algorithm determination
prob = Problem(time_init, n, num_states, num_controls, max_iteration)

# ------------------------
# create instance of operating object
# Nondimensionalization of parameters
obj = Rocket()

# ========================
# Initial parameter guess

# altitude profile
H_init = Guess.cubic(prob.time_all_section, 1.0, 0.0, 1.010, 0.0)
# Guess.plot(prob.time_all_section, H_init, "Altitude", "time", "Altitude")
# if(flag_savefig):plt.savefig(savefig_file + "guess_alt" + ".png")

# velocity
# ========================
plt.close("all")
plt.ion()
# Program Starting Point
time_init = [0.0, 300, 600]
n = [25, 25]
num_states = [3, 3]
num_controls = [1, 1]
max_iteration = 30

flag_savefig = True
savefig_file = "06_Rocket_Ascent/TwoStage_"

# ------------------------
# set OpenGoddard class for algorithm determination
prob = Problem(time_init, n, num_states, num_controls, max_iteration)

# ------------------------
# create instance of operating object
obj = Rocket()

unit_R = obj.Re
unit_v = np.sqrt(obj.GMe / obj.Re)
unit_m = obj.M0
unit_t = unit_R / unit_v
unit_T = unit_m * unit_R / unit_t**2
prob.set_unit_states_all_section(0, unit_R)
prob.set_unit_states_all_section(1, unit_v)
prob.set_unit_states_all_section(2, unit_m)
prob.set_unit_controls_all_section(0, unit_T)
prob.set_unit_time(unit_t)
Exemple #4
0
# ========================

# Program Starting Point
time_init = [0.0, 200, 800]
n = [20, 30]
num_states = [5, 5]
num_controls = [2, 2]
max_iteration = 90

flag_savefig = True
savefig_file = "./11_Polar_TSTO_Taiki/TSTO_"

# ------------------------
# set OpenGoddard class for algorithm determination
prob = Problem(time_init, n, num_states, num_controls, max_iteration)

# ------------------------
# create instance of operating object
obj = Rocket()

unit_R = obj.Re
unit_theta = 1
unit_V = np.sqrt(obj.GMe / obj.Re)
unit_m = obj.M0[0]
unit_t = unit_R / unit_V
unit_T = unit_m * unit_R / unit_t**2
prob.set_unit_states_all_section(0, unit_R)
prob.set_unit_states_all_section(1, unit_theta)
prob.set_unit_states_all_section(2, unit_V)
prob.set_unit_states_all_section(3, unit_V)
    def global_mesh_refine(self, prob = None, new_nodes = None, maxIterator = None, **kwargs):
        """ Refines the mesh. Does not modify current prob

        Parameters
        ----------
        new_nodes : type
            Description of parameter `new_nodes`.
        maxIterator : type
            Description of parameter `maxIterator`.
        **kwargs : type
            Description of parameter `**kwargs`.

        Returns
        -------
        type
            Description of returned object.

        """

        if prob is None:
            prob = self.prob
        #else refine the provided problem

        #get parameters from previous prob
        time_init = prob.time_knots()

        if new_nodes is None:
            new_nodes = [2*n for n in prob.nodes]

        num_of_states = prob.number_of_states
        num_of_controls = prob.number_of_controls

        if maxIterator is None:
            maxIterator = prob.maxIterator

        # construct new problem
        new_prob = Problem(time_init, new_nodes, num_of_states, num_of_controls, maxIterator, **kwargs)


        #assume the equations are the same as before
        new_prob.dynamics           = prob.dynamics
        new_prob.knot_states_smooth = prob.knot_states_smooth
        new_prob.cost               = prob.cost
        new_prob.cost_derivative    = prob.cost_derivative
        new_prob.equality           = prob.equality
        new_prob.inequality         = prob.inequality


        #add in the initial guesses - linear interp on previous solution
        t_previous = prob.time_update() #update total
        t_previous_section = prob.time

        t_new = new_prob.time_all_section
        t_new_section = new_prob.time

        for sec in range(len(new_nodes)):
            for i in range(num_of_states[sec]):
                new_prob.set_states(i, sec, np.interp(t_new_section[sec], t_previous_section[sec], prob.states(i, sec)))

            for i in range(num_of_controls[sec]):
                new_prob.set_controls(i, sec, np.interp(t_new_section[sec], t_previous_section[sec], prob.controls(i, sec)))

        return new_prob
plt.close("all")
plt.ion()
# Program Starting Point
time_init = [0.0, 10.0]
n = [100]
num_states = [3]
num_controls = [4]
max_iteration = 10

flag_savefig = True

savefig_dir = "10_Low_Thrust_Orbit_Transfer/"

# ------------------------
# set OpenGoddard class for algorithm determination
prob = Problem(time_init, n, num_states, num_controls, max_iteration)
obj = Orbiter()

# ========================
# Initial parameter guess
r_init = Guess.linear(prob.time_all_section, obj.r0, obj.rf)
# Guess.plot(prob.time_all_section, r_init, "r", "time", "r")
# if(flag_savefig):plt.savefig(savefig_dir + "guess_r" + savefig_add + ".png")

vr_init = Guess.linear(prob.time_all_section, obj.vr0, obj.vrf)
# Guess.plot(prob.time_all_section, vr_init, "vr", "time", "vr")
# if(flag_savefig):plt.savefig(savefig_dir + "guess_vr" + savefig_add + ".png")

vt_init = Guess.linear(prob.time_all_section, obj.vt0, obj.vtf)
# Guess.plot(prob.time_all_section, theta_init, "vt", "time", "vt")
# if(flag_savefig):plt.savefig(savefig_dir + "guess_vt" + savefig_add + ".png")
# ========================
plt.close("all")
# Program Starting Point
time_init = [0.0, 2.0]
n = [20]
num_states = [4]
num_controls = [1]
max_iteration = 50

flag_savefig = True
savefig_dir = "03_2d_simple_rocket/"

# ------------------------
# set OpenGoddard class for algorithm determination
prob = Problem(time_init, n, num_states, num_controls, max_iteration)
obj = Rocket()

# ========================
# Main Process
# Assign problem to SQP solver
prob.dynamics = [dynamics]
prob.knot_states_smooth = []
prob.cost = cost
prob.cost_derivative = None
prob.equality = equality
prob.inequality = inequality

prob.solve(obj)

# ========================
plt.close("all")
plt.ion()
# Program Starting Point
time_init = [0.0, 600.0]
n = [30]
num_states = [3]
num_controls = [1]
max_iteration = 10

flag_savefig = True

savefig_dir = "01_Brachistochrone/Tokyo_"

# ------------------------
# set OpenGoddard class for algorithm determination
prob = Problem(time_init, n, num_states, num_controls, max_iteration)
obj = Ball()
# obj.make_scales()

unit_x = 300000
unit_y = 100000
unit_t = 100
unit_v = unit_x / unit_t
prob.set_unit_states_all_section(0, unit_x)
prob.set_unit_states_all_section(1, unit_y)
prob.set_unit_states_all_section(2, unit_v)
prob.set_unit_controls_all_section(0, 1.0)
prob.set_unit_time(unit_t)

# ========================
# Initial parameter guess