How to start with ardusub and python script?

Hello,

I’m working and a BlueROV2 since one month as a part of a project. I have to developpe some function and integrate new components on the ROV and QGC layout. I have now, I think understand how the ROV works.

I’m actually trying to control the ROV with Ardusub and python script on the Rpi. I’m asking some help because the control of the outputs seems to be quite hard to understand. I have read the pymavlink documentation and many ardusub documentation too. I have try the exemple " Run pyMavlink on the companion computer" it was working perfectly.

In a first time I’m trying to just to turn on the light, I have made this from exemple :
python

It compile, I have no error but it doesn’t work do I have to make a loop to make it work?
Have I choose the good channel for the lights? The channels output aren’t the same in Ardusub documentation and in QGC. Channel 7 for QGC and 9 for Ardusub.

Working on the BlueROV2 is very interresting but the quantity of thing needed to be learn is big, I might have miss many point in my learning. I’m open to any advice you could give me. Have a good day

Clément

Hi Clément,

The first screenshot is from “Output Channels” and the second screenshot from “Input Channels”, you can check that reading the title from the first screenshot and the title of the section in our documentation from the second one.

Please, check our working examples here for further help, take some time to read and test each one, also, do not forget to read the comments and documentation for each sample.

Hello Patrick,

Thank you for your answer, indeed my question about channels stupid I didn’t take the time to think about it before posting.

Just after posting my post I have tried the other exemple with the pymavlink lybrarie on my ROV. The exemple " Send Manual Control" seems to be better than " Send RC (Joystick)" for my problem but now I have this problem :

I have tried with the ROV connect to my pc with QGC open and close and launch from the RPi with the ROV disconnected from the pc but in each case I had this error. Any idea?

This is the second time I ask for help in this forum, and that the second time I see afterwards that I miss a lot of knowledge about the ROV. Thank you for your help.

Hi Clément,

It appears that you hit Ctrl+C in this terminal, resulting in the end of the script while the wait_heartbeat was running, the result is the backtrace in your terminal.
Did you check the first example of Run pyMavlink on the companion computer ?

Before running any other script, you should test Run pyMavlink on the surface computer and Run pyMavlink on the companion computer, this examples provide the necessary information to how and what to do with the next examples available, configuration may be necessary.

Hello,

After a day of test I finnaly achieved to turn the lights on. This is my code I have some questions about it.

The script only work when I boot the ROV without opening QGC, if QGC is open I can’t use it and if the script is use and QGC is launched after that. QGC will be displaying the video stream but he will say can’t connect to the vehicule. Do I have to add something to my script?

buttons = 1 << 12

# To active button 0 (first button), 3 (fourth button) and 7 (eighth button)
# It's possible to check and configure this buttons in the Joystick menu of QGC
buttons = 1 + 1 << 3 + 1 << 7

I need some explanation about this point, it is written " To active button 0 (first button), 3 (fourth button) and 7 (eighth button)". The “id” of the button 0 seems to be 1 some the id off the button 12 should be 13 no ?

What is the +1 for? I tried with it but I didn’t see something different.

The exemple show how to use the button 0 then 3 and then 7. But when I tried to use the function light_brighter 2 times in a row because I need to do it with the joystick to turn the light on I had an error.

My QGC controls:

control

Hi,

Yes, this is explained in the documentation and example provided, did you check our documentation ?

From Run pyMavlink on the surface computer:

# Create the connection
#  If using a companion computer
#  the default connection is available
#  at ip 192.168.2.1 and the port 14550
# Note: The connection is done with 'udpin' and not 'udpout'.
#  You can check in http:192.168.2.2:2770/mavproxy that the communication made for 14550
#  uses a 'udpbcast' (client) and not 'udpin' (server).
#  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

If you want to use the 12 button, or lights1_cycle in your QGC screenshot, you should use 1 << 12, to select the 12th bit in the bitfield.

the << operator is a logical left shift, to understand why the +1, you should read this wikipedia article.

Can you say what kind of error are you facing ?

Hi,

Thank a lot for your aswer. I’ll try to add a the new port, “I had found an other method, at the beginning and at the end of my script I restart mavproxy and it work perfectly. Is that a viable method?

EDIT: The new port is added and it work well, I can run the light script in background and change mode too while using qgc

I managed to understand bits shiffting.

I have a last question, can I run a python script who make the light blinking while the ROV is on surface mode? Or I have to edit the mode surface? I want to upgrade the failsafe for for light inspection.

Have a good day.

Clément

Yes, you can.