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.

답변 (0개)

카테고리

도움말 센터File Exchange에서 Programming에 대해 자세히 알아보기

제품

릴리스

R2020a

태그

질문:

JV
2021년 7월 9일

편집:

JV
2021년 7월 9일

Community Treasure Hunt

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

Start Hunting!

Translated by