I've coded for the Sphero in the past using the Node.JS SDK, but this is my first time working with the Sphero's Windows SDK.
I played around with the SDK and it feels pretty similar, although it seems like it is missing some features that are present in the SDK for other platforms.
For the project, you will need:
- 2x Sphero 2.0
- 1x Windows 10 Computer with Bluetooth
- Visual Studio
- (Optional) Azure Application Insights
_______________________________________________________________
Week 1:Creating the initial project! I created a very unfinished UI for the program. You can connect two Spheros to the program. One has the "master" role, and the other has the "follower" role.
Right now, the program has which of my Spheros should be in which role hard-coded in. I plan on having a drop-down box to select which connected Sphero(s) should be in which role.
Once connected, the master Sphero displays the gyroscope information, the gyroscope information it had when it first connected (the default/origin), and the cumulative offset the Sphero has had since it connected. You can reset the origin and offset. You can set the heading (rotation) of the Sphero. You can also choose to turn off the stabilization (the motors that make sure the Sphero is always rotated the right way).
Turning off stabilization required a bit of witchcraft. The Sphero Win-SDK doesn't contain a function for it like the SDKs for other platforms do. It does, however, have a function that sends a raw message to the Sphero. It uses this function to build the other functions (like rolling or changing color). I dug around the SDK for other platforms and found the proper message to send to the Sphero. After building the message, it works!
The follower Sphero can have its heading (rotation) set in the UI.
_______________________________________________________________
Week 2:This week, the project is actually starting to take shape! I added drop-down boxes to choose which Sphero should be the master and which Sphero should be the follower. I got rid of my attempts at reading the gyroscope and I am instead reading the pitch and roll of the Sphero.
The Sphero Win-SDK seems really unfinished compared to the Sphero SDK for iOS and Android. The event for reading the attitude (pitch and roll) doesn't work! I'm instead using the event that reads the accelerometer. I then calculate the pitch and roll using the accelerometer data.
You can now actually control the follower Sphero using the master Sphero! It works like a joystick steering a car (tilt the master forward to make the follower roll forward, tilt it right and forward to start rotating to the right while rolling forward, etc). It works best if you put the master in the charging cradle (unplugged) and rotate it inside of the cradle. I'm still working on figuring out what values work best for the maximum speed and turning. I may switch it to work more like the digital joystick in the official Sphero app instead, but I haven't decided for sure.
In addition to fine-tuning the controls next week, I also would like to make it so the master Sphero says how fast it is going to make the follower Sphero roll by changing colors. (Red for slow, yellow for medium, and green for fast.)
_______________________________________________________________
Week 3:The project is mostly finished and functional. As part of the requirements for the MSP Sphero Pilot, a use of Microsoft Azure was included. I replaced all the debug messages with Azure Application Insights. It was incredibly easy to do.
The controls were changed away from "car" controls (accelerate, decelerate, turn) to instead be relative to the way you tilt the master Sphero. Thus, if you tilt the master Sphero back towards you and to the left, the follower Sphero moves back towards you and to the left.
Since the movement is relative to the master Sphero, I added a calibration setting that works fairly similar to the one in the official Sphero application.
If the follower will not move, the master Sphero does not light up. If the follower is moving at a speed less than a third of its max speed, the master lights up red. If the follower is moving at a speed between a third and two-thirds of the max speed, the master lights up yellow. If the follower is moving at a speed of over two-thirds of the max speed, the master lights up green.
Next week I plan to add a color picker and to make the master Sphero shake when the follower runs into something.
_______________________________________________________________
Week 4:The project is finished!
A color picker was added in the form of sliders for red, green, and blue for the follower Sphero. You can also choose to instead sync the color of the follower Sphero with the master Sphero.
There is a toggle to make the master Sphero shake when the follower runs into a wall. This can also get triggered if the follower hits a bump. If you use this feature, you will need to calibrate the master.
Comments