Add energy storage charge detector

This commit is contained in:
Joachim Stolberg 2023-05-17 22:02:10 +02:00
parent dac5872e8c
commit 0f7814034d
15 changed files with 301 additions and 5 deletions

View File

@ -245,4 +245,4 @@ minetest.register_on_mods_loaded(function()
if not minetest.global_exists("hyperloop") then
minetest.clear_craft({output = "techage:ta5_hl_chest"})
end
end)
end)

View File

@ -204,6 +204,7 @@ techage.Items = {
ta4_terminal = "techage:terminal3",
ta4_autocrafter = "techage:ta4_autocrafter_pas",
ta4_recipeblock = "techage:ta4_recipeblock",
ta4_chargedetector = "techage:ta4_chargedetector_off",
----------------------------
techage_ta5 = "techage:ta5_fr_nucleus",
ta5_flycontroller = "techage:ta5_flycontroller",

View File

@ -192,6 +192,7 @@ techage.manual_DE.aTitel = {
"3,TA4 Spieler Detektor / Player Detector",
"3,TA4 Zustandssammler / State Collector",
"3,TA4 Detektor / Detector",
"3,TA4 Energiespeicher-Ladungsdetektor / Energy Storage Charge Detector",
"3,TA4 Sequenzer",
"2,Move/Dreh-Controller",
"3,TA4 Move Controller",
@ -1690,6 +1691,14 @@ techage.manual_DE.aText = {
"\n"..
"\n"..
"\n",
"Der Ladungsdetektor misst alle 8 s den Ladezustand des Energiespeichers des Stromnetzwerkes.\n"..
"\n"..
"Fällt der Wert unter eine konfigurierbare Schwelle (Schaltpunkt)\\, wird ein Kommando (default: \"off\") versendet. Steigt der Wert wieder über diesen Schaltpunkt\\, so wird ein zweites Kommando (default: \"on\") gesendet. Damit lassen sich Verbraucher vom Netz trennen\\, wenn der Ladezustand des Energiespeichers unter den angegebenen Schaltpunkt sinkt.\n"..
"\n"..
"Der Ladungsdetektor muss dazu über eine Verteilerdose an das Stromnetz angeschlossen werden. Die Konfiguration des Ladungsdetektors erfolgt über das Gabelschlüsselmenü.\n"..
"\n"..
"\n"..
"\n",
"über den TA4 Sequenzer können ganze Abläufe programmiert werden. Hier ein Beispiel:\n"..
"\n"..
" -- this is a comment\n"..
@ -2366,6 +2375,7 @@ techage.manual_DE.aItemName = {
"ta4_playerdetector",
"ta4_collector",
"ta4_detector",
"ta4_chargedetector",
"ta4_sequencer",
"",
"ta4_movecontroller",
@ -2631,6 +2641,7 @@ techage.manual_DE.aPlanTable = {
"",
"",
"",
"",
"ta4_liquid_filter_base",
"ta4_liquid_filter_gravel",
"ta4_liquid_filter_top",

View File

@ -194,6 +194,7 @@ techage.manual_EN.aTitel = {
"3,TA4 Player Detector",
"3,TA4 State Collector",
"3,TA4 Detector",
"3,TA4 Energy Storage Charge Detector",
"3,TA4 Sequencer",
"2,Move/Turn Controller",
"3,TA4 Move Controller",
@ -1698,6 +1699,14 @@ techage.manual_EN.aText = {
"\n"..
"\n"..
"\n",
"The charge detector measures the state of charge of the power grid's energy storage every 8 s.\n"..
"\n"..
"If the value falls below a configurable threshold (switching point)\\, a command (default: \"off\") is sent. If the value rises above this switching point again\\, a second command (default: \"on\") is sent. This allows consumers to be disconnected from the grid when the charge level of the energy storage device falls below the specified switching point.\n"..
"\n"..
"To do this\\, the charge detector must be connected to the grid via a junction box. The charge detector is configured via the open-end wrench menu.\n"..
"\n"..
"\n"..
"\n",
"Entire processes can be programmed using the TA4 sequencer. Here's an example:\n"..
"\n"..
" -- this is a comment\n"..
@ -2375,6 +2384,7 @@ techage.manual_EN.aItemName = {
"ta4_playerdetector",
"ta4_collector",
"ta4_detector",
"ta4_chargedetector",
"ta4_sequencer",
"",
"ta4_movecontroller",
@ -2641,6 +2651,7 @@ techage.manual_EN.aPlanTable = {
"",
"",
"",
"",
"ta4_liquid_filter_base",
"ta4_liquid_filter_gravel",
"ta4_liquid_filter_top",

View File

@ -292,6 +292,7 @@ dofile(MP.."/logic/light_detector.lua")
dofile(MP.."/logic/player_detector.lua")
dofile(MP.."/logic/mba_detector.lua")
dofile(MP.."/logic/cart_detector.lua")
dofile(MP.."/logic/charge_detector.lua")
dofile(MP.."/logic/collector.lua")
dofile(MP.."/logic/button_2x.lua")
dofile(MP.."/logic/button_4x.lua")

View File

@ -133,6 +133,7 @@ Type=Typ
### button.lua ###
### button_2x.lua ###
### button_4x.lua ###
### charge_detector.lua ###
### player_detector.lua ###
Command=Kommando
@ -174,6 +175,7 @@ Momentary button or on/off switch=Taster oder Ein-/Ausschalter
### button_2x.lua ###
### button_4x.lua ###
### charge_detector.lua ###
### player_detector.lua ###
Destination block number=Zielblocknummer
@ -225,6 +227,14 @@ TA5 Ceramic Turbine=TA5 Keramikturbine
Dirt with Ash=Erde mit Asche
TA1 Charcoal=TA1 Holzkohle
### charge_detector.lua ###
Command to send when the energy storage charge@nlevel falls below the specified switch point=Befehl zum Senden, wenn der Ladezustand des@nEnergiespeichers den angegebenen Schaltpunkt unterschreitet
Command to send when the energy storage charge@nlevel rises above the specified switch point=Befehl zum Senden, wenn der Ladezustand des@nEnergiespeichers den angegebenen Schaltpunkt überschreitet
Storage charge level switch point=Schaltpunkt Speicherladezustand
Switch point=Schaltpunkt
TA4 Energy Storage Charge Detector=TA4 Energiespeicher-Ladungsdetektor
### chest.lua ###
Allow public access to the chest=Erlaube öffentlichen Zugriff auf die Kiste
@ -498,8 +508,10 @@ Error: Invalid path !!=Fehler: Ungültiger Pfad !!
Error: Recording is missing !!=Fehler: Aufzeichnung fehlt !!
Flight route (A to B)=Flug Route (A nach B)
Move a player without moving blocks=Bewege einen Spieler ohne Blöcke
See chat output=Siehe chat Ausgabe
TA5 Fly Controller=TA5 Flug Controller
Teleport mode=Teleport Mode
Test=Test
[TA4 Fly Controller] Invalid path!=[TA5 Flug Controller] Ungültiger Pfad!
[TA4 Fly Controller] Recording is missing!=[TA5 Flug Controller] Aufzeichnung fehlt!
@ -520,11 +532,9 @@ Maximum speed for moving blocks=Maximale Geschwindigkeit für bewegliche Blöcke
Move=Bewege
Move A-B=Bewege A-B
Move B-A=Bewege B-A
Move a player without moving blocks=Bewege einen Spieler ohne Blöcke
Move block height=Move Block Höhe
Object offset=Objekt Offset
Stored=Gespeichert
Teleport mode=Teleport Mode
Value in the range of 0.0 to 1.0=Wert im Bereich von 0.0 bis 1.0
Y-offset for non-player objects like vehicles (-0.5 to 0.5)=Y-Offset für Nicht-Spieler Objekte wie Fahrzeuge (-0.5 bis 0.5)

View File

@ -133,6 +133,7 @@ Type=
### button.lua ###
### button_2x.lua ###
### button_4x.lua ###
### charge_detector.lua ###
### player_detector.lua ###
Command=
@ -174,6 +175,7 @@ Momentary button or on/off switch=
### button_2x.lua ###
### button_4x.lua ###
### charge_detector.lua ###
### player_detector.lua ###
Destination block number=
@ -225,6 +227,14 @@ TA5 Ceramic Turbine=
Dirt with Ash=
TA1 Charcoal=
### charge_detector.lua ###
Command to send when the energy storage charge@nlevel falls below the specified switch point=
Command to send when the energy storage charge@nlevel rises above the specified switch point=
Storage charge level switch point=
Switch point=
TA4 Energy Storage Charge Detector=
### chest.lua ###
Allow public access to the chest=
@ -498,8 +508,10 @@ Error: Invalid path !!=
Error: Recording is missing !!=
Flight route (A to B)=
Move a player without moving blocks=
See chat output=
TA5 Fly Controller=
Teleport mode=
Test=
[TA4 Fly Controller] Invalid path!=
[TA4 Fly Controller] Recording is missing!=
@ -520,11 +532,9 @@ Maximum speed for moving blocks=
Move=
Move A-B=
Move B-A=
Move a player without moving blocks=
Move block height=
Object offset=
Stored=
Teleport mode=
Value in the range of 0.0 to 1.0=
Y-offset for non-player objects like vehicles (-0.5 to 0.5)=

231
logic/charge_detector.lua Normal file
View File

@ -0,0 +1,231 @@
--[[
TechAge
=======
Copyright (C) 2019-2023 Joachim Stolberg
AGPL v3
See LICENSE.txt for more information
TA4 Energy storage charge detector
]]--
-- for lazy programmers
local M = minetest.get_meta
local S = techage.S
local Cable = techage.ElectricCable
local power = networks.power
local logic = techage.logic
local CYCLE_TIME = 8
local DESCR = S("TA4 Energy Storage Charge Detector")
local WRENCH_MENU = {
{
type = "numbers",
name = "numbers",
label = S("Number"),
tooltip = S("Destination block number"),
default = "",
check = techage.check_numbers,
},
{
type = "dropdown",
choices = "10%,20%,30%,40%,50%,60%,70%,80%,90%",
name = "switch_point",
label = S("Switch point"),
tooltip = S("Storage charge level switch point"),
default = "50",
values = {10, 20, 30, 40, 50, 60, 70, 80, 90}
},
{
type = "ascii",
name = "command1",
label = '"<" ' .. S("Command"),
tooltip = S("Command to send when the energy storage charge\nlevel falls below the specified switch point"),
default = "off",
},
{
type = "ascii",
name = "command2",
label = '">" ' .. S("Command"),
tooltip = S("Command to send when the energy storage charge\nlevel rises above the specified switch point"),
default = "on",
},
}
local function switch_on(pos)
if logic.swap_node(pos, "techage:ta4_chargedetector_on") then
logic.send_cmnd(pos, "command2", "on")
end
end
local function switch_off(pos)
if logic.swap_node(pos, "techage:ta4_chargedetector_off") then
logic.send_cmnd(pos, "command1", "off")
end
end
local function switch_point(pos)
local mem = techage.get_mem(pos)
if not mem.switch_point then
mem.switch_point = tonumber(M(pos):get_string("switch_point")) or 50
end
return mem.switch_point
end
local function above_switch_point(pos)
local outdir = M(pos):get_int("outdir")
local value = networks.power.get_storage_percent(pos, Cable, outdir)
return value > switch_point(pos)
end
local function techage_set_numbers(pos, numbers, player_name)
local res = logic.set_numbers(pos, numbers, player_name, DESCR)
return res
end
local function after_dig_node(pos, oldnode, oldmetadata, digger)
techage.remove_node(pos, oldnode, oldmetadata)
techage.del_mem(pos)
end
local function ta_after_formspec(pos, fields, playername)
local mem = techage.get_mem(pos)
mem.switch_point = nil
end
minetest.register_node("techage:ta4_chargedetector_off", {
description = DESCR,
inventory_image = 'techage_charge_detector_inv.png',
tiles = {
-- up, down, right, left, back, front
"techage_smartline.png",
"techage_smartline.png",
"techage_smartline.png",
"techage_smartline.png",
"techage_smartline.png",
"techage_smartline.png^techage_charge_detector_off.png",
},
drawtype = "nodebox",
node_box = {
type = "fixed",
fixed = {
{ -6/32, -6/32, 14/32, 6/32, 6/32, 16/32},
},
},
after_place_node = function(pos, placer)
local meta = M(pos)
logic.after_place_node(pos, placer, "techage:ta4_chargedetector_off", DESCR)
logic.infotext(meta, DESCR)
M(pos):set_int("outdir", networks.side_to_outdir(pos, "B"))
Cable:after_place_node(pos)
minetest.get_node_timer(pos):start(CYCLE_TIME)
end,
on_timer = function (pos, elapsed)
if not above_switch_point(pos) then
switch_on(pos)
end
return true
end,
techage_set_numbers = techage_set_numbers,
after_dig_node = after_dig_node,
ta_after_formspec = ta_after_formspec,
ta4_formspec = WRENCH_MENU,
paramtype = "light",
sunlight_propagates = true,
paramtype2 = "facedir",
groups = {choppy=2, cracky=2, crumbly=2},
is_ground_content = false,
sounds = default.node_sound_metal_defaults(),
})
minetest.register_node("techage:ta4_chargedetector_on", {
description = DESCR,
inventory_image = 'techage_charge_detector_inv.png',
tiles = {
-- up, down, right, left, back, front
"techage_smartline.png",
"techage_smartline.png",
"techage_smartline.png",
"techage_smartline.png",
"techage_smartline.png",
"techage_smartline.png^techage_charge_detector_on.png",
},
drawtype = "nodebox",
node_box = {
type = "fixed",
fixed = {
{ -6/32, -6/32, 14/32, 6/32, 6/32, 16/32},
},
},
on_timer = function (pos, elapsed)
if above_switch_point(pos) then
switch_off(pos)
end
return true
end,
techage_set_numbers = techage_set_numbers,
after_dig_node = after_dig_node,
ta_after_formspec = ta_after_formspec,
ta4_formspec = WRENCH_MENU,
paramtype = "light",
sunlight_propagates = true,
paramtype2 = "facedir",
groups = {choppy=2, cracky=2, crumbly=2, not_in_creative_inventory=1},
is_ground_content = false,
sounds = default.node_sound_metal_defaults(),
drop = "techage:ta4_chargedetector_off"
})
minetest.register_craft({
output = "techage:ta4_chargedetector_off",
recipe = {
{"", "", ""},
{"basic_materials:plastic_sheet", "dye:blue", "techage:aluminum"},
{"techage:ta4_wlanchip", "techage:electric_cableS", "default:copper_ingot"},
},
})
techage.register_node({
"techage:ta4_chargedetector_off", "techage:ta4_chargedetector_on"
}, {
on_recv_message = function(pos, src, topic, payload)
if topic == "state" then
local node = techage.get_node_lvm(pos)
if node.name == "techage:ta4_chargedetector_on" then
return "on"
else
return "off"
end
else
return "unsupported"
end
end,
on_beduino_request_data = function(pos, src, topic, payload)
if topic == 142 then -- Binary State
local node = techage.get_node_lvm(pos)
if node.name == "techage:ta4_chargedetector_on" then
return 0, {1}
else
return 0, {0}
end
else
return 2, ""
end
end,
on_node_load = function(pos)
minetest.get_node_timer(pos):start(CYCLE_TIME)
end,
}
)
power.register_nodes({"techage:ta4_chargedetector_off", "techage:ta4_chargedetector_on"}, Cable, "con", {"B"})

View File

@ -534,6 +534,15 @@ Diesen Zähler kann man über das Kommando 'count' abfragen und über 'reset' zu
[ta4_detector|image]
### TA4 Energiespeicher-Ladungsdetektor / Energy Storage Charge Detector
Der Ladungsdetektor misst alle 8 s den Ladezustand des Energiespeichers des Stromnetzwerkes.
Fällt der Wert unter eine konfigurierbare Schwelle (Schaltpunkt), wird ein Kommando (default: "off") versendet. Steigt der Wert wieder über diesen Schaltpunkt, so wird ein zweites Kommando (default: "on") gesendet. Damit lassen sich Verbraucher vom Netz trennen, wenn der Ladezustand des Energiespeichers unter den angegebenen Schaltpunkt sinkt.
Der Ladungsdetektor muss dazu über eine Verteilerdose an das Stromnetz angeschlossen werden. Die Konfiguration des Ladungsdetektors erfolgt über das Gabelschlüsselmenü.
[ta4_chargedetector|image]
### TA4 Sequenzer

View File

@ -525,6 +525,16 @@ This counter can be queried with the 'count' command and reset with 'reset'.
[ta4_detector|image]
### TA4 Energy Storage Charge Detector
The charge detector measures the state of charge of the power grid's energy storage every 8 s.
If the value falls below a configurable threshold (switching point), a command (default: "off") is sent. If the value rises above this switching point again, a second command (default: "on") is sent. This allows consumers to be disconnected from the grid when the charge level of the energy storage device falls below the specified switching point.
To do this, the charge detector must be connected to the grid via a junction box. The charge detector is configured via the open-end wrench menu.
[ta4_chargedetector|image]
### TA4 Sequencer
Entire processes can be programmed using the TA4 sequencer. Here's an example:

View File

@ -191,6 +191,7 @@
- [TA4 Spieler Detektor / Player Detector](./manual_ta4_DE.md#ta4-spieler-detektor--player-detector)
- [TA4 Zustandssammler / State Collector](./manual_ta4_DE.md#ta4-zustandssammler--state-collector)
- [TA4 Detektor / Detector](./manual_ta4_DE.md#ta4-detektor--detector)
- [TA4 Energiespeicher-Ladungsdetektor / Energy Storage Charge Detector](./manual_ta4_DE.md#ta4-energiespeicher-ladungsdetektor--energy-storage-charge-detector)
- [TA4 Sequenzer](./manual_ta4_DE.md#ta4-sequenzer)
- [Move/Dreh-Controller](./manual_ta4_DE.md#movedreh-controller)
- [TA4 Move Controller](./manual_ta4_DE.md#ta4-move-controller)

View File

@ -193,6 +193,7 @@
- [TA4 Player Detector](./manual_ta4_EN.md#ta4-player-detector)
- [TA4 State Collector](./manual_ta4_EN.md#ta4-state-collector)
- [TA4 Detector](./manual_ta4_EN.md#ta4-detector)
- [TA4 Energy Storage Charge Detector](./manual_ta4_EN.md#ta4-energy-storage-charge-detector)
- [TA4 Sequencer](./manual_ta4_EN.md#ta4-sequencer)
- [Move/Turn Controller](./manual_ta4_EN.md#moveturn-controller)
- [TA4 Move Controller](./manual_ta4_EN.md#ta4-move-controller)

Binary file not shown.

After

Width:  |  Height:  |  Size: 248 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 175 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 176 B