Difference between revisions of "Gps (API)"
Line 30: | Line 30: | ||
print("I am at ",x," ",y," ",z) | print("I am at ",x," ",y," ",z) | ||
end | end | ||
+ | |||
+ | == Vector Example == | ||
+ | GPS position and navigation can be handled more easily using a [[vector (API)|vector]]. | ||
+ | |||
+ | local home = vector.new(45, 85, 20) | ||
+ | local position = vector.new(gps.locate(5)) | ||
+ | local displacement = position - home | ||
+ | |||
+ | print("I am ", displacement.tostring(), " away from home!!!") | ||
[[Category:APIs]] | [[Category:APIs]] |
Revision as of 19:37, 23 February 2013
The GPS API provides a method for turtles and computers to retrieve their own locations.
It broadcasts a PING message over rednet and wait for responses. In order for this system to work, there must be at least 4 computers used as gps hosts which will respond and allow trilateration. Three of these hosts should be in a plane, and the fourth should be either above or below the other three. You can set up hosts using the gps program.
Note: When entering in the coordinates for the host you need to put in the x,y,z of the computer, not the modem, as all rednet distances are measured from the block the computer is in.
Method Name | Description |
gps.locate(timeout, debug) | Tries to retrieve the computer or turtles own location. @param timeout the amount of time, in seconds, to wait for a rednet response |
Example
print("Man I am so lost right now!") local x, y, z = gps.locate(5) if x == nil then print("Nope, still lost :(") else print("I am at ",x," ",y," ",z) end
Vector Example
GPS position and navigation can be handled more easily using a vector.
local home = vector.new(45, 85, 20) local position = vector.new(gps.locate(5)) local displacement = position - home print("I am ", displacement.tostring(), " away from home!!!")