loop.sa 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. module Loop_SA
  2. semantic adaptation reactive moore LoopSA loop_sa
  3. at "./path/to/LoopSA.fmu"
  4. for inner fmu WindowSA window_sa
  5. at "./path/to/WindowSA.fmu"
  6. with input ports displacement (rad), speed (rad/s), reaction_force (N)
  7. with output ports disp (m), tau (N.m)
  8. for inner fmu Obstacle obstacle
  9. at "./path/to/Obstacle.fmu"
  10. with input ports disp (m)
  11. with output ports reaction_force (m)
  12. with window_sa.disp -> obstacle.disp
  13. with obstacle.reaction_force -> window_sa.reaction_force
  14. output ports tau (N.m) <- window_sa.tau
  15. param MAXITER := 10,
  16. REL_TOL := 1e-05,
  17. ABS_TOL := 1e-05;
  18. control var prev_disp := 0.0;
  19. control rules {
  20. var repeat := false;
  21. for (var iter in 0 .. MAXITER) {
  22. save_state(obstacle);
  23. save_state(window_sa);
  24. obstacle.disp := prev_disp;
  25. do_step(obstacle,t,H);
  26. do_step(window_sa,t,H);
  27. repeat := is_close(prev_disp, window_sa.disp, REL_TOL, ABS_TOL);
  28. prev_disp := window_sa.disp;
  29. if (repeat) {
  30. break;
  31. } else {
  32. rollback(obstacle);
  33. rollback(window_sa);
  34. }
  35. }
  36. return H;
  37. }