[CC][TE3] Get energy conduit output

  • The FTB Forum is now read-only, and is here as an archive. To participate in our community discussions, please join our Discord! https://ftb.team/discord

kaovalin

New Member
Jul 29, 2019
782
0
0
Basically I want to make the computercraft computer read the conduit collar and tell me what the output in RF/t is. I could calculate it as a Net gain/loss from a buffer energy cell but I'd rather get it strait from the horses mouth so to speak.

My plan is to actually use CC as part of my energy management solution this time around. Going to have it read all 16 resonant energy cells and wirelessly transmit the % to a monitor in my main storage room for some fancy bars and energy usage trend information. This particular element pertains to analyzing the usage history (like the CPU % monitor). My control room must have many numbers, figures, and if I can manage it, pie charts.
 

Platinawolf

New Member
Jul 29, 2019
147
0
0
Afaik the energy conduits don't really have that data. You probably would have to map every single connection ^^* Easiest is probably to do a DX/DY on the energy cells but then we have the issue of accurate timekeeping...
I do something similar to you, though I use wired modems and I have 33 energy cells (With capacity of 50 cells without modifying the code/monitor) ^^* Monitor is 2 wide and 4 high. Behind the computer I have a BigReactor computer-port and to the left I have a item conduit to turn off my mining well system (Think similar to what Direwolf20 has in his letsplay but 3 times as wide and a cycle time of 4.05 seconds). Perhaps you can utilize my code for something?

And if you do find a way to get the energy usage out of the conduits, do tell how well it works :)

Code:
function sortByEnergy(x, y)
  return x.energy > y.energy
end

function check (level, heat)
    reactor.setAllControlRodLevels(level)
    while (reactor.getFuelTemperature() < heat) do
        energy()
        if (percentage<5) then
            rs.setOutput("left", true)
            sleep(1)
            rs.setOutput("left",false)
        elseif(percentage>99) then
            heat=0
        else
            sleep(1)
        end  
    end  
    print (reactor.getFuelTemperature())
    reactor.setAllControlRodLevels(100)
end

function percentageColor(percent)
    monitor.setBackgroundColor(colors.green)
    if (percent<50) then
        monitor.setBackgroundColor(colors.orange)
        if (percent<25) then
            monitor.setBackgroundColor(colors.red)
        end
    end  

end

function spaceadder(oldString,desiredLength)
    lengthToAdd = desiredLength-string.len(oldString)
    return oldString..string.rep(" ",lengthToAdd)
end

function spaceadderBefore(oldString,desiredLength)
    lengthToAdd = desiredLength-string.len(oldString)
    return string.rep(" ",lengthToAdd)..oldString
end
  
function monitorlinemaker(outstringpart2,outstringpart3)
    return spaceadderBefore(outstringpart2,3).."%"..spaceadderBefore(outstringpart3,32)
end


  
function shift(value)
    for var = 0,numberOfCells-2,1 do
        oldPower[var] = oldPower[var+1]
    end  
    oldPower[numberOfCells-1] = value
end  

function energy ()
    totalEnergy = 0
  
    for var = 1, tablesize, 1 do
        Table[var].energy = Table[var].getEnergyStored("RF")
        Table[var].percentage = math.floor(Table[var].energy/energyPerCell*100+0,5)
        totalEnergy = totalEnergy + Table[var].energy
        sleep(0,05)
    end  
    table.sort(Table, sortByEnergy)
    for var = 1, tablesize, 1 do
        write(var)
    end  
    updateTotal()
end

function write(var)
    monitorPos = var
    outstringpart1 = tostring(monitorPos)
    outstringpart2 = tostring(Table[var].percentage)
    outstringpart3 = tostring(Table[var].energy)
    outstring = monitorlinemaker(outstringpart2,outstringpart3)
    monitor.setCursorPos(1,monitorPos)
    percentageColor(Table[var].percentage)
    monitor.write(outstring)
end  

function updateTotal()
    percentage = totalEnergy*100/numberOfCells/energyPerCell
    outstringpart1="ALL"
    outstringpart2=math.floor(percentage+0,5)
    outstringpart3=tostring(totalEnergy)
    outstring = monitorlinemaker(outstringpart2,outstringpart3)
    monitor.setCursorPos(1,51)
    percentageColor(percentage)
    monitor.write(outstring)
    print(outstringpart3)
    monitor.setBackgroundColor(colors.black)
end  

function makeTable()
    periList = peripheral.getNames()
    numberOfCells=0
    for i = 1, #periList do
        if ((peripheral.getType(periList[i]) == "cofh_thermalexpansion_energycell")) then
            numberOfCells = numberOfCells+1
            Table[numberOfCells] = peripheral.wrap(periList[i])
        end      
    end  
    tablesize = #Table
    energyPerCell = Table[1].getMaxEnergyStored("RF")
    print(numberOfCells.." cells detected")
    sleep(0.05)
end  
function reactorLineMaker(bool)
        if bool then
            status ="ON "
        else
            status ="OFF"
        end
    return ("Reactor :"..string.rep(" ",24)..status)
end


function monitorReactorOff()
    monitor.setCursorPos(1 ,52)
    monitor.setBackgroundColor(colors.black)
    reactorOutString = reactorLineMaker(false)
    monitor.write(reactorOutString)
end
function monitorReactorOn()
    monitor.setCursorPos(1,52)
    monitor.setBackgroundColor(colors.magenta)
    reactorOutString = reactorLineMaker(true)
    monitor.write(reactorOutString)
end

function startReactor()
    monitorReactorOn()
    check(0,1000)
    monitorReactorOff()
end

rs.setOutput("left", true)
monitor = peripheral.wrap("monitor_0")
monitor.setTextScale(0.5)
Table = {}  
numberOfCells = 0
makeTable()
reactor = peripheral.wrap('back')
reactor.setAllControlRodLevels(100)
monitorReactorOff()
t=0
rs.setOutput("left",false)

while true do  
    energy()
    if(percentage < 25) then
        startReactor()
    end
    sleep(1)
end
 

kaovalin

New Member
Jul 29, 2019
782
0
0
Well I plan to map trends in my average energy usage sortve like a CPU monitor so I dont think the frequency has to be too accurate because the numbers are big enough to hide math impreciseness. Maybe I can find a way to read the GMT time somewhere and compare that way to avoid the whole issue. Separate timekeeper computer maybe?

I think we will end up with similar setups. When I finish I may feel proud enough (without good reason) to post it to the showcase section. Essentially its going to be a cake/netherstar powered base cause reasons. The extrautil generators dont play nice with filled generator buffers in that they dont stop using the fuel when this happens so energy is wasted. If the buffer is completely full and not emptying it wont use an additional piece of fuel when the timer for the last fuel runs out, but I dont want to waste anything if possible so I want to nip it in the bud with some CC magic.

Netherstars will be an emergency backup energy that can kick in if I throw down all my digital miners at once. Got a reactor room planned for it since there is a range that they dmg players when running. Much nicer to deal with than radiation, but still hurts.

Big reactors is a mod I'm adding to my server soon so I may revisit your code to reference it.

Btw I have a question about your function percentageColor(); What's the reasoning behind having the if statements nested like that? I would think you would want if else to ensure the colors arent being applied between lines in the code. Wouldnt notice on green, but orange and especially red could lead to color flickering no?
 

Platinawolf

New Member
Jul 29, 2019
147
0
0
The percentage code is comparativly old and doesn't take much resources. But the logic is equivalent to

if percentage > 50 then
green line
else if percentage > 25 then
orange line
else
red line

Flickering wouldn't occur as a percentage can either be above 25% or below 25%, it can't be both. And as power generation is either massive or nil there won't be any cases where it flickers between 24.9% and 25.1%.

My code is assuming your using identical energy cell types to simplify calculations. As for adapting my code for usage for Netherstar nommers just check that the total energy is below (total energy-the energy one netherstar generates). If I recall correctly from direwolf20 that's 2x resonant energy cells.
 
Last edited:

kaovalin

New Member
Jul 29, 2019
782
0
0
From what I can tell your code is saying
Make green
If less than 50 make orange
If less than 25 make red

Which means at 20% it will make it green, then orange, then red. If you had things other than color changes that could affect later outcomes this distinction would be a lot more important. Its outcome in your special case is the same, but its not equivalent.

EDIT: Additionally I have my cell stack pumping downwards in order to allow me to simplify the readings. As in the top cell constantly tries to fill the one lower than it and so on. Created its own power meter for a time, but I need something to read the whole power core now. Code wise it will read cells until it finds one that is full then itl assume everything below is full because it should be based on my config. Might actually be more trouble than its worth programming wise but we shall see. Definitely will require a matrix instead of a table to assess the power levels I'm thinking.
 

Platinawolf

New Member
Jul 29, 2019
147
0
0
If you just use resonant cells you can store the max power-level in a variable once and then re-use it. The current energylevel you could store in the same table as the one created by peripheral.wrap().

Question is what order and what namings the cells have. My method of doing it might be a tad bloated but its simple and doesn't rely on that the cells are in a specific order. It does however mean that I don't have any control over what name each cell has but as I sort my list after the energy they hold (integer sorting is really easy for computers to do, especially for such a small list) that isn't an issue for me. However, the overhead needed to check if a cell is full or not before checking the cells afterwards might cost you more than it gains you.

As for finding out your entire powerlevel thats rather trivial. I do it by summing the individual power-levels up while I'm checking the status of each cell in the energy() function. Thats the simplest method available.
Alternative solution would be to multiply the max energy a cell can store by the number of cells you haven't checked and adding the energy value of the cells you already checked.

As for my percentage thing, I could just as well have made it set a variable to colors.green/orange/red and then set the monitor color. But its an old part of the code that works as it should and if I flipped the if statements I'd have to change the %-values to 49 and 24 respectively to get it to do what I want (green at 50% and above, orange between 25% and 49% and red at 0 to 24%) as I'm working with integers and not floats.

Logically the two different ways to set it up is equivalent because they both produce the same outputs from the same inputs. Ofcourse if you have to deal with side-effects then the two different methods of doing it stops being equivalent as you say. But as the code is set up with the functions sole function to set the color of the monitor to match the number its given, they are equivalent.

EDIT:

Tried changing my pile of energy cells to toss energy down like your planning and something strange happened about half-way with one energy-cell being next to empty compared to the one above and below. Might be some TE optimization algorithm spooking as I'm now running with 50 cells ^^*
 
Last edited: