Import data to app during simulation

조회 수: 14 (최근 30일)
Julian
Julian 2024년 12월 21일
답변: Walter Roberson 2024년 12월 22일
Hi,
I'm currently trying to control an robot using a matlab app controlling my simulink simulation.
For implementing the inverse kinematics I want to get the current rotation of the joints into my app. But when I try to use toWorkspace I can't access it via "evalin" or searching for it using "who".
So far I tried tons of approaches but nothing works and it starts making no sense to me.
Does anybody here have any experince in exporting live data from simulink into an app?
Here's the problematic part of my simulation/ code.
Thanks in advance! :)
function GOButtonLPushed(app, event)
% Get the values directly from the edit fields
lGoalX = app.rArmGoalXEditField.Value;
lGoalY = app.rArmGoalYEditField.Value;
lGoalZ = app.rArmGoalZEditField.Value;
lGoalXD = 0;
lGoalYD = 0;
lGoalZD = 0;
% Set the values in Simulink
set_param("base_kin/lArm/lGoalX", "value", num2str(lGoalX));
set_param("base_kin/lArm/lGoalY", "value", num2str(lGoalY));
set_param("base_kin/lArm/lGoalZ", "value", num2str(lGoalZ));
set_param("base_kin/lArm/lGoalXD", "value", num2str(lGoalXD));
set_param("base_kin/lArm/lGoalYD", "value", num2str(lGoalYD));
set_param("base_kin/lArm/lGoalZD", "value", num2str(lGoalZD));
%l
for i = 1:7
value = evalin('base', ['out.olJ', num2str(i)]);
disp(value)
lastValue = value.Data(end);
set_param(['base_kin/lArm/lJ', num2str(i)], 'value', num2str(lastValue));
end
%r
for i = 1:7
logsout = evalin('base', 'rJ'+num2str(i));
signalData = logsout.get(['rJ', num2str(i)]);
lastValue = signalData.Data(end); % Last value in the data array
set_param(['base_kin/rArm/rJ', num2str(i)], 'value', num2str(lastValue));
end
end
  댓글 수: 2
Walter Roberson
Walter Roberson 2024년 12월 21일
Could you confirm that you are invoking sim() in a loop, each time advancing the StopTime parameter? "Logged data is written to the workspace when the simulation pauses or stops."
Julian
Julian 2024년 12월 22일
Currently I'm not calling sim each time. Wouldn't the simulation be extremly laggy if I started and stopped it constantly? As far as my research went it should be possible to get the data during the simulation aswell.
Do you know of any different approach to get live data into the app? :)

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2024년 12월 22일

To Workspace only updates when the simulation pauses or stops.

There are no blocks that will update variables in the workspace at run time.

What you can do is to use a MATLAB Function Block to assignin('base').

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Simulation에 대해 자세히 알아보기

제품


릴리스

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by