Plot data from scope to gui mismatch
4 ビュー (過去 30 日間)
古いコメントを表示
hello,i have a question about plotting data from scope simulink to plot GUI. this is my first project in GUI, so sorry if i make a beginner mistake. and im sorry if my english is bad.
so, this my project is make a bouncing ball system, where the input is the gain (k) and the radius of the ball (r). for the output, the position of the ball and the velocity are show in GUI. my Simulink is already correct based on the output. the ilustration is like this.
(velocity)
(position)
but in my GUI, the result is like this
where the blue line is position, and the red lines is velocity. as you can see the data that shows in GUI is different from the scope in my simulink.
this is the data that i get from simulink with the the help of block "To Workspace"
(position)
(velocity)
and this is my matlab script that i use in to build the GUI ( the Run part )
function Run_Callback(hObject, eventdata, handles)
% hObject handle to Run (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
set_param('BolaPantul','SimulationCommand','start');
vrWorld = vrworld('3dBolaPantul.x3d');
open(vrWorld);
myCanvas = vr.canvas(vrWorld,'Parent', handles.uipanel,'Units',...
'normalized', 'Position',[0 0 1 1],'Viewpoint','frontView');
handles.timer = timer('Name','MyTimer', ...
'Period',0.1, ...
'TasksToExecute',inf, ...
'ExecutionMode','fixedSpacing',...
'TimerFcn',{@timerCallback,hObject});
guidata(hObject,handles);
start(handles.timer);
function timerCallback(~,~,guiHandle)
if ~isempty(guiHandle)
% get the handles
handles = guidata(guiHandle);
% if new data, then update the axes
if ~isempty(handles)
% get data from simulink
rto = get_param('BolaPantul/plot_time','RuntimeObject');
x_time = rto.OutputPort(1).Data;
rto_y_measured = get_param('BolaPantul/plot_y_bola','RuntimeObject');
y_measured = rto_y_measured.OutputPort(1).Data;
rto_v_measured = get_param('BolaPantul/plot_v_bola','RuntimeObject');
v_measured = rto_v_measured.OutputPort(1).Data;
set(handles.plotR,'xLim',[x_time-20 x_time+30]);
set(handles.plotR,'yLim',[-22 22]);
axes(handles.plotR);
plot(handles.plotR,[x_time x_time],[y_measured y_measured], 'bo', 'LineWidth', 1, 'MarkerSize', 1);
hold on;
axes(handles.plotR);
plot(handles.plotR,[x_time x_time],[v_measured v_measured], 'ro', 'LineWidth', 1, 'MarkerSize', 1);
hold on;
hChildren = get(handles.plotR,'Children');
xData1 = get(hChildren(:),'XData');
yData1 = get(hChildren(:),'YData');
% inisiasi data x dan y
ns = size(xData1,1);
ax = [0 0 0 0]';
ay = [0 0 0 0]';
if ns > 2
ax = cell2mat(xData1(1:4));
ay = cell2mat(yData1(1:4));
end
%line measured
axes(handles.plotR);
plot(handles.plotR,[ax(2) ax(4)] ,[ay(2) ay(4)], 'b-', 'LineWidth', 1);
hold on;
%line predicted
axes(handles.plotR);
plot(handles.plotR,[ax(1) ax(3)] ,[ay(1) ay(3)], 'r-', 'LineWidth', 1);
hold on;
end
end
and this is my simulink that i used ( ilustration )
and if you guys wants to check it by yourself, you can acces all my file in this link ( im using matlab r2020a ) : https://drive.google.com/drive/folders/1Mo9UDxG2U8A7pS1RiHApo7IPGSK6lOS_?usp=sharing
for my hyphothesis, this problem happen because my time sampling in GUI is not the same like in the simulink, or my method to plot the data is not correct. can anybody help ?
2 件のコメント
Geoff Hayes
2021 年 1 月 26 日
Zaidan - why in your code
plot(handles.plotR,[x_time x_time],[y_measured y_measured]...
do you concatenate the x_time with x_time and the y_measured with the y_measured? Aren't you just duplicating data? Should you be keeping a record of the data from previous iterations and concatenating it with the new set of data? Please clarify.
回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Event Functions についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!