We're going to be playing with a Sphero robot on Make Day! The two activities in this repo are intended to give you some familiarity with Sphero's Javascript SDK. Since you probably don't have a Sphero at home, we'll use a mock library that will give you the basic idea of which commands you can use to interact with the robot.
Make sure you've installed NodeJS, which allows you to run JavaScript files in the terminal. You can edit activity files in the text editor of your choice. We personally like Sublime or Virtual Studio, but others are great too.
If you want explore the SDK itself then have a look here: https://github.com/orbotix/sphero.js
We've also created a Sphero CLI for the Make Day so if you want to have a look at that before hand then go here: https://github.com/OfferZen-Make/sphero-cli
Cheat Sheet. Below are the commands you'll be learning about:
-
sphero.connect
: Connects to Sphero. All your code goes inside this function. -
sphero.roll
: Takes two arguments - distance (unitless) and direction (in degrees). The direction you specify is clockwise relative to the x-axis - see the image below:
-
sphero.setColor
: Takes a string with the color as argument. In lower-case, e.g. "blue", "red", "green", etc. -
sphero.getColor
: Returns Sphero's current color. -
sphero.readOdometer
: We've cheated a little here! In the Sphero SDK the Odometer streams data asynchronously when invokingstreamOdometer
, while here we're just returning Sphero's position. We've included this function so you can get a little familiar with the concept.
TIP: See example.js
for all of the commands required to finish the two activities.
Change Sphero's color and move him programmatically.
- Open activity_1.js and add the required code so that Sphero's final position is at (0, 200) and it's color is "blue".
- Run the activity with
node activity_1.js
.
Sphero's initial position is randomized: Find Sphero's coordinates with the Odomoter and move him to (0, 0). Send Sphero home!
- Open
activity_2.js
and find Sphero's initial position. - You have to send Sphero back to (0, 0), so use the Odometer's reading and figure out a way to do that!
- Run the activity with
node activity_2.js
.