Home        Store        Learn        Blog

Motors Do Not Work When I Run My Code on Ubuntu Computer Connected With Ethernet To The Unmanned Underwater Vehicle

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

# 8 channelimiz var
#http://mavlink.org/messages/common#RC_CHANNELS_OVERRIDE

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)

A post was merged into an existing topic: Motors Do Not Work When I Run My Code on Ubuntu Computer Connected With Ethernet To The Underwater Veh