예제 #1
0
 def getSound(self, port):
     if self._bricks:
         try:
             port = int(port)
         except:
             pass
         if (port in NXT_SENSOR_PORTS):
             try:
                 port_aux = NXT_SENSOR_PORTS[port]
                 sensor = Sound(self._bricks[self.active_nxt], port_aux)
                 return sensor.get_sample()
             except:
                 return ERROR
         else:
             raise logoerror(ERROR_PORT_S % port)
     else:
         raise logoerror(ERROR_BRICK)
예제 #2
0
    def __init__(self, brick='NXT'):
        r'''Creates a new Alpha Rex controller.
        
            brick
                Either an nxt.brick.Brick object, or an NXT brick's name as a
                string. If omitted, a Brick named 'NXT' is looked up.
        '''
        if isinstance(brick, str):
            brick = find_one_brick(name=brick)

        self.brick = brick
        self.arms = Motor(brick, PORT_A)
        self.legs = [Motor(brick, PORT_B), Motor(brick, PORT_C)]

        self.touch = Touch(brick, PORT_1)
        self.sound = Sound(brick, PORT_2)
        self.light = Light(brick, PORT_3)
        self.ultrasonic = Ultrasonic(brick, PORT_4)
예제 #3
0
 def getSound(self, port):
     if self._bricks:
         try:
             port = int(port)
         except:
             pass
         if (port in NXT_SENSOR_PORTS):
             res = ERROR
             try:
                 port_aux = NXT_SENSOR_PORTS[port]
                 sensor = Sound(self._bricks[self.active_nxt], port_aux)
                 res = sensor.get_sample()
             except:
                 pass
             return res
         else:
             pass
     else:
         pass
예제 #4
0
    # 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, Sound

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)
sound = Sound(brick, PORT_1)
ultrasonic = Ultrasonic(brick, PORT_2)
compass = Ultrasonic(brick, PORT_3)

#TODO
# calibrate sleep times might need adjusting
# find bin is probably non functional, and VERY necessary (very short range when picking up bin)
# additional bin ID data to get more accurate values
# line follow data

# LINE FOLLOW VARIABLES
turningPower = 65  # 70, normalized, motor power used when turning in line follow
negInertiaPower = 70  # 65, normalized, motor power for negative inertia
findLineTimeOut = 0.5  # 0.5, time between switching motor to the opposite direction
negInertiaLengthOnWhite = 0.07  # 0.2, time before braking on negative inertia when originally on white
negInertiaLengthOnBlack = 0.07  # 0.05, time before braking on ngative inertia when originally on black (should be smaller than white to prevent overshooting the line)