🏷️QR code detector

With this feature it's possible for Misty to detect and read QR codes. These can be used to tag spaces, for example: labs, classrooms, kitchens or living rooms to make Misty start actions.

We suggest to use a printed QR code, about 15x15 cm. The QR code that we used for this project is the Misty Lessons one.

This project will only work in the Misty Desktop Environment because we will modify the events file.

Open the folder containing the Python-SDK that you use for the desktop environment. The folder should look like this one.

Open the folder MistyPy, open the file Events.py in Visual Studio code and modify the Events class to add the QRdetection Event.

Now you're ready to use Misty's scanning QR capabilities in Python.

Python Code

from mistyPy.Robot import Robot
from mistyPy.Events import Events

misty = Robot("YOUR_ROBOT_IP_ADDRESS") #your Robot IP Address

misty.change_led(0, 255, 0)
misty.move_head(0, 0, 0)

misty.start_qr_tag_detector()

def code(data):
    print(data) #this shows all the data related to the event
    print(data['message']['decodedInfo'])

misty.register_event(event_name='qrtag_event', event_type=Events.QrTagDetection, callback_function=code, keep_alive=True, debounce = 500)

misty.keep_alive()

In the first part of the code, we set the robot by initializing the libraries, calling it and setting it in a standard position. Once these actions are done we start the event like any other event in the Misty world by calling the action .start_qr_tag_detector().

We create a function that will handle the data read by scanning the QR code. We can then register the event and then keep it alive.

You can insert if statements to handle different QR codes and assign to each a different Misty action.

For example, if we want Misty to turn her RGB LED purple when she recognizes the QR code of the Misty lessons or have the RGB LED red when she doesn't, our function can look like this one:

def code(data):
    print(data['message']['decodedInfo'])
    if data['message']['decodedInfo'] == 'unknown person': #intruder
        misty.change_led(100, 70, 160)
    else :
        misty.change_led(255, 0, 0)

Last updated