Ejemplo n.º 1
0
def main():
    print("--------------------------------------------")
    print("IR Remote")
    print(" - Use IR remote channel 1 to drive around")
    print(" - Use IR remote channel 2 to for the arm")
    print(" - Press the Back button on EV3 to exit")
    print("--------------------------------------------")
    ev3.Sound.speak("I R Remote")

    ev3.Leds.all_off()  # Turn the leds off
    robot = robo.Snatch3r()
    dc = DataContainer()

    # Connect two large motors on output ports B and C
    left_motor = ev3.LargeMotor(ev3.OUTPUT_B)
    right_motor = ev3.LargeMotor(ev3.OUTPUT_C)

    # Check that the motors are actually connected
    assert left_motor.connected
    assert right_motor.connected

    # TODO: 4. Add the necessary IR handler callbacks as per the instructions above.
    # Remote control channel 1 is for driving the crawler tracks around (none of these functions exist yet below).
    # Remote control channel 2 is for moving the arm up and down (all of these functions already exist below).

    rc1 = ev3.RemoteControl(channel=1)
    assert rc1.connected

    rc1.on_red_up = lambda state: handle_left_forward(state, left_motor)
    rc1.on_red_down = lambda state: handle_left_backward(state, left_motor)
    rc1.on_blue_up = lambda state: handle_right_forward(state, right_motor)
    rc1.on_blue_down = lambda state: handle_right_backward(state, right_motor)

    rc2 = ev3.RemoteControl(channel=2)
    assert rc2.connected

    rc2.on_red_up = lambda state: handle_arm_up_button(state, robot)
    rc2.on_red_down = lambda state: handle_arm_down_button(state, robot)
    rc2.on_blue_up = lambda state: handle_calibrate_button(state, robot)

    # For our standard shutdown button.
    btn = ev3.Button()
    btn.on_backspace = lambda state: handle_shutdown(state, dc)

    robot.arm_calibration()  # Start with an arm calibration in this program.

    while dc.running:
        # done: 5. Process the RemoteControl objects.
        rc1.process()
        rc2.process()
        btn.process()
        time.sleep(0.01)

    # done: 2. Have everyone talk about this problem together then pick one
    # member to modify libs/robot_controller.py
    # as necessary to implement the method below as per the instructions in the opening doc string. Once the code has
    # been tested and shown to work, then have that person commit their work.  All other team members need to do a
    # VCS --> Update project...
    # Once the library is implemented any team member should be able to run his code as stated in todo3.
    robot.shutdown()
Ejemplo n.º 2
0
def main():
    print("--------------------------------------------")
    print("IR Remote")
    print(" - Use IR remote channel 1 to drive around")
    print("--------------------------------------------")
    robot = robo.Snatch3r()
    color_sensor = ev3.ColorSensor()
    color_sensor.MODE_COL_COLOR
    ir_sensor = ev3.InfraredSensor()
    beacon_seeker = ev3.BeaconSeeker(channel=1)
    assert color_sensor
    dc = DataContainer()
    my_delegate = MyDelegate()
    rc1 = ev3.RemoteControl(channel=1)
    rc1.on_red_up = lambda state: my_delegate.run_left(state, 1)
    rc1.on_red_down = lambda state: my_delegate.run_left(state, -1)
    rc1.on_blue_up = lambda state: my_delegate.run_right(state, 1)
    rc1.on_blue_down = lambda state: my_delegate.run_right(state, -1)
    rc2 = ev3.RemoteControl(channel=2)
    rc2.on_red_up = lambda state: my_delegate.arm_up()
    mqtt_client = com.MqttClient(my_delegate)
    my_delegate.mqtt_client = mqtt_client
    mqtt_client.connect_to_pc()

    while dc.running:
        rc1.process()
        rc2.process()
        color = color_sensor.color
        if color_sensor.color == 5:
            my_delegate.stop()

        time.sleep(0.01)
Ejemplo n.º 3
0
    def control(self):
        dc = DataContainer()
        remote1 = ev3.RemoteControl(channel=1)
        remote2 = ev3.RemoteControl(channel=2)

        remote1.on_red_up = lambda state: handle_move_red_up(state, robot)
        remote1.on_red_down = lambda state: handle_move_red_down(state, robot)

        remote1.on_blue_up = lambda state: handle_move_blue_up(state, robot)
        remote1.on_blue_down = lambda state: handle_move_blue_down(
            state, robot)

        remote2.on_red_up = lambda state: handle_arm_up_button(state, robot)
        remote2.on_red_down = lambda state: handle_arm_down_button(
            state, robot)
        btn = ev3.Button()
        btn.on_backspace = lambda state: handle_shutdown(state, dc)

        while dc.running:
            btn.process()
            remote1.process()
            remote2.process()
            time.sleep(0.01)

        robot.stop()
Ejemplo n.º 4
0
    def rc_loop(self):
        """
        Enter the remote control loop. RC buttons on channel 1 control the
        robot movement, channel 2 is for shooting things.
        The loop ends when the touch sensor is pressed.
        """
        def roll(motor, led_group, speed):
            """
            Generate remote control event handler. It rolls given motor into
            given direction (1 for forward, -1 for backward). When motor rolls
            forward, the given led group flashes green, when backward -- red.
            When motor stops, the leds are turned off.

            The on_press function has signature required by RemoteControl
            class.  It takes boolean state parameter; True when button is
            pressed, False otherwise.
            """
            def on_press(state):
                if state:
                    # Roll when button is pressed
                    motor.run_forever(speed_sp=speed)
                    ev3.Leds.set_color(
                        led_group,
                        ev3.Leds.GREEN if speed > 0 else ev3.Leds.RED)
                else:
                    # Stop otherwise
                    motor.stop()
                    ev3.Leds.set_color(led_group, ev3.Leds.BLACK)

            return on_press

        rc1 = ev3.RemoteControl(self.ir, 1)
        rc1.on_red_up = roll(self.lm, ev3.Leds.LEFT, 900)
        rc1.on_red_down = roll(self.lm, ev3.Leds.LEFT, -900)
        rc1.on_blue_up = roll(self.rm, ev3.Leds.RIGHT, 900)
        rc1.on_blue_down = roll(self.rm, ev3.Leds.RIGHT, -900)

        def shoot(direction):
            def on_press(state):
                if state: self.shoot(direction)

            return on_press

        rc2 = ev3.RemoteControl(self.ir, 2)
        rc2.on_red_up = shoot('up')
        rc2.on_blue_up = shoot('up')
        rc2.on_red_down = shoot('down')
        rc2.on_blue_down = shoot('down')

        # Now that the event handlers are assigned,
        # lets enter the processing loop:
        while not self.ts.is_pressed:
            rc1.process()
            rc2.process()
            time.sleep(0.1)
