:::: MENU ::::

How to program a robotic brain

The field of robotics is often associated with either research or large manufacturing. Robots build cars or they attempt to do new things robots haven’t done before. Rarely do we think of robots as tools for education, but it is a field that is becoming more and more prominent. Universities around the world already offer courses and degrees to do with robotics, but where do we start before that? This article explores an easy way to get into robot programming and was first published for Pluralsight.

Ever since I saw “Alien” for the first time and the character of Ash turned out to be a robot (that went quite a bit mad), I have had a fascination for artificial humans and humanoid characters. The premise of being able to build machines that can do complex tasks for us independently is both scary and fascinating at the same time.

A recent article that outlined the ethics around robotics and their automation reinvigorated my interest in programming robots (to do my bidding). The article featured quotes from Bill Gates, Elon Musk and Stephen Hawking on how to manage automation in a modern society and posed interesting thoughts on how to make robots part of our day-to-day life. Some economists have suggested that 45 percent of all U.S. jobs could be performed and replaced by robots in the next 20 years, so this question will only become more urgent.

Robotic programming

Because of the often bespoke nature of robotics, their programming has also traditionally been completely bespoke. We haven’t had the “PC” of robots, which has made a single paradigm the norm for robotic programming, so each platform has, in essence, created their own standard. In recent years, a number of frameworks , such as dLife for the Java language and CLARAty from NASA, have sprung to life. Even Microsoft has their own Robotics Developer Studio. 

What these frameworks and platforms have in common is that they are academic in nature and often require a significant investment to even get started. The hardware is expensive, the programming requires highly specialized professionals and the interest from the public is very limited.

Which brings me to Cozmo.

Cozmo

This past Christmas, we got our 11-year-old child a Cozmo robot. It is a robot with attitude that can recognize your face, play games with you and get annoyed when it loses. It understands its environment and where obstacles are in its vicinity. It sneezes, falls asleep, has a tantrum when it loses a game and displays plenty of human characteristics. Included in the package are three blocks with color LEDs which Cozmo can control, pick up and interact with.

The interesting thing is that you can program Cozmo yourself using very simple Python code snippets. No academic frameworks required, and, in fact, an 11-year-old child can program it. Anki, the company behind Cozmo, has done a great job of abstracting all the complicated engineering work away from the developer, so all you have to focus on is making Cozmo “do stuff.”

For example, to program Cozmo to talk to you, the code would look like this:

import cozmo

def cozmo_program(robot: cozmo.robot.Robot):
    robot.say_text("Pluralsight loves you").wait_for_completed()

cozmo.run_program(cozmo_program)

To make Cozmo do your (evil) bidding, you connect directly to it in the smartphone app’s developer mode. The app for Cozmo comes with pre-built games as well. Once you have mastered the basics, you can develop your own games to make Cozmo react to your facial expressions, objects in its vicinity and other events. With simple code such as the example below, Cozmo can look for cubes and light them up when it finds them. If it finds two cubes, it will stack them.

lookaround = robot.start_behavior(cozmo.behavior.BehaviorTypes.LookAroundInPlace)

cubes = robot.world.wait_until_observe_num_objects(num=2, object_type=cozmo.objects.LightCube, timeout=60)

lookaround.stop()

if len(cubes) < 2:
        print("Error: need 2 Cubes but only found", len(cubes), "Cube(s)")
else:
        robot.pickup_object(cubes[0]).wait_for_completed()
        robot.place_on_object(cubes[1]).wait_for_completed()

The entire SDK for Cozmo is equally simple and easy to use, and because it utilizes Python, it is quick to pick up and create fun experiences with Cozmo.

Program your own robot

You can build simple experiences for other robot platforms, but, in my opinion, none are as infectious as Cozmo. With his cheeky behavior, fun games and small form factor, he is easy to use anywhere and for anyone. Cozmo is relatively cheap for such an advanced device, and by following the simple get started guide, you will be on your way in no time. I am giving a talk on how to program Cozmo at NDC Sydney in August, and it will be filled with cheekiness and attitude. See you there?