Skip to content

Fix missing ACCGYRO custom alignment defines (used in config) #14092

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Jan 17, 2025

Conversation

haslinghuis
Copy link
Member

@haslinghuis haslinghuis commented Dec 18, 2024

  • we have migrated custom alignment from unified targets using
GYRO_1_ALIGN_ROLL 
GYRO_1_ALIGN_PITCH
GYRO_1_ALIGN_YAW

but they are not being used

@haslinghuis haslinghuis added this to the 4.6 milestone Dec 18, 2024
@haslinghuis haslinghuis self-assigned this Dec 18, 2024
Copy link

Do you want to test this code? You can flash it directly from Betaflight Configurator:

  • Simply put #14092 (this pull request number) in the Select commit field of the Configurator firmware flasher tab (you need to Enable expert mode, Show release candidates and Development).

WARNING: It may be unstable. Use only for testing!

@haslinghuis haslinghuis changed the title Fix missing align defines Fix missing ACCGYRO custom alignment defines Dec 18, 2024
ledvinap
ledvinap previously approved these changes Dec 18, 2024
#define CUSTOM_ALIGN_CW90_DEG_FLIP SENSOR_ALIGNMENT( 0, 180, 90)
#define CUSTOM_ALIGN_CW180_DEG_FLIP SENSOR_ALIGNMENT( 0, 180, 180)
#define CUSTOM_ALIGN_CW270_DEG_FLIP SENSOR_ALIGNMENT( 0, 180, 270)
#define CUSTOM_ALIGN_CW0_DEG SENSOR_ALIGNMENT( 0, 0, 0 )
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd keep only 8 basic alignments and use macro for rest:

#define CUSTOM_ALIGN_CW(deg)   SENSOR_ALIGNMENT(0, 0, (deg));
#define CUSTOM_ALIGN_CW_FLIP(deg)   SENSOR_ALIGNMENT(0, 180, (deg));
#define CUSTOM_ALIGN_CW0_DEG CUSTOM_ALIGN_CW(0)
#define CUSTOM_ALIGN_CW90_DEG_FLIP CUSTOM_ALIGN_CW_FLIP(90)

Copy link
Member Author

Choose a reason for hiding this comment

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

This would be

// #define CUSTOM_ALIGN_CW0_DEG         SENSOR_ALIGNMENT( 0,   0,   0 )
#define CUSTOM_ALIGN_CW90_DEG        SENSOR_ALIGNMENT( 0,   0,  90 )
#define CUSTOM_ALIGN_CW180_DEG       SENSOR_ALIGNMENT( 0,   0, 180 )
#define CUSTOM_ALIGN_CW270_DEG       SENSOR_ALIGNMENT( 0,   0, 270 )
#define CUSTOM_ALIGN_CW0_DEG_FLIP    SENSOR_ALIGNMENT( 0, 180,   0 )
#define CUSTOM_ALIGN_CW45_DEG_FLIP   SENSOR_ALIGNMENT( 0, 180,  45 )
// #define CUSTOM_ALIGN_CW90_DEG_FLIP   SENSOR_ALIGNMENT( 0, 180,  90 )
#define CUSTOM_ALIGN_CW180_DEG_FLIP  SENSOR_ALIGNMENT( 0, 180, 180 )
#define CUSTOM_ALIGN_CW270_DEG_FLIP  SENSOR_ALIGNMENT( 0, 180, 270 )

#define CUSTOM_ALIGN_CW(deg)         SENSOR_ALIGNMENT( 0, 0, (deg) )
#define CUSTOM_ALIGN_CW_FLIP(deg)    SENSOR_ALIGNMENT( 0, 180, (deg) )
#define CUSTOM_ALIGN_CW0_DEG         CUSTOM_ALIGN_CW( 0 )
#define CUSTOM_ALIGN_CW90_DEG_FLIP   CUSTOM_ALIGN_CW_FLIP( 90 )

Copy link
Contributor

Choose a reason for hiding this comment

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

It is IMO better to cascade it. That way, it is easier to change CUSTOM_ALIGN internals

#define CUSTOM_ALIGN_CW90_DEG   CUSTOM_ALIGN_CW(90)
....