Ejemplo n.º 5
0
def main():
    print("--------------------------------------------")
    print("IR Remote")
    print(" - Use IR remote channel 1 to drive around")
    print(" - Use IR remote channel 2 to for the arm")
    print(" - Press the Back button on EV3 to exit")
    print("--------------------------------------------")
    ev3.Sound.speak("I R Remote")

    ev3.Leds.all_off()  # Turn the leds off
    robot = robo.Snatch3r()
    dc = DataContainer()

    remote1 = ev3.RemoteControl(None, 1)
    remote2 = ev3.RemoteControl(None, 2)

    # Done: 4. Add the necessary IR handler callbacks as per the instructions
    # above.
    # Remote control channel 1 is for driving the crawler tracks around (none of these functions exist yet below).
    # Remote control channel 2 is for moving the arm up and down (all of these functions already exist below).

    remote1.on_red_up = lambda state: handle_red_up_1(state, robot)
    remote1.on_red_down = lambda state: handle_red_down_1(state, robot)
    remote1.on_blue_down = lambda state: handle_blue_down_1(state, robot)
    remote1.on_blue_up = lambda state: handle_blue_up_1(state, robot)

    # if remote1.red_up is 0:
    #     robot.left_motor.stop()

    # if remote1.on_red_up is False:
    #     robot.left_motor.stop()
    remote2.on_red_up = lambda state: handle_arm_up_button(state, robot)
    remote2.on_red_down = lambda state: handle_arm_down_button(state, robot)
    remote2.on_blue_up = lambda state: handle_calibrate_button(state, robot)

    # For our standard shutdown button.
    btn = ev3.Button()
    btn.on_backspace = lambda state: handle_shutdown(state, dc)

    # robot.arm_calibration()  # Start with an arm calibration in this program.
    while dc.running:
        # Done: 5. Process the RemoteControl objects.
        btn.process()
        remote1.process()
        remote2.process()
        time.sleep(0.01)

    # Done: 2. Have everyone talk about this problem together then pick one
    # member to modify libs/robot_controller.py
    # as necessary to implement the method below as per the instructions in the opening doc string. Once the code has
    # been tested and shown to work, then have that person commit their work.  All other team members need to do a
    # VCS --> Update project...
    # Once the library is implemented any team member should be able to run his code as stated in todo3.

    robot.shutdown()
Ejemplo n.º 6
0
def main():

    robot = robo.Snatch3r()
    ev3.Sound.speak("Starting")

    # IR remote
    rc1 = ev3.RemoteControl(channel=1)
    rc4 = ev3.RemoteControl(channel=4)
    rc2 = ev3.RemoteControl(channel=2)
    rc1.on_red_up = lambda state: handle_left_drive(state, robot)
    rc1.on_red_down = lambda state: handle_left_reverse(state, robot)
    rc1.on_blue_up = lambda state: handle_right_drive(state, robot)
    rc1.on_blue_down = lambda state: handle_right_reverse(state, robot)
    rc2.on_red_up = lambda state: handle_arm_up_button(state, robot)
    rc2.on_red_down = lambda state: handle_arm_down_button(state, robot)
    rc2.on_blue_up = lambda state: handle_calibrate_button(state, robot)
    rc4.on_red_up = lambda state: handle_mode_change(state, delegate)
    rc4.on_blue_down = lambda state: handle_turn_off(state, delegate)

    # mqtt connect
    delegate = Delagate(robot)
    client = com.MqttClient(delegate)
    client.connect_to_pc()

    ev3.Leds.all_off()
    robot.arm_calibration()
    delegate.arm_state = 'down'

    while delegate.mode != 'off':
        # IR mode
        while delegate.mode == 'ir':
            rc1.process()
            rc2.process()
            rc4.process()
            time.sleep(0.01)
        # mqtt mode
        while delegate.mode == 'mqtt':
            if delegate.a == 'no':
                if delegate.arm_state == 'down':
                    if robot.ir_sensor.proximity < 50:
                        robot.stop()
                        ev3.Leds.set_color(ev3.Leds.LEFT, ev3.Leds.RED)
                        ev3.Leds.set_color(ev3.Leds.RIGHT, ev3.Leds.RED)
                        ev3.Sound.speak("Backing up")
                        robot.drive_inches(-8, 800)
                        client.send_message(
                            "display_message",
                            ["Too close to wall. Turn and continue."])
                        ev3.Leds.set_color(ev3.Leds.LEFT, ev3.Leds.BLACK)
                        ev3.Leds.set_color(ev3.Leds.RIGHT, ev3.Leds.BLACK)
    robot.shutdown()
Ejemplo n.º 7
0
 def seek_beacon(self):
     rc1 = ev3.RemoteControl(channel=1)
     assert rc1.connected
     beacon_seeker = ev3.BeaconSeeker()
     forward_speed = 300
     turn_speed = 100
     slow_turn_speed = 30
     while not self.touch_sensor.is_pressed:
         current_heading = beacon_seeker.heading
         current_distance = beacon_seeker.distance
         if current_distance == -128:
             print("IR Remote not found. Distance is -128")
             self.right(slow_turn_speed, slow_turn_speed)
         else:
             if math.fabs(current_heading) < 2:
                 print("On the right heading. Distance: ", current_distance)
                 if current_distance > 0:
                     self.forward(forward_speed, forward_speed)
                 elif current_distance <= 0:
                     return True
             elif 2 <= math.fabs(current_heading) < 10:
                 if current_heading < 0:
                     self.left(turn_speed, turn_speed)
                 elif current_heading > 0:
                     self.right(turn_speed, turn_speed)
             elif math.fabs(current_heading) > 10:
                 self.right(slow_turn_speed, slow_turn_speed)
                 print("Heading too far off")
         rc1.process()
         time.sleep(0.2)
     print("Abandon ship!")
     self.stop()
     return False
 def set_channel(self, channel):
     """
     Makes this sensor look for signals on the given channel. The physical
     Beacon has a switch that can set the channel to 1, 2, 3 or 4.
     """
     self.channel = channel
     self._underlying_ir_sensor = ev3.RemoteControl(channel=channel)
