How can i send permenantly same position to my robot?

1 view (last 30 days)
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

Accepted Answer

Isabella W
Isabella W on 29 Jul 2016
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 Comment
cemsi888
cemsi888 on 5 Aug 2016
Actually code works well. I would like to ask a question. By means of this code could i send same position along five seconds ?

Sign in to comment.

More Answers (0)

Categories

Find more on MATLAB Support Package for Arduino Hardware in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!