Beispiel #1
0
 def from_file(file):
     diameter = find_parameter(file, "diameter")
     length = find_parameter(file, "length")
     density = find_parameter(file, "density")
     thickness = find_parameter(file, "thickness")
     return Body(eval(diameter), eval(length), eval(thickness),
                 eval(density))
Beispiel #2
0
    def from_file_with_AoAspeed(initFile, sampleReport, path_to_file=''):
        """
                Create an instance of CFDrocket by reading some files

                example: initFile.dot as initFile, myMotor.dot as motor and CFD files as drag.dot, lift.dot, moments.dot
                                    -stored in folder 'myRocket2' (see 'Tests' folder)

                        in 'initFile.dot':

                        initial_mass = value of initial mass
                        initial_moi = Ixx, Iyy, Izz
                        initial_com = x-value of initial COM (this one is negative!)
                        length = value of rocket total length
                         motor = myMotor.dot

                        myRocket = Rocket.from_file('initFile.dot', 'sample-report.dot',
                                                    'myRocket2/')

                :param initFile: The file with content specified above
                :param sampleReport: The CFD file with aero moments about COM.
                                    Add sampling period, alpha_max, delta_v, v0 values to bottom of sampleReport:
                                                    period = ..
                                                    alpha_max = ..
                                                    .
                                                    .
                                                    .

                :param path_to_file: The path to the files above relative to current path (none by default)

                return: A rocket instance with specs from initFile and CFD.
                """
        path = path_to_file + initFile
        # CAD files are using the units mentioned below
        initMass = find_parameter(path, 'initial_mass')  # in grams
        initMOI = find_parameter(path, 'initial_moi')
        initMOI = np.diag(
            np.array([x.strip()
                      for x in initMOI.split(',')]).astype(float))  # in g*mm^2
        initCOM = find_parameter(path, 'initial_com')  # in millimeters
        length = find_parameter(path, 'length')  # in millimeters
        motor = Motor.from_file(path_to_file + find_parameter(path, 'motor'))

        path = path_to_file + sampleReport
        alpha, air_speed, aeroForces, moment = unwrap_report2(path)

        return Rocket(
            float(initMass) / 1e3, initMOI / 1e9,
            float(initCOM) / 1e3,
            float(length) / 1e3, motor, air_speed, alpha, aeroForces, moment)
Beispiel #3
0
    def from_file(motorFile):
        """
            Read a file with motor specs.
            ASSUMPTIONS: -
            :param motorFile: The file with motor specs in proper format
            :return: motor
            """
        name = find_parameter(motorFile, "name")
        diameter = find_parameter(motorFile, "diameter")
        length = find_parameter(motorFile, "length")
        propMass = find_parameter(motorFile, "propellant_mass")
        frameMass = find_parameter(motorFile, "frame_mass")
        totalImpulse = find_parameter(motorFile, "total_impulse")
        motorFile = open(motorFile, 'r')

        thrust = [[0, 0]]
        with motorFile as fp:
            for i, line in enumerate(fp):
                if i > 5:
                    row = line.split()
                    t = eval(row[0])
                    f = eval(row[1])
                    thrust.append([t, f])
        thrust = np.array(thrust)
        return Motor(name, thrust, float(totalImpulse), float(diameter),
                     float(length), float(propMass), float(frameMass))
Beispiel #4
0
 def from_file(file):
     semiChord = find_parameter(file, "semi_chord")
     rootChord = find_parameter(file, "root_chord")
     tipChord = find_parameter(file, "tip_chord")
     angle = find_parameter(file, "root_angle")
     density = find_parameter(file, "density")
     thickness = find_parameter(file, "thickness")
     return Fin(eval(semiChord), eval(rootChord), eval(tipChord),
                eval(angle), eval(thickness), eval(density))
Beispiel #5
0
    def from_file(rocket_file, path_to_file=""):
        """
        Creating an instance of a rocket by reading a rocket file that is located in a folder containing files for all
        necessary rocket parts.
        Example: folder 'myRocket'
                    'myRocket' content:
                                - myNose.dot
                                - myBody.dot
                                - myMotor.dot
                                - myFin.dot
                                - myPayload.dot
                                - myRocket.dot   <--  rocket file!
                 If this folder is located in the current working folder, you can simply create an instance of this
                 rocket with:
                          myRocket = RocketSimple.from_file('myRocket.dot', 'myRocket')
        :param path_to_file: [string] a path to the rocket file relative to the current path (empty by default)
        :param rocket_file: [string] name of rocket file
        :return: [RocketSimple class] Rocket instance with specs from rocket file.
        """
        # get file names of each rocket part
        path = path_to_file + rocket_file
        noseFile = find_parameter(path, "nose")
        bodyFile = find_parameter(path, "body")
        finFile = find_parameter(path, "fin")
        numberOfFins = find_parameter(path, "number_of_fins")
        motorFile = find_parameter(path, "motor")
        payloadFile = find_parameter(path, "payload")
        payloadPlacement = find_parameter(path, "payload_placement")
        finPlacement = find_parameter(path, "fin_placement")
        partsPlacement = np.array([eval(finPlacement), eval(payloadPlacement)])

        # Initialize rocket parts
        path = path_to_file
        nose = Nose.from_file(path + noseFile)
        body = Body.from_file(path + bodyFile)
        fin = Fin.from_file(path + finFile)
        motor = Motor.from_file(path + motorFile)
        payload = Payload.from_file(path + payloadFile)

        return RocketSimple(nose, body, fin, eval(numberOfFins), motor,
                            payload, partsPlacement)
Beispiel #6
0
 def from_file(file):
     noseType = find_parameter(file, "nose_type")
     if noseType.lower() == noseTypes[0] or noseType.lower(
     ) == noseTypes[2]:  # Conic or Ogive
         diameter = find_parameter(file, "diameter")
         length = find_parameter(file, "length")
         density = find_parameter(file, "density")
         thickness = find_parameter(file, "thickness")
         return Nose(noseType.lower(), eval(diameter), eval(length),
                     eval(thickness), eval(density))
     elif noseType.lower() == noseTypes[1]:  # Hemisphere
         diameter = find_parameter(file, "diameter")
         thickness = find_parameter(file, "thickness")
         density = find_parameter(file, "density")
         return Nose(noseType.lower(), eval(diameter), eval(thickness),
                     eval(density))
     else:
         print("ERROR: invalid nose type '" + noseType +
               "' encountered at initialization. "
               "Please check your spelling.")
         print("Possible options:")
         for string in noseTypes:
             print("\t" + string)
         exit(1)
Beispiel #7
0
 def from_file(file=''):
     width = find_parameter(file, "width")
     return Payload(eval(width))