Home        Store        Learn        Blog

[Autonomous BlueROV2] MavLink/Ardusub help

The reason is the time that I need to learn ros, and also make more configuration steps in Raspberry Pi, while in pymavlink I have the reading of telemetry, and I can ARM the ROV. Then if I learn how to send command to the ROV, up/down/move to right, move servo 1 or 2 or 3, turn on lights I will can do everything that I want.
I want in the future use Deep Learning with the BlueROV.

And this is that I need, a simple script that show how move a motor.
This example is about “rotate APMs on bench to test magnetometers”, so, I think use something of this to that I need.

Greetings!

Hi,jwalser. I am following the project acayulao did and I run the scripttest.txt (548 Bytes)
directly on RPI. I got in trouble when adding an output port to mavproxy. I cannot visit the web site http://192.168.2.2:2770/mavproxy. I can just visit http://192.168.2.2:2770. Is there any other solutions to change the line udpin:localhost:9000 to udpout:localhost:9000?
Thank you in advance!

Hi @ggttkl,

Probably you need to update your companion to have access to the mavproxy configuration page.
Go to http://192.168.2.2:2770/system and click in update.

Thx and I solved this problem. However, I came across a new problem.
My companion has updated to version 0.0.10. When I reboot my companion, it failed to get started with the message: /etc/rc.local:4:cd:can’t cd to /home/pi/companion/params[ FAILED ]Failed to start /etc/rc.local compatibility.
Could you please help me with this?
EDIT:solved by copy params to the path

@ggttkl, the last version of companion is 0.0.15.

Hi @ggttkl like @patrickelectric mentioned, the latest is 0.0.15. It sounds like something went wrong during the update that wasn’t handled. Are you able to get to 0.0.15?

I have updated my companion version to 0.0.15 and updated my Ardusub version to v3.6.0 from QGC. Thank you for your help!

Hello, Jacob. sorry to bother.
I am trying pymavlink to manipulate my ROV. And I found a demo code test.txt (624 Bytes)
I am confused about the active button 1, 4 and 8. What do these buttons map?
If I send a positive x value=500, does it mean I push the forward joystick with a half range which based on my own custom model(I installed 8 motors to my ROV with custom model.)
Thank you for your kindness!

This buttons map what is configured in your QGC joystick setup.


The comment says “1, 4 and 8”, or in other way the first, fourth and eighth button. We’ll update the code to be more clear about it.

Yes, you can check the comment in the code that links to MANUAL_CONTROL.

X-axis, normalized to the range [-1000,1000]. A value of INT16_MAX indicates that this axis is invalid. Generally corresponds to forward(1000)-backward(-1000) movement on a joystick and the pitch of a vehicle.

Thank you for your help, and I have made a big step forward on making ROV autonomous. And now, I can use python scripts to control rov directly on Rpi. However, I came across some bugs. The first one is when I used this 新建文本文档.txt (134 Bytes)
to control yaw motion and thrust motion, I found my chan3 value abnormalclipboard
And my rov began to descend rapidly. This bug reminded me of when I used joystick to control ROV on depth hold mode, I push little ascend joystick, the ROV descend slowly. Only when I push a lot ascend joystick, the ROV ascend.
So I wonder if there is any bugs on joystick chan3 input.(z=500 can make chan3_raw=1500)
The next problem I met is I want to make ROV work without QGC connected. But when I do this, after 1s the system protect itselt and disarm the machine. It seems that without a hearbeat from QGC, the system doesn’t work. Could you please give me some advice on how to generate a fake heartbeat signal on Rpi and how to protect the machine without QGC connected.
I would appreciate if you can reply!
Thank you in advance!

Hi,

About your code.

master.mav.manual_control_send(
        master.target_system,
        0,#x
        0,#y
        100,#z
        100,#r
        0)

This is because of some legacy workaround, you need to use your z between -1000 and 1000.

This should not be a problem, you can connect the pixhawk in your computer, start mavproxy (mavproxy.py --master=/dev/ttyACM0 --out=udpbcast:0.0.0.0:14550 --console) and after that run a simple script to arm the vehicle, the vehicle will continue armed after the script finish, you can even restart mavproxy and the vehicle will show as armed :slight_smile:

Can you share your project/code to see what is going wrong ?

I modified the /home/pi/companion/.companion.rc with added one line
sudo -H -u pi screen -dm -S zidingyi /home/pi/companion/scripts/zidingyi.sh
And I write my code in zidingyi.py
clipboard
with
master = mavutil.mavlink_connection(‘udp:192.168.2.2:9001’)
master.wait_heartbeat()
#buttons = 1 << 6
master.mav.manual_control_send(
master.target_system,
0,
0,
0,
0,
buttons)
print(“armed”)
time.sleep(1)
I want my system armed when booting without ethernet connected to PC.
My code works when ethernet connected, while failed with 1s armed and then disarmed without ethernet connected.

Use 0.0.0.0 for your ip address. The 192.168.2.2 address is not assigned until the computer actually connects to the network.

I think the problem was sovled!
Without ethernet connected, I can run the scripts you offered with the modification of ip.