Ejemplo n.º 9
0
    def __init__(self):
        self.left_motor = ev3.LargeMotor(ev3.OUTPUT_B)
        self.right_motor = ev3.LargeMotor(ev3.OUTPUT_C)
        self.arm_motor = ev3.MediumMotor(ev3.OUTPUT_A)
        self.touch_sensor = ev3.TouchSensor()
        self.rc1 = ev3.RemoteControl(channel=1)
        self.rc2 = ev3.RemoteControl(channel=2)
        self.rc3 = ev3.RemoteControl(channel=3)
        self.rc4 = ev3.RemoteControl(channel=4)
        self.color_sensor = ev3.ColorSensor()
        self.ir_sensor = ev3.InfraredSensor()
        self.pixy = ev3.Sensor(driver_name="pixy-lego")

        assert ev3.ColorSensor()
        assert ev3.InfraredSensor()
        assert ev3.Sensor(driver_name="pixy-lego")
Ejemplo n.º 10
0
    def __init__(self,
                 left_motor,
                 right_motor,
                 polarity='inversed',
                 channel=1,
                 speed_sp=400):
        Tank.__init__(self,
                      left_motor,
                      right_motor,
                      polarity,
                      speed_sp=speed_sp)
        log.info("Getting remote control for channel " + str(channel))
        self.remote = ev3.RemoteControl(channel=channel)

        if not self.remote.connected:
            log.error("%s is not connected" % self.remote)
            sys.exit(1)

        self.remote.on_red_up = self.make_move(self.left_motor, self.speed_sp)
        self.remote.on_red_down = self.make_move(self.left_motor,
                                                 self.speed_sp * -1)
        self.remote.on_blue_up = self.make_move(self.right_motor,
                                                self.speed_sp)
        self.remote.on_blue_down = self.make_move(self.right_motor,
                                                  self.speed_sp * -1)
Ejemplo n.º 11
0
def main():
    print("--------------------------------------------")
    print("Final Project")
    print("--------------------------------------------")
    ev3.Sound.speak("Final Project").wait()

    ev3.Leds.all_off()  # Turn the leds off
    robot = robo.Snatch3r()
    dc = DataContainer()

    # Remote control channel 1 is for driving the crawler tracks around (none of these functions exist yet below).
    # Remote control channel 2 is for moving the arm up and down (all of these functions already exist below).

    rc1 = ev3.RemoteControl(channel=1)
    rc1.on_red_up = lambda state: left_move(state, robot)
    rc1.on_blue_up = lambda state: right_move(state, robot)

    rc2 = ev3.RemoteControl(channel=2)
    rc2.on_red_up = lambda state: handle_arm_up_button(state, robot)
    rc2.on_red_down = lambda state: handle_arm_down_button(state, robot)

    rc3 = ev3.RemoteControl(channel=3)
    rc3.on_red_up = lambda state: turn(state, robot)
    rc3.on_red_down = lambda state: dance(state, robot)
    rc3.on_blue_up = lambda state: play_song(state)

    rc4 = ev3.RemoteControl(channel=4)
    rc4.on_red_up = lambda state: go_crazy(state, dc)
    rc4.on_blue_down = lambda state: handle_shutdown(state, dc)

    # For our standard shutdown button.
    btn = ev3.Button()
    btn.on_backspace = lambda state: handle_shutdown(state, dc)

    robot.arm_calibration()  # Start with an arm calibration in this program.

    while dc.running:
        # DONE: 5. Process the RemoteControl objects.
        btn.process()
        rc1.process()
        rc2.process()
        rc3.process()
        rc4.process()
        time.sleep(0.01)

    robot.shutdown()
Ejemplo n.º 12
0
def main():
    print("--------------------------------------------")
    print("IR Remote")
    print(" - Use IR remote channel 1 to drive around")
    print(" - Use IR remote channel 2 to for the arm")
    print(" - Press the Back button on EV3 to exit")
    print("--------------------------------------------")
    ev3.Sound.speak("I R Remote")

    ev3.Leds.all_off()  # Turn the leds off
    robot = robo.Snatch3r()
    dc = DataContainer()
    #
    #     # DONE: 4. Add the necessary IR handler callbacks as per the instructions
    #     #  above.
    #     # Remote control channel 1 is for driving the crawler tracks around (none of these functions exist yet below).
    #     # Remote control channel 2 is for moving the arm up and down (all of these functions already exist below).
    #
    #     # For our standard shutdown button.
    left_motor = ev3.LargeMotor(ev3.OUTPUT_B)
    assert left_motor
    right_motor = ev3.LargeMotor(ev3.OUTPUT_C)
    assert right_motor
    arm_motor = ev3.MediumMotor(ev3.OUTPUT_A)
    assert arm_motor
    btn = ev3.Button()
    btn.on_backspace = lambda state: handle_shutdown(state, dc)
    rc1 = ev3.RemoteControl(channel=1)
    rc1.on_red_up = lambda state: move_red_up(state, left_motor)
    rc1.on_red_down = lambda state: move_red_down(state, left_motor)
    rc1.on_blue_up = lambda state: move_blue_up(state, right_motor)
    rc1.on_blue_down = lambda state: move_blue_down(state, right_motor)
    robot.arm_calibration()  # Start with an arm calibration in this program.

    rc2 = ev3.RemoteControl(channel=2)
    rc2.on_red_up = lambda state: handle_arm_up_button(state, robot)
    rc2.on_red_down = lambda state: handle_arm_down_button(state, robot)
    rc2.on_blue_up = lambda state: handle_calibrate_button(state, robot)
    # rc2.on_blue_down = lambda state: arm_down(state, arm_motor)

    while dc.running:
        #         # DONE: 5. Process the RemoteControl objects.
        btn.process()
        rc1.process()
        rc2.process()
        time.sleep(0.01)
