Talk with an embedded python script with mission planner

Hi everyone, thank you for this wonderfull forum I found a lot of answers in there!

I have a surface boat drone. On board, I have rpanion running, it is connected to pixhawk and forward telemetry of the drone to udp 14550. Now I also have a pymavlink script on board that is running and connected to the pixhawk. I send orders such as mode changes, manual joystick control, and do set servo orders with mission planner and they are received by the drone.

I tried to read those messages with my pymavlink script and i couldn’t do it. I only get command_ack messages from pixhawk but I can’t access all details (like the servo and pwm) that are sent in command_long messages. Here’s my script, if someone can help me it would be really nice ! I wonder if maybe i should connect with a source_system but I am not sure…
My goal is to be able to send 8 different orders from mission planner to my script so if there is an easier solution than do_set_servo I take all advices !


# connect to vehicle
# vehicle = utility.mavlink_connection(device="tcpin:127.0.0.1:5765")
vehicle = utility.mavlink_connection(device="udp:0.0.0.0:14560")

vehicle.wait_heartbeat()

print("Connected to system:", vehicle.target_system, ", component:", vehicle.target_component)

liste_id_auvs = [51,52,53]

# liste_msg_pas_interessants = ["ATTITUDE",
#                               "SIMSTATE",
#                               "TERRAIN_REPORT",
#                               "SCALED_IMU3",
#                               "RANGEFINDER",
#                               "GIMBAL_MANAGER_STATUS",
#                               "DISTANCE_SENSOR",
#                               "GPS_RAW_INT",
#                               "HEARTBEAT",
#                               "SCALED_PRESSURE",
#                               "EXTENDED_SYS_STATE",
#                               "HOME_POSITION",
#                               "NAV_CONTROLLER_OUTPUT",
#                               "RC_CHANNELS",
#                               "MISSION_CURRENT",
#                               "SERVO_OUTPUT_RAW",
#                               "GPS_RTCM_DATA",
#                               "GPS2_RAW",
#                               "RAW_IMU",
#                               "TIMESYNC",
#                               "GLOBAL_POSITION_INT",
#                               "RC_CHANNELS_SCALED",
#                               "SYSTEM_TIME",
#                               "SYS_STATUS",
#                               "MEMINFO",
#                               "POWER_STATUS",
#                               "EKF_STATUS_REPORT",
#                               "LOCAL_POSITION_NED",
#                               "VIBRATION",
#                               "POSITION_TARGET_GLOBAL_INT",
#                               "BATTERY_STATUS",
#                               "AHRS2",
#                               "VFR_HUD",
#                               "AHRS",
#                               "GPS_GLOBAL_ORIGIN",
#                               "NAMED_VALUE_FLOAT",
#                               "SCALED_PRESSURE2",
#                               "GIMBAL_DEVICE_ATTITUDE_STATUS",
#                               "SCALED_IMU2",
#                               "SCALED_PRESSURE3",
#                               "",
#                               "PARAM_VALUE"]

while True:
    #msg = vehicle.recv_match(type='COMMAND_LONG', blocking=True, timeout=1)
    msg = vehicle.recv_match(blocking=True)
    
    # if msg.get_type() not in liste_msg_pas_interessants:
    
    print(msg)

    if msg.get_type() == "COMMAND_LONG":
        if msg.command == 183 :
            servo_number = int(msg.Instance)   
            servo_pwm = int(msg.param2)     

            print(f"DO_SET_SERVO reçu → Servo {servo_number} = {servo_pwm} µs")

    if not msg:
        continue

    target = getattr(msg, 'target', None) or getattr(msg, 'target_system', None)
    if target not in liste_id_auvs:
        continue

I assume your telemetry radio is connected directly to the flight controller, and the companion computer is just connected to another telemetry port.
IN this case, commands that are directed to the flight controller are not brodcasted/forwarded out again.
You need either a mavlink router component that resides between flight controller and telemetry link and route the all incoming commands to the companion computer as well.
Or you can write a LUA script that listens for commands and forward them to the companion computer. (Your script will need to set it’s component id and system id correctly and send out heartbeats)

my setup is the following pixhawk - raspberry pi (rpanion forwards messages to udp 14550 for Mission planner AND TCP 127.0.0.1:5760 for my embedded script). A mavlink router would replace the rpanion ?

So do i understand correctly, you want to set pixhawk - raspberry pi (mavlink router connects to pixhawk and forwards all to script and MP) ? how should I set the source_system and source_component of this mavlink router, and of my script ?

I used LUA before so I am ready to use it if necessary. So what you propose is lua on the pixhawk that receives all commands and forward to script using something like STATUSTEXT message ?

Thank you for this quick answer !

hello,

Check on rpnion, I think it is using mavproxy to do the routing, so your script only get the messages that are for it and not the own from your fcu.

I think it uses mavlink router and not mavproxy, but maybe i am mistaking. Is it the same problem ? Then what do you recommend ? is it possible for my script to have the same id as my drone to listen the messages that arrives ?
Sorry if those are dumb questions ahaha

Well I tried
vehicle = utility.mavlink_connection(device=“tcp:127.0.0.1:5760”, source_system= 255, source_component=190)
vehicle = utility.mavlink_connection(device=“tcp:127.0.0.1:5760”, source_system= 1, source_component=1)
vehicle = utility.mavlink_connection(device=“tcp:127.0.0.1:5760”, source_system= 51, source_component=1) (sysid of my drone)

but none of them worked.

how can we route all incoming commands (and not only the ack) ?