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

Big Reactors control

Started by Livewire13, 10 July 2014 - 04:49 PM
Livewire13 #1
Posted 10 July 2014 - 06:49 PM
I'm working with the Big Reactors "Reactor Computer Port", Computercraft 1.6.3 and Thermal Expansion "Energy Cells".
My setup is an Energy Cell, which outputs an analog signal to a Comparator and then fed into a Computer, which is connected to the Computer Port on the Reactor. My code is here: http://pastebin.com/HpAMHCL7

My goal is when the comparator level drops below 2, the reactor will turn on, and once the comparator level reaches above 14, it will shut off the reactor. In my code, it just hangs at "Reactor connected, starting program"

I'm clueless why it hangs, and even when inputting my own analog signal with another Computer, it does nothing.
flaghacker #2
Posted 10 July 2014 - 09:02 PM
Are you sure the analog redstone signal is smaller than 2 or bigger than 14? That's the only problem I can see, weird why it doesn't trow an "too long without yielding" error then…

EDIT:
Just making sure, the redstone input is at the left side, right?
Edited on 10 July 2014 - 07:03 PM
Livewire13 #3
Posted 10 July 2014 - 09:09 PM
Yes, the redstone input is on the left. If I remove the last sleep() before then 2nd end it DOES throw a "control:6: Too long w'o yielding" in 2 seconds and stops the program.
Lyqyd #4
Posted 10 July 2014 - 10:05 PM
Why do you have it sleep for 16 minutes and 40 seconds every time it loops, with an additional 16:40 delay each time it gets too low or too high? You're probably just not waiting long enough to see any changes when you change the input value. Did you mean sleep(1) instead? Sleep is in seconds.
Livewire13 #5
Posted 10 July 2014 - 10:09 PM
Huh. That might be the problem! Haven't been on CC for awhile and thought it was milliseconds. I fixed that and now it throws "control:10 Too long w/o yielding". On line 10 I have it checking whether or not the analog input is above 14, aka 15. Is there a better way to do this than an if, elseif?
Lyqyd #6
Posted 11 July 2014 - 12:03 AM
Sounds like you took out all the sleeps. You should see if changing analog levels causes a redstone event to be triggered. If so, you could pull a redstone event and then only need to loop when the input changes.
Livewire13 #7
Posted 11 July 2014 - 07:48 PM
I did the redstone event pull example on the wiki and success! Analog level changes count as a redstone event. Unfortunately, when I put it in the original code, it registers the event and throws "Too long w/o yielding" at line 13.

Heres the new code: http://pastebin.com/zrTH0TXQ
Kizz #8
Posted 11 July 2014 - 08:05 PM
I think you need to break your current loop, as it just gets stuck looking at the signial.

Something like this may work better:


local reactor = peripheral.wrap("back")

if reactor.getConnected() then
  print("Reactor connected, starting program")
while true do
  local event = {os.pullEvent()}
  if event[1]=="redstone" then
	print("EVENT!")

	  if rs.getAnalogInput("left") <2 then
		print("Power level low, starting reactor")
		reactor.setActive(true)
		sleep(1)
	  elseif rs.getAnalogInput("left") >14 then
		print("Power level sufficient, reactor idling")
		reactor.setActive(false)
		sleep(1)
	  end
	end
  end
end

What this does is look for the specific redstone event. Compares the signal, then begins listening for the event again.
Edited on 11 July 2014 - 06:08 PM
Lyqyd #9
Posted 11 July 2014 - 08:25 PM
You don't need to do anything with the result of the pullEvent call, and it will be easiest to just call it with the filter for the redstone event. That os.pullEvent("redstone") needs to be inside the while loop, and you don't really need the sleeps inside the if statement.
Kizz #10
Posted 11 July 2014 - 08:28 PM
So essentially what I posted but with the original event call syntax? I would think that with a reactor connected, we would want to avoid using just any event because the reactor may throw other events. If anything it would prevent it running the loop when it is a different event.
Lyqyd #11
Posted 11 July 2014 - 10:16 PM
The loop only cares about redstone state, so it should only run when that state changes, regardless of any other events that may show up. Future expansions of the program, if any, might indeed require removal of the filter and further handling for other events, but this program doesn't need it yet.
Livewire13 #12
Posted 11 July 2014 - 11:38 PM
I test ran the program that Kizz posted, and it does call the print("EVENT!") line, but doesn't seem to execute anything afterwards. Although, it will continue to see events and call the EVENT line every time. So somehow the analog check isn't working.

Edited on 11 July 2014 - 09:48 PM
Livewire13 #13
Posted 13 July 2014 - 05:12 PM
Bump? This is still unsolved.
KingofGamesYami #14
Posted 13 July 2014 - 07:17 PM
Try running this, it will print the input value as well.


local reactor = peripheral.wrap("back")

if reactor.getConnected() then
  print("Reactor connected, starting program")
else
  error( "Reactor unresponsive", 0 )
end
while true do
  local event = {os.pullEvent()}
  if event[1]=="redstone" then
        print( "redstone detected" )
        print( "signal strength: "..rs.getAnalogInput( "left" ) )
  end
end
Livewire13 #15
Posted 13 July 2014 - 07:42 PM
Ok, that does print the correct values each time the analog signal changes, so I added my if statement after it. http://pastebin.com/91wb0ewr
So far if the power level is neither below 2 or above 13 (I changed it to 13 because I found that 14 = full power) it prints "redstone detected"
"signal strength: 7"
or whatever the strength is at the time.
Now I wait for the energy cell to drain down to 1 and see if it works.
Livewire13 #16
Posted 13 July 2014 - 08:15 PM
Success! That code works! Now my reactor will start at analog level 1 and stop at analog level 14. The final code is still here: http://pastebin.com/91wb0ewr
misson20000 #17
Posted 13 July 2014 - 08:33 PM
You might also want to try using the reactor's internal energy storage instead of an external energy cell. You can use reactor.getEnergyStored() to see how much energy is stored in there.
hilburn #18
Posted 13 July 2014 - 10:55 PM
Just a thought, but CC is actually unnecessary for this. I played on an Agrarian Skies map with no CC (booo!) and used 3 redstone ports on the reactor, one triggered below 10% power, the other above 90%. These went into a sticky piston pulse former and into the final port which was set to toggle on/off on pulse. Worked like a charm, and had the added benefit of making a nice Ch-Ch noise every time it triggered :)/>