Ejemplo n.º 13
0
 def __init__(self, channel_value):
     """
     Creates an object that can be used to check if a button is being
     pressed on the remote control.  You might need as many as four of
     these classes if you used all the channels of the remote.
     Valid channels: 1, 2, 3, or 4
     :type channel: int
     """
     self._remote_control = ev3.RemoteControl(channel=channel_value)
 def __init__(self, channel=1):
     self.channel = channel
     self._underlying_ir_sensor = ev3.RemoteControl(channel=channel)
     self.button_names = {
         "red_up": TOP_RED_BUTTON,
         "red_down": BOTTOM_RED_BUTTON,
         "blue_up": TOP_BLUE_BUTTON,
         "blue_down": BOTTOM_BLUE_BUTTON,
         "beacon": BEACON_BUTTON
     }
def ir_remote_example(dc):
    """Example of setting up an IR Remote button, shows only 1 but the pattern is easy to follow for more."""
    def handle_red_up_1(button_state, dc):
        if button_state:
            print("Down button is pressed")
            dc.do_something()
        else:
            print("Down button was released")

    rc1 = ev3.RemoteControl(channel=1)
    assert rc1.connected
    rc1.on_red_up = lambda state: handle_red_up_1(state, dc)
def main():
    print("--------------------------------------------")
    print("   Example of buttons with event handlers")
    print("--------------------------------------------")
    ev3.Sound.speak("Buttons with events").wait()

    robot = None  # Requires you to implement the Snatch3r class in the robot_controller library
    dc = DataContainer(
    )  # Optional class to help you pass around data between different button events.

    # Remote control channel 1
    rc1 = ev3.RemoteControl(channel=1)
    assert rc1.connected
    rc1.on_red_up = lambda state: handle_red_up_1(state, robot, dc)
    rc1.on_red_down = lambda state: handle_red_down_1(state, robot, dc)
    rc1.on_blue_up = lambda state: handle_blue_up_1(state, robot, dc)
    rc1.on_blue_down = lambda state: handle_blue_down_1(state, robot, dc)

    # Remote control channel 2
    rc2 = ev3.RemoteControl(channel=2)
    assert rc2.connected
    rc2.on_red_up = lambda state: handle_red_up_2(state, robot, dc)
    rc2.on_red_down = lambda state: handle_red_down_2(state, robot, dc)
    rc2.on_blue_up = lambda state: handle_blue_up_2(state, robot, dc)
    rc2.on_blue_down = lambda state: handle_blue_down_2(state, robot, dc)

    # Buttons on EV3
    btn = ev3.Button()
    btn.on_up = lambda state: handle_up_button(state, robot, dc)
    btn.on_down = lambda state: handle_down_button(state, robot, dc)
    btn.on_left = lambda state: handle_left_button(state, robot, dc)
    btn.on_right = lambda state: handle_right_button(state, robot, dc)
    # Note there is also an enter button but sometimes that causes issues with Brickman when used
    btn.on_backspace = lambda state: handle_shutdown(state, robot, dc)

    while dc.running:
        rc1.process()
        rc2.process()
        btn.process()
        time.sleep(0.01)
Ejemplo n.º 17
0
def main():

    robot = robo.Snatch3r()
    mqtt_client = com.MqttClient(robot)
    mqtt_client.connect_to_pc()
    game = Game()

    game.eyes()

    rc1 = ev3.RemoteControl(channel=1)
    rc2 = ev3.RemoteControl(channel=2)

    finish_line(ev3.ColorSensor.COLOR_BLACK)
    water_bottle()

    game.accept()

    # This sets up our buttons for the IR remote

    btn = ev3.Button()
    rc1.on_red_up = lambda state: forward_left_motor(state, robot)
    rc1.on_red_down = lambda state: back_left_motor(state, robot)
    rc1.on_blue_up = lambda state: forward_right_motor(state, robot)
    rc1.on_blue_down = lambda state: back_right_motor(state, robot)
    ev3.on_backspace = lambda state: handle_shutdown(state, game)

    rc2.on_red_up = lambda state: handle_arm_up_button(state, robot)
    rc2.on_red_down = lambda state: handle_arm_down_button(state, robot)
    rc2.on_blue_up = lambda state: handle_calibrate_button(state, robot)
    rc2.on_blue_down = lambda state: handle_shutdown(state, game)

    ev3.left_motor = ev3.LargeMotor(ev3.OUTPUT_B)
    ev3.right_motor = ev3.LargeMotor(ev3.OUTPUT_C)

    while game.running:
        btn.process()
        rc1.process()
        rc2.process()
        time.sleep(0.01)
Ejemplo n.º 18
0
def main():
    print("--------------------------------------------")
    print("IR Remote")
    print(" - Use IR remote channel 2 to drive around")
    print(" - Use IR remote channel 3 to for the arm")
    print(" - Press the Back button on EV3 to exit")
    print("--------------------------------------------")
    ev3.Sound.speak("I R Remote")

    ev3.Leds.all_off()  # Turn the leds off
    robot = robo.Snatch3r()
    dc = DataContainer()

    btn = ev3.Button()
    btn.on_backspace = lambda state: handle_shutdown(state, dc)

    assert touch_sensor
    rc1 = ev3.RemoteControl(channel=2)
    rc2 = ev3.RemoteControl(channel=3)

    rc1.on_red_up = lambda state: handle_red_up_1(state)
    rc1.on_red_down = lambda state: handle_red_down_1(state)
    rc1.on_blue_up = lambda state: handle_blue_up_1(state)
    rc1.on_blue_down = lambda state: handle_blue_down_1(state)

    rc2.on_red_up = lambda state: handle_arm_up_button(state, robot)
    rc2.on_red_down = lambda state: handle_arm_down_button(state, robot)
    rc2.on_blue_up = lambda state: handle_calibrate_button(state, robot)

    while dc.running:

        rc1.process()
        rc2.process()
        btn.process()
        time.sleep(0.01)

    robot.shutdown()
