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

Event driven reactor prog.

Started by mrrg, 09 April 2012 - 10:37 AM
mrrg #1
Posted 09 April 2012 - 12:37 PM
Hi this is a reactor program that has no sleep in it just events and timer. Also it uses ccSensors to control temperature and refill with cooling cells when needed. It also controls power lines and displays reactor content.

Youtube movie:

[media]http://www.youtube.com/watch?v=jZfUoa9Q5Zo&context=C486e0b0ADvjVQa1PpcFOzTJ1egzEUdRi3_72-k4pDQBwAjvq9pjM=[/media]


Code:

Spoiler– Code by mrrg

– Make sure reactor is OFF! controlled by red wire
rout = colors.combine(rout,colors.red)
rs.setBundledOutput("back",rout)
– Make sure rin is initialized
rin=rs.getBundledInput("bottom")
term.clear()
term.setCursorPos(1,1)
print("======IRON NOVA REACTOR CONTROL SYSTEM V0.1======")
print("=================================================")
local sides=redstone.getSides()
print("=========== Scanning for pheripherals ===========")
print("")
for i=1,#sides do
if(peripheral.isPresent(sides)) then
local type=peripheral.getType(sides)
print("Found a "..type.." on the "..sides.."side.")
if(type=="SensorController") then
side = sides
local all_sens = sensors.getSensors(sides)
for i=1,#all_sens do
if(all_sens=="Reactor") then
sensor=all_sens
else
print("Reactor sensor not found!")
end
end
print(" Sensor name: "..sensor)
end
end
end
ok=false
print("")
print("=========== Analyzing reactor sensors ===========")
sensorInfo = sensors.getSensorInfo(side,sensor,"cardType","name","distance","SensorRange","loc","activereading")
print("Name: "..sensorInfo.name)
print("Type: "..sensorInfo.cardType)
–print("Distance: "..sensorInfo.distance)
–print("Range: "..sensorInfo.SensorRange)
targets = sensors.getAvailableTargets(side,sensor)
for i=1,#targets do
target=targets
local status = sensors.setTarget(side,sensor,target)
print(" Found "..#targets.." sensor target/targets.")
if(status) then
readings=sensors.getAvailableReadings(side,sensor)
for i=1,#readings do
–print("Readings: "..readings)
if(readings=="Reactor") then
print(" Found a reactor core.")
local status = sensors.setActiveReading(side,sensor,"Reactor")
if(status) then
if sensorInfo.cardType == "IndustrialCraft2 SensorModule" then
core = sensors.getReadingAsTable(side, sensor,"heat","maxheat","output","chambers")
print(" Accessing core readings ok.")
ok=true;
else
core = sensors.getReadingAsTable(side,sensor)
end
end
end
end
end
end
– Make sure reactor is OFF! controlled by red wire
rout = colors.combine(rout,colors.red)
rs.setBundledOutput("back",rout)
–If we can read the reactor core with ic2 sensor module then go on
if(ok) then
print("")
print("Press P to power up reactor")

shutdown=true
cool_in_transit=0
cool_detect=false
request_cool_cnt=0
mon = peripheral.wrap('right')
mon.setTextScale(1)
mon.clear()
mon.setCursorPos(1,1)
mon.write(" IRON NOVA REACTOR")
mon.setCursorPos(1,2)
mon.write(" CONTROL SYSTEM V0.1")
while true do
event,arg = os.pullEvent()
– Update redstone input
if(event == "redstone") then
rin=rs.getBundledInput("bottom")
end
– Handle keys
if(event == "key") then
– print(arg)
if(arg==25) then – Start reactor
os.startTimer(1)
shutdown=false
term.clear()
term.setCursorPos(1,1)
end
if(arg==31) then – Shutdown reactor
shutdown=true
end
end
– Handle timer event, control the reactor
if(event=="timer") then
sensors.setActiveReading(side,sensor,"Reactor")
core = sensors.getReadingAsTable(side, sensor,"heat","maxheat","output","chambers")

term.clear()
term.setCursorPos(1,1)

heat = core[2]
power = core[6]
print("======IRON NOVA REACTOR CONTROL SYSTEM V0.1======")

if(colors.test(rout,colors.red)) then
print("Reactor is : OFFLINE")
else
print("Rector is : ONLINE")
end
print("Temperature : "..heat.." deg C");
mon.setCursorPos(1,5)
mon.write("Temperature : "..heat.." deg C");
print("Production : "..power.." EU/t ");
mon.setCursorPos(1,6)
mon.write("Production : "..power.." EU/t");
if(colors.test(rin,colors.blue)) then
print("External cooling is : OFFLINE")
else
print("External cooling is : ONLINE")
end
if(colors.test(rin,colors.purple)) then
print("Internal cooling is : ONLINE")
else
print("Internal cooling is : OFFLINE")
end
if(colors.test(rin,colors.red)) then
print("Power line 1 is : OFF")
else
print("Power line 1 is : ON")
end

if(colors.test(rin,colors.lime)) then
print("Power line 2 is : OFF")
else
print("Power line 2 is : ON")
end

if(colors.test(rin,colors.white)) then
print("Power line 3 is : OFF")
else
print("Power line 3 is : ON")
end
if(colors.test(rin,colors.yellow)) then
print("Power line 4 is : OFF")
else
print("Power line 4 is : ON")
end
if(shutdown or eshutdown) then
rout = colors.combine(rout,colors.red)
rs.setBundledOutput("back",rout)
else
if(heat>4000) then
rout = colors.combine(rout,colors.red)
rs.setBundledOutput("back",rout)
end
if(heat<1500) then
rout = colors.subtract(rout,colors.red)
rs.setBundledOutput("back",rout)
end
end

sensors.setActiveReading(side,sensor,"ReactorContent")
contents = sensors.getReadingAsTable(side,sensor)

– 1*Uranium
– N*Ice
– 1*Coolant
uranium=0
ice=0
coolant=0
for i=1,#contents-1,2 do
if(string.find(contents[i+1],"1*Uran")~=nil) then
uranium=uranium+1;
end

if(string.find(contents[i+1],"1*Cool")~=nil) then
coolant=coolant+1;
end

ice_str = contents[i+1]
if(string.find(ice_str,"Ice")~=nil) then

if(string.sub(ice_str,3,3)=="*") then
num=tonumber(string.sub(ice_str,1,2))
else
num=tonumber(string.sub(ice_str,1,1))
end
ice=ice+num
end
end
print("Uranium cells : "..uranium)
print("Coolant cells : "..coolant)
print("ICE Blocks : "..ice)

mon.setCursorPos(1,8)
mon.write("Uranium cells : "..uranium)
mon.setCursorPos(1,9)
mon.write("Coolant cells : "..coolant)
mon.setCursorPos(1,10)
mon.write("ICE Blocks : "..ice.." ")
cool_detect_old=cool_detect
cool_detect=colors.test(rin,colors.cyan)
if(cool_detect==true and cool_detect_old==false) then
cool_in_transit=cool_in_transit+1
end
print("Coolant cells in transit : "..cool_in_transit)

if(coolant<15 and request_cool_cnt==0) then
request_cool_cnt=200
end
if(request_cool_cnt>0) then
if(request_cool_cnt==200) then
rout = colors.combine(rout,colors.brown)
rs.setBundledOutput("back",rout)
end
if(request_cool_cnt==100) then
rout = colors.subtract(rout,colors.brown)
rs.setBundledOutput("back",rout)
end

if(request_cool_cnt==1) then
cool_in_transit=0
end
request_cool_cnt=request_cool_cnt-1
end
if(colors.test(rin,colors.orange)) then
print("EMERGENCY SHUTDOWN : ENABLED")
shutdown=true
eshutdown=true
else
print("EMERGENCY SHUTDOWN : DISABLED")
eshutdown=false
end
os.startTimer(0.1)
print("")
print("Press S to shutdown reactor and P to power it up.")
end
end
else
print("Can not get readings from reactor core.")
end

Enjoy the code :P/>/>
Leo Verto #2
Posted 09 April 2012 - 01:28 PM
Wow, all these mods combined in a truly amazing way!

One thing, how do you produce the ice? Do you have to input anything?
mrrg #3
Posted 09 April 2012 - 03:22 PM
No, you put a ic2 pump next to a compressor to make snow, and then you compress the snow to make ice.

The ic2 pump pumps directly into the compressor if it is right next to it, also make an infinite water source below the pump and you are set.

Wow, all these mods combined in a truly amazing way!

One thing, how do you produce the ice? Do you have to input anything?
Leo Verto #4
Posted 09 April 2012 - 06:59 PM
No, you put a ic2 pump next to a compressor to make snow, and then you compress the snow to make ice.

The ic2 pump pumps directly into the compressor if it is right next to it, also make an infinite water source below the pump and you are set.
Thanks for your answer! So is this system completely closed?
And how do you power the machines? Do you use the reactor?
mrrg #5
Posted 09 April 2012 - 07:38 PM
Thanks for your answer! So is this system completely closed?


Yes it is with, one exception the system that makes coolant cells, needs tin.

The system supplies a constant stream of ice..and refills also with collant cells but leaving a slot left for ice blocks.

You could feed more ice to make it a much more efficient reactor, but I did not want to have a gigantic ice machinery.

And how do you power the machines? Do you use the reactor?

Yes. With temperature control the reactor can run without ice blocks and coolant cells..
However with them it makes the on period longer.
yoskaz01 #6
Posted 14 April 2012 - 11:48 AM
looks cool
great to see the sensors put to good use :)/>/>

