controller_sa_BASE_proposed_claudio.sa 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // If the control rules block is defined, then the generic master will not be used. So the code in the block has to ensure that FMUs are run and synchronized correctly. If the block is not defined, then the generic master will be used.
  2. control rules {
  3. // This block gets executed whenever there is a call to doStep of the adapted FMU.
  4. var step_size;
  5. if ((t + H) >= next_internal_transition) {
  6. // Set the last given inputs to the controller
  7. controller.setValues("passenger_up", stored_passenger_up)
  8. ...
  9. controller.setValues("driver_stop", stored_driver_stop)
  10. step_size := controller.do_step(last_transition_time, (t+H) - last_transition_time); // do a step, then decide next internal transition
  11. last_transition_time := t + H
  12. next_internal_transition := NULL // reset this to null, so that it will be executed when the next input is given.
  13. }
  14. return step_size; // For this adaptation, it should never be the case that step_size < (t+H) - last_transition_time
  15. }
  16. // Any in or state variable declared at the global level will be part of the state of the adapted FMU, so that rollback can work.
  17. in var next_internal_transition;
  18. in var last_transition_time;
  19. in var stored_passenger_up;
  20. ...
  21. in var stored_driver_stop;
  22. // The state of the adapted FMU also includes the aggregation of the states of each original FMU, plus the previous inputs fed to them (this last bit is explained in the hierarchical co-simulation section)
  23. in rules {
  24. // This block is run when the setValues function of the adapted FMU is called.
  25. // each rule is tried in order and the first one evaluating to true gets executed.
  26. not is_set(next_internal_transition) -> {
  27. // This block gets executed when the above condition is evaluated to true.
  28. next_internal_transition := controller.getMaxStepSize() + t;
  29. } --> {
  30. // This block is executed whenever the doStep of the adapted FMU is run.
  31. // Following its execution, the control rules block will be executed.
  32. // If there is no control rules block, this block will still be executed before the generic master is executed, with the inputs being set directly from the inputs to the outputs.
  33. // Maybe setting any input port in this block will prevent the generic master from reseting that input port (this has some nuances that need to be investigated)
  34. // Nothing to do here.
  35. };
  36. is_set(next_internal_transition) -> {
  37. // Store the inputs to the controller
  38. stored_passenger_up := passenger_up;
  39. ...
  40. stored_driver_stop := driver_stop;
  41. }
  42. }
  43. out rules{
  44. // These rules are evaluated when a getValues function is called
  45. true -> {
  46. // This block is executed at the end of the control rules block, or at the end of the execution of a single step of the generic master (in case there is no control rules block)
  47. } --> {
  48. // This block is executed when there is a call to getValues to the adapted FMU.
  49. }
  50. }