1

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?

3
  • I didn't realise the HC-SR04 was accurate enough to perform such a function. Are you very close to solid ground? Does the HC-SR04 interrupt when data is available? Mine don't, you have to trigger and then time the echo line.
    – joan
    Mar 2, 2016 at 10:36
  • @Joan I am planning to trigger the interrupt once the echo pin goes high/ I am also planning on flying only close to ground at about 1.5m Mar 2, 2016 at 11:00
  • The best way is to use interrupts, please consult this link for a better answer: raspberrypi.stackexchange.com/questions/43598/… Mar 7, 2016 at 1:40

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.