Ejemplo n.º 19
0
def main():

    robot = robo.Snatch3r()
    dc = DataContainer()

    btn = ev3.Button()
    btn.on_backspace = lambda state: handle_shutdown(state, dc)

    left_motor = ev3.LargeMotor(ev3.OUTPUT_B)
    right_motor = ev3.LargeMotor(ev3.OUTPUT_C)
    assert left_motor.connected
    assert right_motor.connected

    robot.arm_calibration()

    rc1 = ev3.RemoteControl(channel=1)
    rc1.on_red_up = lambda button_state: robot.red_up(button_state)
    rc1.on_red_down = lambda button_state: robot.red_down(button_state)
    rc1.on_blue_up = lambda button_state: robot.blue_up(button_state)
    rc1.on_blue_down = lambda button_state: robot.blue_down(button_state)

    rc2 = ev3.RemoteControl(channel=2)
    rc2.on_red_up = lambda button_state: handle_arm_up_button(
        button_state, robot)
    rc2.on_red_down = lambda button_state: handle_arm_down_button(
        button_state, robot)
    rc2.on_blue_up = lambda button_state: handle_calibrate_button(
        button_state, robot)

    btn.on_backspace = lambda button_state: handle_shutdown(
        button_state, dc, robot)

    while dc.running:
        rc1.process()
        rc2.process()
        btn.process()
        time.sleep(0.01)
Ejemplo n.º 20
0
def main():
    print("Running...")

    #mqtt_client = com.MqttClient()
    #mqtt_client.connect_to_ev3()
    # ------------------------------------------------------------------------------------------------------
    # REMOTE CONTROL -- button for follow me mode, stop following me mode, status? say something mode
    # ------------------------------------------------------------------------------------------------------
    class DataContainer(object):
        """ Helper class that might be useful to communicate between different callbacks."""

        def __init__(self):
            self.running = True

    print("--------------------------------------------")
    print("IR Remote")
    print(" - Use IR remote channel 1.")
    print(" - Press red up to start following")
    print(" - Press red down to STOP following")
    print(" - Press blue up for dog to bark")
    print("--------------------------------------------")

    ev3.Leds.all_off()  # Turn the leds off
    robot = robo.Snatch3r()
    dc = DataContainer()
    left_motor = ev3.LargeMotor(ev3.OUTPUT_B)
    right_motor = ev3.LargeMotor(ev3.OUTPUT_C)
    assert left_motor.connected
    assert right_motor.connected

    rc1 = ev3.RemoteControl(channel=1)
    rc1.on_red_up = lambda state: follow_me(state, robot)  # FOllow me
    rc1.on_red_down = lambda state: stop_following(state, robot)  # Stop following me
    rc1.on_blue_up = lambda state: bark(state, robot)  # Say something

    btn = ev3.Button()
    btn.on_backspace = lambda state: handle_shutdown(state, dc)

    while dc.running:
        # Process the RemoteControl objects.
        rc1.process()
        btn.process()
        time.sleep(0.01)

    robot.shutdown = lambda state: handle_shutdown(dc)
Ejemplo n.º 21
0
    def __init__(self):

        self.MAX_SPEED = 900
        self.running = True

        self.left_motor = ev3.LargeMotor(ev3.OUTPUT_B)
        self.right_motor = ev3.LargeMotor(ev3.OUTPUT_C)
        self.arm_motor = ev3.MediumMotor(ev3.OUTPUT_A)
        self.touch_sensor = ev3.TouchSensor()
        self.remote_contol = ev3.RemoteControl()
        self.color_sensor = ev3.ColorSensor()
        self.ir_sensor = ev3.InfraredSensor()
        self.pixy = ev3.Sensor(driver_name="pixy-lego")
        self.btn = ev3.Button()

        assert self.pixy.connected
        assert self.ir_sensor.connected
        assert self.color_sensor.connected
        assert self.left_motor.connected
        assert self.right_motor.connected
        assert self.arm_motor.connected
        assert self.touch_sensor.connected
Ejemplo n.º 22
0
    def __init__(self):
        # Connect two large motors on output ports B and C
        self.left_motor = ev3.LargeMotor(ev3.OUTPUT_B)
        self.right_motor = ev3.LargeMotor(ev3.OUTPUT_C)

        # Check that the motors are actually connected
        assert self.left_motor.connected
        assert self.right_motor.connected

        # Connect and assert connection of medium motor to output port A
        self.arm_motor = ev3.MediumMotor(ev3.OUTPUT_A)
        assert self.arm_motor.connected

        # Define and check sensors are connected
        self.touch_sensor = ev3.TouchSensor()
        assert self.touch_sensor
        self.color_sensor = ev3.ColorSensor()
        assert self.color_sensor
        self.ir_sensor = ev3.InfraredSensor()
        assert self.ir_sensor
        self.remote_control = ev3.RemoteControl()
        # don't assert remote_control since it is external from the robot
        self.beacon_seeker = ev3.BeaconSeeker(channel=1)
        assert self.beacon_seeker
        self.beacon_seeker_2 = ev3.BeaconSeeker(channel=1)
        assert self.beacon_seeker_2
        self.pixy = ev3.Sensor(driver_name="pixy-lego")
        assert self.pixy

        # Definition for Brickman buttons
        self.btn = ev3.Button()

        # Define recurring variables
        self.current_color = 0
        self.reflected_light_intensity = 0

        self.running = True
