示例#1
0
def main():
    uartComm = UARTDevice(Port.S2, 9600, 100)
    uartComm.clear()
    xlimits = [-310, 310]

    while True:
        reflection = light.reflection()
        try:
            data_raw = uartComm.read(24).decode().replace('B', '')
            data = ujson.loads(data_raw)
        except Exception as e:
            uartComm.clear()
            print(e)
            print('Read Failed')
            data = {'x': 0, 'y': 0}  #need this or robot.drive throws an error

        try:
            signal = reading(reflection)
            uartComm.write(signal)
            print(signal)  #prints json signal
        except Exception as e:
            print(e)
            print("Write Failed")
        #print(data['x'], data['y'])
        robot.drive(data['y'] / 2, 0)
        print(horz.angle())
        horiz_dist = data['x'] * (360 / 90)
        constrain(horiz_dist, xlimits)
        horz.run_target(100, horiz_dist)
示例#2
0
xBut = TouchSensor(Port.S1)
yBut = TouchSensor(Port.S2)

sense = AnalogSensor(Port.S3, False)
uart = UARTDevice(Port.S3, 9600, timeout=2000)


def VibrateMotor():
    joystick.run_angle(1400, 180)


def CompletionVibrate():
    indicator.run_time(1400, 700)


uart.clear()

while True:
    while not (xBut.pressed() | yBut.pressed()):
        wait(100)
        if uart.waiting() > 0:
            msg = uart.read(1)
            uart.clear()  #should clear automatically, but needed some help
            msg = str(msg)
            if msg[2] == 'T':
                VibrateMotor()
                print('|', end='')
            elif msg[2] == 'F':
                print('.', end='')
            elif msg[2] == 'C':
                CompletionVibrate()
示例#3
0
    motorA.track_target(-100)
    motorB.track_target(100)
    motorC.track_target(100)
    wait(1000)

    motorA.track_target(0)
    motorB.track_target(0)
    motorC.track_target(0)
    wait(200)
    motorD.track_target(0)
    wait(500)


# setup serial port
serial = UARTDevice(Port.S4, baudrate=9600, timeout=None)
serial.clear()
while (1):
    if SystemLink.Get_SL('Start27') == 'true':
        throw_ball()
        SystemLink.Put_SL('Start27', 'BOOLEAN', 'false')
    if touch1.pressed() == True:
        throw_ball()
        SystemLink.Put_SL('Start28', 'BOOLEAN', 'true')

    if len(ev3.buttons.pressed()) > 0:
        print("Catching Ball")
        wait(3000)
        motorD.track_target(40)

        # collect data from serial port and move armw
        while (1):