from Tkinter import *
import tkMessageBox
import matplotlib.pyplot as pypt
rocket = Tk()
rocket.title("Rocket Projectotron 9000")
rocket.geometry("1000x180")
LabelMassFullRaw = Label(rocket, text="Mass of Full Rocket")
LabelMassFullRaw.pack()
LabelMassFullRaw.place(bordermode=OUTSIDE, height=25, width=110)
EntryMassFullRaw = Entry(rocket)
EntryMassFullRaw.pack()
EntryMassFullRaw.place(bordermode=OUTSIDE, height=25, width=75, x=120)
LabelMassEmptyRaw = Label(rocket, text="Mass of Empty Rocket")
LabelMassEmptyRaw.pack()
LabelMassEmptyRaw.place(bordermode=OUTSIDE, height=25, width=120, x=230)
EntryMassEmptyRaw = Entry(rocket)
EntryMassEmptyRaw.pack()
EntryMassEmptyRaw.place(bordermode=OUTSIDE, height=25, width=75, x=230+120)
LabelBurnTimeRaw = Label(rocket, text="Burn Time")
LabelBurnTimeRaw.pack()
LabelBurnTimeRaw.place(bordermode=OUTSIDE, height=25, width=100, x=230+150+120)
EntryBurnTimeRaw = Entry(rocket)
EntryBurnTimeRaw.pack()
EntryBurnTimeRaw.place(bordermode=OUTSIDE, height=25, width=75, x=230+120+150+80)
LabelDragCoRaw = Label(rocket, text = "Drag Coefficient")
LabelDragCoRaw.pack()
LabelDragCoRaw.place(bordermode=OUTSIDE, height=25, width=120, x=230+120+150+80+120)
EntryDragCoRaw = Entry(rocket)
EntryDragCoRaw.pack()
EntryDragCoRaw.place(bordermode=OUTSIDE, height=25, width=75, x=230+120+150+80+120+105)
LabelXSecAreaRaw = Label(rocket, text="Cross Sectional Area")
LabelXSecAreaRaw.pack()
LabelXSecAreaRaw.place(bordermode=OUTSIDE, height=25, width=120, y=30)
EntryXSecAreaRaw = Entry(rocket)
EntryXSecAreaRaw.pack()
EntryXSecAreaRaw.place(bordermode=OUTSIDE, height=25, width=75, x=120, y=30)
LabelThrustRaw = Label(rocket, text = "Thrust Force (N)")
LabelThrustRaw.pack()
LabelThrustRaw.place(bordermode=OUTSIDE, height=25, width=110, x=120+150, y=30)
EntryThrustRaw = Entry(rocket)
EntryThrustRaw.pack()
EntryThrustRaw.place(bordermode=OUTSIDE, height=25, width=75, x=120+150+80, y=30)
LabelTempRaw = Label(rocket, text="Temperature (deg C)")
LabelTempRaw.pack()
LabelTempRaw.place(bordermode=OUTSIDE, height=25, width = 120, x=120+150+80+110, y=30)
EntryTempRaw = Entry(rocket)
EntryTempRaw.pack()
EntryTempRaw.place(bordermode=OUTSIDE, height=25, width=75, x=120+150+80+110+120, y=30)
LabelTimeRaw = Label(rocket, text="Time Interval")
LabelTimeRaw.pack()
LabelTimeRaw.place(bordermode=OUTSIDE, height=25, width=100, x=120+150+80+110+120+140, y=30)
TimeVar1 = 1
TimeVar2 = 0.5
TimeVar3 = 0.25
MasterTimeVarRaw=StringVar()
RBut1 = Radiobutton(rocket, text="1 sec", variable=MasterTimeVarRaw, value=TimeVar1)
RBut1.place(bordermode=OUTSIDE, height=25, width=75, x=120+150+80+110+120+140+90, y=30)
RBut2 = Radiobutton(rocket, text="1/2 sec", variable=MasterTimeVarRaw, value=TimeVar2)
RBut2.place(bordermode=OUTSIDE, height=25, width=75, x=120+150+80+110+120+140+95, y=50)
RBut3 = Radiobutton(rocket, text="1/4 sec", variable=MasterTimeVarRaw, value=TimeVar3)
RBut3.place(bordermode=OUTSIDE, height=25, width=75, x=120+150+80+110+120+140+95, y=70)
def RocketFunction():
try:
EntryMassFull=EntryMassFullRaw.get()
EntryMassFull=float(EntryMassFull)
except ValueError:
tkMessageBox.showinfo("Error!", "The input provided for Mass of Full Rocket is not acceptable. Please check input values and try again.")
try:
EntryMassEmpty=EntryMassEmptyRaw.get()
EntryMassEmpty=float(EntryMassEmpty)
except ValueError:
tkMessageBox.showinfo("Error!", "The input provided for Mass of Empty Rocket is not acceptable. Please check input values and try again.")
try:
EntryBurnTime=EntryBurnTimeRaw.get()
EntryBurnTime=float(EntryBurnTime)
except ValueError:
tkMessageBox.showinfo("Error!", "The input provided for Burn Time is not acceptable. Please check input values and try again.")
try:
EntryDragCo=EntryDragCoRaw.get()
EntryDragCo=float(EntryDragCo)
except ValueError:
tkMessageBox.showinfo("Error!", "The input provided for Drag Coefficient is not acceptable. Please check input values and try again.")
try:
EntryXSecArea=EntryXSecAreaRaw.get()
EntryXSecArea=float(EntryXSecArea)
except ValueError:
tkMessageBox.showinfo("Error!", "The input provided for Cross Sectional Area is not acceptable. Please check input values and try again.")
try:
EntryThrust=EntryThrustRaw.get()
EntryThrust=float(EntryThrust)
except ValueError:
tkMessageBox.showinfo("Error!", "The input provided for Thrust is not acceptable. Please check input values and try again.")
try:
EntryTemp=EntryTempRaw.get()
EntryTemp=float(EntryTemp)
except ValueError:
tkMessageBox.showinfo("Error!", "The input provided for Temperature is not acceptable. Please check input values and try again.")
MasterTimeVar=MasterTimeVarRaw.get()
MasterTimeVar=float(MasterTimeVar)
fullburn=((EntryMassFull-EntryMassEmpty)/EntryBurnTime)
groundtemp = EntryTemp + 273.15
tx = 1
speednought = 0
speed = 0
altitude = 0.0001
altitudenought = 0
times = [0]
masses = [EntryMassFull]
speeds = [0]
altitudes =[0]
#Lift-off to Throttle-Down
while (tx*MasterTimeVar) <= EntryBurnTime and altitude > 0:
x = -1*(((tx*MasterTimeVar)*(fullburn)) - EntryMassFull)
acceleration = (EntryThrust-x*9.81)/x
speed = speednought + ((acceleration)*(MasterTimeVar))
altitude = altitudenought + (speed*(MasterTimeVar))
#removed print
times.append((tx*MasterTimeVar))
masses.append(x)
speeds.append(speed)
altitudes.append(altitude)
tx = tx + 1
speednought = speed
altitudenought = altitude
if altitude < 0:
tkMessageBox.showinfo("Error!", "Your rocket could not fly with the given parameters!")
break
else:
continue
#Free-Fall before Terminal Velocity
airpressure = (101.325 *(1-((altitude*0.0065)/groundtemp))**((9.81*0.0289644)/(8.31447*0.0065)))
airtemperature = groundtemp - (altitude*0.0065)
airdensity = ((airpressure*.0289644)/(8.31447*airtemperature))
speedterminal = ((2*EntryMassEmpty*9.81)/(airdensity*EntryXSecArea*EntryDragCo))**(0.5)
while altitude > 0:
if speed > -speedterminal:
(tx*MasterTimeVar) == EntryBurnTime
x = (EntryMassEmpty)
acceleration = (0/x)
speed = speednought + ((acceleration-9.81)*(MasterTimeVar))
altitude = altitudenought + (speed*(MasterTimeVar))
#removed print
times.append((tx*MasterTimeVar))
masses.append(x)
speeds.append(speed)
altitudes.append(altitude)
tx = tx + 1
speednought = speed
altitudenought = altitude
airpressure = (101.325 *(1-((altitude*0.0065)/groundtemp))**((9.81*0.0289644)/(8.31447*0.0065)))
airtemperature = groundtemp - (altitude*0.0065)
airdensity = ((airpressure*.0289644)/(8.31447*airtemperature))
speedterminal = ((2*EntryMassEmpty*9.81)/(airdensity*EntryXSecArea*EntryDragCo))**(0.5)
#removed print
continue
#Free-Fall AFTER Terminal Velocity up to Landing
if speed <= -speedterminal:
(tx*MasterTimeVar) == EntryBurnTime
x = (EntryMassEmpty)
acceleration = (0/x)
#speed is now -speedterminal
altitude = altitudenought + (-speedterminal*(MasterTimeVar))
#removed print
times.append((tx*MasterTimeVar))
masses.append(x)
speeds.append(-speedterminal)
altitudes.append(altitude)
tx = tx + 1
altitudenought = altitude
airpressure = (101.325 *(1-((altitude*0.0065)/groundtemp))**((9.81*0.0289644)/(8.31447*0.0065)))
airtemperature = groundtemp - (altitude*0.0065)
airdensity = ((airpressure*.0289644)/(8.31447*airtemperature))
speedterminal = ((2*EntryMassEmpty*9.81)/(airdensity*EntryXSecArea*EntryDragCo))**(0.5)
#removed print
continue
#removed print
tkMessageBox.showinfo('Flight Duration in seconds =', (tx*MasterTimeVar))
tkMessageBox.showinfo("Reminder", "Close the graph to run different values. The current graph can be saved by clicking on the save icon on the graph")
#Display Altitude vs Time Graph
pypt.plot(times, masses, "b-", times, speeds, "r-", times, altitudes, "g-")
pypt.show()
GoButton = Button(rocket, text="Compute", command=RocketFunction)
GoButton.place(bordermode=OUTSIDE, height=50, width=100, x=450, y=100)
rocket.mainloop()