I am not very familiar with Rpi and I even think the QGC safety protection disarm the vehicle:sweat:
Thank you very much for your help!!:grinning:

1 Like

Hi,Jacob
I am considering using 2 RPIs to work at the same time. I connect the the two RPIs by a switch. The ips of the RPIs are 192.168.2.2, 192.168.2.7 respectively. And 192.168.2.2 is conneccted to my laptop QGroundControl. I can login in the RPI by putty ssh whose ip is 192.168.2.7 and does not run ardusub companion software, however, I cannot login the PI by putty ssh whose ip is 192.168.2.2 and runs the companion software. As the photo shows.situation
I am confused about the situation. QGC can received the raw data from RPI1, while RPI1 cannot be login from PC and video stream cannot be received by QGC.
I use a switch because my RPI1 and RPI2 have to communicate with each other.
Are there any communication errors in this scheme?
I beg for your help. Thank you in advance!
ggttkl

Hello jacob
I have worked on making ROV autonomous recently and I succeed in running python scripts in RPI and control ROV with QGC connected. However, when I shut down my QGC and send a command move backward,

def move_backward(speed,timesec):
	print("movement_action")
	master = mavutil.mavlink_connection('udp:0.0.0.0:9000')
	master.wait_heartbeat()
	start_time = time.time()
	flag=1
	while flag :
	    finish_time = time.time()
	    if finish_time-start_time>=timesec:
	        flag=0
	    master.mav.manual_control_send(
	        master.target_system,
	        -speed,
	        0,
	        500,#405
	        0,
	        0)

The ROV will go backward without stopping. In fact, when QGC connected, the backward motion will last for timesec seconds.
I have tried input hold set command to stop the motion. However, only when I set r value will the rotation motion stop.

	    master.mav.manual_control_send(
	        1,#master.target_system,
	        0,
	        0,
	        500,#405
	        -speed,#r
	        0)

Input hold command doesn’t work for stopping descend, ascend, forward and backward motion.
I thought the manual_control_send command worked as the joystick input and they made equal effect, but when QGC disconnected, they were not equal.
Could you please give me some advice on this issue?
Any suggestions will be grateful! Thank you in advance!
EDIT:

def turn_left(master,speed,timesec):
	print("movement_action_left")
	# master = mavutil.mavlink_connection('udp:0.0.0.0:9000')
	# master.wait_heartbeat()
	start_time=0
	finish_time=0
	start_time = time.time()
	flag=1
	while flag :
	    finish_time = time.time()
	    if finish_time-start_time>=timesec:
	        flag=0
	    master.mav.manual_control_send(
	        master.target_system,#master.target_system,
	        0,
	        0,
	        500,#405
	        -speed,
	        0)

parameter master has been transmitted into the function, which is different from the backward function.

Hello,

The ROV will go backward without stopping

Check if the code will exit from this loop, what is the value of timesec that you are using ? Can you send us your full code via github or pastebin ?

when QGC connected, the backward motion will last for timesec seconds.

Yes, QGC is sending manual_control messages also, that’s why, both messages have different control inputs.

Can you try our pymavlink examples in ardusub.com ? They were all tested and should work in your setup.

# Import sys and time
import sys
import time

# Import mavutil
from pymavlink import mavutil

# Create the connection
master = mavutil.mavlink_connection('udp:0.0.0.0:14550')
# Wait a heartbeat before sending commands
master.wait_heartbeat()

# Send a positive x value for 5 seconds.
# http://mavlink.org/messages/common#MANUAL_CONTROL
i = 0
while i < 10:
        master.mav.manual_control_send(
            master.target_system,
            500,
            0,
            0,
            0,
            0)
        time.sleep(0.5)
        i += 1

sys.exit(0)

I tested this example, this’ll make your vehicle go forward for 5 seconds and stop to actuate. You should run this without QGC running in background.

Hi,
Sorry for my late response. I tested your code in my ROV without QGC connecting and I found my ROV works different from yours. Once I run the code in a manual mode, the machine would be active even though the python program had finished.
And when I armed the machine in depth hold mode, only the first manual_control_send function would be effective.
I cannot figure out why my result is different from yours. Is there any possiblility that my configurations have something wrong? I will upload my code a few days later.
Thank you for your response!

Please, let’s see the code, and maybe a video too to make it clear the behavior that you are observing.

from pymavlink import mavutil
import time
#Create the connection
master = mavutil.mavlink_connection('udp:0.0.0.0:9000')
master.wait_heartbeat()
print(master.target_system)
buttons = 1 << 6
master.mav.manual_control_send(
    master.target_system,
    0,
    0,
    0,
    0,
    buttons)
print("armed")
time.sleep(1)
master.mav.manual_control_send(
    master.target_system,
    100,
    0,
    500,
    0,
    buttons)

This is my test code. I use xshell.exe to login RPI and run this code.

I fail to find the location to upload the video so I transfer the video to gif.9979cc137ea0d95189caa53b45bbab4e
The problems are:

  1. The action should be a instant forward movement while the machine move forward all the time.
  2. The machine should be stopped after the code finished while it isn’t.
    The machine move forward even though the code have finished.