How to continuously modify graphic object in function block from Simulink?
Ältere Kommentare anzeigen
The goal is to create a function to continuously update the position of 2 graphical objects on a 2D plot. This function receives a matrix of points used to plot each of these objects in their new position, and a signal which is used to determine the color of the 'cone' object. Other objects which are static and are visualized by another function need to remain visible.
When calling the 'robotView' function block from Simulink, fields of MxArrays (coneFig and botFig) cannot be extracted during code generation. In Matlab I created a test script to produce a random 'command' signal to test all of these scripts working together outside of Simulink. In that scenario all is well. Note that hold is left 'on' by the 'masterView' function block, which should run once before 'robotView' is called and handles the static objects.
I have found even more issues when attempting to do this without storing the object handles of the extrinsic plot function, but am open to any solution which keeps visualization functions separate from data manipulation functions.
function robotView(cone, robot, detected)
% persistent variables are kept local to the function each time it is
% called
persistent coneFig botFig
% coneFig and botFig are initialized as empty, so we can use that to
% set up a 'run once' part of the funciton that only happens the first
% time it gets called
if isempty(coneFig)
coneFig = plot(cone(:,1), cone(:,2), 'k.-');
botFig = plot(robot(:,1), robot(:,2), 'k.-');
set([coneFig botFig],'LineWidth', 5)
hold off % old objects will be removed
end
% need to update the color of the cone if an object is detected
if detected
coneFig.Color = 'red';
else
coneFig.Color = 'black';
end
coneFig.XData = cone(:,1);
coneFig.YData = cone(:,2);
botFig.XData = robot(:,1);
botFig.YData = robot(:,2);
drawnow % update plot without waiting for script to finish
end


Antworten (0)
Kategorien
Mehr zu Trajectory Generation finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!