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

[Feature] Implement pybricks.hubs.MoveHub.imu.tilt #539

Closed
laurensvalk opened this issue Nov 22, 2021 · 9 comments
Closed

[Feature] Implement pybricks.hubs.MoveHub.imu.tilt #539

laurensvalk opened this issue Nov 22, 2021 · 9 comments
Assignees
Labels
documentation Improvements or additions to documentation enhancement New feature or request hub: movehub Issues related to the LEGO BOOST Move hub topic: sensors Issues involving sensors

Comments

@laurensvalk
Copy link
Member

laurensvalk commented Nov 22, 2021

Is your feature request related to a problem? Please describe.
The Move Hub has had an experimental IMU implementation for a while now. There's not enough space to implement something equivalent to the other hubs.

Since V3.1 may be the last release for Move Hub, we'll want to make sure this is working the way we want. And documented accordingly.

It may be useful to see if we can implement a crude version of tilt/roll measurement, as this is really the main use case for having the IMU enabled in the first place. The user can't really do this in their code since floating point support isn't enabled, and look-up tables in user code would take too much space.

Maybe we can use libfixmath.

@laurensvalk laurensvalk added documentation Improvements or additions to documentation enhancement New feature or request hub: movehub Issues related to the LEGO BOOST Move hub topic: sensors Issues involving sensors labels Nov 22, 2021
@dlech
Copy link
Member

dlech commented Nov 22, 2021

I was able to use the existing API for the R2-D2 example without problems, so I would be fine not adding/changing anything.

@laurensvalk
Copy link
Member Author

That sounds good. Also, I'm not going to have time to look at this any time soon, so let's not hang V3.1 on it.

So :shipit: 🚢

@laurensvalk
Copy link
Member Author

It should be feasible to implement tilt using libfixmath.

As for base orientation specification, we can't use the Axis in the hub init like we do for the other hubs, but we could instead provide a Side argument to tilt to specify which side of the hub is "up" in the (0, 0) orientation.

@laurensvalk laurensvalk changed the title [Feature] Finalize and document pybricks.hubs.MoveHub.imu [Feature] Implement pybricks.hubs.MoveHub.imu Jan 13, 2022
@laurensvalk laurensvalk self-assigned this Jan 13, 2022
@laurensvalk

This comment was marked as resolved.

@laurensvalk laurensvalk changed the title [Feature] Implement pybricks.hubs.MoveHub.imu [Feature] Implement pybricks.hubs.MoveHub.imu.tilt Jan 13, 2022
@laurensvalk
Copy link
Member Author

It should be feasible to implement tilt using libfixmath.

As for base orientation specification, we can't use the Axis in the hub init like we do for the other hubs, but we could instead provide a Side argument to tilt to specify which side of the hub is "up" in the (0, 0) orientation.

This works quite nicely: https://github.com/pybricks/pybricks-micropython/tree/movehub-tilt

But it takes up a bit too much space: 832 bytes.

This is partly due to bringing in fix16 trigonometry. This may not be worth it unless we use it for other things like pybricks/pybricks-micropython#93

@laurensvalk
Copy link
Member Author

But it takes up a bit too much space: 832 bytes.

Now that libfixmath is no longer used, this implementation would be about +1000 bytes.

Here's a new variant that is about +550 bytes. Out of that 200 bytes comes from an integer implementation for atan2.

It works by interpolating a few points (green) on the positive side, and derives the full result from there (orange). It is quite close to the real result (blue).

image

This is accurate enough for roll computation:

image

The code for linear interpolation can be shared with approximations for other trigonometric functions if/when we have any.

@laurensvalk
Copy link
Member Author

laurensvalk commented Oct 27, 2023

I'm going to give this a final push for this release:

  • It makes sense for our upcoming code editor --- hub init and acceleration reads would all be the same
  • Since the Move Hub has BLE broadcast, broadcasting tilt makes it a great contender for remote control.

@laurensvalk
Copy link
Member Author

@laurensvalk
Copy link
Member Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request hub: movehub Issues related to the LEGO BOOST Move hub topic: sensors Issues involving sensors
Projects
None yet
Development

No branches or pull requests

2 participants