Exemplo n.º 1
0
def calc_drag(current_data):
    h, T, p, rho = coesa.table(1000 * current_data['altitude'])

    if type(rho) == complex:
        return 0

    return 0.5 * Cd * rho * FAIRING_AREA * current_data['velocity'] ** 2
Exemplo n.º 2
0
def test_sea_level():
    """Tests sea level values.

    """
    h, T, p, rho = coesa.table(0.0)

    np.testing.assert_equal(h, 0.0)
    np.testing.assert_equal(T, sp.constants.C2K(15))
    np.testing.assert_equal(p, sp.constants.atm)
    np.testing.assert_almost_equal(rho, 1.2250, decimal=3)
    def __init__(self, prop, motor, battery, numCells, esc, altitude,
                 showData):

        #Open database and read records from database
        db = sql.connect("Database/components.db")
        dbcur = db.cursor()

        #Fetch prop data
        formatString = """select * from Props where Name = "{propName}" """
        command = formatString.format(propName=prop)
        dbcur.execute(command)
        propRecord = dbcur.fetchall()
        propInfo = np.asarray(propRecord[0])
        if showData:
            print("----Propeller Data----\n", propInfo)
        self.prop = s.Propeller(propInfo[1], propInfo[2], propInfo[3],
                                propInfo[4:])

        #Fetch motor data
        formatString = """select * from Motors where Name = "{motorName}" """
        command = formatString.format(motorName=motor)
        dbcur.execute(command)
        motorRecord = dbcur.fetchall()
        motorInfo = np.asarray(motorRecord[0])
        if showData:
            print("----Motor Data----\n", motorInfo)
        self.motor = s.Motor(motorInfo[1], motorInfo[2], motorInfo[3],
                             motorInfo[5], motorInfo[4], motorInfo[6])

        #Fetch battery data
        formatString = """select * from Batteries where Name = "{batteryName}" """
        command = formatString.format(batteryName=battery)
        dbcur.execute(command)
        batteryRecord = dbcur.fetchall()
        batteryInfo = np.asarray(batteryRecord[0])
        if showData:
            print("----Battery Data----\n", batteryInfo)
        self.batt = s.Battery(batteryInfo[1], numCells, batteryInfo[3],
                              batteryInfo[6], batteryInfo[5], batteryInfo[4])

        #Fetch ESC data
        formatString = """select * from ESCs where Name = "{escName}" """
        command = formatString.format(escName=esc)
        dbcur.execute(command)
        escRecord = dbcur.fetchall()
        escInfo = np.asarray(escRecord[0])
        if showData:
            print("----ESC Data----\n", escInfo)
        self.esc = s.ESC(escInfo[1], escInfo[5], escInfo[2], escInfo[4])

        #Initialize exterior parameters to be set later
        self.prop.vInf = 0
        self.prop.angVel = 0
        _, _, _, self.airDensity = coesa.table(altitude)
        db.close()
Exemplo n.º 4
0
def c_at_altitude(altitude):
    """This function calculates the speed of sound(c) for a given altitude.
    :param data: An object that contains data about the rocket's altitude and velocity.
    :return: the speed of sound.
    """
    h, T, P, rho = coesa.table(altitude)

    if type(P) == complex or P < 1:
        return 0

    return (AIR_ADIABATIC * P/rho)**0.5
Exemplo n.º 5
0
def get_atmos_data(altitude):
    """
    This function calculates data about the atmosphere
    :param altitude: Distance from the surface of the Earth [m]
    :return:
    """
    h, T, P, rho = coesa.table(altitude)

    if np.isnan(P) or type(P) == complex:
        P = 0
        rho = 0

    return h, T, P, rho
Exemplo n.º 6
0
def test_sea_level_nd_array():
    """Tests sea level values using n dimension array.

    """
    h_ = np.array([0.0, 0.0, 0.0])
    h, T, p, rho = coesa.table(h_)

    np.testing.assert_array_equal(h, h_)
    np.testing.assert_array_almost_equal(
        T, [288.15] * 3, decimal=3)
    np.testing.assert_array_almost_equal(
        p, [101325.0] * 3, decimal=3)
    np.testing.assert_array_almost_equal(
        rho, [1.2250] * 3, decimal=3)
Exemplo n.º 7
0
    def __init__(self, prop, motor, battery, esc, altitude):

        self.prop = prop
        self.motor = motor
        self.batt = battery
        self.esc = esc

        _, _, _, self.airDensity = coesa.table(altitude * 0.3048)
        self.airDensity = self.airDensity * 0.0019403203  # Converts kg/m^3 to slug/ft^3

        #Initialize exterior parameters to be set later
        self.prop.vInf = 0
        self.prop.angVel = 0
        self.Im = 0  #Instantaneous current being drawn through the motor
