This repo includes common algorithms, such as gait phase detection and yaw correction, that SageMotion apps use. As we develop more apps and share more algorithms between them, we will add those here as well.
GaitPhase1.py: Four-state gait phase estimator (early/mid/late stance and swing). Tracks gyro magnitude to detect heel strike and toe off, adapts stance timing per step, and increments a step counter when switching from swing to stance.GaitPhase2.py: Simplified two-state gait detector (stance vs swing). Uses gyro magnitude thresholds and a stance duration estimate to transition; updates last stance time to stay responsive to slower/faster cadence.Rotation.py: Thin wrapper aroundscipy.spatial.transform.Rotationthat preserves quaternion component order (scalar-first or vector-first) acrossfrom_quat/as_quat. Falls back to a compatibility class on older SciPy versions and offers aRotationScalarFirsthelper that defaults to scalar-first quaternions.YawCorrection.py: Computes per-sensor yaw corrections relative to a base IMU. Aligns all sensor quaternions so the base yaw becomes zero while applying optional starting offsets to other sensors, returning corrected quaternions for each sample.