power_canonical_generated_algorithm.sa 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. code power_sa:
  2. var in_condition_executed;
  3. var out_condition_executed;
  4. var power; //FMU power ref
  5. var time_last_window;
  6. var stored_windowsa_u,
  7. stored_windowsa_d;
  8. var stored_window_reaction_torque,
  9. stored_window_height;
  10. var init_armature_current = 0,
  11. init_displacement = 0,
  12. init_speed = 0;
  13. var stored_armature_current,
  14. stored_displacement,
  15. stored_speed;
  16. function instantiate()
  17. power.instantiate()
  18. return
  19. end function
  20. function setup_experiment(t, ...)
  21. time_last_window := t;
  22. end function
  23. function enter_init()
  24. power.enter_init()
  25. return
  26. end function
  27. function exit_init()
  28. power.exit_init()
  29. return
  30. end function
  31. function setValues(ports, values)
  32. in_condition_executed = empty map
  33. if (true) then
  34. in_condition_executed[cond1] = true
  35. stored_windowsa_u = values["u"]
  36. stored_windowsa_d = values["d"]
  37. // power_sa is moore, so nothing else to do.
  38. end if
  39. out_condition_executed := empty map // force output computation.
  40. end function
  41. function doStep(t, H)
  42. var e := t - time_last_window;
  43. { // new scope
  44. var t := t
  45. var h := H
  46. var dt := 0
  47. power.setValues("u", stored_windowsa_u)
  48. power.setValues("d", stored_windowsa_d)
  49. }
  50. power.doStep(t, H);
  51. time_last_window := t;
  52. out_condition_executed := empty map
  53. end function
  54. function getValues(ports)
  55. var values = empty map
  56. if out_condition_executed == empty map then
  57. if true then
  58. stored_armature_current = power.getValues("armature_current")
  59. out_condition_executed[cond1] := true
  60. end if
  61. if true then
  62. stored_displacement = power.getValues("displacement")
  63. out_condition_executed[cond2] := true
  64. end if
  65. if true then
  66. stored_speed = power.getValues("speed")
  67. out_condition_executed[cond3] := true
  68. end if
  69. end if
  70. if out_condition_executed[cond1] then
  71. values["armature_current"] := stored_armature_current
  72. end if
  73. if out_condition_executed[cond2] then
  74. values["displacement"] := stored_displacement
  75. end if
  76. if out_condition_executed[cond3] then
  77. values["speed"] := stored_speed
  78. end if
  79. return values
  80. end function