fork download
  1.  
  2. from Tkinter import *
  3.  
  4. import tkMessageBox
  5.  
  6. import matplotlib.pyplot as pypt
  7.  
  8. rocket = Tk()
  9. rocket.title("Rocket Projectotron 9000")
  10. rocket.geometry("1000x180")
  11.  
  12. LabelMassFullRaw = Label(rocket, text="Mass of Full Rocket")
  13. LabelMassFullRaw.pack()
  14. LabelMassFullRaw.place(bordermode=OUTSIDE, height=25, width=110)
  15.  
  16. EntryMassFullRaw = Entry(rocket)
  17. EntryMassFullRaw.pack()
  18. EntryMassFullRaw.place(bordermode=OUTSIDE, height=25, width=75, x=120)
  19.  
  20. LabelMassEmptyRaw = Label(rocket, text="Mass of Empty Rocket")
  21. LabelMassEmptyRaw.pack()
  22. LabelMassEmptyRaw.place(bordermode=OUTSIDE, height=25, width=120, x=230)
  23.  
  24. EntryMassEmptyRaw = Entry(rocket)
  25. EntryMassEmptyRaw.pack()
  26. EntryMassEmptyRaw.place(bordermode=OUTSIDE, height=25, width=75, x=230+120)
  27.  
  28. LabelBurnTimeRaw = Label(rocket, text="Burn Time")
  29. LabelBurnTimeRaw.pack()
  30. LabelBurnTimeRaw.place(bordermode=OUTSIDE, height=25, width=100, x=230+150+120)
  31.  
  32. EntryBurnTimeRaw = Entry(rocket)
  33. EntryBurnTimeRaw.pack()
  34. EntryBurnTimeRaw.place(bordermode=OUTSIDE, height=25, width=75, x=230+120+150+80)
  35.  
  36. LabelDragCoRaw = Label(rocket, text = "Drag Coefficient")
  37. LabelDragCoRaw.pack()
  38. LabelDragCoRaw.place(bordermode=OUTSIDE, height=25, width=120, x=230+120+150+80+120)
  39.  
  40. EntryDragCoRaw = Entry(rocket)
  41. EntryDragCoRaw.pack()
  42. EntryDragCoRaw.place(bordermode=OUTSIDE, height=25, width=75, x=230+120+150+80+120+105)
  43.  
  44. LabelXSecAreaRaw = Label(rocket, text="Cross Sectional Area")
  45. LabelXSecAreaRaw.pack()
  46. LabelXSecAreaRaw.place(bordermode=OUTSIDE, height=25, width=120, y=30)
  47.  
  48. EntryXSecAreaRaw = Entry(rocket)
  49. EntryXSecAreaRaw.pack()
  50. EntryXSecAreaRaw.place(bordermode=OUTSIDE, height=25, width=75, x=120, y=30)
  51.  
  52. LabelThrustRaw = Label(rocket, text = "Thrust Force (N)")
  53. LabelThrustRaw.pack()
  54. LabelThrustRaw.place(bordermode=OUTSIDE, height=25, width=110, x=120+150, y=30)
  55.  
  56. EntryThrustRaw = Entry(rocket)
  57. EntryThrustRaw.pack()
  58. EntryThrustRaw.place(bordermode=OUTSIDE, height=25, width=75, x=120+150+80, y=30)
  59.  
  60. LabelTempRaw = Label(rocket, text="Temperature (deg C)")
  61. LabelTempRaw.pack()
  62. LabelTempRaw.place(bordermode=OUTSIDE, height=25, width = 120, x=120+150+80+110, y=30)
  63.  
  64. EntryTempRaw = Entry(rocket)
  65. EntryTempRaw.pack()
  66. EntryTempRaw.place(bordermode=OUTSIDE, height=25, width=75, x=120+150+80+110+120, y=30)
  67.  
  68. LabelTimeRaw = Label(rocket, text="Time Interval")
  69. LabelTimeRaw.pack()
  70. LabelTimeRaw.place(bordermode=OUTSIDE, height=25, width=100, x=120+150+80+110+120+140, y=30)
  71.  
  72. TimeVar1 = 1
  73. TimeVar2 = 0.5
  74. TimeVar3 = 0.25
  75.  
  76. MasterTimeVarRaw=StringVar()
  77.  
  78. RBut1 = Radiobutton(rocket, text="1 sec", variable=MasterTimeVarRaw, value=TimeVar1)
  79. RBut1.place(bordermode=OUTSIDE, height=25, width=75, x=120+150+80+110+120+140+90, y=30)
  80.  
  81. RBut2 = Radiobutton(rocket, text="1/2 sec", variable=MasterTimeVarRaw, value=TimeVar2)
  82. RBut2.place(bordermode=OUTSIDE, height=25, width=75, x=120+150+80+110+120+140+95, y=50)
  83.  
  84. RBut3 = Radiobutton(rocket, text="1/4 sec", variable=MasterTimeVarRaw, value=TimeVar3)
  85. RBut3.place(bordermode=OUTSIDE, height=25, width=75, x=120+150+80+110+120+140+95, y=70)
  86.  
  87.  
  88.  
  89. def RocketFunction():
  90.  
  91. try:
  92. EntryMassFull=EntryMassFullRaw.get()
  93. EntryMassFull=float(EntryMassFull)
  94.  
  95. except ValueError:
  96. tkMessageBox.showinfo("Error!", "The input provided for Mass of Full Rocket is not acceptable. Please check input values and try again.")
  97.  
  98. try:
  99. EntryMassEmpty=EntryMassEmptyRaw.get()
  100. EntryMassEmpty=float(EntryMassEmpty)
  101.  
  102. except ValueError:
  103. tkMessageBox.showinfo("Error!", "The input provided for Mass of Empty Rocket is not acceptable. Please check input values and try again.")
  104.  
  105. try:
  106. EntryBurnTime=EntryBurnTimeRaw.get()
  107. EntryBurnTime=float(EntryBurnTime)
  108.  
  109. except ValueError:
  110. tkMessageBox.showinfo("Error!", "The input provided for Burn Time is not acceptable. Please check input values and try again.")
  111.  
  112. try:
  113. EntryDragCo=EntryDragCoRaw.get()
  114. EntryDragCo=float(EntryDragCo)
  115.  
  116. except ValueError:
  117. tkMessageBox.showinfo("Error!", "The input provided for Drag Coefficient is not acceptable. Please check input values and try again.")
  118.  
  119. try:
  120. EntryXSecArea=EntryXSecAreaRaw.get()
  121. EntryXSecArea=float(EntryXSecArea)
  122.  
  123. except ValueError:
  124. tkMessageBox.showinfo("Error!", "The input provided for Cross Sectional Area is not acceptable. Please check input values and try again.")
  125.  
  126. try:
  127. EntryThrust=EntryThrustRaw.get()
  128. EntryThrust=float(EntryThrust)
  129.  
  130. except ValueError:
  131. tkMessageBox.showinfo("Error!", "The input provided for Thrust is not acceptable. Please check input values and try again.")
  132.  
  133. try:
  134. EntryTemp=EntryTempRaw.get()
  135. EntryTemp=float(EntryTemp)
  136.  
  137. except ValueError:
  138. tkMessageBox.showinfo("Error!", "The input provided for Temperature is not acceptable. Please check input values and try again.")
  139.  
  140. MasterTimeVar=MasterTimeVarRaw.get()
  141. MasterTimeVar=float(MasterTimeVar)
  142.  
  143. fullburn=((EntryMassFull-EntryMassEmpty)/EntryBurnTime)
  144.  
  145. groundtemp = EntryTemp + 273.15
  146.  
  147. tx = 1
  148.  
  149. speednought = 0
  150.  
  151. speed = 0
  152.  
  153. altitude = 0.0001
  154.  
  155. altitudenought = 0
  156.  
  157. times = [0]
  158.  
  159. masses = [EntryMassFull]
  160.  
  161. speeds = [0]
  162.  
  163. altitudes =[0]
  164.  
  165. #Lift-off to Throttle-Down
  166.  
  167. while (tx*MasterTimeVar) <= EntryBurnTime and altitude > 0:
  168.  
  169. x = -1*(((tx*MasterTimeVar)*(fullburn)) - EntryMassFull)
  170.  
  171. acceleration = (EntryThrust-x*9.81)/x
  172.  
  173. speed = speednought + ((acceleration)*(MasterTimeVar))
  174.  
  175. altitude = altitudenought + (speed*(MasterTimeVar))
  176.  
  177. #removed print
  178.  
  179. times.append((tx*MasterTimeVar))
  180.  
  181. masses.append(x)
  182.  
  183. speeds.append(speed)
  184.  
  185. altitudes.append(altitude)
  186.  
  187. tx = tx + 1
  188.  
  189. speednought = speed
  190.  
  191. altitudenought = altitude
  192.  
  193. if altitude < 0:
  194.  
  195. tkMessageBox.showinfo("Error!", "Your rocket could not fly with the given parameters!")
  196.  
  197. break
  198.  
  199. else:
  200. continue
  201.  
  202.  
  203.  
  204. #Free-Fall before Terminal Velocity
  205.  
  206. airpressure = (101.325 *(1-((altitude*0.0065)/groundtemp))**((9.81*0.0289644)/(8.31447*0.0065)))
  207.  
  208. airtemperature = groundtemp - (altitude*0.0065)
  209.  
  210. airdensity = ((airpressure*.0289644)/(8.31447*airtemperature))
  211.  
  212. speedterminal = ((2*EntryMassEmpty*9.81)/(airdensity*EntryXSecArea*EntryDragCo))**(0.5)
  213.  
  214. while altitude > 0:
  215.  
  216.  
  217. if speed > -speedterminal:
  218.  
  219. (tx*MasterTimeVar) == EntryBurnTime
  220.  
  221. x = (EntryMassEmpty)
  222.  
  223. acceleration = (0/x)
  224.  
  225. speed = speednought + ((acceleration-9.81)*(MasterTimeVar))
  226.  
  227. altitude = altitudenought + (speed*(MasterTimeVar))
  228.  
  229. #removed print
  230.  
  231. times.append((tx*MasterTimeVar))
  232.  
  233. masses.append(x)
  234.  
  235. speeds.append(speed)
  236.  
  237. altitudes.append(altitude)
  238.  
  239. tx = tx + 1
  240.  
  241. speednought = speed
  242.  
  243. altitudenought = altitude
  244.  
  245. airpressure = (101.325 *(1-((altitude*0.0065)/groundtemp))**((9.81*0.0289644)/(8.31447*0.0065)))
  246.  
  247. airtemperature = groundtemp - (altitude*0.0065)
  248.  
  249. airdensity = ((airpressure*.0289644)/(8.31447*airtemperature))
  250.  
  251. speedterminal = ((2*EntryMassEmpty*9.81)/(airdensity*EntryXSecArea*EntryDragCo))**(0.5)
  252.  
  253. #removed print
  254.  
  255. continue
  256.  
  257.  
  258. #Free-Fall AFTER Terminal Velocity up to Landing
  259.  
  260. if speed <= -speedterminal:
  261.  
  262. (tx*MasterTimeVar) == EntryBurnTime
  263.  
  264. x = (EntryMassEmpty)
  265.  
  266. acceleration = (0/x)
  267.  
  268. #speed is now -speedterminal
  269.  
  270. altitude = altitudenought + (-speedterminal*(MasterTimeVar))
  271.  
  272. #removed print
  273.  
  274. times.append((tx*MasterTimeVar))
  275.  
  276. masses.append(x)
  277.  
  278. speeds.append(-speedterminal)
  279.  
  280. altitudes.append(altitude)
  281.  
  282. tx = tx + 1
  283.  
  284. altitudenought = altitude
  285.  
  286. airpressure = (101.325 *(1-((altitude*0.0065)/groundtemp))**((9.81*0.0289644)/(8.31447*0.0065)))
  287.  
  288. airtemperature = groundtemp - (altitude*0.0065)
  289.  
  290. airdensity = ((airpressure*.0289644)/(8.31447*airtemperature))
  291.  
  292. speedterminal = ((2*EntryMassEmpty*9.81)/(airdensity*EntryXSecArea*EntryDragCo))**(0.5)
  293.  
  294. #removed print
  295.  
  296. continue
  297.  
  298.  
  299. #removed print
  300.  
  301.  
  302. tkMessageBox.showinfo('Flight Duration in seconds =', (tx*MasterTimeVar))
  303.  
  304. 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")
  305.  
  306.  
  307. #Display Altitude vs Time Graph
  308.  
  309. pypt.plot(times, masses, "b-", times, speeds, "r-", times, altitudes, "g-")
  310.  
  311. pypt.show()
  312.  
  313.  
  314.  
  315.  
  316.  
  317. GoButton = Button(rocket, text="Compute", command=RocketFunction)
  318. GoButton.place(bordermode=OUTSIDE, height=50, width=100, x=450, y=100)
  319.  
  320.  
  321.  
  322. rocket.mainloop()
  323.  
