top of page

Configure PWM Camera Gimbal with PX4

Oct 29
7 min read

How to Configure and Troubleshoot a 3-Axis PWM Camera Gimbal with PX4 v1.16 — CANDY Flight Controller

CANDY Development Blog | PX4 Integration & Testing

Category: Flight Controller Development / Gimbal Stabilization / Troubleshooting

Introduction

During the development of the CANDY Flight Controller, we integrated a 3-axis PWM camera gimbal using PX4 v1.16.

The objective was to stabilize the camera's Roll, Pitch and Yaw axes while the aircraft changes attitude during flight.

During initial testing, we encountered an interesting issue:

The servo responded correctly to the Gimbal Pitch slider in QGroundControl Actuator Testing, but it did not move when we tried to command the gimbal through PX4 or test automatic stabilization.

This article explains the system configuration, testing process, possible causes and troubleshooting methods.

1. Understanding the CANDY Gimbal System

The proposed CANDY architecture consists of:

  • Flight Controller: CANDY (STM32H743-based custom hardware)

  • Autopilot Firmware: PX4 v1.16

  • Ground Control Station: QGroundControl

  • Gimbal Interface: PWM

  • Gimbal Axes: Roll, Pitch and Yaw

  • Output Devices: PWM servos or a compatible PWM-input gimbal controller

How the system works

The flight controller measures aircraft orientation using its onboard inertial sensors and attitude estimator.

The PX4 gimbal system can use this information to compensate for aircraft movement, helping the camera maintain its commanded orientation.

System Signal Flow

CANDY Flight Controller↓PX4 Vehicle Attitude Estimation↓PX4 Gimbal / Mount Driver↓PX4 Actuator Output Functions↓PWM Outputs (Roll / Pitch / Yaw)↓Gimbal Servos or Gimbal Controller↓Camera Orientation

Important: PWM outputs from CANDY provide control signals, not direct three-phase power for brushless gimbal motors. A brushless gimbal requires a suitable motor controller.

2. Hardware Wiring Configuration

For our proposed configuration, three unused PWM channels are assigned to the gimbal.

CANDY Output

Function

Gimbal Connection

AUX1

Gimbal Roll

Roll PWM input

AUX2

Gimbal Pitch

Pitch PWM input

AUX3

Gimbal Yaw

Yaw PWM input

GND

Signal reference

Gimbal signal ground

External Power

Servo supply

Regulated power input

The physical pin assignments depend on the CANDY board design and PX4 timer configuration.

Before connecting the servo, verify the PWM signal voltage, operating supply voltage and common ground.

For typical standard PWM servos, an initial configuration may use a 50 Hz PWM signal with 1000–2000 µs pulse widths, provided the servo supports that range.

3. PX4 Gimbal Parameter Configuration

Open:

QGroundControl → Vehicle Setup → Parameters

Configure the following mount parameters:

Parameter

Value

Description

MNT_MODE_IN

0

Automatic input selection

MNT_MODE_OUT

0

AUX/PWM output

MNT_DO_STAB

1

Enable stabilization on all axes

For the initial gimbal setup, we use automatic input selection. PX4 can then accept applicable RC or MAVLink gimbal commands.

The MNT_DO_STAB parameter enables attitude compensation for the gimbal.

After modifying the parameters, save the configuration and reboot the CANDY Flight Controller.

PWM output assignments

Open:

Vehicle Setup → Actuators → Actuator Outputs

Assign the following output functions:

Channel

Function

PX4 Function ID

AUX1

Gimbal Roll

420

AUX2

Gimbal Pitch

421

AUX3

Gimbal Yaw

422

When supported by the active PWM output driver, these may correspond to:

  • PWM_AUX_FUNC1 = 420

  • PWM_AUX_FUNC2 = 421

  • PWM_AUX_FUNC3 = 422

For a custom flight controller, parameter names may differ depending on the configured output driver.

4. Initial Servo Testing with QGroundControl

Before testing stabilization, we first verify the individual PWM servo outputs.

Test Procedure

  1. Connect CANDY to QGroundControl.

  2. Open Vehicle Setup → Actuators.

  3. Locate the Actuator Testing section.

  4. Enable actuator testing.

  5. Select the Gimbal Pitch channel.

  6. Move the slider slowly.

  7. Observe the servo movement.

Our test result

The Gimbal Pitch servo moved correctly when the slider was adjusted.

This confirmed that the basic output system was functional:

  • Servo hardware was operating.

  • Power and signal wiring were functional.

  • The CANDY PWM channel could generate a servo-control signal.

  • The actuator-output function was assigned to the channel.

However, we discovered that successful actuator testing did not automatically mean the full gimbal stabilization system was working.

The actuator slider can directly test an output, while normal gimbal operation requires commands to pass through the PX4 mount driver and actuator pipeline.

5. Testing the PX4 Gimbal Driver

The next step is to verify that PX4 has started the gimbal driver.

Open:

QGroundControl → Analyze → MAVLink Console

Enter:

gimbal status

This command reports the status of the PX4 gimbal driver.

If the driver is not running, review the mount parameters and reboot the flight controller.

For diagnostic purposes, the driver can also be started manually:

gimbal start

Then check again:

gimbal status

Test the Pitch Axis

Enter the following command:

gimbal test pitch -20

Then:

gimbal test pitch 20

These commands request gimbal pitch angles through the mount driver.

Expected result: The gimbal output responds to the commanded angles when the driver, actuator pipeline and output safety state permit operation.

If the servo responds to QGroundControl's actuator slider but not to these commands, the issue may lie between the mount driver and the normal PWM output path.

