Jump to content




Satelite builder


20 replies to this topic

#1 dustpuppy

  • New Members
  • 16 posts
  • LocationWexford, Ireland

Posted 06 October 2012 - 03:57 PM

Hi,
to get a turtle reading the right GPS position you need to setup a GPS host system with 4 computers, like this http://www.computerc...osition-system/
To do this on every world could be a lot of work.
So i' ve made a little program, that build a satelite system in 100 meter height.
Program needs to be started with x,y,z coordinates and facing of the turtle. Then simply follow the instructions to fill the slots.

Hope it's usefull.

local tArgs = { ... }
if #tArgs < 4 then
  print("Usage : satelite <x> <y> <z> <f>")
  return
end
local Xpos = tonumber(tArgs[1])
local Ypos = tonumber(tArgs[2])
local Zpos = tonumber(tArgs[3])
local facing = tonumber(tArgs[4])

function buildUp(floppySlot)
  -- Put the disk drive
  turtle.select(3)
  turtle.place()
  -- Load disk into drive and write startup file
  turtle.select(floppySlot)
  turtle.drop()
  file = fs.open("disk/startup","w")
  file.writeLine("shell.run(\"gps\",\"host\","..Xpos..","..Ypos..","..Zpos..")")
  file.close()
  -- put the computer
  turtle.up()
  turtle.select(2)
  turtle.place()
  -- place the modem
  turtle.up()
  turtle.up()
  turtle.forward()
  turtle.select(4)
  turtle.placeDown()
  turtle.back()
  turtle.down()
  turtle.down()
  -- turn computer on
  computer = peripheral.wrap("front")
  sleep(0.5)
  if computer then
    computer.turnOn()
  end
  turtle.down()
end

if type(Xpos) ~= "number" then
  print("x must be number")
  return
end
if type(Ypos) ~= "number" then
  print("y must be number")
  return
end
if type(Zpos) ~= "number" then
  print("z must be number")
  return
end
if type(facing) ~= "number" then
  print("facing must be number")
  return
end
print("Please fill up following slots")
print("1 = Fuel")
print("2 = Computer (4x)")
print("3 = Disk drive (4x)")
print("4 = Modem (4x)")
print("5 - 8 = Floppy disk (4x)")
print("Press any key to continue")
while true do
  event, param1 = os.pullEvent()
  if event == "char" then
    break
  end
end
while turtle.getItemCount(1) > 0 do
  turtle.refuel()
end
print("Fuel level is "..turtle.getFuelLevel())
print("Going up to 100 meter to build satelite")
for height = 1, 100, 1 do
  turtle.up()
end
Ypos = Ypos + 101
-- Go 10 forward to set the first computer
for c = 1, 10, 1 do
  turtle.forward()
end
if facing == 0 then
  Zpos = Zpos + 11
end
if facing == 2 then
  Zpos = Zpos - 11
end
if facing == 1 then
  Xpos = Xpos - 11
end
if facing == 3 then
  Xpos = Xpos + 11
end
buildUp(5)
-- Go back 20 and put the second computer
turtle.turnRight()
turtle.turnRight()
if facing == 0 then
  facing = 2
elseif facing == 1 then
  facing = 3
elseif facing == 2 then
  facing = 0
elseif facing == 3 then
  facing = 1
end
for c = 1, 20, 1 do
  turtle.forward()
end
if facing == 0 then
  Zpos = Zpos + 22
end
if facing == 2 then
  Zpos = Zpos - 22
end
if facing == 1 then
  Xpos = Xpos - 22
end
if facing == 3 then
  Xpos = Xpos + 22
end
buildUp(6)
-- go 10 forward to the middle
turtle.turnRight()
turtle.turnRight()
if facing == 0 then
  facing = 2
elseif facing == 1 then
  facing = 3
elseif facing == 2 then
  facing = 0
elseif facing == 3 then
  facing = 1
end
for c = 1, 10, 1 do
  turtle.forward()
end
if facing == 0 then
  Zpos = Zpos + 11
end
if facing == 2 then
  Zpos = Zpos - 11
end
if facing == 1 then
  Xpos = Xpos - 11
end
if facing == 3 then
  Xpos = Xpos + 11
end
-- and 10 more up
for c = 1, 10, 1 do
  turtle.up()
end
Ypos = Ypos + 10
-- turn 90 degree to setup the second row
turtle.turnRight()
facing = facing + 1
if facing == 4 then
  facing = 0
end
-- Go 10 forward to set the third computer
for c = 1, 10, 1 do
  turtle.forward()
end
if facing == 0 then
  Zpos = Zpos + 11
end
if facing == 2 then
  Zpos = Zpos - 11
end
if facing == 1 then
  Xpos = Xpos - 11
end
if facing == 3 then
  Xpos = Xpos + 11
end
buildUp(7)
-- Go back 20 and put the last computer
turtle.turnRight()
turtle.turnRight()
if facing == 0 then
  facing = 2
elseif facing == 1 then
  facing = 3
elseif facing == 2 then
  facing = 0
