From 8777ae6fb606fbd40977ba85f2c1df81290003c8 Mon Sep 17 00:00:00 2001 From: Mark Nolan Date: Fri, 20 Nov 2026 13:07:16 +0000 Subject: [PATCH] DEV-1521: KXTC9-2050 default calibration is 2047 and 83, as the KXRB5-2042's The KXTC9-2050's output is ratiometric to its supply. Kionix specifies its zero-g offset (1.65 V) and sensitivity (660 mV/g) at Vdd = 3.3 V, with an offset and a sensitivity ratiometric error (KXTC9-2050 Specifications Rev. 2, Table 1). Every Shimmer3 board that carries it (SR31-10, SR47-6, SR48-5, SR49-3) powers it from the same 3.0 V LDO as the MSP430's AVCC, the ADC reference, so in ADC counts it reads 1.5 V (2047) at zero g and 600 mV/g (83 per m/s2): the KXRB5-2042's defaults, and what the firmware's own default calibration record has held since DEV-4. The old 2253 and 92 assumed a 3.3 V supply. A new-IMU Shimmer3 left on default calibration read gravity about 17 % high (A615: 11.5 m/s2). API_00051_Kxtc9DefaultCalibrationTest checks the defaults against the datasheet scaled to 3.0 V, against the KXRB5-2042's, and A615's raw sample at rest. All three fail on the old values. Co-Authored-By: Claude Opus 5.5 --- .../sensors/kionix/SensorKionixKXTC92050.java | 16 +++-- ...API_00051_Kxtc9DefaultCalibrationTest.java | 58 +++++++++++++++++++ 2 files changed, 68 insertions(+), 6 deletions(-) create mode 100644 ShimmerDriver/src/test/java/com/shimmerresearch/sensors/kionix/API_00051_Kxtc9DefaultCalibrationTest.java diff --git a/ShimmerDriver/src/main/java/com/shimmerresearch/sensors/kionix/SensorKionixKXTC92050.java b/ShimmerDriver/src/main/java/com/shimmerresearch/sensors/kionix/SensorKionixKXTC92050.java index 4a6732ba1..c8f326f89 100644 --- a/ShimmerDriver/src/main/java/com/shimmerresearch/sensors/kionix/SensorKionixKXTC92050.java +++ b/ShimmerDriver/src/main/java/com/shimmerresearch/sensors/kionix/SensorKionixKXTC92050.java @@ -38,12 +38,16 @@ public class SensorKionixKXTC92050 extends SensorKionixAccel { //--------- Sensor specific variables start -------------- public static final double[][] AlignmentMatrixLowNoiseAccelShimmer3 = {{0,-1,0},{-1,0,0},{0,0,-1}}; - // Based on a manufacturer stated, typical zero-g offset of 1.65V per axis over an input of 0v to 3v - // [(1.65/3)*4096 = 2252.8] - public static final double[][] OffsetVectorLowNoiseAccelShimmer3 = {{2253},{2253},{2253}}; - // Based on a manufacturer stated, typical sensitivity of 660mV/g per axis over an input of 0v to 3v - // [+-2g full-range so 4g (or 39.24 m/s2) over 2.64V -> (2.64/3*4096)/39.24 = 91.85] - public static final double[][] SensitivityMatrixLowNoiseAccel2gShimmer3 = {{92,0,0},{0,92,0},{0,0,92}}; + // DEV-1521. The KXTC9-2050's output is ratiometric to its supply: Kionix specifies its zero-g + // offset (1.65 V) and sensitivity (660 mV/g) at Vdd = 3.3 V, with an offset and a sensitivity + // "ratiometric error" (KXTC9-2050 Specifications Rev. 2, Table 1). Every Shimmer3 board that + // carries it (SR31-10, SR47-6, SR48-5, SR49-3) powers it from the same 3.0 V LDO as the MSP430's + // AVCC, the ADC reference, so in ADC counts it reads like the KXRB5-2042 it replaced: + // zero-g 1.5 V -> (1.5/3)*4095 = 2047.5 + public static final double[][] OffsetVectorLowNoiseAccelShimmer3 = {{2047},{2047},{2047}}; + // 600 mV/g -> (0.6/3)*4095/9.81 = 83.5 per m/s2. 83, as the firmware's own default calibration + // record and the KXRB5-2042's defaults use. The old 2253 and 92 assumed a 3.3 V supply. + public static final double[][] SensitivityMatrixLowNoiseAccel2gShimmer3 = {{83,0,0},{0,83,0},{0,0,83}}; private CalibDetailsKinematic calibDetailsAccelLn2g = new CalibDetailsKinematic( LN_ACCEL_RANGE_VALUE, LN_ACCEL_RANGE_STRING, diff --git a/ShimmerDriver/src/test/java/com/shimmerresearch/sensors/kionix/API_00051_Kxtc9DefaultCalibrationTest.java b/ShimmerDriver/src/test/java/com/shimmerresearch/sensors/kionix/API_00051_Kxtc9DefaultCalibrationTest.java new file mode 100644 index 000000000..311236bdc --- /dev/null +++ b/ShimmerDriver/src/test/java/com/shimmerresearch/sensors/kionix/API_00051_Kxtc9DefaultCalibrationTest.java @@ -0,0 +1,58 @@ +package com.shimmerresearch.sensors.kionix; + +import static org.junit.Assert.*; + +import org.junit.Test; + +import com.shimmerresearch.driver.calibration.UtilCalibration; + +/** + * DEV-1521: the KXTC9-2050's default calibration on a Shimmer3. + *

