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

Turtle Quarry State

Started by OupaOorlog, 27 September 2012 - 08:34 PM
OupaOorlog #1
Posted 27 September 2012 - 10:34 PM
Hi all,

Firstly, one of the best mods in minecraft as far as I am concerned, thanks
for all the effort put into it. Prepare for the great wall of text. Can be seen from
space.

I wrote an involved turtle quarry.. Basically boils down to turtles in a row,
you define a lateral distance from a docking bay/drop-off point to each
turtle and it will mine downwards row for row all the way down to bedrock
and as far forward as you want (currently limiting it at 64 blocks forward).
When full the turle will return to its initial deployment point and from there
move towards the defined drop off point and empty its inventory. It will then
move back to the row it was busy excavating(before its inventory got full)
and continue excavating.

As I suspected when I started writing said turtle quarry I would need a system
in place to save the state of each turtle so it can continue atleast almost
seamlessly after restarting my world.

The quarry itself works great, no bugs except maybe for creatures getting in
the way(which I can fix in CC 1.4 pretty easily with turtle.attack in a small
loop to confirm that i am actually at bedrock and not trying to mine a zombie).
Also this is not a train smash as the turtle will just skip that row and move
on to the next. The state file also works great in most cases. My question is
in regards to the rest of the cases.

I noticed that if I leave my world when a turtle is half way during a movement
it will complete its movement when restarting the world, obviously without
writing that movement into the state file. This is assuming I go with moving
and then saving the state. Obviously if I swap it around and save the state
before moving the same thing can occur. Infact in theory it is possible that i
can end up with an empty state file if I quit the world at exactely the right(wrong?)
time after opening the state file with the "w mode".

Is there any way for me to force the LUA to finish the current function(although I
highly doubt this) it is in before the world quits?

Any other suggestion to solve this problem would be greatly appreciated.
Even if it entails changing the way i handle the location/movement of
the individual turtles(even GPS) or the clearing of their inventories.
Initially i used a computer(with modem) and wireless mining turtles to handle
the docking. But much easier and less of a hassle to set-up by going with
normal mining turtles and some checking on movement. I guess I could
solve the problem by forcing the turles to stop, after docking, with a wireless
computer before i quit the world.

First prize however would be for them to automatically continue doing what they do.

