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

GPS Goto Program problems

Started by AzzA, 11 February 2014 - 10:09 PM
AzzA #1
Posted 11 February 2014 - 11:09 PM
Hello Computercraft Forum, I have recently jumped into computercraft and am now attempting to write a simple gps goto program. I think I have the basic concept but a few things still elude me, firstly I have a gps tower built that seems to be working fine and have constructed a support frame craft that has x and y control but no height at the moment. The craft is able to detect its location and goes into a loop until the target location has been reached. Every now and then while its moving the gps starts giving wrong readings (normally only one axis). The other problem is I believe math related, depending on what quadrant the craft is in I have to change the < and > around. I realise I haven't been able to give much information but ill post the code as well. If any one can give me a hand it would be greatly appreciated. PS sorry about not having any paragraphs for some reason I'm unable to get a newline with enter.

print("	GPS GOTO PROGRAM")
print("--------------------------------")
x, z, y = gps.locate(5)
if x == nil then
  print("Error Getting Location")
else
  print("Current Location")
  print("x=",x," y=",y," z=",z)
end
print("Target Cords")
print("Enter x Cord")
local tx = io.read()
tx = tonumber(tx)
print("Enter y Cord")
local ty = io.read()
ty = tonumber(ty)
print("Target Cords")
print("------------")
print("x=",tx," y=",ty)
print("Press enter to confirm")
io.read()
print("Calculating!!!!!")
print("-------------------------------")
print("The conclusion is justin is gay")
print("Current Location   : ",x," ",y)
print("Target Location	: ",tx," ",ty)
print("Location Difference: ",tx-x," ",ty-y)
print("-------------------------------")
print("Press enter to continue...")
io.read()
while true do
  x, z, y = gps.locate(5)
  print("Current x: ",x," Current y: ",y)
  if x==tx then
	print("x done")
  end
  if y==ty then
	print("y done")
  end
  if (x==tx) and (y==ty) then
	print("Finished!")
	break
  end
  if x<tx then
	print("moving x")
	rs.setOutput("right",true)
	sleep(1)
	rs.setOutput("right",false)
	sleep(1.5)
  end
  if x>tx then
	print("moving -x")
	rs.setOutput("left",true)
	sleep(1)
	rs.setOutput("left",false)
	sleep(1.5)
  end

  if y<ty then
	print("moving y")
	rs.setOutput("bottom",true)
	sleep(1)
	rs.setOutput("bottom",false)
	sleep(1.5)
  end
  if y>ty then
	print("moving -y")
	rs.setOutput("top",true)
	sleep(1)
	rs.setOutput("top",false)
	sleep(1.5)
  end
end
Bomb Bloke #2
Posted 12 February 2014 - 01:22 AM
Your GPS issue sounds familiar; I suggest having a read through this thread and see if it rings any bells. Even if not then it'd still be worth reporting your MineCraft/ComputerCraft versions here.

I'm not strictly sure what your "other problem" is supposed to be.