Пример #1
0
def run_test_arm():
    robot = rb.Snatch3rRobot()
    robot.arm.calibrate()
    time.sleep(1)
    robot.arm.raise_arm_and_close_claw()
    time.sleep(1)
    robot.arm.move_arm_to_position(300)
Пример #2
0
def run_test_ir():
    robot = rb.Snatch3rRobot()

    while True:
        # TODO: Print the value of the following, one at a time. For each,
        # TODO:   do the appropriate user actions (e.g. try pressing a button
        # TODO:   on the Beacon and see what the beacon_button_sensor produces).
        # TODO:   Discover what values the sensors produce in which situations.
        #    touch_sensor
        #    color_sensor
        #    camera
        #    proximity_sensor
        #    beacon_sensor  NOT YET IMPLEMENTED
        #    beacon_button_sensor  NOT YET IMPLEMENTED
        print("Beacon sensor:",
              robot.beacon_button_sensor.is_bottom_blue_button_pressed(),
              robot.beacon_button_sensor.is_bottom_red_button_pressed(),
              robot.beacon_button_sensor.is_top_blue_button_pressed(),
              robot.beacon_button_sensor.is_top_red_button_pressed(),
              robot.beacon_sensor.get_heading_to_beacon(),
              robot.beacon_sensor.get_distance_to_beacon())

        character = input(
            "Press the ENTER (return) key to continue, or q to quit: ")
        if character == "q":
            break
Пример #3
0
def main():

    robot = rb.Snatch3rRobot()

    rc = RemoteControlEtc(robot)
    mqtt_client = com.MqttClient(rc)
    mqtt_client.connect_to_pc()

    # --------------------------------------------------------------------------
    # TODO: 5. Add a class for your "delegate" object that will handle messages
    # TODO:    sent from the laptop.  Construct an instance of the class and
    # TODO:    pass it to the MqttClient constructor above.  Augment the class
    # TODO:    as needed for that, and also to handle the go_forward message.
    # TODO:    Test by PRINTING, then with robot.  When OK, delete this TODO.
    # --------------------------------------------------------------------------

    # --------------------------------------------------------------------------
    # TODO: 6. With your instructor, discuss why the following WHILE loop,
    # TODO:    that appears to do nothing, is necessary.
    # TODO:    When you understand this, delete this TODO.
    # --------------------------------------------------------------------------
    while True:
        # ----------------------------------------------------------------------
        # TODO: 7. Add code that makes the robot beep if the top-red button
        # TODO:    on the Beacon is pressed.  Add code that makes the robot
        # TODO:    speak "Hello. How are you?" if the top-blue button on the
        # TODO:    Beacon is pressed.  Test.  When done, delete this TODO.
        # ----------------------------------------------------------------------
        if robot.beacon_button_sensor.is_top_red_button_pressed() is True:
            ev3.Sound.beep().wait()
        if robot.beacon_button_sensor.is_top_blue_button_pressed() is True:
            ev3.Sound.speak('Hello. How are you?').wait()
        time.sleep(0.01)  # For the delegate to do its work
Пример #4
0
def main():
    """ Runs YOUR specific part of the project """
    print('hello')
    robot = rb.Snatch3rRobot()
    print('goodbye')
    #polyogon(robot, 4, 5)
    #follow_black_line(robot)
    #go_to_color(robot, 5)
    beep_when_in_front_of_camera(robot)
Пример #5
0
def detectItem():
    robot = rb.Snatch3rRobot()
    sensor = robot.proximity_sensor

    while True:
        if ((70 *
             ((sensor.get_distance_to_nearest_object()) / 100)) < 15) and (
                 (70 * ((sensor.get_distance_to_nearest_object()) / 100)) > 9):
            ev3.Sound.beep()
Пример #6
0
def line_follow():
    robot = rb.Snatch3rRobot()
    drivesystem = robot.drive_system
    colorsensor = robot.color_sensor
    drivesystem.start_moving()
    while True:
        if colorsensor.get_reflected_intensity() > 10:
            drivesystem.spin_in_place_degrees(10)
            drivesystem.start_moving(50, 50)
Пример #7
0
def drive_polygon(n, inches):
    x = rb.Snatch3rRobot()
    drivesystem = x.drive_system
    # degrees = ((n - 2) * 180) / n
    # degrees = 180 - degrees
    degrees = (360 / n)

    for k in range(n):
        drivesystem.go_straight_inches(inches)
        drivesystem.spin_in_place_degrees(-degrees)
Пример #8
0
def drive_until_color(color):
    robot = rb.Snatch3rRobot()
    drivesystem = robot.drive_system
    colorsensor = robot.color_sensor
    drivesystem.start_moving(50, 50)

    while True:
        colorsensor.wait_until_color_is(color)
        drivesystem.stop_moving()
        break
