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.
What would you ask?