Exemplo n.º 8
0
def test_sea_level_0d_array():
    """Tests sea level values using zero dimension array.

    """
    h_ = np.array(0.0)
    T_ = np.array(sp.constants.C2K(15))
    p_ = np.array(sp.constants.atm)
    rho_ = np.array(1.2250)

    h, T, p, rho = coesa.table(h_)

    np.testing.assert_array_equal(h, h_)
    np.testing.assert_array_almost_equal(T, T_, decimal=3)
    np.testing.assert_array_almost_equal(p, p_, decimal=3)
    np.testing.assert_array_almost_equal(rho, rho_, decimal=3)
Exemplo n.º 9
0
def test_sea_level():
    """Tests sea level values.

    """
    h = 0.0
    expected_h = 0.0
    expected_T = sp.constants.C2K(15)
    expected_p = sp.constants.atm
    expected_rho = 1.2250

    h, T, p, rho = coesa.table(h)

    assert_equal(h, expected_h)
    assert_equal(T, expected_T)
    assert_equal(p, expected_p)
    assert_almost_equal(rho, expected_rho, decimal=4)
Exemplo n.º 10
0
def test_sea_level_nd_array():
    """Tests sea level values using n dimension array.

    """
    h = np.array([0.0, 0.0, 0.0])
    expected_h = np.array([0.0, 0.0, 0.0])
    expected_T = np.array([288.15] * 3)
    expected_p = np.array([101325.0] * 3)
    expected_rho = np.array([1.2250] * 3)

    h, T, p, rho = coesa.table(h)

    assert_array_equal(h, expected_h)
    assert_array_almost_equal(T, expected_T)
    assert_array_almost_equal(p, expected_p)
    assert_array_almost_equal(rho, expected_rho)
Exemplo n.º 11
0
def test_sea_level():
    """Tests sea level values.

    """
    h = 0.0
    expected_h = 0.0
    expected_T = _C2K(15)
    expected_p = sp.constants.atm
    expected_rho = 1.2250

    h, T, p, rho = coesa.table(h)

    assert_equal(h, expected_h)
    assert_equal(T, expected_T)
    assert_equal(p, expected_p)
    assert_almost_equal(rho, expected_rho, decimal=4)
Exemplo n.º 12
0
def test_sea_level_0d_array():
    """Tests sea level values using zero dimension array.

    """
    h = np.array(0.0)
    expected_h = np.array(0.0)
    expected_T = np.array(sp.constants.C2K(15))
    expected_p = np.array(sp.constants.atm)
    expected_rho = np.array(1.2250)

    h, T, p, rho = coesa.table(h)

    assert_array_equal(h, expected_h)
    assert_array_almost_equal(T, expected_T)
    assert_array_almost_equal(p, expected_p)
    assert_array_almost_equal(rho, expected_rho)
Exemplo n.º 13
0
def test_sea_level_nd_array():
    """Tests sea level values using n dimension array.

    """
    h = np.array([0.0, 0.0, 0.0])
    expected_h = np.array([0.0, 0.0, 0.0])
    expected_T = np.array([288.15] * 3)
    expected_p = np.array([101325.0] * 3)
    expected_rho = np.array([1.2250] * 3)

    h, T, p, rho = coesa.table(h)

    assert_array_equal(h, expected_h)
    assert_array_almost_equal(T, expected_T)
    assert_array_almost_equal(p, expected_p)
    assert_array_almost_equal(rho, expected_rho)
Exemplo n.º 14
0
def test_sea_level_0d_array():
    """Tests sea level values using zero dimension array.

    """
    h = np.array(0.0)
    expected_h = np.array(0.0)
    expected_T = np.array(_C2K(15))
    expected_p = np.array(sp.constants.atm)
    expected_rho = np.array(1.2250)

    h, T, p, rho = coesa.table(h)

    assert_array_equal(h, expected_h)
    assert_array_almost_equal(T, expected_T)
    assert_array_almost_equal(p, expected_p)
    assert_array_almost_equal(rho, expected_rho)
Exemplo n.º 15
0
def test_under_86km():
    """Tests for altitude values between 35 and 86 km

    """
    z = np.array([50000.0, 70000.0, 86000.0])
    h = util.geometric_to_geopotential(z)
    expected_h = np.array([49610.0, 69238., 84852.0])
    expected_T = np.array([270.65, 219.585, 186.87])
    expected_p = np.array([79.779, 5.2209, 0.37338])
    expected_rho = np.array([0.0010269, 0.000082829, 0.000006958])

    h, T, p, rho = coesa.table(h)
    
    assert_array_almost_equal(h, expected_h, decimal=0)
    assert_array_almost_equal(T, expected_T, decimal=2)
    assert_array_almost_equal(p, expected_p, decimal=3)
    assert_array_almost_equal(rho, expected_rho, decimal=7)
