示例#1
0
文件: solid.py 项目: agcooke/yeadon
    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 anterior-posteriorly, the inertia is rotated
        by pi/2 about the z axis.

        '''
        D = self.density
        h = self.height
        r0 = self.stads[0].radius
        t0 = self.stads[0].thick
        r1 = self.stads[1].radius
        t1 = self.stads[1].thick
        a = (r1 - r0) / r0
        if (t0 == 0):
            b = 1.0
        else:
            b = (t1 - t0) / t0 # DOES NOT WORK FOR CIRCLES!!!
        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
        self.relCOM = np.array([[0.0],[0.0],[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 )
        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)))
        # CAUGHT AN (minor) ERROR IN YEADON'S PAPER HERE
        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.relInertia = np.mat([[Ixcom,0.0,0.0],
                                  [0.0,Iycom,0.0],
                                  [0.0,0.0,Izcom]])
        if self.alignment == 'AP':
            # rearrange to anterior-posterior orientation
            self.relInertia = inertia.rotate3_inertia(
                              inertia.rotate3([0,0,np.pi/2]),self.relInertia)
示例#2
0
文件: ui.py 项目: StefenYin/yeadon
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 "MEASUREMENTS: can be provided as a 95-field dict (units must be " \
          "meters), or a .TXT file"
    temp = raw_input("Type the name of the dict variable "\
                     "or the .TXT filename (to use preloaded measurements," \
                     " just hit enter): ")
    if temp == '':
        meas = measPreload
    else:
        meas = temp
    print "CONFIGURATION (joint angles): can be provided as a 21-field dict,"\
          " or a .TXT file"
    CFG = raw_input("Type the name of the dict variable "\
                    "or 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:
        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 using matplotlib\n",\
              "  v: draw 3D human using VPython\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.rotate3(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 MATPLOTLIB
        elif userIn == 'd':
            print "To continue using the YEADON UI after drawing,",\
                   "close the plot window."
            H.draw()

        # DRAW HUMAN WITH VPYTHON
        elif userIn == 'v':
            H.draw_visual()

        # 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.isSymmetric) ],"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.isSymmetric == True:
                        H.isSymmetrc = False
                        H.meas = meas
                    elif H.isSymmetric == False:
                        H.isSymmetric = True
                        H.average_limbs()
                    H.update_solids()
                    print "Symmetry is now turned",sym,"."
                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."