def main():
    root = tkinter.Tk()
    root.title = "MQTT Shared Circles"

    main_frame = ttk.Frame(root, padding=5)
    main_frame.grid()

    instructions = "Click the window to make a circle"
    label = ttk.Label(main_frame, text=instructions)
    label.grid(columnspan=2)

    # Make a tkinter.Canvas on a Frame.
    canvas = tkinter.Canvas(main_frame,
                            background="lightgray",
                            width=800,
                            height=500)
    canvas.grid(columnspan=2)

    # Make callbacks for mouse click events.
    canvas.bind("<Button-1>",
                lambda event: left_mouse_click(event, mqtt_client))

    # Make callbacks for the two buttons.
    clear_button = ttk.Button(main_frame, text="Clear")
    clear_button.grid(row=3, column=0)
    clear_button["command"] = lambda: clear(canvas)

    quit_button = ttk.Button(main_frame, text="Quit")
    quit_button.grid(row=3, column=1)
    quit_button["command"] = lambda: quit_program(mqtt_client)

    # Create an MQTT connection
    # DONE: 5. Delete the line below (mqtt_client = None) then uncomment the code below.  It creates a real mqtt client.
    my_delegate = MyDelegate(canvas)
    mqtt_client = com.MqttClient(my_delegate)
    mqtt_client.connect("draw", "draw")

    root.mainloop()
def main():
    print("--------------------------------------------")
    print(" Pixy display")
    print(" Press the touch sensor to exit")
    print("--------------------------------------------")
    ev3.Sound.speak("Pixy display").wait()
    print("Press the touch sensor to exit this program.")

    # DONE: 2. Create an MqttClient (no delegate needed since EV3 will only send data, so an empty constructor is fine)
    # Then connect to the pc using the connect_to_pc method.

    robot = robo.Snatch3r()
    robot.pixy.mode = "SIG1"
    mqtt_client = com.MqttClient()
    mqtt_client.connect_to_pc()

    while not robot.touch_sensor.is_pressed:

        # DONE: 3. Read the Pixy values for x, y, width, and height
        # Print the values (much like the print_pixy_readings example)
        x = robot.pixy.value(1)
        y = robot.pixy.value(2)
        width = robot.pixy.value(3)
        height = robot.pixy.value(4)

        print("value1: X", robot.pixy.value(1))
        print("value2: Y", robot.pixy.value(2))
        print("value3: Width", robot.pixy.value(3))
        print("value4: Height", robot.pixy.value(4))

        # DONE: 4. Send the Pixy values to the PC by calling the on_rectangle_update method
        # If you open m2_pc_pixy_display you can see the parameters for that method [x, y, width, height]
        mqtt_client.send_message("on_rectangle_update", [x, y, width, height])
        time.sleep(0.25)

    print("Goodbye!")
    ev3.Sound.speak("Goodbye").wait()
    mqtt_client.close()
Exemple #3
0
def main():
    print("--------------------------------------------")
    print(" Pixy display")
    print(" Press the touch sensor to exit")
    print("--------------------------------------------")
    ev3.Sound.speak("Pixy display").wait()
    print("Press the touch sensor to exit this program.")

    # DONE: 2. Create an MqttClient (no delegate needed since EV3 will only send data, so an empty constructor is fine)
    # Then connect to the pc using the connect_to_pc method.
    mqtt_client = com.MqttClient(
    )  #Sets up a MQTT client to communicate with EV3
    mqtt_client.connect_to_pc()
    robot = robo.Snatch3r()
    robot.pixy.mode = "SIG1"

    while not robot.touch_sensor.is_pressed:

        # DONE: 3. Read the Pixy values for x, y, width, and height
        # Print the values (much like the print_pixy_readings example)
        x = robot.pixy.value(
            1
        )  #Gathers and stores the values form the pixy camera for later use
        y = robot.pixy.value(2)
        width = robot.pixy.value(3)
        height = robot.pixy.value(4)
        print("(X, Y)= ({}, {}) Width={} Height={}".format(
            x, y, width, height))

        # DONE: 4. Send the Pixy values to the PC by calling the on_rectangle_update method
        # If you open m2_pc_pixy_display you can see the parameters for that method [x, y, width, height]
        mqtt_client.send_message('on_rectangle_update', [x, y, width, height])

        time.sleep(0.25)

    print("Goodbye!")
    ev3.Sound.speak("Ciao").wait()
    mqtt_client.close()
def main():
    # --------------------------------------------------------------------------
    # DONE: 3. Construct a Snatch3rRobot.  Test.  When OK, delete this TODO.
    # --------------------------------------------------------------------------
    robot = rb.Snatch3rRobot()

    # --------------------------------------------------------------------------
    # TODO: 4. Add code that constructs a   com.MqttClient   that will
    # TODO:    be used to receive commands sent by the laptop.
    # TODO:    Connect it to this robot.  Test.  When OK, delete this TODO.
    # --------------------------------------------------------------------------
    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.
        # ----------------------------------------------------------------------
        time.sleep(0.01)  # For the delegate to do its work
        if robot.beacon_button_sensor.is_top_red_button_pressed():
            ev3.Sound.beep().wait()
Exemple #5
0
def main():
    root = tkinter.Tk()
    my_delegate = MyDelegate()
    mqtt_client = com.MqttClient(my_delegate)
    mqtt_client.connect_to_ev3()
    root.title("Robit")
    style = ttk.Style()

    label0 = ttk.Label(root, text=" ", font=('Helvetica', 10))
    label0.grid(row=0, column=0)

    label1 = ttk.Label(root,
                       text="What do you want Robit to do?",
                       font=("Helvetica", 17))
    label1.grid(row=2, column=0)

    style.configure('my.TFrame', background='#a8c9ff')
    frame1 = ttk.Frame(root, style='my.TFrame', padding=70)
    frame1.grid()

    command(frame1, root, mqtt_client)

    root.mainloop()
Exemple #6
0
def select_color_window():
    mqtt_client = com.MqttClient()
    mqtt_client.connect_to_ev3()

    root = tkinter.Tk()
    root.title("Select Color")

    colors_frame = ttk.Frame(root, padding=20, relief='raised')
    colors_frame.grid()

    red_button = ttk.Button(colors_frame, text='Red')
    red_button.grid(row=1, column=1)
    red_button['command'] = lambda: set_color(mqtt_client, red, "red")

    green_button = ttk.Button(colors_frame, text='Green')
    green_button.grid(row=1, column=2)
    green_button['command'] = lambda: set_color(mqtt_client, green, "green")

    black_button = ttk.Button(colors_frame, text='Black')
    black_button.grid(row=1, column=3)
    black_button['command'] = lambda: set_color(mqtt_client, black, "black")

    root.mainloop()
