From 0f7814034de27c5436238805780766fab64ce8eb Mon Sep 17 00:00:00 2001 From: Joachim Stolberg Date: Wed, 17 May 2023 22:02:10 +0200 Subject: [PATCH] Add energy storage charge detector --- basic_machines/ta5_chest.lua | 2 +- doc/items.lua | 1 + doc/manual_DE.lua | 11 ++ doc/manual_EN.lua | 11 ++ init.lua | 1 + locale/techage.de.tr | 14 +- locale/template.txt | 14 +- logic/charge_detector.lua | 231 +++++++++++++++++++++++ manuals/manual_ta4_DE.md | 9 + manuals/manual_ta4_EN.md | 10 + manuals/toc_DE.md | 1 + manuals/toc_EN.md | 1 + textures/techage_charge_detector_inv.png | Bin 0 -> 248 bytes textures/techage_charge_detector_off.png | Bin 0 -> 175 bytes textures/techage_charge_detector_on.png | Bin 0 -> 176 bytes 15 files changed, 301 insertions(+), 5 deletions(-) create mode 100644 logic/charge_detector.lua create mode 100644 textures/techage_charge_detector_inv.png create mode 100644 textures/techage_charge_detector_off.png create mode 100644 textures/techage_charge_detector_on.png diff --git a/basic_machines/ta5_chest.lua b/basic_machines/ta5_chest.lua index 7165a07..0046ee0 100644 --- a/basic_machines/ta5_chest.lua +++ b/basic_machines/ta5_chest.lua @@ -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) \ No newline at end of file +end) diff --git a/doc/items.lua b/doc/items.lua index fa08dcb..98e9db9 100644 --- a/doc/items.lua +++ b/doc/items.lua @@ -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", diff --git a/doc/manual_DE.lua b/doc/manual_DE.lua index f612db8..a803517 100644 --- a/doc/manual_DE.lua +++ b/doc/manual_DE.lua @@ -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", diff --git a/doc/manual_EN.lua b/doc/manual_EN.lua index 7ac1e38..beb66b0 100644 --- a/doc/manual_EN.lua +++ b/doc/manual_EN.lua @@ -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", diff --git a/init.lua b/init.lua index 5fc377a..313182c 100644 --- a/init.lua +++ b/init.lua @@ -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") diff --git a/locale/techage.de.tr b/locale/techage.de.tr index 597dc14..a94ca5c 100644 --- a/locale/techage.de.tr +++ b/locale/techage.de.tr @@ -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) diff --git a/locale/template.txt b/locale/template.txt index 9f4bee3..e0dc790 100644 --- a/locale/template.txt +++ b/locale/template.txt @@ -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)= diff --git a/logic/charge_detector.lua b/logic/charge_detector.lua new file mode 100644 index 0000000..7fa225e --- /dev/null +++ b/logic/charge_detector.lua @@ -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"}) + diff --git a/manuals/manual_ta4_DE.md b/manuals/manual_ta4_DE.md index d7d6643..b26857e 100644 --- a/manuals/manual_ta4_DE.md +++ b/manuals/manual_ta4_DE.md @@ -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 diff --git a/manuals/manual_ta4_EN.md b/manuals/manual_ta4_EN.md index 6ba5651..a5cb63b 100644 --- a/manuals/manual_ta4_EN.md +++ b/manuals/manual_ta4_EN.md @@ -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: diff --git a/manuals/toc_DE.md b/manuals/toc_DE.md index 8b41dac..9d01b13 100644 --- a/manuals/toc_DE.md +++ b/manuals/toc_DE.md @@ -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) diff --git a/manuals/toc_EN.md b/manuals/toc_EN.md index fdd0398..432465e 100644 --- a/manuals/toc_EN.md +++ b/manuals/toc_EN.md @@ -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) diff --git a/textures/techage_charge_detector_inv.png b/textures/techage_charge_detector_inv.png new file mode 100644 index 0000000000000000000000000000000000000000..93d48f7fcd539ab5a41795748d27dd049427f228 GIT binary patch literal 248 zcmeAS@N?(olHy`uVBq!ia0vp^1|ZDB3?!H8JlO)I_yc@GTpfD0F*7r}%{>19|Nq=| zmx2z=QwK^d@pN$vu{gc<%5B~T1s>K5>n?0yl$Hof_&;+?SjJ1|WG4BhId`s1Qux9b zu>RnA!}#6Oj0;$qAIKIkUvL+g!eh|9xMIcBtOPbQql0cNJ}w7b7}VAXvSzy+7P^>T znsC9=*>gbx+p4Zt&0WcCLWT;0+{Q_XZZXf5AN8{sS16s1{3ymY*L)_^gXtXaZhkdX wQoPW_c=t!skGefhzghQw-pc=vXZHh^LwC1oCeG$N4RkMqr>mdKI;Vst0L|B4djJ3c literal 0 HcmV?d00001 diff --git a/textures/techage_charge_detector_off.png b/textures/techage_charge_detector_off.png new file mode 100644 index 0000000000000000000000000000000000000000..fef26f4d0cd186aeadcba3f5a1dafe7ed9ee1961 GIT binary patch literal 175 zcmeAS@N?(olHy`uVBq!ia0vp^4j|0L3?#3!&-4XSJOMr-uI>ds|NsAIVq#+W&+ubm zv^7wiu_VYZn8D%MjWi%9(9^{+#Nu>vf&?owYlL&70z+himSf}67fjX{S-&mhelx#I z?}JF}1NB`8^m#;sFR}(*WL3JzddMJWW|!WCEzopr0C|Bn7ytkO literal 0 HcmV?d00001 diff --git a/textures/techage_charge_detector_on.png b/textures/techage_charge_detector_on.png new file mode 100644 index 0000000000000000000000000000000000000000..ad2743cace3840b413da8ad56cc18f715a16862a GIT binary patch literal 176 zcmeAS@N?(olHy`uVBq!ia0vp^4j|0L3?#3!&-4XSJOMr-uI>ds|NsAIVq*Hwz;IP| z(h{IJV@Z%-FoVOh8)-mJkf)1dh{fsT1PNAV)(GcD1%}83Eyu>CFPMxkvMx)UVJI4_ z07OEu3S6-YRa(0a1eY|