Controlling more than 4 relays while using QGroundControl

I’m working with a BlueROV running BlueOS on a Raspberry Pi with the Navigator Board.
There are 6 relays attached to Pins on the Navigator Servo Rail.
They have all been successfully tested using Mission Planner.
QGroundControl however only allows 4 relays in total to be mapped to joystick buttons.

So far I have found a few possible approaches worth checking out:

  1. Using a Lua script running on the Navigator:
    This forum post mentions a github pull request for a feature that enables lua scripts to read joystick input. Apart from an example in the github repo there doesn’t seem to be much documentation to go off.

  2. Using a pymavlink script running on the ground control station simultaneously with QGroundControl:
    This possibility is briefly mentioned in a comment in an example in the ardusub docs.
    I am not sure if this actually enables the ROV to receive commands from two ground control stations simultaneously or if this is only meant for sending telemetry to several recipients.

  3. (Modifying QGroundControl to allow for a few extra relays to be assigned)
    “Simply” dealing with the hardcoded limit by extending it.
    I would even consider doing this myself, if I had any idea how to do it. This is obviously demands more programming knowledge than duct-taping a script together from some premade examples, but for the sake of completion I’m mentioning it too.

I will keep updating this post as I find out what does and doesn’t work.
Please let me know your thoughts.

1 Like

Hi, Bob –

  1. I just looked at the code (~master), and I see that AP_Relay.h allows for 6 relays, but only 4 are mapped to joystick buttons in joystick.h. So, this is possible, but as you point out it is non-trivial.

  2. There is a MAV_CMD_DO_SET_RELAY message handled in GCS_ServoRelay.cpp. So this is possible. Scripts can run alongside QGC. You should be able to get this working right away. The pilot experience isn’t that great, though.

  3. Lua has access to the relays (see libraries/AP_Scripting/examples/relay_control.lua), and you could use the new joystick buttons to activate these relays. So this seems like a very nice option: simple, good pilot experience. The only challenge is that the latest stable release of ArduSub (1.1.x) doesn’t include these script buttons, so you’ll need to run on DEV ArduSub until there is a stable 4.5 release.

I hope this helps,


Thanks! This does help a lot. You saved me quite some headache by confirming a few things I was unsure about.

I like the Lua option best, but I am unable to change the firmware at the moment so pymavlink will have to do for now. I’ll post an update once I get it running.

I’ve had some issues with python, so I took a break and used Wireshark to look at the communication between QGC and the BlueROV.

I was hoping to see QGC control the ROV using conventional mavlink commands.
As it turns out, QGC is simply forwarding raw joystick input to the ROV.
For example, to turn on the lights, you map “Lights1” to “Button 12”, and then send a MANUAL_CONTROL message that has the bit corresponding to button 12 set.
The “conventional mavlink way” to do this would be to simply send something like CMD_DO_SET_RELAY.

So I did some more digging and found several examples of people using pymavlink to talk to their BlueROV involve overriding the raw joystick input messages instead of using mavlink messages to address specific functions.
This does indicate that the Bluerov may not be responsive to conventional mavlink like CMD_DO_SET_RELAY, but I can’t verify that until I fix my pymavlink setup.

Running the same test again with Mission Planner instead of QGroundControl, it has become clear that the ROV does respond to MAV_CMD_DO_SET_RELAY.

Seems like I found something that works:

This is a script using the default pymavlink library obtainable by running pip install pymavlink.

No need to generate a custom dialect if you just want to control relays.

Initially, I bothered with creating a custom mavlink dialect library as detailed in the pymavlink installation instructions here but that was overkill since the relay control commands are included in the standard message set.

Once you have pymavlink installed, the process should be straightforward:

Details if you want to run the script alongside QGroundControl:

To use the script alongside QGroundControl, make sure to add a MAVLink endpoint in BlueOS (pirate mode):
It should be a UDP Client and have a port different to the default 14550 used by QGroundControl. Remember to update the port your script listens on accordingly.

This example turns the 5th relay on:

from pymavlink import mavutil
master = mavutil.mavlink_connection('udpin:')

0, # unused, set to 0
4, # relay number
1, # desired state (1 or 0)
0,0,0,0,0) # unused, set to 0
Details on the script:

command_long_send sends a command ID along with 8 parameters whose meaning depends on the command specified in the ID. In this case, we’re sending command #181 which is CMD_DO_SET_RELAY. The meaning of each parameter can be found in the documentation.
Messages (common) · MAVLink Developer Guide

1 Like

Turns out, there is an even simpler way.

Instead of running a python script alongside QGC, you can just run Mission Planner alongside QGroundControl and use the GUI functionality of Mission Planner to control the relays.

You just need to create a separate MAVLink Endpoint in BlueOS (exactly the same way as for a script).
The menu is only visible in pirate mode.
The new Endpoint needs to be a UDP Client pointed towards the IP of the ground control Station, but with a non-default port (default is 14550).

Launching Mission Planner and QGroundControl is a bit awkward but they should run fine after that:

  1. Launch Mission Planner First
  2. Make sure you are not connected to anything using the disconnect button.
  3. Select and connect to the non-default port in the top right dropdown menu. Make sure again that Mission Planner is NOT connected to the default port.
  4. Start QGroundControl and it should establish a connection like normal.

At this point, functionality of both programs should be available. You can control the Relays (and a few other things) via the GUI of Mission Planner and use the Joystick and Camera functionality of QGC to pilot the ROV.

1 Like