Runtime error #stdin #stdout #stderr 0.21s 47456KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Traceback (most recent call last):
  File "prog.py", line 6, in <module>
  File "/usr/lib/python2.7/dist-packages/matplotlib/__init__.py", line 1102, in <module>
    rcParams = rc_params()
  File "/usr/lib/python2.7/dist-packages/matplotlib/__init__.py", line 949, in rc_params
    fname = matplotlib_fname()
  File "/usr/lib/python2.7/dist-packages/matplotlib/__init__.py", line 770, in matplotlib_fname
    configdir = _get_configdir()
  File "/usr/lib/python2.7/dist-packages/matplotlib/__init__.py", line 635, in _get_configdir
    return _get_config_or_cache_dir(_get_xdg_config_dir())
  File "/usr/lib/python2.7/dist-packages/matplotlib/__init__.py", line 612, in _get_config_or_cache_dir
    return _create_tmp_config_dir()
  File "/usr/lib/python2.7/dist-packages/matplotlib/__init__.py", line 544, in _create_tmp_config_dir
    tempdir = os.path.join(tempdir, 'matplotlib-%s' % getpass.getuser())
  File "/usr/lib/python2.7/getpass.py", line 158, in getuser
    return pwd.getpwuid(os.getuid())[0]
KeyError: 'getpwuid(): uid not found: 20042'