semantic adaptation reactive moore LoopSA loop_sa
at "./path/to/LoopSA.fmu"

	for inner fmu WindowSA window_sa
		at "./path/to/WindowSA.fmu"
		with input ports displacement (rad), speed (rad/s), reaction_force (N)
		with output ports disp (m), tau (N.m)
	
	for inner fmu Obstacle obstacle
		at "./path/to/Obstacle.fmu"
		with input ports disp (m)
		with output ports reaction_force (m)
	
	with window_sa.disp -> obstacle.disp
	with obstacle.reaction_force -> window_sa.reaction_force

output ports tau <- window_sa.tau

param 	MAXITER := 10, 
		REL_TOL := 1e-05, 
		ABS_TOL := 1e-05;

control var prev_disp := 0.0;
control rules {
	var repeat := false;
	for (var iter in 0 .. MAXITER) {
		save_state(obstacle);
		save_state(window_sa);
		obstacle.disp := prev_disp;
		do_step(obstacle,t,H);
		do_step(window_sa,t,H);
		
		repeat := is_close(prev_disp, window_sa.disp, REL_TOL, ABS_TOL);
		prev_disp := window_sa.disp;
		if (repeat) {
			break;
		} else {
			rollback(obstacle);
			rollback(window_sa);
		}
	}
	return H;
}


