SDKJava (Android) SDK

Reading retargeting data

Android Java SDK: Reading retargeting data

Current version · 2.0.0

Reading retargeting data

Use algorithms delivered for this Android SDK and complete their required capture and calibration. Calling skeleton APIs does not produce skeleton output when the delivery lacks the built-in algorithm.

Install an Android algorithm ZIP

Download the android-arm64 ZIP with the desktop QnBot CLI; see Android targets in Algorithm packages. Before creating the SDK, install the original ZIP on a worker thread. Pass a readable file path or a document-picker URI with a read grant. Keep dependencies supplied inside the ZIP with the package.

The excerpt below is the importAlgorithmArchive method from AlgorithmConfiguration.java; the full preparation flow also includes exportBoneConfig and prepareBoneConfig, shown in Hand model parameter configuration.

// Excerpt from examples-public/examples/glove/java/src/main/java/com/qnbot/examples/AlgorithmConfiguration.java (importAlgorithmArchive)
import android.content.Context;
import android.net.Uri;
import com.qnbot.sdk.algorithm.AlgorithmPackageManager;
import com.qnbot.sdk.algorithm.InstallBatchResult;
import java.io.IOException;

public final class AlgorithmConfiguration {
  private AlgorithmConfiguration() {}

  public static InstallBatchResult importAlgorithmArchive(Context context, Uri selectedZip)
      throws IOException {
    return new AlgorithmPackageManager(context, "glove").installFromArchive(selectedZip);
  }
}

Use the installed package ID in new TargetAlgorithm(packageId). The built-in Skeleton does not use this install step.

Built-in skeleton

Call device.skeleton() before start to select the built-in skeleton and subscribe to jointAngles() or pose(), then start the runtime loop. See Hand skeleton visualization for the complete example; this page does not repeat it.

Skeleton.pose() returns HandSkeletonPose; jointAngles() returns HandJointCommand. HandSkeletonPose provides names, positionsLocal, orientationsLocalXyzw, coordinateFrame, handSide and timestampMs. Match each joint name to position and orientation at the same index. Quaternion order is xyzw. Positions are wrist-local; the app must apply its hand-root transform for world rendering.

Read target output

ForegroundRuntime.run(...) declares an openxr_hand target, subscribes to device.output("openxr_hand") before start, then streams target output on the calling thread with runForever(). It takes the port, side and algorithm package; call it on a worker thread.

import android.content.Context;
import com.qnbot.sdk.Sdk;
import com.qnbot.sdk.SdkConfig;
import com.qnbot.sdk.android.SerialTransport;
import com.qnbot.sdk.config.DeviceSelector;
import com.qnbot.sdk.config.SerialConnection;
import com.qnbot.sdk.config.Side;
import com.qnbot.sdk.config.TargetAlgorithm;
import com.qnbot.sdk.config.TargetConfig;
import com.qnbot.sdk.glove.Glove;
import com.qnbot.sdk.glove.GloveConfig;
import com.qnbot.sdk.glove.GloveDevice;

/**
 * Streams one retargeted hand output on the caller's thread.
 *
 * <p>Pass the host {@link Context}, an authorized transport, the glove port and side, and the
 * installed algorithm package. Run on a worker thread; the target subscription prints each
 * command.
 */
public final class ForegroundRuntime {
  private ForegroundRuntime() {}

  public static void run(Context context, SerialTransport transport, String port, Side side,
      String packageId) {
    SdkConfig config = SdkConfig.builder()
        .device(GloveConfig.builder()
                    .name("primary")
                    .side(side)
                    .connection(SerialConnection.port(port))
                    .build())
        .target(TargetConfig.builder()
                    .name("openxr_hand")
                    .side(side)
                    .source(new DeviceSelector("glove", "primary", side))
                    .algorithm(new TargetAlgorithm(packageId))
                    .build())
        .build();
    try (Sdk sdk = new Sdk(config, context, transport); Glove glove = sdk.glove()) {
      GloveDevice device = glove.device();
      device.output("openxr_hand")
          .subscribe(sample
              -> System.out.println("retargeting sequence=" + sample.sequence
                  + " target=" + sample.value.target + " joints=" + sample.value.joints));
      glove.start();
      glove.runForever();
    }
  }
}

Declare algorithm targets through SdkConfig.builder().target(...). TargetConfig.source selects the device, name identifies the output, and algorithm selects delivered algorithms. Read HandJointCommand through device.output(outputName); output() selects the default. The command includes target, joints, timestamp, source and metadata.

For multiple outputs, pass their actual configured names and check calibration/output state separately. See MultipleOutputs in Data channels & read methods for a complete two-output example. Manage algorithms through the product CLI and delivery guide rather than desktop installation paths inside the app.

Hand model parameters are configured through TargetAlgorithm; see Hand model parameter configuration for the bone configuration mode and algorithm configuration file.