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.