How can i send permenantly same position to my robot?

3 次查看(过去 30 天)
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 中查找有关 MATLAB Support Package for Arduino Hardware 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by