Oupa Oorlog.
Cranium #2
Posted 27 September 2012 - 10:44 PM
Since you seem to have figured tou how to have them save their position after restart automatically, I am going to assume you know how to do this with a general idea.(I don't know how, since I have never done it.)
I think what you can do, is set up a GPS system, not for the primary location system of the turtles, but for double checking their location. I'm not sure how you have the setup, but this is the only thing I can think of to help.
Have the turtles, on startup, query the GPS towers on where they are. Then check that value against what it's last state is, and if correct continue. However if it's incorrect, adjust accordingly. Since the GPS computers will be stationary, it is guaranteed that their location would be absolute. The turtles are just checking that their information is the same as what the towers have.

Hope that helps!
OmegaVest #3
Posted 27 September 2012 - 10:45 PM
There is not (so far as I know) a way to force the computers and turtles to finish their cycle before quitting. However, there was supposed to be a chunk-unload save state in the works at some point.

On the other hand, why don't you store the origin and destination in the save file, then set up a GPS Satellite overhead? When the turtles turn on, look for that save file, and see if it has reached its destination (via GPS).

Going further, you can put the ara it's supposed to be covering in it as well. From what you put up there, it looks like you just have them move in straight lines, dropping to the next row/column when they get to the end. This is efficient in that it is easy to code, but inefficient in that it creates the problem you are having now.


EDIT: Ninja'd bad.
Cranium #4
Posted 27 September 2012 - 10:58 PM
:P/>/> I am NINJA :D/>/>
OupaOorlog #5
Posted 28 September 2012 - 12:10 AM
Well i did consider a GPS(GPS satellite?) solution but i am not sure if this will work. In a small test case, i did, the turtles dug down 70 blocks to bedrock(depending where you start them from ofc). Is this not out of range for the wireless communications, think i read somewhere that it can only communicate up to a distance of 50 blocks(I know there are some changes to this in 1.4 but still on 1.3 currently)? I will also need four computers (three on the surface to triangulate X and Y and one on bedrock for depth(Z)) as I understand. Also i will have to limit the size of the quarry if the comm limit is 50 and the computers need to cover the entire area. This solution does however sound like the most elegant way to confirm the turtles coordinates. I will investigate it further and see if I can come up with a solution using GPS.

Another point, Is there no event that i can "subscribe" to when a turtle completes moving up/down/forward which i can then use to compensate with?

At the moment i use the state on restart to move the turtle back to its original deployment block and to continue on from there(move to the row it was digging or clear inventory if full) Its the turtles current location thats the problem. In my code i assume the original deployment block as (0,0,0) for (x,y,z). z-axis is inverted so positive if it goes down.

As an example:

while Z > 0 do
Up() – Up decreases Z in my case
end

Which should move the turtle to the surface, however if Z is wrong the turtle will either end up in the sky or underground.

If or when i get this working properly i will post some code as an example.
Cranium #6
Posted 28 September 2012 - 12:16 AM
Here's a post I found in the suggestions forums that really helps. If you set up a satellite, with the range of the modems increased, you would have no problems.

the broadcast range at 255 is 384 meters. any WIFI within that circle can communicate with the WIFI at the center of it. so it one is a bed rock it can communicate with a turtle at the top of the world.


Edit: The range of the modem increases the higher it gets to the top of the world, in case you did not know.
OupaOorlog #7
Posted 28 September 2012 - 10:27 AM
@Cranium : Edit: The range of the modem increases the higher it gets to the top of the world, in case you did not know.

Only from CC 1.4 though. Maybe its time I make the jump to 1.4. Could use the bigger inventory as well.

@OmegaVest: This is efficient in that it is easy to code, but inefficient in that it creates the problem you are having now.

I was trying to create the quickest way to mine down to bedrock repeatedly. The BC quarry(especially if you go bigger than default) takes to long to reach the good stuff. If you have a suggestion on how to make it more efficient I will gladly try and implement it in another way.

When you guys talk about a satellite, I assume you mean a normal computer + modem just really high? Or is there something I am missing?

Anyway, thanks for all the help. Think I will change to CC 1.4 and see if i can make it work with GPS
OmegaVest #8
Posted 28 September 2012 - 03:20 PM
A GPS satellite is a small platform, usually 3x3x3 that has at least three computers, but usually four, that have their modems at unique (save the fourth) X Y and Z coordinates. If you would like an example, go check out Direwolf20's Server Play series. They do a lot with them recently. And I think episode 70 or there abouts shows Eloraam's (the RP2 dev) turtle mining platform. And the chaos that ensues.



And, no I don't have a better solution right off the top of my head. For a quick y-mine, yeah, just going there is probably easier. You will still encounter the problem that it will take an army of turtles a while to find good resources (unless you are in a mountainous biome, which seem to have a higher ore density).
GopherAtl #9
Posted 28 September 2012 - 03:36 PM
just saving before moving instead of after eliminates a huge amount of the errors. This is because the turtle movement commands yield, and so take many times longer than saving the position to disk, meaning in the huge majority of cases, the move is what will be interrupted. They could be interrupted mid-save, or between save and move, but these are very rare, while saving after a move is almost guaranteed to create an inconsistency. That's as good as you can do, I think, without some external way to verify your position - be it gps, or some other known info in the context (ex, if you were moving away from a wall at a known position, you could back up to the wall to figure out where you were interrupted)
OupaOorlog #10
Posted 28 September 2012 - 06:22 PM
[indent=1]@omegavest[/indent]

[indent=1]Thanks for the explanation of the satellite. I am actually quite surprised at the speed these little buggers dig up the world. > quarry in both speed and just plain awesomeness :P/>/>[/indent]

[indent=1]@gopher[/indent]

[indent=1]That does make sense, thanks. I will change my code accordingly and see if it works out better. I did consider using two extra turtles to build a wooden structure or something in that line around the quarry and use as you suggested. Each turtle can also place a block above it, before starting to dig down a new column, as a point of reference. Will only cost me one space in each turtles inventory.[/indent]