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

https://www.ardusub.com/developers/pymavlink.html#armdisarm-the-vehicle

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

2 Likes

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:0.0.0.0:14550')
# Wait a heartbeat before sending commands
master.wait_heartbeat()

def set_rc_channel_pwm(...):
    ...

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


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


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

Note that connecting to udpin:0.0.0.0:14550 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: