Using Sonar (HC-SR04) to avoid Ground Collision

Hi,

So, a few weeks ago I acquired a sonar module for use with the APM 2.8 on my drone.

The module works well, and I can see relatively accurate height readings on Mission Planner. The question though, is it possible to use this sonar module to maintain a specific height off the ground, when in either AltHold or Loiter mode? Such that I can avoid crashing in to the ground when I get too low, acting in a similar way to obstacle avoidance.

This video from 7 years ago explains what I mean perfectly:

Kindly let me know what setting I’ll need to edit to achieve this. Thanks.

Hi, yes this is a built in feature with arducopter, you just need to tell it what port your sonar is connected to!

http://ardupilot.org/copter/docs/sonar.html

The only issue is that I am not 100% sure on what data your sonar outputs, but as long as it is an analogue voltage i believe it should work.

Hi! Thanks for your reply. My sonar outputs a voltage signal which is then correlated to a distance value.

I’ve connected it up well, and it’s working perfectly to detect heights up to 3m, but I just can’t get it to “avoid” the ground like in the video I posted earlier.

Is this a setting I can edit on the APM, say, “minimum height in AltHold=2m”, or do I need a separate Arduino to run this?

Thanks again.

Please tell me how to connect this sonar and pixhark.