Exemple #1
0
    def calc_rel_properties(self):
        """Calculates mass, relative center of mass, and relative/local
        inertia, according to formulae in Appendix B of Yeadon 1990-ii. If the
        stadium solid is arranged anteroposteriorly, the inertia is rotated
        by pi/2 about the z axis.

        """
        # There are two cases of stadium solid degeneracy to consider:
        # t0 = 0, and t0 = t1 = 0. The degeneracy arises when b has a
        # denominator of 0. The case that t1 = 0 is not an issue, then.
        # The way the case of t0 = 0 is handled is by switching the two stadia.
        # Note that thi affects how the relative center of mass is set, but
        # does not affect the mass or moments of inertia calculations.
        # The case in which t0 = t1 = 0, we set b to 1. That is because t = t0
        # (1 + bz) is going to be zero anyway, since t0 = 0.
        D = self.density
        h = self.height
        if self.degenerate_by_t0:
            # Swap the stadia.
            r0 = self.stads[1].radius
            t0 = self.stads[1].thickness
            r1 = self.stads[0].radius
            t1 = self.stads[0].thickness
        else:
            r0 = self.stads[0].radius
            t0 = self.stads[0].thickness
            r1 = self.stads[1].radius
            t1 = self.stads[1].thickness
        a = (r1 - r0) / r0
        if t0 == 0:
            # Truncated cone, since both thicknesses are zero.
            # b can be anything, because t = t0(1 + bz) = (0)(1 + bz) = 0.
            b = 1
        else:
            b = (t1 - t0) / t0
        self._mass = D * h * r0 * (4.0 * t0 * self._F1(a,b) +
                                  np.pi * r0 * self._F1(a,a))
        zcom = D * (h**2.0) * (4.0 * r0 * t0 * self._F2(a,b) +
                               np.pi * (r0**2.0) * self._F2(a,a)) / self.mass
        if self.degenerate_by_t0 and t0 != 0:
            # We swapped the stadia, and it's not a truncated cone.
            # Must define this intermediate because zcom above is still what
            # must be used for the parallel axis theorem below.
            adjusted_zcom = h - zcom
        else:
            adjusted_zcom = zcom
        self._rel_center_of_mass = np.array([[0.0],[0.0],[adjusted_zcom]])

        # moments of inertia
        Izcom = D * h * (4.0 * r0 * (t0**3.0) * self._F4(a,b) / 3.0 +
                         np.pi * (r0**2.0) * (t0**2.0) * self._F5(a,b) +
                         4.0 * (r0**3.0) * t0 * self._F4(b,a) +
                         np.pi * (r0**4.0) * self._F4(a,a) * 0.5 )
        # CAUGHT AN (minor) ERROR IN YEADON'S PAPER HERE. The Dh^3 in the
        # formula below is missing from the second formula for Iy^0 on page 73
        # of Yeadon1990-ii.
        Iy = (D * h * (4.0 * r0 * (t0**3.0) * self._F4(a,b) / 3.0 +
                       np.pi * (r0**2.0) * (t0**2.0) * self._F5(a,b) +
                       8.0 * (r0**3.0) * t0*self._F4(b,a) / 3.0 +
                      np.pi * (r0**4.0) * self._F4(a,a) * 0.25) +
              D * (h**3.0) * (4.0 * r0 * t0 * self._F3(a,b) +
                              np.pi * (r0**2.0) * self._F3(a,a)))
        Iycom = Iy - self.mass * (zcom**2.0)
        Ix = (D * h * (4.0 * r0 * (t0**3.0) * self._F4(a,b) / 3.0 +
                       np.pi * (r0**4.0) * self._F4(a,a) * 0.25) +
              D * (h**3.0) * (4.0 * r0 * t0 * self._F3(a,b) +
                              np.pi * (r0**2.0) * self._F3(a,a)))
        Ixcom = Ix - self.mass*(zcom**2.0)
        self._rel_inertia = np.mat([[Ixcom,0.0,0.0],
                                  [0.0,Iycom,0.0],
                                  [0.0,0.0,Izcom]])
        if self.alignment == 'AP':
            # rearrange to anterorposterior orientation
            self._rel_inertia = inertia.rotate_inertia(
                    inertia.rotate_space_123([0, 0, np.pi/2]), self.rel_inertia)
