Obstacle avoidance on pixhawk using sonar

Mavlink should be plenty fast enough for this application.
The sonar should work well enough for the proof of concept you wish to demonstrate.
I don’t know of any reason that it would be un-safe, but then I have never tried it.