Exemplo n.º 16
0
def test_under_35km():
    """Tests for altitude values between 11 and 35 km

    """
    z = np.array([15000.0, 25000.0, 35000.0])
    h = util.geometric_to_geopotential(z)
    expected_h = np.array([14965.0, 24902., 34808.0])
    expected_T = np.array([216.65, 221.552, 236.513])
    expected_p = np.array([12111.0, 2549.2, 574.59])
    expected_rho = np.array([0.19476, 0.040084, 0.0084634])

    h, T, p, rho = coesa.table(h)
    
    assert_array_almost_equal(h, expected_h, decimal=0)
    assert_array_almost_equal(T, expected_T, decimal=3)
    assert_array_almost_equal(p, expected_p, decimal=0)
    assert_array_almost_equal(rho, expected_rho, decimal=5)
Exemplo n.º 17
0
def test_under_11km():
    """Tests for altitude values between 1 and 11 km

    """
    z = np.array([500.0, 2500.0, 6500.0, 9000.0, 11000.0])
    h = util.geometric_to_geopotential(z)
    expected_h = np.array([500.0, 2499.0, 6493.0, 8987.0, 10981.0])
    expected_T = np.array([284.900, 271.906, 245.943, 229.733, 216.774])
    expected_p = np.array([95461.0, 74691.0, 44075.0, 30800.0, 22699.0])
    expected_rho = np.array([1.1673, 0.95695, 0.62431, 0.46706, 0.36480])

    h, T, p, rho = coesa.table(h)
    
    assert_array_almost_equal(h, expected_h, decimal=0)
    assert_array_almost_equal(T, expected_T, decimal=3)
    assert_array_almost_equal(p, expected_p, decimal=0)
    assert_array_almost_equal(rho, expected_rho, decimal=4)
Exemplo n.º 18
0
def test_under_1000m():
    """Tests for altitude values under 1000.0 m

    """
    z = np.array([50.0, 550.0, 850.0])
    h = util.geometric_to_geopotential(z)
    expected_h = np.array([50.0, 550.0, 850.0])
    expected_T = np.array([287.825, 284.575, 282.626])
    expected_p = np.array([100720.0, 94890.0, 91523.0])
    expected_rho = np.array([1.2191, 1.1616, 1.1281])

    h, T, p, rho = coesa.table(h)

    assert_array_almost_equal(h, expected_h, decimal=0)
    assert_array_almost_equal(T, expected_T, decimal=3)
    assert_array_almost_equal(p, expected_p, decimal=-1)
    assert_array_almost_equal(rho, expected_rho, decimal=4)
Exemplo n.º 19
0
def test_under_1000m():
    """Tests for altitude values under 1000.0 m

    """
    z = np.array([50.0, 550.0, 850.0])
    h = util.geometric_to_geopotential(z)
    expected_h = np.array([50.0, 550.0, 850.0])
    expected_T = np.array([287.825, 284.575, 282.626])
    expected_p = np.array([100720.0, 94890.0, 91523.0])
    expected_rho = np.array([1.2191, 1.1616, 1.1281])

    h, T, p, rho = coesa.table(h)

    assert_array_almost_equal(h, expected_h, decimal=0)
    assert_array_almost_equal(T, expected_T, decimal=3)
    assert_array_almost_equal(p, expected_p, decimal=-1)
    assert_array_almost_equal(rho, expected_rho, decimal=4)
Exemplo n.º 20
0
def test_under_86km():
    """Tests for altitude values between 35 and 86 km

    """
    z = np.array([50000.0, 70000.0, 86000.0])
    h = util.geometric_to_geopotential(z)
    expected_h = np.array([49610.0, 69238., 84852.0])
    expected_T = np.array([270.65, 219.585, 186.87])
    expected_p = np.array([79.779, 5.2209, 0.37338])
    expected_rho = np.array([0.0010269, 0.000082829, 0.000006958])

    h, T, p, rho = coesa.table(h)

    assert_array_almost_equal(h, expected_h, decimal=0)
    assert_array_almost_equal(T, expected_T, decimal=2)
    assert_array_almost_equal(p, expected_p, decimal=3)
    assert_array_almost_equal(rho, expected_rho, decimal=7)
