Good day,
I am currently working on an autonomous quadcopter project. I am using the HC-SR04 sensor for altitude hold, however in testing the sensor, the maximum data throughput of the sensor is only 20 samples/second or 20Hz before incurring errors through Polling.
If I were to place this in my PID control loop running at 150Hz, wouldn't this cause my control loop to lag as well?
I found possible solutions that may help with this. One is through interrupt signal handling or through multithreading.
In my understanding, when using interrupts, it is only when data us available from my read sonar function that I will incurr delays in my control loop, at other times I would still maintain my 150Hz loop rate.
Is this notion correct?
I am not yet familiar with using interrupts with raspberry pi. However I also found a solution which is to use multithreading using the wiring-pi library. I think in doing this, this would allow me to concurrently make my read sonar function run along side my PID control loop.
Which is the best way to approach this problem?