print('Device with serial number ' + SN[count] + ' has been successfully set up') portaddr.append(deviceinfo.ser.port) x.append(opstruct(count, rt.K10CR1(deviceinfo.ser))) totnum += 1 trig = [] for count in range(4): xlist = [] for i in range(totnum): if x[i].trigport == count: xlist.append(i) trig.append(trigstruct(len(xlist), xlist, trigmenu[count])) lentrig = len(trig) ad = ads.ADS1256() #----------------------------------------------------------------------------- #main loop: mainloopflag = 1 totangle = [0, 0, 0, 0] error = 0 integral = 0 output = 0 calcount = 0 fullflag = [0, 0, 0, 0] odata = [0, 0, 0, 0] ndata = [0, 0, 0, 0] esign = [1, 1, 1, 1] error_array = [0, 0, 0, 0]
chan = 'xyz' for arg in sys.argv: arg = arg.strip() if arg.find('n=') == 0: N = int(arg.replace('n=', '')) if arg.find('ch=') == 0: chan = arg.replace('ch=', '') if arg.find('g=') == 0: vgain = int(arg.replace('g=', '')) if vgain > 6: vgain = 0 ADC = ADS1256.ADS1256() ADC.initADC(vgain, 0x82) ADC.setMode(1) vx = 0 vy = 0 vz = 0 for i in range(10): ADC.getValue(0) ADC.getValue(1) ADC.getValue(2) #time.sleep(1) for i in range(N):
def run(self): ads1256_controller = ADS1256.ADS1256() ads1256_controller.ADS1256_Init() ad_controller = AD_controller.AD_controller(self.game_dot_queue, ads1256_controller) ad_controller.start() # producer-consumer queue for AD input for tablet and joystick # joystick_x_queue = queue.Queue() # joystick_y_queue = queue.Queue() # 注册GPIO: 电机-2-OUT,霍尔开关-2-IN,平板-2-OUT GPIO.setup(self.HALL_1_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(self.HALL_2_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.add_event_detect( self.HALL_1_PIN, GPIO.RISING, callback=self.hall_1_callback) # 会为回调函数另外开启一个线程,与主程序并发运行 GPIO.add_event_detect(self.HALL_2_PIN, GPIO.RISING, callback=self.hall_2_callback) self.hall_1_target = self.hall_1_counter self.hall_2_target = self.hall_2_counter HALL_1_MAX = 50 HALL_2_MAX = 50 JOYSTICK_X_MAX = 8388607 JOYSTICK_X_MIN = 28500 JOYSTICK_Y_MAX = 8388607 JOYSTICK_Y_MIN = 28500 JOYSTICK_X_MID = 4451000 JOYSTICK_Y_MID = 4397000 joystick_x = 0 joystick_y = 0 loop_count = 0 while True: # 0:jx, 1:jy, 2:h1t, 3:h1c, 4:h2t, 5:h2c, 6:m1, 7:m2, 8:loop_time status = [0, 0, 0, 0, 0, 0, 0, 0, 0] time_3 = time.time() ''' if (not joystick_x_queue.empty()) and (not joystick_y_queue.empty()): joystick_x = joystick_x_queue.get() # print("joystick_x = ", joystick_x) joystick_y = joystick_y_queue.get() # print("joystick_y = ", joystick_y) # 计算所需脉冲值 self.hall_1_target = (joystick_x - JOYSTICK_X_MIN - JOYSTICK_X_MID) / ( JOYSTICK_X_MAX - JOYSTICK_X_MIN) * HALL_1_MAX self.hall_2_target = (joystick_y - JOYSTICK_Y_MIN - JOYSTICK_Y_MID) / ( JOYSTICK_Y_MAX - JOYSTICK_Y_MIN) * HALL_2_MAX # print("In Master_controller, hall_1_target = ", int(hall_1_target), ", hall_2_target = ", int(hall_2_target)) # print("In Master_controller, hall_1_counter = ", self.hall_1_counter, ", hall_2_counter = ", self.hall_2_counter) ''' joystick_x = ads1256_controller.ADS1256_GetoneChannel(3) joystick_y = ads1256_controller.ADS1256_GetoneChannel(4) status[0] = joystick_x status[1] = joystick_y self.hall_1_target = int( (joystick_x - JOYSTICK_X_MIN - JOYSTICK_X_MID) / (JOYSTICK_X_MAX - JOYSTICK_X_MIN) * HALL_1_MAX) self.hall_2_target = int( (joystick_y - JOYSTICK_Y_MIN - JOYSTICK_Y_MID) / (JOYSTICK_Y_MAX - JOYSTICK_Y_MIN) * HALL_2_MAX) status[2] = self.hall_1_target status[4] = self.hall_2_target # 驱动电机 status[3] = self.hall_1_counter if status[3] < (self.hall_1_target - 1): cur_time = time.time() status[6] = 1 if (self.motor_1_direction == 2): self.motor.Stop_1() self.Last_direction_x = 2 self.motor_1_direction = 0 self.time_1 = time.time() status[6] = 2 elif not (self.Last_direction_x == 2 and cur_time - self.time_1 < 0.1): self.motor.Go_1() self.motor_1_direction = 1 self.Last_direction_x = 0 status[6] = 3 elif status[3] > (self.hall_1_target + 1): cur_time = time.time() status[6] = 4 if (self.motor_1_direction == 1): self.motor.Stop_1() self.Last_direction_x = 1 self.motor_1_direction = 0 self.time_1 = time.time() status[6] = 5 elif not (self.motor_1_direction == 1 and cur_time - self.time_1 < 0.1): self.motor.Back_1() self.motor_1_direction = 2 self.Last_direction_x = 0 status[6] = 6 else: # if self.my_equal(self.hall_1_counter, self.hall_1_target): self.motor.Stop_1() status[6] = 7 if (self.motor_1_direction != 0): self.Last_direction_x = self.motor_1_direction self.motor_1_direction = 0 self.time_1 = time.time() status[6] = 8 status[5] = self.hall_2_counter if status[5] < (self.hall_2_target - 1): cur_time = time.time() status[7] = 1 if (self.motor_2_direction == 2): self.motor.Stop_2() self.Last_direction_y = 2 self.motor_2_direction = 0 self.time_2 = time.time() status[7] = 2 elif not (self.motor_2_direction == 2 and cur_time - self.time_2 < 0.1): self.motor.Go_2() self.motor_2_direction = 1 self.Last_direction_y = 0 status[7] = 3 elif status[5] > (self.hall_2_target + 1): cur_time = time.time() status[7] = 4 if (self.motor_2_direction == 1): self.motor.Stop_2() self.Last_direction_y = 1 self.motor_2_direction = 0 self.time_2 = time.time() status[7] = 5 elif not (self.motor_2_direction == 1 and cur_time - self.time_2 < 0.1): self.motor.Back_2() self.motor_2_direction = 2 self.Last_direction_y = 0 status[7] = 6 else: # if self.my_equal(self.hall_2_counter, self.hall_2_target): self.motor.Stop_2() status[7] = 7 if (self.motor_2_direction != 0): self.Last_direction_y = self.motor_2_direction self.motor_2_direction = 0 self.time_2 = time.time() status[7] = 8 status[8] = round(time.time() - time_3, 5) # status[9] = round(time.time(), 5) print(status)
def __init__(self): threading.Thread.__init__(self) self.ads1256 = ADS1256.ADS1256()
def __init__(self, master=None): """ This will create the window, labels and buttons required. """ self.master = master self.master.title("Tag Tester") self.master.geometry("480x650") self.vbatt = StringVar() self.vmcu = StringVar() self.vreg = StringVar() self.led_low = StringVar() self.led_high = StringVar() self.vbatt_sense_low = StringVar() self.vbatt_sense_high = StringVar() self.bleeding_low = StringVar() self.bleeding_high = StringVar() self.currentAction = StringVar() self.reset_time = StringVar() self.vbatt2 = StringVar() self.cnew = StringVar() self.cprogmin = StringVar() self.cprogmax = StringVar() self.ccharge = StringVar() self.vcoil = StringVar() self.vbatt.set("0 V") self.vmcu.set("0 V") self.vreg.set("0 V") self.led_low.set("0 V") self.led_high.set("0 V") self.vbatt_sense_low.set("0 V") self.vbatt_sense_high.set("0 V") self.bleeding_low.set("0 V") self.bleeding_high.set("0 V") self.reset_time.set("0 mS") self.vcoil.set("0 V") self.vbatt2.set("0 V") self.cnew.set("0 mA") self.cprogmin.set("0 mA") self.cprogmax.set("0 mA") self.ccharge.set("0 mA") self.currentAction.set("Press Start Test to begin") #Serial number entry x = 0 y = 0 self.el1 = Label(self.master, text="Serial Number") self.el1.grid(row=y, column=x, pady=5) x = 1 self.e1 = Entry(self.master) self.e1.grid(row=y, column=x) ########################################################################################## #read current button x = 1 y = 1 self.b1 = Button(self.master, text="Read initial current", command=self.readcurrent) #self.b1=Button(self.master, text="Read initial current", command=self.read_samplecurrent) self.b1.grid(row=y, column=x, pady=10) #current reading display x = 0 y = 2 self.l13x = Label(self.master, text="Current new") self.l13x.grid(row=y, column=x) x = 1 self.ll13x = Label(self.master, text=" ") self.ll13x.grid(row=y, column=x) x = 2 self.lll13x = Label(self.master, textvariable=self.cnew) self.lll13x.grid(row=y, column=x) #start test button x = 1 y = 3 self.b1 = Button(self.master, text="Start Test", command=self.startTest) self.b1.grid(row=y, column=x, pady=5) x = 0 y = 4 self.d1 = Label(self.master, textvariable=self.currentAction) self.d1.grid(row=y, column=x, columnspan=4, pady=5) tabley = 5 #First column self.l0 = Label(self.master, text="SIGNAL") self.l1 = Label(self.master, text="Vbatt ") self.l2 = Label(self.master, text="Vmcu") self.l3 = Label(self.master, text="Vreg") self.l4 = Label(self.master, text="PF6 led low") self.l5 = Label(self.master, text="PF6 led high") self.l6 = Label(self.master, text="PC10 vbatt sense low") self.l7 = Label(self.master, text="PC10 vbatt sense high") self.l8 = Label(self.master, text="PA4 bleeding low") self.l9 = Label(self.master, text="PA4 bleeding high") self.l10 = Label(self.master, text="Reset timing") self.l11 = Label(self.master, text="Vcoil") self.l12 = Label(self.master, text="Charging Voltage") self.l13 = Label(self.master, text="Current prog min") self.l14 = Label(self.master, text="Current prog max") self.l15 = Label(self.master, text="Current charging") x = 0 y = tabley self.l0.grid(row=y, column=x) y += 1 self.l1.grid(row=y, column=x) y += 1 self.l2.grid(row=y, column=x) y += 1 self.l3.grid(row=y, column=x) y += 1 self.l4.grid(row=y, column=x) y += 1 self.l5.grid(row=y, column=x) y += 1 self.l6.grid(row=y, column=x) y += 1 self.l7.grid(row=y, column=x) y += 1 self.l8.grid(row=y, column=x) y += 1 self.l9.grid(row=y, column=x) y += 1 self.l10.grid(row=y, column=x) y += 1 self.l11.grid(row=y, column=x) y += 1 self.l12.grid(row=y, column=x) y += 1 self.l13.grid(row=y, column=x) y += 1 self.l14.grid(row=y, column=x) y += 1 self.l15.grid(row=y, column=x) #Second column self.ll0 = Label(self.master, text="Pass Criteria") self.ll1 = Label(self.master, text="3.0-4.2 V") self.ll2 = Label(self.master, text="3.2-3.4 V") self.ll3 = Label(self.master, text="1.7-1.9 V") self.ll4 = Label(self.master, text="<500 mV") self.ll5 = Label(self.master, text=">2.7 V") self.ll6 = Label(self.master, text="<500 mV") self.ll7 = Label(self.master, text=">2.7 V") self.ll8 = Label(self.master, text="<500 mV") self.ll9 = Label(self.master, text=">2.7 V") self.ll10 = Label(self.master, text=">5 mS") self.ll11 = Label(self.master, text="4.9-5.1 V") self.ll12 = Label(self.master, text="4.0-4.2 V") self.ll13 = Label(self.master, text=" ") self.ll14 = Label(self.master, text=" ") self.ll15 = Label(self.master, text=" ") x = 1 y = tabley self.ll0.grid(row=y, column=x) y += 1 self.ll1.grid(row=y, column=x) y += 1 self.ll2.grid(row=y, column=x) #Vcoil y += 1 self.ll3.grid(row=y, column=x) y += 1 self.ll4.grid(row=y, column=x) y += 1 self.ll5.grid(row=y, column=x) y += 1 self.ll6.grid(row=y, column=x) y += 1 self.ll7.grid(row=y, column=x) y += 1 self.ll8.grid(row=y, column=x) y += 1 self.ll9.grid(row=y, column=x) y += 1 self.ll10.grid(row=y, column=x) y += 1 self.ll11.grid(row=y, column=x) y += 1 self.ll12.grid(row=y, column=x) y += 1 self.ll13.grid(row=y, column=x) y += 1 self.ll14.grid(row=y, column=x) y += 1 self.ll15.grid(row=y, column=x) #Third column self.lll0 = Label(self.master, text="Actual Value") self.lll1 = Label(self.master, textvariable=self.vbatt) self.lll2 = Label(self.master, textvariable=self.vmcu) self.lll3 = Label(self.master, textvariable=self.vreg) self.lll4 = Label(self.master, textvariable=self.led_low) self.lll5 = Label(self.master, textvariable=self.led_high) self.lll6 = Label(self.master, textvariable=self.vbatt_sense_low) self.lll7 = Label(self.master, textvariable=self.vbatt_sense_high) self.lll8 = Label(self.master, textvariable=self.bleeding_low) self.lll9 = Label(self.master, textvariable=self.bleeding_high) self.lll10 = Label(self.master, textvariable=self.reset_time) self.lll11 = Label(self.master, textvariable=self.vcoil) self.lll12 = Label(self.master, textvariable=self.vbatt2) self.lll13 = Label(self.master, textvariable=self.cprogmin) self.lll14 = Label(self.master, textvariable=self.cprogmax) self.lll15 = Label(self.master, textvariable=self.ccharge) x = 2 y = tabley self.lll0.grid(row=y, column=x) y += 1 self.lll1.grid(row=y, column=x) y += 1 self.lll2.grid(row=y, column=x) y += 1 self.lll3.grid(row=y, column=x) y += 1 self.lll4.grid(row=y, column=x) y += 1 self.lll5.grid(row=y, column=x) y += 1 self.lll6.grid(row=y, column=x) y += 1 self.lll7.grid(row=y, column=x) y += 1 self.lll8.grid(row=y, column=x) y += 1 self.lll9.grid(row=y, column=x) y += 1 self.lll10.grid(row=y, column=x) y += 1 self.lll11.grid(row=y, column=x) y += 1 self.lll12.grid(row=y, column=x) y += 1 self.lll13.grid(row=y, column=x) y += 1 self.lll14.grid(row=y, column=x) y += 1 self.lll15.grid(row=y, column=x) #Fourth column self.llll0 = Label(self.master, text="Pass / Fail") self.llll1 = Label(self.master, text=" ", bg="white") self.llll2 = Label(self.master, text=" ", bg="white") self.llll3 = Label(self.master, text=" ", bg="white") self.llll4 = Label(self.master, text=" ", bg="white") self.llll5 = Label(self.master, text=" ", bg="white") self.llll6 = Label(self.master, text=" ", bg="white") self.llll7 = Label(self.master, text=" ", bg="white") self.llll8 = Label(self.master, text=" ", bg="white") self.llll9 = Label(self.master, text=" ", bg="white") self.llll10 = Label(self.master, text=" ", bg="white") self.llll11 = Label(self.master, text=" ", bg="white") self.llll12 = Label(self.master, text=" ", bg="white") x = 3 y = tabley self.llll0.grid(row=y, column=x) y += 1 self.llll1.grid(row=y, column=x) y += 1 self.llll2.grid(row=y, column=x) y += 1 self.llll3.grid(row=y, column=x) y += 1 self.llll4.grid(row=y, column=x) y += 1 self.llll5.grid(row=y, column=x) y += 1 self.llll6.grid(row=y, column=x) y += 1 self.llll7.grid(row=y, column=x) y += 1 self.llll8.grid(row=y, column=x) y += 1 self.llll9.grid(row=y, column=x) y += 1 self.llll10.grid(row=y, column=x) y += 1 self.llll11.grid(row=y, column=x) y += 1 self.llll12.grid(row=y, column=x) y += 6 self.exit = Button( self.master, text="Exit", command=self.master.destroy) #.pack(side="top",pady=40) self.exit.grid(row=y, column=1, pady=5) self.ADC = ADS1256.ADS1256() self.ADC.ADS1256_init() self.relaywirelesscharge = 24 self.relaybatt = 23 self.reset = 27