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

forward declaration to avoid ARM-specific __fp16 in transitive dependency of stabilizer_types.h #676

Closed
wants to merge 1 commit into from

Conversation

jpreiss
Copy link
Contributor

@jpreiss jpreiss commented Jan 27, 2021

stabilizer_types.h now depends on lighthouse_calibration.h, which depends on ootx_decoder.h, which defines a struct containing the __fp16 type. This type does not exist on x86, so it breaks the Crazyswarm Python bindings for stabilizer_types.h.

Since lighthouse_calibration.h only declares functions that accept a pointer to the struct containing __fp16, we can use a forward declaration instead.

(In contrast, making stabilizer_types.h not depend on lighthouse_calibration.h at all would require forward-declaring some nontrivial function pointer typedef.)

@jpreiss
Copy link
Contributor Author

jpreiss commented Jan 27, 2021

Sorry, I forgot to build/run the tests. Will fix this.

@jpreiss
Copy link
Contributor Author

jpreiss commented Jan 27, 2021

It seems that the test problem is nontrivial because CMock only generates mocks based on the header file, so it can't mock the functions that accept that struct. I'm not familiar enough with CMock to fix this problem at the CMock configuration level.

We could also use conditional compilation to switch between forward declaration and including, either with a flag for test builds, or a flag for x86 builds.

Maybe the easiest solution is to just #define __fp16 uint16_t in our bindings, since we don't need that struct anyway...

@jpreiss
Copy link
Contributor Author

jpreiss commented Jan 28, 2021

adopting the "easiest solution" above for now and closing. please comment if there's a less hacky way to get around this that I'm missing.

@jpreiss jpreiss closed this Jan 28, 2021
@krichardsson
Copy link
Contributor

Hi @jpreiss !

Yeah, the dependency tree is a not stellar and some clean up would be nice at some point...

The reason there is a dependency to lighthouse is that it is needed for the sweepAngleMeasurement_t that is used when pushing data into the estimators.

I have only had a 5 min look at this, but what would happen if we moved the estimator related types to estimator.h instead?

@jpreiss
Copy link
Contributor Author

jpreiss commented Jan 29, 2021

@krichardsson Hi! thanks for taking a look.

Moving structs to estimator.h might fix the problem for now, but it would return if we want bindings to the estimator modules in the future. I could see that happening for SITL testing.

The uint16_t workaround feels OK to me. In general, we expect C primitive types to exist on both platforms. __fp16 is a weird edge case. ootx_decoder.h does not depend on any ARM headers, so it is already "clean" in the sense we normally mean w.r.t. firmware bindings.

@jpreiss jpreiss mentioned this pull request Sep 27, 2021
cafeciaojoe pushed a commit to cafeciaojoe/crazyflie-firmware that referenced this pull request Sep 27, 2024
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.

2 participants