Ejemplo n.º 23
0
def main():
    print("--------------------------------------------")
    print(" IR Events with the Screen")
    print("--------------------------------------------")
    print("Exit this program with the Back button.")
    # You will notice very few print commands in this module since this module uses the screen.
    # If you run Screen programs on the EV3 using Brickman, print commands go to that screen too which causes ugly
    # screen images. If you run Screen programs via SSH print commands work as expected.

    # Object that is storing references to images that can be passed into callbacks.
    dc = DataContainer()

    display_image(dc.lcd_screen, dc.eyes)  # Display an image on the EV3 screen
    ev3.Sound.speak("I R events with the Screen").wait()

    # DONE: 3. Create a remote control object for channel 1. Add lambda callbacks for:
    #   .on_red_up    to call handle_red_up_1    (that exist already) with state and dc as parameters
    #   .on_red_down  to call handle_red_down_1  (that exist already) with state and dc as parameters
    #   .on_blue_up   to call handle_blue_up_1   (that exist already) with state and dc as parameters
    #   .on_blue_down to call handle_blue_down_1 (that exist already) with state and dc as parameters
    remote1 = ev3.RemoteControl(channel=1)
    remote1.on_red_up = lambda state: handle_red_up_1(state, dc)
    remote1.on_red_down = lambda state: handle_red_down_1(state, dc)
    remote1.on_blue_up = lambda state: handle_blue_up_1(state, dc)
    remote1.on_blue_down = lambda state: handle_blue_down_1(state, dc)

    # TODO: 5. Create remote control objects for channels 2, 3, and 4. Add lambda callbacks for on_red_up to each one:
    #   Channel 2's .on_red_up should call handle_red_up_2 (that exist already) with state and dc as parameters
    #   Channel 3's .on_red_up should call handle_red_up_3 (that exist already) with state and dc as parameters
    #   Channel 4's .on_red_up should call handle_red_up_4 (that exist already) with state and dc as parameters

    remote2 = ev3.RemoteControl(channel=2)
    remote3 = ev3.RemoteControl(channel=3)
    remote4 = ev3.RemoteControl(channel=4)

    remote2.on_red_up = lambda state: handle_red_up_2(state, dc)
    remote3.on_red_up = lambda state: handle_red_up_3(state, dc)
    remote4.on_red_up = lambda state: handle_red_up_4(state, dc)

    # Buttons on EV3
    btn = ev3.Button()
    btn.on_backspace = lambda state: handle_shutdown(state, dc)

    while dc.running:
        # TODO: 4. Call the .process() method on your channel 1 RemoveControl object, then review and run your code.
        #   Review the handle functions below to see how they draw to the screen.  They are already finished.
        remote1.process()
        # TODO: 6. Call the .process() method on your channel 2 - 4 RemoveControl objects and demo your code.
        #   Review the handle functions below to see how they draw to the screen.  They are already finished.
        remote2.process()
        remote3.process()
        remote4.process()
        # TODO: 7. Call over a TA or instructor to sign your team's checkoff sheet and do a code review.
        #
        # Observations you should make, IR buttons work exactly like buttons on the EV3.
        #   The screen is a bit annoying to work with due to the Brickman OS interference.
        #   Note you could've run this program with Brickman too, but screen draws would last one 1 second each.

        btn.process(
        )  # Monitors for the Back button to exit the program if called.
        time.sleep(0.01)

    # When the program completes (the user hit the Back button), display a crying image and say goodbye.
    display_image(dc.lcd_screen, dc.teary_eyes)
    ev3.Sound.speak("Goodbye").wait()
    print(
        "If you ran via SSH and typed 'sudo chvt 6' earlier, don't forget to type"
    )
    print("'sudo chvt 1' to get Brickman back after you finish this program.")
