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

Issues Debugging (not sure what it is, more detail inside)

Started by trollsama, 07 February 2013 - 05:12 PM
trollsama #1
Posted 07 February 2013 - 06:12 PM
I have been working on a program for my turtle for some time now, and have been able to get this far without asking the forums (besides a single simple question :P/> )
this program IMO is way above my skill set and is likely why I have been having soo many issues during debugging.
in the state posted, I have fixed most of the issues, but have been stuck on a few…

Program Summery:
The idea behind the program is a hybrid between automation of mining, and maximizing gains (enchanted pickaxes for more loot, and XP gains)
the turtle itself builds a branch mine for the player after receiving a few details about what the player is after.
  • the length of the branches out,
  • how many branches there should be,
  • if the player would like the mine lit,
  • and if the turtle should prioritize completion or loot. IE bring loot back or not.
once the information is gathered, it runs a few calculations to figure out distances and such for things not specified, such as the "trunk" or main shaft, and will proceed to creating the mineshaft without further user input. first it will dig out the primary hallway (3 wide, 3 tall, with the first 2 layers cleared fully, and the 3rd just removing a center block up top) then it will start the shafts, starting at the end, digging the left side, the right side, and re-positioning for the next row.

Issues I am stuck on:
  1. currently, at random it seems, there is a slight chance that the turtle will simply freeze up for no apparent reason.
  2. this almost always occurs on a return trip from one of the branches, but occasionally has happened during re positioning, and once while mining… I have been completely unable to reproduce it properly, even when running the same settings in the same spot. and have no idea what it could be.
  3. The turtle, despite trying many things does not correctly position and dig the proper number of tunnels.
  4. in the variation posted above, the turtle when asked to make 4 branches, that a 10 blocks long, this is what i get:
Spoiler
Iron Blocks: Expected Path
Red Wool: Actual Path
Lapis block: starting position
as a bonus, the turtle did its hang where it is sitting in the picture. (during the return to the trunk)
( I am not really that good with the math in lua at all, so likely its something in my math.)

Code:
-Pastebin Code- (I suggest viewing in something like notepad++, as it looks like hell in paste bin, not to mention its over 700 lines long so collapsing trees help)



If you could help me figure this out, I would be grateful. I have invested a ton of time into this code and after hours trying to understand why its doing this, i feel it is time to ask the pro's.
Preemptive Thanks for the help
P.S. I apologize for the large post. there is a lot of code to the program so I figured giving an overview of what its purpose is may help understand whats what while reading it.


