ODE events where value does not contain state

Hi all, I'm currently working on a simple hybrid dynamical system with discrete state jumps. For that I'm using ODE events. The problem is that my 'value's' (that which will cross zero) are not directly related to the state of the dynamical system. I'm not able to express these variables alongside the proper state (e.g. position + velocity of angles).
Currently I'm using global variables but it seems that MATLAB does not decrease the step-size when the 'value' crosses zero. I assume this is because the value is not part of the state. Here is the code for the events;
function [value, isterminal,direction] = leg_events(t,x)
global isSwingL isSwingR frcLegL frcLegR posFooL posFooR frcComL frcComR
value = [];
isterminal = [];
direction = [];
if isSwingL
value = [value; posFooL(2)];
isterminal = [isterminal; 1];
direction = [direction; -1];
else
value = [value; frcComL(2)];
isterminal = [isterminal; 1];
direction = [direction; -1];
end
if isSwingR
value = [value; posFooR(2)];
isterminal = [isterminal; 1];
direction = [direction; -1];
else
value = [value; frcComR(2)];
isterminal = [isterminal; 1];
direction = [direction; -1];
end
end
Anyone have any suggestion? Please let me know.
The model is implemented in Simulink which doe seem to be able to deal with this kind of thing but I need it specifically in code for optimization purposes. I've also considered changing the 'MaxStep' but this makes the simulation unnecessary slow and unusable for the optimization.

Answers (0)

Categories

Find more on Programming in Help Center and File Exchange

Products

Release

R2020a

Tags

Asked:

JV
on 9 Jul 2021

Edited:

JV
on 9 Jul 2021

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!