Skip to main content

Python SDK

Python library to work with your Misty robot. Currently in BETA. It is designed to follow the same naming conventions that will show up in the API Explorer. There is a method generator built in to update the built in methods and available events, this works on all current Misty II product versions.

Requirements

python >= 3.8

requests>=2.25.1
websocket-client<=0.57.0
yapf>=0.30.0


Updating available commands and events

After installing the requirements, the first thing that should be done is updating the methods and events using the builtin generator.

# First import the RobotGenerator
from mistyPy.GenerateRobot import RobotGenerator

# Creating a new robot generator will rewrite the RobotCommands.py and Websocket.py 
# files to adjust them to the commands and websockets the robot has available
RobotGenerator("<IP_ADDRESS>")

Running commands

To send commands to the robot first we need to initialize the connection to the robot.

# First import the robot object
from mistyPy.Robot import Robot

if __name__ == "__main__":
    ip_address = "<IP_ADDRESS>"
    # Create an instance of a robot
    misty = Robot(ip_address)

Sending the commands uses the REST API for Misty, so every return from a command will be a response object.

    current_response = misty.MoveArms(30, 20)
    print(current_response)
    print(current_response.status_code)
    print(current_response.json())

    current_response = misty.GetLogLevel()
    print(current_response)
    print(current_response.status_code)
    print(current_response.json())
    print(current_response.json()["result"])

Output:

<Response [200]>
200
{'result': True, 'status': 'Success'}
<Response [200]>
200
{'result': {'local': 'Debug', 'remote': 'Debug'}, 'status': 'Success'}
{'local': 'Debug', 'remote': 'Debug'}

Events

Subscribing to events is done through the Robot object. The list of available events are found in the Events class.

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

There are then two ways of interacting with the events. The first is to use a callback function for every new message returned after the successful subscribtion, the second is to reference the event object itself. By default all event registrations are set to trigger once then unregister. To set an event registration to constantly trigger use the keep_alive parameter and set it to True.

Example:

misty.RegisterEvent("AudioCallbackEvent", Events.VoiceRecord, callback_function=capture_speech_callback, keep_alive=True)

Using a callback function

# The callback function must only accept one parameter, which will be the event message data
def capture_speech_callback(data):
    print(data["message"])

if __name__ == "__main__":
    try:
        # First create the robot object
        ip_address = "<IP_ADDRESS>"
        misty = Robot(ip_address)

        # Register the event, which has a minimum of 2 parameters: the user defined name of the event, and the event type
        misty.RegisterEvent("AudioCallbackEvent", Events.VoiceRecord, callback_function=capture_speech_callback)

        # Start recording speech to get an event message
        misty.CaptureSpeechAzure(overwriteExisting=True, requireKeyPhrase=False, captureFile=True, speechRecognitionLanguage="en-us", azureSpeechRegion="eastus", azureSpeechKey=my_speech_key)

        # Use the KeepAlive function to keep running the main python thread until all events are closed, or the script is killed due to an exception
        misty.KeepAlive()

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

Output:

{'errorCode': 0, 'errorMessage': 'Detected end of voice command.', 'filename': 'capture_Dialogue.wav', 'speechRecognitionResult': 'How are you doing?', 'success': True}
Event connection has closed for event: AudioCallbackEvent

Using the Event object

if __name__ == "__main__":
    try:
        ip_address = "<IP_ADDRESS>"
        misty = Robot(ip_address)

        # Not including the callback_function parameter
        audio_callback_event = misty.RegisterEvent("AudioCallbackEvent", Events.VoiceRecord)

        misty.CaptureSpeechAzure(overwriteExisting=True, requireKeyPhrase=False, captureFile=True, speechRecognitionLanguage="en-us", azureSpeechRegion="eastus", azureSpeechKey=my_speech_key)

        # Wait for the event to get some data before printing the message
        while "just waiting for data" in str(audio_callback_event.data):
            pass

        print(audio_callback_event.data["message"])
    except Exception as ex:
        print(ex)
    finally:
        misty.UnregisterAllEvents()

Output:

{'errorCode': 0, 'errorMessage': 'Detected end of voice command.', 'filename': 'capture_Dialogue.wav', 'speechRecognitionResult': 'What are you doing?', 'success': True}

Adding event filters

There are built in methods for adding filters to the events. By default there are a handful of built in event specific filters. A sample are shown here:

from mistyPy.EventFilters import EventFilters

misty.RegisterEvent("right_arm", Events.ActuatorPosition, condition=[EventFilters.ActuatorPosition.ArmRight])

The condition parameter takes a list of filters to apply, so the event conditions can be combined:

front_right = misty_robot.RegisterEvent("frontright", Events.TimeOfFlight,
                                        condition=[EventFilters.TimeOfFlightPosition.FrontRight, 
                                                   EventFilters.TimeOfFlightDistance.MaxDistance(0.150),
                                                   EventFilters.TimeOfFlightStatus.MaxStatus(102)])

There is also a method to build up your own filters that are not built in yet. The following example shows creating an event filter such that the returned voice record event must have an error code of 0 for the event to be triggered

misty.RegisterEvent("found_speech_result", Events.VoiceRecord, condition=[EventFilters.event_filter("errorCode", "=", 0)])

Metadata

Release files for Misty-SDK 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for Misty-SDK 0.1.1
File Interpreter ABI Platform Actions
Misty_SDK-0.1.1-py3-none-any.whl Python 3 none any Details for Misty_SDK-0.1.1-py3-none-any.whl

Release files / Misty_SDK-0.1.1-py3-none-any.whl

Download URL Misty_SDK-0.1.1-py3-none-any.whl
Size 23.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a757615a30bac76e04d0bd3dd7c423a775491551e0e0f12033c4dd0aa8c0d161
BLAKE2b-256 checksum
How to use checksums
df58bccf7b1f2b528538875e80f2f62a16de810af5474924695c24a7f39d8171
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.4.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.9.0

Security for Misty-SDK 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.1 This release

1 release file No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page