Compiling odeset events on simulink, without global variables
Show older comments
I have a simulink matlab function block where I am trying to use ode23 with an events function, but I get the following error when compiling:
All inputs must be constant.
Function 'npcFullProp_debug.m' (#274.284.325), line 8, column 14:
"odeset('RelTol',1e-6,'Events',@npcEvents)"
@npcEvents is defined as a nested function so it can access 'env_par', a structure from the parent function (npcFullProp_debug).
(Note: Matlab Function Block > guidanceLong.m > npcFullProp_debug.m > ode23)
I had hoped that using the parent function variable would be equivalent to a global variable, as suggested in this similar post: Code generation for event functions and ODE solvers
I also tried to make 'env_par' global, but simulink just gets stuck at t = 0.00 s until I stop the simulation. Still haven't figured out why.
Is there a solution that avoids the use of global variables? (why/why not?) I have been running ode23 in small 10sec arcs and checking the events manually, but this curbs the efficacy of a variable step solver.
Answers (1)
Pedro Lima
on 2 Nov 2022
Edited: Pedro Lima
on 2 Nov 2022
0 votes
Categories
Find more on General Applications in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!