-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSensorPipeline.lf
More file actions
47 lines (41 loc) · 1.76 KB
/
Copy pathSensorPipeline.lf
File metadata and controls
47 lines (41 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# Lab 2 starter: build a two-reactor pipeline.
# A Sensor will produce periodic readings and a Display will consume them.
# Follow the exercises in the lab README. The TODO markers below show where
# each exercise makes its changes. This file compiles as it is.
target Python {
timeout: 4 s
}
reactor Sensor(period = 1 s, gain=3) {
timer sample(0, period)
# TODO (Exercise 2): declare a state variable named `raw`, initialized
# to 0, to count how many samples have been taken.
# TODO (Exercise 3): declare an output port named `reading`.
reaction(startup) {=
print(f"Sensor started with period {self.period // MSEC(1)} ms and gain {self.gain}.")
=}
# TODO (Exercise 3): declare `reading` as an effect of this reaction by
# changing its signature to: reaction(sample) -> reading
reaction(sample) {=
# TODO (Exercise 2): increment the `raw` state variable here.
# TODO (Exercise 3): replace the print below by producing an output:
# send the value raw * gain on the `reading` port.
print("Sensor sampled.")
=}
}
reactor Display {
state received = 0
# TODO (Exercise 3): declare an input port named `reading`.
# TODO (Exercise 3): add a reaction triggered by `reading` that increments
# `received` and prints the received value and the elapsed logical time
# in milliseconds.
reaction(shutdown) {=
print(f"Display received {self.received} readings in total.")
=}
}
# TODO (Exercise 4): instantiate a Sensor named `s` and a Display named
# `d`, then connect the Sensor's output port to the Display's input port.
# TODO (Exercise 5): give `s` a period of 500 ms at instantiation and
# predict how many readings the Display will report.
# TODO (Exercise 6): change the timeout above to 2 s and predict again.
main reactor SensorPipeline {
}