@@ -61,14 +61,22 @@ typedef union sensorAlignment_u {
.yaw = DEGREES_TO_DECIDEGREES(YAW), \
Copy link
Contributor

Choose a reason for hiding this comment

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

Above:

#define SENSOR_ALIGNMENT(ROLL, PITCH, YAW) ((const sensorAlignment_t){\

At least in some situations it generated considerably better code

@ledvinap ledvinap dismissed their stale review December 18, 2024 18:38

Add new one

@haslinghuis
Copy link
Member Author

haslinghuis commented Dec 18, 2024

Consensus Idea is too use SENSOR_ALIGN( 0, 180, 270) // 270 flip directly in configuration as this would be easier to use for manufacturers

@ledvinap
Copy link
Contributor

ledvinap commented Dec 18, 2024

(please don't force-push this PR now - I'm working on PR against your branch)

(edited - original version had wrong interpretation)

@haslinghuis
Copy link
Member Author

Another idea would be to use current defines for filling up SENSOR_ALIGNMENT define

@ledvinap
Copy link
Contributor

@haslinghuis : Look at haslinghuis#7

If GYRO_x_ALIGN is defined, it is used to fill both alignment and customAlignment.
When GYRO_1_CUSTOM_ALIGN is set, GYRO_1_ALIGN must be either undefined or ALIGN_CUSTOM and GYRO_1_CUSTOM_ALIGN is used for customAlignment
When both are defined, code enforces that GYRO_1_ALIGN == ALIGN_CUSTOM (needs testing)

This should IMO handle intended use and allow easy transition from STD align in code

@ledvinap
Copy link
Contributor

@haslinghuis : The code is not tested .

@haslinghuis
Copy link
Member Author

Agree. Custom defines in first message were not being used. Configuration repository needs update.
Two situations:

  • migrated configurations from unified targets
  • new targets defined custom alignments but were not working due to missing definition

@haslinghuis
Copy link
Member Author

haslinghuis commented Dec 18, 2024

@haslinghuis
Copy link
Member Author

@ledvinap think best uniform way this should be used as (to simplify configuration):

#define GYRO_1_CUSTOM_ALIGN SENSOR_ALIGNMENT( ROLL, PITCH, YAW )
#define GYRO_2_CUSTOM_ALIGN SENSOR_ALIGNMENT( ROLL, PITCH, YAW )

@haslinghuis
Copy link
Member Author

haslinghuis commented Dec 19, 2024

@ledvinap to retain configuration defines in config repository how about

#ifndef GYRO_1_ALIGN_ROLL
#define GYRO_1_ALIGN_ROLL 0
#endif

#ifndef GYRO_1_ALIGN_PITCH
#define GYRO_1_ALIGN_PITCH 0
#endif

#ifndef GYRO_1_ALIGN_YAW
#define GYRO_1_ALIGN_YAW 0
#endif

#ifndef GYRO_2_ALIGN_ROLL
#define GYRO_2_ALIGN_ROLL 0
#endif

#ifndef GYRO_2_ALIGN_PITCH
#define GYRO_2_ALIGN_PITCH 0
#endif

#ifndef GYRO_2_ALIGN_YAW
#define GYRO_2_ALIGN_YAW 0
#endif

#define GYRO_1_CUSTOM_ALIGN SENSOR_ALIGNMENT( GYRO_1_ALIGN_ROLL, GYRO_1_ALIGN_PITCH, GYRO_1_ALIGN_YAW )

#define GYRO_2_CUSTOM_ALIGN SENSOR_ALIGNMENT( GYRO_2_ALIGN_ROLL, GYRO_2_ALIGN_PITCH, GYRO_2_ALIGN_YAW )

@ledvinap
Copy link
Contributor

@ledvinap
Copy link
Contributor

@ledvinap to retain configuration defines in config repository how about

  • there are 2 targets using custom align, it is easier to fix them

  • all three GYRO_1_ALIGN_x are defined together, so

#def GYRO_1_ALIGN_ROLL
# ifndef GYRO_1_CUSTOM_ALIGN 
#  define GYRO_1_CUSTOM_ALIGN SENSOR_ALIGNMENT( GYRO_1_ALIGN_ROLL, GYRO_1_ALIGN_PITCH, GYRO_1_ALIGN_YAW )
# else
#  error "GYRO_1_ALIGN_x and GYRO_1_CUSTOM_ALIGN  are mutually exclusive"
# endif
#endif

@ledvinap
Copy link
Contributor

@haslinghuis:

SENSOR_ALIGNMENT_FROM_STD is not necessary now, but maybe keep it - custom alignment parameters will be always valid ant it can be later used to unify alignment, scaling and offset compensation.

#define CUSTOM_ALIGN_CW90_DEG_FLIP SENSOR_ALIGNMENT( 0, 180, 90)
#define CUSTOM_ALIGN_CW180_DEG_FLIP SENSOR_ALIGNMENT( 0, 180, 180)
#define CUSTOM_ALIGN_CW270_DEG_FLIP SENSOR_ALIGNMENT( 0, 180, 270)
#define CUSTOM_ALIGN_CW0_DEG SENSOR_ALIGNMENT( 0, 0, 0 )
Copy link
Contributor

Choose a reason for hiding this comment

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

It is IMO better to cascade it. That way, it is easier to change CUSTOM_ALIGN internals

#define CUSTOM_ALIGN_CW90_DEG   CUSTOM_ALIGN_CW(90)
....

@nerdCopter
Copy link
Member

grep -r -Z -l 'GYRO_1_ALIGN ' . | xargs -0 grep 'GYRO_1_ALIGN_'

there are some GYRO_2_ as well
grep -r -Z -l 'GYRO_[12]_ALIGN ' . | xargs -0 grep 'GYRO_[12]_ALIGN_'

Copy link
Member

@nerdCopter nerdCopter left a comment

Choose a reason for hiding this comment

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

approving for workflow, not tested, only visually reviewed.

@haslinghuis haslinghuis changed the title Fix missing ACCGYRO custom alignment defines Fix missing ACCGYRO custom alignment defines (used in config) Jan 2, 2025
@haslinghuis
Copy link
Member Author

@blckmn please approve / review

@blckmn blckmn merged commit c188a03 into betaflight:master Jan 17, 2025
27 checks passed
haslinghuis added a commit to haslinghuis/betaflight that referenced this pull request Jan 17, 2025
haslinghuis added a commit that referenced this pull request Jan 18, 2025
* Fix missing ACCGYRO custom alignment defines (used in config) (#14092)

* Remove CLKIN pin not available in 4.5

* Update src/main/common/sensor_alignment_impl.h

Co-authored-by: Petr Ledvina <ledvinap@gmail.com>

---------

Co-authored-by: Petr Ledvina <ledvinap@gmail.com>
@haslinghuis haslinghuis deleted the add-missing-align-defines branch April 23, 2025 14:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

Successfully merging this pull request may close these issues.

4 participants