when active then
reinit(state, pre(newState));
end when;
stateOut = if active then state else sOff;
if active then
der(state) = {state[2], -(k/m)*state[2] + (g/l)*sin(state[1])};
else
der(state) = zeros(N);
end if;
when h1 < 0 then
active1 = false;
elsewhen h2 < 0 then
active1 = true;
end when;
active2 = not active1;
new2[1] = l*sin(state1[1]);
new2[2] = l*cos(state1[1]);
new2[3] = l*state1[2]*cos(state1[1]);
new2[4] = -l*state1[2]*sin(state1[1]);