DEV-958: use the ST datasheet accel sensitivity for the gen-2 LSM6DSV - #288
DEV-958: use the ST datasheet accel sensitivity for the gen-2 LSM6DSV#288marknolan wants to merge 3 commits into
Conversation
SensorLSM6DSV derived accel sensitivity as 32768/(FS_g*9.80665), while the firmware seed, the web SDK catalog and the driver's own gen-1 classes all use the ST datasheet mg/LSB figure - a 0.0576% split, and the only such divergence left in the gen-2 chain. +-2 g 1670.703 -> 1671.665922915 +-4 g 835.3517 -> 835.832961457 +-8 g 417.6759 -> 417.916480729 +-16 g 208.8379 -> 208.958240364 Worth being explicit that the old values were not a mistake, and this is not a correctness fix. Checked against ST's own vendored driver (lsm6dsv_reg.c): every printed accel figure - 0.061 / 0.122 / 0.244 / 0.488 mg/LSB - is exactly 32768/FS rounded to three significant figures, because the accel really does span the full 16-bit range at nominal full scale. So the derived form was the more precise of the two, and moving to the datasheet figure trades a little accuracy for agreement. Agreement is worth more here. The firmware seeds these values into the on-device calibration blob, so they are what the device reports and what becomes the source of truth once per-unit calibration is honoured; keeping the exact form would leave a 0.0576% step change in calibrated output waiting to surface on that day. 0.0576% is far inside per-unit sensitivity variation. The gyro is a genuinely different case and is deliberately left alone: 4.375 mdps/LSB implies a real full scale of 143.4 dps on the +-125 dps setting, which is where the part is observed to saturate, so there a 32768/FS derivation is wrong by ~14.7% rather than by a rounding. The comment now spells out the distinction so the two are not "fixed" to match each other later. API_00008 CAL locks updated (accel +-4 g literal); 51 driver tests pass. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Aligns the gen-2 SensorLSM6DSV accelerometer sensitivity constants with the ST datasheet nominal mg/LSB figures to keep the Java driver consistent with firmware-seeded calibration defaults and other SDKs/components.
Changes:
- Updated LSM6DSV accel sensitivity matrices (LSB per m/s²) to match datasheet-nominal mg/LSB-derived values, with expanded in-code rationale distinguishing accel vs gyro behavior.
- Updated
API_00008regression-lock assertions and comments to reflect the new default accel sensitivity for ±4 g.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| ShimmerDriver/src/main/java/com/shimmerresearch/verisense/sensors/SensorLSM6DSV.java | Switch accel sensitivity constants to datasheet-nominal-derived values and document the accel/gyro distinction. |
| ShimmerDriver/src/test/java/com/shimmerresearch/verisense/API_00008_VerisenseLsm6dsvTaggedFifoParsing.java | Update regression-locked CAL assertions/comments to the new accel sensitivity constant. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
Correcting the last section of the description: the CSV encoding problem I described does not need a new ticket — it is already fixed and waiting to merge in ShimmerResearch/ASM_PC#365 (DEV-793), which changes all five That also explains the symptom precisely: Nothing changes for this PR. The references regenerated here were produced with |
My previous comment claimed ST's accel figures were just 32768/FS rounded to three significant figures, and that the old derived values were therefore the more accurate of the two. That was wrong, and the datasheet settles it. AN5922 Table 27 (FS_XL = +-2 g) gives worked register contents: 1 g reads 0x4009 = 16393 LSB and 350 mg reads 0x1669 = 5737 LSB. 0.061 mg/LSB predicts 16393.4 and 5737.7; a 32768/FS derivation predicts 16384 and 5734.4. The accelerometer does not map its nominal full scale onto exactly 2^15 counts - it has a small margin, the same phenomenon as the gyro, just far smaller. So the old values were wrong by 0.0576%, and this is a correctness fix rather than a consistency trade-off. The constants themselves are unchanged from the previous commit; only the reasoning recorded beside them. Corroborated four ways: the datasheet worked example, ST's upstream driver (STMicroelectronics/lsm6dsv-pid, byte-identical to the copy this firmware vendors), every example in STMems_Standard_C_drivers/lsm6dsv_STdC/examples, and lsm6dsv_self_test.c in particular - its pass/fail limits are specified in mg, so ST's own self-test only produces correct results if 0.122 mg/LSB is right. Comment-only; 51 driver tests still pass. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
Correction — I had the rationale backwards, and the datasheet settles it. Pushed as The description above claims ST's accel figures are just AN5922 Table 27 ("Content of output data registers vs. acceleration", FS_XL = ±2 g) gives worked register contents:
So the accelerometer does not map its nominal full scale onto exactly 2¹⁵ counts — it has a small margin, the same phenomenon as the gyro, just far smaller (0.058% vs ~14.7%). 0.061 mg/LSB is the real sensitivity, not a rounding. This is therefore a correctness fix, not a consistency trade-off. The old values were wrong by 0.0576%. The outcome is unchanged, but the reasoning recorded in the code now matches reality, so nobody reverts this later on the "32768/FS is exact" argument. Corroborated four ways:
The gyro remains untouched and the accel-vs-gyro distinction still holds; it is a difference of degree, not of kind, and the comment now says so. |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
Suppressed comments (2)
ShimmerDriver/src/main/java/com/shimmerresearch/verisense/sensors/SensorLSM6DSV.java:48
- The class Javadoc sensitivity sentence is grammatically unclear ("0.061 mg/LSB at +-2 g spec of 4.375...") and reads like the accel and gyro clauses are run together. Rewording/punctuation would make the public documentation unambiguous.
* Sensitivities: the ST datasheet nominal for every axis - 0.061 mg/LSB at +-2 g
* spec of 4.375 mdps/LSB at +-125 dps for gyro, and 667 LSB/Gauss for the LIS2MDL
* mag - the last taken from {@link SensorLIS2MDL} rather than duplicated here, so
* calibrated magnetometer output is in GAUSS, consistent with every other Shimmer
* magnetometer and with the per-unit calibration the device stores.
ShimmerDriver/src/main/java/com/shimmerresearch/verisense/sensors/SensorLSM6DSV.java:311
- This accel-sensitivity rationale asserts the 32768/FS derivation is "wrong" and "simply incorrect", which conflicts with the PR description stating this is a consistency change (and that 32768/FS is the more-precise form). Please reconcile the in-code explanation with the PR intent to avoid future readers “fixing” it back based on contradictory rationale.
// These were previously derived as 32768/(FS_g*9.80665), on the assumption that
// the accel spans exactly the full 16-bit range at nominal full scale and that
// ST's printed figures were just that quantity rounded to three significant
// figures. They are not. The datasheet's own worked example (AN5922 Table 27,
// FS_XL = +-2 g) settles it: 1 g reads 0x4009 = 16393 LSB and 350 mg reads
Copilot review on PR #288: my earlier edit left the sentence ungrammatical - dropping "the ST angular-rate" from the first line orphaned the "spec of 4.375 mdps/LSB..." that followed, running the accel and gyro clauses together, and it listed only the +-2 g accel case. Now a list giving all three sensors' nominals with their ranges. Javadoc-only; 51 driver tests still pass. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
Suppressed comments (3)
ShimmerDriver/src/main/java/com/shimmerresearch/verisense/sensors/SensorLSM6DSV.java:328
- The gyro sensitivity note says "unlike the accel above" even though the preceding accel note explicitly explains the accel also does not map nominal full-scale to exactly 2^15 counts. This contradiction could mislead a future reader into thinking accel is special-cased differently than gyro.
// gen-1 LSM6DS3. NOTE: unlike the accel above, the gyro genuinely does NOT span
// the full 16-bit range at its nominal full scale - 4.375 mdps/LSB implies a real
// full scale of 143.4 dps for the +-125 dps setting, which is exactly where the
// part is observed to saturate - so here a 32768/FS derivation is not a rounding
// difference but plainly wrong (~14.7%).
ShimmerDriver/src/test/java/com/shimmerresearch/verisense/API_00008_VerisenseLsm6dsvTaggedFifoParsing.java:154
- The accel sensitivity literal is repeated across three adjacent assertions, which makes it easy for them to drift if the value is updated again. Defining a local constant keeps the regression-lock literal while reducing duplication.
assertEquals(-200 / 835.832961457, cal(aligned0, SensorLSM6DSV.ObjectClusterSensorName.LSM6DSV_ACC_X), 0.0001);
assertEquals(300 / 835.832961457, cal(aligned0, SensorLSM6DSV.ObjectClusterSensorName.LSM6DSV_ACC_Y), 0.0001);
assertEquals(100 / 835.832961457, cal(aligned0, SensorLSM6DSV.ObjectClusterSensorName.LSM6DSV_ACC_Z), 0.0001);
ShimmerDriver/src/test/java/com/shimmerresearch/verisense/API_00008_VerisenseLsm6dsvTaggedFifoParsing.java:148
- The comment documents the gyro sensitivity as 57.142857 LSB/dps, but the assertions (and SensorLSM6DSV constants) use 57.142857143. Keeping the comment consistent avoids confusion when debugging test failures.
// gyro +/-500 dps = 57.142857 LSB/dps (ST 17.50 mdps/LSB);
SensorLSM6DSVderived accel sensitivity as32768/(FS_g*9.80665), while the firmware seed, the web SDK catalog and the driver's own gen-1 classes all use the ST datasheet mg/LSB figure — a 0.0576% split, and the last such divergence in the gen-2 chain.This is a correctness fix — the old values were wrong
AN5922 Table 27 ("Content of output data registers vs. acceleration", FS_XL = ±2 g) gives worked register contents, and they settle it:
32768/FSpredicts40h 09h16h 69hBFh F7hThe accelerometer does not map its nominal full scale onto exactly 2¹⁵ counts — it has a small margin, the same phenomenon as the gyro, just far smaller (0.058% against ~14.7%). So 0.061 mg/LSB is the genuine sensitivity and the old derivation was wrong by 0.0576%.
Corroborated four ways:
STMicroelectronics/lsm6dsv-pid(master) —0.061f / 0.122f / 0.244f / 0.488f, byte-identical to the copy the firmware already vendors.STMems_Standard_C_drivers/lsm6dsv_STdC/examplesconverts through thelsm6dsv_from_fsN_to_mghelpers; none derives32768/FS.lsm6dsv_self_test.cusesfrom_fs4_to_mg, and self-test pass/fail limits are specified in mg — ST's own self-test only comes out right if 0.122 mg/LSB is the true sensitivity.The gyro is deliberately left alone. Same phenomenon, much larger margin: 4.375 mdps/LSB implies a real full scale of 143.4 dps on the ±125 dps setting, exactly where the part is observed to saturate. That was the DEV-793 round-2 bug. The comments spell out the distinction so the two are not "reconciled" to each other later.
These values also match the firmware calibration seed, the web SDK catalog and the gen-1
SensorLSM6DS3/SensorLIS2DW12classes, so the whole gen-2 chain now agrees.Verification
API_00008, whose CAL locks are updated (2 of its 3 accel assertions exceeded the 0.0001 tolerance, exactly as predicted).ASM_PC_00005against the regenerated references: 142 tests, 0 failures.The 41 gen-2 accel reference CSVs in the SharePoint Data Repository have been regenerated. Branches built against a driver without this change will fail those
ASM_PC_00005gen-2 accel comparisons until the ASM_PC submodule pointer is bumped past this merge. Same transition as the DEV-922 regeneration. Old references backed up before overwrite.Note on running the suite locally
ASM_PC_00005currently needsJAVA_TOOL_OPTIONS="-Dfile.encoding=UTF-8", otherwise a default Windows JVM writes the±in theSensor configheader as cp1252 and all 26 gen-2 tests fail on that one header line. Already fixed and awaiting merge in ShimmerResearch/ASM_PC#365, which sets the charset explicitly at all fivePrintWritersites.🤖 Generated with Claude Code