1
0
mirror of https://gitlab.com/lander-team/air-prop-simulation.git synced 2025-07-23 22:51:35 +00:00

code cleanup

This commit is contained in:
2021-04-22 13:08:49 -07:00
parent 81d689f4b8
commit 3a462bde38
8 changed files with 65 additions and 35 deletions

View File

@@ -1,14 +1,12 @@
using Unitful
using DataFrames
using Plots
theme(:ggplot2);
using UnitfulRecipes
theme(:ggplot2);
using CSV
using Measurements
using Measurements: value, uncertainty
using Printf
# Tank https://www.amazon.com/Empire-Paintball-BASICS-Pressure-Compressed/dp/B07B6M48SR/
V = (85 ± 5)u"inch^3"
P0 = (4200.0 ± 300)u"psi"
@@ -27,15 +25,13 @@ P_amb = (1 ± 0.2)u"atm"
R = 287.05u"J/(kg * K)"
T = (300 ± 20)u"K"
# Setting up while loop
t = 0.0u"s"
P = P0 |> u"Pa"
M = V * (P / (R * T)) |> u"kg"
ts = 1u"ms"
df = DataFrame(Thrust=(0 ± 0)u"N", Pressure=P, Time=t, Mass=M)
df = DataFrame(Thrust = (0 ± 0)u"N", Pressure = P, Time = t, Mass = M)
while M > 0.005u"kg"
# while t < 30u"s"
# Calculate what is leaving tank
P = minimum([P, Pmax])
ve = sqrt((2 * γ / (γ - 1)) * R * T * (1 - P_amb / P)^((γ - 1) / γ)) |> u"m/s"
@@ -44,65 +40,80 @@ while M > 0.005u"kg"
Thrust = * ve + a_nozzle * (P - P_amb) |> u"N"
# Calculate what is still in the tank
M = M - * ts |> u"kg"
P = (M * R * T) / V |> u"Pa"
t = t + ts
df_step = DataFrame(Thrust=Thrust, Pressure=P, Time=t, Mass=M)
df_step = DataFrame(Thrust = Thrust, Pressure = P, Time = t, Mass = M)
append!(df, df_step)
end
final_time = t |> u"s"
impulse = sum(df.Thrust) * ts |> u"N*s"
println("---------------------------\n\n\n\n")
println("Total Impulse: ", impulse)
println("Burn Time: ", t)
println("Mass Total: ", Wtank + Wsolenoid + maximum(df.Mass))
print(describe(df))
thrust_values = df.Thrust .|> ustrip .|> value
thrust_uncertainties = df.Thrust .|> ustrip .|> uncertainty
thrust_uncertainties = df.Thrust .|> ustrip .|> uncertainty
plot(df.Time .|> ustrip, thrust_values,
title="Thrust Over Time",
ribbon=(thrust_uncertainties, thrust_uncertainties),
fillalpha=.2,label="Thrust",
xlabel="Time (s)",
ylabel="Thrust (N)",
palette=:leonardo,
)
plot(
df.Time .|> ustrip,
thrust_values,
title = "Thrust Over Time",
ribbon = (thrust_uncertainties, thrust_uncertainties),
fillalpha = 0.2,
label = "Thrust",
xlabel = "Time (s)",
ylabel = "Thrust (N)",
palette = :leonardo,
)
out = DataFrame(Thrust=thrust_values, Uncertainty=thrust_uncertainties, Time=df.Time .|> u"s" .|> ustrip)
CSV.write("AirProp.csv",out)
out = DataFrame(
Thrust = thrust_values,
Uncertainty = thrust_uncertainties,
Time = df.Time .|> u"s" .|> ustrip,
)
CSV.write("AirProp.csv", out)
### Save data to readme.md
savefig("ThrustCurve.png")
include("prop_compare.jl")
b = IOBuffer();
t = TextDisplay(b);
display(t, "text/html", describe(df));
table = String(take!(b)); # https://stackoverflow.com/a/60443621/8774114
t = TextDisplay(b);
display(t, "text/html", describe(df));
table = String(take!(b)); # https://stackoverflow.com/a/60443621/8774114
readme = Printf.@sprintf """
# Air Prop Thrust
`readme auto generated, run air_prop_sim.jl to recreate.`
![Thrust Over Time](ThrustCurve.png)
Total Impulse: %s
Burn TIme: %s
![Thrust Over Time](ThrustCurve.png)
More Data:
%s
`readme auto generated`
## Comparison to Rocket Motors
![Propulsion Comparison](prop_compare.png)
https://www.thrustcurve.org/
""" impulse final_time table
write("readme.md", readme);
write("readme.md", readme);