Connecting BlueROV2 with Python and pymavlink

Hi,

I am trying to connect to BlueROV2 using Python and pymavlink.
I installed Python 3.8 and the pymavlink package with pip command, everything went well.

But when I run this script:

import time
from pymavlink import mavutil

class ROV_Infos:
def init(self, url: string):
print(“ROV_Infos init”)
self.url = url

def connect(self):
    master = mavutil.mavlink_connection(self.url)
    wait_conn(master)

    # Get some information !
    while True:
        try:
            print(master.recv_match().to_dict())
        except:
            pass
        time.sleep(0.1)

if name == ‘main’:
print(“pymavlink.py”)

rov = ROV_Infos('udpin:198.168.2.255:14550')
rov.connect()

I have the error message:

ImportError: cannot import name ‘mavutil’ from partially initialized module ‘pymavlink’ (most likely due to a circular import)

Is there anything else to do after installing pymavlink with pip ?

Thanks,
Regards,
Nico

1 Like

Hi @AWDRONE,

can you inform which version of pymavlink do you have installed ?
You can see it in: pip search pymavlink
Also, please inform the output of the test installation step of our guide.

1 Like

Hi,

The version of pymavlink is 2.4.8 (latest) and python 3.8.2 on windows 10
The test installation seems OK.

Nico

Hi @AWDRONE,

So everything should be correct and ready to use, can you provide a minimum example with a file or via paste.rs - Rocket Powered Pastebin - New Paste ?

The code that you put in your last post has some indentation problems, probably related to the copy-paste.

Hi,

here is my Python script in a file (with .txt extension, because upload a .py extension file is not possible).

pymavlink.txt (1.4 KB)

Nico

Hi @AWDRONE,

There is some problems with your script that does not reproduce the same error message.
I would recommend to check where are you running this script and move it to a folder where there is no other file besides this same script. From the error message that you are describing, it’s probably a file with the same name of the libraries.
As you can see from your previous test, the “test installation” works, so it’s probably a problem in your script/project folder.

Hi,

It works by naming the script file other than with the same name as a library.
thank you,
Now I am trying to run the script at the same time as QGroundControl. If I saw correctly, you must define a new output port via the web interface of the companion. That’s it ?

Nico

The address --out udpbcast:192.168.2.255:14550 is by default in MAVProxy in companion interface.
So I run QGC, then my python script with the connection to the udpin address: 192.168.2.255: 14555
But I have an error message on the connection address :slight_smile:

(The requested address is not valid in its context)

What address should you enter to run the python script in parallel with QGC?

Nico

Hi @AWDRONE,

Please check our documentation and follow the Run pyMavlink on the surface computer comments.

Here is my mavproxy configuration (by default, I haven’t changed anything):

mavproxy setup

So I have the line --out udpbcast:192.168.2.255:14550

Here is my Python script:
ROVPilot.txt (1.4 KB)

If I run the script alone, it works, I have the mavlink messages that appear.
But if I run QGC and then run the script in parallel, QGC works and commands the ROV, but the script does not display anything.
What have I forgotten?

Thanks,
Nico

Hi @AWDRONE,

Sorry if I was not clear, but check what the documentation from the example that I said:

#  If you want to use QGroundControl in parallel with your python script,
#  it's possible to add a new output port in http:192.168.2.2:2770/mavproxy as a new line.
#  E.g: --out udpbcast:192.168.2.255:yourport

You need to add this line, where yourport is the port for your script, to have both running.

OK it works by defining a new connection in the MAVProxy options, with port 14551.

Now I have the mavlink messages that appear when I run my script.
I would like to recover the values ​​of a certain number of parameters (motor gain level, light level, battery level, camera tilt)

For the camera tilt for example, in the message of type NAMED_VALUE_FLOT, there is indeed a CamTilt parameter, but it has the value of the camera tilt when launching the python script, and when I modify the tilt with the radiocommand via QGC, this value does not change.

How to recover the value of these parameters in real time?

Nico

This isn’t working for me. I added the line and used 14551 for the “yourport” number. I think the problem is it’s not updating MAVProxy. When I refresh the page the line i just added goes away. I tried rebooting after I add the line, but that also just deletes the line. I tried clicking “restart MAVProxy” button, but that just greys out both the bottom buttons and nothing actually happens. After 5 minutes or so of nothing happening, I refreshed the page and the line i added disappeared again.

@AWDRONE How did you add the port? I wrote the line, “–out udpbcast:192.168.2.255:14551” in the MAVProxy options box, but it won’t actually update MAVProxy. If I refresh the page, the line I added goes away. If I click “restart MAVProxy” at the bottom of the page, it just greys out the buttons and nothing actually happens. I even tried clicking the reboot button at the top of the page, but when it reboots, the line I just wrote also disappears. How do you actually add the port after typing in the line?

@autery I’ve responded to your post, which is where any further discussion should take place for your issue so we don’t split the topic :slight_smile: