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

Remote terminal respond to commands

Started by Simmons928, 22 June 2014 - 03:02 PM
Simmons928 #1
Posted 22 June 2014 - 05:02 PM
Ok, I am not sure where to start with this.


I have a reactor(From Big Reactor Mod). I have an automation program on a computer. It outputs information to 6 monitors. What I am trying to do is add a feature to that program that keeps the automation loop running but allows me to make changed to a couple different variables while that program is running. I would like to be able to use commands like "set [parm] [value]" which I dont believe will be a problem. I just need to make the computer be able to listen for the command while not interrupting the loop.
Bubba #2
Posted 22 June 2014 - 07:23 PM
Please post your current code. There are several ways to do this, but the easiest implementation will depend on your code. However, if you would like to research how to do this yourself, I would suggest one of two things:

- The parallels api
- Use os.setAlarm in order to do interval checks while using os.pullEvent

Both of these are documented on the wiki.
Edited on 22 June 2014 - 05:26 PM
Simmons928 #3
Posted 22 June 2014 - 08:24 PM
My preference would be to do it on my own. I currently do not have a build of my program contain this function. Thank you very much for the info. Below is the code if you would like to take a look. I think os.setAlarm is going to do what I am looking for I will experiment with it and get back to you. Again thank you for the information :)/>


function basicValues()
reactor = peripheral.wrap("right")
modem = peripheral.wrap("back")
mon1 = peripheral.wrap("monitor_8")
mon2 = peripheral.wrap("monitor_7")
mon3 = peripheral.wrap("monitor_9")
mon4 = peripheral.wrap("monitor_10")
mon5 = peripheral.wrap("monitor_11")
mon6 = peripheral.wrap("monitor_12")

connected = reactor.getConnected()
numOfContRod = reactor.getNumberOfControlRods()
active = reactor.getActive()
runtime = 0
errors = 0
lastPowerStore = 0

--Monitor 1 formatting
mon1.setBackgroundColor(colors.white)
mon1.setTextColor(colors.black)
mon1.setTextScale(1)
mon1.clear()
--Monitor 2 formatting
mon2.setBackgroundColor(colors.white)
mon2.setTextColor(colors.black)
mon2.setTextScale(1)
mon2.clear()
--Monitor 3 formatting
mon3.setBackgroundColor(colors.white)
mon3.setTextColor(colors.black)
mon3.setTextScale(1)
mon3.clear()
--Monitor 4 formatting
mon4.setBackgroundColor(colors.white)
mon4.setTextColor(colors.black)
mon4.setTextScale(1)
mon4.clear()
--Monitor 5 formatting
mon5.setBackgroundColor(colors.white)
mon5.setTextColor(colors.black)
mon5.setTextScale(1)
mon5.clear()
--Monitor 6 formatting
mon6.setBackgroundColor(colors.white)
mon6.setTextColor(colors.black)
mon6.setTextScale(1)
mon6.clear()

--default starting levels
maxPower = 7500000
minPower = 7000000
maxCaseTemp = 700
maxFuelTemp = 2500
hardLimit = 99
end

function rodLevels()
rod1Level = reactor.getControlRodLevel(0)
rod2Level = reactor.getControlRodLevel(1)
rod3Level = reactor.getControlRodLevel(2)
rod4Level = reactor.getControlRodLevel(3)
rod5Level = reactor.getControlRodLevel(4)
rod6Level = reactor.getControlRodLevel(5)
rod7Level = reactor.getControlRodLevel(6)
rod8Level = reactor.getControlRodLevel(7)
rod9Level = reactor.getControlRodLevel(8)
rod10Level = reactor.getControlRodLevel(9)
rod11Level = reactor.getControlRodLevel(10)
rod12Level = reactor.getControlRodLevel(11)
mon1.setCursorPos(1,1)
mon1.write("R 1: "..rod1Level)
mon1.setCursorPos(1,2)
mon1.write("R 2: "..rod2Level)
mon1.setCursorPos(1,3)
mon1.write("R 3: "..rod3Level)
mon1.setCursorPos(1,4)
mon1.write("R 4: "..rod4Level)
mon1.setCursorPos(1,5)
mon1.write("R 5: "..rod5Level)
mon1.setCursorPos(1,6)
mon1.write("R 6: "..rod6Level)
mon1.setCursorPos(1,7)
mon1.write("R 7: "..rod7Level)
mon1.setCursorPos(1,8)
mon1.write("R 8: "..rod8Level)
mon1.setCursorPos(1,9)
mon1.write("R 9: "..rod9Level)
mon1.setCursorPos(1,10)
mon1.write("R10: "..rod10Level)
mon1.setCursorPos(1,11)
mon1.write("R11: "..rod11Level)
mon1.setCursorPos(1,12)
mon1.write("R12: "..rod12Level)
end