def main():
    print("--------------------------------------------")
    print(" LED Button communication")
    print(" Press Back to exit when done.")
    print("--------------------------------------------")
    ev3.Sound.speak("LED Button communication").wait()

    # TODO: 3. Create an instance of your delegate class and an MQTT client, passing in the delegate object.
    # Note: you can determine the variable names that you should use by looking at the errors underlined in later code.
    # Once you have that done connect the mqtt_client to the MQTT broker using the connect_to_pc method.
    # Note: on EV3 you call connect_to_pc, but in the PC code it will call connect_to_ev3



    my_delegate = MyDelegate()
    mqtt_client = com.MqttClient(my_delegate)
    mqtt_client.connect_to_pc()





    # Buttons on EV3 (these obviously assume TO DO: 3. is done)
    btn = ev3.Button()
    btn.on_up = lambda state: handle_button_press(state, mqtt_client, "Up")
    btn.on_down = lambda state: handle_button_press(state, mqtt_client, "Down")
    btn.on_left = lambda state: handle_button_press(state, mqtt_client, "Left")
    btn.on_right = lambda state: handle_button_press(state, mqtt_client, "Right")
    btn.on_backspace = lambda state: handle_shutdown(state, my_delegate)

    while my_delegate.running:
        btn.process()
        time.sleep(0.01)

    ev3.Sound.speak("Goodbye").wait()
    ev3.Leds.set_color(ev3.Leds.LEFT, ev3.Leds.GREEN)
    ev3.Leds.set_color(ev3.Leds.RIGHT, ev3.Leds.GREEN)
Exemple #8
0
def main():
    robot = robo.Snatch3r()
    mqtt_client = com.MqttClient(robot)
    mqtt_client.connect_to_pc()

    touch_sensor = ev3.TouchSensor()
    assert touch_sensor

    ev3.Sound.speak('Guide me back home').wait()
    mqtt_client.send_message('msg', ['Guide me back home'])

    while True:
        if robot.color_sensor.color == ev3.ColorSensor.COLOR_BLUE:
            robot.drive_stop()
            robot.turn_degrees(380, 300)
            time.sleep(3)
        if robot.color_sensor.color == ev3.ColorSensor.COLOR_RED:
            robot.drive_stop()
            ev3.Sound.speak('you just killed me').wait()
            mqtt_client.send_message('msg', ['you just killed me'])
            robot.arm_down()
            exit()
        if robot.color_sensor.color == ev3.ColorSensor.COLOR_YELLOW:
            robot.drive_stop()
            ev3.Sound.play(
                "/home/robot/csse120/assets/sounds/awesome_pcm.wav").wait()
            time.sleep(3)
        while not touch_sensor.is_pressed:
            time.sleep(5)
            ev3.Sound.speak('I am home').wait()
            mqtt_client.send_message('msg', ['I am home'])
            time.sleep(1)
            ev3.Sound.speak('Here is the bone').wait()
            mqtt_client.send_message('msg', ['Here is the bone'])
            exit()

    robot.loop_forever()
Exemple #9
0
def main():
    robot = robo.Snatch3r()
    mqtt_client = com.MqttClient(robot)
    mqtt_client.connect_to_pc()
    btn = ev3.Button()
    btn.process()
    while True:
        if btn.left:
            print("left")
            ev3.Leds.set_color(ev3.Leds.LEFT, ev3.Leds.GREEN)
            ev3.Leds.set_color(ev3.Leds.RIGHT, ev3.Leds.BLACK)
        # if the right button is pressed, print "right" and turn on the right LED set to red
        if btn.right:  # an if statement is used because more than one button can be pressed at a time
            print("right")
            ev3.Leds.set_color(ev3.Leds.RIGHT, ev3.Leds.RED)
            ev3.Leds.set_color(ev3.Leds.LEFT, ev3.Leds.BLACK)
        # if the up button is pressed, print "up" and turn all LEDs off
        if btn.up:
            print("up")
            ev3.Leds.all_off()
        print(robot.color_sensor.color,
              robot.color_sensor.reflected_light_intensity)
        if robot.color_sensor.color == 1:
            mqtt_client.send_message("change_points", 10)
        if robot.touch_sensor.is_pressed:
            ev3.Sound.speak("Done")
        if btn.backspace:
            break
        time.sleep(
            0.01
        )  # Best practice to have a short delay to avoid working too hard between loop iterations.

    # Best practice to leave the LEDs on after you finish a program so you don't put away the robot while still on.
    ev3.Leds.set_color(ev3.Leds.LEFT, ev3.Leds.GREEN)
    ev3.Leds.set_color(ev3.Leds.RIGHT, ev3.Leds.GREEN)
    robot.loop_forever(
    )  # Calls a function that has a while True: loop within it to avoid letting the program end.
def main():
    """
    This code, which must run on a LAPTOP:
      1. Constructs a GUI for my part of the Capstone Project.
      2. Communicates via MQTT with the code that runs on the EV3 robot.
    """
    # -------------------------------------------------------------------------
    # Construct and connect the MQTT Client:
    # -------------------------------------------------------------------------
    mqtt_sender = com.MqttClient()
    mqtt_sender.connect_to_ev3()

    # -------------------------------------------------------------------------
    # The root TK object for the GUI:
    # -------------------------------------------------------------------------
    root = tkinter.Tk()
    root.title("CSSE 120 Capstone Project")

    # -------------------------------------------------------------------------
    # The main frame, upon which the other frames are placed.
    # -------------------------------------------------------------------------
    main_frame = ttk.Frame(root)
    main_frame.grid()

    # -------------------------------------------------------------------------
    # Grid the frames.
    # -------------------------------------------------------------------------
    # grid_frames(teleop_frame, arm_frame, control_frame, movement_frame, noise_frame)

    get_user_controlled_dance_frame(main_frame, mqtt_sender).grid(row=0,
                                                                  column=0)
    get_automatic_dance_frame(main_frame, mqtt_sender).grid(row=1, column=0)

    # -------------------------------------------------------------------------
    # The event loop:
    # -------------------------------------------------------------------------
    root.mainloop()
def main():
    ev3.Sound.speak("Avoid collision system activated").wait()
    left_motor = ev3.LargeMotor(ev3.OUTPUT_B)
    right_motor = ev3.LargeMotor(ev3.OUTPUT_C)
    assert left_motor.connected
    assert right_motor.connected

    # Robot
    robot = robo.Snatch3r()
    # Remote control
    mqtt_client = com.MqttClient(robot)
    mqtt_client.connect_to_pc()
    while not robot.touch_sensor.is_pressed:
        while robot.active is True:
            if robot.ir_sensor.proximity <= 40:
                robot.left_motor.stop(stop_action=ev3.Motor.STOP_ACTION_COAST)
                robot.right_motor.stop(stop_action=ev3.Motor.STOP_ACTION_COAST)
                time.sleep(1)
                robot.turn_degrees(90, 200)
            else:
                left_motor.run_forever(speed_sp=400)
                right_motor.run_forever(speed_sp=400)
        robot.stop()
        time.sleep(0.1)
