semantic adaptation window_obstacle_sa_loop
for fmu window_sa, obstacle
input ports motor_speed
output ports reaction_torque
param MAXITER = 100;
param REL_TOL = 1e-8;
param ABS_TOL = 1e-8;
initial state {
	
}
control rules {
	var reaction_force;
	var height := window_sa.get("height")
	var prev_height := height
	var window_state, obstacle_state;
	for (var iter in 0 .. MAXITER) {
		window_state := window_sa.getState()
		obstacle_state := obstacle.getState()
		obstacle.set("height", height)
		obstacle.doStep(t, H)
		reaction_force := obstacle.get("reaction_force")
		window_sa.set("reaction_force", reaction_force)
		window_sa.doStep(t, H)
		height := window_sa.get("height")
		if (is_close(prev_height, height, REL_TOL, ABS_TOL)) {
			break;
		} else {
			prev_height := height;
			obstacle.setState(obstacle_state);
			window_sa.setState(window_state);
		}
	}
}
in rules {
	true ->	{ } --> { window_sa.set("reaction_force", f(in_state)) };
} 
