Controlling T200 thrusters using pymavlink

Hi, I am a beginner trying to control T200 thrusters using pymavlink python. How can i make my thrusters move forward, backward, downward and so on. I tried using rc_channel_override_send() but i got some error saying that 11 or 12 positional arguments required but 21 were given. I tried using set_servo_pwm() but it didnt work. And is there any way to make my auv move to certain distance for eg: if 5m forward command were given then my auv should go 5m forward.

I am using Jetson Nano, Pixhawk 2.4.3, Ardusub 4
Communicating nano and pixhawk using usb connection.
Thank you!

Update!
Now i can control my thrusters using manual_control() but i can give movement commands with a delay of 2 seconds, command without delay is not executed. Exact 2 seconds delay is required for to run thrusters constantly. how can i change the delay?

I searched for this problem in this entire forum i couldn’t get it solved.

i can give movement commands using manual control but with a delay of 2 seconds, command without delay is not executed. Exact 2 seconds delay is required for to run thrusters constantly. how can i change the delay?

delay is given in the while loop

@EliotBR
P.S: mentioning someone because no one answered my previous post and my old post been posted about week ago

Hey,

How are you getting the python commands to the ESCs for the thrusters? We need a lot more info about your system architecture to be able to help.

Are you running ROS (1or 2)?
MavRos?
Python to some PWM controller?

Hi @jagajith23, welcome to the forum :slight_smile:

Apologies for the delay on responding to this - I’m travelling at the moment along with several other members of the team, which has made fast turnaround on responses quite difficult.

That issue sounds potentially the same as this one, so I’d recommend reading through that and trying some of the suggestions there.

Precise positioning requires some form of positioning system, or at least a velocity sensor) for somewhat accurate movement estimation. It’s possible to use the flight controller’s internal accelerometer for very rough movement estimates, but positioning error grows quickly with double-integrated quantities that have no source of feedback.

I’m not certain what you’re referring to here. Are you saying if you don’t add a delay to your code it doesn’t work, or that your commands stop working after some amount of time (that you’re referring to as a delay)? If it’s the latter, you’re most likely running into a failsafe that you’re not handling correctly.

Hey, Greetings for the day, Thank you for your answers @EliotBR


import time
import math
import sys
import pymavlink
from pymavlink import mavutil

buttons = 1 + 1 << 3 + 1 << 7


def control(x=0, y=0, z=500):
    master.mav.manual_control_send(
        master.target_system,
        x,
        y,
        z,  # 500 means neutral throttle
        0,
        buttons
    )


def set_mode(mode):
    if mode not in master.mode_mapping():
        print("Unknown mode: %s" % mode)
        print("Available modes: %s" % master.mode_mapping())
        sys.exit(1)
    # Get mode ID
    mode_id = master.mode_mapping()[mode]
    # Set mode
    master.set_mode(mode_id)


def set_target_depth(depth):

    # Set the target depth as negative values

    master.mav.set_position_target_global_int_send(
        int(1e3 * (time.time() - boot_time)),  # ms since boot
        master.target_system, master.target_component,
        coordinate_frame=mavutil.mavlink.MAV_FRAME_GLOBAL_INT,
        type_mask=(
            mavutil.mavlink.POSITION_TARGET_TYPEMASK_X_IGNORE |
            mavutil.mavlink.POSITION_TARGET_TYPEMASK_Y_IGNORE |
            mavutil.mavlink.POSITION_TARGET_TYPEMASK_VX_IGNORE |
            mavutil.mavlink.POSITION_TARGET_TYPEMASK_VY_IGNORE |
            mavutil.mavlink.POSITION_TARGET_TYPEMASK_VZ_IGNORE |
            mavutil.mavlink.POSITION_TARGET_TYPEMASK_AX_IGNORE |
            mavutil.mavlink.POSITION_TARGET_TYPEMASK_AY_IGNORE |
            mavutil.mavlink.POSITION_TARGET_TYPEMASK_AZ_IGNORE |
            mavutil.mavlink.POSITION_TARGET_TYPEMASK_YAW_IGNORE |
            mavutil.mavlink.POSITION_TARGET_TYPEMASK_YAW_RATE_IGNORE
        ), lat_int=0, lon_int=0, alt=depth,
        vx=0, vy=0, vz=0,
        afx=0, afy=0, afz=0, yaw=0, yaw_rate=0
    )


print(mavutil.mavlink20())
# Create the connection
master = mavutil.mavlink_connection('/dev/ttyACM0', baud=115200)
# Wait a heartbeat before sending commands
master.wait_heartbeat()
# Choose a mode
mode = 'ALT_HOLD'

# set_mode(mode)
# set_target_depth(-0.5)
for _ in range(10):
    control(x=550)
    time.sleep(2)

this is the code i developed. i’m referring delay as time.sleep(2). if i run this for loop for one time, my thrusters will run for two seconds and if i give any command without time.sleep(2) , those commands are not executed for example:

for _ in range(10):
    control(x=550)

my thrusters will run for only 2 seconds for the above code but if add time.sleep(2) my thrusters will run for 20 seconds. How can i overcome this problem

Hey, Greetings for the day,
i’m not using ROS here
i’m just using pymavlink manual_control commands to control my auv.

And now encountered a new problem somehow i messed up with my code, now vehicle type changed to default MAV_TYPE_FIXED_WING. how can i change it back to MAV_TYPE_SUBMARINE. Can you provide me a code sample. And can you also provide me a code sample for to change FS_PILOT_TIMEOUT and RC_OVERRIDE_TIME parameters. @EliotBR
Thanks & Regards

That’s most likely a failsafe issue - with no delay the loop sends the 10 control commands within a few milliseconds, and then a few seconds later with no pilot input and no heartbeats sent the vehicle will failsafe and disarm. When you add a sleep your vehicle sends additional pilot input commands within the failsafe period until it finishes the loop, after which there’s a period of no pilot input and a failsafe occurs to stop the vehicle.

You can overcome that by either sending regular heartbeats and control input while you want to control the vehicle (recommended), or by adjusting the failsafe timeout(s) and/or turning off the failsafes entirely (not recommended).

Either the connection was not established correctly, your flight controller is not running ArduSub firmware, or you’re connecting to a different vehicle. None of those can be fixed with a code sample - you may wish to install ArduSub.

Parameters are persistent across reboots, so should only need to be changed / set once (unless you flash new firmware onto your flight controller). If you want to do it with code you can use our read and write parameters pymavlink example, or something like this, but you can also set them using QGroundControl if you want (you can connect your Pixhawk directly to your topside computer to do this, if you don’t have an existing connection through your Jetson Nano).

Thank you for your time @EliotBR

But one last thing, can you give some code sample for sending regular heartbeats and control input.
Thank you