Adding MAVlink channel data

Trying to add a message to MAVlink for the voltage data from the 3.3V ADC port on the Pixhawk. I’ve got the code written, and the libraries stored, but the data isn’t coming through. Wanted to submit my code here just to make sure I’m not making a dumb mistake.

Message file is “adc_report.msg” which already collects voltage data.

.xml file

<?xml version="1.0"?>
	    <message id="160" name="ADC_REPORT">
		    <description> This message encodes voltage data from pins 13 and 14 on the Pixhawk's 3.3V ADC converter.  Data is run through conversion to translate from voltage to degrees.</description>
			<field type="uint8_t" name="AOA"> Angle of attack in degrees.</field>
			<field type="uint8_t" name="SS"> Sideslip angle in degrees.</field>    

Made the libraries with the mavlink generator, submitted them to the specified folders in the firmware and qgroundcontrol. This is the code I used for mavlink_messages.cpp.

class MavlinkStreamAdcreport : public MavlinkStream

const char *get_name() const
return MavlinkStreamAdcreport::get_name_static();

static const char *get_name_static()
	return "ADC_REPORT";

static uint8_t get_id_static()

uint8_t get_id()
		return get_id_static();
static MavlinkStream *new_instance(Mavlink *mavlink)
	return new MavlinkStreamAdcreport(mavlink);

unsigned get_size()

MavlinkOrbSubscription *_sub;
uint64_t _adc_report_time;

/* do not allow top copying this class */
MavlinkStreamAdcreport(MavlinkStreamAdcreport &);
MavlinkStreamAdcreport& operator = (const MavlinkStreamAdcreport &);

explicit MavlinkStreamAdcreport(Mavlink *mavlink) : MavlinkStream(mavlink),

