Configure PWM outputs for servo motors and ESC control
UAV Toolbox Support Package for PX4 Autopilots / PX4 Utility Blocks
The PX4 PWM Output block helps you to configure the PWM output from the PX4 flight controller board. The block accepts time value (in microseconds) that represents the ON period of PWM signal for a particular channel, and passes the same to the corresponding PWM channels on the board.
The PX4 PWM Output block also accepts signals for arming the flight controller and enabling failsafe conditions.
Arm— Arm the PX4 flight controller
Enable signal for arming the PX4 flight controller.
Set failsafe— Enforce failsafe for PX4 flight controller
Enforce failsafe values even though the failsafe conditions might or might not have occurred. You can specify the failsafe values in the Configuration Parameters dialog box in Simulink.
If you are using PX4 firmware 1.10.2, the value at
failsafe input port is not valid if you use AUX channels for PWM.
Ch— Inputs that accept PWM ON values
Connect the Ch
x inputs to signals that represent PWM ON values
Ch inputs are selected using the PWM
Port_1— Error status while processing PWM commands
0(default) | 16-bit value
Obtain the error status of the PWM operations in the block. The error status corresponds to a 16-bit representation of the various possible errors.
An output value of
0 indicates a successful PWM operation (no
errors). A non-zero output indicates the different errors that you can interpret based
on the 16-bit value.
To interpret the errors (if any), connect the Port_1 output
to a Display block that has the Format value
binary (Stored Integer), and run the model in
Port_1 (error status) connected to a Display block and viewed in External mode
Use the following table to interpret the 16-bit error status as obtained from the output of PX4 PWM Output block:
|LSB of the 16-bit field that is set to 1 (as it will appear in a Display block in case of errors)||Error|
|1||Failed to open the PWM device (Main/AUX)|
|2||Failed to obtain the number of servo motors|
|3||Failed to Arm the PWM device|
|4||Failed to Disarm the PWM device|
|5||Failed to set the PWM frequency|
|6||Failed to select the PWM channel that is configured as input|
|7||Failed to set the failsafe values on the selected channels (values that
are defined in the |
|8||Failed to set the disarmed values on the selected channels (values that
are defined in the |
|9||Failed to interpret the |
|10||Failed to interpret the |
|11||Failed to set the PWM motor values|
|12||Failed to reset the PWM motor values|
|13||Failed to close the PWM device (Main/AUX)|
If the 16-bit error status shows [
If the 16-bit error status shows
This output appears only if you have selected the Output error status parameter.
Select PWM Device— Channel category to identify the channels that you are going to select
Select the category (Main or AUX) to identify and select the corresponding channels. After you select this category, you can select the channels in the parameter list, for Main and AUX, separately.
PWM Channels— Channels to which you want to send the PWM ON time values
Select the channels to which you want to send the values for PWM ON time (the
channels to which you connect servo motors or ESC). The
Ch inputs to
the block appear based on the selection in this parameter list.
Ensure that you select all the channels that belong to the same channel group. If you need to connect to PWM channels that are in different groups, select all channels in all the desired groups. Only one PX4 PWM Output block per channel category (Main or AUX) is allowed in the entire Simulink model.
To identify the channel groups in the Pixhawk Series flight controller board, use QGroundControl application on your host computer:
Connect the Pixhawk Series flight controller board to the USB port of the host computer.
In QGroundControl, go to Mavlink Console, and do the following:
To identify the Main channels and their groups, enter the command
To identify the Aux channels and their groups, enter the command
pwm info -d /dev/pwm_output1
Force terminate failsafe mode— Set the failsafe as permanent and non-recoverable
If this parameter is enabled, and if an actual failsafe condition occurs, the
failsafe values are permanently set. In this case, sending a disable signal
0) at the
Set failsafe input, will not have any
If you are using PX4 firmware 1.10.2, the enabling of
failsafe mode parameter is not valid if you use AUX channels for
Output error status— Enable the error status as the output
Enable the error status of the block as the output. This output is a 16-bit binary value that you can interpret to analyze the errors.