Home        Store        Learn        Blog

Set Thrusters To Run With A Pilot Input Gain Less Than 25%

Hi all,

I wish to control the BlueROV2 thrusters with Pymavlink with a pilot input gain less than 25%.

I’ve reference the following hyperlinks:

https://www.ardusub.com/developers/full-parameter-list.html#jsgaindefault-default-gain-at-boot

http://www.ardusub.com/developers/pymavlink.html#read-and-write-parameters

http://www.ardusub.com/developers/pymavlink.html#read-all-parameters

https://mavlink.io/en/messages/common.html#PARAM_VALUE

https://mavlink.io/en/messages/common.html#PARAM_SET

I tried setting the JS_GAIN_DEFAULT parameter to 0.1 with the following function:

But when I read all parameters with the following:

The output of the JS_GAIN parameter settings was this:

It’s not clear to me why the JS_GAIN_DEFAULT parameter didn’t change.

I’d appreciate the assistance.

-Cameron

%d is an integer format-specifier so it’s rounding whatever value it gets to the nearest integer. Your parameter is a float, so you want to use %f instead (or you can use e.g. %.3f if you want a float with three decimal places).

Even better, if you’re using Python 3 you can use f-strings, and if you’re using >= Python 3.8 you can use the equals formatting that can help make things a bit clearer:

        message = master.recv_match(type='PARAM_VALUE', blocking=True).to_dict()
        name, value = message['param_id'], message['param_value']
        print(f'{name = }\t{value = :.3f}')

By the way, where possible it’s preferred for code to be posted as code blocks, so it can be directly copied for testing. There are instructions for how to do that in the Formatting a Post/Comment section of the “How to Use the Blue Robotics Forums” pinned post :slight_smile:

EDIT: More generally, those two examples could do with an update, so I’ve raised a github issue about that here:

Hi Eliot,

I took your input and edited my code for reading out the parameters, as presented here:

import time
import sys

# Import mavutil
from pymavlink import mavutil

# Create the connection
master = mavutil.mavlink_connection('udpin:0.0.0.0:505')
master.wait_heartbeat()  # Wait a heartbeat before sending commands or trying to send or recieve new data
print("Heartbeat from system (system %u component %u)" % (master.target_system, master.target_system))
# Wait a heartbeat before sending commands
master.wait_heartbeat()

# Request all parameters
master.mav.param_request_list_send(
    master.target_system, master.target_component
)

while True:
    time.sleep(0.01)
    try:
        message = master.recv_match(type='PARAM_VALUE', blocking=True).to_dict()
        name, value = message['param_id'], message['param_value']
        print('name: %s\tvalue: %.3f' % (message['param_id'], message['param_value']))
        
    except Exception as error:
        print(error)
        sys.exit(0)

The read parameters from ArduSub made more sense. I couldn’t compile my code with the “python3” command. I followed the installation guide; GitHub - ArduPilot/pymavlink: python MAVLink interface and utilities My python version is 2.7.16 and python3 version is 3.9.7. It’s clear that Pymavlink assumes the command “python” is my path.

By the way, I also read your instructions on How to Use the Blue Robotics Forums (Please Read).

Thank you!

Cameron

This is redundant - you extract the name and value into variables, and then extract them again instead of using the variables you just defined. You can either do just

        message = master.recv_match(type='PARAM_VALUE', blocking=True).to_dict()
        print('name: %s\tvalue: %.3f' % (message['param_id'], message['param_value']))

or you can use the extracted values

        message = master.recv_match(type='PARAM_VALUE', blocking=True).to_dict()
        name, value = message['param_id'], message['param_value']
        print('name: %s\tvalue: %.3f' % (name, value))

Different versions of python don’t have access to the same libraries. If you want to use pymavlink with python3 and you’re not using a utility like python-is-python3 (mentioned in the installation guide) then you can install it using the python3 command instead of python (e.g. if you installed with

sudo python -m pip install --upgrade pymavlink

you can instead use

sudo python3 -m pip install --upgrade pymavlink

to install it for Python 3).

Glad to hear it - hope that’s helpful! :slight_smile:

Thank you Eliot! I appreciate the extra input. I successfully installed the pymavlink with python3 using

sudo python3 -m pip install --upgrade pymavlink

and my code compiled with the edits you suggested when using >= Python 3.8

  message = master.recv_match(type='PARAM_VALUE', blocking=True).to_dict()
        name, value = message['param_id'], message['param_value']
        print(f'{name = }\t{value = :.3f}')

As a side note, I suggest that

sudo python3 -m pip install --upgrade pymavlink

be written into the installation guide.

Thank you again!

-Cameron