Пример #9
0
def main():
    """

    type: rb.Snatch3rRobot
    """
    print('running')
    speed = 100
    robot = rb.Snatch3rRobot()
    remote = Remote(robot, speed)
    client = com.MqttClient(remote)
    client.connect_to_pc()
    while True:
        pass
Пример #10
0
def run_test_touch_sensor():
    """ Tests the  touch_sensor  of the Snatch3rRobot. """
    robot = rb.Snatch3rRobot()

    print()
    print("Testing the  touch_sensor  of the robot.")
    print("Repeatedly press and release the touch sensor.")
    print("Press Control-C when you are ready to stop testing.")
    time.sleep(1)
    count = 1
    while True:
        print("{:4}.".format(count), "Touch sensor value is: ",
              robot.touch_sensor.get_value())
        time.sleep(0.5)
        count = count + 1
def main():

    robot = rb.Snatch3rRobot()

    rc = RemoteControlEtc(robot)
    george = com.MqttClient(rc)
    rc.mr = george
    george.connect_to_pc()

    while True:
        if robot.beacon_button_sensor.is_top_red_button_pressed():
            ev3.Sound.beep().wait()
        time.sleep(0.01)  # For the delegate to do its work
        if robot.beacon_button_sensor.is_top_blue_button_pressed():
            ev3.Sound.speak('You pressed the blue button')
Пример #12
0
def main():
    root = tkinter.Tk()

    mqtt_client = com.MqttClient()
    mqtt_client.connect_to_ev3()

    setup_gui(root, mqtt_client)

    root.mainloop()

    robot = rb.Snatch3rRobot()
    move_robot(robot)
    # stop_color = rb.Color.BLUE.value
    # move_until_color(stop_color)
    moving_arm_and_claw()
Пример #13
0
def main():

    robot = rb.Snatch3rRobot()

    rc = RemoteControlEtc(robot)
    mqtt_client = com.MqttClient(rc)
    mqtt_client.connect_to_pc()

    while True:
        if robot.beacon_button_sensor.is_top_red_button_pressed() is True:
            ev3.Sound.beep().wait()
        if robot.beacon_button_sensor.is_top_blue_button_pressed() is True:
            ev3.Sound.speak(
                'I love you bitch, I aint never gonna stop loving you, bitch'
            ).wait()
        time.sleep(0.01)  # For the delegate to do its work
def finding_object():
    robot=rb.Snatch3rRobot()
    print()
    print("Testing")
    time.sleep(2)
    print("Testing!")
    time.sleep(2)
    print("Ctrl-C to TERMINATE!! the program!!!!!")
    time.sleep(3)

    while True:
        if robot.camera.get_biggest_blob().get_area() >= 300:
            ev3.Sound.beep().wait()
            ev3.Sound.speak("It is huge").wait()
            break
    robot.drive_system.stop_moving()
Пример #15
0
def ColorSorting(red, white, yellow, black, green):
    robot = rb.Snatch3rRobot()
    colorsensor = robot.color_sensor
    drivesystem = robot.drive_system
    ev3.Sound.set_volume(100)
    drivesystem.start_moving(20, 20)

    while True:
        if colorsensor.get_color() == red:
            ev3.Sound.speak("Hello")
        if colorsensor.get_color() == white:
            ev3.Sound.speak("to")
        if colorsensor.get_color() == yellow:
            ev3.Sound.speak("the")
        if colorsensor.get_color() == black:
            ev3.Sound.speak("world")
        if colorsensor.get_color() == green:
            ev3.Sound.speak("Greetings humans")
Пример #16
0
def main():
    """ Runs YOUR specific part of the project """
    robot = rb.Snatch3rRobot()
    robot.arm.calibrate()
    rc = RemoteControlEtc(robot)
    mqtt_client = com.MqttClient(rc)
    mqtt_client.connect_to_pc()
    wait_for_ball(robot)
    hike_the_ball(robot)
    while True:
        if robot.color_sensor.green() > 70:
            run_off_blocker(robot)
        elif robot.color_sensor.red() > 70:
            spin_defender(robot)
        elif robot.color_sensor.blue() > 70:
            celebrate(robot)
            break
    time.sleep(10)
    robot.drive_system.stop_moving()
Пример #17
0
def run_test_color_sensor():
    """ Tests the  color_sensor  of the Snatch3rRobot. """
    robot = rb.Snatch3rRobot()

    print()
    print("Testing the  color_sensor  of the robot.")
    print("Repeatedly move the robot to different surfaces.")
    print("Press Control-C when you are ready to stop testing.")
    time.sleep(1)
    count = 1
    while True:
        print(
            "{:4}.".format(count), "Color sensor value/color/intensity is: ",
            "{:3} {:3} {:3}".format(robot.color_sensor.get_value()[0],
                                    robot.color_sensor.get_value()[1],
                                    robot.color_sensor.get_value()[2]),
            "{:4}".format(robot.color_sensor.get_color()),
            "{:4}".format(robot.color_sensor.get_reflected_intensity()))
        time.sleep(0.5)
        count = count + 1
