Adding a message (having trouble with the guide)

Hi,
I’ve followed the guide dev.ardupilot.com/wiki/apmcopter-code-overview/code-overview-adding-a-new-mavlink-message/) for adding a new MavLink message, but I’m unsure how I go from there to being able to see my message on MavProxy or Mission Planner. My current message is simple – it has one field, which is an int, and my goal is to have the int display on some GCS. I’ve gotten through step 4 just fine so far, but am stuck on step 5. Here’s what I’ve done so far:

  1. I created a send_test_message function, which simply takes a pre-defined uint8_t = 8 and sends it to the mavlink_msg_test_message_send function

  2. I then updated the try_send message with the case(TEST_MESSAGE), where I checked the payload to see if my message fits and then called the send_test_message function

I didn’t update anything else and don’t know if I need to or not. The problem I’m currently having is that I can’t see my output anywhere on Mission Planner or MavProxy. I want to basically be able to open the parameters list and see my test variable there, but it’s not showing up at all. I’m at a crossroads at this point and have no idea what to do. Any advice would be highly appreciated

bump

I struggled with this a bit myself. I only found out how to show it in MAVProxy, not in a GCS.

To show a new (custom) mavlink message in MAVProxy, you have to tell it somewhere that it should print that message (and how it should be formatted).

For this, you first have to update your MAVLink installation on your computer to include the new message as well:

[ol][li]Clone github.com/mavlink/mavlink to your PC[/li]
[li]Add your new message to the proper definition-file (/message-definitions)[/li]
[li]Cd to /pymavlink[/li]
[li]run python setup.py install[/li][/ol]

Next, the easiest is to write a simple module that catches the message and dumps it to the screen:

#!/usr/bin/env python
'''Custom'''

import time, os

from MAVProxy.modules.lib import mp_module
from pymavlink import mavutil
import sys, traceback

class CustomModule(mp_module.MPModule):
    def __init__(self, mpstate):
        super(CustomModule, self).__init__(mpstate, "Custom", "Custom module")
        '''initialisation code'''

    def mavlink_packet(self, m):
        'handle a mavlink packet'''
        if m.get_type() == 'MY_CUSTOM_PACKET':
            print "My Int: %(x).2f" % \
                {"x" : m.intField}

def init(mpstate):
    '''initialise module'''
    return CustomModule(mpstate) 

Put that file in a file called custom.py (or whatever you call your module) and copy it to your MAVProxy modules (for me on windows it is here: C:\Python27\Lib\site-packages\MAVProxy\modules).

Restart MAVProxy and type module load custom to load your module.
Anytime you now receive that message, mavproxy will print it.

To display it in MissionPlanner (or another GCS), you will have to make a similar modification. I however do not know how.

A simpler, but more hacky, solution which will show it in both MAVProxy and MissionPlanner, is to send a statustext message with high severity instead of a custom mavlink message:

gcs_send_text_P(SEVERITY_HIGH, PSTR("My message"));

These will automatically be printed to MAVProxy and on the artificial horizon in MissionPlanner.
Including integers in your message is a bit harder. You’ll have to modify gcs_send_text_fmt to use a different priority and then you could use something like:

gcs_send_text_fmt(PSTR("My Int: %d"), 2);

Note that unlike gcs_send_text_P this function only uses 1 buffer. Trying to send too many message in short succession can cause messages to be skipped