Sensor driver development/testing

Hi,

I am an absolute newbie in PX4 development and I’ve been tasked with developing a driver for a rangefiner. There are plenty of examples in the source tree of PX4, however I’m more interesting in how does one go about testing the actual driver.

I’ve got Pixhawk 2.1 (Cube) flight controller and was thinking whether it’s worthwhile to try and come up with some sort of HITL setup where the rangefinder is connected to one of the serial ports (as that is what I intend to use for the final driver) and everything else is simulated - has this been done before? I suspect it has, but as it’s not the most common use case, I haven’t come across it in the documentation so far.

Alternatively, maybe there is a simpler way/pattern for sensor driver development/testing than SITL/HITL testing?

Thank you in advance!

Hi, so HITL and SITL is certainly possible, however, if you’re trying to implement and validate a new driver, I would do that on the real hardware without simulation.

My workflow would be to get a serial console first (see devguide), so that you have the NuttShell (nsh>) to do tests and printfs visible.

This way you can then manually start the driver with yournewsensor start and try to get first results with e.g. yournewsensor info in the same way it’s done for other sensors.

Thank you for your answer! I’m already at a point where I have console connection, I do agree that it’s a good starting point and I will continue that way for awhile.

What I wonder for the future is what is the minimal setup required for me to get some sort of plot from QGC that displays the data from the sensor (or, in fact, dummy data passed via the interface to begin with)? To my current understanding, that would entail MAVROS + a simulation. Is that correct? Or is there a more lightweight solution?

I think QGC should show the distance sensor data once it is published to uORB and then MAVLink.

The MAVLink message should be: https://mavlink.io/en/messages/common.html#DISTANCE_SENSOR

1 Like

Thank you Julian, I believe listener will do for me for now and I’ll investigate how to pipe sensor uORB messages to MAVLink once I’m happy with the results so far!

1 Like