# tried to use ultrasonic sensors to detect how far away a wall was, didn't go too well
    # distance_cm = robot.get_sensor_value(Data.ULTRASONIC) - 10 #so that the robot doesn't HIT the wall
    # print(distance_cm)

    robot.setup_wait(WaitType.DISTANCE, distance_cm * 1000)
    robot.move(MotorDirection.FORWARD, MotorDirection.FORWARD, 1, 1, True)

    robot.deactivate_motors()
    robot.disconnect()


# If we are on the main thread, run the program
if __name__ == "__main__":

    try:
        main()
    except:
        LocoRobo.stop()
        raise

    LocoRobo.stop()

    # For compatibility with webapp's python, we can't use finally.
    # If you are using local python, you can do the following
    #
    # try:
    #     main()
    # finally:
    #     LocoRobo.stop()
Beispiel #2
0
    robot.connect()
    robot.activate_motors()

    robot.enable_sensor(Data.ULTRASONIC, True)
    robot.enable_sensor(Data.ACCELEROMETER, True)
    robot.enable_sensor(Data.GYROSCOPE_RAW, True)
    robot.enable_sensor(Data.RUNNING_ENCODERS, True)

    while True:
        print(robot.get_sensor_value(Data.ULTRASONIC))
        print(robot.get_sensor_value(Data.ACCELEROMETER))
        print(robot.get_sensor_value(Data.GYROSCOPE_RAW))
        print(robot.get_sensor_value(Data.RUNNING_ENCODERS))
        time.sleep(0.1)

    robot.deactivate_motors()
    robot.disconnect()

    print('done')

# If we are on the main thread, run the program
if __name__ == "__main__":

    try:
        main()
    finally:
        # If the program has been stopped by the user, KeyboardInterrupt
        # Is thrown
        LocoRobo.stop()