Esempio n. 1
0
    def test_write_simple_JSBSimAircraft(self):
        rocket = rdoc.Rocket("Rocket")
        stage0 = rdoc.Stage("Sustainer")

        body = rdoc.Bodytube("body", 1, 0.2, diameter=0.33)
        engine = rdoc.Engine("test engine")
        engine.manufacturer = "Open Aerospace"
        engine.length = 0.1
        engine.diameter = 0.2
        engine.Isp = 169
        engine.m_prop = 1.0
        engine.thrust_avg = 1000

        body.components = [engine]

        stage0.components = [
            rdoc.Nosecone(rdoc.Noseshape.VONKARMAN, 1, 0.2, 1.0), body
        ]
        rocket.stages = [stage0]
        rocket.aero_properties['CD'] = [(0.1, 0.8), (0.5, 0.6), (1.0, 0.8)]
        str_file = writers.JSBSimAircraft.dump(rocket)

        # print(str_file)

        # smoke test
        self.assertGreater(len(str_file), 150)
Esempio n. 2
0
    def test_rocket_aero_exist(self):
        rocket = document.Rocket("Rocket")
        self.assertEqual(rocket.aero_properties, {})

        # add some properties
        rocket.aero_properties['CD'] = [0.8]
        self.assertEqual(rocket.aero_properties, {'CD': [0.8]})
Esempio n. 3
0
 def test_spec_a_rocket(self):
     rocket = document.Rocket("Rocket")
     stage0 = document.Stage("Booster")
     stage0.components = [
         document.Nosecone(document.Noseshape.VONKARMAN, 1, 0.7, 1.2),
         document.Bodytube("body", 1.2, 0.5),
     ]
     rocket.stages = [stage0]
Esempio n. 4
0
    def __init__(self, Isp, thrust, impulse, CD):
        """Take variables as input, build a rocket"""

        # Create an engine document
        engine = document.Engine('Motor')

        # Set our design
        engine.Isp = Isp
        engine.thrust_avg = thrust
        engine.I_total = impulse

        # volume of propellent needed
        prop_volume = engine.m_prop / self.prop_density

        # Solve for the radius/length of the fuel grain (assume solid, end burning)
        engine.diameter = 2 * (prop_volume / (2 * self.LD * pi))**(1 / 3.0)
        engine.length = engine.diameter * self.LD

        # Add a nose
        nose = document.Nosecone(
            document.Noseshape.TANGENT_OGIVE,  # Shape
            1.0,  # shape_parameter
            3.5,  # mass
            engine.diameter * self.Nose_LD,  # Length
            diameter=engine.diameter,
        )

        # Payload section
        payload = document.Bodytube(
            "Payload",  # Name
            3.5,  # mass
            0.33,  # length, fixed
            diameter=engine.diameter,
        )

        # Body section the size of the engine
        body = document.Bodytube(
            "Body",  # Name
            20.0,  # mass
            engine.length,
            diameter=engine.diameter,
        )

        body.components = [engine]

        # Rocket:
        rocket = document.Rocket("Rocket")
        rocket.aero_properties['CD'] = CD
        stage0 = document.Stage("Sustainer")
        stage0.components = [nose, payload, body]
        rocket.stages = [stage0]

        self.rocket = rocket
Esempio n. 5
0
    def test_write_document_smoke(self):
        rocket = rdoc.Rocket("Rocket")
        stage0 = rdoc.Stage("Sustainer")
        stage0.components = [
            rdoc.Nosecone(rdoc.Noseshape.VONKARMAN, 1, 0.2, 1.0),
            rdoc.Bodytube("body", 1, 0.2),
        ]
        rocket.stages = [stage0]
        str_file = writers.Document().dump(rocket)

        # print("Output:")
        # print(str_file)

        self.assertGreater(len(str_file), 10)
Esempio n. 6
0
    def test_write_simple_svg(self):
        rocket = rdoc.Rocket("Rocket")
        stage0 = rdoc.Stage("Sustainer")
        stage0.components = [
            rdoc.Nosecone(rdoc.Noseshape.VONKARMAN, 1, 0.2, 1.0, diameter=0.2),
            rdoc.Bodytube("body", 1, 1.2, diameter=0.2),
        ]
        rocket.stages = [stage0]
        str_file = writers.SVG.dump(rocket)

        # print("Output:")
        # print(str_file)
        # with open("testdraw.svg", "w") as testwrite:
        #     testwrite.write(str_file)

        self.assertGreater(len(str_file), 10)
