SDKJava (Android) SDK

Calibration

Android Java SDK: Calibration

Current version · 2.0.0

Calibration

Skeleton and retargeting output depend on the capture and calibration required by the algorithm. Select the target before starting the device and runtime. Startup policy drives the automatic workflow; use CalibrationMode.MANUAL and explicit sessions when the app needs separate control.

When a new capture fully reuses the current compatible data without changing it, the SDK preserves matching calibration. Capturing replacement data invalidates calibration derived from the replaced data.

Explicit calibration

First obtain a completed, still-open CaptureSession as described in Capture. The excerpt below is the calibrate method from HostCaptureCalibration.java; the public run calls it for each hand after capture, passing that hand's capture session and the target name.

// Excerpt from examples-public/examples/glove/java/src/main/java/com/qnbot/examples/HostCaptureCalibration.java (calibrate)
import com.qnbot.sdk.SleepResult;
import com.qnbot.sdk.glove.Glove;
import com.qnbot.sdk.glove.GloveDevice;
import com.qnbot.sdk.glove.calibration.CalibrationJobProgress;
import com.qnbot.sdk.glove.calibration.CalibrationJobState;
import com.qnbot.sdk.glove.calibration.CalibrationResult;
import com.qnbot.sdk.glove.calibration.CalibrationSession;
import com.qnbot.sdk.glove.calibration.CalibrationSessionSnapshot;
import com.qnbot.sdk.glove.calibration.CalibrationSessionState;
import com.qnbot.sdk.glove.capture.CaptureSession;
import java.util.List;
import java.util.concurrent.CancellationException;
import java.util.function.BooleanSupplier;

public final class HostCaptureCalibration {
  private HostCaptureCalibration() {}

  private static void calibrate(GloveDevice device, Glove glove, CaptureSession capture,
      String target, BooleanSupplier cancelled) throws InterruptedException {
    try (CalibrationSession calibration = device.startCalibration(capture, List.of(target))) {
      try {
        long deadline = System.nanoTime() + 300_000_000_000L;
        String previous = "";
        while (!cancelled.getAsBoolean()) {
          CalibrationSessionSnapshot snapshot = calibration.snapshot();
          StringBuilder progress = new StringBuilder("calibration=").append(snapshot.state);
          for (CalibrationJobProgress job : snapshot.jobs) {
            progress.append(" target=").append(job.targetId).append(" state=").append(job.state);
            if (job.state == CalibrationJobState.FAILED) {
              throw new IllegalStateException(
                  job.failure == null ? "Calibration failed" : job.failure.message);
            }
          }
          if (!previous.equals(progress.toString())) {
            previous = progress.toString();
            System.out.println(previous);
          }
          if (snapshot.state == CalibrationSessionState.COMPLETED) {
            for (CalibrationResult result : calibration.result().orElseThrow(
                     () -> new IllegalStateException("Completed calibration has no results"))) {
              System.out.println("saved calibration source=" + result.sourceId
                  + " target=" + result.targetId);
            }
            return;
          }
          if (snapshot.state == CalibrationSessionState.FAILED
              || snapshot.state == CalibrationSessionState.CANCELLED) {
            throw new IllegalStateException("Calibration stopped: " + snapshot.state);
          }
          if (System.nanoTime() >= deadline) {
            throw new IllegalStateException("Calibration timed out");
          }
          var update = glove.update();
          if (!update.hasNextTask) {
            Thread.sleep(10);
          } else if (update.sleep() == SleepResult.STOPPED) {
            break;
          }
        }
        if (cancelled.getAsBoolean()) {
          throw new CancellationException("Calibration cancelled by caller");
        }
        throw new IllegalStateException("Calibration stopped");
      } finally {
        if (calibration.snapshot().state == CalibrationSessionState.RUNNING) {
          calibration.cancel();
        }
      }
    }
  }
}

Call the public run on a worker thread; its calibrate() polls snapshot() and reads each job's CalibrationJobState; on COMPLETED it reads and prints results through result(), and on failure it raises the current job error. For a nonblocking UI, post the same snapshot fields to the main thread. Close the capture session only after calibration finishes.

Targets and failures

calibrationStatus() checks the default output; calibrationStatus(outputName) checks a named output. The built-in skeleton uses "skeleton". Subscribe to calibrationProgress(outputName) for progress. Use the configured output names for other calibration targets rather than reusing the built-in name for arbitrary algorithms.

On failure, display the job error and fix the capture pose, input or delivery problem before retrying. Cancel with CalibrationSession.cancel(). Do not wait on the main thread or after stopping the runtime loop. Recapture and recalibrate if the captured pose cannot be confirmed.

Complete calibration-file replay

Set TargetAlgorithm.calibrationKey to a complete .qnbotkey file exported by Python/C++ to reuse the target's algorithm configuration, bone configuration and calibration result. Match the target and hand side. See Configuration reference for constructors.