@@ -23,7 +23,9 @@ export enum CalibrationStatus {
2323}
2424
2525export const IMU_CALIBRATION_TIME = 4 ;
26- const ACCEL_TOLERANCE = 0.2 ; // m/s^2
26+ export const IMU_SETTLE_TIME = 1 ;
27+ const ACCEL_TOLERANCE = 0.5 ; // m/s^2
28+ const ACCEL_HYSTERESIS = 0.1 ; // m/s^2
2729
2830export function CalibrationTutorialPage ( ) {
2931 const { l10n } = useLocalization ( ) ;
@@ -32,16 +34,17 @@ export function CalibrationTutorialPage() {
3234 CalibrationStatus . WAITING
3335 ) ;
3436 const [ skipButton , setSkipButton ] = useState ( false ) ;
37+ const [ settled , setSettled ] = useState ( false ) ;
3538 const { timer, isCounting, startCountdown, abortCountdown } = useCountdown ( {
36- duration : IMU_CALIBRATION_TIME ,
37- onCountdownEnd : ( ) => setCalibrationStatus ( CalibrationStatus . SUCCESS ) ,
39+ duration : settled ? IMU_CALIBRATION_TIME : IMU_SETTLE_TIME ,
40+ onCountdownEnd : ( ) => settled ? setCalibrationStatus ( CalibrationStatus . SUCCESS ) : setSettled ( true ) ,
3841 } ) ;
3942 useTimeout ( ( ) => setSkipButton ( true ) , 10000 ) ;
4043 const connectedIMUTrackers = useAtomValue ( connectedIMUTrackersAtom ) ;
4144 const restCalibrationTrackers =
4245 useRestCalibrationTrackers ( connectedIMUTrackers ) ;
4346 const [ rested , setRested ] = useState ( false ) ;
44- const lastValueMap = useRef ( new Map < number , Vector3 [ ] > ( ) ) ;
47+ const lastValueMap = useRef ( new Map < number , Vector3 > ( ) ) ;
4548 useEffect ( ( ) => {
4649 const accelLength = restCalibrationTrackers . every ( ( x ) => {
4750 if (
@@ -58,17 +61,32 @@ export function CalibrationTutorialPage() {
5861 lastValueMap . current . set ( trackerId , lastValue ) ;
5962
6063 const vec3 = Vector3FromVec3fT ( x . tracker . linearAcceleration ) ;
61- if ( lastValues . length > 5 ) {
62- lastValues . shift ( ) ;
63- const avg = averageVector ( lastValues ) . lengthSq ( ) ;
64- lastValues . push ( vec3 ) ;
65- return vec3 . lengthSq ( ) <= avg + ACCEL_TOLERANCE ** 2 ;
64+
65+ if ( vec3 . lengthSq ( ) > ACCEL_TOLERANCE ** 2 ) {
66+ return false ;
67+ }
68+
69+ const delta = new Vector3 ( ) ;
70+ delta . subVectors ( lastValue , vec3 ) ;
71+
72+ if ( delta . lengthSq ( ) > ACCEL_HYSTERESIS ** 2 ) {
73+ lastValue . copy ( vec3 ) ;
74+ return false ;
6675 }
67- lastValues . push ( vec3 ) ;
68- return false ;
76+
77+ return true ;
6978 } ) ;
7079
71- setRested ( accelLength || restCalibrationTrackers . length === 0 ) ;
80+ if ( accelLength && ! settled && ! isCounting ) {
81+ abortCountdown ( ) ;
82+ startCountdown ( ) ;
83+ } else if ( ! accelLength && ! settled && isCounting ) {
84+ abortCountdown ( ) ;
85+ } else if ( ! accelLength && settled ) {
86+ setSettled ( false ) ;
87+ }
88+
89+ setRested ( settled || restCalibrationTrackers . length === 0 ) ;
7290 } , [ restCalibrationTrackers ] ) ;
7391
7492 useEffect ( ( ) => {
@@ -148,7 +166,7 @@ export function CalibrationTutorialPage() {
148166 </ div >
149167 < ProgressBar
150168 progress = {
151- isCounting
169+ isCounting && settled
152170 ? ( IMU_CALIBRATION_TIME - timer ) / IMU_CALIBRATION_TIME
153171 : calibrationStatus === CalibrationStatus . SUCCESS ||
154172 calibrationStatus === CalibrationStatus . ERROR
0 commit comments