waitfor(rate) pauses execution until
the code reaches the desired execution rate. The function accounts for the time
that is spent executing code between waitfor calls.
Start a loop using the rateControl object inside to control the loop execution. Reset the object prior to the loop execution to reset timer. Print the iteration and time elapsed.
reset(r)
for i = 1:10
time = r.TotalElapsedTime;
fprintf('Iteration: %d - Time Elapsed: %f\n',i,time)
waitfor(r);
end
Iteration: 1 - Time Elapsed: 0.006162
Iteration: 2 - Time Elapsed: 1.001194
Iteration: 3 - Time Elapsed: 2.000957
Iteration: 4 - Time Elapsed: 3.000868
Iteration: 5 - Time Elapsed: 4.001015
Iteration: 6 - Time Elapsed: 5.000832
Iteration: 7 - Time Elapsed: 6.001095
Iteration: 8 - Time Elapsed: 7.000390
Iteration: 9 - Time Elapsed: 8.000648
Iteration: 10 - Time Elapsed: 9.001008
Rate object, specified as a handle. This object
contains the information for the desired rate and other information about
the execution. See rateControl for more information.
Number of missed task executions, returned as a scalar. waitfor (Robotics System Toolbox) returns the number of times the task was missed in
the Rate object based on the
LastPeriod time. For example, if the desired rate is
1 Hz and the last period was 3.2 seconds, numMisses
returns 3.
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.