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

RoxRC - Remote control turtle program

Started by Roxforbraynz, 06 April 2014 - 12:47 AM
Roxforbraynz #1
Posted 06 April 2014 - 02:47 AM
RoxRC

Wireless control for your Turtle


A very simple code with a clean UI designed to control a remote mining turtle. Most remote turtle programs I looked at make an effort to only control one turtle at once. This code doesn't include such protections and thus allows you to control more than one turtle at once if desired.


You may modify this code in any way you desire and share it with whomever you wish.

This code was designed for a Pocket Computer, though will work on a normal Computer if the wireless modem is on the back.





-- This section goes on the controller. (Handheld computer recommended) --
local function RoxMaster()
  local run = 1
  while run == 1 do
	local sEvent, param = os.pullEvent("key")
	if sEvent == "key" then
	  if param == 17 then
		rednet.broadcast("MoveForward")
	  elseif param == 30 then
		rednet.broadcast("MoveLeft")
	  elseif param == 31 then
		rednet.broadcast("MoveBack")
	  elseif param == 32 then
		rednet.broadcast("MoveRight")
	  elseif param == 18 then
		rednet.broadcast("MoveUp")
	  elseif param == 16 then
		rednet.broadcast("MoveDown")
	  elseif param == 33 then
		rednet.broadcast("DigForward")
	  elseif param == 19 then
		rednet.broadcast("DigUp")
	  elseif param == 46 then
		rednet.broadcast("DigDown")
	  elseif param == 45 then
		rednet.broadcast("EndTurtle")
		textutils.slowPrint("Ended program on the")
		textutils.slowPrint("current Turtle and closed")
		textutils.slowPrint("it\'s Rednet connection.")
		print("--------------------------")
	  elseif param == 44 then
		rednet.broadcast("EndBoth")
		run = 0
		rednet.close("back")
		textutils.slowPrint("Ended program on both")
		textutils.slowPrint("machines.")
		sleep(0.75)
		textutils.slowPrint("Closed rednet connection.")
	  end
	end
  end
end
rednet.open("back")
term.clear()
textutils.slowPrint("Rox Remote Control Console \(RoxRCC\) sending signal.")
print("--------------------------")
textutils.slowPrint("WASD to move.")
textutils.slowPrint("E to rise.")
textutils.slowPrint("Q to fall.")
textutils.slowPrint("F to dig forward.")
textutils.slowPrint("R to dig up.")
textutils.slowPrint("C to dig down.")
textutils.slowPrint("X to stop current Turtle.")
textutils.slowPrint("Z to exit.")
print("--------------------------")
RoxMaster()

-- This section goes on the turtle. --
local function check()
  if turtle.getFuelLevel() < 5 then
	turtle.select(16)
	turtle.refuel(1)
	turtle.select(1)
  end
end
local function RoxSlave()
  local run = 1
  while run == 1 do
	local scrap, message = rednet.receive()
	if message == "MoveForward" then
	  check()
	  turtle.forward()
	elseif message == "MoveBack" then
	  check()
	  turtle.back()
	elseif message == "MoveLeft" then
	  turtle.turnLeft()
	elseif message == "MoveRight" then
	  turtle.turnRight()
	elseif message == "MoveUp" then
	  check()
	  turtle.up()
	elseif message == "MoveDown" then
	  check()
	  turtle.down()
	elseif message == "DigForward" then
	  turtle.dig()
	elseif message == "DigUp" then
	  turtle.digUp()
	elseif message == "DigDown" then
	  turtle.digDown()
	elseif message == "EndTurtle" then
	  run = 0
	  rednet.close("right")
	  textutils.slowPrint("Console ended program.")
	elseif message == "EndBoth" then
	  run = 0
	  rednet.close("right")
	  textutils.slowPrint("Console ended program.")
	end
  end
end
rednet.open("right")
term.clear()
textutils.slowPrint("Rox Remote Control Turtle \(RoxRCT\)")
print("---------------------------------------")
textutils.slowPrint("Receiver ready. Awaiting command from")
textutils.slowPrint("the console.")
textutils.slowPrint("Fuel is used from slot 16.")
print("---------------------------------------")
RoxSlave()


Edit: Pastebin codes now available!

RoxRCT (For the turtle): ZGmtKEkT
RoxRCC (For the console): kDiVVeRd
Edited on 09 April 2014 - 03:13 AM
TheMrIron2 #2
Posted 06 April 2014 - 09:36 AM
So, you're controlling the Turtles like Remote Control cars? :P/> I like it!

EDIT: By the way, (for ease of download) on your computer/PDA, type pastebin put [your program] and it'll give you a pastebin code, so someone could simply do pastebin get (code) (program name) to download it.
Just making it easier.
Edited on 06 April 2014 - 07:38 AM
Roxforbraynz #3
Posted 09 April 2014 - 04:47 AM
So, you're controlling the Turtles like Remote Control cars? :P/> I like it!

EDIT: By the way, (for ease of download) on your computer/PDA, type pastebin put [your program] and it'll give you a pastebin code, so someone could simply do pastebin get (code) (program name) to download it.
Just making it easier.

Ah, that's a good idea! I'll do that next time I hop on my server. I'll edit the main post in a bit to include the codes. Stay tuned!
TheMrIron2 #4
Posted 09 April 2014 - 05:17 PM
I really like the idea. Not only is using keyboard buttons instead of a line of code clever, but putting it on a PDA is ingenious. Never seen anything like it :o/> It opens up the possibility of Racing Turtles :P/>
Agoldfish #5
Posted 09 April 2014 - 05:35 PM
It opens up the possibility of Racing Turtles :P/>
I'm on it.
Csstform #6
Posted 09 April 2014 - 08:45 PM
It opens up the possibility of Racing Turtles :P/>/>
I'm on it.
*cough* irc gp *cough*
TheMrIron2 #7
Posted 12 April 2014 - 09:45 PM
It opens up the possibility of Racing Turtles :P/>
I'm on it.
Can't wait.
Csstform #8
Posted 13 April 2014 - 01:29 PM
-snip-
[shamelessplug] http://www.computercraft.info/forums2/index.php?/topic/18018-goldkart/ [/shamelessplug]
DavEdward #9
Posted 28 April 2014 - 02:19 AM
Thanks for the very useful program!

I wanted to add more functionality to it so I made some tweaks to the code. Feel free to pick it apart and improve on it.
I wanted to add the ability to have turtles suck, drop, and select slots.

Computer/Pocket Computer Code:


local function RoxMaster()
  local run = 1
  while run == 1 do
	local sEvent, param = os.pullEvent("key")
	if sEvent == "key" then
	  if param == 17 then
		rednet.broadcast("MoveForward")
	  elseif param == 30 then
		rednet.broadcast("MoveLeft")
	  elseif param == 31 then
		rednet.broadcast("MoveBack")
	  elseif param == 32 then
		rednet.broadcast("MoveRight")
	  elseif param == 18 then
		rednet.broadcast("MoveUp")
	  elseif param == 16 then
		rednet.broadcast("MoveDown")
	  elseif param == 33 then
		rednet.broadcast("DigForward")
	  elseif param == 19 then
		rednet.broadcast("DigUp")
	  elseif param == 46 then
		rednet.broadcast("DigDown")
------ Dav's additions for place, suck, and select -----
	  elseif param == 13 then
		print("Which slot?")
		sleep(0.5)
		local selectslot = read()
		selectslot = tonumber(selectslot)
		if (selectslot~=nil) and (selectslot>0) and (selectslot<17) then
		  rednet.broadcast("Select,"..selectslot)
		else
		  print("Error: Must be number 1-16")
		  sleep(2)
		end
		Menu()
	  elseif param == 34 then
		rednet.broadcast("SuckForward")
	  elseif param == 20 then
		rednet.broadcast("SuckUp")
	  elseif param == 48 then
		rednet.broadcast("SuckDown")
	  elseif param == 35 then
		rednet.broadcast("DropForward")
	  elseif param == 21 then
		rednet.broadcast("DropUp")
	  elseif param == 49 then
		rednet.broadcast("DropDown")
	  elseif param == 36 then
		rednet.broadcast("PlaceForward")
	  elseif param == 22 then
		rednet.broadcast("PlaceUp")
	  elseif param == 50 then
		rednet.broadcast("PlaceDown")
------------------
	  elseif param == 45 then
		rednet.broadcast("EndTurtle")
		textutils.slowPrint("Ended program on the")
		textutils.slowPrint("current Turtle and closed")
		textutils.slowPrint("it\'s Rednet connection.")
		print("--------------------------")
	  elseif param == 44 then
		rednet.broadcast("EndBoth")
		run = 0
		rednet.close("back")
		textutils.slowPrint("Ended program on both")
		textutils.slowPrint("machines.")
		sleep(0.75)
		textutils.slowPrint("Closed rednet connection.")
	  end
	end
  end
end
rednet.open("back")
function Menu()
term.clear()
print("--------------------------")
print("WASD to move.")
print("E to rise.")
print("Q to fall.")
print("F to dig forward.")
print("R to dig up.")
print("C to dig down.")
----- Dav's Additions ---
print("= to select slot.")
print("G to suck forward.")
print("T to suck up.")
print("B to suck down.")
print("H to drop forward.")
print("Y to drop up.")
print("N to drop down.")
print("J to place forward.")
print("U to place up.")
print("M to place down.")
----------------
print("X to stop current Turtle.")
print("Z to exit.")
end
Menu()
RoxMaster()

Turtle Code:


local function check()
  if turtle.getFuelLevel() < 5 then
	turtle.select(16)
	turtle.refuel(1)
	turtle.select(1)
  end
end
local function RoxSlave()
  local run = 1
  while run == 1 do
	local scrap, message = rednet.receive()
----- Dav's addtions ---
local splitData = {}
local index = 1
for data in string.gmatch(message, "[^,]+") do
	splitData[index] = data;
	index = index + 1
end
print(message)
if type(splitData[2]) == "string" then
print("splitData 2 is a string")
splitData[2]= tonumber(splitData[2])
end
--------- Above takes rednet recieve data and makes it split the value into 2 values in the table 'splitData'
	if splitData[1] == "MoveForward" then
	  check()
	  turtle.forward()
	elseif splitData[1] == "MoveBack" then
	  check()
	  turtle.back()
	elseif splitData[1] == "MoveLeft" then
	  turtle.turnLeft()
	elseif splitData[1] == "MoveRight" then
	  turtle.turnRight()
	elseif splitData[1] == "MoveUp" then
	  check()
	  turtle.up()
	elseif splitData[1] == "MoveDown" then
	  check()
	  turtle.down()
	elseif splitData[1] == "DigForward" then
	  turtle.dig()
	elseif splitData[1] == "DigUp" then
	  turtle.digUp()
	elseif splitData[1] == "DigDown" then
	  turtle.digDown()
-------- Dav's addtions
	elseif splitData[1] == "Select" then
	  turtle.select(splitData[2])
	elseif splitData[1] == "SuckForward" then
	  turtle.suck()
	elseif splitData[1] == "SuckUp" then
	  turtle.suckUp()
	elseif splitData[1] == "SuckDown" then
	  turtle.suckDown()
	elseif splitData[1] == "DropForward" then
	  turtle.drop()
	elseif splitData[1] == "DropUp" then
	  turtle.dropUp()
	elseif splitData[1] == "DropDown" then
	  turtle.dropDown()
	elseif splitData[1] == "PlaceForward" then
	  turtle.place()
	elseif splitData[1] == "PlaceUp" then
	  turtle.placeUp()
	elseif splitData[1] == "PlaceDown" then
	  turtle.placeDown()
-----------
	elseif splitData[1] == "EndTurtle" then
	  run = 0
	  rednet.close("right")
	  textutils.slowPrint("Console ended program.")
	elseif splitData[1] == "EndBoth" then
	  run = 0
	  rednet.close("right")
	  textutils.slowPrint("Console ended program.")
	end
  end
end
rednet.open("right")
term.clear()
textutils.slowPrint("Rox Remote Control Turtle \(RoxRCT\)")
print("---------------------------------------")
print("Receiver ready. Awaiting command from")
print("the console.")
print("Fuel is used from slot 16.")
print("---------------------------------------")
RoxSlave()
ArsenArsen #10
Posted 26 May 2015 - 03:56 PM
Thanks for the very useful program!

I wanted to add more functionality to it so I made some tweaks to the code. Feel free to pick it apart and improve on it.
I wanted to add the ability to have turtles suck, drop, and select slots.

Computer/Pocket Computer Code:


local function RoxMaster()
  local run = 1
  while run == 1 do
	local sEvent, param = os.pullEvent("key")
	if sEvent == "key" then
	  if param == 17 then
		rednet.broadcast("MoveForward")
	  elseif param == 30 then
		rednet.broadcast("MoveLeft")
	  elseif param == 31 then
		rednet.broadcast("MoveBack")
	  elseif param == 32 then
		rednet.broadcast("MoveRight")
	  elseif param == 18 then
		rednet.broadcast("MoveUp")
	  elseif param == 16 then
		rednet.broadcast("MoveDown")
	  elseif param == 33 then
		rednet.broadcast("DigForward")
	  elseif param == 19 then
		rednet.broadcast("DigUp")
	  elseif param == 46 then
		rednet.broadcast("DigDown")
------ Dav's additions for place, suck, and select -----
	  elseif param == 13 then
		print("Which slot?")
		sleep(0.5)
		local selectslot = read()
		selectslot = tonumber(selectslot)
		if (selectslot~=nil) and (selectslot>0) and (selectslot<17) then
		  rednet.broadcast("Select,"..selectslot)
		else
		  print("Error: Must be number 1-16")
		  sleep(2)
		end
		Menu()
	  elseif param == 34 then
		rednet.broadcast("SuckForward")
	  elseif param == 20 then
		rednet.broadcast("SuckUp")
	  elseif param == 48 then
		rednet.broadcast("SuckDown")
	  elseif param == 35 then
		rednet.broadcast("DropForward")
	  elseif param == 21 then
		rednet.broadcast("DropUp")
	  elseif param == 49 then
		rednet.broadcast("DropDown")
	  elseif param == 36 then
		rednet.broadcast("PlaceForward")
	  elseif param == 22 then
		rednet.broadcast("PlaceUp")
	  elseif param == 50 then
		rednet.broadcast("PlaceDown")
