Fixing (to an extent) a deficiency in current native API implementation.
Allows automatic calibration and arbitrary course setting, rotation using specific angle, and keeps internal track of position and course changes.
Changes to existing methods:
Internal changes to all movement methods for course/location tracking.
New properties:
turtle.directions
a dictionary table to translate numeric directions into verbal form. State-dependent.
turtle.location() read-only
Returns current turtle location, in order: x, y, z as returned by GPS API, bearing (0-3 clockwise, 0 being East/Forward), inertial navigation flag (true if using inertial navigation).
Usage example:
local x, y, z, b, i = turtle.location()
io.write("Unit " .. (os.getComputerLabel() or os.getComputerID()) ..
" at (" .. x .. "," .. y .. "), altitude " .. z ..
", facing " .. turtle.directions[b])
if i then
print(", using inertial navigation.")
else
print(".")
end
turtle.version() read-only
Returns API internal version.
New methods:
turtle:calibrate( boolean verbose )
Attempts a short calibration sequence and return turtle to the starting position. Working GPS network and an opened modem on turtle is required in order for it to work.
verbose - allows printing of progress information.
Returns true, if calibration was successful, othervise false.
Note the ":" - this function call is required to be self-referenced.
turtle.rotate( int angle )
Performs a rotation arbitrary number of times into given direction. Negative number will cause turtle to rotate counter-clockwise.
Due to turtle being heavily armoured and overall aimed to achieve a result rather performing a process, only necessary amount of maneuvering will be executed at a time.
turtle.setCourse( int course )
Attempt to point a turtle into specific direction (0-3 clockwise, with 0 being East/Forward)
Negative course allowed.
Returns true if succesful, or false othervise.
Installation
Dump archive contents into minecraft/mods folder.
Reports and suggestions are welcome.
UPD 20120504-1: Sneaky edit
+ Added version properly. You can check for correct API installation by addressing turtle.version(). If it works, then you have it all proper. If not, you probably screwed something.
UPD 20120504:
+ Full inertial navigation.
* Rewritten and better state reporting.
UPD 20120424:
! Finally made it's way to my Subversion repo. No more code loss due to power outages.
* Fixed directions tables.
* A few preparations for inertial navigation.
UPD 20120423:
* More stupid error fixes.
* More consistency fixes.
UPD 20120422:
* Fixed some stupid errors in course handling.
* Split native call in two parts for easier code reuse.
Edited by AnrDaemon, 04 May 2012 - 05:31 AM.











