Jump to content
  • Sky
  • Blueberry
  • Slate
  • Blackcurrant
  • Watermelon
  • Strawberry
  • Orange
  • Banana
  • Apple
  • Emerald
  • Chocolate
  • Charcoal
  • 0
dieselfuelonly

Need help finding different ways of measuring RF usage

Question

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

 

 

local component = require("component")
local computer = require("computer")
local math = require("math")
local term = require("term")
local event = require("event")

local running = true


--Addresses of Engine Control Units
local 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 by default)
local batAddress = component.list("RFBattery")()

--Maximum power output of one generation unit in RF
local maxOutput = 129052  

--Create ECU Proxy Table (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 Battery Proxy Table (contains component proxy, Last RF Value, Last Tick, Current RF Value, and Storage Percent)     
local bat = 
{
  proxy = component.proxy(batAddress),
  lastRF = 0,
  curRF = 0,
  curTick = 0,
  lastTick = 0,
  io = 0,
  pRF = 0
}

--Sync ECU State and stored state to full power
for proxy, _ in pairs(ecu) do
  proxy.setECU(4)
  ecu[proxy].state = 4
end

--Shutdown function
function shutDown()
  running = false
  term.clear()
  return false
end

--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 Battery
function updateBat() 
  bat.curTick = tick()
  --For more accuracy we take a reading every 5 seconds 
  if (bat.curTick - bat.lastTick) >= 100 then
    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
  end
  return 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) do
  if rfProd < 0 then
    for state, output in ipairs(ecu[proxy].stateOpt) do
      if rfProd - output > 0 then
        ecuCon(proxy, state)
      else
        ecuCon(proxy, 4)
      end
    end
  elseif rfProd > 0 then
    for state, output in ipairs(ecu[proxy].stateOpt) do
      if output - rfProd > 0 then
        ecuCon(proxy, state)
      else
        ecuCon(proxy, 1)
      end
    end
    rfProd = rfProd - ecu[proxy].stateOpt[ecu[proxy].curState]
  end
  print(ecu[proxy].curState)
end
os.sleep(1)   
end

 

 

Link to post
Share on other sites

1 answer to this question

Recommended Posts

Join the conversation

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.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and Privacy Policy.