Exemple #12
0
def main():
    """
    This code, which must run on a LAPTOP:
      1. Constructs a GUI for my part of the Capstone Project.
      2. Communicates via MQTT with the code that runs on the EV3 robot.
    """
    # -------------------------------------------------------------------------
    # Construct and connect the MQTT Client:
    # -------------------------------------------------------------------------
    # ROOT ONE LOSE
    root1 = tkinter.Tk()
    laptop_handler_lose = Laptop_handler(root1)
    mqtt_sender = com.MqttClient(laptop_handler_lose)
    mqtt_sender.connect_to_ev3()

    root = tkinter.Toplevel()
    root.title("CSSE 120 Capstone Project, Winter 2018-19, Robot 11")

    # # ROOT TWO WIN
    # root2 = tkinter.Toplevel()

    main_frame = ttk.Frame(root, padding=10, borderwidth=5, relief='groove')
    main_frame.grid()

    # laptop_handler_lose = Laptop_handler(root1)
    # laptop_handler_win = Laptop_handler(root2)
    # laptop_handler_lose.window_two(root1)
    # laptop_handler_win.window_one(root2)

    teleop_frame, arm_frame, control_frame, drive_system_frame, haiden_frame, mario_frame = get_shared_frames(
        main_frame, mqtt_sender)

    grid_frames(teleop_frame, arm_frame, control_frame, drive_system_frame,
                haiden_frame, mario_frame)

    root.mainloop()
def main():
    my_delegate = MyDelegate()
    mqtt_client = com.MqttClient(my_delegate)
    mqtt_client.connect_to_ev3()

    root = tkinter.Tk()
    root.title("                            Pokemon Red: Remastered Edition")

    party = tkinter.Toplevel()

    walk_speed = 500

    charmander = Pokemon()
    charmander.type = "Fire"
    squirtle = Pokemon()
    squirtle.type = "Water"
    bulbasaur = Pokemon()
    bulbasaur.type = "Grass"

    start_window(root)
    movement(party, mqtt_client, walk_speed)
    party_window(party, mqtt_client, charmander, squirtle, bulbasaur)

    root.mainloop()
Exemple #14
0
    def __init__(self):
        delegate = delegate_on_laptop()
        self.mqtt_sender = com.MqttClient(delegate)
        self.mqtt_sender.connect_to_ev3()
        # Declaring variables
        self.time_initial = time.time()
        self.energy = 100
        self.speed = 0

        self.root = tkinter.Tk()
        self.root.title('CSSE120 Capstone Project')

        self.main_frame = ttk.Frame(self.root,
                                    padding=10,
                                    borderwidth=5,
                                    relief='groove')
        self.main_frame.grid()

        # Creates the title frame
        self.title_frame = ttk.Frame(self.main_frame,
                                     padding=10,
                                     borderwidth=5,
                                     relief="ridge")
        title_label = tkinter.Label(self.title_frame,
                                    text='ROBO-KART',
                                    font=("Cooper Black", 33),
                                    fg='goldenrod')
        title_label.grid()

        self.create_play_frame()

        # Grids title and play frame onto the main frame
        self.title_frame.grid(row=0, column=0)
        self.play_frame.grid(row=1, column=0)

        self.bind_keys()
def the_computer_can_receive_messages_too():
    """ Showing an example of a PC receiving a message.  This code is similar to turnerwb but not
        identical, so don't copy anything from here except maybe the words:
          mqtt_client.send_message("on_circle_draw", [        ])
        """

    # Make a quick custom class.
    class MyDelegate(object):
        def __init__(self, canvas):
            self.canvas = canvas

        def on_circle_draw(self, color, x, y):
            self.canvas.create_oval(x - 10, y - 10, x + 10, y + 10, fill=color, width=3)

    canvas = "A Tkinter object"  # Something specific to the m1_pc_shared_circles example.
    my_delegate = MyDelegate(canvas)
    mqtt_client = com.MqttClient(my_delegate)
    mqtt_client.connect("draw", "draw")

    time.sleep(2)
    mqtt_client.send_message("on_circle_draw", ['blue', 50, 50])

    time.sleep(5)
    mqtt_client.close()
def main():
    root = tkinter.Tk()
    root.title = "Pixy display"

    main_frame = ttk.Frame(root, padding=5)
    main_frame.grid()

    # The values from the Pixy range from 0 to 319 for the x and 0 to 199 for the y.
    canvas = tkinter.Canvas(main_frame, background="lightgray", width=320, height=200)
    canvas.grid(columnspan=2)

    rect_tag = canvas.create_rectangle(150, 90, 170, 110, fill="blue")

    # Buttons for quit and exit
    quit_button = ttk.Button(main_frame, text="Quit")
    quit_button.grid(row=3, column=1)
    quit_button["command"] = lambda: quit_program(mqtt_client)

    # Create an MQTT connection
    my_delegate = MyDelegate(canvas, rect_tag)
    mqtt_client = com.MqttClient(my_delegate)
    # mqtt_client.connect_to_ev3()
    mqtt_client.connect_to_ev3("35.194.247.175")  # Off campus IP address of a GCP broker
    root.mainloop()
Exemple #17
0
def main():
    """
    This code, which must run on the EV3 ROBOT:
      1. Makes the EV3 robot to various things.
      2. Communicates via MQTT with the GUI code that runs on the LAPTOP.
    """

    robot = rosebot.RoseBot()
    delegate = shared_gui_delegate_on_robot.Handler(robot)
    mqtt_receiver = com.MqttClient(delegate)
    mqtt_receiver.connect_to_pc()

    while True:
        time.sleep(0.04)
        if delegate.is_time_to_stop:
            break
        robot.sensor_system.camera.set_signature('SIG4')
        #print(robot.sensor_system.camera.get_biggest_blob())
        mqtt_receiver.send_message("display_camera", [
            robot.sensor_system.camera.get_biggest_blob().center.x,
            robot.sensor_system.camera.get_biggest_blob().center.y,
            robot.sensor_system.camera.get_biggest_blob().height,
            robot.sensor_system.camera.get_biggest_blob().width
        ])
def main():
    """
    This code, which must run on a LAPTOP:
      1. Constructs a GUI for my part of the Capstone Project.
      2. Communicates via MQTT with the code that runs on the EV3 robot.
    """
    # -------------------------------------------------------------------------
    # Construct and connect the MQTT Client:
    # -------------------------------------------------------------------------
    laptop_delegate = m1.DelegateLaptop()
    mqtt_sender = com.MqttClient(laptop_delegate)
    mqtt_sender.connect_to_ev3()

    # -------------------------------------------------------------------------
    # The root TK object for the GUI:
    # -------------------------------------------------------------------------

    # root = tkinter.Tk()
    # root.title("CSSE 120 Capstone Project")
    #
    # personal_root = tkinter.Tk()
    # personal_root.title("Personal Feature")

    sprint3_root = tkinter.Tk()
    sprint3_root.title("Metal-and-Oil Detector")
    sprint3_root.configure(background="cornflower blue")
    sprint3_root.geometry("337x340")

    # -------------------------------------------------------------------------
    # The main frame, upon which the other frames are placed.
    # -------------------------------------------------------------------------

    # main_frame = ttk.Frame(root, padding=10)
    # main_frame.grid()

    # -------------------------------------------------------------------------
    # Sub-frames for the shared GUI that the team developed:
    # -------------------------------------------------------------------------

    # teleop_frame, arm_frame, control_frame, drive_system_frame, sound_system_frame, \
    # ColorSensor_driving_frame, IR_driving_frame, camera_frame = get_shared_frames(main_frame, mqtt_sender)

    # -------------------------------------------------------------------------
    # Frames that are particular to my individual contributions to the project.
    # -------------------------------------------------------------------------
    # DONE: Implement and call get_my_frames(...)

    # m1_get_my_frame(personal_root, mqtt_sender)

    m1_sprint3_get_my_frame(sprint3_root, mqtt_sender)

    # -------------------------------------------------------------------------
    # Grid the frames.
    # -------------------------------------------------------------------------

    # grid_frames(teleop_frame, arm_frame, control_frame, drive_system_frame, sound_system_frame,
    #             ColorSensor_driving_frame, IR_driving_frame, camera_frame)

    # -------------------------------------------------------------------------
    # The event loop:
    # -------------------------------------------------------------------------

    # root.mainloop()
    sprint3_root.mainloop()
