|
@@ -1,5 +1,10 @@
|
|
|
module Lazy_SA
|
|
|
|
|
|
+/*
|
|
|
+ * The purpose of this adaptation is to only run the internal FMU
|
|
|
+ * when any of its inputs changes, or when it requests to be explicitly run.
|
|
|
+ */
|
|
|
+
|
|
|
semantic adaptation reactive moore LazySA lazy_sa
|
|
|
at "./path/to/LazySA.fmu"
|
|
|
|
|
@@ -9,20 +14,35 @@ at "./path/to/LazySA.fmu"
|
|
|
with output ports up, down, stop
|
|
|
|
|
|
/*
|
|
|
- * We only need to declare one input port: the one we are interested in.
|
|
|
- * The others (both input and output ports) are bound by assumption.
|
|
|
* In addition, we do not need to do anything about the outputs of the inner FMU, because they are zero order holded by default.
|
|
|
*/
|
|
|
-input ports obj_detected -> controller.obj_detected
|
|
|
+input ports obj_detected -> controller.obj_detected,
|
|
|
+ passenger_up -> controller.passenger_up,
|
|
|
+ passenger_down -> controller.passenger_down,
|
|
|
+ passenger_stop -> controller.passenger_stop,
|
|
|
+ driver_up -> controller.driver_up,
|
|
|
+ driver_down -> controller.driver_down,
|
|
|
+ driver_stop -> controller.driver_stop
|
|
|
|
|
|
output ports up, down, stop
|
|
|
|
|
|
-param INIT_UP := 0.0,
|
|
|
- INIT_DOWN := 0.0,
|
|
|
- INIT_STOP := 0.0;
|
|
|
+param INIT_OBJ_DETECTED := false,
|
|
|
+ INIT_PASSENGER_UP := false,
|
|
|
+ INIT_PASSENGER_DOWN := false,
|
|
|
+ INIT_PASSENGER_STOP := false,
|
|
|
+ INIT_DRIVER_UP := false,
|
|
|
+ INIT_DRIVER_DOWN := false,
|
|
|
+ INIT_DRIVER_STOP := false;
|
|
|
|
|
|
control var tn := -1.0,
|
|
|
- tl := -1.0;
|
|
|
+ tl := -1.0,
|
|
|
+ prev_obj_detected := INIT_OBJ_DETECTED,
|
|
|
+ prev_passenger_up := INIT_PASSENGER_UP,
|
|
|
+ prev_passenger_down := INIT_PASSENGER_DOWN,
|
|
|
+ prev_passenger_stop := INIT_PASSENGER_STOP,
|
|
|
+ prev_driver_up := INIT_DRIVER_UP,
|
|
|
+ prev_driver_down := INIT_DRIVER_DOWN,
|
|
|
+ prev_driver_stop := INIT_DRIVER_STOP;
|
|
|
|
|
|
control rules {
|
|
|
// This initialisation covers simulations that start at a non-zero time.
|
|
@@ -32,7 +52,15 @@ control rules {
|
|
|
|
|
|
var step_size := min(H, tn - t); // In case tn < t, this ensures that the controller will be run at the right time.
|
|
|
// Note that the expression lazy_sa.obj_detected gets replaced by the corresponding storage var in the canonical version.
|
|
|
- if (lazy_sa.obj_detected or (t+H) >= tn){
|
|
|
+ if (lazy_sa.obj_detected != prev_obj_detected or
|
|
|
+ lazy_sa.passenger_up != prev_passenger_up or
|
|
|
+ lazy_sa.passenger_down != prev_passenger_down or
|
|
|
+ lazy_sa.passenger_stop != prev_passenger_stop or
|
|
|
+ lazy_sa.driver_up != prev_driver_up or
|
|
|
+ lazy_sa.driver_down != prev_driver_down or
|
|
|
+ lazy_sa.driver_stop != prev_driver_stop or
|
|
|
+ (t+H) >= tn
|
|
|
+ ){
|
|
|
var step_to_be_done := (t+H-tl);
|
|
|
var step_done := do_step(controller, t, step_to_be_done); // calls the mapIn function that will take care of forwarding the values of the input ports to the internal FMU.
|
|
|
// We calculate these as if step_done == step_to_be_done. If that is not the case, a rollback will be done anyway.
|
|
@@ -49,9 +77,20 @@ control rules {
|
|
|
tl := tl + step_done; // assert tl == t+H
|
|
|
}
|
|
|
|
|
|
+ // Store the previous values of the inputs
|
|
|
+ prev_obj_detected := lazy_sa.obj_detected;
|
|
|
+ prev_passenger_up := lazy_sa.passenger_up;
|
|
|
+ prev_passenger_down := lazy_sa.passenger_down;
|
|
|
+ prev_passenger_stop := lazy_sa.passenger_stop;
|
|
|
+ prev_driver_up := lazy_sa.driver_up;
|
|
|
+ prev_driver_down := lazy_sa.driver_down;
|
|
|
+ prev_driver_stop := lazy_sa.driver_stop;
|
|
|
+
|
|
|
return step_size;
|
|
|
}
|
|
|
|
|
|
+/*
|
|
|
+The following code is not needed because the outputs are zero order hold'ed by default:
|
|
|
out var stored_up := INIT_UP,
|
|
|
stored_down := INIT_DOWN,
|
|
|
stored_stop := INIT_STOP;
|
|
@@ -66,3 +105,4 @@ out rules{
|
|
|
lazy_sa.stop := stored_stop;
|
|
|
};
|
|
|
}
|
|
|
+ */
|