A little background - I'm using Rotarycraft for power generation and am using OC to control engine control units connected to the engines themselves. The ECU lets me throttle the engine in 4 stages - 1/16th, 1/4, 1/2, and full power.
I have two engines powering my AE network - I use an adapter connected to the ME controller along with the getAvgPowerUsage() function to get the energy use of the AE network, then the program throttles the engines accordingly depending on how much power is needed to run the network - it works great, with the program selecting a throttle setting that produces the most minimal excess of power generation possible.
I'm trying to do something similar with RF. I'm using the RF Battery from ElectriCraft which has only two real useful functions that return the current RF stored in the battery, and the maximum amount of RF stored in the battery.
The problem I'm running into is how to accurately measure the amount of RF being used and adjusting the engines accordingly. Right now my program (messy and incomplete, see bottom) reads the change in stored energy in the battery every 5 seconds, and then attempts to adjust the throttles on the engine to produce an output value closer to keeping the battery at a just above "neutral" state.
What happens is it gets stuck in the cycle of producing too much power, throttling way down, sensing it's not producing enough power, returning the engines to maximum power, and repeating over and over. I've tried waiting for longer periods of time before changing the throttles on the engines, but this doesn't seem to smooth things out much. It's especially exaggerated because the engines don't immediately change from one power state to the other, instead they will smoothly wind up or down to reach the set power state.
The only other idea that I've had would be to find a way to cut the power input to the battery completely, then take two measurements 5 seconds apart to determine the power running out of the battery, and THEN set the engines to produce a slight excess of power. I can see this working, as it basically works just like my AE power program, where it has a defined energy target to produce and selects what ever throttle levels let it meet or exceed that target. However, it would be messy and a waste of very expensive ways to do that, so I was wondering if there were some other ideas?
Thanks
local component =require("component")local computer =require("computer")local math =require("math")local term =require("term")localevent=require("event")local running =true--Addresses of EngineControlUnitslocal ecuAddress ={"cd1ae864-e5aa-42b0-abfc-d7134e5da40f","b12af19b-3357-43c6-99a5-287a0f21256d","fa2cbaa6-776c-4f75-baaa-e740e64fb765","27a756ad-8b67-4551-85d0-8a654b96f5e1"}--Address of RF Battery(will find automatically bydefault)local batAddress = component.list("RFBattery")()--Maximum power output of one generation unit in RF
local maxOutput =129052--Create ECU ProxyTable(contains component proxy, engine state,and RF output values per engine state)local ecu ={}for i =1,#ecuAddress do
ecu[component.proxy(ecuAddress[i])]={
curState =0,
stateOpt ={
maxOutput /16,
maxOutput /4,
maxOutput /2,
maxOutput
}}end--Create RF BatteryProxyTable(contains component proxy,Last RF Value,LastTick,Current RF Value,andStoragePercent)local bat ={
proxy = component.proxy(batAddress),
lastRF =0,
curRF =0,
curTick =0,
lastTick =0,
io =0,
pRF =0}--Sync ECU Stateand stored state to full power
for proxy, _ in pairs(ecu)do
proxy.setECU(4)
ecu[proxy].state =4end--Shutdownfunctionfunction shutDown()
running =false
term.clear()returnfalseend--Press any key to stop
event.listen("key_down", shutDown)--Function to get current tick since startup
function tick()local t =(computer.uptime()*20)return t
end--Function to set ECU state and update current state
function ecuCon(proxy, state)
proxy.setECU(state)
ecu[proxy].curState = state
end--Returns I/O rate of RF to/from RF Batteryfunction updateBat()
bat.curTick = tick()--For more accuracy we take a reading every 5 seconds
if(bat.curTick - bat.lastTick)>=100then
bat.lastRF = bat.curRF
bat.curRF = bat.proxy.getFullStoredEnergy()
bat.io = math.floor((bat.curRF - bat.lastRF)/(bat.curTick - bat.lastTick))
bat.lastTick = bat.curTick
endreturn bat.io
end--[[for proxy, _ in pairs(ecu)do
ecuCon(proxy,4)end]]--while running do
term.clear()local rfProd = updateBat()print(rfProd)for proxy, _ in pairs(ecu)doif rfProd <0thenfor state, output in ipairs(ecu[proxy].stateOpt)doif rfProd - output >0then
ecuCon(proxy, state)else
ecuCon(proxy,4)endend
elseif rfProd >0thenfor state, output in ipairs(ecu[proxy].stateOpt)doif output - rfProd >0then
ecuCon(proxy, state)else
ecuCon(proxy,1)endend
rfProd = rfProd - ecu[proxy].stateOpt[ecu[proxy].curState]endprint(ecu[proxy].curState)end
os.sleep(1)end
You can post now and register later.
If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.
I need some ideas on measuring RF usage.
A little background - I'm using Rotarycraft for power generation and am using OC to control engine control units connected to the engines themselves. The ECU lets me throttle the engine in 4 stages - 1/16th, 1/4, 1/2, and full power.
I have two engines powering my AE network - I use an adapter connected to the ME controller along with the getAvgPowerUsage() function to get the energy use of the AE network, then the program throttles the engines accordingly depending on how much power is needed to run the network - it works great, with the program selecting a throttle setting that produces the most minimal excess of power generation possible.
I'm trying to do something similar with RF. I'm using the RF Battery from ElectriCraft which has only two real useful functions that return the current RF stored in the battery, and the maximum amount of RF stored in the battery.
The problem I'm running into is how to accurately measure the amount of RF being used and adjusting the engines accordingly. Right now my program (messy and incomplete, see bottom) reads the change in stored energy in the battery every 5 seconds, and then attempts to adjust the throttles on the engine to produce an output value closer to keeping the battery at a just above "neutral" state.
What happens is it gets stuck in the cycle of producing too much power, throttling way down, sensing it's not producing enough power, returning the engines to maximum power, and repeating over and over. I've tried waiting for longer periods of time before changing the throttles on the engines, but this doesn't seem to smooth things out much. It's especially exaggerated because the engines don't immediately change from one power state to the other, instead they will smoothly wind up or down to reach the set power state.
The only other idea that I've had would be to find a way to cut the power input to the battery completely, then take two measurements 5 seconds apart to determine the power running out of the battery, and THEN set the engines to produce a slight excess of power. I can see this working, as it basically works just like my AE power program, where it has a defined energy target to produce and selects what ever throttle levels let it meet or exceed that target. However, it would be messy and a waste of very expensive ways to do that, so I was wondering if there were some other ideas?
Thanks
Link to post
Share on other sites