How can i send permenantly same position to my robot?

1 visualización (últimos 30 días)
cemsi888
cemsi888 el 29 de Jul. de 2016
Comentada: cemsi888 el 5 de Ag. de 2016
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

Respuesta aceptada

Isabella W
Isabella W el 29 de Jul. de 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 comentario
cemsi888
cemsi888 el 5 de Ag. de 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 ?

Iniciar sesión para comentar.

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by