Home        Store        Learn        Blog

Running thrusters using python

I am trying to control the PWM, Time , and direction of each T200 thruster using python code,

I am using raspberry pi OS connected with an Ardusub pixhawk , I would greatly appritate if anyone could please guide me through the process and code

I have tried to run some of the code written on the website directly, such as “Send RC Joystick”
on the raspberry pi, using the terminal, but the motors didn’t spin


may I add my python experience is pretty limited , :smiley:


Hi @MokhtarYahia,

If you’re trying to use the Send RC (Joystick) example you still need to arm the ROV to enable the motors to move. You can do that by first using the arm functionality from the Arm/Disarm the Vehicle example before you run the commands to move the ROV.

Thank you Eliot, So do I have to copy the Arm/Disarm the Vehicle and the Send RC (Joystick) in a single .py folder, and then run them on the Rasberry/pixhawk, and the thruster should automatically arm and spin ? , or are there some additional steps?

I apologize if my knowledge is a bit lacking, and I sincerely appreciate your time in advance

Our pymavlink examples are snippets that can be combined into more general programs to create desired functionality. In this case the vehicle needs to be armed before it can move, which means you would want to set up a program like the following, which you can then run on your surface computer:

# Import mavutil
from pymavlink import mavutil

# Create the connection
master = mavutil.mavlink_connection('udpin:')
# Wait a heartbeat before sending commands

def set_rc_channel_pwm(...):

# +ADDED+ Arm the vehicle before engaging thrusters
# wait until arming confirmed (can manually check with master.motors_armed())
print("Waiting for the vehicle to arm")

... # TODO: continue with RC functionality (e.g. set_rc_channel_pwm(2, 1600))

# +ADDED+ Disarm once desired motion is complete
print("Waiting for the vehicle to disarm")
# wait until disarming confirmed
print("Disarmed (safe)")

Note that connecting to udpin: is for if you’re running your python program on the surface computer. If you’re instead wanting to run your code on the companion computer you’ll need to replace the # Create the connection section with the relevant code from the Run pyMavlink on the companion computer example :slight_smile: