PYTHON: Level 1 HPR (high powered rocketry) simulator

This project combines physics and mathematics to calculate the velocity and 2D displacement of an Estes F15-4 solid rocket motor. It uses NumPy and MatPlotlib which are both python libraries to create a time-dependant array to graph and analyze the information. This project was created because I am currently working towards my HPR Level One Certification, which inspired me to use my understanding of physics to understand further what is happening when you press the ignite button.

import numpy as np

import matplotlib.pyplot as plt

#variable in SI units

Mass = 1 # this is the weight of the rocket in kg

Dmass = 0.800 # this is the dry mass of the rocket ( mass without propellant)

Burntime = 3.5 #F15-4 rocket motor burn time

Timpulse = 49.61 # this is the total impulse of the F15-4 motor

Propmass = 0.065 # this is the actual mass of just the propellant


# defines the array that solves the area under the curve

def integrateGraph (time, array):

resArray = [0]

for n in range(0, len(time)-1):

resArray.append(resArray[-1]+0.5 *(array[n+1] + array[n])*(time[n+1]-time[n]))


return np.array(resArray)


#basic calculations to find thrust and mass flow rate


avgthrust = Timpulse/Burntime

mdot = Propmass/Burntime


# make a time array to later graph


time= np.linspace(0,10,100,False) # linspace is an array of numbes from 0-9.9


#phyiscs and integration method, its finding the area under the curve


index = int(np.where(time==Burntime)[0]+1)


thrust = np.append(np.repeat(avgthrust, index), np.repeat(0, len(time)-index))

mass= np.append(np.repeat(Mass, index) - time[0:index] * mdot, np.repeat(Dmass, len(time) - index))

acceleration = thrust/mass - 9.81


velocity = integrateGraph(time, acceleration)

displacement = integrateGraph(time, velocity)


plt.plot(time, displacement)

plt.plot(time, velocity)

plt.legend(["Displacement", "Velocity"])

plt.xlabel("Time")

plt.show()