Why is the pause function not activating?
14 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I don't understand why this code isn't pausing normally. I'll run this section of the script and it'll speed through without pausing, and then I'll type in the same parts of the code piece-by-piece into the command window and pause WILL work.
Short background on the code: I'm controlling two simple servos using Arduino packages.
stepTime = goalTime/(length(invPath(:,1))-1) % This value is about 0.5
lastq = qStart;
step = 0;
tic
for i=1:length(invPath(:,1))
step = step + 1;
% Simultaneously Map on Plot
simMoveRR(.03,lastq,qend,base,L1,L2); % This plots the results to mock the robot.
lastq = qend;
%Send Command to Arduino; ServoInputVal converts degree input to 0-1 value.
writePosition(s1, ServoInputVal(rad2deg(invPath(i,1)),s1InputRange,s1ArmRange));
pause(stepTime/2); % Doesn't work
writePosition(s2, ServoInputVal(rad2deg(invPath(i,2)),s2InputRange,s2ArmRange));
pause(stepTime/2); % Doesn't work
toc
if mod(step,20)==0; % An attempt to pause the code to review the position.
pause % This doesn't work either.
end
end
EDIT: fixed mod input ; still doesn't explain problem with pause. I'm running MATLAB R2016a
0 comentarios
Respuestas (4)
Stephen23
el 16 de Ag. de 2017
Editada: Stephen23
el 16 de Ag. de 2017
The reason is because
mod(step,20)
will never output the value 20, and so your comparison
mod(step,20)==20
will never be true. You need to review how the modulo function is defined. Or simply try it yourself:
>> mod(15:25,20)
ans =
15 16 17 18 19 0 1 2 3 4 5
Do you see any 20's in the output?
To make it work, perhaps either of these will do what you want:
mod(step,20)==19
mod(step,20)==0
4 comentarios
Jan
el 18 de Ag. de 2017
stepTime = goalTime/(length(invPath(:,1))-1) % This value is about 0.5
Perhaps this is a wrong assumption? Test this:
disp(stepTime / 2)
tic
pause(stepTime/2); % Doesn't work - sure?
toc
Note: Prefer size(invPath,1) instead of length(invPath(:,1)).
John BG
el 17 de Ag. de 2017
Hi Grant Jones
step is a built in function
Apparently, from the help file it looks like it has to be called with at least 2 arguments, for instance
step(obj,1)
Yet when one keys in just step, MATLAB returns
step
Here is an example of how the function step works:
Consider a randomly generated stable Transfer Function Model:
of the form G(s)=num(s)/den(s):
num =
0 -0.1022 0.0316 0.1934 -0.1795 0.1620
.
MATLAB even generates a default damping plot
.
So why don't you try to rename your variable step to something else?
.
if you find this answer useful would you please be so kind to consider marking my answer as Accepted Answer?
To any other reader, if you find this answer useful please consider clicking on the thumbs-up vote link
thanks in advance
John BG
1 comentario
Divyabharathi V
el 26 de Jun. de 2019
Try this command before using pause in your code
pause on;
John BG
el 18 de Ag. de 2017
Editada: John BG
el 19 de Ag. de 2017
Hi Grant Jones
Again, pause is a MATLAB command, shouldn't you be sending the pause wrapped in a Send-To-Arduino command?
When you say that the pause works, keying in single lines, isn't it that you are pausing the MATLAB application, that in turn pauses the connection to the Arduino, so so it looks as if working, but it isn't really?
When you run the script, the lines containing pause commands, are they really sent to your board?
.
1 comentario
Walter Roberson
el 19 de Ag. de 2017
"shouldn't you be sending the pause wrapped in a Send-To-Arduino command?"
No. It is not the arduino that needs to be paused. Positioning control commands are being sent by MATLAB, and the arduino needs to react to them, and then after a brief time MATLAB needs to send a different command.
It would probably be possible to rewrite portions of the work as an Arduino sketch that received data from MATLAB and executed the appropriate I/O commands, but that is not necessary.
Ver también
Categorías
Más información sobre MATLAB Support Package for Arduino Hardware en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!