Fetching JS_GAIN value

I combined all the sources you mentioned here: Reading current gain percentage and flight mode - #2 by EliotBR

And the code is working, thank you very much. I am putting my final code below:

from pymavlink import mavutil
import time
# connect to vehicle
# Create the connection
master = mavutil.mavlink_connection('udp:192.168.2.1:14880')
# Wait a heartbeat before sending commands
master.wait_heartbeat()


message_types = {'NAMED_VALUE_FLOAT'}
def handle_named_value_float(msg):
    if msg.name == 'PilotGain':
        print(f'Gain is {msg.value:.2%}')

message_handlers = {
    'NAMED_VALUE_FLOAT': handle_named_value_float,
}

def handle_message(message):
    type_ = message.get_type()
    if type_ in message_handlers:
        message_handlers[type_](message)
    else:
        print(type_)

while True:
    message = master.recv_match(type=message_types, blocking=True)
    handle_message(message)
1 Like