필터 지우기
필터 지우기

How can i send permenantly same position to my robot?

조회 수: 1 (최근 30일)
cemsi888
cemsi888 2016년 7월 29일
댓글: cemsi888 2016년 8월 5일
Hi Guys ı would like to send for example in 5 seconds same positions to my robot. Actually i createda function but it sends he position and wait a bit and after sends the next position. Here is my code. I will appreciate if you offer me a solution.Thanks in advance
% function timertest()
global pos actval
pos = 1; % aktuelle Position im Feld
actval = 0; % aktueller Wert aus dem Feld
n = 5; % Anzahl der Durchlaeufe
del = 5.0; % Intervall in sec.
disp('Start');
t = timer('TimerFcn',@timer_callback_fcn,'Period', del,'ExecutionMode','fixedDelay','TasksToExecute',n);
start(t);
disp('Ende');
end
function timer_callback_fcn(obj, event, string_arg) global pos actval
feld = [1 2 3 4 5];
actval = feld(pos);
pos=pos + 1;
disp(actval);
end

채택된 답변

Isabella W
Isabella W 2016년 7월 29일
I believe that the following code does what you are looking for:
function timertest()
global pos actval
pos = 1;
actval = 0;
n = 5;
del = 5.0;
disp('Start');
t = timer('TimerFcn',@timer_callback_fcn, ...
'Period', del,...
'ExecutionMode','fixedDelay', ...
'TasksToExecute',n, ...
'StopFcn','disp(''Ende'')'); % display 'Ende' when all positions have been printed
start(t);
%disp('Ende'); this will display 'Ende' immediately after start(t), not after all the callbacks have run
end
function timer_callback_fcn(~,~) % you do not use obj or event in your function so it's fine to ignore them
% you do not require any additional parameters (ie. string_arg)
global pos actval;
feld = [1 2 3 4 5];
actval = feld(pos);
pos = pos + 1;
disp(actval);
end
I hope this helps!
  댓글 수: 1
cemsi888
cemsi888 2016년 8월 5일
Actually code works well. I would like to ask a question. By means of this code could i send same position along five seconds ?

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by