-
Notifications
You must be signed in to change notification settings - Fork 1
steami_config: Add accelerometer calibration storage. #323
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
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
47c91c7
feat(ism330dl): add permanent config for calibration
Charly-sketch 53415d5
feat(ism330dl): add example for permanent config
Charly-sketch ad477c2
feat(ism330dl): add accelerometer offset support and calibration helpers
Charly-sketch 1f80aac
feat(steami_config): add ism330dl calibration persistence
Charly-sketch 1cf93fb
feat(steami_config): add accelerometer calibration example for ISM330DL
Charly-sketch 74c5b0e
test(ism330dl): add accelerometer offset tests
Charly-sketch edc9a23
test(steami_config): add accelerometer calibration tests
Charly-sketch 109372e
docs(ism330dl): add accelerometer calibration
Charly-sketch da38e62
docs(steami_config): add accelerometer calibration
Charly-sketch f6c1c8b
docs(steami_config): update accelerometer calibration section in README
Charly-sketch 76ce8b2
style(steami_config): remove unnecessary blank lines in device.py
Charly-sketch 269db82
refactor(steami_config): rename accelerometer calibration key to redu…
Charly-sketch 6847a16
docs(steami_config): clarify Z offset calculation in comments
Charly-sketch 3d3a5b7
docs(ism330dl): add separation after get offset
Charly-sketch e9de067
test(steami_config): rename accelerometer calibration key for ISM330DL
Charly-sketch File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| """Calibrate ISM330DL accelerometer bias and save to persistent config. | ||
|
|
||
| This example measures accelerometer offsets while the board is lying flat. | ||
| The computed offsets (ox, oy, oz) are stored in the config zone and | ||
| survive power cycles. | ||
|
|
||
| Instructions: | ||
| - Place the board flat and still (screen up) | ||
| - Wait for measurement | ||
| """ | ||
|
|
||
| from time import sleep_ms | ||
|
|
||
| from daplink_bridge import DaplinkBridge | ||
| from ism330dl import ISM330DL | ||
| from machine import I2C | ||
| from steami_config import SteamiConfig | ||
|
|
||
| # --- Init --- | ||
|
|
||
| i2c = I2C(1) | ||
| bridge = DaplinkBridge(i2c) | ||
| config = SteamiConfig(bridge) | ||
| config.load() | ||
|
|
||
| imu = ISM330DL(i2c) | ||
|
|
||
| print("=== Accelerometer Calibration ===\n") | ||
| print("Place the board flat (screen up) and keep it still...") | ||
| sleep_ms(2000) | ||
|
|
||
| # --- Step 1: Collect samples --- | ||
|
|
||
| samples = 100 | ||
| sx = sy = sz = 0.0 | ||
|
|
||
| for _ in range(samples): | ||
| ax, ay, az = imu.acceleration_g() | ||
| sx += ax | ||
| sy += ay | ||
| sz += az | ||
| sleep_ms(20) | ||
|
|
||
| ax = sx / samples | ||
| ay = sy / samples | ||
| az = sz / samples | ||
|
|
||
| # Expected resting orientation: flat, screen up -> (0, 0, -1g) | ||
| ox = ax | ||
| oy = ay | ||
| oz = az + 1.0 | ||
| # Flat, screen up → expected (0,0,-1g), so Z offset = measured - (-1g) = az + 1.0 | ||
| # because gravity points downward while the sensor Z axis is defined positive downward | ||
|
|
||
| print("\nMeasured average:") | ||
| print(" ax = {:.3f} g".format(ax)) | ||
| print(" ay = {:.3f} g".format(ay)) | ||
| print(" az = {:.3f} g".format(az)) | ||
|
|
||
| print("\nComputed offsets:") | ||
| print(" ox = {:.3f} g".format(ox)) | ||
| print(" oy = {:.3f} g".format(oy)) | ||
| print(" oz = {:.3f} g".format(oz)) | ||
|
|
||
| # --- Step 2: Save to config zone --- | ||
|
|
||
| config.set_accelerometer_calibration(ox=ox, oy=oy, oz=oz) | ||
| config.save() | ||
|
|
||
| print("\nCalibration saved to config zone.") | ||
|
|
||
| # --- Step 3: Verify after reload --- | ||
|
|
||
| config2 = SteamiConfig(bridge) | ||
| config2.load() | ||
|
|
||
| imu2 = ISM330DL(i2c) | ||
| config2.apply_accelerometer_calibration(imu2) | ||
|
|
||
| print("\nApplied offsets after reload:") | ||
| ox2, oy2, oz2 = imu2.get_accel_offset() | ||
| print(" ox = {:.3f} g".format(ox2)) | ||
| print(" oy = {:.3f} g".format(oy2)) | ||
| print(" oz = {:.3f} g".format(oz2)) | ||
|
|
||
| print("\nVerification (5 corrected readings):") | ||
| for i in range(5): | ||
| ax, ay, az = imu2.acceleration_g() | ||
| print(" {}: ax={:.3f} ay={:.3f} az={:.3f}".format(i + 1, ax, ay, az)) | ||
| sleep_ms(500) | ||
|
|
||
| print("\nDone! Calibration is stored and will be restored at next boot.") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.