Main Content

PX4 PWM Output

Configure PWM outputs for servo motors and ESC control

  • PX4 PWM Output block

Libraries:
UAV Toolbox Support Package for PX4 Autopilots / PX4 Utility Blocks

Description

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.

Note

A limitation is observed when the PX4 PWM Output block is deployed on the Pixhawk 1 board and if you select Use default startup script (rcS) as the startup script option for the PX4 Autopilot during the Select System Startup Script in PX4 step of the Hardware Setup process. Then, if you use rcS as the startup script for Pixhawk 1, the PWM block will not work. This limitation is not present for Pixhawk 2.1 (Cube), Pixracer, and Pixhawk 4 boards. The PWM block works after deployment on these Autopilots even when rcS is used as the startup script.

During Connected I/O simulation, this block writes data to the peripherals of the hardware.

Ports

Input

expand all

Enable signal for arming the PX4 flight controller.

Data Types: Boolean

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.

Note

If you are using PX4 firmware 1.12.3, the value at Set failsafe input port is not valid if you use AUX channels for PWM.

Data Types: Boolean

Connect the Ch x inputs to signals that represent PWM ON values (in microseconds)

Dependencies

The required Ch inputs are selected using the PWM Channels parameter.

Data Types: uint16

Output

expand all

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 set as binary (Stored Integer), and run the model in External mode.

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
1Failed to open the PWM device (Main/AUX)
2Failed to obtain the number of servo motors
3Failed to Arm the PWM device
4Failed to Disarm the PWM device
5Failed to set the PWM frequency
6Failed to select the PWM channel that is configured as input
7Failed to set the failsafe values on the selected channels (values that are defined in the Main PWM or AUX PWM panes in the Configuration Parameters dialog box)
8Failed to set the disarmed values on the selected channels (values that are defined in the Main PWM or AUX PWM panes in the Configuration Parameters dialog box)
9Failed to interpret the Set failsafe input
10Failed to interpret the Force terminate failsafe mode input
11Failed to set the PWM motor values
12Failed to reset the PWM motor values
13Failed to close the PWM device (Main/AUX)

For example:

If the 16-bit error status shows [0000 0000 0010 0000], the bit 6 is set, and the error is that the block failed to select PWM channel that is configured as input. The possible reason can be that you did not select all the channels that belong to a particular group.

If the 16-bit error status shows [0000 0100 0010 0000], the bits 6 and 11 are set. The errors are that the block failed to select the PWM channel that is configured as input, and it also failed to set the PWM motor values.

Dependencies

This output appears only if you have selected the Output error status parameter.

Data Types: uint16

Parameters

expand all

Main tab

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.

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.

Note

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.

Tip

To identify the channel groups in the Pixhawk Series flight controller board, use QGroundControl application on your host computer:

  1. Open QGroundControl.

  2. Connect the Pixhawk Series flight controller board to the USB port of the host computer.

  3. In QGroundControl, go to Mavlink Console, and do the following:

    • To identify the Main channels and their groups, enter the command pwm info.

    • To identify the Aux channels and their groups, enter the command pwm info -d /dev/pwm_output1

Advanced tab

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 impact.

Note

If you are using PX4 firmware 1.10.2, the enabling of Force terminate failsafe mode parameter is not valid if you use AUX channels for PWM.

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.

Version History

Introduced in R2018b