Get data in real time, draw graphics changing in real time.

1 回表示 (過去 30 日間)
Modestas Sekreckis
Modestas Sekreckis 2011 年 4 月 12 日
Hi, I'm getting real-time data from the manipulator, its current position.
channel = ddeinit('ipc_data', 'ipc_1');
data(1,1)=ddereq(channel,'mw1311'); % X coordinate
data(1,2)=ddereq(channel,'mw1312');% Y coordinate
data(1,3)=ddereq(channel,'mw1313');% Z coordinate
I need to represent the manipulator's position on the chart. and when the manipulator moves, it should be evident in the chart.

採用された回答

Paulo Silva
Paulo Silva 2011 年 4 月 12 日
clf
p=plot3(nan,nan,nan);
while 1
data(1,1)=ddereq(channel,'mw1311'); % X coordinate
data(1,2)=ddereq(channel,'mw1312');% Y coordinate
data(1,3)=ddereq(channel,'mw1313');% Z coordinate
set(p,'XData',[0 data(1,1)],'YData',[0 data(1,2)],'ZData',[0 data(1,3)])
pause(0.5) %read and draw data every 0.5 seconds
end
To stop the loop do CTRL+C
Alternative way, using a timer:
function test
fig=figure;
set(fig,'CloseRequestFcn','delete(gcf);')
h = plot3(NaN, NaN, NaN,'LineWidth',5);
t = timer('TimerFcn',@readdata,...
'Period', 0.5,'executionmode','fixedSpacing');start(t)
function readdata(g1,gg1)
if (~ishandle(fig)),stop(t),return,end
data(1,1)=ddereq(channel,'mw1311'); % X coordinate
data(1,2)=ddereq(channel,'mw1312');% Y coordinate
data(1,3)=ddereq(channel,'mw1313');% Z coordinate
set(p,'XData',[0 data(1,1)],'YData',[0 data(1,2)],'ZData',[0 data(1,3)])
end
end

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeInstrument Control Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by