T2000 thruster control using Mavlink and Python

Hi,

I am using Python code to control the individual thrusters of our AUV. It has 8 thrusters, 4 vertical and 4 horizontal. How can I control the thrusters manually 1 by 1, using Python code?

Also, if there is any other way to control, please mention it. I have tried several approaches, and I have also used some code I found in this community, but none of them have worked.

This is the code I was using:

from pymavlink import mavutil
import time

# Connect to Pixhawk
print(“[INFO] Connecting to Pixhawk…”)
master = mavutil.mavlink_connection(‘udpin:0.0.0.0:14550’)
master.wait_heartbeat()
print(f"[INFO] Connected to system {master.target_system}, component {master.target_component}")

# Set mode to MANUAL
mode_mapping = master.mode_mapping()
if ‘MANUAL’ not in mode_mapping:
    raise Exception("\[ERROR\] MANUAL mode not available in mode mapping.")
mode_id = mode_mapping[‘MANUAL’]
master.set_mode(mode_id)
print(“[INFO] Set to MANUAL mode.”)
time.sleep(1)

# Arm the vehicle
print(“[INFO] Arming the vehicle…”)
master.arducopter_arm()
master.motors_armed_wait()
print(“[SUCCESS] Vehicle armed.”)

# RC override array: 8 channels + 10 spares
rc_override = [1500] * 8 + [65535] * 10

# Apply forward thrust – adjust channels based on your config
# Assuming Thrusters 5 and 6 (MAIN OUT 5 and 6) = index 4 and 5
rc_override[1] = 1550  # Forward thrust
# rc_override[2] = 1550
# rc_override[2] = 1700
# rc_override[3] = 1700

print(“[ACTION] Rolling for 5 seconds…”)
start_time = time.time()
while time.time() - start_time < 8:
    master.mav.rc_channels_override_send(
        master.target_system,
        master.target_component,
        *rc_override
    )
    time.sleep(0.1)

# # Stop motion

# rc_override[4] = 1500
# rc_override[5] = 1500
# master.mav.rc_channels_override_send(
#     master.target_system,
#     master.target_component,
#     *rc_override
# )
# print(“[INFO] Motion stopped.”)

# Disarm the vehicle
print(“[INFO] Disarming the vehicle…”)
master.arducopter_disarm()
master.motors_disarmed_wait()
print(“[SUCCESS] Vehicle disarmed. Done.”)

WHEN I RUN THIS CODE, ALL THE VERTICAL THRUSTERS RUNS ONLY.

Hi @radwan

Ardusub does not support actuating individual thrusters like this! You can simulate user control input via higher level commands, like going up or forward, but not running each motor individually… sorry for the news! There are some “hacky” workarounds, that I would not recommend trying…. searching the forum is always a good first step!

1 Like

Thank you.

Anyway can you please help me with the AUV movement? Like basic movements: Forwards, Backward, Left, Right.

Should I control all these movements using the rc_override = ___ ?

Hi @radwan
Yes, that’s correct - you command overall vehicle motion with the appropriate RC_Override commands. Can you share more about your goals for control? A lua script may be a good solution, or something with pymavlink as you’re doing…

1 Like

Sorry for the late reply. So I was doing some unit testing like diving, going forward, then coming back to the surface. Here are some demo:
```
print(“[ACTION] 1. Diving DOWN for 4 seconds.”)

set_neutral()

rc_override[0] = 1430

rc_override[1] = 1430

# rc_override[2] = 1350

# rc_override[3] = 1350

start_time = time.time()

while time.time() - start_time < 4:

send_rc_override()

time.sleep(0.1)

``
```
print(“[ACTION] 3. Moving forward for 10 seconds at 1600 PWM…”)

set_neutral()

rc_override[4] = 1600

rc_override[2] = 1520

start_time = time.time()

while time.time() - start_time < 30:

send_rc_override()

time.sleep(0.1)

```

But the issue I am facing is that it’s moving randomly. Can you give some ideas? I am using 8 thursters, 4 horizontally 45 degree angle placed, and 4 vertical.
``
I am using the Bar30 pressure sensor, Pixhawk’s internal sensors.
```

Hi @radwan -

What mode is the vehicle in? If in Manual, it won’t automatically try to hold heading, and so can move a bit randomly without user input compensation. You may also need to calibrate your motion sensors?

This is my full code:
`
from pymavlink import mavutil

import time

# -----------------------------

# Connect to Pixhawk

# -----------------------------

print(“[INFO] Connecting to Pixhawk…”)

master = mavutil.mavlink_connection(‘udpin:0.0.0.0:14550’)

master.wait_heartbeat()

print(f"[INFO] Connected to system {master.target_system}, component {master.target_component}")

# -----------------------------

# Set mode to MANUAL

# -----------------------------

print(“[INFO] Setting mode to STABILIZE…”)

mode_mapping = master.mode_mapping()

mode_id = mode_mapping[‘STABILIZE’] # Change to STABILIZE for better control

master.set_mode(mode_id)

print(“[SUCCESS] Mode set to STABILIZE”)

time.sleep(2)

# -----------------------------

# Arm the vehicle

# -----------------------------

print(“[INFO] Arming the vehicle…”)

master.arducopter_arm()

master.motors_armed_wait()

print(“[SUCCESS] Vehicle armed.”)

# -----------------------------

# RC override: 8 channels + 10 unused

# -----------------------------

rc_override = [1500] * 8 + [65535] * 10

def send_rc_override():

"""Send the current RC override values"""

master.mav.rc_channels_override_send(

    master.target_system,

    master.target_component,

    \*rc_override

)

def set_neutral():

"""Set all channels to neutral position"""

for i in range(8):

    rc_override\[i\] = 1500

# -----------------------------

# MISSION SEQUENCE START

# -----------------------------

# 1. DIVING (DOWN) for 3s at 1700 PWM

print(“[ACTION] 1. Diving DOWN for 4 seconds.”)

set_neutral()

rc_override[0] = 1430

rc_override[1] = 1430

# rc_override[2] = 1350

# rc_override[3] = 1350

start_time = time.time()

while time.time() - start_time < 4:

send_rc_override()

time.sleep(0.1)

# 2. REMAIN IDLE for 2s

print(“[ACTION] 2. Remaining idle for 2 seconds…”)

set_neutral()

start_time = time.time()

while time.time() - start_time < 1:

send_rc_override()

time.sleep(0.1)

# 3. FORWARD for 5s at 1600 PWM

print(“[ACTION] 3. Moving forward for 10 seconds at 1600 PWM…”)

set_neutral()

rc_override[4] = 1600

rc_override[2] = 1520

start_time = time.time()

while time.time() - start_time < 30:

send_rc_override()

time.sleep(0.1)

# 4. REMAIN IDLE for 2s

print(“[ACTION] 4. Remaining idle for 2 seconds…”)

set_neutral()

start_time = time.time()

while time.time() - start_time < 2:

send_rc_override()

time.sleep(0.1)

# -----------------------------

# MISSION COMPLETE - STOP ALL MOTION

# -----------------------------

print(“[INFO] Mission sequence complete. Stopping all motion…”)

set_neutral()

send_rc_override()

# Clear RC override

rc_override = [65535] * 18

send_rc_override()

print(“[INFO] RC override cleared.”)

# -----------------------------

# Disarm the vehicle

# -----------------------------

print(“[INFO] Disarming the vehicle…”)

master.arducopter_disarm()

master.motors_disarmed_wait()

print(“[SUCCESS] Vehicle disarmed. Mission complete.”)

# Close connection

master.close()

print(“[INFO] Connection closed.”)
`