elseif facing == 3 then
  facing = 1
end
for c = 1, 20, 1 do
  turtle.forward()
end
if facing == 0 then
  Zpos = Zpos + 22
end
if facing == 2 then
  Zpos = Zpos - 22
end
if facing == 1 then
  Xpos = Xpos - 22
end
if facing == 3 then
  Xpos = Xpos + 22
end
buildUp(8)
-- go 10 forward to the middle
turtle.turnRight()
turtle.turnRight()
for c = 1, 10, 1 do
  turtle.forward()
end
-- and back to earth
while not turtle.detectDown() do
  turtle.down()
end


#2 Sebra

  • Members
  • 726 posts

Posted 06 October 2012 - 07:33 PM

1. Hide code under spoiler, please.
2. Why 100 only? You should use maximum height for maximum efficiency.
3. I think modems on top is slightly more efficient. :D/>

#3 dustpuppy

  • New Members
  • 16 posts
  • LocationWexford, Ireland

Posted 06 October 2012 - 07:40 PM

If i did it more height, i need to calculate from the starting point. If player stands on a hill, it could end over 256 and then it will not work anymore. The modem is on top of the computer.

#4 sjele

  • Members
  • 334 posts
  • LocationSomewhere on the planet called earth

Posted 06 October 2012 - 07:45 PM

while true do
  turtle.up()
  if not turtle.up() then
	break
  end
end

--Rest of code


#5 dustpuppy

  • New Members
  • 16 posts
  • LocationWexford, Ireland

Posted 06 October 2012 - 08:24 PM

Here a new version. Now it's going up to 251, no matter where it starts.

Spoiler


#6 Sebra

  • Members
  • 726 posts

Posted 06 October 2012 - 08:34 PM

You are learn fast :D/>
It is possible to use 1 disk, 1 drive and do not leave it.

#7 dustpuppy

  • New Members
  • 16 posts
  • LocationWexford, Ireland

Posted 06 October 2012 - 08:38 PM

But if i leave it, it's possible to update the computers by a turtle with easy changing the boot disk.

#8 ChunLing

  • Members
  • 2,027 posts

Posted 09 October 2012 - 06:09 PM

Nice. You can tighten this up a lot though, the array doesn't need to be that big to get accurate triangulation, since the rednet range is relatively short (making it so big just means you lose a few extra blocks of effective range). An array of just having each computer placed one block from the center would work fine out to the range limit, but then it would be too difficult to place the modems. Also, for purposes of rednet, the computer, not the modem, is the point of origin. So you should put the computers as high as possible (if you put the modems on the side--or front like I ended up doing, they're just as high anyway).

You can also make it so that the turtle automatically detects existing GPS signals or just sets itself as the new center (and East, the positive x axis, as the turtle facing). It can do a gps.locate() from the center, then move forward one and do another, and subtract the results of the first to get the facing. I like this because I'm lazy and I don't like being told I have to put in extra parameters.

#9 dustpuppy

  • New Members
  • 16 posts
  • LocationWexford, Ireland

Posted 09 October 2012 - 07:43 PM

I've made it that size, because it's only a part of my real satelite system. I am doing a storage system, where i have another server in the middle and some other systems like a server storing all positions of all turtles are also on work.

#10 ChunLing

  • Members
  • 2,027 posts

Posted 10 October 2012 - 05:08 PM

Your central control server can be at ground level and still be in range to communicate with the GPS array. All you have to do is program them to act as relays rather than just responding to GPS PING messages.

#11 slango20

  • Members
  • 43 posts

Posted 11 October 2012 - 06:14 PM

View PostChunLing, on 10 October 2012 - 05:08 PM, said:

Your central control server can be at ground level and still be in range to communicate with the GPS array. All you have to do is program them to act as relays rather than just responding to GPS PING messages.
how would you do that? I'm planning on a massive storage and retrieval room, where a turtle acts in place of logistics pipes, and attacks and kills mobs that wander in (if they are in its path)

#12 dustpuppy

  • New Members
  • 16 posts
  • LocationWexford, Ireland

Posted 11 October 2012 - 06:33 PM

View PostChunLing, on 10 October 2012 - 05:08 PM, said:

Your central control server can be at ground level and still be in range to communicate with the GPS array. All you have to do is program them to act as relays rather than just responding to GPS PING messages.

Then i have to change the GPS api. I want to keep the original apis.

#13 Sebra

  • Members
  • 726 posts

Posted 11 October 2012 - 07:25 PM

copy & edit

#14 ChunLing

  • Members
  • 2,027 posts

Posted 11 October 2012 - 09:41 PM

You don't need to actually edit the gps API, you can just make a new program that both responds to "PING" messages and messages that have the form "^(RELAY:)(%d+)(.*)$" (or something like that) by stripping off "RELAY:" and the number and sending the remaining message to the ID matching that number. Then have your array programed to use that instead of the regular GPS program.

True, I'm not bothering to do that myself, at least not yet. My interests in turtles run mainly in the direction of using them to help carry out the grunt work in minecraft, not creating some kind of endless self-replicating army controlled by a central computer. But you don't need a new API, just a slightly improved version of an existing program.

