Home Community Blog Buy Now
Blog

Misty Community Forum

RegisterEvent() in the newly released Python SDK does not appear to be working consistently for all events

Hello,
I am using the Python SDK. I am able to do basic things such as change LED, moveArms, etc… However, I am having problem with successful registering to all the events. The events such as Actuator Position and BatteryCharge worked just fine. However, two of the events that are critical to my projects, namely IMU and Time of Flight are not returning any data back. As an example, I tried to register to the IMU Event Type as shown below. But I am not getting any data back even after waiting for a long time. Please see a sample below.

I am also a newbie with threading concept, so I am not sure if I have to manually create new threads when registering for events using Python SDK.

************* RUN-able code after entering the right IP address ************

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

if name == “main”:
try:
# First create the robot object
ip_address = “xx.xx.xx.xx”
misty = Robot(ip_address)

    _Data = misty.RegisterEvent(event_name="IMU_data", event_type=Events.IMU)
    print(misty.active_event_registrations)
    print(_Data.data)
    print(_Data.event_name)
    print(_Data.event_type)
    print(_Data.is_active)
    print(_Data.data["message"])

    misty.KeepAlive()

except Exception as ex:
    print(ex)
finally:
    # Unregister events if they aren't all unregistered due to an error
    misty.UnregisterAllEvents()

The result from the print() statements is as below.
{‘IMU_data’: <mistyPy.Events.Event object at 0x00000256BE942B20>}
{‘status’: ‘Not_Subscribed or just waiting for data’}
None
IMU
True
‘message’

If I am understanding it correctly, the registration to the IMU event type is active (per the first print() statement result). Then in the next statement, it says ‘Not subscribed or waiting for data’. I have tried waiting for a very long time (~10minutes or so) and I don’t see any data coming back. For _Data.event_name, I was expecting “IMU_data” but it is giving me None… Lastly, I don’t see the desired results in _Data.data["message].

I have tested the code in both Windows and Ubuntu OS.

I would really appreciate any help here. Thanks!

I was able to find my mistake.
I was missing the following statement.
while “just waiting for data” in str(_Data.data):
pass

The following code gave the expected results.

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

if __name__ =="__main__":
    try:
        # First create the robot object
        ip_address = "IP ADDRESS"
        misty = Robot(ip_address)

        _Data = misty.RegisterEvent("IMU_data", Events.IMU)


        # Wait for the event to get some data before printing the message
        while "just waiting for data" in str(_Data.data):
            pass
        print(misty.active_event_registrations)
        print(_Data.data)
        print(_Data.event_name)
        print(_Data.event_type)
        print(_Data.is_active)
        print(_Data.data["message"])

        #misty.KeepAlive()

    except Exception as ex:
        print(ex)
    finally:
    # Unregister events if they aren't all unregistered due to an error
        misty.UnregisterAllEvents()