I am new with gekko, but I think the usage of m.if2 might be wrong. 'm.if2(m.abs(v)<=1e-4, u,xs_)' should be written as 'm.if2(m.abs(v)-1e-4, u,xs_)', it means if 'm.abs(v)-1e-4' is less than 0, the value is u, or else it is xs_.