Jump to content




Need help with goto program

help turtle

  • You cannot reply to this topic
5 replies to this topic

#1 jag

  • Members
  • 533 posts
  • LocationStockholm, Sweden

Posted 18 October 2012 - 06:56 PM

First off, I want to create a goto program.

This is how long I've come so far:
(Also on pastebin: D1UKi7vU)
Spoiler

This goto program uses it's current position as x, y and z coordinates and the direction 0 (facing the Z-axle).
That means that if you run the program like this
-- goto x y z
goto 0 0 4
it will then go 4 times forward.

But what I want to do is to replace this
local posX, posY, posZ = 0
dir = 0
with some way to detect the pos and dir.

The detection of the pos is really simple, just do
rednet.open("right")
local posX, posY, posZ = gps.locate(.5)
rednet.close("right")
if not posX then
  print("Could not locate position!")
  return
end
but the tricky part comes in where I need to find out the direction...

If you come up with some clever way to detect this then I would love to see some suggestions from you guys!

Thanks!
//Kalle

EDIT: I found out why the program was acting weird! The x-coordinates was kind of inverted. Instead of going 2 steps forward on the x-axle it went 2 steps backward...

#2 Ditto8353

  • New Members
  • 138 posts

Posted 18 October 2012 - 07:06 PM

Have the turtle move one space and then get the new location.
Compare that with the old location.

#3 jag

  • Members
  • 533 posts
  • LocationStockholm, Sweden

Posted 18 October 2012 - 07:24 PM

View PostDitto8353, on 18 October 2012 - 07:06 PM, said:

Have the turtle move one space and then get the new location.
Compare that with the old location.
Yeah but what if its a block in the way? I dont want it to break the block just to figure out its position

EDIT: Ofc if it can't go forward I could let it go up... But then I get into the "no breaking unnecessary blocks"-problem.

EDIT 2: What I could do is just print a line for the user that the turtle must be able to move to check its pos...

#4 Ditto8353

  • New Members
  • 138 posts

Posted 18 October 2012 - 07:29 PM

if it can't move forward, try backward.
If it can't move backward then turn to either side and try forward then backward again.
If all 4 directions fail then move up one and start over... Or error out.

#5 jag

  • Members
  • 533 posts
  • LocationStockholm, Sweden

Posted 18 October 2012 - 07:41 PM

Yeah, gonna try that!

View PostDitto8353, on 18 October 2012 - 07:29 PM, said:

if it can't move forward, try backward.
If it can't move backward then turn to either side and try forward then backward again.
If all 4 directions fail then move up one and start over... Or error out.
Thanks for the tip!

#6 jag

  • Members
  • 533 posts
  • LocationStockholm, Sweden

Posted 18 October 2012 - 08:02 PM

I got a code now:
Spoiler
It's not the most beautiful piece of code, but it will do.

And to be clear: This has not been tested yet!





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users