def motorposition(self, port): if self._bricks: port = str(port) port_up = port.upper() if (port_up in NXT_MOTOR_PORTS): port = NXT_MOTOR_PORTS[port_up] try: m = Motor(self._bricks[self.active_nxt], port) t = m.get_tacho() previous = self._motor_pos[port_up][self.active_nxt] return (t.tacho_count - previous) except: raise logoerror(ERROR_GENERIC) else: raise logoerror(ERROR_PORT_M % port) else: raise logoerror(ERROR_BRICK)
def motorreset(self, port): if self._bricks: port = str(port) port_up = port.upper() if (port_up in NXT_MOTOR_PORTS): port = NXT_MOTOR_PORTS[port_up] try: m = Motor(self._bricks[self.active_nxt], port) t = m.get_tacho() self._motor_pos[port_up][self.active_nxt] = t.tacho_count m.idle() except: raise logoerror(ERROR_GENERIC) else: raise logoerror(ERROR_PORT_M % port) else: raise logoerror(ERROR_BRICK)
useUSB = False if useUSB: brick = nxt.find_one_brick(name=brickName, strict=True, method=nxt.locator.Method(usb=True, bluetooth=True)) else: # the bluetooth function of the nxt library works too, but "wastes" # time searching for devices. brick = nxtConnect.btConnect(brickName) print(brick.get_device_info()) # check what brick you connected to from time import sleep from nxt.motor import Motor, PORT_A, PORT_B, PORT_C from nxt.sensor import Touch, PORT_4, PORT_3, PORT_2, Light, PORT_1, Ultrasonic #from basicFunctions import step, calibrate light = Light(brick, PORT_4) turningMotor = Motor(brick, PORT_B) walkingMotor = Motor(brick, PORT_C) armMotor = Motor(brick, PORT_A) touch = Touch(brick, PORT_1) #ultrasonic = Ultrasonic(brick, PORT_2) #compass = Ultrasonic(brick, PORT_3) while True: print(armMotor.get_tacho().tacho_count)
# the bluetooth function of the nxt library works too, but "wastes" # time searching for devices. brick = nxtConnect.btConnect(brickName) print(brick.get_device_info()) # check what brick you connected to from time import sleep from nxt.sensor import Light from nxt.sensor.hitechnic import Gyro from nxt.sensor import PORT_1, PORT_2 from nxt.motor import Motor, PORT_A, PORT_B, PORT_C motor = Motor(brick, PORT_C) light = Light(brick, PORT_2) motor.reset_position(False) print(motor.get_tacho()) black = light.get_lightness() print("black = ", black) motor.turn(30, 50, brake=True, timeout=1.5, emulate=True) sleep(0.05) print(motor.get_tacho()) motor.brake() white = light.get_lightness() print("white = ", white) motor.turn(-30, 50, brake=True, timeout=1.5, emulate=True) threshold = (black + white) / 2 print(motor.get_tacho()) print("Threshold = ", threshold) while light.get_lightness() < 1020: light.get_lightness()