def kinematics_pickle(rname, dh, constants, pvals, vv, unks, test): # # Check for a pickle file of combined pre-computed Mech and Robot objects # pickle_dir = 'fk_eqns/' if not os.path.isdir(pickle_dir): # if this doesn't exist, create it. print 'Creating a new pickle directory: ./'+pickle_dir os.mkdir(pickle_dir) name = pickle_dir + rname + '_pickle.p' print 'kinematics pickle: trying to open ', name,' in ', os.getcwd() if(os.path.isfile(name)): with open(name, 'rb') as pick: print '\Trying to read pre-computed forward kinematics from '+name [m, R, unknowns] = pickle.load(pick) print 'Successfully read pre-computed forward kinematics' print 'pickle contained ', len(unknowns), ' unknowns' else: #print 'WRONG - quitting, error: ',sys.exc_info()[0] #sys.exit # set up mechanism object instance m = kc.mechanism(dh, constants, vv) m.pvals = pvals # store numerical values of parameters print 'Did not find VALID stored pickle file: ', name print "Starting Forward Kinematics" m.forward_kinematics() print "Completed Forward Kinematics" print 'Starting Sum of Angles scan (slow!)' # set up Robot Object instance R = Robot(m, rname) # set up IK structs etc R.scan_for_equations(unks) # generate equation lists # below is commented out for testing and devel of sum_of_angles_transform R.sum_of_angles_transform(unks) # find sum of angles R.generate_solution_nodes(unks) # generate solution nodes print ' Storing kinematics pickle for '+rname + '('+name+')' with open(name,'wb') as pf: pickle.dump( [m, R, unks], pf, protocol=pprotocol) unknowns = unks # be sure to return updated unknown list (including SOAs) return [m,R,unknowns]
def kinematics_pickle(rname, dh, constants, pvals, vv, unks, test): # # Check for a pickle file of combined pre-computed Mech and Robot objects # if test: # for some reason in unittest/module mode, default dir is changed upward os.chdir('IK-2') # correct this situation pickle_dir = 'fk_eqns/' if not os.path.isdir(pickle_dir): # if this doesn't exist, create it. os.mkdir(pickle_dir) name = pickle_dir + rname + '_pickle.p' try: with open(name, 'r') as pick: print '\nReading pre-computed forward kinematics\n' [m, R, unks] = pickle.load(pick) except: # set up mechanism object instance m = kc.mechanism(dh, constants, vv) m.pvals = pvals # store numerical values of parameters print 'Did not find stored pickle file: ', name print "Starting Forward Kinematics" m.forward_kinematics() print "Completed Forward Kinematics" print 'Starting Sum of Angles scan (slow!)' # set up Robot Object instance R = Robot(m, rname) # set up IK structs etc R.scan_for_equations(unks) # generate equation lists #R.sum_of_angles_transform(unks) # find sum of angles R.generate_solution_nodes(unks) # generate solution nodes print ' Storing results' with open(name,'wb') as pf: pickle.dump( [m, R, unks], pf) return [m,R,unks]