performSROM method

Future<SromResult> performSROM()

Performs the SROM test by starting the probe, tracking angles in real-time, waiting for the test duration, stopping the probe, processing the data, and returning the result.

Implementation

Future<SromResult> performSROM() async {
  try {
    // Start probe
    await probe.start();
    startGyroTracking();

    if (kDebugMode) {
      print('[SromTestStep] Execute starting...');
    }

    // Wait for test duration
    await Future.delayed(measure.duration);

    // Stop probe
    await probe.stop();
    _liveAngleTracker.reset();

    // Process data
    final results = await processor.processData(
      accData: probe.accelerometerData,
      gyroData: probe.gyroscopeData,
      magData: probe.magnetometerData,
      accActualRate: probe.currentAccSamplingRate().toDouble(),
      gyroActualRate: probe.currentGyroSamplingRate().toDouble(),
      magActualRate: probe.currentMagSamplingRate().toDouble(),
    );

    // Create SromResult
    if (results.isNotEmpty) {
      final sromResult = results.first;
      if (kDebugMode) {
        print(
          '[SromTestStep] SromResult rangeOfMotionAngle: ${sromResult.rangeOfMotionAngle}, detectedArm:${sromResult.detectedArm.toString()}',
        );
      }
      return SromResult(
        identifier: identifier,
        rangeOfMotionAngle: sromResult.rangeOfMotionAngle,
        detectedArm: sromResult.detectedArm,
      );
    } else {
      return SromResult(
        identifier: identifier,
        rangeOfMotionAngle: 0.0,
        detectedArm: Arm.unknown,
      );
    }
  } catch (e) {
    if (kDebugMode) {
      print('Error in SromTestStep.execute: $e');
    }
    testEndReset();
    return SromResult(
      identifier: identifier,
      rangeOfMotionAngle: 0.0,
      detectedArm: Arm.unknown,
    )..results['error'] = e.toString();
  }
}