I’m doing some control systems work and wanting to find things like risetime of responses, so I want to find where a simulation variable crosses some value. findfirst works but it searches among the simulation points rather than finding where the interpolation crosses the desired point, which if things are smooth might be some distance from the point I would like to find.

I suspect someone has crossed this bridge already, but I’m struggling to find it.

I could do it using callbacks, but that seems a bit overkill for what feels more natural to be done with analysis after the simulation has been run.

"find 10-90 risetime of sol in interval ti to tf, 100% step from yi to yf; n(th) state var"
function findTr(sol, ti, tf, yi, yf, n=1)
v10,v90 = [0.1,0.9].*(yf-yi).+yi
t10 = fzero(t -> sol(t)[n] - v10, [ti,tf])
t90 = fzero(t -> sol(t)[n] - v90, [ti,tf])
return t90-t10
end