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

AP_Compass: add IIS2MDC driver #28602

Merged
merged 1 commit into from
Jan 15, 2025

Conversation

dakejahl
Copy link
Contributor

Adds a driver for the ST IIS2MDC magnetometer
https://www.st.com/resource/en/datasheet/iis2mdc.pdf

Copy link
Contributor

@peterbarker peterbarker left a comment

Choose a reason for hiding this comment

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

Please fold the commits.

Please also outline the testing you've done.

@dakejahl
Copy link
Contributor Author

Please fold the commits.

Done. Should I do a separate commit for Tools/? I assumed a single commit since this PR should be atomic.

Please also outline the testing you've done.

Bench tested on the ARK FPV. I've uploaded the log file to Drive.

QGC
Screenshot from 2024-11-17 19-29-13
PlotJuggler
Screenshot from 2024-11-17 20-56-37

@dakejahl dakejahl force-pushed the pr-compass_iis2mdc branch 2 times, most recently from 553dc1f to 6750137 Compare November 19, 2024 01:19
@dakejahl
Copy link
Contributor Author

dakejahl commented Dec 2, 2024

@peterbarker can you let me know if there's anything else here you'd like to see?

@dakejahl
Copy link
Contributor Author

dakejahl commented Jan 7, 2025

Is there anything else needed to get this merged? The ARK FPV board support depends on it.

I've also uploaded a flight log in position mode demonstrating functionality
#28603 (comment)

Copy link
Contributor

@peterbarker peterbarker left a comment

Choose a reason for hiding this comment

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

LGTM apart from the minor include issue

@dakejahl
Copy link
Contributor Author

BTW, this driver will also work for the LIS2MDL. Just discovered this while doing a betaflight port board. ST says that this is basically just a better version of the LIS2MDL

LIS2MDL, IIS2MDC, LSM303AGR and LSM303AH are firmware and pin-to-pin compatible solutions

https://www.st.com/resource/en/design_tip/dt0131-digital-magnetometer-and-ecompass-efficient-design-tips--stmicroelectronics.pdf

@andyp1per
Copy link
Collaborator

Binary Name      Text [B]        Data [B]     BSS (B)        Total Flash Change [B] (%)      Flash Free After PR (B)
---------------  --------------  -----------  -------------  ----------------------------  -------------------------
arducopter-heli  996 (+0.0546%)  0 (0.0000%)  4 (+0.0015%)   996 (+0.0545%)                                   137060
antennatracker   996 (+0.0739%)  0 (0.0000%)  -4 (-0.0015%)  996 (+0.0738%)                                   614956
arducopter       996 (+0.0546%)  0 (0.0000%)  -4 (-0.0015%)  996 (+0.0544%)                                   135436
ardurover        996 (+0.0596%)  0 (0.0000%)  4 (+0.0015%)   996 (+0.0595%)                                   292164
arduplane        996 (+0.0550%)  0 (0.0000%)  4 (+0.0015%)   996 (+0.0549%)                                   149348
blimp            996 (+0.0727%)  0 (0.0000%)  -4 (-0.0015%)  996 (+0.0726%)                                   592608
ardusub          996 (+0.0617%)  0 (0.0000%)  -4 (-0.0015%)  996 (+0.0616%)                                   348032

This adds 1k to all the boards that include all the compasses, but none of them are using it. I think we should consider having this off by default or disabling by default one of the other compass drivers that is now little used.

@dakejahl
Copy link
Contributor Author

@andyp1per does ardupilot have a mechanism to enable only certain drivers for a target? For example in PX4 uses Kconfig
https://github.com/PX4/PX4-Autopilot/blob/main/boards/ark/fpv/default.px4board#L17

@andyp1per
Copy link
Collaborator

@andyp1per does ardupilot have a mechanism to enable only certain drivers for a target? For example in PX4 uses Kconfig https://github.com/PX4/PX4-Autopilot/blob/main/boards/ark/fpv/default.px4board#L17

Yes, just define the backends you need -

define AP_BARO_ICM20789_ENABLED 1

@dakejahl dakejahl force-pushed the pr-compass_iis2mdc branch 2 times, most recently from 52c2908 to 4514de3 Compare January 12, 2025 23:21
@dakejahl
Copy link
Contributor Author

@andyp1per hmm it seems that I need to change both of these

Feature('Compass', 'IIS2MDC', 'AP_COMPASS_IIS2MDC_ENABLED', 'Enable IIS2MDC compasses', 0, None),

and

#ifndef AP_COMPASS_IIS2MDC_ENABLED
#define AP_COMPASS_IIS2MDC_ENABLED 0
#endif

which is a little strange since I would expect the latter to only be necessary if the former is missing. I noticed only changing the "Feature" to 0 (default disabled) still results in the .cpp being compiled

@dakejahl
Copy link
Contributor Author

Re-tested on hardware functional.

@andyp1per
Copy link
Collaborator

Feature only affects custom build server.
File will be compiled regardless, but the lack of linkage means it will be elided

@dakejahl
Copy link
Contributor Author

Okay, should I change one of these back to 1? Or does this look good to go?

@andyp1per
Copy link
Collaborator

Looks good to me

@peterbarker peterbarker merged commit 64bb0ad into ArduPilot:master Jan 15, 2025
99 checks passed
@peterbarker
Copy link
Contributor

Merged, thanks!

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.

4 participants