is there any way to execute all queued interrupts?
I do the project concerning a robot that creates a map of walls in the room. It fallow walls and keep the stated distance from them.
Interrupt is atached to the Foro interuptor which works with encoder shield ( 20 holes in it -> 20 interupts per wheel rotation). Every 3 interrupts program puts actual angle and distance to wall at the END of Lists.
While the robot is ruuning, every time Arduino goes through a main loop it sends data form the BEGINING of Lists to the computer and deletes them to clear the memory. So the data is nicely queued and robot may run continuously without worrying about memory.
It works fine, but there is a problem. When robot goes into a correner I need to put new data into Lists ( regarding the position of the corer). Right now this data is added, but when robot turn and go further, eralier interrupts become executed and points that should be befor this data goes into a queue behind it.|
So I would like to do I like this. When the robot goes into corner, I should wait until all remaining interrupts were executed. (Time is not a problem here). And then go further. Is there any way to check if there are still interrupts in queue and to make them execute?
Until now i tried dleays, timers, and some loops but it is awlways the same.
The line with the problem was comented "//PROBLEM"
Interrupts are not queued, they are executed the instance they happen. Only exeption to this is if interrupts are disabled with "cli()" or "noInterrupts()".
So why is execution so delayed? Why are they executed only when robot is riding?
What is more. Even though the robot has already turned and has new angle, it is still listing the angles which were noticed before the turn. The data isn't lost but it is added in some kind of delay, and only when interrupts are triggered. It is like this data wait in the memory.
The code is to long to post it. I put it in attachment.
If you want a responsive program don't use delay() anywhere outside setup()
The functions delay() and delayMicroseconds() block the Arduino until they complete. Have a look at how millis() is used to manage timing without blocking in Several Things at a Time.
Okay, changing every delay to millis() helped, and performance is far better. Thanks a lot <3
But there is still some kind of delay in executing interrupts. The data which could only be measured before the robot turn is put into the List after it turn, so it is somehow stored in the memory.
What I trying to explain.
Robot follows the wall, and the Interrupt continuously stores the data into the Lists.
Robot goes int the corner. The program put one new data into the Lists (only moment when the data is put into List not via Interrupt).
Robot turns and goes further. Arduino puts the data achived before the turn now. So something measured before the turn is put into the list after the turn. So it have to be in the memory, don't it?