Controlling PWM outputs with Python/Mavlink2Rest

Hi.

I’m new to BlueOS and software development for this.
I would like to develop my own software for controlling the ROV.
Currently I’m able to read status (heading, roll, depth etc) from the ROV by using a Python program and Mavlink2Rest interface.
But I’m struggeling with controlling the PWM outputs from the Navigator Flight Controller.

Is there anyone that has a very basic Python program that can control these PWM outputs ?

Best regards
Eivind Vigsnes
Norway

Hi @EivindV, welcome to the forum :slight_smile:

Which outputs are you trying to control? There are different MAVLink messages that are relevant for different output types (e.g. MANUAL_CONTROL or RC_CHANNELS_OVERRIDE for controlling the vehicle motion, and MAV_CMD_DO_SET_SERVO for auxiliary control of vehicle peripherals (like lights and grippers and the like)).

We have some old Pymavlink examples, which you could potentially adjust to using with the MAVLink2REST API instead…

1 Like

Thanks for guiding me in the right direction.
I don’t need to use Mavlink2Rest , if it works with Pymavlink it would be great.

I had a look at the examples.
" Run pyMavlink on the surface computer"
With this example I’m receiving a stream with messages.

“Send Message to QGroundControl”
This is working OK.

" Set Servo PWM"
When I’m running this , there is no error messages.
But there is no change on the PWM signal.
I’m measuring the PWM signal with a oscilloscope, and the signal is constant on 1500 uS pulsewidth.
The QGroundControl is not running.

Any advice how I should proceeed ?

Thanks

Are you running the example as-is? It was written for controlling the AUX servo outputs of a Pixhawk, skipping over the MAIN ones. The Navigator doesn’t have such a distinction, so you might just be controlling servo 9 instead of servo 1.

Note that if you are trying to control output 1, that will not work using set_servo commands if it is assigned as a motor, because the motion components of the autopilot generally need to be controlled using vehicle motion commands.

You should be able to check what’s changing using the SERVO_OUTPUT_RAW message values, which you can receive in your code or view in the BlueOS MAVLink inspector :slight_smile:

I wrote this more complete example a while ago, which may be useful for a sense of how to string different functionalities together :slight_smile:

1 Like

Thanks for clarifying this.
Yes, you are correct, I was controlling servo 9.
This helped me a lot :slight_smile:

A second question:

I have this in the code:

# Create the connection
master = mavutil.mavlink_connection('udpin:0.0.0.0:14550')

Here it’s using IP 0.0.0.0, but my Navigator/BlueOS is running on 192.168.10.158

I guess my program is receiving UDP messages from the Navigator/BlueOs, and the know which IP it should communicate with.
But what if I have another Navigator/BlueOS connected to the network?
How can I distinguish between them in the software?

That’s using the “GCS Client Link” MAVLink Endpoint, at the port that control station software like QGroundControl expects to broadcast to and receive communications through.

If you’re using Pymavlink then I’d recommend setting up a custom endpoint for that[1] in each BlueOS device, in which case you can use different ports for those endpoints, and your Pymavlink code can be set to reflect that.

Alternatively, if you’re connecting with MAVLink2REST (or using a UDP server MAVLink Endpoint) you can specify the IP address of the BlueOS device you’re connecting to.


  1. See the example in the docs - you’ll need Pirate Mode enabled to see the MAVlink Endpoints page in the sidebar ↩︎