dxax = -int(binascii.b2a_hex(ser.read()).decode('utf-8'), 16) if dxax <= -128: dxax = dxax + 256 #print('[A B C D : X Y] = [' + str(btn[0]) + ' ' + str(btn[1]) + ' ' + str(btn[2]) + ' ' + str(btn[3]) + ' : ' + str(dxax) + ' ' + str(dyax)+ ']') elif dtyp == '11': #print('Idle') val = ser.read() val = ser.read() if dxax > 8 and dxax_old <= 8: gb.move_stepper(BOARD_A, STEPPER_A, -20000) print('Forward') elif dxax < -8 and dxax_old >= -8: gb.move_stepper(BOARD_A, STEPPER_A, 20000) print('Backword') elif abs(dxax) <= 8 and abs(dxax_old) > 8: gb.stop_stepper(BOARD_A, STEPPER_A, 1) print('Stop') if dyax > 8 and dyax_old <= 8: gb.move_stepper(BOARD_B, STEPPER_B, -20000) gb.move_stepper(BOARD_B, STEPPER_C, 20000) print('Left') elif dyax < -8 and dyax_old >= -8: gb.move_stepper(BOARD_B, STEPPER_B, 20000) gb.move_stepper(BOARD_B, STEPPER_C, -20000) print('Right') elif abs(dyax) <= 8 and abs(dyax_old) > 8: gb.stop_stepper(BOARD_B, STEPPER_B, 1) gb.stop_stepper(BOARD_B, STEPPER_C, 1) print('Stop') dxax_old = dxax dyax_old = dyax
gb.move_brushed(BOARD, BRS_A, BACKW) #print('[A B C D : X Y] = [' + str(btn[0]) + ' ' + str(btn[1]) + ' ' + str(btn[2]) + ' ' + str(btn[3]) + ' : ' + str(dxax) + ' ' + str(dyax)+ ']') elif dtyp == '08': dyax_old = dyax dxax_old = dxax val = ser.read() dyax = -int(binascii.b2a_hex(ser.read()).decode('utf-8'), 16) if dyax <= -128: dyax = dyax + 256 dxax = -int(binascii.b2a_hex(ser.read()).decode('utf-8'), 16) if dxax <= -128: dxax = dxax + 256 #print('[A B C D : X Y] = [' + str(btn[0]) + ' ' + str(btn[1]) + ' ' + str(btn[2]) + ' ' + str(btn[3]) + ' : ' + str(dxax) + ' ' + str(dyax)+ ']') elif dtyp == '11': #print('Idle') val = ser.read() val = ser.read() if dxax > 8 and dxax_old <= 8: gb.move_stepper(BOARD, STEPPER_B, -20000) print('Forward') elif dxax < -8 and dxax_old >= -8: gb.move_stepper(BOARD, STEPPER_B, 20000) print('Backword') elif abs(dxax) <= 8 and abs(dxax_old) > 8: gb.stop_stepper(BOARD, STEPPER_B, 1) print('Stop') dxax_old = dxax dyax_old = dyax gb.emergency_stop()