20 ms delay in repeat until loops

This year we are using vexcode iq blocks to code our autonomous program. We use a pid loop to drive/turn accurately. Vexcode iq blocks has a feature that allows you to see the text equivalent of your block code. While looking at text version, we see that for every “repeat until” loop block we use, the code automatically adds a wait 20 ms line of code to the end of the loop.

block_test

The first image shows the block code, and the second shows the text version of the same code. As you can see, their is an unnecessary wait 20 ms line that the vex iq blocks put there. We suspect that this will mess up the integral part of our pid loop. We are considering converting all our code to text, and deleting the wait 20 ms line.

Can anyone tell me why this 20 ms wait is added, and if it is necessary for the code to work?

so you don’t do this and crash the brain.

why do you think that ?
What do you think would happen to the derivative part if the delay was 0 for each loop iteration ?

9 Likes

I believe that it may be to make the program run more smoothly. Try adding a “wait” block into the program.

1 Like

Hey, big points to @codesnipe for looking a the code.

So your program isn’t the only other program running on the brain. Other tasks are going “What are the values of the buttons, joystick, etc” from the controller. And geting data from the robot about sensor values (wheel rotation for one, but other sensors too) and all of that takes time. In the way before times of the PIC controller, the data from all of that was ready every 20 milliseconds. So it was and is to wait 20 milliseconds before asking again.

And you know the real world version of this, asking “Are we there yet?” Over and over and over every mile makes the driver very unhappy. Same thing here, give some time for the robot / car to go some distance before asking for data again.

Remember there are 1000 milliseconds in a second, so waiting 20 or 100 milliseconds isn’t a big deal.

And for parents “Don’t make me pull this car over and stop” is something we may have said in the past :roll_eyes:

4 Likes

It is necessary. I used text before I knew that, put in a while True: if bumper pressed: stop catapult loop without a wait and immediately got an error on the brain: User program exceeded time limit of 3 seconds. In other words, the brain is not powerful enough to check the bumper that often (literally more than every millisecond), so it just crashes.

I assure you, everyone puts 20 ms delays in their loops and it will not hurt your program in any way, especially since most sensors only update to the brain every 10, 15, or 20 ms anyway. It’s just fine for basically everything, and actually necessary for your D to have any more than negligible and highly oversensitive values, as jpearman alluded to:

As Foster said, I commend you for looking at the C++.

7 Likes