How can i send permenantly same position to my robot?
1 次查看(过去 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
0 个评论
采纳的回答
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!
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File 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!