------------------
	  elseif param == 45 then
		rednet.broadcast("EndTurtle")
		textutils.slowPrint("Ended program on the")
		textutils.slowPrint("current Turtle and closed")
		textutils.slowPrint("it\'s Rednet connection.")
		print("--------------------------")
	  elseif param == 44 then
		rednet.broadcast("EndBoth")
		run = 0
		rednet.close("back")
		textutils.slowPrint("Ended program on both")
		textutils.slowPrint("machines.")
		sleep(0.75)
		textutils.slowPrint("Closed rednet connection.")
	  end
	end
  end
end
rednet.open("back")
function Menu()
term.clear()
print("--------------------------")
print("WASD to move.")
print("E to rise.")
print("Q to fall.")
print("F to dig forward.")
print("R to dig up.")
print("C to dig down.")
----- Dav's Additions ---
print("= to select slot.")
print("G to suck forward.")
print("T to suck up.")
print("B to suck down.")
print("H to drop forward.")
print("Y to drop up.")
print("N to drop down.")
print("J to place forward.")
print("U to place up.")
print("M to place down.")
----------------
print("X to stop current Turtle.")
print("Z to exit.")
end
Menu()
RoxMaster()

Turtle Code:


local function check()
  if turtle.getFuelLevel() < 5 then
	turtle.select(16)
	turtle.refuel(1)
	turtle.select(1)
  end
end
local function RoxSlave()
  local run = 1
  while run == 1 do
	local scrap, message = rednet.receive()
----- Dav's addtions ---
local splitData = {}
local index = 1
for data in string.gmatch(message, "[^,]+") do
	splitData[index] = data;
	index = index + 1
end
print(message)
if type(splitData[2]) == "string" then
print("splitData 2 is a string")
splitData[2]= tonumber(splitData[2])
end
--------- Above takes rednet recieve data and makes it split the value into 2 values in the table 'splitData'
	if splitData[1] == "MoveForward" then
	  check()
	  turtle.forward()
	elseif splitData[1] == "MoveBack" then
	  check()
	  turtle.back()
	elseif splitData[1] == "MoveLeft" then
	  turtle.turnLeft()
	elseif splitData[1] == "MoveRight" then
	  turtle.turnRight()
	elseif splitData[1] == "MoveUp" then
	  check()
	  turtle.up()
	elseif splitData[1] == "MoveDown" then
	  check()
	  turtle.down()
	elseif splitData[1] == "DigForward" then
	  turtle.dig()
	elseif splitData[1] == "DigUp" then
	  turtle.digUp()
	elseif splitData[1] == "DigDown" then
	  turtle.digDown()
-------- Dav's addtions
	elseif splitData[1] == "Select" then
	  turtle.select(splitData[2])
	elseif splitData[1] == "SuckForward" then
	  turtle.suck()
	elseif splitData[1] == "SuckUp" then
	  turtle.suckUp()
	elseif splitData[1] == "SuckDown" then
	  turtle.suckDown()
	elseif splitData[1] == "DropForward" then
	  turtle.drop()
	elseif splitData[1] == "DropUp" then
	  turtle.dropUp()
	elseif splitData[1] == "DropDown" then
	  turtle.dropDown()
	elseif splitData[1] == "PlaceForward" then
	  turtle.place()
	elseif splitData[1] == "PlaceUp" then
	  turtle.placeUp()
	elseif splitData[1] == "PlaceDown" then
	  turtle.placeDown()
-----------
	elseif splitData[1] == "EndTurtle" then
	  run = 0
	  rednet.close("right")
	  textutils.slowPrint("Console ended program.")
	elseif splitData[1] == "EndBoth" then
	  run = 0
	  rednet.close("right")
	  textutils.slowPrint("Console ended program.")
	end
  end
end
rednet.open("right")
term.clear()
textutils.slowPrint("Rox Remote Control Turtle \(RoxRCT\)")
print("---------------------------------------")
print("Receiver ready. Awaiting command from")
print("the console.")
print("Fuel is used from slot 16.")
print("---------------------------------------")
RoxSlave()
My change:
Remote: pastebin get d4dEZM62 startup
Turtle: pastebin get GE9D197H startup

On both type reboot at the end
DeathNET #11
Posted 27 November 2015 - 10:38 AM
Control multiple turtles with the same device brilliant! but uh how do i connect them?