function tempCheck()
caseTemp = reactor.getCasingTemperature()
mon4.setCursorPos(1,1)
mon4.write("Case Temp")
mon4.setCursorPos(1,2)
mon4.write(caseTemp)

fuelTemp = reactor.getFuelTemperature()
mon5.setCursorPos(1,1)
mon5.write("Fuel Temp")
mon5.setCursorPos(1,2)
mon5.write(fuelTemp)

if caseTemp>maxCaseTemp then
reactor.setAllControlRodLevels(100)
while caseTemp>maxCaseTemp do

mon4.setBackgroundColor(colors.red)
mon4.setBackgroundColor(colors.white)
caseTemp = reactor.getCasingTemperature()
errors = errors+1
end
elseif fuelTemp>maxFuelTemp then
reactor.setAllControlRodLevels(100)
while fuelTemp>maxFuelTemp do

mon5.setBackgroundColor(colors.yellow)
mon5.setBackgroundColor(colors.white)
fuelTemp = reactor.getFuelTemperature()
errors = errors+1
end
end
end

function fuelCheck()
currentFuel = reactor.getFuelAmount()
amountWaste = reactor.getWasteAmount()
maxFuel = reactor.getFuelAmountMax()
waste = (amountWaste/currentFuel)*100
fuel = (currentFuel/maxFuel)*100

mon2.setCursorPos(1,1)
mon2.write("Fuel")
mon2.setCursorPos(1,2)
mon2.write(fuel)
mon2.setCursorPos(1,3)
mon2.write(currentFuel)
if fuel<50 then
mon2.setBackgroundColor(colors.yellow)
else
mon2.setBackgroundColor(colors.white)
end
mon3.setCursorPos(1,1)
mon3.write("Waste")
mon3.setCursorPos(1,2)
mon3.write(waste)
mon3.setCursorPos(1,3)
mon3.write(amountWaste)
if amountWaste>2000 then
mon3.setBackgroundColor(colors.blue)
else
mon3.setBackgroundColor(colors.white)
end
end

function logic()
powerStore = reactor.getEnergyStored()
energyProd = reactor.getEnergyProducedLastTick()
fuelReact = reactor.getFuelReactivity()
fuelUsed = reactor.getFuelConsumedLastTick()
averageRodLevel = (rod1Level+rod2Level+rod3Level+rod4Level+rod5Level+rod6Level+rod7Level+rod8Level+rod9Level+rod10Level+rod11Level+rod12Level)/12
if powerStore<minPower then
if rod1Level>=averageRodLevel then
rod1Level = rod1Level-1
if rod1Level<0 then
rod1Level = 0
end
reactor.setControlRodLevel(0,rod1Level)

elseif rod2Level>=averageRodLevel then
rod2Level = rod2Level-1
if rod2Level<0 then
rod2Level = 0
end
reactor.setControlRodLevel(1,rod2Level)

elseif rod3Level>=averageRodLevel then
rod3Level = rod3Level-1
if rod3Level<0 then
rod3Level = 0
end
reactor.setControlRodLevel(2,rod3Level)

elseif rod4Level>=averageRodLevel then
rod4Level = rod4Level-1
if rod4Level<0 then
rod4Level = 0
end
reactor.setControlRodLevel(3,rod4Level)

elseif rod5Level>=averageRodLevel then
rod5Level = rod5Level-1
if rod5Level<0 then
rod5Level = 0
end
reactor.setControlRodLevel(4,rod5Level)

elseif rod6Level>=averageRodLevel then
rod6Level = rod6Level-1
if rod6Level<0 then
rod6Level = 0
end
reactor.setControlRodLevel(5,rod6Level)

elseif rod7Level>=averageRodLevel then
rod7Level = rod7Level-1
if rod7Level<0 then
rod7Level = 0
end
reactor.setControlRodLevel(6,rod7Level)

elseif rod8Level>=averageRodLevel then
rod8Level = rod8Level-1
if rod8Level<0 then
rod8Level = 0
end
reactor.setControlRodLevel(7,rod8Level)

elseif rod9Level>=averageRodLevel then
rod9Level = rod9Level-1
if rod9Level<0 then
rod9Level = 0
end
reactor.setControlRodLevel(8,rod9Level)

elseif rod10Level>=averageRodLevel then
rod10Level = rod10Level-1
if rod10Level<0 then
rod10Level = 0
end
reactor.setControlRodLevel(9,rod10Level)

