🐍Python Lessons
Learning with Python
In recent years Python has become one of the most popular programming languages for education in computer science and robotics. Its simplicity, versatility, extensive libraries and robust community support makes it an ideal choice for both robotics beginners and experienced programmers who are looking to elevate their knowledge about Human-Robot Interaction. Throughout Misty Python Lessons you will learn the basics of syntax coding in Python, as well as explore how to utilize Misty's capabilities to create fun and real-life applications for your projects.
Misty's Python Interface
Misty's Python Interface is designed to directly use Misty’s hosted API endpoints, acting as an API client for Misty. This API client is generated by calling Misty's API and producing Python code as a result. Misty currently runs Python 3.9, built for a 32 bit ARM architecture running on Windows. Misty also hosts a Python Language Server, which gives her the ability to analyze your Python scripts, providing code completion, highlighting, and syntax validation. Misty even has a Python editor that you can use to create and debug your code!
Misty's built-in Python interface uses the Python runtime, Python Language Server, and version of the Monaco editor to allow for simple Python development within Misty Studio.
To start using Python on Misty, open Misty Studio and navigate to Programming, then Python. You should see Misty's Python editor.
The buttons at the top of the page give you the tools necessary to start programming Misty. Here's what each of them does:
The 'New' button clears the editor window of all text
The 'Open' button lets you select an existing Python script to run on Misty
The 'Save' button lets you save your Python code to your computer
The templates dropdown give you some code to start with, which makes creating your first programs easier
The 'Load Template' button loads the contents of the selected template into the editor. Be careful, it'll replace anything currently in the editor!
The 'Run' button runs your script on Misty
The 'Stop' button stops a currently running script
At the bottom of the editor, you'll see three boxes labelled 'Messages', 'Output', and 'Errors'.
Because Python scripts are run using the Python runtime on Misty, some of the outputs are what you'd expect to see from any shell script. The 'Output' box captures anything that your script outputs when using the Python 'print' function. These statements are reported after the script has completed execution. Similarly, the 'Errors' box captures any unhandled error produced by your script, which you'll be presented with after the completion of the script. Lastly, the 'Messages' box receives debug messages sent from your code in real time.
Building Python Skills
Every Python program on Misty starts with importing the Misty Python library and the robot as shown in the example below. When you start building a new program these lines are already in place.
To start programming Misty in Python and building skills you will also need to familiarize yourself with her API endpoints in the API Explorer under the Programming tab in Misty Studio and Misty Python API.There are approximately 150 endpoints that you can discover.
Calling Misty’s API endpoints in Python
Once you've imported the libraries and the robot you will be able to call your APIs. To call Misty’s API endpoints in Python and have her execute a certain command you will need to start your code with ‘misty’ followed by a dot. After the dot you can write in the name of the API endpoint you want to call, for example if you want to call the head or arm movement APIs, you will need to use the following syntax to select a list of actions when typing an API call.
Once you've determines the APIs you want to use, you can place them after misty=Robot().
Since Misty’s Python uses the same API endpoints as Misty’s Blockly, you can use the same values in the parameters, however they are not as easy to identify. To check the name and order in which your values need to be set in Python, you can add a comma in the brackets as shown in the example below.
There are different ways you can write your values in the parameters. For example you can follow the parameter structure in the brackets or just write the values in the corresponding order.
The programming term to refer to the name of the box that contains the value is “label”. When you start writing the parameters in Misty’s Python interface Misty will give you suggestions and you can select your label by clicking on the tab.
This is really useful when your commands can contain a lot of parameters and you need to name only some of them while leaving the rest as default.
Of course if you are naming them manually you can choose which ones to insert and which ones to omit.
Or
Start Lessons
🦿Lesson 1: Loco-motionLast updated