I've updated the lua API in build 014pre-rel - you can add to your control room mfsu monitoring as well :)/>/>

sample snapshot:
Spoiler

let me know if there is any feature you thought could be useful or make things easier…
Fallout301 #7
Posted 15 April 2012 - 07:43 PM
Hey, I feel like a COMPLETE moron here, but.. how do I set this up? eh heh heh.. it keeps telling me can not get readings from reactor core, Here are a couple of screenshots, mind if i ask what I'm doing wrong?

http://i.imgur.com/XhZbR.png
http://i.imgur.com/PEgzJ.png
http://i.imgur.com/FRmAA.png
http://i.imgur.com/gNjqr.png
http://i.imgur.com/97OGr.png

EDIT: doesn't matter if i put it in creative or normal mode, and it is using frequency 1 red, I crafted the stuff legitimately.
mrrg #8
Posted 17 April 2012 - 07:09 PM
First read: http://www.computercraft.info/forums2/index.php?/topic/126-cc13-addonccsensors/

Then there was an issue with the order you added sensorcontrollers and sensors.. try Ctrl+R to rebbot the computer.

Also the name of the sensor need to match the program, I see you figured that one out :)/>/>

Hey, I feel like a COMPLETE moron here, but.. how do I set this up? eh heh heh.. it keeps telling me can not get readings from reactor core, Here are a couple of screenshots, mind if i ask what I'm doing wrong?

