- #1
mastermechanic
- 108
- 15
Last week I encountered a problem in my graduate project. The project was about designing an autonomous and mobile robot that picks up 9 glass tiles from a stack point and place them into a 3x3 matrix with minimum tolerance.
I am using a DC motor with an infinite turn potentiometer for closed loop feedback. For testing purposes I wrote a different Arduino sketch to test PID code and in that sketch the code was inside loop function but in the actual project the robot has specific number of tasks, therefore, I wrote my functions inside setup function so that it does it only once. However, PID control code must run all the time so that it can detect disturbances and make corrections but as you can imagine I cannot write it inside loop function due the reasons I mentioned above.
What I did was, I wrote a separate function and wrote the PID code inside a while (true) loop, when the actual position is within 99-101% of the target position it breaks the loop. But in this case, we lose the PID functionality since I am manually stopping the operation.
My question is, is there any method for arduino to implement PID loop function while other codes are running. I was thinking about interrupts but couldn't find what I want. First of all, is it possible? or do we need to run this PID code in another board? How it is done in industrial projects?
I am waiting your thoughts., thank you in advance.
I am using a DC motor with an infinite turn potentiometer for closed loop feedback. For testing purposes I wrote a different Arduino sketch to test PID code and in that sketch the code was inside loop function but in the actual project the robot has specific number of tasks, therefore, I wrote my functions inside setup function so that it does it only once. However, PID control code must run all the time so that it can detect disturbances and make corrections but as you can imagine I cannot write it inside loop function due the reasons I mentioned above.
What I did was, I wrote a separate function and wrote the PID code inside a while (true) loop, when the actual position is within 99-101% of the target position it breaks the loop. But in this case, we lose the PID functionality since I am manually stopping the operation.
My question is, is there any method for arduino to implement PID loop function while other codes are running. I was thinking about interrupts but couldn't find what I want. First of all, is it possible? or do we need to run this PID code in another board? How it is done in industrial projects?
I am waiting your thoughts., thank you in advance.
Last edited: