window_obstacle_sa_loop_BASE_proposed.sa 949 B

12345678910111213141516171819202122232425262728293031323334353637
  1. semantic adaptation window_obstacle_sa_loop
  2. for fmu window_sa, obstacle
  3. input ports motor_speed
  4. output ports reaction_torque
  5. param MAXITER = 100;
  6. param REL_TOL = 1e-8;
  7. param ABS_TOL = 1e-8;
  8. initial state {
  9. }
  10. control rules {
  11. var reaction_force;
  12. var height := window_sa.get("height")
  13. var prev_height := height
  14. var window_state, obstacle_state;
  15. for (var iter in 0 .. MAXITER) {
  16. window_state := window_sa.getState()
  17. obstacle_state := obstacle.getState()
  18. obstacle.set("height", height)
  19. obstacle.doStep(t, H)
  20. reaction_force := obstacle.get("reaction_force")
  21. window_sa.set("reaction_force", reaction_force)
  22. window_sa.doStep(t, H)
  23. height := window_sa.get("height")
  24. if (is_close(prev_height, height, REL_TOL, ABS_TOL)) {
  25. break;
  26. } else {
  27. prev_height := height;
  28. obstacle.setState(obstacle_state);
  29. window_sa.setState(window_state);
  30. }
  31. }
  32. }
  33. in rules {
  34. true -> { } --> { window_sa.set("reaction_force", f(in_state)) };
  35. }