I asked this once before, but did not get the response I wished.
I was wondering if it will be possible to control a RC Switch (https://menacerc.co.uk/product/rc-switch-rcswitch) or the Kill Switch (RCEXL Opto Gas Kill Engine Switch Version 2.0 - Ultimate Guide) which I use to give enable the engine ignition and kill the engine, with some command from a USB Joystick which is connected to QGroundControl?
You could use QGC’s Custom Mavlink Action | QGC Guide (master) and assign a Joystick button to that.
This article explains better how to write a custom actions.
BUT Actually, last week I tried assigning a custom action to a Joystick button and could find my custom function in the drop-down menu of assigning Joystick button actions in QGC. It might be a bug or something on my end.
Anyways - once you load a custom Mavlink action to QGC you’ll have it available in the Fly view regardless of joystick assignment.
Thanks for your advice and help, in the article they use ArduPilot, I have thoughts that maybe that will work different in PX4?
The structure of the JSON file remains the same between PX4 and Ardupilot, you only need to make sure to use Mavlink commands that are supported by PX4.
It’s working for me using PX4. Command I use is MAV_CMD_DO_SET_ACTUATOR (187)
. You can assign the actuator in QGC but notice the PWM might by <1000 before arming the vehicle.
I don’t see references to MAV_CMD_DO_SET_RELAY
and MAV_CMD_DO_SET_SERVO
in PX4 source code.
Ok I think I got it, I have to do set the mavcmd to 187 to set the actuator riht?
Then param1 and param 2 is for the pwm value I want to set, if I understand right?
Yes. For me the json looks like this:
{
"version": 1,
"fileType": "CustomActions",
"actions":
[
{
"label": "Label in QGC",
"description": "What it does",
"mavCmd": 187, // this is MAV_CMD_DO_SET_ACTUATOR
"param1": -1, // this is 0%
"param2": 0, // this is 50%
"param3": 1, // this is 100%
"param4": 0,
"param5": 0,
"param6": 0,
"param7": 0
}
]
}
Since you want to control a single output, you can leave params 1-7 at 0.
I managed to have the button displayed in QGC but i tried a while but I did not get any movement on the switch, servo etc…
I’m not sure if there’s a way to make the actuators “work” without arming the vehicle.
Obviously, you also need to assign the actuator in the vehicle configuration.
To help you debug the issue you can open the Mavlink monitor and watch the servo output messages to see if the PWM does go out to your servo.
I’m not sure if there’s a way to make the actuators “work” without arming the vehicle
You can make them work before arming through COM_PREARM_MODE
Arm, Disarm, Prearm Configuration | PX4 Guide (main).
If you want more automation in the ICE control you can check out the ongoing work of adding a ICE module that handles the starting automatically (only really useful if you have RPM feedback). See [WIP] Add IC engine control module by sfuhrer · Pull Request #24055 · PX4/PX4-Autopilot · GitHub
The servo works othwise, in armed or disarmed, with the actuator testing sliders as well. But when I want to use the custom action button I have created there is no movement on the servo/channel i want to control for the engine kill switch
I guess it’s something with assigning the right actuator in vehicle settings, or your custom functions json file.
It seems PX4 (or QGC) only supports a single group of 6 actuators, so param7
in a "mavCmd": 187
should always be 0, for the “first” set.
Then, in the Actuators page in the vehicle setup, you go for the appropriate channel and assign it Peripheral via Actuator Set [1-6]
.
Then Set 1 would be controlled with "param1": x
, Set 1 with param2 etc.
Notice param[1-6] values should be between -1 and 1.
P.S Thanks @sfuhrer, that parameter did allow actuator output before arming the quad.
I have it now working.
I was using 1.14.3 when I tested, now I use 1.15.2 as firmware and it works.
In the Actuator section I selected Pripheral via Actuator Set 2 for channel two and assigned it to AUX2. Now my buttons also are steering the servos.
thanks for your help.
But the default QGC Actions seems to be dissappeared?