# Doubts in pymavlink

**URL:** <https://discuss.bluerobotics.com/t/doubts-in-pymavlink/5113>\
**Category:** ArduSub\
**Created:** [May 21, 2019, 5:33am UTC](https://discuss.bluerobotics.com/t/doubts-in-pymavlink/5113 "2019-05-21T05:33:47Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![deepak](https://avatars.discourse-cdn.com/v4/letter/d/7bcc69/32.png) [@deepak](https://discuss.bluerobotics.com/u/deepak)\
**Post date:** [May 21, 2019, 5:33am UTC](https://discuss.bluerobotics.com/t/doubts-in-pymavlink/5113/1 "2019-05-21T05:33:47Z")

</div>

Sir,

I am using ubuntu 16.04 OS in my topside computer. The topside computer has an IP address 192.168.2.1. I have installed python2 and mavproxy in this computer. It is connected using ethernet to a raspberry pi whose IP is 192.168.2.2. The raspberry pi has been connected to pixhwk and latest ardusub software has been installed in it. As given in pymavlink page in ardusub, I followed the same code to “Run pyMavlink on the surface computer”. I wrote the code in some text editor, saved it as ‘file.py’ and tried to execute this file in the python shell. I didn’t get any output. Actually when I run he file, actually the vehicle information should come below the line . I have also checked by writing each line of the code individually in the python shell. Still I didn’t get any information from the vehicle(pixhawk). Am I following the correct steps? My doubt is whether, is this the way to send or receive mavlink messages using python? Please reply.

---

<div class="post-metadata">

**Author:** ![patrickelectric](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.bluerobotics.com/patrickelectric/32/2162_2.png) [@patrickelectric](https://discuss.bluerobotics.com/u/patrickelectric)\
**Post date:** [May 21, 2019, 11:03am UTC](https://discuss.bluerobotics.com/t/doubts-in-pymavlink/5113/2 "2019-05-21T11:03:50Z")

</div>

Hi,

Are you running the script with QGroundControl open ?  
The script provides a small explanation about this:

```auto
# Create the connection
# If using a companion computer
# the default connection is available
# at ip 192.168.2.1 and the port 14550
# Note: The connection is done with 'udpin' and not 'udpout'.
# You can check in http:192.168.2.2:2770/mavproxy that the communication made for 14550
# uses a 'udpbcast' (client) and not 'udpin' (server).
# If you want to use QGroundControl in parallel with your python script,
# it's possible to add a new output port in http:192.168.2.2:2770/mavproxy as a new line.
# E.g: --out udpbcast:192.168.2.255:yourport

```

Also, can you check if the communication between your surface computer and the ROV is working with QGroundControl ? If QGC is not working, you should fix your connection configuration/hardware before running the script.

---

<div class="post-metadata">

**Author:** ![deepak](https://avatars.discourse-cdn.com/v4/letter/d/7bcc69/32.png) [@deepak](https://discuss.bluerobotics.com/u/deepak)\
**Post date:** [May 22, 2019, 3:55am UTC](https://discuss.bluerobotics.com/t/doubts-in-pymavlink/5113/3 "2019-05-22T03:55:36Z")

</div>

Sir,  
The topside computer is connected to raspberry pi through an ethernet cable. I had installed python-pip, python-future and pymavlink in my topside computer, along with python 2.7.12. I followed the commands given in the ardusub page ‘[https://www.ardusub.com/developers/pymavlink.html’](https://www.ardusub.com/developers/pymavlink.html%E2%80%99). For eg, if I wanted to send RC values to my vehicle, the command given in the page is as given below.

# 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()

# Create a function to send RC values

# More information about Joystick channels

# here: [Redirecting...](https://www.ardusub.com/operators-manual/rc-input-and-output.html#rc-inputs)

def set\_rc\_channel\_pwm(id, pwm=1500):  
“”" Set RC channel pwm value  
Args:  
id (TYPE): Channel ID  
pwm (int, optional): Channel pwm value 1100-1900  
“”"  
if id \< 1:  
print(“Channel does not exist.”)  
return

```auto
# We only have 8 channels
#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.

```

# Set some roll

set\_rc\_channel\_pwm(2, 1600)

# Set some yaw

set\_rc\_channel\_pwm(4, 1600)

# The camera pwm value is the servo speed

# and not the servo position

# Set camera tilt to 45º with full speed

set\_rc\_channel\_pwm(8, 1900)

The main doubt lies within the code. Here we gave a certain PWM value to each channel which implies we are setting the PWM value for yaw, roll etc which are the RC channel inputs. Now suppose, if I want the whole ardusub vehicle to move up/down, If I give the input " Vehicle up/down", all the thrusters which makes the vehicle to move up/down, should receive the PWM(it may be thruster2, thruster 3, thruster5) and these thruster should spin. Is it possible in ardusub using pymavlink. if so, How do I need to change the code?  
Looking forward for your reply,

Thanking you,  
Regards,  
Deepak

---

<div class="post-metadata">

**Author:** ![patrickelectric](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.bluerobotics.com/patrickelectric/32/2162_2.png) [@patrickelectric](https://discuss.bluerobotics.com/u/patrickelectric)\
**Post date:** [May 22, 2019, 11:51am UTC](https://discuss.bluerobotics.com/t/doubts-in-pymavlink/5113/4 "2019-05-22T11:51:02Z")

</div>

Hi,

This example, as the comments explain, points how to send RC pwm values to the vehicle.  
If you want to send `Throttle`, you should check the [rc-inputs link in the example](https://www.ardusub.com/operators-manual/rc-input-and-output.html#rc-inputs) and use the channel that deals with `Throttle` information (channel number 3).

---

<div class="post-metadata">

**Author:** ![DJ95](https://avatars.discourse-cdn.com/v4/letter/d/c77e96/32.png) [@DJ95](https://discuss.bluerobotics.com/u/DJ95)\
**Post date:** [February 13, 2020, 4:32pm UTC](https://discuss.bluerobotics.com/t/doubts-in-pymavlink/5113/5 "2020-02-13T16:32:23Z")

</div>

> [@patrickelectric](#):
>
> 168

Just to clarify again the PWM values correspond to a particular motion (like forward, lateral, yaw) and not for a particular thruster?
