Hi all, this post is going to contain a lot of background, so for those of you looking for the tldr: I’ve written a library that you can upload to your Sparki, which can then be used with a library I’ve written for Python. You can write Python programs with this library and control your Sparki with Python. The github can be found here: https://github.com/radarjd/sparki_learning
Okay, so now the background, which will be cathartic for me if not interesting to anyone else. I teach a class in Robot Programming using the Institute for Personal Robotics in Education (IPRE) Myro library using the Scribbler 2 / Fluke robot combo. The IPRE provides a textbook free of charge, and use of this particular robot and the text predates my involvement with the class. The Myro API itself is fine, but the Calico Project IDE gives me and my students lots of problems. Moreover, it has its own internal implementation of Python, and cannot use many standard libraries.
About a year ago, I got a Sparki and saw its potential as a robot to be used in education. Unfortunately, there wasn’t a python library for it. Fortunately, it had Bluetooth, so I knew one could be written. I did not have the impetus to write the library at the time so I didn’t.
This year a local high school, targeted at poor and underprivileged but smart high school students, was founded and requested my help with the robotics program. We met and I suggested that they use the Sparki, though I noted that there wasn’t a Python library. There was some discussion that either the college (where I am an adjunct) or the high school would pay me for development of the library, but I heard little and forgot about it. Several months later, the high school contacted me and said they’d bought the robots and asked when the library might be available. They used their entire budget on the hardware purchase. Rather than leave them with expensive hardware (for an inner city school) and nothing to show for it, I wrote the libraries which are attached.
The concept behind the libraries is that Sparki runs an interpreter to which Python sends commands over Bluetooth:
While I am not the most talented of programmers, these were no small task. The C code which runs on the Sparki is 1199 lines (with internal spaces) and the Python code is 1952 lines (with internal spaces). They implement most of the Myro API, so an educator wishing to do so could make use of the existing materials published by the IPRE (see http://calicoproject.org/Learning_Computing_With_Robots_Using_Calico_Python). Further, using the Python library allows you to teach programming without the compile / upload cycle, and allows the students to get immediate feedback from their work.
I have tested the libraries to the extent I am able – I’m certain there are bugs and edge cases I have missed. The Sparki library was particularly challenging as I haven’t done extensive C++ programming since college, and the Sparki is extremely limited in space – the compiled library uses 28,650 bytes of the 28,672 bytes available. Adding the String data type pushed the robot over the limit, so everything is done with char*. Probably a better coder than I could have done better, and I hope someone will take what I’ve done and improve it. I have limited access to a Mac, so while I have tried the Python code out on it, there may be some implementation specific issues. I have not tried it on Linux at all.
The code is released under the Apache 2.0 license with one exception – I would ask that Arcbotics only link to the library and not distribute it. In an attempt to recoup some of my time, I contacted the company, but it was unwilling to pay anything at all for it. I understand that every business has to weigh costs and benefits, and they don’t see the benefits. That is fine, but it should not be distributed by them, nor should they create derivative works from it.
I hope this code is of use to students and educators. I have commented the code heavily and used a variety of techniques in the Python portion, which again I hope is useful. I did not use OOP – this was partially a stylistic choice, but also because I think it can be challenging for students who are not intending to be computer scientists or professional programmers. It’s not that elementary school students can’t be taught OOP, but I do think it can get in the way. Others can (and I’m sure, do) disagree, and that’s fine – rewrite or wrap it as an OOP library!
Sparki is a fantastic piece of hardware. I hope this library aids in your enjoyment of it and the enjoyment of your students. If anyone has any suggestions or finds any bugs, please let me know and I will try to fix them when I have the opportunity.