void send(const hrt_abstime t)
	struct adc_report_s adc;

	if (_sub->update(&_adc_report_time, &adc)) {
		mavlink_adc_report_t _msg_adc_report;

		_msg_adc_report.AOA = adc.channel_value[6];
		_msg_adc_report.SS = adc.channel_value[7];

		mavlink_msg_adc_report_send_struct(_mavlink->get_channel(), &_msg_adc_report);


Added the stream list item

new StreamListItem(&MavlinkStreamAdcreport::new_instance, &MavlinkStreamAdcreport::get_name_static,&MavlinkStreamAdcreport::get_id_static),

Enabled the streaming

mavlink stream -r 50 -s ADC_REPORT -u 14556

Is there something I’m missing here? Any help would be appreciated.

What are you doing on the receiving on? Do you have the same version of mavlink?

I’m receiving on qgroundcontrol. Both have up to date libraries, I’ve only added the adc report library to the v1.0 folder and the .xml file for the firmware and qgroundcontrol.

Are you looking in the mavlink inspector? What’s the connection (usb, radio, etc)? Any change it’s actually using mavlink 2? If you have access to the PX4 console you can run mavlink status and check MAVLink version.

Looked into mavlink inspector, but there’s no instructions on how to use it. I’m using a telemetry radio connection. Changed it so the modified libraries are stored in V2.0 and tried again, still no results. I don’t have the tools to get access to the PX4 console.

Just clarifying, I’m looking at qgroundcontrols analyze for the for the data, but in all my tests there were no extra message ids. I do get this message when connecting to the plane.

“unable to save telemetry log telemetry save directory is not set”

EDIT: Looking at QGCExternalLibs.pri, and it is using V2.0.

MAVLINKPATH_REL = libs/mavlink/include/mavlink/v2.0
MAVLINK_CONF = ardupilotmega

Reading another forum post with a similar problem, and they say i need to change MAVLINK_CONF to my directory. Its already looking up the home directory though, so I’m not sure what that means.

Forum post for reference: Receiving custom mavlink message in QGC

EDIT 2: Looked back through mavlink_messages.cpp and the documentation says its for MAVlink 1.0 message formatters implementation. Is this not compatible with V2.0?

Is your new mavlink message in common or a new message definition that includes common?

Its a new message definition file that includes common. Here’s the xml file after I finished playing with it yesterday.

<?xml version="1.0"?>
	<message id="200" name="ADC_REPORT">
		<description> This message encodes voltage data from pins 13 and 14 on the Pixhawk's 3.3V ADC converter.  Data is run through conversion to translate from voltage to degrees.</description>
		<field type="uint8_t" name="AOA"> Angle of attack in degrees.</field>
		<field type="uint8_t" name="SS"> Sideslip angle in degrees.</field>

In that case you’ll need to update QGC to use that message definition, however it needs ardupilotmega so you’ll need include ardupilotmega.xml (which includes common.xml).

I’m not sure how to do that

Which part? In your custom mavlink message dialect replace common.xml with ardupilotmega.xml and regenerate.
In the QGC build system replace MAVLINK_CONF with your own.

Where do I find the mavlink message dialect?

It’s the xml file you created in mavlink.

so rather than saying


I say


Yes that’s right.


Had to change the id to 198 since 200 was taken. Still not getting anything, so just to double check, when replacing MAVLINK_CONF, you mean replace it with the custom folder name (e.g adc_report)?

Yes that sounds right. Are you sure the message is streaming on the PX4 side? Either check in a debugger or simply add a print.

Couldn’t find anything on the debugger, so I updated the MAVlink libraries. Now I can’t get get qgroundcontrol or the PX4 firmware to update. I’m getting similar errors for both.

06:13:13: Running steps for project qgroundcontrol...
06:13:13: Configuration unchanged, skipping qmake step.
06:13:13: Starting: "/usr/bin/make" 
compiling ../qgroundcontrol/src/MissionManager/
In file included from ../../Qt/5.7/gcc_64/include/QtTest/qtest.h:45:0,
             from ../../Qt/5.7/gcc_64/include/QtTest/QtTest:7,
             from ../qgroundcontrol/src/qgcunittest/UnitTest.h:21,
             from ../qgroundcontrol/src/MissionManager/MissionCommandTreeTest.h:13,
             from ../qgroundcontrol/src/MissionManager/
../qgroundcontrol/src/MissionManager/ In member function ‘void     MissionCommandTreeTest::testAllTrees()’:
../qgroundcontrol/src/MissionManager/ error: ‘MAV_CMD_NAV_WAYPOINT’ was not declared in this scope
         QVERIFY(qgcApp()->toolbox()->missionCommandTree()->getUIInfo(vehicle, MAV_CMD_NAV_WAYPOINT) != NULL);
../../Qt/5.7/gcc_64/include/QtTest/qtestcase.h:66:26: note: in definition of macro ‘QVERIFY’
 if (!QTest::qVerify((statement), #statement, "", __FILE__, __LINE__))\
Makefile:89189: recipe for target 'obj/MissionCommandTreeTest.o' failed
make: *** [obj/MissionCommandTreeTest.o] Error 1
06:13:21: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project qgroundcontrol (kit: Desktop Qt 5.7.1 GCC 64bit)
When executing step "Make"

Getting this error in the px4 build

 ‘MAV_CMD_NAV_WAYPOINT’ was not declared in this scope

I noticed in the MAVlink library generation there were two protocols avaliable, 1.0 and 2.0. Started with a clean slate for qgroundcontrol and the firmware, and wrote the new libraries in with the 2.0 protocol. Got a similar result.

@Deafro Did you ever get this working? I’m having the same problem.

I ran into the same problem a while back. I was trying to make my own mavlink message and followed the tutorial but ended up with ‘MAV_something’ - related errors at compile. I spent a while on it and haven’t managed to get it to work with my newly created message so I decided to put message inside an existing .xml file instead.

I found an available ID inside ‘common.xml’, put it there went through the whole process using pymavgenerate to generate new headers (selecting ardupilot xml, because it includes common.xml). That didn’t work either, still failed at compile.

Then I went ahead and used meld on some of the original mavlink library headers and those generated by pymavgenerate. When I compared old and new ‘common.h’ I discovered that a large chunk of code containing declarations for many ‘MAV_…’-something variables was MISSING in the new headers. I don’t recall right now if something was missing in ‘ardupilotmega.h’ as well.

After copying missing declarations for old header file to new header file, both px4 firmware and qgroundcontrol compiled successfully and I am able to receive my mavlink message. From what I am able to tell it would seem that pymavgenerate drops some of the ardupilot-related declarations during creation of new headers, making things fall apart.

1 Like