Exemple #2
0
def start_ui():
    print "Starting YEADON user interface."

    measPreload = { 'Ls5L' : 0.545, 'Lb2p' : 0.278, 'La5p' : 0.24, 'Ls4L' :
    0.493, 'La5w' : 0.0975, 'Ls4w' : 0.343, 'La5L' : 0.049, 'Lb2L' : 0.2995,
    'Ls4d' : 0.215, 'Lj2p' : 0.581, 'Lb5p' : 0.24, 'Lb5w' : 0.0975, 'Lk8p' :
    0.245, 'Lk8w' : 0.1015, 'Lj5L' : 0.878, 'La6w' : 0.0975, 'Lk1L' : 0.062,
    'La6p' : 0.2025, 'Lk1p' : 0.617, 'La6L' : 0.0805, 'Ls5p' : 0.375, 'Lj5p' :
    0.2475, 'Lk8L' : 0.1535, 'Lb5L' : 0.049, 'La3p' : 0.283, 'Lj9w' : 0.0965,
    'La4w' : 0.055, 'Ls6L' : 0.152, 'Lb0p' : 0.337, 'Lj8w' : 0.1015, 'Lk2p' :
    0.581, 'Ls6p' : 0.53, 'Lj9L' : 0.218, 'La3L' : 0.35, 'Lj8p' : 0.245, 'Lj3L'
    : 0.449, 'La4p' : 0.1685, 'Lk3L' : 0.449, 'Lb3p' : 0.283, 'Ls7L' : 0.208,
    'Ls7p' : 0.6, 'Lb3L' : 0.35, 'Lk3p' : 0.3915, 'La4L' : 0.564, 'Lj8L' :
    0.1535, 'Lj3p' : 0.3915, 'Lk4L' : 0.559, 'La1p' : 0.2915, 'Lb6p' : 0.2025,
    'Lj6L' : 0.05, 'Lb6w' : 0.0975, 'Lj6p' : 0.345, 'Lb6L' : 0.0805, 'Ls0p' :
    0.97, 'Ls0w' : 0.347, 'Lj6d' : 0.122, 'Ls8L' : 0.308, 'Lk5L' : 0.878,
    'La2p' : 0.278, 'Lj9p' : 0.215, 'Ls1L' : 0.176, 'Lj1L' : 0.062, 'Lb1p' :
    0.2915, 'Lj1p' : 0.617, 'Ls1p' : 0.865, 'Ls1w' : 0.317, 'Lk4p' : 0.34,
    'Lk5p' : 0.2475, 'La2L' : 0.2995, 'Lb4w' : 0.055, 'Lb4p' : 0.1685, 'Lk9p' :
    0.215, 'Lk9w' : 0.0965, 'Ls2p' : 0.845, 'Lj4L' : 0.559, 'Ls2w' : 0.285,
    'Lk6L' : 0.05, 'La7w' : 0.047, 'La7p' : 0.1205, 'La7L' : 0.1545, 'Lk6p' :
    0.345, 'Ls2L' : 0.277, 'Lj4p' : 0.34, 'Lk6d' : 0.122, 'Lk9L' : 0.218,
    'Lb4L' : 0.564, 'La0p' : 0.337, 'Ls3w' : 0.296, 'Ls3p' : 0.905, 'Lb7p' :
    0.1205, 'Lb7w' : 0.047, 'Lj7p' : 0.252, 'Lb7L' : 0.1545, 'Ls3L' : 0.388,
    'Lk7p' : 0.252 }

    # initialize the joint angle data
    # user supplies names/paths of input text files
    print "PROVIDE DATA INPUTS: measurements and configuration (joint angles)."
    print "\nMEASUREMENTS: can be provided as a 95-field dict (units must be " \
          "meters), or a .TXT file"
    temp = raw_input("Type the name of the .TXT filename (to use preloaded "
                    "measurements just hit enter): ")
    if temp == '':
        meas = measPreload
    else:
        file_exist_meas = os.path.exists(temp)
        meas = temp
        while not file_exist_meas:
            temp = raw_input("Please type the correct name of the .TXT filename "
                            "(or just use preloaded measurements just hit enter): ")
            file_exist_meas = os.path.exists(temp)

            if temp == '':
                meas = measPreload
                break
            elif file_exist_meas:
                meas = temp

    print "\nCONFIGURATION (joint angles): can be provided as a 21-field dict,"\
          " or a .TXT file"
    CFG = raw_input("Type the name of the .TXT filename (for all joint angles "
                    "as zero, just hit enter): ")
    # create the human object. only one is needed for this commandline program
    print "Creating human object."

    if CFG == '':
        H = hum.Human(meas)
    else:
        file_exist_CFG = os.path.exists(CFG)
        while not file_exist_CFG:
            CFG = raw_input("Please type the correct name of the .TXT filename "
                            "(for all joint angles as zero, just hit enter): ")
            file_exist_CFG = os.path.exists(CFG)

            if CFG == '':
                H = hum.Human(meas)
                break
            elif file_exist_CFG:
                H = hum.Human(meas, CFG)

    done = 0 # loop end flag

    while done != 1:
        print "\nYEADON MAIN MENU"
        print "----------------"
        print "  j: print/modify joint angles\n\n",\
              "  a: save current joint angles to file\n",\
              "  p: load joint angles from file\n",\
              "  s: format input measurements for ISEG Fortran code\n\n",\
              "  t: transform absolute/base/fixed coordinate system\n\n",\
              "  d: draw 3D human\n\n",\
              "  h: print human properties\n",\
              "  g: print segment properties\n",\
              "  l: print solid properties\n\n",\
              "  c: combine solids/segments for inertia parameters\n\n",\
              "  o: options\n",\
              "  q: quit"

        userIn = raw_input("What would you like to do next? ")
        print ""

        # MODIFY JOINT ANGLES
        if userIn == 'j':
            # this function is defined above
            H = modify_joint_angles(H)

        # SAVE CURRENT JOINT ANGLES
        elif userIn == 'a':
            fname = raw_input("The joint angle dictionary CFG will be pickled" \
                              " into a file saved in the current directory." \
                              " Specify a file name (without quotes or spaces," \
                              " q to quit): ")
            if fname != 'q':
                H.write_CFG(fname)
                print "The joint angles have been saved in",fname,".pickle."

        # LOAD JOINT ANGLES
        elif userIn == 'p':
            print "Be careful with this, because there is no error checking"\
                  " yet. Make sure that the pickle file is in the same format"\
                  " as a pickle output file from this program."
            fname = raw_input("Enter the name of a CFG .TXT file" \
                              " including its extension" \
                              " (q to quit):")
            if fname != 'q':
                H.read_CFG(fname)
                print "The joint angles in",fname,".pickle have been loaded."

        # FORMAT INPUT MEASUREMENTS FOR ISEG FORTRAN CODE
        elif userIn == 's':
            fname = raw_input("Enter the file name to which you would like" \
                              " to write the ISEG input: ")
            if H.write_meas_for_ISEG(fname) == 0:
                print "Success!"
            else:
                print "Uh oh, there was an error when trying to write",\
                       "the ISEG input."

        # TRANSFORM COORDINATE SYSTEM
        elif userIn == 't':
            print "Transforming absolute/base/fixed coordinate system."
            print "First we will rotate the yeadon coordinate system " \
                  "with respect to your new, desired coordinate system. " \
                  "We will first rotate about your x-axis, then your " \
                  "y-axis, then your z-axis."
            thetx = raw_input("Angle (rad) about your x-axis: ")
            thety = raw_input("Angle (rad) about your y-axis: ")
            thetz = raw_input("Angle (rad) about your z-axis: ")
            H.rotate_coord_sys(inertia.rotate_space_123(thetx,thety,thetz))
            print "Now we'll specify the position of yeadon with respect to " \
                  "your coordinate system. You will provide the three " \
                  "components, x y and z, in YOUR coordinates."
            posx = raw_input("X-position (m): ")
            posy = raw_input("Y-position (m): ")
            posz = raw_input("Z-position (m): ")
            H.translate_coord_sys( (posx,posy,posz) )
            print "All done!"

        # DRAW HUMAN WITH MAYAVI
        elif userIn == 'd':
            H.draw()

        # PRINT HUMAN PROPERTIES
        elif userIn == 'h':
            print "\nHuman properties."
            H.print_properties()

        # PRINT SEGMENT PROPERTIES
        elif userIn == 'g':
            print_segment_properties(H)

        # PRINT SOLID PROPERTIES
        elif userIn == 'l':
            print_solid_properties(H)

        # COMBINE INERTIA PARAMETERS
        elif userIn == 'c':
            print "Use the following variables/keywords to select which" \
                  " solids/segments to combine: "
            print "     s0 - s7, a0 - a6, b0 - b6, j0 - j8, k0 - k8"
            print "     P, T, C, A1, A2, B1, B2, J1, J2, K1, K2\n"
            print "Enter in the keywords one at a time. When you are " \
                  "done, enter q."
            combinedone = False
            combinectr = 1
            objlist = []
            while combinedone == False:
                objtemp = raw_input('Solid/segment #' + str(combinectr) + ': ')
                if objtemp == 'q':
                    combinedone = True
                else:
                    objlist.append(objtemp)
                    combinectr += 1
            print "Okay, get ready for your results (mass, COM, Inertia)!"
            combineMass,combineCOM,combineInertia = H.combine_inertia(objlist)
            print "These values are with respect to your fixed frame."
            print "Mass (kg):", combineMass
            print "COM (m):\n", combineCOM
            print "Inertia (kg-m^2):\n", combineInertia

        # OPTIONS
        elif userIn == 'o':
            optionsdone = 0
            sym = ('off','on')
            while optionsdone != 1:
                print "\nOPTIONS"
                print "-------"
                print "  1: toggle symmetry (symmetry is",\
                       sym[ int(H.is_symmetric) ],"now)\n", \
                      "  2: scale human by mass\n", \
                      "  q: back to main menu"
                optionIn = raw_input("What would you like to do? ")
                if optionIn == '1':
                    if H.is_symmetric == True:
                        H.is_symmetric = False
                        H.meas = meas
                    elif H.is_symmetric == False:
                        H.is_symmetric = True
                        H._average_limbs()
                    H.update()
                    print "Symmetry is now turned", sym[int(H.is_symmetric)], "."
                elif optionIn == '2':
                    measmass = raw_input("Provide a measured mass with which "\
                               "to scale the human (kg): ")
                    H.scale_human_by_mass(float(measmass))
                elif optionIn == 'q':
                    print "Going back to main menu."
                    optionsdone = 1
                else:
                    print "Invalid input."
        elif userIn == 'q':
            print "Quitting YEADON"
            done = 1
        else:
            print "Invalid input."