How do I solve an algebraic loop error in Simulink?
6 views (last 30 days)
In brief, I am trying to create a simulink function block that selects the next waypoint in a predefined array when the model vehicle gets within a certain distance of the current waypoint.
Inputs into this function block are the current waypoint 'target' in the form of a [1 x 2] array, distance to the currently selected waypoint 'd2w' and 'accuracy' as a value at which when 'd2w' is less than 'accuracy', the function block switches to the next waypoint in the predefined array.
Output is simply the desired waypoint 'targetnew'.
function targetnew = setwaypoint(d2w,target,accuracy)
waypoints = [100 150; 200 400; 175 275; 600 300]; % pre-defined waypoints (in the future imported as a large array from an external source).
target = waypoints(1,:); % initializes the first waypoint.
Lia = ismember(waypoints,target,'rows'); % identifies if each row of waypoints is equal to target.
idxa = find(Lia); % indexes waypoints rows that are equal to target.
idx = 1; % prevents error when idxa is empty.
idx = idxa(1); % selects only the first matched row in case more exist.
if d2w > accuracy
idx = idx + 1; % if target waypoint is reached, add one to index.
if idx > size(waypoints, 1) % attempt to avoid any issues if simulation time is greater than time taken to reach final waypoint.
targetnew = waypoints(end, :);
targetnew = waypoints(idx, :);
When running the simulink model, I am presented with this error:
I've tried all of the actions it suggests, I've tried putting in a delay block, but nothing works.
This is part of the simulink model:
Note that I took the delay back out, but I can put it back in if needs be.
How do I stop this error?
Vijaya Lakshmi Chagi on 13 Mar 2019
One of the best way to troubleshoot algebraic loop issues in your model is to use Simulink Debugger.
The following link gives more information: https://www.mathworks.com/matlabcentral/answers/97687-how-can-i-resolve-algebraic-loops-in-my-simulink-model-in-simulink-6-5-r2006b