Integration of custom sensor in PixHawk/ArduCopter

We have a custom sensor that emits an ASCII data stream via UART, approx. 5290 Bytes/sec. Our customers would be flying our sensor on PixHawk drones, but our sensor is not involved in flight control. We would like to have the data logged to SD card on the PixHawk, and possible streamed in real time using radio connection from the drone. A requirement is to have our custom sensor’s data acquired and synced with the usual GPS, accelerometer, and magnetometer data for display in Mission Planner.

I have already tried integrating into ArduCopter code to capture this sensor data and save to dataflash log, and could review the data in Mission Planner. (I modeled this integration of our sensor using AP_Baro implementation.) However in testing, I am seeing gaps in my saved data, indicating that my code might be taxing the real-time capability of the system and so perhaps interfering with flight control or some other functions.

Therefore I am now rethinking whether this approach is sound, and asking for suggestions for the best way to implement this. It occurs to me that if the requirement is to only acquire, save and transmit our sensor data with position, time, accelerometer, etc., that it could make sense to use a second PixHawk only for sensor data acquisition. Is that possible? Is there a better way to accomplish our requirements?

Thanks,
John

If a baud rate of 115200 is sufficient for your sensor data then the overhead should be similar to a 2nd GPS and not a problem. You could always use a cheap arduino board as a companion and log your sensor data and other required parameters with that. I have interfaced numerous sensors with the Pixhawk this way

Thx jimovonz.
Sensor ASCII data is at 115200, however byte rate is higher than GPS so my Ardupilot code to convert sensor values to int and log to dataflash slowed down the PixHawk firmware.

In the scenario you describe, the companion computer gets MAVLink data from the Pixhawk, is that correct? Then I could log it all on the companion computer?
Is that how you did it?

Hi John,

I believe that the Ublox GPS can saturate the serial bandwidth at 57600. You can monitor the PM (performance monitoring) entry from the log to see what effect your additional processing is having. Most of the extra sensors I have used have been fairly low bandwidth and I have no trouble processing and logging the data directly on the Pixhawk. This is obviously the most convenient. I did have one case where I had multiple SPI devices with lots of data where I used an arduino nano with SD card module (~$10 for both) and used a mavlink connection to sync timestamps then just logged the additional sensor data with timestamp so I could integrate all the Pixhawk log data post mission.

Just to make sure I understand your example of multiple SPI sensors, you logged that data to a local SD card, then integrated as a post-processing step with the sensor data in the dataflash log?

This approach is very attractive because our sensor platform already logs our sensor data (only) to SD card with a uS timestamp. How did you accomplish alignment of the data records with the MAVLink connection?

I could see how to align if there is some way to send a “start recording” event that appears in both of the data logs. Is that possible? And the clocks in PixHawk and the companion computer may drift over the measurement interval.
Is there an example of how to do the sync of the 2 systems with MAVLink connection?

John

Yes, you understand correctly. Absolute time accuracy was not so critical in my case - certainly any drift between systems in the interval of interest was not a factor. From memory I used CMD/ACK intervals as an indication of latency and then noted the SYS_TIME to match the logged times. Obviously you need to use a cmd with low overhead or account for execution time. Unfortunately the PING mavlink cmd is not implemented in Ardupilot (easy enough to implement I suppose - especially if you just hijack an existing unused cmd…).

Dear John, we are looking for the same thing: We have an external sensor (RS232, 57600 baud), and we would like to stream the data of this sensor to a ground station, together with the position, speed, heading, roll+pitch attitude of our flying pixhawk2.1.
Did you find a solution for your problem? We are even considering to add another wireless serial module to the Copter and to the groundstation, just to stream the data of our sensor to the ground. But I guess there is a more elegant solution for this…