[Autonomous BlueROV2] MavLink/Ardusub help

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.

No, you need to tell the machine to stop with your code.

Something strange is when my QGC is connected, the machine will have a instantaneous forward movement action and then stop. While when my QGC is not connected, the machine will move all the time without stop.

Do you have a joystick connected to the computer running QGC, or the virtual joystick setting turned on?

I don’t have a joystick connected to the computer running QGC.
I think the master.mav.manual_control_send function is kind of virtual joystick. So when I call this function, I send an instantenous virtual joystick input to the machine.
I don’t know what kind of virtual joystick you mean. Is there any other forms of virtual joystick setting?

No, I think you are doing it right. I just want to make sure that QGC is not also sending MANUAL_CONTROL. Virtual joystick is to use touchscreen in QGC.

Show me exactly the code you are running with QGC to get this behavior. Let me know the version of QGC, companion, and ArduSub please.

My project is still on working, so I want to keep it private until it finish. Can you give an email address so that I can send you the code I am working on?
I will share my project on github when it accomplish my goal.


%E5%9B%BE%E7%89%87

Try using ArduSub v3.5.3 (stable). Email support@bluerobotics.com.

Hello Jacob
I sent my email to your support address a week ago. Have you received my attachment? If any details unclear, I can explain.
Hope for your reply.
Thank you for your help!

I’m sorry I missed it. Please send it again.

hello, is your project finished? I need this spin. We designed a 4-engine vehicle, but we have a different configuration. We want it to autonomously draw a circle. What can we do.

A post was split to a new topic: Pymavlink SET_POSITION_TARGET with velocity