102 lines
2.9 KiB
Julia
102 lines
2.9 KiB
Julia
"""
|
|
Maximum ΔV that a spacecraft can impulse for a given single time step
|
|
"""
|
|
function max_ΔV(duty_cycle::Float64,
|
|
num_thrusters::Int,
|
|
max_thrust::Float64,
|
|
tf::Float64,
|
|
t0::Float64,
|
|
mass::Float64)
|
|
return duty_cycle*num_thrusters*max_thrust*(tf-t0)/mass
|
|
end
|
|
|
|
"""
|
|
This function propagates the spacecraft forward in time 1 Sim-Flanagan step (of variable length of time),
|
|
applying a thrust in the center.
|
|
"""
|
|
function prop_one(ΔV_unit::Vector{Float64},
|
|
state::Vector{Float64},
|
|
duty_cycle::Float64,
|
|
num_thrusters::Int,
|
|
max_thrust::Float64,
|
|
mass::Float64,
|
|
mass_flow_rate::Float64,
|
|
μ::Float64,
|
|
time::Float64)
|
|
|
|
if norm(ΔV_unit) > 1.
|
|
throw(ErrorException("ΔV input is too high"))
|
|
end
|
|
halfway = laguerre_conway(state, μ, time/2)
|
|
halfway[4:6] += ΔV_unit * max_ΔV(duty_cycle, num_thrusters, max_thrust, time, 0., mass)
|
|
return laguerre_conway(halfway, μ, time/2), mass - mass_flow_rate*norm(ΔV_unit)*time
|
|
|
|
end
|
|
|
|
"""
|
|
A convenience function for using spacecraft. Note that this function outputs a sc instead of a mass
|
|
"""
|
|
function prop_one(ΔV_unit::Vector{Float64},
|
|
state::Vector{Float64},
|
|
craft::Sc,
|
|
μ::Float64,
|
|
time::Float64)
|
|
state, mass = prop_one(ΔV_unit, state, craft.duty_cycle, craft.num_thrusters, craft.max_thrust,
|
|
craft.mass, craft.mass_flow_rate, μ, time)
|
|
return state, Sc(mass, craft.mass_flow_rate, craft.max_thrust, craft.num_thrusters, craft.duty_cycle)
|
|
end
|
|
|
|
"""
|
|
This propagates over a given time period, with a certain number of intermediate steps
|
|
"""
|
|
function prop(ΔV_units::Vector{Vector{Float64}},
|
|
state::Vector{Float64},
|
|
duty_cycle::Float64,
|
|
num_thrusters::Int,
|
|
max_thrust::Float64,
|
|
mass::Float64,
|
|
mass_flow_rate::Float64,
|
|
μ::Float64,
|
|
time::Float64,
|
|
n::Int)
|
|
|
|
if length(ΔV_units) != n
|
|
throw(ExceptionError("Bad number of ΔV vectors"))
|
|
end
|
|
|
|
for i in 1:n
|
|
state, mass = prop_one(ΔV_units[i], state, duty_cycle, num_thrusters, max_thrust, mass,
|
|
mass_flow_rate, μ, time/n)
|
|
end
|
|
|
|
return state, mass
|
|
|
|
end
|
|
|
|
"""
|
|
The same function, using Scs
|
|
"""
|
|
function prop(ΔV_units::Vector{Vector{Float64}},
|
|
state::Vector{Float64},
|
|
craft::Sc,
|
|
μ::Float64,
|
|
time::Float64,
|
|
n::Int)
|
|
|
|
if length(ΔV_units) != n
|
|
throw(ExceptionError("Bad number of ΔV vectors"))
|
|
end
|
|
|
|
states = state'
|
|
masses = craft.mass
|
|
|
|
for i in 1:n
|
|
state, craft = prop_one(ΔV_units[i], state, craft, μ, time/n)
|
|
states = [states; state']
|
|
masses = [masses, craft.mass]
|
|
end
|
|
|
|
return states, masses
|
|
|
|
end
|