From 8b7cc28d92db6af3ceeb824e00f4ba53cffc69e4 Mon Sep 17 00:00:00 2001 From: erlingrj Date: Mon, 14 Oct 2024 18:15:45 -0700 Subject: [PATCH 1/3] Add example programs and a short README --- examples/C/src/tomacs/Consistency.lf | 42 ++++++++++++++++ examples/C/src/tomacs/Feedback.lf | 72 ++++++++++++++++++++++++++++ examples/C/src/tomacs/README.md | 2 + 3 files changed, 116 insertions(+) create mode 100644 examples/C/src/tomacs/Consistency.lf create mode 100644 examples/C/src/tomacs/Feedback.lf create mode 100644 examples/C/src/tomacs/README.md diff --git a/examples/C/src/tomacs/Consistency.lf b/examples/C/src/tomacs/Consistency.lf new file mode 100644 index 00000000..f7ee02bc --- /dev/null +++ b/examples/C/src/tomacs/Consistency.lf @@ -0,0 +1,42 @@ +/** This test has two coupled cycles. In this variant, both are a zero-delay cycles (ZDC). */ +target C { + timeout: 1 sec, + tracing: true +} + +import PhysicalPlant from "Feedback.lf" + +reactor Controller { + input remote_update: double + input local_update: double + output control: double + + state latest_control: double = 0.0 + state first: bool = true + + reaction(local_update, remote_update) {= + =} + + reaction(local_update) -> control {= + =} +} + +reactor Platform { + input update: double + output publish: double + + c = new Controller() + p = new PhysicalPlant() + p.sensor -> c.local_update + p.sensor -> publish + update -> c.remote_update + c.control -> p.control +} + +federated reactor { + p1 = new Platform() + p2 = new Platform() + + p1.publish -> p2.update + p2.publish -> p1.update +} diff --git a/examples/C/src/tomacs/Feedback.lf b/examples/C/src/tomacs/Feedback.lf new file mode 100644 index 00000000..b4c0147b --- /dev/null +++ b/examples/C/src/tomacs/Feedback.lf @@ -0,0 +1,72 @@ +/** This test has two coupled cycles. In this variant, both are a zero-delay cycles (ZDC). */ +target C { + timeout: 1 sec, + tracing: true +} + +reactor PhysicalPlant { + input control: double + output sensor: double + timer t(0, 100 ms) + state last_sensor_time: time = 0 + state previous_sensor_time: time = 0 + state count: int = 0 + + reaction(t) -> sensor {= + lf_set(sensor, 42); + self->previous_sensor_time = self->last_sensor_time; + self->last_sensor_time = lf_time_physical(); + =} + + reaction(control) {= + self->count++; + lf_print("Control input: %f", control->value); + instant_t control_time = lf_time_physical(); + lf_print("Latency: " PRINTF_TIME ".", control_time - self->previous_sensor_time); + lf_print("Logical time: " PRINTF_TIME ".", lf_time_logical_elapsed()); + =} +} + +reactor Planner { + input request: double + output response: double + + reaction(request) -> response {= + lf_sleep(MSEC(10)); + lf_set(response, request->value); + =} +} + +reactor Controller { + input sensor: double + output control: double + + state latest_control: double = 0.0 + state first: bool = true + + output request_for_planning: double + input planning: double + + reaction(sensor) -> control, request_for_planning {= + if (!self->first) { + lf_set(control, self->latest_control); + } + self->first = false; + lf_set(request_for_planning, sensor->value); + =} + + reaction(planning) {= + self->latest_control = planning->value; + =} +} + +federated reactor { + p = new PhysicalPlant() + c = new Controller() + pl = new Planner() + + p.sensor -> c.sensor + c.request_for_planning -> pl.request + pl.response -> c.planning + c.control -> p.control +} diff --git a/examples/C/src/tomacs/README.md b/examples/C/src/tomacs/README.md new file mode 100644 index 00000000..a52351a2 --- /dev/null +++ b/examples/C/src/tomacs/README.md @@ -0,0 +1,2 @@ +# Example LF programs from "Strongly-Consistent Distributed Discrete-Event Systems" +This folder contains the example LF programs found in the publication "Strongly-Consistent Distributed Discrete-Event Systems". \ No newline at end of file From e72086a831bac766fe5eaa0ea5b6d88fd8d000d2 Mon Sep 17 00:00:00 2001 From: erlingrj Date: Thu, 24 Oct 2024 15:08:17 -0700 Subject: [PATCH 2/3] Rename folder and add Beyong-gil's evaluation --- .../C/src/{tomacs => TOMACS}/Consistency.lf | 0 examples/C/src/TOMACS/Evaluation.lf | 38 +++++++++++++++++++ examples/C/src/{tomacs => TOMACS}/Feedback.lf | 0 examples/C/src/{tomacs => TOMACS}/README.md | 3 +- 4 files changed, 40 insertions(+), 1 deletion(-) rename examples/C/src/{tomacs => TOMACS}/Consistency.lf (100%) create mode 100644 examples/C/src/TOMACS/Evaluation.lf rename examples/C/src/{tomacs => TOMACS}/Feedback.lf (100%) rename examples/C/src/{tomacs => TOMACS}/README.md (69%) diff --git a/examples/C/src/tomacs/Consistency.lf b/examples/C/src/TOMACS/Consistency.lf similarity index 100% rename from examples/C/src/tomacs/Consistency.lf rename to examples/C/src/TOMACS/Consistency.lf diff --git a/examples/C/src/TOMACS/Evaluation.lf b/examples/C/src/TOMACS/Evaluation.lf new file mode 100644 index 00000000..b06ab369 --- /dev/null +++ b/examples/C/src/TOMACS/Evaluation.lf @@ -0,0 +1,38 @@ +target C { + timeout: 1 sec, + tracing: true +} + +reactor A (offset:time = 0, period:time = 100 msec){ + timer t(offset, period) + input in: int + output out: int + + reaction (t) -> out {= + lf_set(out, 42); + =} + + reaction(in) {= + instant_t logical_time = lf_time_logical_elapsed(); + instant_t physical_time = lf_time_physical_elapsed(); + + lf_print("The lag is " PRINTF_TIME ".", physical_time - logical_time); + =} +} + +reactor B { + input in: int + output out: int + + reaction(in) -> out {= + lf_set(out, in->value); + =} +} + +federated reactor at localhost { + a = new A(offset = 0, period = 10 msec) + b = new B() + + a.out -> b.in + b.out -> a.in +} \ No newline at end of file diff --git a/examples/C/src/tomacs/Feedback.lf b/examples/C/src/TOMACS/Feedback.lf similarity index 100% rename from examples/C/src/tomacs/Feedback.lf rename to examples/C/src/TOMACS/Feedback.lf diff --git a/examples/C/src/tomacs/README.md b/examples/C/src/TOMACS/README.md similarity index 69% rename from examples/C/src/tomacs/README.md rename to examples/C/src/TOMACS/README.md index a52351a2..5d728a73 100644 --- a/examples/C/src/tomacs/README.md +++ b/examples/C/src/TOMACS/README.md @@ -1,2 +1,3 @@ # Example LF programs from "Strongly-Consistent Distributed Discrete-Event Systems" -This folder contains the example LF programs found in the publication "Strongly-Consistent Distributed Discrete-Event Systems". \ No newline at end of file +This folder contains the example LF programs found in the publication "Strongly-Consistent Distributed Discrete-Event +Systems". \ No newline at end of file From 3ccf8a91e4355b932fd574cf670a5ea9b86ab1e0 Mon Sep 17 00:00:00 2001 From: erlingrj Date: Thu, 24 Oct 2024 15:16:34 -0700 Subject: [PATCH 3/3] Disable tracing --- examples/C/src/TOMACS/Evaluation.lf | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/examples/C/src/TOMACS/Evaluation.lf b/examples/C/src/TOMACS/Evaluation.lf index b06ab369..1766949d 100644 --- a/examples/C/src/TOMACS/Evaluation.lf +++ b/examples/C/src/TOMACS/Evaluation.lf @@ -1,6 +1,7 @@ target C { timeout: 1 sec, - tracing: true + // tracing: true, + coordination: centralized } reactor A (offset:time = 0, period:time = 100 msec){ @@ -35,4 +36,6 @@ federated reactor at localhost { a.out -> b.in b.out -> a.in + // Replace preceeding line with the following to observe overhead introduced by coordinating + // b.out -> a.in after 0 } \ No newline at end of file