elseif rod11Level>=averageRodLevel then
rod11Level = rod11Level-1
if rod11Level<0 then
rod11Level = 0
end
reactor.setControlRodLevel(10,rod11Level)

elseif rod12Level>=averageRodLevel then
rod12Level = rod12Level-1
if rod12Level<0 then
rod12Level = 0
end
reactor.setControlRodLevel(11,rod12Level)

end
elseif powerStore>maxPower then
if rod1Level<=averageRodLevel then
rod1Level = rod1Level+1
if rod1Level>hardLimit then
rod1Level = hardLimit
end
reactor.setControlRodLevel(0,rod1Level)

elseif rod2Level<=averageRodLevel then
rod2Level = rod2Level+1
if rod2Level>hardLimit then
rod2Level = hardLimit
end
reactor.setControlRodLevel(1,rod2Level)

elseif rod3Level<=averageRodLevel then
rod3Level = rod3Level+1
if rod3Level>hardLimit then
rod3Level = hardLimit
end
reactor.setControlRodLevel(2,rod3Level)

elseif rod4Level<=averageRodLevel then
rod4Level = rod4Level+1
if rod4Level>hardLimit then
rod4Level = hardLimit
end
reactor.setControlRodLevel(3,rod4Level)

elseif rod5Level<=averageRodLevel then
rod5Level = rod5Level+1
if rod5Level>hardLimit then
rod5Level = hardLimit
end
reactor.setControlRodLevel(4,rod5Level)

elseif rod6Level<=averageRodLevel then
rod6Level = rod6Level+1
if rod6Level>hardLimit then
rod6Level = hardLimit
end
reactor.setControlRodLevel(5,rod6Level)

elseif rod7Level<=averageRodLevel then
rod7Level = rod7Level+1
if rod7Level>hardLimit then
rod7Level = hardLimit
end
reactor.setControlRodLevel(6,rod7Level)

elseif rod8Level<=averageRodLevel then
rod8Level = rod8Level+1
if rod8Level>hardLimit then
rod8Level = hardLimit
end
reactor.setControlRodLevel(7,rod8Level)

elseif rod9Level<=averageRodLevel then
rod9Level = rod9Level+1
if rod9Level>hardLimit then
rod9Level = hardLimit
end
reactor.setControlRodLevel(8,rod9Level)

elseif rod10Level<=averageRodLevel then
rod10level = rod10Level+1
if rod10Level>hardLimit then
rod10Level = hardLimit
end
reactor.setControlRodLevel(9,rod10Level)

elseif rod11Level<=averageRodLevel then
rod11Level = rod11Level+1
if rod11Level>hardLimit then
rod11Level = hardLimit
end
reactor.setControlRodLevel(10,rod11Level)

elseif rod12Level<=averageRodLevel then
rod12Level = rod12Level+1
if rod12Level>hardLimit then
rod121Level = hardLimit
end
reactor.setControlRodLevel(11,rod12Level)

end
else 
end
end

function mainScrOut()
powerStore = reactor.getEnergyStored()
energyProd = reactor.getEnergyProducedLastTick()
fuelReact = reactor.getFuelReactivity()
fuelUsed = reactor.getFuelConsumedLastTick()
perSec = energyProd*20
lastPowerStore = lastPowerStore-powerStore
mon1.setCursorPos(10,1)
mon1.write("The reactor is now managing itself")
mon1.setCursorPos(10,2)
mon1.write("---------------------------------------------------")
mon1.setCursorPos(10,3)
mon1.write("Number of Control rods in reactor? "..numOfContRod)
mon1.setCursorPos(10,4)
mon1.write("Fuel use per Tick: "..fuelUsed)
mon1.setCursorPos(10,5)
mon1.write("Power Stored: "..powerStore)
mon1.setCursorPos(10,6)
mon1.write("Power Use vs Power Created: "..lastPowerStore)
mon1.setCursorPos(10,7)
mon1.write("Energy p/tic: "..energyProd)
mon1.setCursorPos(10,8)
mon1.write("RF energy per second: "..perSec)
mon1.setCursorPos(10,9)
mon1.write("Fuel reactivity: "..fuelReact)
end

function clearScr()
mon1.clear()
mon2.clear()
mon3.clear()
mon4.clear()
mon5.clear()
end

function automation()
basicValues()
reactor.setAllControlRodLevels(hardLimit)
while true do
rodLevels()
tempCheck()
fuelCheck()
logic()
mainScrOut()
sleep(1)
clearScr()
runtime = runtime+1
term.clear()
print("current uptime of automation program: "..runtime)
print("number of error seconds: "..errors)
end
end

automation()