From c07e7b2c397dc226fd3b6571710daf7df9419ed0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?I=C3=B1igo=20Etxaniz?= Date: Fri, 2 Oct 2026 19:48:14 +0200 Subject: [PATCH] Initial content, migrated from the aml gateway rpi7-am-1 --- README.md | 12 +++++++++++- bar_detection.py | 29 +++++++++++++++++++++++++++++ schedule.yaml | 11 +++++++++++ signals.yml | 4 ++++ 4 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 bar_detection.py create mode 100644 schedule.yaml create mode 100644 signals.yml diff --git a/README.md b/README.md index fb51600..f8be183 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,13 @@ # bar-detection -Detects bars entering and leaving the oven and writes in-detect-oven / out-detect-oven \ No newline at end of file +Runs continuously, once a second. Detects a bar entering the oven on the rising edge of the +entry photocell `Hin` (3) and writes a pulse to `in-detect-oven` (11). Detects a bar leaving +when the reading it calls `THact` crosses above 600 and writes a pulse to `out-detect-oven` +(12). Both outputs are i7state pulse signals, consumed by `bar-tracker`. + +**Known mismatch, kept as it runs today:** `signals.yml` maps id 17 to the name `THact`, but +signal 17 is `THprocess`; the real `THact` is 18. The exit trigger therefore fires on +`THprocess`. Correcting it means changing the id to 18 in `signals.yml` and tagging a new +version. + +Runs in `docker.izazpi.cloud/aml/aml-python`; the version is in `schedule.yaml`. diff --git a/bar_detection.py b/bar_detection.py new file mode 100644 index 0000000..0c3b89a --- /dev/null +++ b/bar_detection.py @@ -0,0 +1,29 @@ +from i7lib.client import run + +prev_hin = 1.0 +prev_thact = 610.0 + + +def logic(plant): + global prev_hin, prev_thact + + hin = plant.state.get("Hin", 0.0) + thact = plant.state.get("THact", 0.0) + + batch = plant.new_write_batch() + + if hin > 0 and prev_hin == 0: + batch.add(signal_id=11, value=1.0, name="in-detect-oven") + + if thact > 600 and prev_thact <= 600: + batch.add(signal_id=12, value=1.0, name="out-detect-oven") + + if batch.payload: + plant.send(batch) + + prev_hin = hin + prev_thact = thact + + +if __name__ == "__main__": + run(logic, interval_ms=1000, offset_ms=100) diff --git a/schedule.yaml b/schedule.yaml new file mode 100644 index 0000000..fe6633b --- /dev/null +++ b/schedule.yaml @@ -0,0 +1,11 @@ +name: bar-detection +active: true +schedule: "* * * * *" +action: ensure +runOnStartup: true +imageName: docker.izazpi.cloud/aml/aml-python:0.1.0 +command: ["python", "/app/bar_detection.py"] +maxCpuCores: 0.5 +maxMemoryMb: 128 +autoremove: false +logOption: 1 diff --git a/signals.yml b/signals.yml new file mode 100644 index 0000000..157e7bb --- /dev/null +++ b/signals.yml @@ -0,0 +1,4 @@ +- { id: 3, name: 'Hin', read: 1, write: 0 } +- { id: 17, name: 'THact', read: 1, write: 0 } +- { id: 11, name: 'in-detect-oven', read: 0, write: 1 } +- { id: 12, name: 'out-detect-oven', read: 0, write: 1 }