Ejemplo n.º 24
0
def main():
    print("--------------------------------------------")
    print("IR Remote")
    print(" - Use IR remote channel 1 to drive around")
    print(" - Use IR remote channel 2 to for the arm")
    print(" - Press the Back button on EV3 to exit")
    print("--------------------------------------------")
    ev3.Sound.speak("I R Remote")

    ev3.Leds.all_off()  # Turn the leds off
    robot = robo.Snatch3r()
    dc = DataContainer()

    # DONE: 4. Add the necessary IR handler callbacks as per the instructions above.
    # Remote control channel 1 is for driving the crawler tracks around (none of these functions exist yet below).
    # Remote control channel 2 is for moving the arm up and down (all of these functions already exist below).
    rc1 = ev3.RemoteControl(channel=1)
    rc2 = ev3.RemoteControl(channel=2)
    rc1.on_red_up = lambda state: handle_drive_left_forward(state, robot)
    rc1.on_red_down = lambda state: handle_drive_left_backward(state, robot)
    rc1.on_blue_up = lambda state: handle_drive_right_forward(state, robot)
    rc1.on_blue_down = lambda state: handle_drive_right_backward(state, robot)
    rc2.on_red_up = lambda state: robot.arm_up()
    rc2.on_red_down = lambda state: robot.arm_down()
    rc2.on_blue_up = lambda state: robot.arm_calibration()
    """
    -- Pressing red up   calls robot.arm_up().
    -- Pressing red down calls robot.arm_down().
    -- Pressing blue up  calls robot.arm_calibration().
    """

    # For our standard shutdown button.
    btn = ev3.Button()
    btn.on_backspace = lambda state: handle_shutdown(state, dc)

    robot.arm_calibration()  # Start with an arm calibration in this program.

    while dc.running:
        # DONE: 5. Process the RemoteControl objects.
        rc1.process()
        rc2.process()
        btn.process()
        time.sleep(0.01)

    # DONE: 2. Have everyone talk about this problem together then pick one  member to modify libs/robot_controller.py
    # as necessary to implement the method below as per the instructions in the opening doc string. Once the code has
    # been tested and shown to work, then have that person commit their work.  All other team members need to do a
    # VCS --> Update project...
    # Once the library is implemented any team member should be able to run his code as stated in todo3.
    robot.shutdown()

    # ----------------------------------------------------------------------
    # Event handlers
    # Some event handlers have been written for you (ones for the arm).
    # Movement event handlers have not been provided.
    # ----------------------------------------------------------------------
    # TODO: 6. Implement the IR handler callbacks handlers.

    # TODO: 7. When your program is complete, call over a TA or instructor to sign your checkoff sheet and do a code review.
    #
    # Observations you should make, IR buttons are a fun way to control the robot.
    """IR remote channel 1 to drive the crawler tracks around:
Ejemplo n.º 25
0
def main():
    print("--------------------------------------------")
    print("IR Remote")
    print(" - Use IR remote channel 1 to drive around")
    print(" - Use IR remote channel 2 to for the arm")
    print(" - Press the Back button on EV3 to exit")
    print("--------------------------------------------")
    ev3.Sound.speak("I R Remote")

    arm_motor = ev3.MediumMotor(ev3.OUTPUT_A)
    assert arm_motor.connected

    touch_sensor = ev3.TouchSensor()
    assert touch_sensor

    ev3.Leds.all_off()  # Turn the leds off
    robot = robo.Snatch3r()
    dc = DataContainer()
    left_motor = ev3.LargeMotor(ev3.OUTPUT_B)
    right_motor = ev3.LargeMotor(ev3.OUTPUT_C)
    assert left_motor.connected
    assert right_motor.connected

    # Done: 4. Add the necessary IR handler callbacks as per the instructions above.
    # Remote control channel 1 is for driving the crawler tracks around (none of these functions exist yet below).
    # Remote control channel 2 is for moving the arm up and down (all of these functions already exist below).

    def handle_red_up_1(button_state, motor):
        if button_state:
            motor.run_forever(speed_sp=600)
            ev3.Leds.set_color(ev3.Leds.LEFT, ev3.Leds.GREEN)
        else:
            motor.stop(stop_action="brake")
            ev3.Leds.set_color(ev3.Leds.LEFT, ev3.Leds.BLACK)

    def handle_red_down_1(button_state, motor):
        if button_state:
            motor.run_forever(speed_sp=-600)
            ev3.Leds.set_color(ev3.Leds.LEFT, ev3.Leds.RED)
        else:
            motor.stop(stop_action="brake")
            ev3.Leds.set_color(ev3.Leds.LEFT, ev3.Leds.BLACK)

    def handle_blue_up_1(button_state, motor):
        if button_state:
            motor.run_forever(speed_sp=600)
            ev3.Leds.set_color(ev3.Leds.RIGHT, ev3.Leds.GREEN)
        else:
            motor.stop(stop_action="brake")
            ev3.Leds.set_color(ev3.Leds.RIGHT, ev3.Leds.BLACK)

    def handle_blue_down_1(button_state, motor):
        if button_state:
            motor.run_forever(speed_sp=-600)
            ev3.Leds.set_color(ev3.Leds.RIGHT, ev3.Leds.RED)
        else:
            motor.stop(stop_action="brake")
            ev3.Leds.set_color(ev3.Leds.RIGHT, ev3.Leds.BLACK)

    def shutdown(button_state, dc2):
        if button_state:
            dc2.running = False

    # For our standard shutdown button.
    btn = ev3.Button()
    btn.on_backspace = lambda state: shutdown(state, dc)
    ir1 = ev3.RemoteControl(channel=1)
    ir2 = ev3.RemoteControl(channel=2)

    ir1.on_red_up = lambda state: handle_red_up_1(state, left_motor)
    ir1.on_red_down = lambda state: handle_red_down_1(state, left_motor)
    ir1.on_blue_up = lambda state: handle_blue_up_1(state, right_motor)
    ir1.on_blue_down = lambda state: handle_blue_down_1(state, right_motor)
    ir2.on_red_up = lambda state: handle_arm_up_button(state, robot)
    ir2.on_red_down = lambda state: handle_arm_down_button(state, robot)
    ir2.on_blue_up = lambda state: handle_calibrate_button(state, robot)
    robot.arm_calibration()  # Start with an arm calibration in this program.

    while dc.running:
        # Done: 5. Process the RemoteControl objects.
        ir1.process()
        ir2.process()
        btn.process()
        time.sleep(0.01)

    # Done: 2. Have everyone talk about this problem together then pick one  member to modify libs/robot_controller.py
    # as necessary to implement the method below as per the instructions in the opening doc string. Once the code has
    # been tested and shown to work, then have that person commit their work.  All other team members need to do a
    # VCS --> Update project...
    # Once the library is implemented any team member should be able to run his code as stated in todo3.
    robot.shutdown()
Ejemplo n.º 26
0
#!/usr/bin/env python3
""" 
    remote.py: Checks which button is pressed
    Author: Cristina Serrano Gonzalez (Naeriel)
"""

import ev3dev.ev3 as ev3
import ev3dev.fonts as fonts
from time import sleep

remote = ev3.RemoteControl(sensor=None, channel=1)
lcd = ev3.Screen()

while True:
    if remote.red_up:
        lcd.draw.text((10, 10), 'Red Up', font=fonts.load("luBS14"))
        lcd.update()
        sleep(5)
    else:
        lcd.draw.text((10, 10), 'None pressed', font=fonts.load("luBS14"))
        lcd.update()
        sleep(5)
When prompted for the password - C$$E120

To restart the Brickman interface after you complete this problem type:
  sudo chvt 1
Which will probably not require you to type the password since sudo was just run earlier.

BTW chvt means CHange the Virtual Terminal, and 86ing something means to kick it out.

Authors: David Fisher and Allison Shi, Ryan Fleetham, Stephen Acomb.
"""  # DONE: 1. PUT YOUR NAME IN THE ABOVE LINE.

import ev3dev.ev3 as ev3
import time
from PIL import Image

ch1 = ev3.RemoteControl(channel=1)
ch2 = ev3.RemoteControl(channel=2)
ch3 = ev3.RemoteControl(channel=3)
ch4 = ev3.RemoteControl(channel=4)

# DONE: 2. Have someone on your team run this program as is on the EV3 and make
#  sure everyone understands the code.
# Can you see what the robot does and explain what each line of code is doing? Talk as a group to make sure.


class DataContainer(object):
    """ Helper class that might be useful to communicate between different callbacks."""
    def __init__(self):
        self.running = True

        # Creates the one and only Screen object and prepares a few Image objects.
Ejemplo n.º 28
0
#!/usr/bin/env python3
# Test the hardware config needed by loev3go

import ev3dev.ev3 as ev3
from ev3dev.auto import OUTPUT_A, OUTPUT_B, OUTPUT_C, OUTPUT_D

# assumed connections
medium_motor_output = OUTPUT_A
left_motor = OUTPUT_B
right_motor = OUTPUT_C
channel = 1

# test if remote is connected
remote = ev3.RemoteControl(channel=channel)
assert (remote)
assert (remote.connected)
print("IR seems connected")

# test motors
left_motor = ev3.LargeMotor(left_motor)
right_motor = ev3.LargeMotor(right_motor)
med_motor = ev3.MediumMotor(medium_motor_output)

for m in [left_motor, right_motor, med_motor]:
    print("Testing", m)
    assert m.connected
    m.reset()
    m.run_to_rel_pos(speed_sp=150, position_sp=300)  #, stop_action="stop")
    m.run_to_rel_pos(speed_sp=150, position_sp=-300)  #, stop_action="stop")
    print("Tested", m)
Ejemplo n.º 29
0
def distance():

    conn = rpyc.classic.connect(
        'ev3dev.local')  # host name or IP address of the EV3
    ev3 = conn.modules['ev3dev.ev3']  # import ev3dev.ev3 remotely

    m1 = ev3.LargeMotor('outB')
    assert m1.connected, "Connecter un large motor sur outB"
    m2 = ev3.LargeMotor('outC')
    assert m2.connected, "Connecter un large motor sur outC"
    m3 = ev3.MediumMotor('outA')

    m3.run_to_rel_pos(position_sp=-45, speed_sp=100, stop_action="brake")
    m3.wait_while('running')
    m3.run_to_rel_pos(position_sp=45, speed_sp=100, stop_action="brake")
    m3.wait_while('running')
    m3.run_to_rel_pos(position_sp=45, speed_sp=100, stop_action="brake")
    m3.wait_while('running')
    m3.run_to_rel_pos(position_sp=-45, speed_sp=100, stop_action="brake")
    m3.wait_while('running')

    beeps(1)

    ir = ev3.InfraredSensor()
    assert ir.connected, "Connecter svp le senseur infrarouge a un des ports"

    # Connect remote control
    rc = ev3.RemoteControl()
    assert rc.connected, "Remote control does not work"

    #Mettre le senseur infrarouge en mode de proximite
    ir.mode = 'IR-PROX'

    cl = ev3.ColorSensor()
    assert cl.connected, "Connecter svp le senseur de couleur a un des ports"

    # Mettre le senseur en mode RGB
    cl.mode = 'RGB-RAW'

    cur_distance = ir.value()
    # print "Distance %d cur_distance de depart" % cur_distance

    m1.run_forever(speed_sp=0)
    m2.run_forever(speed_sp=0)

    # Turn leds off
    ev3.Leds.all_off()

    def stop_luigi():

        conn = rpyc.classic.connect(
            'ev3dev.local')  # host name or IP address of the EV3
        ev3 = conn.modules['ev3dev.ev3']  # import ev3dev.ev3 remotely

        ev3.Sound.beep().wait()

        m1.run_forever(speed_sp=0)

        m2.run_forever(speed_sp=0)

    while ir.value() > 2:  # While no button is pressed.

        cur_distance = ir.value()
        while ir.value() > 50:  # While no button is pressed.
            cur_distance = ir.value()
            m1.run_forever(speed_sp=300 - 2000 / (cur_distance + 3))
            m2.run_forever(speed_sp=300 - 2000 / (cur_distance + 3))

        m1.run_forever(speed_sp=0)
        m2.run_forever(speed_sp=0)
        m1.run_forever(speed_sp=-300)
        m2.run_forever(speed_sp=-300)

        if random.randint(0, 1) == 0:
            ev3.Sound.speak('Ou la la la la')
        else:
            ev3.Sound.speak('Oops')

        if random.randint(0, 1) == 0:
            m2.run_timed(speed_sp=500)
        else:
            m1.run_timed(speed_sp=500)

        sleep(1.5)

        sleep(0.6)

    ev3.Sound.beep().wait()
    m1.run_forever(speed_sp=0)
    m2.run_forever(speed_sp=0)

    beeps(2)
    sleep(1)
Ejemplo n.º 30
0
def telecommand():
    conn = rpyc.classic.connect(
        'ev3dev.local')  # host name or IP address of the EV3
    ev3 = conn.modules['ev3dev.ev3']  # import ev3dev.ev3 remotely

    # lmotor: moteur de gauche  rmotor: moteur de droite
    lmotor = ev3.LargeMotor('outB')
    rmotor = ev3.LargeMotor('outC')
    assert lmotor.connected, "Connecter le moteur gauche sur outB"
    assert rmotor.connected, "Connecter le moteur droite sur outC"

    ev3.Sound.speak('Hey').wait()

    ir = ev3.InfraredSensor()  #distance et telecommande
    assert ir.connected, "Connecter svp le senseur infrarouge a un des ports"

    # Connect remote control
    rc = ev3.RemoteControl()
    assert rc.connected, "Remote control does not work"

    # Initialize button handler
    #button = Button()   # not working so disabled

    # Turn leds off
    ev3.Leds.all_off()

    def tourne(moteur, led_group, direction):
        conn = rpyc.classic.connect(
            'ev3dev.local')  # host name or IP address of the EV3
        ev3 = conn.modules['ev3dev.ev3']  # import ev3dev.ev3 remotely

        def on_press(state):
            conn = rpyc.classic.connect(
                'ev3dev.local')  # host name or IP address of the EV3
            ev3 = conn.modules['ev3dev.ev3']  # import ev3dev.ev3 remotely
            if state:
                moteur.run_forever(speed_sp=600 * direction)
            else:
                # sinon stop
                print('processus 3')
                moteur.stop(stop_action='brake')
                print('processus 4')

        return on_press

    # Assigne un event handler a chaque bouton
    rc.on_red_up = tourne(lmotor, Leds.LEFT, 1)
    rc.on_red_down = tourne(lmotor, Leds.LEFT, -1)
    rc.on_blue_up = tourne(rmotor, Leds.RIGHT, 1)
    rc.on_blue_down = tourne(rmotor, Leds.RIGHT, -1)

    # Boucle de travail
    while True:
        ir.mode = 'IR-REMOTE'  # mode telecommande
        rc.process()
        sleep(0.01)

        ir.mode = 'IR-PROX'  # mode distance
        cur_distance = ir.value()

        if cur_distance >= 0 and cur_distance <= 8:
            lmotor.stop(stop_action='brake')
            rmotor.stop(stop_action='brake')

            ev3.Sound.beep()
            sleep(1.0)

            sys.exit(0)