-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add example programs and a short README
- Loading branch information
Showing
3 changed files
with
116 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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". |