Exemple #19
0
def main():
    my_pc_delegate = MyDelegateOnPc()
    mqtt_client = com.MqttClient(my_pc_delegate)
    mqtt_client.connect_to_ev3()

    root = tkinter.Tk()
    root.title("Satellite Remote Drive")

    main_frame = ttk.Frame(root, padding=20)
    main_frame.grid()

    left_speed_label = ttk.Label(main_frame, text="Left")
    left_speed_label.grid(row=0, column=0)

    left_speed_entry = ttk.Entry(main_frame, width=10)
    left_speed_entry.grid(row=1, column=0)

    right_speed_label = ttk.Label(main_frame, text="Right")
    right_speed_label.grid(row=0, column=2)

    right_speed_entry = ttk.Entry(main_frame, width=10)
    right_speed_entry.grid(row=1, column=2)

    forward_button = ttk.Button(main_frame, text="Forward")
    forward_button.grid(row=2, column=1)
    forward_button['command'] = lambda: callback_forward(
        mqtt_client, left_speed_entry, right_speed_entry)
    root.bind(
        '<Up>', lambda event: callback_forward(mqtt_client, left_speed_entry,
                                               right_speed_entry))

    left_button = ttk.Button(main_frame, text="Left")
    left_button.grid(row=3, column=0)
    left_button['command'] = lambda: callback_left(
        mqtt_client, left_speed_entry, right_speed_entry)
    root.bind(
        '<Left>', lambda event: callback_left(mqtt_client, left_speed_entry,
                                              right_speed_entry))

    right_button = ttk.Button(main_frame, text="Right")
    right_button.grid(row=3, column=2)
    right_button['command'] = lambda: callback_right(
        mqtt_client, left_speed_entry, right_speed_entry)

    root.bind(
        '<Right>', lambda event: callback_right(mqtt_client, left_speed_entry,
                                                right_speed_entry))

    back_button = ttk.Button(main_frame, text="Back")
    back_button.grid(row=4, column=1)
    back_button['command'] = lambda: callback_back(
        mqtt_client, left_speed_entry, right_speed_entry)
    root.bind(
        '<Down>', lambda event: callback_back(mqtt_client, left_speed_entry,
                                              right_speed_entry))

    stop_button = ttk.Button(main_frame, text="Stop")
    stop_button.grid(row=3, column=1)
    stop_button['command'] = lambda: callback_stop(mqtt_client)
    root.bind('<space>', lambda event: callback_stop(mqtt_client))

    up_button = ttk.Button(main_frame, text="Up")
    up_button.grid(row=5, column=0)
    up_button['command'] = lambda: send_up(mqtt_client)
    root.bind('<u>', lambda event: send_up(mqtt_client))

    down_button = ttk.Button(main_frame, text="Down")
    down_button.grid(row=6, column=0)
    down_button['command'] = lambda: send_down(mqtt_client)
    root.bind('<j>', lambda event: send_down(mqtt_client))

    q_button = ttk.Button(main_frame, text="Quit")
    q_button.grid(row=5, column=2)
    q_button['command'] = (lambda: quit_program(mqtt_client, False))

    e_button = ttk.Button(main_frame, text="Exit")
    e_button.grid(row=6, column=2)
    e_button['command'] = (lambda: quit_program(mqtt_client, True))

    root.mainloop()
def main():
    robot = robo.Snatch3r()
    mqtt_client = com.MqttClient(robot)
    mqtt_client.connect_to_pc()
    robot.loop_forever()
Exemple #21
0
def main():
    # Done: 2. Setup an mqtt_client.  Notice that since you don't need to receive any messages you do NOT need to have
    # a MyDelegate class.  Simply construct the MqttClient with no parameter in the constructor (easy).

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

    root = tkinter.Tk()
    root.title("MQTT Remote")

    main_frame = ttk.Frame(root, padding=20, relief='raised')
    main_frame.grid()

    left_speed_label = ttk.Label(main_frame, text="Left")
    left_speed_label.grid(row=0, column=0)
    left_speed_entry = ttk.Entry(main_frame, width=8)
    left_speed_entry.insert(0, "600")
    left_speed_entry.grid(row=1, column=0)

    right_speed_label = ttk.Label(main_frame, text="Right")
    right_speed_label.grid(row=0, column=2)
    right_speed_entry = ttk.Entry(main_frame, width=8, justify=tkinter.RIGHT)
    right_speed_entry.insert(0, "600")
    right_speed_entry.grid(row=1, column=2)

    # Done: 3. Implement the callbacks for the drive buttons. Set both the click and shortcut key callbacks.
    #
    # To help get you started the arm up and down buttons have been implemented.
    # You need to implement the five drive buttons.  One has been writen below to help get you started but is commented
    # out. You will need to change some_callback1 to some better name, then pattern match for other button / key combos.

    forward_button = ttk.Button(main_frame, text="Forward")
    forward_button.grid(row=2, column=1)
    # forward_button and '<Up>' key is done for your here...
    forward_button['command'] = lambda: drive_forward(
        mqtt_client, left_speed_entry, right_speed_entry)
    root.bind(
        '<Up>', lambda event: drive_forward(mqtt_client, left_speed_entry,
                                            right_speed_entry))

    left_button = ttk.Button(main_frame, text="Left")
    left_button.grid(row=3, column=0)
    # left_button and '<Left>' key
    left_button['command'] = lambda: turn_left(mqtt_client, left_speed_entry,
                                               right_speed_entry)
    root.bind(
        '<Left>', lambda event: turn_left(mqtt_client, left_speed_entry,
                                          right_speed_entry))

    stop_button = ttk.Button(main_frame, text="Stop")
    stop_button.grid(row=3, column=1)
    # stop_button and '<space>' key (note, does not need left_speed_entry, right_speed_entry)
    stop_button['command'] = lambda: stop(mqtt_client)
    root.bind('<space>', lambda event: stop(mqtt_client))

    right_button = ttk.Button(main_frame, text="Right")
    right_button.grid(row=3, column=2)
    # right_button and '<Right>' key
    right_button['command'] = lambda: turn_right(mqtt_client, left_speed_entry,
                                                 right_speed_entry)
    root.bind(
        '<Right>', lambda event: turn_right(mqtt_client, left_speed_entry,
                                            right_speed_entry))

    back_button = ttk.Button(main_frame, text="Back")
    back_button.grid(row=4, column=1)
    # back_button and '<Down>' key
    back_button['command'] = lambda: drive_back(mqtt_client, left_speed_entry,
                                                right_speed_entry)
    root.bind(
        '<Down>', lambda event: drive_back(mqtt_client, left_speed_entry,
                                           right_speed_entry))

    up_button = ttk.Button(main_frame, text="Up")
    up_button.grid(row=5, column=0)
    up_button['command'] = lambda: send_up(mqtt_client)
    root.bind('<u>', lambda event: send_up(mqtt_client))

    down_button = ttk.Button(main_frame, text="Down")
    down_button.grid(row=6, column=0)
    down_button['command'] = lambda: send_down(mqtt_client)
    root.bind('<j>', lambda event: send_down(mqtt_client))

    # Buttons for quit and exit
    q_button = ttk.Button(main_frame, text="Quit")
    q_button.grid(row=5, column=2)
    q_button['command'] = (lambda: quit_program(mqtt_client, False))

    e_button = ttk.Button(main_frame, text="Exit")
    e_button.grid(row=6, column=2)
    e_button['command'] = (lambda: quit_program(mqtt_client, True))

    root.mainloop()
Exemple #22
0
def main():
    """Makes a gui that controls the robot"""
    robot_to_computer = PictureToComputer()
    mqtt_client = com.MqttClient(robot_to_computer)
    mqtt_client.connect_to_ev3()

    root = tkinter.Tk()
    root.title("Let's Play Mario")

    main_frame = ttk.Frame(root, padding=20, relief='raised')
    main_frame.grid()

    left_speed_label = ttk.Label(main_frame, text="Left")
    left_speed_label.grid(row=0, column=0)
    left_speed_entry = ttk.Entry(main_frame, width=8)
    left_speed_entry.insert(0, "300")
    left_speed_entry.grid(row=1, column=0)

    right_speed_label = ttk.Label(main_frame, text="Right")
    right_speed_label.grid(row=0, column=2)
    right_speed_entry = ttk.Entry(main_frame, width=8, justify=tkinter.RIGHT)
    right_speed_entry.insert(0, "300")
    right_speed_entry.grid(row=1, column=2)

    forward_button = ttk.Button(main_frame, text="Forward")
    forward_button.grid(row=2, column=1)
    forward_button['command'] = lambda: send_forward(mqtt_client,
                                                     left_speed_entry,
                                                     right_speed_entry)
    root.bind('<Up>', lambda event: send_forward(mqtt_client,
                                                 left_speed_entry,
                                                 right_speed_entry))

    left_button = ttk.Button(main_frame, text="Left")
    left_button.grid(row=3, column=0)
    left_button['command'] = lambda: send_left(mqtt_client,
                                               left_speed_entry,
                                               right_speed_entry)
    root.bind('<Left>', lambda event: send_left(mqtt_client, left_speed_entry,
                                                right_speed_entry))

    stop_button = ttk.Button(main_frame, text="Stop")
    stop_button.grid(row=3, column=1)
    stop_button['command'] = lambda: send_stop(mqtt_client)
    root.bind('<space>', lambda event: send_stop(mqtt_client))

    right_button = ttk.Button(main_frame, text="Right")
    right_button.grid(row=3, column=2)
    right_button['command'] = lambda: send_right(mqtt_client,
                                                 left_speed_entry,
                                                 right_speed_entry)
    root.bind('<Right>', lambda event: send_right(mqtt_client,
                                                  left_speed_entry,
                                                  right_speed_entry))

    back_button = ttk.Button(main_frame, text="Back")
    back_button.grid(row=4, column=1)
    back_button['command'] = lambda: send_back(mqtt_client,
                                               left_speed_entry,
                                               right_speed_entry)
    root.bind('<Down>', lambda event: send_back(mqtt_client,
                                                left_speed_entry,
                                                right_speed_entry))

    up_button = ttk.Button(main_frame, text="Up")
    up_button.grid(row=5, column=0)
    up_button['command'] = lambda: send_up(mqtt_client)
    root.bind('<u>', lambda event: send_up(mqtt_client))

    down_button = ttk.Button(main_frame, text="Down")
    down_button.grid(row=6, column=0)
    down_button['command'] = lambda: send_down(mqtt_client)
    root.bind('<j>', lambda event: send_down(mqtt_client))

    q_button = ttk.Button(main_frame, text="Quit")
    q_button.grid(row=5, column=2)
    q_button['command'] = (lambda: quit_program(mqtt_client, False))

    e_button = ttk.Button(main_frame, text="Exit")
    e_button.grid(row=6, column=2)
    e_button['command'] = (lambda: quit_program(mqtt_client, True))

    root.mainloop()
Exemple #23
0
def main():
    dc = DataContainer()
    mydelegate = MyDelegatePC()
    mqtt_client = com.MqttClient(mydelegate)
    mqtt_client.connect_to_ev3()
    dc.running = True

    root = tkinter.Tk()
    root.title("THE HUNT")

    main_frame = ttk.Frame(root, padding=20, relief='raised')
    main_frame.grid()
    left_speed = 400
    right_speed = 400

    hunt_photo = tkinter.PhotoImage(file='The_Hunt (1).gif')
    hunt_button = ttk.Button(main_frame, image=hunt_photo)
    hunt_button.image = hunt_photo
    hunt_button.grid(row=1, column=4)
    hunt_button['command'] = lambda: print("Are you ready to join THE HUNT?")

    forward_button = ttk.Button(main_frame, text="Forward")
    forward_button.grid(row=3, column=2)
    forward_button['command'] = lambda: forward_callback(mqtt_client, left_speed, right_speed)
    root.bind('<Up>', lambda event: forward_callback(mqtt_client, left_speed, right_speed))

    down_button = ttk.Button(main_frame, text="Reverse")
    down_button.grid(row=5, column=2)
    down_button['command'] = lambda: backward_callback(mqtt_client, left_speed, right_speed)
    root.bind('<Down>', lambda event: backward_callback(mqtt_client, left_speed, right_speed))

    left_button = ttk.Button(main_frame, text="Left")
    left_button.grid(row=4, column=1)
    left_button['command'] = lambda: left_callback(mqtt_client, left_speed, right_speed)
    root.bind('<Left>', lambda event: left_callback(mqtt_client, left_speed, right_speed))

    right_button = ttk.Button(main_frame, text="Right")
    right_button.grid(row=4, column=3)
    right_button['command'] = lambda: right_callback(mqtt_client, left_speed, right_speed)
    root.bind('<Right>', lambda event: right_callback(mqtt_client, left_speed, right_speed))

    stop_button = ttk.Button(main_frame, text="Stop")
    stop_button.grid(row=4, column=2)
    stop_button['command'] = lambda: stop_callback(mqtt_client)
    root.bind('<space>', lambda event: stop_callback(mqtt_client))

    quit_button = ttk.Button(main_frame, text="Quit")
    quit_button.grid(row=5, column=5)
    quit_button['command'] = (lambda: quit_program(mqtt_client, False))
    root.bind('<q>', lambda event: quit_program(mqtt_client, False))

    park_button = ttk.Button(main_frame, text="Pick up box?")
    park_button.grid(row=3, column=4)
    park_button['command'] = lambda: park_callback(mqtt_client)
    root.bind('<p>', lambda event: park_callback(mqtt_client))

    arm_down_button = ttk.Button()
    arm_down_button['command'] = lambda: arm_down_callback(mqtt_client)
    root.bind('<d>', lambda event: arm_down_callback(mqtt_client))

    cali_button = ttk.Button()
    cali_button['command'] = lambda: cali_callback(mqtt_client)
    root.bind('<c>', lambda event: cali_callback(mqtt_client))

    e_button = ttk.Button(main_frame, text="Exit")
    e_button.grid(row=6, column=5)
    e_button['command'] = (lambda: quit_program(mqtt_client, True))
    root.bind('<e>', lambda event: quit_program(mqtt_client, True))

    root.mainloop()