EDIT: doesn't matter if i put it in creative or normal mode, and it is using frequency 1 red, I crafted the stuff legitimately.
Wolvan #9
Posted 17 April 2012 - 09:10 PM
Nice! I like it ;D +1 for you buddy
Wired2coffee #10
Posted 18 April 2012 - 03:16 AM
That is the best program I've seen for reactor controlling ever! Nice work!
mrrg #11
Posted 18 April 2012 - 06:17 PM
That is the best program I've seen for reactor controlling ever! Nice work!

Thank you!
It is my first LUA program though so there might be things in there that are bad.
monzyer #12
Posted 29 April 2012 - 07:42 PM
Just wanted to start off and say this is a great program. If you would help a fellow computer guy out, could you make a video of your reactor so i can see the wiring.

thanks,
kikotte #13
Posted 18 May 2012 - 04:21 PM
Hi,

how do you get it to work?


[attachment=228:2012-05-18_17.08.09.png]

kikotte

// Fuck Max 500K
Stockium #14
Posted 19 May 2012 - 08:03 PM
Hey. I'm looking to create the same sort of thing. Would it be possible to upload the map :P/>/> I'm not going to copy your work I just want to use it on my SSP world
Thanks
Stockium
Mega1mpact #15
Posted 20 May 2012 - 02:56 PM
epic!

Can you upload a DL of the world?
kikotte #16
Posted 21 May 2012 - 11:06 PM
Hi,

what could be the problem?

http://i.imgur.com/lIVLPh.jpg
http://i.imgur.com/bb6p0h.jpg
http://i.imgur.com/fcOBIh.jpg

kikotte
devilclarke #17
Posted 09 July 2012 - 10:43 AM
HI
Please help i have the same problem as
kikotte
Wayno #18
Posted 03 August 2012 - 06:00 AM
Hello, love the look of this.

but i have a issue, i been trying to work out why this isnt working.

so i read over code found that

targets = sensors.getAvailableTargets(side,sensor)
for i=1,#targets do
target=targets[i]
local status = sensors.setTarget(side,sensor,targets)
print(" Found "..targets.." sensor target/targets.")
isnt working anyone help plz?
cgctech #19
Posted 09 August 2012 - 08:17 PM
Same issue as kikotte, has anyone found a solution


