Getting Started With the Cozmo SDK
To make sure you get the best experience possible out of the SDK, please ensure you have followed the steps in the :doc:`Initial Setup </initial>`.
Cozmo SDK Forums
Please visit our Cozmo SDK Forums where you can:
- Get assistance with your code
- Hear about upcoming SDK additions
- Share your work
- Join discussion about the SDK
- Be a part of the Cozmo SDK Community!
Starting Up the SDK
- Plug the mobile device containing the Cozmo app into your computer.
- Open the Cozmo app on the phone. Make sure Cozmo is on and connected to the app via WiFi.
- Tap on the gear icon at the top right corner to open the Settings menu.
- Swipe left to show the Cozmo SDK option and tap the Enable SDK button.
- Make sure the SDK examples are downloaded from the :doc:`Downloads page </downloads>`.
- On the computer, open Terminal (macOS/Linux) or Command Prompt (Windows) and type
cd cozmo_sdk_examples, where cozmo_sdk_examples is the directory you extracted the examples into, and press Enter.
For your convenience, here is a video detailing the first few simple example programs. You can also find a simple text-based walkthrough of running your first program below.
First Steps - "Hello, World!"
Let's test your new setup by running a very simple program. This program instructs Cozmo to say "Hello, World!" - a perfect way to introduce him and you to the world of programming.
- To run the program, using the same Terminal (macOS/Linux) / Command Prompt (Windows) window mentioned above:
First, change to the
01_basics sub-directory of the
For macOS and Linux systems, type the following and press Enter:cd tutorials/01_basics
For Windows systems, type the following and press Enter:cd tutorials\01_basics
Then, run the program.
For macOS and Linux systems, type the following and press Enter:./01_hello_world.py
The same can also be achieved on macOS/Linux with:python3 01_hello_world.py
For Windows systems, type the following and press Enter:py 01_hello_world.py
- If done correctly, Cozmo will say "Hello, World!"
If Cozmo does not perform as expected, look at the first Terminal window and make sure no error messages appeared. If you continue to have issues, please seek help in the Forums.
The code for the Hello World program can be viewed here.
The usbmuxd (USB Multiplexor Daemon) must be installed on any computer system paired with an iOS device before running any programs. Installing iTunes will also install the usbmuxd on those systems. Linux users can install the usbmuxd module through the command line with sudo apt-get install usbmuxd.
Make sure adb (Android Debug Bridge) is installed on your system prior to running a program with an Android device. See the :ref:`Install page <initial>` for instructions.
You are now all set up to run Python programs on Cozmo. Next we will go over how to edit the above code to make Cozmo say something new. Let's write our first program.
Next Steps - "Night-Night"
01_hello_world.pyto a new file named
nightnight.pyby doing the following:
For macOS and Linux systems, type the following and press Enter:
cp 01_hello_world.py nightnight.py
For Windows systems, type the following and press Enter:
copy 01_hello_world.py nightnight.py
Now, nightnight.py is saved in the same folder as 01_hello_world.py.
Open this new document in a source code editor or plain-text editor. Free source code editors, such as PyCharm Community Edition , Atom , Sublime , or TextWrangler can be found online. Anki does not provide tech support for third-party source code editors.
Each line in the program relates to a specific function.
import cozmoallows your program to access the Cozmo SDK code contained within the
Text sandwiched between three
'marks is a Docstring. Docstrings are like comments, and are placed inside code to give information to the user.
robot.say_text("Hello, World!").wait_for_completed()is the core of the program:
robot.say_text(…)is the function that makes Cozmo speak a string out loud.
"Hello World"is the string which Cozmo will speak.
wait_for_completed()tells Cozmo to finish speaking before moving to the next line of code. Without this, our program would end before Cozmo said anything!
Move to the line that starts with "robot.say_text"
- Select the phrase "Hello World". Do NOT select the parentheses or quotation marks around the phrase; those are necessary for Python to properly parse the command.
- Type in the new phrase you would like Cozmo to say. In this example, Cozmo will say "Night Night", so that line should look like this:
Save the nightnight.py file.
Now you can run your program:
For macOS and Linux systems, type the following into the same Terminal window and press Enter:
For Windows systems, type the following into the same Command Prompt window and press Enter:
If done correctly, Cozmo will say the new phrase.
Now that you have written your own Cozmo program, take a look at the rest of the Cozmo SDK and at the many other example programs to get more ideas.