def main():
    # TO DO: 2. Set my_name and set team_member_name then try this program with that person.
    # For teams of 3 just have 2 people talk to each other and the other person can just watch this time.
    my_name = input(
        "Name of sub.: "
    )  # Used to set the topic that you are *subscribed to* listen to
    team_member_name = input(
        "Team name(pub to): "
    )  # Used to set the topic that you will *publish to*

    # What happens if you set my_name and team_member_name to the same value?
    # The goal is simply for you to become more comfortable with how subscriptions and publish work with MQTT
    # Review the code to see if there are any other useful things you can learn.

    # TODO: 3. Call over a TA or instructor to sign your team's checkoff sheet.
    #
    # Observations you should make:
    # You published messages to "legoXX/{team_member_name}"  (where XX is set in libs/mqtt_remote_method_calls.py)
    # You subscribed to messages for  "legoXX/{my_name}"
    # So only MQTT clients listening for that name will hear, and you only hear messages sent to you.
    # Later you'll publish messages to your EV3 and subscribe to messages that your EV3 sends.

    root = tkinter.Tk()
    root.title = "MQTT PyChat"

    main_frame = ttk.Frame(root, padding=20, relief='raised')
    main_frame.grid()

    label = ttk.Label(main_frame,
                      justify=tkinter.LEFT,
                      text="Send a message to " + team_member_name)
    label.grid(columnspan=2)

    msg_entry = ttk.Entry(main_frame, width=60)
    msg_entry.grid(row=2, column=0)

    msg_button = ttk.Button(main_frame, text="Send")
    msg_button.grid(row=2, column=1)
    msg_button['command'] = lambda: send_message(mqtt_client, my_name,
                                                 chat_window, msg_entry)
    root.bind(
        '<Return>', lambda event: send_message(mqtt_client, my_name,
                                               chat_window, msg_entry))

    chat_window = ttk.Label(main_frame,
                            justify=tkinter.LEFT,
                            text="",
                            width=60,
                            wraplength="500p")
    # chat_window.pack(fill="x")
    chat_window.grid(columnspan=2)

    q_button = ttk.Button(main_frame, text="Quit")
    q_button.grid(row=4, column=1)
    q_button['command'] = (lambda: quit_program(mqtt_client))

    # Create an MQTT connection
    my_delegate = MyDelegate(chat_window)
    mqtt_client = com.MqttClient(my_delegate)
    mqtt_client.connect(my_name, team_member_name)
    # mqtt_client.connect(my_name, team_member_name, "35.194.247.175")  # Off campus IP address of a GCP broker

    root.mainloop()
Exemple #25
0
def main():
    # Makes a robot for a delegate and then starts a connection
    robot = robo.Snatch3r()
    mqtt_client = com.MqttClient(robot)
    mqtt_client.connect_to_pc()

    # Initial variable values for calculations and sending
    robot.right_motor.position = 0
    robot.left_motor.position = 0
    right_start = 0
    left_start = 0
    x_start = 250
    y_start = 250
    angle_total = math.pi
    # While loop to keep the robot running
    while not robot.touch_sensor.is_pressed:
        # Strange if statement formatted by the text editor that sets a
        # range of area for the robot to stop or beep
        if not (not (11 < robot.ir_sensor.proximity) or not (
                    20 >= robot.ir_sensor.proximity)):
            # Robot will beep as a warning that the robot is getting close
            # to something
            ev3.Sound.beep()
            time.sleep(1)
        elif robot.ir_sensor.proximity <= 10:
            # Stops the robot if the robot is too close to something
            robot.stop()
            ev3.Sound.speak('Crash Avoided')
            time.sleep(5)

        # Calculation to send map items
        right = right_start
        right_new = robot.right_motor.position
        left = left_start
        left_new = robot.left_motor.position

        distance = (right_new - right) / 10
        distance_y = (left_new - left) / 10

        if (not distance <= 0 and 0 > distance_y) or (not distance >= 0 and 0 < distance_y):
            angle = ((right_new-right)/5.14)*(math.pi/180)
        else:
            angle = 0

        angle_total = angle_total + angle

        # Send command for the computer
        send_map(mqtt_client, x_start, y_start, angle_total)

        right_start = right_new
        left_start = left_new

        time.sleep(0.01)

        # r = 30
        # theta is found from time that robot turns and speed at which robot
        #  turns
        # theta start is 0.951 radians

        # ANGLES FOR MATH NEEDS TO BE IN RADIANS
        # Need scale factor for distance
    robot.shutdown()