Пример #18
0
def main():
    # --------------------------------------------------------------------------
    # Done: 3. Construct a Snatch3rRobot.  Test.
    # --------------------------------------------------------------------------
    robot = rb.Snatch3rRobot()
    # --------------------------------------------------------------------------
    # Done: 4. Add code that constructs a   com.MqttClient   that will
    # Done:    be used to receive commands sent by the laptop.
    # Done:    Connect it to this robot.  Test.
    # --------------------------------------------------------------------------
    rc = RemoteControlEtc(robot)
    mqtt_client = com.MqttClient(rc)
    mqtt_client.connect_to_pc()
    mario(robot)
    # --------------------------------------------------------------------------
    # Done: 5. Add a class for your "delegate" object that will handle messages
    # Done:    sent from the laptop.  Construct an instance of the class and
    # Done:    pass it to the MqttClient constructor above.  Augment the class
    # Dome:    as needed for that, and also to handle the go_forward message.
    # Done:    Test by PRINTING, then with robot.
    # --------------------------------------------------------------------------

    # --------------------------------------------------------------------------
    # Done: 6. With your instructor, discuss why the following WHILE loop,
    # Done:    that appears to do nothing, is necessary.
    # --------------------------------------------------------------------------
    while True:
        # ----------------------------------------------------------------------
        # Done: 7. Add code that makes the robot beep if the top-red button
        # Done:    on the Beacon is pressed.  Add code that makes the robot
        # Done:    speak "Hello. How are you?" if the top-blue button on the
        # Done:    Beacon is pressed.  Test.
        # ----------------------------------------------------------------------
        if robot.beacon_button_sensor.is_top_red_button_pressed():
            ev3.Sound.beep().wait()
        if robot.beacon_button_sensor.is_top_blue_button_pressed():
            ev3.Sound.speak("Hello")

        time.sleep(0.01)  # For the delegate to do its work
Пример #19
0
def run_test_drive_system():
    """ Tests the  drive_system  of the Snatch3rRobot. """
    robot = rb.Snatch3rRobot()

    print()
    print("Testing the  drive_system  of the robot.")
    print("Move at (20, 50) - that is, veer left slowly")
    robot.drive_system.start_moving(20, 50)
    time.sleep(2)
    robot.drive_system.stop_moving()

    print("Left/right wheel positions:",
          robot.drive_system.left_wheel.get_degrees_spun(),
          robot.drive_system.right_wheel.get_degrees_spun())

    time.sleep(1)
    print()
    print("Spin clockwise at half speed for 2.5 seconds")
    robot.drive_system.move_for_seconds(2.5, 50, -50)

    print("Left/right wheel positions:",
          robot.drive_system.left_wheel.get_degrees_spun(),
          robot.drive_system.right_wheel.get_degrees_spun())

    robot.drive_system.left_wheel.reset_degrees_spun()
    robot.drive_system.right_wheel.reset_degrees_spun(2000)

    time.sleep(1)
    print()
    print("Move forward at full speed for 1.5 seconds, coast to stop")
    robot.drive_system.start_moving()
    time.sleep(1.5)
    robot.drive_system.stop_moving(rb.StopAction.COAST.value)

    print("Left/right wheel positions:",
          robot.drive_system.left_wheel.get_degrees_spun(),
          robot.drive_system.right_wheel.get_degrees_spun())
def main():
    robot = rb.Snatch3rRobot()
Пример #21
0
def move_to_pose():
    robot = rb.Snatch3rRobot()
    robot.arm.move_arm_to_position(3600, 100)
Пример #22
0
def calibrating():
    robot = rb.Snatch3rRobot()
    robot.arm.calibrate(100)
Пример #23
0
def moving_arm_and_claw():
    robot = rb.Snatch3rRobot()
    robot.arm.raise_arm_and_close_claw(100)
Пример #24
0
def main():
    """ Runs YOUR specific part of the project """
    robot = rb.Snatch3rRobot()
    robot.arm.calibrate()
Пример #25
0
def main():
    """ Runs YOUR specific part of the project """
    robot = rb.Snatch3rRobot()
    follow_black_lines(robot)
Пример #26
0
def main():
    """ Runs YOUR specific part of the project """
    robot = rb.Snatch3rRobot()
    #polyogon(robot, 4, 5)
    follow_black_line(robot)