Implementing Dry friction in modeling toolkit

I would like to implement some function to have components simulating dry friction with modeling toolkit. As a starting point, I think the implementation from modelica is quite good. Most of it can be implemented with IFelse.ifelse function. What I 'm missing is how to have the previous values of a state in modeling toolkit i.e. in modelica they use the pre keyword… Using that they are building a small state machine to track the status of the component i.e. blocked / sliding forward / sliding backward etc …

The model i want to implement in modelica pseudo code (copy from modelica doc):

// part of mixed system of equations
startFor = pre(mode) == Stuck and sa > 1;
startBack = pre(mode) == Stuck and sa < -1;
a = der(v);
a = if pre(mode) == Forward or startFor then sa - 1 elseif
pre(mode) == Backward or startBack then sa + 1 else 0;
f = if pre(mode) == Forward or startFor then f0 + f1v elseif
pre(mode) == Backward or startBack then -f0 + f1
v else f0*sa;

// state machine to determine configuration
mode = if (pre(mode) == Forward or startFor) and v>0 then Forward elseif
(pre(mode) == Backward or startBack) and v<0 then Backward else Stuck;

So any idea on how to have previous state value in modeling toolkit or on another way to implement dry friction ?
Thanks a lot,
Br Yves-Julien

Conditionals don’t work very well for this use case, I believe this issue is tracking progress on this feature: Support for events · Issue #38 · SciML/ModelingToolkit.jl · GitHub

In the mean time, there is a nice implementation using callbacks here: Modeling Friction with State Machines

1 Like