the only post on the page with no responses but still 33 views (more than quite a few of the front pagers with responses)
:(/> guess i will come back tomorrow to see if someone posted before it gets berried.
Edited on 07 February 2013 - 09:51 PM
ChunLing #2
Posted 08 February 2013 - 10:19 AM
When the turtle "freezes up" do you mean that it isn't accepting any input, as if the program were still running? Can the program be terminated by using Ctrl+T, or the turtle shutdown by using Ctrl+S/R? Is there anything directly in front of the turtle? Has the program displayed any error message?
trollsama #3
Posted 08 February 2013 - 10:32 AM
the random freeze up, the turtle just stops, just as if it is stuck in a loop of sleep.
the program still runs and i do believe it was killable with the CTR-T (i just started breaking them, since i had to move it anyway)
as for the error, oddly no. that is why i compare it to a sleep loop. I let it idol in its frozen state for quite some time in the hopes of it returning some sort of error, but it just sat there.
and no, nothing in front of the turtle. I thought it could have something to do with my move commands getting stuck from something originally, so i started running tests above ground on a superflat, and still had the issue.
ChunLing #4
Posted 08 February 2013 - 11:28 AM
Yeah…are the turtle's labeled? If so, check their fuel.

I'm pretty sure that your program is stuck in this loop:
repeat
        forward()
until currX == 0
which doesn't ever call your refueling function (which is set to trigger at a fuel level of 5, which is pretty dang low). So if the turtle didn't happen to refuel at the right place, then eventually it runs out of fuel while attempting to return home. Set your refuelAt value higher than the return home (or any other move sequence). I generally use a required fuel value of at least 500, and for a general refueling function for an autonomous turtle I'd have it be at least a couple of thousand. Just me, though.
Edited on 08 February 2013 - 10:36 AM
trollsama #5
Posted 08 February 2013 - 03:35 PM
that's a good catch, thankyou.
but i don't believe that is it, as I labeled the turtle, and added 64 coal to it for the purpose of testing. i then broke it so i had a creative version of a fully fueled turtle for the tests.
also, if it was a fuel issue, wouldn't the turtle stop running the program? or would it just return false on the turtle.move() call?

as for the low fuel count. that is because in a later variation of the design, I plan to implement a fuel cost calculation, that will then compare to the current fuel level, and call to the user to let them know how much more fuel will be needed to complete the task. and right now it was just a quick toss in value for the testing. it was basically just to make sure the turtle was refueling properly.
ChunLing #6
Posted 08 February 2013 - 06:49 PM
You don't have any calls to your fueling check in that loop, so it would get stuck on the:
while not turtle.forward(true) do
sleep(1)
end
part of the function forward() once the fuel was gone. Anything that persistently keeps the turtle from moving forward will do that, even a torch in front of it (my first thought, but there shouldn't be a torch right there). Both turtle.forward() and sleep() yield, so nothing will ever end that loop automatically if the turtle cannot move forward for some reason.

As for creative, that doesn't automatically switch to no fuel mode, you have to do that in the configuration file. A full stack of coal should have been plenty of fuel for this test, though. But if the turtle was labeled it should still have the old fuel level if you put it down and check.

BTW, turtle.forward() doesn't take any arguments, so that true you've got in there doesn't do anything.
Edited on 08 February 2013 - 05:50 PM
trollsama #7
Posted 08 February 2013 - 07:14 PM
interesting, it wasnt working for me before I added the "true" in there.
so would something like this work?



while not turtle.forward() do
	ensureFuel()
	sleep(1)
if turtle.detect() then
	turtle.dig()
elseif not turtle.detect() then
	print("Unknown Movement Error")
     sleep(10)
    os.shutdown()
end
end
if currO == 0 then
	currX = currX + 1
elseif currO == 1 then
	currZ = currZ + 1
elseif currO == 2 then
	currX = currX - 1
elseif currO == 3 then
	currZ = currZ - 1
else
	navError()
end
end
ChunLing #8
Posted 08 February 2013 - 08:28 PM
Er…it would work in some cases, but not all. the detect functions don't detect entities, which can still block movement, and this would cause your turtle to shutdown if that happened (I'd just use return false rather than shutdown). A less general concern is that this will still infinite loop on hitting bedrock or another unbreakable block.

You also call ensureFuel() every time you can't move forward, rather than detecting first and trying ensure fuel if nothing was in the way. This matters a bit because ensureFuel() is pretty expensive.

That said, there is no absolutely right way to do this and while this code may fail in certain circumstances it should prevent your turtle from running out of fuel while moving about.
trollsama #9
Posted 09 February 2013 - 04:50 PM
yeah i was half asleep when i did that XD


function forward()
ensureFuel()	--forward, , with location tracking and wait to move code
issueCounter = 0
while not turtle.forward() do
  sleep(1)
  issueCounter = issueCounter + 1
  if issueCounter >= 10 then
   print("Unknown Issue. Stopping.")
   sleep(10)
   exit()
  elseif issueCounter >= 3 then
   turtle.dig()
  end
end
if currO == 0 then
  currX = currX + 1
elseif currO == 1 then
  currZ = currZ + 1
elseif currO == 2 then
  currX = currX - 1
elseif currO == 3 then
  currZ = currZ - 1
else
  navError()
end
end

This seems to fix my issue :D/>
ChunLing #10
Posted 09 February 2013 - 08:31 PM
My standard move pattern makes 64 attempts before declaring failure (only for mobs and gravel/sand, though). If something's supposed to work without you around, might as well make it try for as long as it could possibly still have a hope of success.
trollsama #11
Posted 09 February 2013 - 09:27 PM
does it not use fuel when it uses dig or move regardless of if succeeds?
ChunLing #12
Posted 10 February 2013 - 05:43 AM
Obviously not, since you don't go below zero fuel when you attempt a move with no fuel.

Only successful moves use fuel. Digging and other operations do not use fuel.
trollsama #13
Posted 10 February 2013 - 12:40 PM
XD well i was meaning if it has fuel to use. just like if you were to butt a car against a wall… hitting the gas will burn fuel regardless of if it takes you anywhere kinda deal :P/>
but thats good to know, I thought dig used fuel too :/ lol i apparently don't know my turtles that well.
ChunLing #14
Posted 12 February 2013 - 11:15 AM
The turtle is smart enough to detect if there is something in it's way, so it doesn't waste fuel.

Digging will eventually reduce the durability of the turtle's tool, which will eventually break and need to be replaced. This is somewhat consistent with how excavators in some other mods work.