+ * Kionix specifies the KXTC9-2050 at Vdd = 3.3 V (zero-g 1.65 V, 660 mV/g) and gives an offset and + * a sensitivity "ratiometric error": its output scales with its supply. Every Shimmer3 board that + * carries it (SR31-10, SR47-6, SR48-5, SR49-3) powers it from the same 3.0 V LDO as the MSP430's + * AVCC, the ADC reference. In ADC counts it therefore reads like the KXRB5-2042 it replaced, and + * its defaults must be that part's: offset 2047, sensitivity 83. The old 2253 and 92 assumed 3.3 V + * and made an uncalibrated new-IMU Shimmer3 read gravity about 17 % high. + * + * @author Mark Nolan + */ +public class API_00051_Kxtc9DefaultCalibrationTest { + + private static final double ADC_FULL_SCALE = 4095, ADC_VREF = 3.0, SUPPLY = 3.0, G = 9.81; + + @Test + public void defaultsAreTheDatasheetFiguresScaledToTheShimmersThreeVoltSupply() { + double zeroG = 1.65 * SUPPLY / 3.3; // V + double mvPerG = 660 * SUPPLY / 3.3; + double offset = zeroG / ADC_VREF * ADC_FULL_SCALE; // 2047.5 + double sensitivity = mvPerG / 1000 / ADC_VREF * ADC_FULL_SCALE / G; // 83.5 + + for (int axis = 0; axis < 3; axis++) { + assertEquals("offset, axis " + axis, offset, SensorKionixKXTC92050.OffsetVectorLowNoiseAccelShimmer3[axis][0], 1.0); + assertEquals("sensitivity, axis " + axis, sensitivity, SensorKionixKXTC92050.SensitivityMatrixLowNoiseAccel2gShimmer3[axis][axis], 1.0); + } + } + + @Test + public void defaultsMatchTheKxrb5s() { + assertArrayEquals(SensorKionixKXRB52042.OffsetVectorLowNoiseAccelShimmer3, SensorKionixKXTC92050.OffsetVectorLowNoiseAccelShimmer3); + assertArrayEquals(SensorKionixKXRB52042.SensitivityMatrixLowNoiseAccel2gShimmer3, SensorKionixKXTC92050.SensitivityMatrixLowNoiseAccel2gShimmer3); + assertArrayEquals(SensorKionixKXRB52042.AlignmentMatrixLowNoiseAccelShimmer3, SensorKionixKXTC92050.AlignmentMatrixLowNoiseAccelShimmer3); + } + + /** + * Shimmer3 A615 (SR49-3-1) lying still, 20 Nov 2026: its raw LN accel at rest. On the defaults + * it must read 1 g; on the old 2253 and 92 it read 11.5 m/s2. + */ + @Test + public void aShimmer3AtRestReadsOneG() { + double[] cal = UtilCalibration.calibrateInertialSensorData(new double[] { 1232, 2011, 2125 }, + SensorKionixKXTC92050.AlignmentMatrixLowNoiseAccelShimmer3, + SensorKionixKXTC92050.SensitivityMatrixLowNoiseAccel2gShimmer3, + SensorKionixKXTC92050.OffsetVectorLowNoiseAccelShimmer3); + double magnitude = Math.sqrt(cal[0] * cal[0] + cal[1] * cal[1] + cal[2] * cal[2]); + assertEquals(9.81, magnitude, 0.15); + } +}