It was downloading the latest update to the Tickle app application that made me realize that I hadn’t written a program to make my Sphero do something for a while.  A look at the street closings in town for the Santa Claus parade gave me a bit of an inspiration.

• there are lots of turns to be made
• there are four stop lights along the main street in town
• some drivers seem to make random turns at time
• I wonder if people will end up where they plan as a result

There’s my inspiration.  Sure, I play around with Sphero chasing the dog around the rec room but this would be something that would have a bit of a focus.

So, here’s my program.

The nice thing about Tickle for those of us who grew up on code is that you can actually see the scripting that makes the magic happen.

Stepping back and going on a tangent here, this introduction illustrates one of my frustration with block programming languages.

I know exactly what I want to make Sphero do.  Chances are, you’re going to have to spend a few moments to figure it out.  I find it frustrating when people demonstrate or students code by going directly to the language and try to make things happen.  I grew up, and I taught my students, about the importance of planning in advance and of the value of internal documentation to a program.  I reminds me of the advice that “if a program was hard to write, it should be harder for others to modify”.  That bit of sarcasm is guaranteed to NOT land you the job.

So, here’s my explanation of the program.

• I’m going to simulate a stop light for the Sphero movement – Sphero is going to be both car and light.  You’ll start at a red light where Sphero is stopped.  The program makes Sphero turn red accordingly.
• The red light lasts three seconds.
• When the light turns green, Sphero will turn green and move.
• How Sphero moves is dependent of the results of a random number.  If the random number is 1, then Sphero turns right.  If the random number is 2, then Sphero turns left.  If the random number is 3, then Sphero goes straight ahead.
• The actual movement of Sphero is 2 seconds at a speed of 50% of full.  Truth in numbers – I would need a bigger floor space to make that happen; when playing around with the program, I adjusted these to lower numbers.
• An amber light signals that Sphero needs to get ready to stop and does.
• We’ll repeat this for the four stop lights in town.
• My red lights are three seconds in duration.  That’s totally unrealistic in real life but it seems to take forever when you test it.

And I had a bit of fun playing around while the dog went to another place in the house.

I wonder – how could I make it better?  How about using it to explore things on a road trip or a little question about randomness?

• What would have to happen for Sphero to go straight through town without making any turns?
• What would have to happen for Sphero to turn around?  U-turns aren’t legal.
• Would I end up in the same place every time the program runs?  Of course not – but how many different places could it possibly end?  Could we plot it on a map or chart paper?
• What would be the scenic highlights of the roadtrip in our town?
• What would you see if, instead of starting in town, we tracked Sphero’s movement if it started at Yonge and Bloor Streets in Toronto?

I think that questions like this along with the corresponding programming make for a great bit of fun and certainly more understanding.

## Author: dougpete

The content of this blog is generated by whatever strikes my fancy at any given point. It might be computers, weather, political, or something else in nature. I experiment and comment a lot on things so don't take anything here too seriously; I might change my mind a day later but what you read is my thought and opinion at the time I wrote it! My personal website is at: http://www.dougpeterson.ca Follow me on Twitter: http://www.twitter.com/dougpete I'm bookmarking things at: http://www.diigo.com/user/dougpete

## 5 thoughts on “A Sphero roadtrip”

1. Thanks for the great post, and a reminder, as I prepare to start my students on Scratch, that we will need a reminder that our science/design/creative process rhinking has to apply here, too. What do we want to do, and how can we plan it effectively?

Like

2. I am so glad you retain your sense of wonder. And that you share stuff like this. Thanks for brightening my day.

Like

3. I want to mention the documentation. I’m learning a new platform, and the code for a longish sample tutorial has example TWO lines of documentation. Some judicious use of comments is always welcome.

Like