Skip to content
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

GYRO_x_ALIGN_YAW #645

Merged
merged 8 commits into from
Dec 20, 2024
Merged

Conversation

ledvinap
Copy link
Contributor

@ledvinap ledvinap commented Dec 19, 2024

use strict;
use warnings;
my ($gyro_id, $angle);
while (<>) {
if (/^#define GYRO_([12])_ALIGN CW(90|180|270)DEG$/) {
$gyro_id = $1;
$angle = $2;
print; # Print the first line
next;
}
if (defined($gyro_id) && /^#define GYRO
\Q$gyro_id\E_ALIGN_YAW \Q$angle\E0$/) {
undef $gyro_id; # Skip the second line if it matches
next;
}
undef $gyro_id; # Reset if no match
print;
}

use strict;
use warnings;
my ($gyro_id, $angle);
while (<>) {
    if (/^#define GYRO_([12])_ALIGN CW(90|180|270)_DEG$/) {
        $gyro_id = $1;
        $angle = $2;
        print;                  # Print the first line
        next;
    }
    if (defined($gyro_id) && /^#define GYRO_\Q$gyro_id\E_ALIGN_YAW \Q$angle\E0$/) {
        undef $gyro_id;         # Skip the second line if it matches
        next;
    }
    undef $gyro_id;             # Reset if no match
    print;
}
@ledvinap
Copy link
Contributor Author

This removes simple cases. 80 _FLIP still remaining, but that is manageable manually

@haslinghuis
Copy link
Member

grep -r -Z -l 'GYRO_1_ALIGN ' . | xargs -0 sed -i '/GYRO_1_ALIGN_/d'
grep -r -Z -l 'GYRO_2_ALIGN ' . | xargs -0 sed -i '/GYRO_2_ALIGN_/d'

BEGIN {undef $/;}

s/(^\#define\s+GYRO_([12])_ALIGN\s+CW(90|180|270)_DEG)\n
\#define\s+GYRO_\g2_ALIGN_YAW\s+\g3[0]
/$1/mx;

s/(^\#define\s+GYRO_([12])_ALIGN\s+CW(90|180|270)_DEG_FLIP)\n
\#define\s+GYRO_\g2_ALIGN_PITCH\s+1800\n
\#define\s+GYRO_\g2_ALIGN_YAW\s+\g3[0]
/$1/mx;
@ledvinap
Copy link
Contributor Author

fix.pl (ugly, but does the job):

BEGIN {undef $/;}

s/(^\#define\s+GYRO_([12])_ALIGN\s+CW(90|180|270)_DEG)\n
\#define\s+GYRO_\g2_ALIGN_YAW\s+\g3[0]
/$1/mx;

s/(^\#define\s+GYRO_([12])_ALIGN\s+CW(90|180|270)_DEG_FLIP)\n
\#define\s+GYRO_\g2_ALIGN_PITCH\s+1800\n
\#define\s+GYRO_\g2_ALIGN_YAW\s+\g3[0]
/$1/mx;

then, in betaflight directory:

find ./src/config/configs/ -name "config.h" -exec perl -i"" -p ./fix.pl {} +

(better newline handling in perl script)

BEGIN {undef $/;}

s/(^\#define\s+GYRO_([12])_ALIGN\s+CW(90|180|270)_DEG\n)
\#define\s+GYRO_\g2_ALIGN_YAW\s+\g3[0]\n
/$1/mxg;

s/(^\#define\s+GYRO_([12])_ALIGN\s+CW(90|180|270)_DEG_FLIP\n)
\#define\s+GYRO_\g2_ALIGN_PITCH\s+1800\n
\#define\s+GYRO_\g2_ALIGN_YAW\s+\g3[0]\n
/$1/mxg;

s/(^\#define\s+GYRO_([12])_ALIGN\s+CW0_DEG_FLIP\n)
\#define\s+GYRO_\g2_ALIGN_PITCH\s+1800\n
(?!\#define\s+GYRO_\g2_ALIGN_)
/$1/mxg;
@ledvinap
Copy link
Contributor Author

BEGIN {undef $/;}

s/(^\#define\s+GYRO_([12])_ALIGN\s+CW(90|180|270)_DEG\n)
\#define\s+GYRO_\g2_ALIGN_YAW\s+\g3[0]\n
(?!\#define\s+GYRO_\g2_ALIGN_)
/$1/mxg;

s/(^\#define\s+GYRO_([12])_ALIGN\s+CW(90|180|270)_DEG_FLIP\n)
\#define\s+GYRO_\g2_ALIGN_PITCH\s+1800\n
\#define\s+GYRO_\g2_ALIGN_YAW\s+\g3[0]\n
(?!\#define\s+GYRO_\g2_ALIGN_)
/$1/mxg;

s/(^\#define\s+GYRO_([12])_ALIGN\s+CW0_DEG_FLIP\n)
\#define\s+GYRO_\g2_ALIGN_PITCH\s+1800\n
(?!\#define\s+GYRO_\g2_ALIGN_)
/$

@ledvinap
Copy link
Contributor Author

There are some files with DOS line endings (\r\n), it should be fixed eventually

@ledvinap
Copy link
Contributor Author

OK, I think all trivial case are handled. Rest should be handled individually, based on actual target.

@haslinghuis
Copy link
Member

@ledvinap

Roll axis (GYRO_1_ALIGN_ROLL) ??? as this define would make it custom

$ grep -rni GYRO_1_ALIGN_ROLL
configs/FLYCOLORF7_AIO/config.h:115:#define GYRO_1_ALIGN_ROLL 0
configs/TALONF4V2/config.h:109:#define GYRO_1_ALIGN_ROLL 0

@ledvinap
Copy link
Contributor Author

@haslinghuis : I don't see in in last version

@haslinghuis
Copy link
Member

image

@ledvinap
Copy link
Contributor Author

@haslinghuis : FLYFISHRCF405 gyro2 is wrong. With current implementation, CW90_DEG is used and ALIGN_PITCH 900 ignored. But someone should check it (and all other conflicting gyro definitions).

I'd fix easy cases and enable ASSERT in accgyro. Affected targets will fail until someone fixes them

@ledvinap
Copy link
Contributor Author

I think I fixed all trivial cases. Someone should check remaining ones.
Valid custom cases are now marked (GYRO_1_ALIGN ALIGN_CUSTOM)

find ./src/config/configs -type f -name "*.h" -exec grep --color=auto -nH --null -e GYRO_[12]_ALIGN_[RPY] \{\} +

@haslinghuis
Copy link
Member

Thanks. Spotted an issue outside of this change:

image

-45 should be -450 or 3600 - 450 = 3150 ?

@ledvinap
Copy link
Contributor Author

-45 should be -450 or 3600 - 450 = 3150 ?

IMO both should work fine, argument is normalized before use.

 { "gyro_1_align_roll", VAR_INT16  | HARDWARE_VALUE, .config.minmax = { -3600, 3600 }, PG_GYRO_DEVICE_CONFIG, PG_ARRAY_ELEMENT_OFFSET(gyroDeviceConfig_t, 0, customAlignment.roll) },

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, only skimmed over, saw some nice cleanups

@haslinghuis haslinghuis mentioned this pull request Dec 20, 2024
@haslinghuis haslinghuis merged commit ac7c65c into betaflight:master Dec 20, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants