# Fetching JS\_GAIN value

**URL:** <https://discuss.bluerobotics.com/t/fetching-js-gain-value/13192>\
**Category:** General Discussion\
**Tags:** ardusub, pymavlink\
**Created:** [November 11, 2022, 12:31pm UTC](https://discuss.bluerobotics.com/t/fetching-js-gain-value/13192 "2022-11-11T12:31:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![elchinaslanli](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.bluerobotics.com/elchinaslanli/32/10461_2.png) [@elchinaslanli](https://discuss.bluerobotics.com/u/elchinaslanli)\
**Post date:** [November 11, 2022, 12:31pm UTC](https://discuss.bluerobotics.com/t/fetching-js-gain-value/13192/1 "2022-11-11T12:31:57Z")

</div>

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](https://www.ardusub.com/developers/full-parameter-list.html#jsgaindefault-default-gain-at-boot)). 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 😃 which does not seems so reasonable.

Thanks for the answers in advance.

---

<div class="post-metadata">

**Author:** ![EliotBR](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.bluerobotics.com/eliotbr/32/6937_2.png) [@EliotBR](https://discuss.bluerobotics.com/u/EliotBR)\
**Post date:** [November 11, 2022, 6:36pm UTC](https://discuss.bluerobotics.com/t/fetching-js-gain-value/13192/2 "2022-11-11T18:36:01Z")

</div>

Hi @elchinaslanli,

> [@elchinaslanli](#):
>
> How can I fetch the current joystick gain value?

[This comment](https://discuss.bluerobotics.com/t/reading-current-gain-percentage-and-flight-mode/12303/2) answers your question 🙂

---

<div class="post-metadata">

**Author:** ![elchinaslanli](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.bluerobotics.com/elchinaslanli/32/10461_2.png) [@elchinaslanli](https://discuss.bluerobotics.com/u/elchinaslanli)\
**Post date:** [November 14, 2022, 2:43pm UTC](https://discuss.bluerobotics.com/t/fetching-js-gain-value/13192/3 "2022-11-14T14:43:50Z")

</div>

I combined all the sources you mentioned here: [Reading current gain percentage and flight mode - #2 by EliotBR](https://discuss.bluerobotics.com/t/reading-current-gain-percentage-and-flight-mode/12303/2)

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

```auto
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)

```
