Pymavlink RC Command Issue

I run the following code to control my blue robotics motors for our unmanned underwater vehicle. I use Ubuntu and my computer is connected to the vehicle with ethernet. I ran this code both on Spyder (Anaconda) and also directly from the terminal as a .py file.
I do not receive any errors and the code prints out “it runs” which shows that it enters the while loop for the motor codes successfully, also I checked my ethernet connection and it is connected to my vehicle successfully. I also can understand it because when I ran the code it disconnects Qground as they use the same IP.
However, although my code runs and my computer is connected to the vehicle, when I run the code the motors do not move. I opened Qground from Ubuntu and could move the motor with a JoyStick, also I could move my motors from Putty (inside Raspberry).
However, I cannot make my motors move on my Ubuntu computer with these codes neither from the terminal nor Spyder (Anaconda). What should I do? What is the problem and how can I solve it?
Thank you

from pymavlink import mavutil
import sys

master = mavutil.mavlink_connection(‘udpin:0.0.0.0:14550’)
master.arducopter_arm() # robotu arm et

mode = ‘MANUAL’
if mode not in master.mode_mapping():
print(‘Unknown mode : {}’.format(mode))
print(‘Try:’, list(master.mode_mapping().keys()))
sys.exit(1)
print(“hd”)
mode_id = master.mode_mapping()[mode]

master.set_mode(mode_id)

def set_rc_channel_pwm(id, pwm=1500):


if id < 1:
    print("Channel does not exist.")
    return



if id < 9:
    rc_channel_values = [65535 for _ in range(8)]
    rc_channel_values[id - 1] = pwm
    master.mav.rc_channels_override_send(
        master.target_system,                # target_system
        master.target_component,             # target_component
        *rc_channel_values)                  # RC channel list, in microseconds.

count = 0
a = 190

while ( a < 140 ):
#go left
         set_rc_channel_pwm(4, 1400)
         count+=1
         if count == 1001:
                 master.arducopter_disarm()

while (a > 140 and a < 180) :
         set_rc_channel_pwm(4, 800)
         count+=1
         if count == 1001:
               master.arducopter_disarm()

while ( 180 < a ) :
#go right
        set_rc_channel_pwm(4, 1600)
        print(“it runs”)
        count+=1
        if count == 10000001:
               set_rc_channel_pwm(3, 1500)

Hi @Sena,

As per our pymavlink docs:

All system components that communicate via MAVLink are expected to send a HEARTBEAT message at a constant rate of at least 1 Hz. If the autopilot does not receive a heartbeat from your application after this interval, it will trigger a failsafe.

There’s some more info about how to deal with that around the forum - there’s a recent example at the bottom of this comment:

As a more general note, I’d recommend starting with simple bits of code and working your way up to the functionality you actually want. The snippet you provided has some formatting/indentation issues, but also has three while loops that are reliant on a variable that doesn’t change anywhere in the code, which makes it unnecessarily confusing to understand.

When posting examples that you want help with, try to simplify the code down to the simplest example you can that replicates the issue :slight_smile: