This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
zortag's profile picture

GPS is not so accurate

Started by zortag, 22 December 2014 - 11:37 PM
zortag #1
Posted 23 December 2014 - 12:37 AM
i'm programming a farming turtle for 2 different crop that grow in a way similar to cactus and sugar canes
i'm playing with gps function from previous versions of cc (maybe mc 1.5.2? i don't remember cc version), and now i see cc 1.6.5 gps localization (using old gps tower setup) is less accurate and final coordinations changes when i reload the world.
i'm programming a farming turtle for 2 different crop that grow in a way similar to cactus and sugar canes
maybe i make something wrong with this version (gps tower setup is changed?), but i found a way to bypass the problem.
if i use the string

local x, y, z = gps.locate(5)

the "world reload issue" is bypassed (actually i set the home position manually in the code).

unfortunely the turtle "forget" the coordinate when i call the "gohome" function

function gohome()
term.clear()
write("Positioning…")
shell.run("moveto", x,y,z) – actually x,y,z are numeric coordinates but i need use the cordinates given by the gps.locate(5) command
turtle.back() – this line and the next are to face the turtle correctly (there is a way to turn the turtle to the choosen direction?)
shell.run("moveto", x,y,z) – "moveto" script can be found here and it is not written by me (it moves the turtle to specific coordinates. i accept suggestions about a better way to do that)
term.setCursorPos(1,2)
term.write("I'm at home")
sleep(2)
end

there is the question:
so i want to create a file from the gps.locate() command results and call it to read the coordinates but i don't know how to do that.
i saw something similar in a script to control the turtle with an xbox controller but is not enough similar to what i need. i'm not so good with programming, i can read and understand what a script does but not modify it. i just copy and paste strings and make them works each other (sorry i can't explain better).

so what i need is:
launch gps.locate(5) and write a file called xyz with the result in the turtle memory
the turtle execute its job
by the "gohome" function the script run "moveto" and read x,y,z from the xyz file

sorry for the confused explanation, english is not my language.

P.S. i know some things are canged from older versions and many old script fails. idk if "moveto" is one of them so i recognize my problem in a less accurate gps localization. can somebody check that script or suggest me an alternative that works better?

thanks to everybody who wil answer me
Lyqyd #2
Posted 23 December 2014 - 01:13 AM
I haven't noticed any problems with correctly configured GPS systems giving inaccurate or inconsistent results. Reproduction instructions to achieve that problematic state would be very helpful.
Bomb Bloke #3
Posted 23 December 2014 - 06:44 AM
Odds are your "gohome" function can't see x/y/z because you declared them as local variables after declaring the function. Make sure you define them before you define the functions that need to access them.

Regarding any GPS "inaccuracies", my bet is that one or more of the satellites that're in range have incorrect co-ordinates coded into them (do they all belong to you? are other players building satellites too?).

Edit:

Even if all the satellites in the area belong to you and have the right co-ords, also double check:

* At least four are in range of the turtle whenever it tries a gps.locate() call. Remember rain affects range.
* Those four systems must be turned on - fly up and check their modems are red.
* Those systems must not be located too close together, and certain layouts will also cause problems (eg putting more than two of your in-range satellite systems at the exact same world-height is bad; the layout suggested here should work fine).

Typing "gps locate" directly into your turtle's command prompt when it's having "problems" may give more information as to why.
Edited on 23 December 2014 - 06:12 AM