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

[Lua]Refuelling Prog

Started by Bimgo, 23 January 2013 - 09:26 PM
Bimgo #1
Posted 23 January 2013 - 10:26 PM
Hello all,
I have made a prog for move the turtle with gps localisation (for the start point but i can use it again if need) i have a goto function and now i have some problem for implement the fuel gestion of the turtle + the quary step . I know this program exist but i need to make mine to try to understand how the turtle/prog work.

I need any help i can get to try to find the best way to do my refuel prog.

The problem/reflexion i have is :
1) check how much fuel need for the deplacement >> this function is made from start to quary zone (Difference in x, y, z coord)
2) check how much fuel need for quary (start coord to end coord) >> this function is made
3) check turtle inventory and return item when full

but

i have make a test for large quary (30x30 blocks) with much deplacement to go and the problem is in midle of quary the turtle go out of fuel beacause i can't anticipate the fuel need to go to return item (depend of block type, qty of each type, …

Thanks all for your reflexion on my problem.

writing this I had an idea that I must develop :
-maybe when the return item phase i can refuel just for the journey for go from quary -> base for eject item -> quary

PS: sorry for synthax error but english is not my first language…
sjkeegs #2
Posted 24 January 2013 - 03:06 AM
You can use turtle.getFuelLevel() to tell you how far the turtle can travel. You could then compute what the maximum distance the turtle would have to travel to get back to the home position. Use that value as a minimum amount of fuel that you don't let getFuelLevel() go below. When you then detect that you have run out of coal being carried by the turtle (or whatever you are using for fuel), you can then initiate the return to home position to grab more fuel.
PixelToast #3
Posted 24 January 2013 - 03:15 AM
TL;DR:
if turtle.getFuelLevel() < (distance_traveled*2)+1 then
go_back()
end
Bimgo #4
Posted 24 January 2013 - 03:52 AM
Yes i have tink to this but if i do this how much i need to refuel?
Maybe i need to recalculate all (travel, remaining quary)?

i will try to put one quantity for do the travel x 2 (from base to quary and go back) and the quary (b * l * h) and when i need to clear my inventory i take some more fuel to cover consumption for this travel to clear inventory
PixelToast #5
Posted 24 January 2013 - 03:57 AM

while turtle.getFuelLevel() < distance_you_want_to_travel do
turtle.refuel(1)
end
ChunLing #6
Posted 24 January 2013 - 09:25 AM
I think that this is an interesting programming challenge but I generally just fuel my turtles up to several thousand and let them go at it. Even if a definite limit on fuel tank size is implemented, it's likely to be at least 5000 (which is less than a full stack of coal/charcoal).

If you simply want to have the turtle have a stack of coal that it eats when it finds more coal, that could probably keep your turtle fairly autonomous for fuel during normal excavation. If you're doing building, then you can feed it coal and do some refueling when giving it new building materials.

Leaving aside all that, and looking at the problem as stated, if your turtle is getting full faster than expected, it will consume less than the expected amount of fuel. So if you fueled it according to the maximum movement, it should be okay in all other cases.
Bimgo #7
Posted 24 January 2013 - 10:33 PM
Hello thanks to your reponse ChunLing,
I have made my prog with this consideration : my turtle is full before it goes out of fuel -> i have a start amount of fuel (calculate for quary and journey to go and come back to the end of quary) and each time it go back it refuel of a litle amount of fuel only for cover the travel for empty its inventory and go back again to quary.
It's not possible to calculate exactly wich time the turtle go back with inventory full -> this is not possible to calculate the maximum mouvement they will do.

it seems that it works but i need to do some more test and of course optimize my functions() .

another method can be used (same as your method i tink) is fill with max fuel (no max actualy) for exemple 5000 and launch the turtle with a fuel check if the fuellevel < 1000 (for exemple) the turtle go back to refuel for go to 5000. But with this method some time is wasted when the turtle must go back only for refuel…

I don't no if my reasoning is correct and if the text its all understandable…

Have a nice day
ChunLing #8
Posted 26 January 2013 - 11:09 AM
You definitely know how much the max fuel consumption would be in the case that the turtle is excavating an area where there are no drops from broken blocks. You also can calculate the max fuel consumption in the case that every block dropped is the same type and stacks to 64. So just fuel the turtle to the larger max (completing the remainder of the excavation without ever needing to return to off-load blocks). 5000 moves is plenty to clear an entire chunk if your movement isn't completely inefficient.

And go ahead and leave a stack of coal and eat some whenever you have more than a certain amount.