Mavink Sonar Depth reading

I have a boat with a sonar that records depth and GPS coordinates to an SD card using an arduino mega. The GPS coordinates are got from the pixhawk flight controller through Mavlink. Could I pass back the depth via mavlink and have it display and be recorded as altitude on the ground control station.

Thanks

David Ardis

Is the Mega connected to the Pixhawk using mavlink over a serial connection? Is that how its getting the GPS co-ordintates? Or are the Mega and Pixhawk separate systems?

Thanks, Grant.

Yes mega is connected to pixhawk via serial and thats how it gets the GPS Data

David Ardis

What does your Sonar output? If it has a voltage output you could ditch the Mega and attach the Sonar to one of the ADC analog inputs on the Pixhawk and we could configure it as a range finder. You would then have all the data together in the same log. However without some code changes I can’t see how we could put it into the Alt field.

Thanks, Grant.

The Sonar actually puts out a CAN message at 1HZ that why i am using a mega with a CAN shield and decode the depth measurement. I though there might have been a way inject a value that could be displayed on any Mission Planner screen even the tuning eg ch16out

I think gmorph is onto something. If you have the arduino mega output a scaled analog value based on the sonar depth measurement, you could connect this output on the mega to the Pixhawk ADC port, configure the scaling for the rangefinder, and it would show up in MP with a lot less hacking than injecting a mavlink message.

I could use an I2C DAC to give the analogue values?

You could use an external DAC, yes. I’d thought of using Arduino’s analogWrite(), but after reading it’s actually a PWM and not a true analog output. But with a low pass filter it should work acceptably as an analog output, especially for a slow changing value like a depth measurement.

I don’t know the make/model of the sonar. Does it have any other outputs other then CAN? If its just CAN someone could always write a driver for it in ArduPilot and you could then plug it directly into the Pixhawk.

Thanks, Grant.

I am using a https://buy.garmin.com/en-GB/GB/p/13578#overview as the Sonar its only got a CAN output and runs at 12v