6. Testing Automatic Gimbal Stabilization

After verifying servo command movement, the next step is to test attitude compensation.

The objective is to determine whether the gimbal automatically compensates for movements of the flight controller.

Roll Stabilization Test

  1. Set the gimbal to its neutral position.

  2. Hold the CANDY Flight Controller securely.

  3. Slowly rotate the controller approximately +10° in Roll.

  4. Observe the Roll servo.

Expected behavior: The gimbal compensates in the opposite direction to help maintain the camera's horizontal orientation.

Pitch Stabilization Test

  1. Return the controller to level.

  2. Slowly pitch the controller approximately +10°.

  3. Observe the Pitch servo.

Expected behavior: The gimbal compensates for the aircraft's pitch change and attempts to maintain its commanded camera orientation.

Yaw Stabilization Test

  1. Return the controller to its initial heading.

  2. Slowly rotate the controller approximately +15° in Yaw.

  3. Observe the Yaw servo.

Expected behavior: With yaw stabilization configured and sufficient mechanical travel, the gimbal attempts to maintain its commanded heading.

These tests should be performed with the propulsion system disabled and the aircraft securely supported.

7. Troubleshooting: Servo Moves in Actuator Testing but Not in Stabilization Mode

This was the main issue encountered during our initial CANDY integration testing.

Possible Cause 1 — Gimbal Driver Not Running

The PWM output may work correctly even when the gimbal driver is inactive.

Check:

gimbal status

Also verify:

param show MNT_MODE_IN
param show MNT_MODE_OUT

The input mode must not be disabled (-1).

Possible Cause 2 — Stabilization Not Enabled

Check:

param show MNT_DO_STAB

For the intended PX4 attitude-compensated servo gimbal configuration, use:

param set MNT_DO_STAB 1

This enables stabilization but does not guarantee that a servo command is being generated. A functioning mount control path is still required.

Possible Cause 3 — Incorrect PWM Output Assignment

Verify the actual actuator channel assigned to Gimbal Pitch.

For example:

param show PWM_AUX_FUNC2

If AUX2 is the Pitch output, its function should be 421.

For custom CANDY firmware, verify the correct PWM output group and driver.

Possible Cause 4 — Disarmed Output Behavior

QGroundControl Actuator Testing can temporarily control an output even though the normal actuator pipeline is not driving it.

Inspect:

param show COM_PREARM_MODE

The prearm setting influences when certain actuator outputs may become available.

This parameter alone does not guarantee that the gimbal moves while disarmed.

Do not arm an aircraft with an active propulsion system merely to test the gimbal.

Possible Cause 5 — No Valid Gimbal Command or Control Input

The gimbal driver must receive an appropriate command or target orientation.

Verify:

gimbal status

Then test:

gimbal test pitch 20

A correctly assigned PWM channel cannot move through the mount-control path if the driver is inactive or its commands are not reaching that output.

Possible Cause 6 — Attitude Data or Stabilization Control Issue

Verify that CANDY is publishing vehicle attitude data:

listener vehicle_attitude

Slowly rotate the flight controller and confirm that the attitude information changes.

Then inspect the actuator output commands:

listener actuator_servos

Where available, also inspect:

listener actuator_outputs

If the actuator servo commands change but the physical PWM output does not, investigate the PWM output driver and safety gating.

If the commands never change, investigate the gimbal driver, control inputs and stabilization configuration.

8. CANDY Gimbal Diagnostic Checklist

Test

Expected Result

Actuator Testing slider

Servo moves

Gimbal driver status

Driver running

Gimbal Pitch command

Servo responds

Vehicle attitude topic

Attitude changes with movement

Actuator servo output

Command changes when expected

Roll compensation

Camera counters roll movement

Pitch compensation

Camera counters pitch movement

Yaw compensation

Camera counters yaw movement

For our development process, each test should be completed independently before proceeding to flight testing.

9. Recommended CANDY Development Approach

To simplify troubleshooting, we recommend integrating the gimbal system in stages.

Stage 1 — Single-Axis PWM Verification

Use one Pitch servo to verify physical PWM output and actuator assignment.

Stage 2 — Gimbal Command Verification

Confirm the gimbal driver is operating and can command the Pitch servo.

Stage 3 — Attitude Stabilization

Verify that rotating CANDY produces the appropriate compensating output.

Stage 4 — Three-Axis Integration

Add Roll and Yaw after the Pitch stabilization function works reliably.

Stage 5 — System Validation

Evaluate mechanical limits, servo response speed, camera stability, disarmed behavior and loss-of-signal behavior before flight.

10. Conclusion

During the CANDY Flight Controller development, we identified a useful troubleshooting lesson:

A servo moving correctly in QGroundControl Actuator Testing does not necessarily confirm that PX4 gimbal stabilization is functioning.

The actuator test verifies the physical PWM output path, while the full stabilization function also depends on the gimbal driver, control commands, attitude information and actuator-output state.

By separating these functions into individual tests, it becomes easier to identify the cause of an unresponsive gimbal without making unnecessary changes to the flight controller hardware.

Our next development objective is to validate the complete three-axis stabilization function on the CANDY Flight Controller and evaluate its performance during controlled aircraft-motion tests.

Project: CANDY Flight ControllerPlatform: PX4 Autopilot v1.16Application: 3-Axis PWM Camera GimbalDevelopment Status: Initial PWM output verified; gimbal stabilization troubleshooting ongoing.

Technical References

Disclaimer: This article documents a development and diagnostic procedure. Parameter settings, physical output assignments and test conditions must be verified against the actual CANDY firmware build and connected gimbal hardware before operational use.

Comments


bottom of page