Dronekit and mavlink2

Hello,
I am using sitl and dronekit to test some code to retrieve information regarding mission. Right now I want to access the parameters of mavlink message #42 , more specifically the mission_state field, that seems to be a mavlink extension field.
I tried researching this and found it seems dronekit has a bit of problem with dealing with mavlink2, but could only guesses and not solutions.
Can somebody lend a hand? Should I change some parameters in sitl to solve this?

Dronekit has not been maintained in years. I suggest you switch to pymavlink. Pierre has done a great PR that adds examples on how to use it.

You can use dronekit for that.
Here is an example:

Hi, thank you for answering.
I know how to listen to a message and extract their parameter fields, but it seems that when I try to acess a message that has a mavlink 2 extension field, the dronekit doesn’t recognizes it’s field and say the message doesn’t have the extension.
For example, the message #42 MISSION_CURRENT has 3 parameters field, seq, that is not a mavlink 2 extension field, and two others that are (total and mission_state).
If I try to extract any of those two, it gives me an error saying these fields do not exist and if I print the whole message, I only get the seq field.
It seems this happens because dronekit doesn’t automatically recognize mavlink 2 and I can’t figure out how to make it do so.

I am probably going to change to pymavlink in the near future to avoid problems like these, but for now I am going to try to find a solution within dronekit.

So I tried using pymavlink and sitl to get that message, but I still can’t access the mavlink2 extension fields.

Is mavlink 2 active as serial protocol?

At least in sitl, I saw a peter barker’s post if freemem32 from MEMINFO was freemem32 : 131072, then it meant sitl was MAVLINK2, and mine is 131072. Other than that, SERIAL0_PROTOCOL is confirmed to be 2.

In the script using pymavlink, I have the following:

os.environ['MAVLINK20'] = '1'
os.environ['MAVLINK_DIALECT'] = 'ardupilotmega'

but so far can’t get any of the extension fields from MISSION_CURRENT.

Are you sure you are not using serial1?

SERIAL0_PROTOCOL,2
SERIAL1_PROTOCOL,2
SERIAL2_PROTOCOL,2

I connected sitl to mission planner and checked all the serials set as telemetry, and all of them are mavlink2.

For connecting to either script or mission planner, I am using :‘tcp:127.0.0.1:5762’. If I need both at the same time, I also ‘tcp:127.0.0.1:5763’ for the other, normally 62 for the script and 63 for the mission planner. I don’t know if there is other parameter for setting these two as mavlink other than the serials_protocols

I came up with this after seeing a similar code in the discord, but it doesn’t work, but this seems to be the closest one. Also, pymavlink has already been upgraded and all the serial ports for telemetry are set to 2.

#!/usr/bin/env python
import os
os.environ['MAVLINK20'] = '1'
os.environ['MAVLINK_DIALECT'] = 'ardupilotmega'
from pymavlink import mavutil

def wait_heartbeat(m):
    '''wait for a heartbeat so we know the target system IDs'''
    print("Waiting for APM heartbeat")
    m.wait_heartbeat()
    print("Heartbeat from APM (system %u component %u)" % (m.target_system, m.target_system))

mav_conn=mavutil.mavlink_connection('tcp:127.0.0.1:5762')

wait_heartbeat(mav_conn)

mav_conn.mav.request_data_stream_send(mav_conn.target_system, mav_conn.target_component, mavutil.mavlink.MAV_DATA_STREAM_ALL, 1, 1)

while True:
    msg = mav_conn.recv_match(blocking=True)
    if not msg:
        continue
    if msg.get_type() == 'MISSION_CURRENT':
        print("Message: %s" % msg)

so, a development, I tested this with RAW_IMU message, that also has extension fields, and I got the extensions fields. It seems it’s something specific with MISSION_CURRENT.

So, I figured it out, the extension, it has this problem because in the ardupilot repo, at least as recent as March 6, 2023, hasn’t been added to the ardupilot repo.

I suppose it’s not as simply to just modify the common.xml and add the extensions and just compile the firmware, is it?