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

GPS Host with give coordinates at computer boot.

Started by KJA, 30 April 2012 - 12:02 AM
KJA #1
Posted 30 April 2012 - 02:02 AM
Hi there.
As the title already says, I would want to make a startup script, so a computer automatically configures itself as a GPS Host with given coordinates ( I assign them in the script). Now I already got the computer to start the wireless at startup, but I can't get the GPS thing to load. I hope anybody can help me.
Thanks already.
MysticT #2
Posted 30 April 2012 - 02:06 AM
Just add this to the startup file:

shell.run("gps", "x", "y", "z")
replacing the x, y, and z for the corresponding values.
KJA #3
Posted 30 April 2012 - 02:21 AM
So many thanks. Just have another problem, how do you get a computer to send the gps data which he git with the GPS locate command to another computer?
Zalerinian #4
Posted 30 April 2012 - 02:24 AM
If you mean that you placed another computer, types gps locate, and got a single definite position, how to use that? simple type gps host, and it will set you up with the co-ordinates it uses your current GPS network to triangulate.
Luanub #5
Posted 30 April 2012 - 02:25 AM
You can use the gps api from within your program so doing this would send out a request for the turtles/computers coordinates to the host and wait 1 second for a reply, and print the results, or error message if it fails.


x, y, z = gps.locate(1)
if x == nil or y == nil or z == nil then
error("Failed to get Coordinates, check GPS Hosts")
else
print (x)
print (y)
print(z)
end
end
KJA #6
Posted 30 April 2012 - 02:28 AM
@ luanub

Not directly, the computer/turtle sends his gps coordinates to an other computer with different coordinates and the second computer will print it.
Luanub #7
Posted 30 April 2012 - 02:33 AM
You would want to use rednet to send the x,y,z vars to the second computer in a message then have that computer print the message
turtle/computer

rednet.send( id, x.." "..y.." "..z ) -- replace id with the 2nd computer's id

2nd computer

id , msg = rednet.receive()
print ("Computer "..id.." is at "..msg)

should work, I havent tested it though.
Edited on 30 April 2012 - 12:40 AM
KJA #8
Posted 30 April 2012 - 02:44 AM
Thanks a lot. I'll test it and report, if there is a bug in the code.
KJA #9
Posted 30 April 2012 - 02:55 AM
Sorry to say, but in the first script it tells my attempt to concenatate string and nill, and in the second script it tells me unexpected symbol in line 3.
KJA #10
Posted 30 April 2012 - 03:21 AM
I accidently kinda left the lua lines at the top of. Maby that was the problem.
=
KJA #11
Posted 30 April 2012 - 03:30 AM
Never minde, it works now.
Luanub #12
Posted 30 April 2012 - 03:54 AM
You can do this to filter out the GPS request if your getting clutter from them too


if msg ~= "PING" then
	print ("Computer "..id.." is at "..msg.."n")
end

And this to make the message look better:

msg = ("X: "..x.." Y: "..y.." Z: "..z)
rednet.send( id , msg )
Edited on 30 April 2012 - 01:59 AM
KJA #13
Posted 30 April 2012 - 04:07 AM
thanks. but what does the n in the first script do?
Luanub #14
Posted 30 April 2012 - 04:10 AM
Its a line break. So it will print like

Computer 0 is at x y z

Computer 1 is at x y z
instead of

Computer 0 is at x y z
Computer 1 is at x y z

Just personal preference, if you want to remove it just do ..msg)
KJA #15
Posted 30 April 2012 - 04:12 AM
no no. its okay. just wanted to know.
KJA #16
Posted 30 April 2012 - 04:23 AM
Now it is perfect. Thanks.
KJA #17
Posted 30 April 2012 - 09:29 AM
Just so i can plan my map, how many gps hosts does a turtle/computer use when i execute the gps locate command?
Luanub #18
Posted 30 April 2012 - 09:54 AM
I believe it needs at least 3 replies
KJA #19
Posted 30 April 2012 - 10:03 AM
Yea, but how many will it use, i have about 6 or so built. Will it use all 6 at the same time for one positioning?
Luanub #20
Posted 30 April 2012 - 10:08 AM
If it can reach all 6 it will use all 6. I use 5 and they all respond to each request since the are all in range of my turtles, this helps to ensure that the coordinates are accurate.
KJA #21
Posted 30 April 2012 - 10:11 AM
goodi, but why does it then just list 4 of them on the screen?
Luanub #22
Posted 30 April 2012 - 10:17 AM
Ya I guess I remembered wrong. It needs 4 of them, and apparently >4 does not matter if its only listing the first 4. It just says you need at least 4 does not mention if >4 is useful or not.
KJA #23
Posted 30 April 2012 - 10:21 AM
Still good. Thanks for the help. If I have further questions, I'll tell you.
KJA #24
Posted 30 April 2012 - 11:51 AM
Got a question: what is wrong with that code


lua
=
x, y, z = gps.locate(1)
rednet.send( 100, ..x" "..y.." "..z )



It tells me, there is an unexpected symbol in line 3
Luanub #25
Posted 30 April 2012 - 12:15 PM
It's due to the lua =

It's trying to assign it x,y,z but then see's the = gps.locate(1) and gets confused. What are you wanting to use the var lua for?
KJA #26
Posted 30 April 2012 - 12:26 PM
Oh. I thought the lua must always be there. But it is working now (without the lua). Thanks.