http://i.imgur.com/lIVLPh.jpg
http://i.imgur.com/bb6p0h.jpg
http://i.imgur.com/fcOBIh.jpg
Megaprr #20
Posted 25 August 2012 - 02:24 AM
@yoskaz01 hey. i'm a bit of a noob here :D/>/>. I'm very new to Computercraft. I was looking online to learn how to make that menu that you had in that image and I can't find anything on it. I've also seen an image with the exact same layout as that, in the tekkit wiki (i believe it was in the ccsensor part.). Could you possibly help me out? or post the code?
patrick19892 #21
Posted 27 August 2012 - 07:27 AM
After working though the code I found out why it wasn't working. I have marked the lines where I changed the code, so it should be working now.

It wasn't selecting the target correctly as well as it was not displaying the number of ice due to a small typo. I also marked the location in the code where you set the side you want the moniter to be on, however if i was the orginal programmer i might update this part to allow the computer to auto select the correct side. I have posted the updated code below.

Spoiler


-- Code by mrrg
-- Some bug fixes by patrick19892
-- Make sure reactor is OFF! controlled by red wire
rout = colors.combine(rout,colors.red)
rs.setBundledOutput("back",rout)
-- Make sure rin is initialized
rin=rs.getBundledInput("bottom")
term.clear()
term.setCursorPos(1,1)
print("======IRON NOVA REACTOR CONTROL SYSTEM V0.1======")
print("=================================================")
local sides=redstone.getSides()
print("=========== Scanning for pheripherals ===========")
print("")
for i=1,#sides do
if(peripheral.isPresent(sides[i])) then
local type=peripheral.getType(sides[i])
print("Found a "..type.." on the "..sides[i].."side.")
if(type=="SensorController") then
side = sides[i]
local all_sens = sensors.getSensors(sides[i])
for i=1,#all_sens do
if(all_sens[i]=="Reactor") then
sensor=all_sens[i]
else
print("Reactor sensor not found!")
end
end
print(" Sensor name: "..sensor)
end
end
end
ok=false
print("")
print("=========== Analyzing reactor sensors ===========")
sensorInfo = sensors.getSensorInfo(side,sensor,"cardType","name","distance","SensorRange","loc","activereading")
print("Name: "..sensorInfo.name)
print("Type: "..sensorInfo.cardType)
--print("Distance: "..sensorInfo.distance)
--print("Range: "..sensorInfo.SensorRange)
targets = sensors.getAvailableTargetsforProbe(side,sensor,"Reactor") -- *** fixed so that this program can select the correct target ***
for i=1,#targets do
target=targets[i]
local status = sensors.setTarget(side,sensor,target)
print(" Found "..#targets.." sensor target/targets.")
if(status) then
readings=sensors.getAvailableReadings(side,sensor)
for i=1,#readings do
--print("Readings: "..readings[i])
if(readings[i]=="Reactor") then
print(" Found a reactor core.")
local status = sensors.setActiveReading(side,sensor,"Reactor")
if(status) then
if sensorInfo.cardType == "IndustrialCraft2 SensorModule" then
core = sensors.getReadingAsTable(side, sensor,"heat","maxheat","output","chambers")
print(" Accessing core readings ok.")
ok=true;
else
core = sensors.getReadingAsTable(side,sensor)
end
end
end
end
end
end
-- Make sure reactor is OFF! controlled by red wire
rout = colors.combine(rout,colors.red)
rs.setBundledOutput("back",rout)
--If we can read the reactor core with ic2 sensor module then go on
if(ok) then
print("")
print("Press P to power up reactor")

shutdown=true
cool_in_transit=0
cool_detect=false
request_cool_cnt=0
mon = peripheral.wrap('left') -- ***change for side with monitor***
mon.setTextScale(1)
mon.clear()
mon.setCursorPos(1,1)
mon.write(" IRON NOVA REACTOR")
mon.setCursorPos(1,2)
mon.write(" CONTROL SYSTEM V0.1")
while true do
event,arg = os.pullEvent()
-- Update redstone input
if(event == "redstone") then
rin=rs.getBundledInput("bottom")
end
-- Handle keys
if(event == "key") then
-- print(arg)
if(arg==25) then -- Start reactor
os.startTimer(1)
shutdown=false
term.clear()
term.setCursorPos(1,1)
end
if(arg==31) then -- Shutdown reactor
shutdown=true
end
end
-- Handle timer event, control the reactor
if(event=="timer") then
sensors.setActiveReading(side,sensor,"Reactor")
core = sensors.getReadingAsTable(side, sensor,"heat","maxheat","output","chambers")

term.clear()
term.setCursorPos(1,1)

heat = core[2]
power = core[4]
print("======IRON NOVA REACTOR CONTROL SYSTEM V0.1======")

if(colors.test(rout,colors.red)) then
print("Reactor is : OFFLINE")
else
print("Rector is : ONLINE")
end
print("Temperature : "..heat.." deg C");
mon.setCursorPos(1,5)
mon.write("Temperature : "..heat.." deg C");
print("Production : "..power.." EU/t ");
mon.setCursorPos(1,6)
mon.write("Production : "..power.." EU/t");
if(colors.test(rin,colors.blue)) then
print("External cooling is : OFFLINE")
else
print("External cooling is : ONLINE")
end
if(colors.test(rin,colors.purple)) then
print("Internal cooling is : ONLINE")
else
print("Internal cooling is : OFFLINE")
end
if(colors.test(rin,colors.red)) then
print("Power line 1 is : OFF")
else
print("Power line 1 is : ON")
end

if(colors.test(rin,colors.lime)) then
print("Power line 2 is : OFF")
else
print("Power line 2 is : ON")
end

if(colors.test(rin,colors.white)) then
print("Power line 3 is : OFF")
else
print("Power line 3 is : ON")
end
if(colors.test(rin,colors.yellow)) then
print("Power line 4 is : OFF")
else
print("Power line 4 is : ON")
end
if(shutdown or eshutdown) then
rout = colors.combine(rout,colors.red)
rs.setBundledOutput("back",rout)
else
if(heat>4000) then
rout = colors.combine(rout,colors.red)
rs.setBundledOutput("back",rout)
end
if(heat<1500) then
rout = colors.subtract(rout,colors.red)
rs.setBundledOutput("back",rout)
end
end

sensors.setActiveReading(side,sensor,"ReactorContent")
contents = sensors.getReadingAsTable(side,sensor)

-- 1*Uranium
-- N*Ice
-- 1*Coolant
uranium=0
ice=0
coolant=0
for i=1,#contents-1,2 do
if(string.find(contents[i+1],"1*Uran")~=nil) then
uranium=uranium+1;
end

if(string.find(contents[i+1],"1*Cool")~=nil) then
coolant=coolant+1;
end

ice_str = contents[i+1]
if(string.find(ice_str,"ice")~=nil) then -- *** fixed so it will detected ice correctly ***

if(string.sub(ice_str,3,3)=="*") then
num=tonumber(string.sub(ice_str,1,2))
else
num=tonumber(string.sub(ice_str,1,1))
end
ice=ice+num
end
end
print("Uranium cells : "..uranium)
print("Coolant cells : "..coolant)
print("ICE Blocks : "..ice)

mon.setCursorPos(1,8)
mon.write("Uranium cells : "..uranium)
mon.setCursorPos(1,9)
mon.write("Coolant cells : "..coolant)
mon.setCursorPos(1,10)
mon.write("ICE Blocks : "..ice.." ")
cool_detect_old=cool_detect
cool_detect=colors.test(rin,colors.cyan)
if(cool_detect==true and cool_detect_old==false) then
cool_in_transit=cool_in_transit+1
end
print("Coolant cells in transit : "..cool_in_transit)

if(coolant<15 and request_cool_cnt==0) then
request_cool_cnt=200
end
if(request_cool_cnt>0) then
if(request_cool_cnt==200) then
rout = colors.combine(rout,colors.brown)
rs.setBundledOutput("back",rout)
end
if(request_cool_cnt==100) then
rout = colors.subtract(rout,colors.brown)
rs.setBundledOutput("back",rout)
end

if(request_cool_cnt==1) then
cool_in_transit=0
end
request_cool_cnt=request_cool_cnt-1
end
if(colors.test(rin,colors.orange)) then
print("EMERGENCY SHUTDOWN : ENABLED")
shutdown=true
eshutdown=true
else
print("EMERGENCY SHUTDOWN : DISABLED")
eshutdown=false
end
os.startTimer(0.1)
print("")
print("Press S to shutdown reactor and P to power it up.")
end
end
else
print("Can not get readings from reactor core.")
end
dorky106 #22
Posted 30 August 2012 - 10:39 PM
(Found my problem)