Esempio n. 7
0
    def test_rocket_length_sum(self):
        stage0 = document.Stage("Booster")
        stage0.components = [
            document.Nosecone("", 1, 0.7, 1.2),
            document.Bodytube("body", 0, 1),
            document.Bodytube("body", 24.1, 1),
        ]
        stage1 = document.Stage("Booster")
        stage1.components = [
            document.Bodytube("body", 4.87, 1),
            document.Fin('fin', 1, 1, 1, sweepangle=45.0, mass=0.1),
        ]

        rocket = document.Rocket("Rocket")
        rocket.stages = [stage0, stage1]

        self.assertAlmostEqual(rocket.length, 5.2)
Esempio n. 8
0
    def test_rocket_length_sum_0(self):
        # just rocket
        rocket = document.Rocket("Rocket")
        self.assertEqual(rocket.length, 0)

        # rocket and a stage
        stage0 = document.Stage("sustainer")
        rocket.stages = [stage0]
        self.assertEqual(rocket.length, 0)

        # zero length components in rocket
        stage0.components = [
            document.Nosecone("", 1, 0.7, 0),
            document.Bodytube("body", 0, 0),
            document.Bodytube("body", 24.1, 0)
        ]
        self.assertEqual(rocket.length, 0)
Esempio n. 9
0
    def load(self, filename):
        """Read an OpenRocket file"""

        zf = ZipFile(filename)
        root = ET.fromstring(zf.read(zf.namelist()[0]))

        self.or_version = root.attrib['version']

        # Walk tree, there should be a 'rocket' and 'simulation tags'. We only
        # care about 'rocket'. After that there is a little metadata and then
        # components.
        for element in root:
            if element.tag == 'rocket':

                # We found a rocket! Create a document
                ordoc = rdoc.Rocket("Imported OpenRocket File")  # default name

                for orkrocket in element:
                    if orkrocket.tag == 'name':
                        # This rocket has a name
                        ordoc.name = orkrocket.text

                    if orkrocket.tag == 'subcomponents':
                        # This rocket has stages
                        for orkstage in orkrocket:
                            if orkstage.tag == 'stage':
                                # Create a stage, default name is stage number
                                stage = rdoc.Stage("stage {0}".format(len(ordoc.stages)))

                                for stage_parts in orkstage:
                                    if stage_parts.tag == 'name':
                                        stage.name = stage_parts.text
                                    if stage_parts.tag == 'subcomponents':
                                        # Recurse down through all components
                                        stage.components = [part for part in self._subcomponent_walk(stage_parts)]

                                # Append to rocket
                                ordoc.stages.append(stage)

        return ordoc
Esempio n. 10
0
    def test_rocket_name_slug(self):

        # replace spaces with dashes
        c = document.Rocket("My Rocket")
        self.assertEqual(c.name_slug, "my-rocket")
Esempio n. 11
0
def rocket():

    # parametric thrust curve:
    peak_thrust = random.uniform(3000, 4200)
    delay_time = random.uniform(0.5, 30.0)
    min_thrust = random.uniform(0.5, 1.0)
    growth_rate = random.uniform(1.01, 2.5)

    engine = document.Engine("Motor")
    engine.m_prop = 70.0  # kg
    engine.diameter = 0.28
    engine.length = 1.5

    isp = 244
    max_impulse = engine.m_prop * isp * 9.8

    thrust = 1.0
    thrustcurve = []
    itot = 0
    for i in range(500):
        t = i * 0.1

        if t > delay_time:
            thrust = min_thrust * growth_rate**(t - delay_time)
            if thrust > 1.0:
                thrust = 1.0

        thrust_N = thrust * peak_thrust

        # compute Total impulse
        if i > 0:
            x = thrustcurve[-1]['t']
            x_1 = t
            f_x = thrustcurve[-1]['thrust']
            f_x1 = thrust_N
            itot += ((x_1 - x) * (f_x1 + f_x)) / 2.0

        thrustcurve.append({'t': t, 'thrust': thrust_N})

        # When we exceed our impulse budget quit
        if itot > max_impulse:
            break

    engine.thrustcurve = thrustcurve

    body.components = [engine]

    # Rocket:
    rocket = document.Rocket("Rocket")
    rocket.aero_properties['CD'] = [
        (0.010, 0.699865),
        (0.200, 0.580362),
        (0.300, 0.586504),
        (0.400, 0.595115),
        (0.500, 0.606208),
        (0.600, 0.619801),
        (0.700, 0.635912),
        (0.800, 0.654567),
        (0.900, 0.675792),
        (0.950, 0.681607),
        (1.000, 0.688266),
        (1.050, 0.725044),
        (1.100, 0.722610),
        (1.200, 0.657679),
        (1.300, 0.595412),
        (1.400, 0.572275),
        (1.500, 0.550839),
        (1.600, 0.530843),
        (1.700, 0.512105),
        (1.800, 0.494492),
        (1.900, 0.477901),
        (2.000, 0.462252),
    ]
    stage0 = document.Stage("Sustainer")
    stage0.components = [nose, payload, body]
    rocket.stages = [stage0]

    return rocket