Exemple #26
0
def main():
    # DONE: 2. Setup an mqtt_client.  Notice that since you don't need to receive any messages you do NOT need to have
    # a MyDelegate class.  Simply construct the MqttClient with no parameter in the constructor (easy).
    mqtt_client = com.MqttClient()
    mqtt_client.connect_to_ev3()

    root = tkinter.Tk()
    root.title("MQTT Remote")

    main_frame = ttk.Frame(root, padding=20, relief='raised')
    main_frame.grid()

    enter_emotion_entry = ttk.Entry(main_frame, width=8)
    enter_emotion_entry.grid(row=5, column=1)
    enter_emotion_button = ttk.Button(main_frame, text='Enter Emotion Color')
    enter_emotion_button.grid(row=6, column=1)
    enter_emotion_button['command'] = lambda: emotion(mqtt_client, enter_emotion_entry)

    slider_speed_left_label = ttk.Label(main_frame, text="Left Speed")
    slider_speed_left_label.grid(row=0, column=0)
    slider_speed_left= tkinter.Scale(main_frame, from_=0, to_=600, orient=tkinter.HORIZONTAL)
    slider_speed_left.grid(row=1, column=0)

    slider_speed_right_label = ttk.Label(main_frame, text="Right Speed")
    slider_speed_right_label.grid(row=0, column=2)
    slider_speed_right = tkinter.Scale(main_frame, from_=0, to_=600, orient=tkinter.HORIZONTAL)
    slider_speed_right.grid(row=1, column=2)

    forward_button = ttk.Button(main_frame, text="Forward")
    forward_button.grid(row=2, column=1)
    # forward_button and '<Up>' key is done for your here...
    forward_button['command'] = lambda: move_forward(mqtt_client, slider_speed_left, slider_speed_right)
    root.bind('<Up>', lambda event: move_forward(mqtt_client, slider_speed_left, slider_speed_right))

    left_button = ttk.Button(main_frame, text="Left")
    left_button.grid(row=3, column=0)
    # left_button and '<Left>' key
    left_button['command'] = lambda: turn_left(mqtt_client, slider_speed_left, slider_speed_right)
    root.bind('<Left>', lambda event: turn_left(mqtt_client, slider_speed_left, slider_speed_right))

    stop_button = ttk.Button(main_frame, text="Stop")
    stop_button.grid(row=3, column=1)
    # stop_button and '<space>' key (note, does not need left_speed_entry, right_speed_entry)
    stop_button['command'] = lambda: stop(mqtt_client)
    root.bind('<space>', lambda event: stop(mqtt_client))

    right_button = ttk.Button(main_frame, text="Right")
    right_button.grid(row=3, column=2)
    # right_button and '<Right>' key
    right_button['command'] = lambda: turn_right(mqtt_client, slider_speed_left, slider_speed_right)
    root.bind('<Right>', lambda event: turn_right(mqtt_client, slider_speed_left, slider_speed_right))

    back_button = ttk.Button(main_frame, text="Back")
    back_button.grid(row=4, column=1)
    # back_button and '<Down>' key
    back_button['command'] = lambda: move_back(mqtt_client, slider_speed_left, slider_speed_right)
    root.bind('<Down>', lambda event: move_back(mqtt_client, slider_speed_left, slider_speed_right))

    up_button = ttk.Button(main_frame, text="Up")
    up_button.grid(row=5, column=0)
    up_button['command'] = lambda: send_up(mqtt_client)
    root.bind('<h>', lambda event: send_up(mqtt_client))

    down_button = ttk.Button(main_frame, text="Down")
    down_button.grid(row=6, column=0)
    down_button['command'] = lambda: send_down(mqtt_client)
    root.bind('<j>', lambda event: send_down(mqtt_client))

    # Buttons for quit and exit
    q_button = ttk.Button(main_frame, text="Quit")
    q_button.grid(row=5, column=2)
    q_button['command'] = (lambda: quit_program(mqtt_client, False))

    e_button = ttk.Button(main_frame, text="Exit")
    e_button.grid(row=6, column=2)
    e_button['command'] = (lambda: quit_program(mqtt_client, True))

    c_button = ttk.Button(main_frame, text="Crush")
    c_button.grid(row=7, column=2)
    c_button['command'] = (lambda: grab(mqtt_client))
    root.bind('<c>', lambda event: grab(mqtt_client))

    c_button = ttk.Button(main_frame, text="Calibrate")
    c_button.grid(row=7, column=0)
    c_button['command'] = (lambda: cali(mqtt_client))
    root.bind('<c>', lambda event: cali(mqtt_client))

    root.mainloop()
def main():
    """
    This code, which must run on a LAPTOP:
      1. Constructs a GUI for my part of the Capstone Project.
      2. Communicates via MQTT with the code that runs on the EV3 robot.
    """
    # -------------------------------------------------------------------------
    # Construct and connect the MQTT Client:
    # -------------------------------------------------------------------------

    mqtt_sender = com.MqttClient()
    mqtt_sender.connect_to_ev3()

    # -------------------------------------------------------------------------
    # The root TK object for the GUI:
    # -------------------------------------------------------------------------

    root = tkinter.Tk()
    root.title('ZZ Capstone Project')

    # -------------------------------------------------------------------------
    # The main frame, upon which the other frames are placed.
    # -------------------------------------------------------------------------

    main_frame = ttk.Frame(root, padding=10, borderwidth=5, relief="groove")
    main_frame.grid()

    # -------------------------------------------------------------------------
    # Sub-frames for the shared GUI that the team developed:
    # -------------------------------------------------------------------------

    #teleop_frame, arm_frame, control_frame,drive_system_frame, sound_system_frame=get_shared_frames(main_frame,mqtt_sender)

    # -------------------------------------------------------------------------
    # Frames that are particular to my individual contributions to the project.
    # -------------------------------------------------------------------------
    # TODO: Implement and call get_my_frames(...)

    #Feature 9 Person 3
    #flashy_pickup_frame=ttk.Frame(padding=10,borderwidth=5,relief="groove")
    #flashy_pickup_button=ttk.Button(flashy_pickup_frame,text="Flashy Pickup")
    #speed_label=ttk.Label(flashy_pickup_frame, text='Starting Flash Speed')
    #speed_entry=ttk.Entry(flashy_pickup_frame, width='10')
    #increase_label=ttk.Label(flashy_pickup_frame, text='Flash Speed Increase')
    #increase_entry=ttk.Entry(flashy_pickup_frame, width='10')
    #flashy_pickup_label=ttk.Label(flashy_pickup_frame, text='Flash While Getting an Item')

    #flashy_pickup_label.grid(row=0, column=1)
    #flashy_pickup_button.grid(row=1, column=1)
    #speed_label.grid(row=1, column=0)
    #speed_entry.grid(row=2,column=0)
    #increase_label.grid(row=1, column=2)
    #increase_entry.grid(row=2, column=2)

    #flashy_pickup_button["command"]=lambda: handle_flashy_pickup(speed_entry,increase_entry,mqtt_sender)

    # -------------------------------------------------------------------------
    # Grid the frames.
    # -------------------------------------------------------------------------

    #grid_frames(teleop_frame,arm_frame,control_frame,drive_system_frame,sound_system_frame,flashy_pickup_frame)

    #--------------------------------------------------------------------------

    #Sprint 3 Stuff (Final Personalized GUI)

    #--------------------------------------------------------------------------

    filename = PhotoImage(
        file="C:\\Users\\zdanavz\\Documents\\Classes\\CS120\\Jaws.jpg")
    Jaws_Pic = ttk.Label(main_frame, image=filename)
    Jaws_Pic.grid()

    RoboShark_Frame = ttk.Frame(padding=10, borderwidth=5, relief="groove")
    RoboShark_Label = ttk.Label(RoboShark_Frame, text="ROBOSHARK")
    Hunt_Button = ttk.Button(RoboShark_Frame, text="HUNT!")
    Lazer_Beam_Button = ttk.Button(RoboShark_Frame, text="FIRE LAZER!")
    Action_Label = ttk.Label(RoboShark_Frame, text="Waiting")

    RoboShark_Frame.grid(row=0, column=1)
    RoboShark_Label.grid(row=0, column=1)
    Hunt_Button.grid(row=1, column=1)
    Lazer_Beam_Button.grid(row=2, column=1)
    Action_Label.grid(row=3, column=1)

    Hunt_Button["command"] = lambda: (handle_hunt(mqtt_sender),
                                      Action_Label.config(text="Hunting"))
    Lazer_Beam_Button["command"] = lambda: (handle_Lazer(
        mqtt_sender), Action_Label.config(text="Lazer Fired"))

    # -------------------------------------------------------------------------
    # The event loop:
    # -------------------------------------------------------------------------
    root.mainloop()
