I THINK that the single shooter is ok. I can always improve it later

This commit is contained in:
rconnorjohnstone
2021-06-17 23:36:50 -06:00
parent 2c39c34f01
commit 966f954528
13 changed files with 170 additions and 61 deletions

View File

@@ -1,12 +1,12 @@
"""
Maximum ΔV that a spacecraft can impulse for a given single time step
"""
function max_ΔV(duty_cycle::Float64,
function max_ΔV(duty_cycle::T,
num_thrusters::Int,
max_thrust::Float64,
tf::Float64,
t0::Float64,
mass::Float64)
max_thrust::T,
tf::T,
t0::T,
mass::S) where {T <: Real, S <: Real}
return duty_cycle*num_thrusters*max_thrust*(tf-t0)/mass
end
@@ -14,33 +14,49 @@ 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},
function prop_one(ΔV::Vector{T},
state::Vector{S},
duty_cycle::Float64,
num_thrusters::Int,
max_thrust::Float64,
mass::Float64,
mass::S,
mass_flow_rate::Float64,
μ::Float64,
time::Float64)
time::Float64) where {T <: Real, S <: Real}
if norm(ΔV_unit) > 1.
throw(ErrorException("ΔV input is too high"))
mag, α, β = ΔV
if mag > 1 || mag < 0
throw(ErrorException("ΔV input is too high: $mag"))
elseif α > π || α < -π
throw(ErrorException("α angle is incorrect: $α"))
elseif β > π/2 || β < -π/2
throw(ErrorException("β angle is incorrect: "))
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
thrust_rθh = mag * [cos(β)*sin(α), cos(β)*cos(α), sin(β)]
a,e,i,Ω,ω,ν = xyz_to_oe(state, μ)
θ = ω+ν
,,ci,si,, = cos(Ω),sin(Ω),cos(i),sin(i),cos(θ),sin(θ)
DCM = [*-*ci* -*-*ci* *si;
*+*ci* -*+*ci* -*si;
si* si* ci]
ΔV = DCM*thrust_rθh
thrust = max_ΔV(duty_cycle, num_thrusters, max_thrust, time, 0., mass) * ΔV
halfway = laguerre_conway(state, μ, time/2) + [0., 0., 0., thrust[1], thrust[2], thrust[3]]
return laguerre_conway(halfway, μ, time/2), mass - mass_flow_rate*norm(ΔV)*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},
function prop_one(ΔV_unit::Vector{T},
state::Vector{S},
craft::Sc,
μ::Float64,
time::Float64)
time::Float64) where {T <: Real,S <: Real}
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)
@@ -49,7 +65,7 @@ end
"""
This propagates over a given time period, with a certain number of intermediate steps
"""
function prop(ΔV_units::Vector{Vector{Float64}},
function prop(ΔVs::Matrix{T},
state::Vector{Float64},
duty_cycle::Float64,
num_thrusters::Int,
@@ -57,15 +73,13 @@ function prop(ΔV_units::Vector{Vector{Float64}},
mass::Float64,
mass_flow_rate::Float64,
μ::Float64,
time::Float64,
n::Int)
time::Float64) where T <: Real
if length(ΔV_units) != n
throw(ExceptionError("Bad number of ΔV vectors"))
end
if size(ΔVs)[2] != 3 throw(ErrorException("ΔV input is wrong size")) end
n = size(ΔVs)[i]
for i in 1:n
state, mass = prop_one(ΔV_units[i], state, duty_cycle, num_thrusters, max_thrust, mass,
state, mass = prop_one(ΔVs[i,:], state, duty_cycle, num_thrusters, max_thrust, mass,
mass_flow_rate, μ, time/n)
end
@@ -76,22 +90,20 @@ end
"""
The same function, using Scs
"""
function prop(ΔV_units::Vector{Vector{Float64}},
function prop(ΔVs::AbstractArray{T},
state::Vector{Float64},
craft::Sc,
μ::Float64,
time::Float64,
n::Int)
time::Float64) where T <: Real
if length(ΔV_units) != n
throw(ExceptionError("Bad number of ΔV vectors"))
end
if size(ΔVs)[2] != 3 throw(ErrorException("ΔV input is wrong size")) end
n = size(ΔVs)[1]
states = state'
masses = craft.mass
for i in 1:n
state, craft = prop_one(ΔV_units[i], state, craft, μ, time/n)
state, craft = prop_one(ΔVs[i,:], state, craft, μ, time/n)
states = [states; state']
masses = [masses, craft.mass]
end