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

dieselfuelonly

Members
  • Content Count

    2
  • Joined

  • Last visited

Posts posted by dieselfuelonly

  1. 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

     

     

  2. So I've been trying to write a program that can find unstackable/limited-stackability items within my AE2 network and export them to a different location.  From a lot of playing around with adapter blocks and looking the the documentation when connected to various AE2 components I've found that I can use getItemsInNetwork() function when connecting an Adapter Block to an ME Controller on a network.

    local component = require("component")
    local ser = require("serialization")
    
    contents = component.proxy(component.list("mekanism")()).getItemsInNetwork()
    
    for _,v in pairs(contents) do
        if not tonumber(v) then
            if v.hasTag or v.maxSize < 16 then
                print(v.name)
            end
        end
    end
    
    file = io.open("contents", "w")
    file:write(ser.serialize(contents))
    file:close()
    

    The little program above finds items with NBT tags or a stack size of less than 16, and prints out the names of these items.  I was writing the table to a file as well just so I could have a better understanding of what information was contained within the item tables.

     

    And yes, for some odd reason the ME Controller is referenced as a Mekanism block when connected to the Adapter block... lol.  No idea why.

     

    Now, comes the part I'm stuck at, and which appears may not be possible - but maybe I'm just missing something:

     

    In order to move items I would need to use an adapter block connected to an ME export bus.  The function used to set the configuration of the ME export bus needs a database entry containing the item I want the export.

     

    The only way that I can find to write information to a database is by using the Inventory Controller module. And it appears that the store() function needs physical access to the item (whether in a robot slot, or in an inventory slot connected through an adapter/inv. controller when using a computer) in order to be able to create the database entry.  Since I'm only able to pull a table with information about the items from the ME network, but not physically access the items to be able to use the store() function on, I can't seem to get anywhere.

     

    Am I missing something or is it just not possible to do what I'm trying to accomplish?

     

     

×
×
  • Create New...

Important Information

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