def main():
    """Creates a GUI and monitors the state of keyboard buttons to determine
        robot's motion."""

    my_delegate = MyDelegate()

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

    root = Tk()
    root.title("Mario Kart")

    main_frame = Frame(root, width=400, height=400)
    main_frame.pack_propagate(0)
    main_frame.pack()

    picture_frame = Frame(main_frame,
                          width=200,
                          height=200,
                          background='white',
                          borderwidth=4,
                          relief=RIDGE)
    picture_frame.grid(columnspan=2, row=3, column=0)

    photo1 = PhotoImage(file='blank.gif')
    photo2 = PhotoImage(file='star_mario.gif')
    photo3 = PhotoImage(file='mushroom_.gif')
    photo4 = PhotoImage(file='ink.gif')
    # photo1 = 'white'
    # photo2 = 'yellow'
    # photo3 = 'red'
    # photo4 = 'black'
    my_delegate.dc.photos += [photo1, photo2, photo3, photo4]
    my_delegate.dc.window = Label(picture_frame, image=photo1)

    forward_button = Button(main_frame, text="Forward = w")
    forward_button["command"] = lambda: forward_callback(mqtt_client)
    forward_button.grid(row=0, column=1)
    root.bind('<w>', lambda event: forward_callback(mqtt_client))

    left_button = Button(main_frame, text="Left = a")
    left_button["command"] = lambda: left_callback(mqtt_client)
    left_button.grid(row=1, column=0)
    root.bind('<a>', lambda event: left_callback(mqtt_client))

    right_button = Button(main_frame, text="Right = d")
    right_button["command"] = lambda: right_callback(mqtt_client)
    right_button.grid(row=1, column=2)
    root.bind('<d>', lambda event: right_callback(mqtt_client))

    stop_button = Button(main_frame, text="Stop = s")
    stop_button["command"] = lambda: stop_callback(mqtt_client)
    stop_button.grid(row=1, column=1)
    root.bind('<s>', lambda event: stop_callback(mqtt_client))

    powerup_frame = Frame(main_frame,
                          width=200,
                          height=30,
                          background='yellow',
                          borderwidth=6,
                          relief=RAISED)
    powerup_frame.grid(columnspan=2, row=2, column=0)

    powerup_label = Label(powerup_frame, text="Powerup:")
    powerup_label.grid(row=0, column=0)

    my_delegate.dc.powerup_label = Label(powerup_frame,
                                         text=my_delegate.dc.current_powerup)
    my_delegate.dc.powerup_label.grid(row=0, column=1)

    use_powerup = Button(main_frame, text="Use Powerup = Space")
    use_powerup['command'] = lambda: powerup_callback(mqtt_client, my_delegate)
    use_powerup.grid(row=1, column=3)
    root.bind('<space>',
              lambda event: powerup_callback(mqtt_client, my_delegate))

    quit_button = Button(main_frame, text="Quit")
    quit_button['command'] = lambda: quit_program(mqtt_client)
    quit_button.grid(row=3, column=3)
    root.bind('<q>', lambda event: quit_program(mqtt_client))

    root.bind('<KeyRelease-w>', lambda event: stop_callback(mqtt_client))
    root.bind('<KeyRelease-a>', lambda event: stop_callback(mqtt_client))
    root.bind('<KeyRelease-d>', lambda event: stop_callback(mqtt_client))

    root.mainloop()
def main():
    """Allows for the robot to connect to the computer and recieve commands"""
    robot = robo.Snatch3r()
    mqtt_client = com.MqttClient(robot)
    mqtt_client.connect_to_pc()
    robot.loop_forever()
Exemple #30
0
def main():
    mqtt_client = com.MqttClient()
    mqtt_client.connect_to_ev3()

    root = tkinter.Tk()
    root.title("MQTT Remote")

    main_frame = ttk.Frame(root, padding=20, relief='raised')
    main_frame.grid()

    green_button = ttk.Button(main_frame, text="Find Green")
    green_button.grid(row=0, column=0)
    green_button['command'] = lambda: find_color(mqtt_client, "SIG1")

    blue_button = ttk.Button(main_frame, text="Find Blue")
    blue_button.grid(row=1, column=0)
    blue_button['command'] = lambda: find_color(mqtt_client, "SIG2")

    pink_button = ttk.Button(main_frame, text="Find Pink")
    pink_button.grid(row=0, column=1)
    pink_button['command'] = lambda: find_color(mqtt_client, "SIG3")

    yellow_button = ttk.Button(
        main_frame,
        text="Find Yellow",
    )
    yellow_button.grid(row=1, column=1)
    yellow_button['command'] = lambda: find_color(mqtt_client, "SIG4")

    q_button = ttk.Button(main_frame, text="Exit")
    q_button.grid(row=14, column=2)
    q_button['command'] = (lambda: quit_program(mqtt_client, False))

    left_speed_label = ttk.Label(main_frame, text="Left")
    left_speed_label.grid(row=8, column=0)
    left_speed_entry = ttk.Entry(main_frame, width=8)
    left_speed_entry.insert(0, "600")
    left_speed_entry.grid(row=9, column=0)

    right_speed_label = ttk.Label(main_frame, text="Right")
    right_speed_label.grid(row=8, column=2)
    right_speed_entry = ttk.Entry(main_frame, width=8, justify=tkinter.RIGHT)
    right_speed_entry.insert(0, "600")
    right_speed_entry.grid(row=9, column=2)

    forward_button = ttk.Button(main_frame, text="Forward")
    forward_button.grid(row=10, column=1)
    # forward_button and '<Up>' key is done for your here...
    forward_button['command'] = lambda: handle_forward_button(
        mqtt_client, left_speed_entry, right_speed_entry)
    root.bind(
        '<Up>', lambda event: handle_forward_button(
            mqtt_client, left_speed_entry, right_speed_entry))

    left_button = ttk.Button(main_frame, text="Left")
    left_button.grid(row=11, column=0)
    left_button['command'] = lambda: handle_left_button(
        mqtt_client, right_speed_entry)
    root.bind('<Left>',
              lambda event: handle_left_button(mqtt_client, right_speed_entry))
    # left_button and '<Left>' key

    right_button = ttk.Button(main_frame, text="Right")
    right_button.grid(row=11, column=2)
    right_button['command'] = lambda: handle_right_button(
        mqtt_client, left_speed_entry)
    root.bind('<Right>',
              lambda event: handle_right_button(mqtt_client, left_speed_entry))
    # right_button and '<Right>' key

    back_button = ttk.Button(main_frame, text="Back")
    back_button.grid(row=12, column=1)
    back_button['command'] = lambda: handle_back_button(
        mqtt_client, left_speed_entry, right_speed_entry)
    root.bind(
        '<Down>', lambda event: handle_back_button(
            mqtt_client, left_speed_entry, right_speed_entry))
    # back_button and '<Down>' key

    up_button = ttk.Button(main_frame, text="Up")
    up_button.grid(row=0, column=2)
    up_button['command'] = lambda: send_up(mqtt_client)
    root.bind('<u>', lambda event: send_up(mqtt_client))

    down_button = ttk.Button(main_frame, text="Down")
    down_button.grid(row=1, column=2)
    down_button['command'] = lambda: send_down(mqtt_client)
    root.bind('<j>', lambda event: send_down(mqtt_client))

    stop_button = ttk.Button(main_frame, text="Stop")
    stop_button.grid(row=11, column=1)
    left_button['command'] = lambda: handle_stop(mqtt_client)
    root.bind('<space>', lambda event: handle_stop(mqtt_client))
    # stop_button and '<space>' key (note, does not need left_speed_entry, right_speed_entry)

    root.mainloop()