#15 evilguard

  • Members
  • 30 posts

Posted 17 October 2012 - 03:07 AM

Quote

If i did it more height, i need to calculate from the starting point. If player stands on a hill, it could end over 256 and then it will not work anymore. The modem is on top of the computer.

hums, Would be nice if the programs actually ask for actual GPS coordinate and then calculate about that? So that don't mean anything is the turtle is on a mountain in a quarry hole :D/>

Just saying. nice programs btw :P/>

#16 ChunLing

  • Members
  • 2,027 posts

Posted 17 October 2012 - 04:30 AM

The version I include in User Friendly Program combining several useful functions doesn't worry about the initial height, it just goes up till it hits the height limit and presumes that to be 255 unless an exiting GPS system tells it otherwise. It also asks for the starting coordinates and facing during the launch prep.

I also have a version of the relay host, but I'd like to flesh it out with more functions.

#17 MrZuribachi

  • New Members
  • 44 posts
  • LocationGermany

Posted 17 October 2012 - 02:54 PM

A GPS-System is quite usefull (I think), but I'm quite confused about it. Could you add a demonstration-video please? Would be very kind

#18 ChunLing

  • Members
  • 2,027 posts

Posted 17 October 2012 - 03:51 PM

I can't because I'm too lazy to post a video that will take longer for you to watch and explain less than simply copy/pasting the code into a turtle's folder and running it. But I'm not too lazy to post an explanation of what the code does.
Spoiler
In the first line, we declare some variables. These variables are intended to hold default values for xyz coordinates and additional xz coordinates 1 meter from the xz coordinates to indicate a displacement of 1 meter in a horizontal direction (east, in this case)

Then we have a function called gpsnode. This function causes the turtle to place a block from slot two (which should contain disk drives), put an item from slot 4-7 (which should be disks) into the inventory of the placed block, write a startup file (which will start the gps hosting program with coordinates passed to the function as arguments) to a disk in a disk drive placed next to the turtle(which we have just done if the slots were loaded correctly), and then proceed to place a block from slot one (which should contain computers) on the top of the previous block and a block from slot 3 (which should contain modems) on the side of that block. The turtle then maneuvers back around to the block it placed from slot 1 (which should be a computer) and tries to turn it on. It then goes down one meter to be exactly in the position and facing it was when it started this function.

Then we have a function called plcaxis which also takes xyz coordinates as arguments. This function assigns our programs local xyz coordinate variables to be equal to the output of a gps.locate call with a two second timeout (and verbose output). Then the turtle moves forward one meter and checks if it got coordinate values or nil from the gps.locate call. If it has coordinates, it makes another gps.locate call and subtracts the xz coordinates from the previous coordinates to get xz coordinates that will indicate one meter of horizontal movement. If it got nil from the first gps.locate, it just assumes that the coordinates are those initially passed to the function. The turtle then positions itself and calls the gpsnode function defined above at coordinates equal to its starting coordinates plus double the one meter displacement coordinates calculated or passed to the function. Then it turns around, goes to the other side of the current axis, and places another gpsnode at its starting coordinates minus double the displacement coordinates.

These functions defined, the turtle resumes it's main program, first outputing a description of how you are to set up the inventory and asking you to input some numbers representing the x and z coordinates and the facing. On receiving the facing, it spins around till the facing equals 3 (based on the value you entered for facing). If it doesn't have a sufficient quantity of fuel to make the trip, it asks for fuel until it has enough.

Then it goes up till it can go up no more. When it can go up no more, it calls plcaxis, starting in what you told it was an easterly direction. It then resets the presumed xz displacement and y coordinates, returns to the center, turns 90 degrees, and calls plcaxis again (it will end each plcaxis call one meter lower than it started it, so the new axis is one meter below the first as well as rotated 90 degrees). Then, work presumably finished, it will descend until it can descend no more.

If you loaded the turtle correctly and gave it good coordinates, then you now have a working four point GPS array with the largest range possible. If you put the wrong blocks/items in the slots, then you now have a non working dummy array that will mock you from above whenever the sun is high and the weather clear. Oh, and if you launched this indoors, then you have an array on your ceiling, where you can admire its design but where it will not do you very much good.

#19 dustpuppy

  • New Members
  • 16 posts
  • LocationWexford, Ireland

Posted 17 October 2012 - 05:40 PM

Take a look into my other threat.
http://www.computerc...ventory-system/

#20 Snablesnot

  • Members
  • 4 posts

Posted 02 November 2012 - 01:14 AM

I am new to CC and lua. however I don't understand why it would not just be simpler to create 4 of the plain wireless turtles and have a program that uses them as the gps.
launch program on turtle 1 and enter world coordinates. and tell it the 3 other ids of fellow gps turtles and give it some fuel let it rocket to the stars.
start the program on the other 3 turtles and tell it the id of its master coordinator turtle (turtle 1) and they position themselves accordingly.

Would this make sense?





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users