Exemplo n.º 21
0
def test_under_35km():
    """Tests for altitude values between 11 and 35 km

    """
    z = np.array([15000.0, 25000.0, 35000.0])
    h = util.geometric_to_geopotential(z)
    expected_h = np.array([14965.0, 24902., 34808.0])
    expected_T = np.array([216.65, 221.552, 236.513])
    expected_p = np.array([12111.0, 2549.2, 574.59])
    expected_rho = np.array([0.19476, 0.040084, 0.0084634])

    h, T, p, rho = coesa.table(h)

    assert_array_almost_equal(h, expected_h, decimal=0)
    assert_array_almost_equal(T, expected_T, decimal=3)
    assert_array_almost_equal(p, expected_p, decimal=0)
    assert_array_almost_equal(rho, expected_rho, decimal=5)
Exemplo n.º 22
0
def test_under_11km():
    """Tests for altitude values between 1 and 11 km

    """
    z = np.array([500.0, 2500.0, 6500.0, 9000.0, 11000.0])
    h = util.geometric_to_geopotential(z)
    expected_h = np.array([500.0, 2499.0, 6493.0, 8987.0, 10981.0])
    expected_T = np.array([284.900, 271.906, 245.943, 229.733, 216.774])
    expected_p = np.array([95461.0, 74691.0, 44075.0, 30800.0, 22699.0])
    expected_rho = np.array([1.1673, 0.95695, 0.62431, 0.46706, 0.36480])

    h, T, p, rho = coesa.table(h)

    assert_array_almost_equal(h, expected_h, decimal=0)
    assert_array_almost_equal(T, expected_T, decimal=3)
    assert_array_almost_equal(p, expected_p, decimal=0)
    assert_array_almost_equal(rho, expected_rho, decimal=4)
Exemplo n.º 23
0
    def Update(self):   
        from numpy import arcsin, arccos, arctan2

        # Assigns local variables
        Vx = self.States['Velocity_x']
        Vy = self.States['Velocity_y']
        Vz = self.States['Velocity_z']
        h = -self.States['Position_z']      # Assumption : Z Position_z is the altitude
        
        self.Speed = sqrt(Vx*Vx +Vy*Vy +Vz*Vz)
        self.Alpha = arctan2(Vz, Vx)
        self.Beta = arctan2(Vy, self.Speed)

        h, T, p, self.AirDensity = isa.table(h)
        c = (331.5 + 0.6*(T - 273.15))
        self.Mach = self.Speed/c

        return super(MissileSimplified, self).Update()
Exemplo n.º 24
0
def test_under_1000m():
    """Tests for altitude values under 1000.0 m

    """
    z_ = np.array([50.0, 550.0, 850.0])
    h_ = coesa.geometric_to_geopotential(z_)

    # Retrieve desired data from PDAS tables
    desired = np.array([data[data[:, 0] == x][0] for x in z_])

    T_ = desired[:, 4]
    p_ = desired[:, 5]
    rho_ = desired[:, 6]

    h, T, p, rho = coesa.table(h_)

    np.testing.assert_array_almost_equal(T, T_, decimal=1)
    np.testing.assert_array_almost_equal(p, p_, decimal=0)
    np.testing.assert_array_almost_equal(rho, rho_, decimal=3)
Exemplo n.º 25
0
def mach_number(data):
    h, T, p, rho = coesa.table(1000 * data['altitude'])
    return data['velocity'] / sqrt(1.66 * p / rho)
Exemplo n.º 26
0
 def __post_init__(self):
     # an atmosphere object at a height
     self.atm = coesa.table(self.alt/3.28084)
     self.T = self.atm[1]*1.8         # [Rankine]
     self.p = self.atm[2]/6895        # [psi]
     self.rho = self.atm[3]/515       # [slug/ft3]
Exemplo n.º 27
0
 def q_infinity(self):
     _, _, _, rho = coesa.table(self.altitude)
     return 0.5 * rho * self.velocity**2
Exemplo n.º 28
0
    tgrad = GTAB[i]  # i will be in 1...NTAB-1
    tbase = TTAB[i]
    deltah = h - HTAB[i]
    tlocal = tbase + tgrad * deltah
    theta = tlocal / TTAB[1]  # temperature ratio

    if tgrad == 0.0:  # pressure ratio
        delta = PTAB[i] * exp(-GMR * deltah / tbase)
    else:
        delta = PTAB[i] * (tbase / tlocal)**(GMR / tgrad)

    sigma = delta / theta  #! density ratio

    rho = sigma * 1.225
    pressure = delta * 101325
    temperature = theta * 288.15
    a = sqrt(1.4 * pressure / rho)
    # print()
    # print(f"speed of sound p/rho:  {a}")
    # b = sqrt(1.4 * 287 * (temperature))
    # print(f"speed of sound RT:  {b}")
    print()
    return altitude, temperature, pressure, rho, a


print()
print(atmos(6.7056))
print()
print(coesa.table(0.6))