I just pushed a new update to the github repository (https://github.com/radarjd/sparki_learning
) with version 1.1.0 of the python library containing what I'm calling the "grid commands". The following commands have been added:
drawFunction(function, xvals) - draws the function given on the coordinate plane; the function given as the argument should be a lambda function which calculates the y coordinate for a given x; the xvals argument should be an iterable of the x values for which to calculate a y value; a test / example python file has also been added demonstrating the use of this function
getAngle() - returns the current heading of the robot in degrees, where Sparki starts at 0 degrees when initialized; only turns done through turnBy() will be "tracked" for the purposes of this command; a heading of 0 is treated as going up the y axis
getPosition() - returns the current position of Sparki on the coordinate plane
moveBy(x,y) - moves to the x,y position relative to the current position; the behavior of this command is exactly the same as a moveTo() executed immediately following initialization
moveTo(x,y) - moves to the x,y position indicated on the coordinate plane
resetPosition() - resets the position to a heading of 0 and a current position of 0,0
setAngle(degrees) - sets the current heading of the Sparki
setPosition(x,y) - sets the current position on the coordinate plane
The turnTo(degrees) command has had its behavior changed since the previous version. It will now turn to the heading given as the argument.
The python library will maintain an internal x,y coordinate on a coordinate plane so long as you're using the moveTo() and moveBy() commands. drawFunction() uses moveTo() internally, and so will also maintain the current coordinates.
Each integer position is 1cm away from the next. That is, 0,1 is one cm up the y axis from 0,0. 1,1 is sqrt(2) cm from 0,0.
The commands rely on the Sparki's internal moveBackward(), moveForward(), moveLeft() and moveRight() commands which seem to be quite accurate. The shapes that you can draw with the coordinate plane are very cool.
I have updated the increasingly inaccurately named "quick" reference to include descriptions of the new commands.
For the next update, I'm hoping to get a setup.py working, and then upload the library to Pypi for easy distribution.
Please let me know if any bugs, errors, etc.
edit: noted change in behavior for turnTo()