Skip to content

PWM: Servo center & asymetric deflection#25897

Merged
sfuhrer merged 20 commits intoPX4:mainfrom
ttechnick:pr-servo-pwm-trim
Nov 26, 2025
Merged

PWM: Servo center & asymetric deflection#25897
sfuhrer merged 20 commits intoPX4:mainfrom
ttechnick:pr-servo-pwm-trim

Conversation

@ttechnick
Copy link
Copy Markdown
Member

@ttechnick ttechnick commented Nov 11, 2025

Solved Problem

Setting up servos is very tedious, because when you change the PWM_MIN and PWM_MAX, the neutral point also changes. Additionally, it was not possible to have different deflections for the positive and negative direction.

Solution

  • Add PWM_*_CENTERx for each servo.
  • Use a bilinear transform to map actuator_servos to PWM signals.

This solution only works for PWM based servos. Other types of servos are not affected.

Changelog Entry

For release notes:

Feature PWM CENTER
New parameter: `PWM_MAIN_CENTx` and PWM_AUX_CENTx`
Documentation: Need to clarify page [Actuator Configuration and Testing](https://docs.px4.io/main/en/config/actuators#output-assignment-and-configuration)  

Alternatives

We could also implement this feature for other types of servos.

Context

Illustration of the mapping form actuator_servos to pwm using bilinear transform:
servo_pwm_trim

Example Result:
image

Log (Bench):
https://review.px4.io/plot_app?log=5fed3401-4849-4417-a807-212a4ce540ab
Log (Flight):
https://review.px4.io/plot_app?log=899e5f98-3985-401c-8513-0f324339e625

@ttechnick ttechnick marked this pull request as ready for review November 11, 2025 15:16
@ttechnick ttechnick marked this pull request as draft November 11, 2025 15:16
@ttechnick
Copy link
Copy Markdown
Member Author

For review: @mahima-yoga, @sfuhrer

Copy link
Copy Markdown
Contributor

@mahima-yoga mahima-yoga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't get through everything yet but since I am going on holiday for a few days I will post my partial review in case I don't manage to get through the rest today/tomorrow 😄

Comment thread docs/en/config/actuators.md Outdated
Comment thread src/lib/mixer_module/mixer_module.cpp Outdated
Copy link
Copy Markdown
Contributor

@sfuhrer sfuhrer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should start thinking about how to handle the transition from the current "trim on the control surface function" to "trim on the servo output".

  • remove the function trim (but then how is trimming done for UAVCAN servos? And can we translate the settings on existing airframes to the PWM_TRIM?)
  • display warning when the legacy fields are being altered ("consider setting PWM_TRIM instead of surface trim")
  • set all surface trims to 0 when any PWM_TRIM is set to non-1500PWM

Comment thread docs/en/config/actuators.md Outdated
Comment thread docs/en/config/actuators.md Outdated
@ttechnick
Copy link
Copy Markdown
Member Author

We should start thinking about how to handle the transition from the current "trim on the control surface function" to "trim on the servo output".

* remove the function trim (but then how is trimming done for UAVCAN servos? And can we translate the settings on existing airframes to the PWM_TRIM?)

* display warning when the legacy fields are being altered ("consider setting PWM_TRIM instead of surface trim")

* set all surface trims to 0 when any PWM_TRIM is set to non-1500PWM
  • I included a formula in the docs that will translate the current trim settings to the new parameter.
  • We cannot (yet) remove the surface trims, as they are needed for other types of servos, such as UAVCAN or Dshot. If these drivers are updated, we should certainly do that.
  • I added a Note to the CA_SV_CSx_TRIM field, that it should not be used with PWM servos.
  • All surface trims are set to 0 when any PWM_TRIM is set to non-1500PWM automatically, and a note has been added about this.

@ttechnick ttechnick marked this pull request as ready for review November 17, 2025 13:00
@ttechnick ttechnick requested a review from sfuhrer November 17, 2025 13:00
@sfuhrer sfuhrer changed the title PWM: Servo Trim & asymetric deflection PWM: Servo center & asymetric deflection Nov 18, 2025
Copy link
Copy Markdown
Contributor

@sfuhrer sfuhrer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's in a very good state. What I would still consider:

  • default the _CENT params to -1, so keep it disabled and do the PWM range linearily from MIN to MAX
  • hide the CENT params for motors in the UI (if complexity is reasonable)

Comment thread docs/en/config/actuators.md Outdated
Comment thread docs/en/config/actuators.md Outdated
Comment thread docs/en/config/actuators.md
Comment thread docs/en/config/actuators.md Outdated
Comment thread docs/en/config/actuators.md
@ttechnick
Copy link
Copy Markdown
Member Author

It's in a very good state. What I would still consider:

* default the _CENT params to -1, so keep it disabled and do the PWM range linearily from MIN to MAX

* hide the CENT params for motors in the UI (if complexity is reasonable)

The default is now -1.
Old legacy trims can thus still be used the exact same way, as long as the *_CENTx values are kept at -1.

Unfortunately, hiding these parameters is quite complex and would required large changes in mavlink, and maybe the groundstations, that I do not think are worth the effort.
However, I added clearer warnings, that this is only to be used for pwm servos (for now).

@ttechnick ttechnick requested a review from sfuhrer November 20, 2025 13:14
@github-actions
Copy link
Copy Markdown

No flaws found

@sfuhrer
Copy link
Copy Markdown
Contributor

sfuhrer commented Nov 26, 2025

@ttechnick I've added the event for the warning when TRIM settings are present and you add CENTER.
image

Copy link
Copy Markdown
Contributor

@sfuhrer sfuhrer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ready to go now from my side. The transition (from TRIM to CENTER) is handled diligently, and docs are clean.
Let's squash-merge.

@sfuhrer sfuhrer merged commit 575fa08 into PX4:main Nov 26, 2025
71 of 73 checks passed
@ttechnick ttechnick deleted the pr-servo-pwm-trim branch January 5, 2026 14:33
ttechnick added a commit to ttechnick/PX4-Autopilot that referenced this pull request Jan 13, 2026
Add PWM_*_CENTERx for each servo.
Use a bilinear transform to map actuator_servos to PWM signals.

This solution only works for PWM based servos. Other types of servos are not affected.

* PWM: Add servo trim option

* PWM: Improve documentation of PWM trim feature

* PWM: cleaner clamping and docs typo

* update documentation & safety

* add migration formula

* rename param from trim to center

* docs with center instead of trim

* move clamping and reorder values

* improve documentation

* adress failing range check

* improve documentation

* CA: add event for setting CENTER with TRIM

Signed-off-by: Silvan <silvan@auterion.com>

---------

Signed-off-by: Silvan <silvan@auterion.com>
Co-authored-by: Silvan <silvan@auterion.com>
ttechnick added a commit that referenced this pull request Jan 21, 2026
Add PWM_*_CENTERx for each servo.
Use a bilinear transform to map actuator_servos to PWM signals.

This solution only works for PWM based servos. Other types of servos are not affected.

* PWM: Add servo trim option

* PWM: Improve documentation of PWM trim feature

* PWM: cleaner clamping and docs typo

* update documentation & safety

* add migration formula

* rename param from trim to center

* docs with center instead of trim

* move clamping and reorder values

* improve documentation

* adress failing range check

* improve documentation

* CA: add event for setting CENTER with TRIM

Signed-off-by: Silvan <silvan@auterion.com>

---------

Signed-off-by: Silvan <silvan@auterion.com>
Co-authored-by: Silvan <silvan@auterion.com>
sfuhrer added a commit that referenced this pull request Jan 22, 2026
Add PWM_*_CENTERx for each servo.
Use a bilinear transform to map actuator_servos to PWM signals.

This solution only works for PWM based servos. Other types of servos are not affected.

* PWM: Add servo trim option

* PWM: Improve documentation of PWM trim feature

* PWM: cleaner clamping and docs typo

* update documentation & safety

* add migration formula

* rename param from trim to center

* docs with center instead of trim

* move clamping and reorder values

* improve documentation

* adress failing range check

* improve documentation

* CA: add event for setting CENTER with TRIM

Signed-off-by: Silvan <silvan@auterion.com>

---------

Signed-off-by: Silvan <silvan@auterion.com>
Co-authored-by: Silvan <silvan@auterion.com>
mbjd pushed a commit that referenced this pull request Feb 17, 2026
Add PWM_*_CENTERx for each servo.
Use a bilinear transform to map actuator_servos to PWM signals.

This solution only works for PWM based servos. Other types of servos are not affected.

* PWM: Add servo trim option

* PWM: Improve documentation of PWM trim feature

* PWM: cleaner clamping and docs typo

* update documentation & safety

* add migration formula

* rename param from trim to center

* docs with center instead of trim

* move clamping and reorder values

* improve documentation

* adress failing range check

* improve documentation

* CA: add event for setting CENTER with TRIM

Signed-off-by: Silvan <silvan@auterion.com>

---------

Signed-off-by: Silvan <silvan@auterion.com>
Co-authored-by: Silvan <silvan@auterion.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants