Fetching JS_GAIN value

Hi there,

As I mentioned in previous discuss post, I am developing some basic ROV GUI for operations.

I succeed on sending custom joystick commands to Ardusub with pymavlink library.

I’m able to perform all necessary actions including increasing and decreasing joystick gain and I am able to change and read respective parameters related to JS_GAIN (Full Parameter List · GitBook). Furthermore I need to fetch the current joystick gain value to show it on my custom GUI.

How can I fetch the current joystick gain value? Is it possible? I searched for this value both in parameters and mavlink messages cannot find anything.

If it is not possible to fetch, I will calculate it by button count on ground control station :smiley: which does not seems so reasonable.

Thanks for the answers in advance.

Hi @elchinaslanli,

This comment answers your question :slight_smile:

1 Like

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