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

Turtle Recharge Station

Started by Hoodai, 25 February 2014 - 09:28 PM
Hoodai #1
Posted 25 February 2014 - 10:28 PM
Hello all. I created a simple recharging station for turtles using Thermal Expansion's fluid transposers.

This REQUIRES THERMAL EXPANSION.

How it works is it takes a bucket and puts it into the fluid transposer, takes it out, refuels, rinse and repeat. What makes it special is that it accepts a redstone signal to stop it. Allowing you to leave it ready to charge at the flip of a lever. It also accepts an argument to be the fuel level that it will continue to fuel till it reaches.

I understand that at the current moment it's design is simplistic, but that is the beauty of it. Simple means expandable! In the future I plan to add additional features including build craft pipe/hopper support, etc.

Without further adieu: vfyLTtby.

Pictures:Charge Station (
http://imgur.com/hvEqBxx)

Enjoy! p.s. constructive criticism, suggestions, and improvements are welcome and encouraged.


Updates:

* Fixed some confusing console print messages.
* Got rid of extraneous methods that were only there for testing.
* Added os.pullEvent("redstone") to stop until you flip the switch back off.
* Made the turtle wait for the bucket to continue instead of assuming the turtle's timing was correct.
* Check the slot the bucket gets added to.
* Made the turtle's movements deal with obstructions.
Edited on 03 March 2014 - 07:34 PM
jakemg #2
Posted 27 February 2014 - 01:42 AM
Very nice I was actually just writing almost the same exact script to refuel my turtles haha nice job
Bomb Bloke #3
Posted 27 February 2014 - 02:25 AM
Various minor nit-picks:

The inbuilt "print()" function does pretty much the same thing as your "writeLine()" function.

If the turtle pauses and then resumes, it'll constantly state "resuming", as "paused" never gets set back to false. I'd remove the "resuming" bit completely and just have it say either "pausing" or "fueling".

When pausing, you could throw in an os.pullEvent("redstone"). This'll basically have the script yield (wait) on that line until one of the turtle's redstone inputs changes in some way (somewhat more efficient then looping tiny "sleep()"s flat out).

Assuming your version of ComputerCraft is at least semi-up-to-date, you can also use os.pullEvent("turtle_inventory") to pause on a line until eg a bucket gets dumped into it by the transposer. Speaking of which, it'd be worth making sure the slot the bucket goes into is the slot you're attempting to refuel from - a way to do this would be to check for the first empty inventory slot when this script is called (use turtle.getItemCount() in a loop for that), and turtle.select() it before getting on with the rest of your code.

I'd also recommend checking your movements. "turtle.forward()" for eg attempts to go forward, but the script simply carries on if that fails - what if a random player/mob wanders in front of the turtle, or it just randomly decides not to move? "while not turtle.forward() do end" is a simple way to effectively halt the script until the turtle has gone forward once (given that the movement functions return true/false depending on whether they actually worked or not).
Hoodai #4
Posted 28 February 2014 - 05:23 AM
Quote from jakemg
Very nice I was actually just writing almost the same exact script to refuel my turtles haha nice job

Thanks! Glad you found it to be useful!

Quote from Bomb Bloke
Various minor nit-picks:

The inbuilt "print()" function does pretty much the same thing as your "writeLine()" function.

If the turtle pauses and then resumes, it'll constantly state "resuming", as "paused" never gets set back to false. I'd remove the "resuming" bit completely and just have it say either "pausing" or "fueling".

When pausing, you could throw in an os.pullEvent("redstone"). This'll basically have the script yield (wait) on that line until one of the turtle's redstone inputs changes in some way (somewhat more efficient then looping tiny "sleep()"s flat out).

Assuming your version of ComputerCraft is at least semi-up-to-date, you can also use os.pullEvent("turtle_inventory") to pause on a line until eg a bucket gets dumped into it by the transposer. Speaking of which, it'd be worth making sure the slot the bucket goes into is the slot you're attempting to refuel from - a way to do this would be to check for the first empty inventory slot when this script is called (use turtle.getItemCount() in a loop for that), and turtle.select() it before getting on with the rest of your code.

I'd also recommend checking your movements. "turtle.forward()" for eg attempts to go forward, but the script simply carries on if that fails - what if a random player/mob wanders in front of the turtle, or it just randomly decides not to move? "while not turtle.forward() do end" is a simple way to effectively halt the script until the turtle has gone forward once (given that the movement functions return true/false depending on whether they actually worked or not).

First of all, great catch on the "Paused/Resuming" thing. Fixing…

The "writeLine()" function was something I was using for testing that completely I forgot to remove. Removing…

I really like the os.pullEvent("redstone") to yield instead of using sleep to yield… silly me! Changing…

As far as the turtle wait for the bucket, I made the whole thing so it was timed to work in synch with the transposer's timings. However, since things do change with updates, I will implement this for longevity of the code.

Lastly, as far as checking moves and checking the slot the bucket gets dropped into, I was waiting to see if anyone was using it before I added features that I, myself, don't really need. Well, jakemg using it is enough for me. Adding…
Edited on 28 February 2014 - 11:21 PM
Sentrus #5
Posted 01 March 2014 - 09:03 AM
Used your program today to refuel my turtle swarm. However, it didn't stop refueling at 1 million fuel and I had to stop it manually. I looked in the code and I don't see why it isn't doing that, but I'm not familiar with the nuances of Lua. Otherwise, fantastic little program. Thanks!
Hoodai #6
Posted 03 March 2014 - 08:40 PM
Quote from Sentrus
Used your program today to refuel my turtle swarm. However, it didn't stop refueling at 1 million fuel and I had to stop it manually. I looked in the code and I don't see why it isn't doing that, but I'm not familiar with the nuances of Lua. Otherwise, fantastic little program. Thanks!

Sentrus, did you perhaps put a number after the program name? Example:


pastebin get vfyLTtby refuelLava
refuelLava 10000

If so, then you will find it only refueling to 10,000.
Also, the other possibility is that you are running the build a computer craft (that I didn't even know was out) that forcibly imposes a fuel limit (not configurable).
Bomb Bloke #7
Posted 04 March 2014 - 12:46 AM
This bit here:

        while not redstone.getInput("front") do
                term.clear()
                term.setCursorPos(1,1)
                print("No Redstone Signal --> Fueling")
                refuel()
        end

… continues to fuel so long as there's no redstone signal, without ever checking the current fuel level.
Sentrus #8
Posted 04 March 2014 - 06:59 PM
This bit here:

		while not redstone.getInput("front") do
				term.clear()
				term.setCursorPos(1,1)
				print("No Redstone Signal --> Fueling")
				refuel()
		end

… continues to fuel so long as there's no redstone signal, without ever checking the current fuel level.

Ah, you're right. It's getting caught in that while loop. I edited my copy of the program and it seems to work fine now.
Hoodai #9
Posted 07 March 2014 - 03:09 AM
I fixed it. That's what I get for writing code while not listening at a business conference! Hahaha
SuperKomputerKid #10
Posted 08 March 2014 - 03:45 AM
Very Nice! Quite Impressed with it.
gollark8 #11
Posted 08 March 2014 - 06:16 AM
Would this work with a GT QTank?