1
0
mirror of https://gitlab.com/lander-team/air-prop-simulation.git synced 2025-07-23 06:31:37 +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

Binary file not shown.

Before

Width:  |  Height:  |  Size: 26 KiB

6
Project.toml Normal file
View File

@@ -0,0 +1,6 @@
[deps]
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
Measurements = "eff96d63-e80a-5855-80a2-b1b0885c5ab7"
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"

BIN
SSAD.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 16 KiB

View File

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

View File

@@ -1,7 +1,7 @@
using CSV using CSV
using DataFrames using DataFrames
using Plots using Plots
theme(:juno) theme(:ggplot2)
air = CSV.read("AirProp.csv", DataFrame) air = CSV.read("AirProp.csv", DataFrame)
@@ -9,15 +9,21 @@ f10 = CSV.read("AeroTech_F10.csv", DataFrame)
f15 = CSV.read("Estes_F15.csv", DataFrame) f15 = CSV.read("Estes_F15.csv", DataFrame)
g8 = CSV.read("AeroTech_G8ST.csv", DataFrame) g8 = CSV.read("AeroTech_G8ST.csv", DataFrame)
plot(
plot(air.Time, air.Thrust, label="Air Propulsion", ribbon=(zeros(length(df.Time)), min.(15, air.Uncertainty)), fillalpha=.1, legend=:topleft) air.Time,
air.Thrust,
label = "Air Propulsion",
ribbon = (zeros(length(df.Time)), min.(15, air.Uncertainty)),
fillalpha = 0.1,
legend = :topleft,
)
for (d, l) in [(f10, "F10"), (f15, "F15"), (g8, "G8ST")] for (d, l) in [(f10, "F10"), (f15, "F15"), (g8, "G8ST")]
plot!(d[!,"Time (s)"], d[!, "Thrust (N)"], label=l) plot!(d[!, "Time (s)"], d[!, "Thrust (N)"], label = l)
end end
title!("Propulsion Comparison") title!("Propulsion Comparison")
xlabel!("Time (s)") xlabel!("Time (s)")
ylabel!("Thrust (N)") ylabel!("Thrust (N)")
savefig("Presentation.png") savefig("prop_compare.png")

BIN
prop_compare.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

View File

@@ -1,13 +1,20 @@
# Air Prop Thrust # Air Prop Thrust
`readme auto generated`
![Thrust Over Time](ThrustCurve.png)
Total Impulse: 405.0 ± 40.0 N s Total Impulse: 405.0 ± 40.0 N s
Burn TIme: 20.30300000000183 s Burn TIme: 20.30300000000183 s
![Thrust Over Time](ThrustCurve.png)
More Data: More Data:
<table class="data-frame"><thead><tr><th></th><th>variable</th><th>mean</th><th>min</th><th>median</th><th>max</th><th>nmissing</th><th>eltype</th></tr><tr><th></th><th>Symbol</th><th>Quantity</th><th>Quantity</th><th>Quantity</th><th>Quantity</th><th>Int64</th><th>DataType</th></tr></thead><tbody><p>4 rows × 7 columns</p><tr><th>1</th><td>Thrust</td><td>20.0±2.0 N</td><td>0.0±0.0 N</td><td>21.1±4.7 N</td><td>21.1±4.7 N</td><td>0</td><td>Quantity{Measurement{Float64}, 𝐋 𝐌 𝐓^-2, FreeUnits{(N,), 𝐋 𝐌 𝐓^-2, nothing}}</td></tr><tr><th>2</th><td>Pressure</td><td>1.39e7±3.6e6 Pa</td><td>300000.0±1.1e6 Pa</td><td>1.38e7±3.9e6 Pa</td><td>2.9e7±2.1e6 Pa</td><td>0</td><td>Quantity{Measurement{Float64}, 𝐌 𝐋^-1 𝐓^-2, FreeUnits{(Pa,), 𝐌 𝐋^-1 𝐓^-2, nothing}}</td></tr><tr><th>3</th><td>Time</td><td>10.1515 s</td><td>0.0 s</td><td>10.1515 s</td><td>20.303 s</td><td>0</td><td>Quantity{Float64, 𝐓, FreeUnits{(s,), 𝐓, nothing}}</td></tr><tr><th>4</th><td>Mass</td><td>0.225±0.066 kg</td><td>0.005±0.018 kg</td><td>0.224±0.071 kg</td><td>0.468±0.053 kg</td><td>0</td><td>Quantity{Measurement{Float64}, 𝐌, FreeUnits{(kg,), 𝐌, nothing}}</td></tr></tbody></table> <table class="data-frame"><thead><tr><th></th><th>variable</th><th>mean</th><th>min</th><th>median</th><th>max</th><th>nmissing</th><th>eltype</th></tr><tr><th></th><th>Symbol</th><th>Quantity</th><th>Quantity</th><th>Quantity</th><th>Quantity</th><th>Int64</th><th>DataType</th></tr></thead><tbody><p>4 rows × 7 columns</p><tr><th>1</th><td>Thrust</td><td>20.0±2.0 N</td><td>0.0±0.0 N</td><td>21.1±4.7 N</td><td>21.1±4.7 N</td><td>0</td><td>Quantity{Measurement{Float64}, 𝐋 𝐌 𝐓^-2, FreeUnits{(N,), 𝐋 𝐌 𝐓^-2, nothing}}</td></tr><tr><th>2</th><td>Pressure</td><td>1.39e7±3.6e6 Pa</td><td>310000.0±1.1e6 Pa</td><td>1.38e7±3.9e6 Pa</td><td>2.9e7±2.1e6 Pa</td><td>0</td><td>Quantity{Measurement{Float64}, 𝐌 𝐋^-1 𝐓^-2, FreeUnits{(Pa,), 𝐌 𝐋^-1 𝐓^-2, nothing}}</td></tr><tr><th>3</th><td>Time</td><td>10.1515 s</td><td>0.0 s</td><td>10.1515 s</td><td>20.303 s</td><td>0</td><td>Quantity{Float64, 𝐓, FreeUnits{(s,), 𝐓, nothing}}</td></tr><tr><th>4</th><td>Mass</td><td>0.225±0.066 kg</td><td>0.005±0.018 kg</td><td>0.224±0.071 kg</td><td>0.468±0.053 kg</td><td>0</td><td>Quantity{Measurement{Float64}, 𝐌, FreeUnits{(kg,), 𝐌, nothing}}</td></tr></tbody></table>
## Comparison to Rocket Motors
![Propulsion Comparison](prop_compare.png)
https://www.thrustcurve.org/
`readme auto generated`