Hi everyone,
I’ve recently unearthed some little-known functionality in QGroundControl that allows configuring custom MAVLink commands to be sent to the vehicle, using either on-screen or joystick buttons!
While ArduSub comes with a number of joystick button functions built in, this can augment that, and also allows functionalities like controlling relays and setting PWM output values on other vehicle firmwares (like ArduRover on the BlueBoat!).
Fly View Actions (On-Screen Buttons)
-
Create an actions file, with the MAVLink commands you want to be able to send:
~/Documents/QGroundControl/CustomActions/FlyViewActions.json
:{ "version": 1, "fileType": "CustomActions", "actions": [ { "label": "Servo5 HIGH", "description": "Sets servo 5 to a high PWM value", "mavCmd": 183, "param1": 5, "param2": 1900 }, { "label": "Servo5 LOW", "description": "Sets servo 5 to a low PWM value", "mavCmd": 183, "param1": 5, "param2": 1000 }, { "label": "Relay1 ON", "description": "Turns on relay 1", "mavCmd": 181, "param1": 0, "param2": 1 }, { "label": "Relay1 OFF", "description": "Turns off relay 1", "mavCmd": 181, "param1": 0, "param2": 0 } ] }
-
Enable Custom Actions in QGC’s Application Settings (access via the top left corner)
- This step is only required for QGC versions before the upcoming 4.5 release
-
Select the actions file from where you saved it
-
Access the actions when in Fly View, by clicking the “Action” button in the left sidebar, and pressing the relevant action button(s) in the popup at the bottom of the screen
- You may need to restart QGC after the actions file location is first configured
- The actions popup can be scrolled sideways to see additional actions, if more than a few are available
Joystick Button Functions
The process and syntax for this is changing from the existing stable releases, so there are two sets of instructions depending on which QGroundControl version you’re running.
QGC < 4.5
Instructions for existing stable versions
- Create a
JoystickMavCommands.json
file:- The filename is hardcoded in QGC, so must match exactly
{ "comment": "Joystick MAV commands", "version": 1, "commands": [ { "id": 181, "name": "Relay1 ON", "param1": 0.0, "param2": 1.0 }, { "id": 181, "name": "Relay1 OFF", "param1": 0.0, "param2": 0.0 } ] }
- Save it where your QGroundControl instance gets run from
- In Windows this is inside the folder where you installed it
- e.g.
C:\\Program Files\QGroundControl\JoystickMavCommands.json
- e.g.
- In MacOS this seems to be the root directory (
/
), which is read-only- This can be worked around by saving it in a memorable location (e.g.
~/Documents/QGroundControl/CustomActions/JoystickMavCommands.json
), and then running QGC from in that folder via the Terminal:% cd ~/Documents/QGroundControl/CustomActions/ % /Applications/QGroundControl.app/Contents/MacOS/QGroundControl
- This can be worked around by saving it in a memorable location (e.g.
- In Windows this is inside the folder where you installed it
- Configure your joystick buttons via the Vehicle Setup options
- You’ll need to scroll to the bottom of the actions dropdown to find your custom options
- You’ll need to scroll to the bottom of the actions dropdown to find your custom options
QGC >= 4.5
Instructions for current development and future stable releases
-
Create an actions file, with the MAVLink commands you want to be able to send:
~/Documents/QGroundControl/CustomActions/JoystickCustomActions.json
:{ "version": 1, "fileType": "CustomActions", "actions": [ { "label": "Servo5 HIGH", "description": "Sets servo 5 to a high PWM value", "mavCmd": 183, "param1": 5, "param2": 1900 }, { "label": "Servo5 LOW", "description": "Sets servo 5 to a low PWM value", "mavCmd": 183, "param1": 5, "param2": 1000 }, { "label": "Relay1 ON", "description": "Turns on relay 1", "mavCmd": 181, "param1": 0, "param2": 1 }, { "label": "Relay1 OFF", "description": "Turns off relay 1", "mavCmd": 181, "param1": 0, "param2": 0 } ] }
-
Select the actions file from where you saved it, via the Application Settings in the top left corner
-
Access the actions when in Fly View, by clicking the “Action” button in the left sidebar, and pressing the relevant action button(s) in the popup at the bottom of the screen
- You may need to restart QGC after the actions file location is first configured
- The actions popup can be scrolled sideways to see additional actions, if more than a few are available
-
Configure your joystick buttons via the Vehicle Setup options
- You’ll need to scroll to the bottom of the actions dropdown to find your custom options
- You’ll need to scroll to the bottom of the actions dropdown to find your custom options
Relay Configuration
While the servo PWM commands typically provide direct control over flight controller servo output pins, the relay output pins are selectable from the available servo output pins, which needs to be set up in the autopilot parameters before the relay can be used.
When using a Navigator Flight Controller it is possible to see the state of the relay pins as 0/1 in the
SERVO_OUTPUT_RAW
MAVlink messages (e.g. via the MAVLink Inspector).
ArduSub (BlueROV2)
- Allow the relevant servo pin to be used as a relay output, by setting its
SERVOn_FUNCTION
parameter toDisabled (0)
- “n” is the pin number being configured (e.g.
9
)
- “n” is the pin number being configured (e.g.
- Configure the relay number with the desired servo output pin, using the
RELAY_PIN
/RELAY_PIN2/3/4/5/6
parameter - Configure the joystick button function(s) as desired
- ArduSub provides built in
relay_n_*
functions for controlling relays 1-4 - The custom joystick button functions can be configured to allow control over relays 5 and 6, using the
DO_SET_RELAY (181)
and/orDO_REPEAT_RELAY (182)
MAVLink commands- Note the relay numbering in the MAVLink message is 0-indexed, so relay 5 is index 4
- ArduSub provides built in
ArduRover (BlueBoat)
- Allow the relevant servo pin to be used as a relay output, by setting its
SERVOn_FUNCTION
parameter toGPIO (-1)
- “n” is the pin number being configured (e.g.
9
)
- “n” is the pin number being configured (e.g.
- Allow the relay number to be used as a servo output relay, by setting the
RELAYn_FUNCTION
toRelay (1)
, and rebooting the autopilot- “n” is the relay number being configured (e.g.
1
)
- “n” is the relay number being configured (e.g.
- Connect the relay number to its servo output pin via the
RELAYn_PIN
parameter - Set up custom joystick button functions using the
DO_SET_RELAY (181)
and/orDO_REPEAT_RELAY (182)
MAVLink commands, and configure the joystick button function(s) as desired