def fill_cells_random(): scope=m3t.M3Scope2(xwidth=100,yrange=None) ns=30#5#K*2 #Build desired vector log={'ns':ns,'type':'fill_cells_random', 'actuator':'MA12J1','L':L,'K':K,'CW':cw,'a':list(a),'b':list(b),'u_max':u_max,'u_min':u_min,'ut':[],'wt':[],'gt':[],'des':[]} des=[u_min] for nn in range(ns): while True: x=u_min+(u_max-u_min)*(random.random()) #randomly in range if abs(des[-1]-x)>5*cw: #make excursion at least 5 cells des.append(x) break log['des']=des print 'Des',des print 'Enable power. Hit enter to continue' raw_input() for ii in range(len(des)): print ii,'Des: ',des[ii] uu,ww,gg=ramp_to_torque(des[ii],scope) print len(uu),len(ww),len(gg) log['ut'].append(list(uu)) #input log['wt'].append(list(ww)) #output log['gt'].append(list(gg)) #hysteron states print 'Save data [y]?' if m3t.get_yes_no('y'): fn=m3t.get_m3_config_path()+'data/preisach_data_random_ma12j1_'+m3t.time_string()+'.yml' print 'Enter annotation string [None]' note=m3t.get_string('None') log['note']=note f=file(fn,'w') print 'Saving...',fn f.write(yaml.safe_dump(log, default_flow_style=False,width=200)) f.close() return log
def run(self): vias = {} for c in self.chains: vias[c] = [] while not self.done: print '--------------' print 'r: record via' print 's: save via file' print 'p: print current pose' print 'q: quit' print '--------------' print k = m3t.get_keystroke() print 'Dbg', dbg if k == 'r': print '-------------' for c in self.chains: vias[c].append(m3t.float_list(self.bot.get_theta_deg(c))) print 'Record of: ', vias[c][-1], 'for', c if k == 'p': print '----------------' for c in self.chains: print 'Chain:', c, ' : ', self.bot.get_theta_deg(c) print '----------------' if k == 's': bot_name = m3t.get_robot_name() fn = bot_name + '_' + m3t.time_string() print 'Enter via file name [', fn, ']' fn = m3t.get_string(fn) fn = m3t.get_m3_animation_path() + fn + '.via' print 'Writing file: ', fn f = file(fn, 'w') d = {} for c in self.chains: ndof = self.bot.get_num_dof(c) if c == 'torso': param = { 'slew': [1.0] * ndof, 'stiffness': [0.8] * ndof, 'velocity': [25.0, 15.0] } else: param = { 'slew': [1.0] * ndof, 'stiffness': [0.4] * ndof, 'velocity': [25.0] * ndof } d[c] = { 'postures': vias[c], 'param': param } #safe defaults f.write(yaml.safe_dump(d)) vias = {} for c in self.chains: vias[c] = [] if k == 'q': self.done = True
def fill_cells_random(): scope = m3t.M3Scope2(xwidth=100, yrange=None) ns = 30 #5#K*2 #Build desired vector log = { 'ns': ns, 'type': 'fill_cells_random', 'actuator': 'MA12J1', 'L': L, 'K': K, 'CW': cw, 'a': list(a), 'b': list(b), 'u_max': u_max, 'u_min': u_min, 'ut': [], 'wt': [], 'gt': [], 'des': [] } des = [u_min] for nn in range(ns): while True: x = u_min + (u_max - u_min) * (random.random()) #randomly in range if abs(des[-1] - x) > 5 * cw: #make excursion at least 5 cells des.append(x) break log['des'] = des print 'Des', des print 'Enable power. Hit enter to continue' raw_input() for ii in range(len(des)): print ii, 'Des: ', des[ii] uu, ww, gg = ramp_to_torque(des[ii], scope) print len(uu), len(ww), len(gg) log['ut'].append(list(uu)) #input log['wt'].append(list(ww)) #output log['gt'].append(list(gg)) #hysteron states print 'Save data [y]?' if m3t.get_yes_no('y'): fn = m3t.get_m3_config_path( ) + 'data/preisach_data_random_ma12j1_' + m3t.time_string() + '.yml' print 'Enter annotation string [None]' note = m3t.get_string('None') log['note'] = note f = file(fn, 'w') print 'Saving...', fn f.write(yaml.safe_dump(log, default_flow_style=False, width=200)) f.close() return log
def run(self): vias = {} for c in self.chains: vias[c] = [] while not self.done: print "--------------" print "r: record via" print "s: save via file" print "p: print current pose" print "q: quit" print "--------------" print k = m3t.get_keystroke() print "Dbg", dbg if k == "r": print "-------------" for c in self.chains: vias[c].append(m3t.float_list(self.bot.get_theta_deg(c))) print "Record of: ", vias[c][-1], "for", c if k == "p": print "----------------" for c in self.chains: print "Chain:", c, " : ", self.bot.get_theta_deg(c) print "----------------" if k == "s": bot_name = m3t.get_robot_name() fn = bot_name + "_" + m3t.time_string() print "Enter via file name [", fn, "]" fn = m3t.get_string(fn) fn = m3t.get_m3_animation_path() + fn + ".via" print "Writing file: ", fn f = file(fn, "w") d = {} for c in self.chains: ndof = self.bot.get_num_dof(c) if c == "torso": param = {"slew": [1.0] * ndof, "stiffness": [0.8] * ndof, "velocity": [25.0, 15.0]} else: param = {"slew": [1.0] * ndof, "stiffness": [0.4] * ndof, "velocity": [25.0] * ndof} d[c] = {"postures": vias[c], "param": param} # safe defaults f.write(yaml.safe_dump(d)) vias = {} for c in self.chains: vias[c] = [] if k == "q": self.done = True