Glove + Exo composite solution
Android Java SDK: Glove + Exo composite solution
Glove + Exo composite solution
Use the Maven directory from the complete Glove offline archive as the QnBot Maven repository, then use the Gradle dependencies below.
Install both components from the matching offline delivery. Pass the authorized shared serial port once in the outer configuration. Create one Sdk with this configuration, call sdk.start() to start all three members, then select data channels through sdk.glove() and sdk.exo().
Configuration approach
CompositeExoGloveConfig.builder().name(...) sets the composite outer name, independent of member names. The outer connection is the shared serial port; devices contains two gloves and one Exo. Members still use ordinary GloveConfig and ExoConfig.
Complete example
QuickStart.run(context, transport) auto-discovers the only composite device, starts the root Sdk and keeps reading both glove poses. The root Sdk owns the shared serial link and the lifecycle of all three members.
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.CompositeExoGloveConfig;
import com.qnbot.sdk.config.Side;
import com.qnbot.sdk.exo.ExoConfig;
import com.qnbot.sdk.glove.Glove;
import com.qnbot.sdk.glove.GloveConfig;
import com.qnbot.sdk.glove.GloveDevice;
import com.qnbot.sdk.glove.GloveFinger;
/**
* Connects one composite Exo+Glove device and prints the pose of both gloves.
*
* <p>Supply an Android {@link Context} and an authorized {@link SerialTransport}; the SDK
* auto-discovers the shared endpoint. One root Sdk owns the whole composite link.
*/
public final class QuickStart {
private QuickStart() {}
public static void run(Context context, SerialTransport transport) {
SdkConfig config = SdkConfig.builder()
.device(CompositeExoGloveConfig.builder()
.devices(GloveConfig.builder().side(Side.LEFT).build(),
GloveConfig.builder().side(Side.RIGHT).build(),
ExoConfig.builder().build())
.build())
.build();
try (Sdk sdk = new Sdk(config, context, transport)) {
Glove glove = sdk.glove();
GloveDevice left = glove.device(Side.LEFT);
GloveDevice right = glove.device(Side.RIGHT);
// Subscribe before start so the first samples of both gloves are observed.
left.pose().subscribe(sample -> System.out.println("left sequence=" + sample.sequence
+ " thumb=" + sample.value.payload.fingertipLocal.get(GloveFinger.THUMB).position
+ " index=" + sample.value.payload.fingertipLocal.get(GloveFinger.INDEX).position));
right.pose().subscribe(sample -> System.out.println("right sequence=" + sample.sequence
+ " thumb=" + sample.value.payload.fingertipLocal.get(GloveFinger.THUMB).position
+ " index=" + sample.value.payload.fingertipLocal.get(GloveFinger.INDEX).position));
// The root Sdk starts both glove members and the Exo over their shared serial link.
sdk.start();
sdk.runForever();
}
}
}Discovery
DiscoverExoGlove.run(...) prints the host transport inventory before creating the SDK, then reads both glove sources and the Exo device information. Pass the shared port, or null to discover the only authorized port.
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.CompositeExoGloveConfig;
import com.qnbot.sdk.config.SerialConnection;
import com.qnbot.sdk.config.Side;
import com.qnbot.sdk.exo.Exo;
import com.qnbot.sdk.exo.ExoConfig;
import com.qnbot.sdk.exo.ExoDeviceInfo;
import com.qnbot.sdk.glove.Glove;
import com.qnbot.sdk.glove.GloveConfig;
/**
* Discovers a composite Exo+Glove device and prints the two glove sources and the Exo identity.
* Callers supply the authorized transport; pass a shared port, or null to discover the only
* authorized one. The transport inventory is listed before the Sdk is created.
*/
public final class DiscoverExoGlove {
private DiscoverExoGlove() {}
public static void run(Context context, SerialTransport transport, String port) throws Exception {
// Android needs the authorized endpoint list before the SDK takes ownership of the transport.
System.out.println("USB candidates=" + transport.inventory());
SerialConnection connection = port == null
? SerialConnection.autoDiscover()
: SerialConnection.port(port);
SdkConfig config = SdkConfig.builder()
.device(CompositeExoGloveConfig.builder()
.connection(connection)
.devices(GloveConfig.builder().side(Side.LEFT).build(),
GloveConfig.builder().side(Side.RIGHT).build(), ExoConfig.builder().build())
.build())
.build();
try (Sdk sdk = new Sdk(config, context, transport)) {
// One root Sdk exposes both member domains for the shared link.
Glove glove = sdk.glove();
Exo exo = sdk.exo();
System.out.println("left source=" + glove.device(Side.LEFT).sourceId());
System.out.println("right source=" + glove.device(Side.RIGHT).sourceId());
ExoDeviceInfo info = exo.device().getDeviceInfo();
System.out.println("Exo product=" + info.product + " serial=" + info.serialNumber
+ " hardware=" + info.hardwareName);
}
}
}A composite device has one root Sdk; obtain member domains through sdk.glove() and sdk.exo(), then select gloves by Side or read the single Exo. The Exo getDeviceInfo() returns ExoDeviceInfo.
Two-hand target output
GloveRetargeting.run(...) declares one target per hand and subscribes to device.output("left-hand") and device.output("right-hand"); the root Sdk drives both targets.
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.CompositeExoGloveConfig;
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.exo.ExoConfig;
import com.qnbot.sdk.glove.Glove;
import com.qnbot.sdk.glove.GloveConfig;
import com.qnbot.sdk.glove.GloveDevice;
/**
* Subscribes to both retargeted hand outputs of one composite Exo+Glove device.
*
* <p>Callers supply an authorized transport, the shared port and a target-hand algorithm package
* prepared for this app. The root Sdk drives both targets.
*/
public final class GloveRetargeting {
private GloveRetargeting() {}
public static void run(Context context, SerialTransport transport, String port,
String packageId) {
SdkConfig config = SdkConfig.builder()
.device(CompositeExoGloveConfig.builder()
.connection(SerialConnection.port(port))
.devices(GloveConfig.builder().side(Side.LEFT).build(),
GloveConfig.builder().side(Side.RIGHT).build(),
ExoConfig.builder().build())
.build())
.target(TargetConfig.builder()
.name("left-hand")
.side(Side.LEFT)
.source(new DeviceSelector("glove", null, Side.LEFT))
.algorithm(new TargetAlgorithm(packageId))
.build())
.target(TargetConfig.builder()
.name("right-hand")
.side(Side.RIGHT)
.source(new DeviceSelector("glove", null, Side.RIGHT))
.algorithm(new TargetAlgorithm(packageId))
.build())
.build();
try (Sdk sdk = new Sdk(config, context, transport)) {
Glove glove = sdk.glove();
GloveDevice left = glove.device(Side.LEFT);
GloveDevice right = glove.device(Side.RIGHT);
// Subscribe both target outputs before start; the SDK keeps its default Capture interaction.
left.output("left-hand").subscribe(sample
-> System.out.println("left retargeting sequence=" + sample.sequence
+ " target=" + sample.value.target + " joints=" + sample.value.joints));
right.output("right-hand").subscribe(sample
-> System.out.println("right retargeting sequence=" + sample.sequence
+ " target=" + sample.value.target + " joints=" + sample.value.joints));
sdk.start();
sdk.runForever();
}
}
}Haptics requests
GloveHaptics.run(...) submits the same haptics request to both hands, holds it for the requested seconds, then clears it. Composite devices accept but currently ignore glove haptics, so no physical output occurs; the example shows the request path and cleanup.
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.CompositeExoGloveConfig;
import com.qnbot.sdk.config.SerialConnection;
import com.qnbot.sdk.config.Side;
import com.qnbot.sdk.exo.ExoConfig;
import com.qnbot.sdk.glove.Glove;
import com.qnbot.sdk.glove.GloveConfig;
import com.qnbot.sdk.glove.GloveDevice;
import com.qnbot.sdk.glove.GloveFinger;
import com.qnbot.sdk.glove.Haptics;
/**
* Submits haptics requests to both gloves of a composite Exo+Glove device and holds them for the
* caller's duration. Composite devices accept but ignore glove haptics, so this example shows the
* request path only. Callers supply the authorized transport, the shared port and hold seconds.
*/
public final class GloveHaptics {
private GloveHaptics() {}
public static void run(Context context, SerialTransport transport, String port,
double holdSeconds) throws InterruptedException {
if (!Double.isFinite(holdSeconds) || holdSeconds < 0)
throw new IllegalArgumentException("holdSeconds must be finite and nonnegative");
SdkConfig config = SdkConfig.builder()
.device(CompositeExoGloveConfig.builder()
.connection(SerialConnection.port(port))
.devices(GloveConfig.builder().side(Side.LEFT).build(),
GloveConfig.builder().side(Side.RIGHT).build(), ExoConfig.builder().build())
.build())
.build();
try (Sdk sdk = new Sdk(config, context, transport)) {
// One root Sdk owns the shared link; the glove domain selects both hands.
Glove glove = sdk.glove();
GloveDevice left = glove.device(Side.LEFT);
GloveDevice right = glove.device(Side.RIGHT);
sdk.start();
Haptics request =
Haptics.builder().set(GloveFinger.THUMB, 80).set(GloveFinger.INDEX, 40).build();
try {
left.haptics().set(request);
right.haptics().set(request);
System.out.println("Composite Glove haptics requests are ignored; no physical output");
Thread.sleep((long) (holdSeconds * 1000));
} finally {
left.haptics().clear();
right.haptics().clear();
}
}
}
}Device information
DeviceInfo.run(...) reads both glove sources plus the Exo product, serial number, firmware, protocol version and capabilities.
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.CompositeExoGloveConfig;
import com.qnbot.sdk.config.SerialConnection;
import com.qnbot.sdk.config.Side;
import com.qnbot.sdk.exo.Exo;
import com.qnbot.sdk.exo.ExoConfig;
import com.qnbot.sdk.exo.ExoDevice;
import com.qnbot.sdk.exo.ExoDeviceInfo;
import com.qnbot.sdk.glove.Glove;
import com.qnbot.sdk.glove.GloveConfig;
import com.qnbot.sdk.glove.GloveDevice;
/**
* Shows the members of one composite Exo+Glove device: the two glove source IDs plus the Exo
* product, firmware, protocol and capability details. Callers supply an authorized transport and
* the shared port; the single Sdk is closed after the read.
*/
public final class DeviceInfo {
private DeviceInfo() {}
public static void run(Context context, SerialTransport transport, String port) {
SdkConfig config = SdkConfig.builder()
.device(CompositeExoGloveConfig.builder()
.connection(SerialConnection.port(port))
.devices(GloveConfig.builder().side(Side.LEFT).build(),
GloveConfig.builder().side(Side.RIGHT).build(), ExoConfig.builder().build())
.build())
.build();
try (Sdk sdk = new Sdk(config, context, transport)) {
// One root Sdk exposes both member domains for the shared link.
Glove glove = sdk.glove();
Exo exo = sdk.exo();
GloveDevice left = glove.device(Side.LEFT);
GloveDevice right = glove.device(Side.RIGHT);
ExoDevice exoDevice = exo.device();
System.out.println("left source=" + left.sourceId());
System.out.println("right source=" + right.sourceId());
ExoDeviceInfo info = exoDevice.getDeviceInfo();
System.out.println("product=" + info.product + " serial=" + info.serialNumber + " firmware="
+ info.firmware.platform + "." + info.firmware.revision + "." + info.firmware.feature
+ "." + info.firmware.build + " protocol=" + info.protocolVersion.major + "."
+ info.protocolVersion.minor + " encoders=" + info.components.encoders.available + "/"
+ info.components.encoders.totalSlots + " handsets=" + info.capabilities.handsets
+ " imus=" + info.capabilities.imus + " haptics=" + info.capabilities.haptics
+ " wireless=" + info.capabilities.wireless);
}
}
}Exo IMU
Imu.run(...) reads only the Exo IMUs supported by the shared link; composite devices do not expose raw glove IMU. When the device has no IMU capability, the example prints a notice and returns.
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.CompositeExoGloveConfig;
import com.qnbot.sdk.config.SerialConnection;
import com.qnbot.sdk.config.Side;
import com.qnbot.sdk.exo.Exo;
import com.qnbot.sdk.exo.ExoConfig;
import com.qnbot.sdk.exo.ExoDevice;
import com.qnbot.sdk.exo.ExoImuState;
import com.qnbot.sdk.glove.GloveConfig;
/**
* Reads the Exo IMUs reported by a composite Exo+Glove device. The shared link does not expose raw
* glove IMU, so this example checks the Exo capability and subscribes to Exo telemetry only.
*/
public final class Imu {
private Imu() {}
public static void run(Context context, SerialTransport transport, String port) {
SdkConfig config = SdkConfig.builder()
.device(CompositeExoGloveConfig.builder()
.connection(SerialConnection.port(port))
.devices(GloveConfig.builder().side(Side.LEFT).build(),
GloveConfig.builder().side(Side.RIGHT).build(),
ExoConfig.builder().build())
.build())
.build();
try (Sdk sdk = new Sdk(config, context, transport)) {
Exo exo = sdk.exo();
ExoDevice exoDevice = exo.device();
if (!exoDevice.getDeviceInfo().capabilities.imus) {
System.out.println("Exo has no IMU capability; composite Glove raw IMU is unavailable");
return;
}
exoDevice.telemetry().subscribe(sample -> {
for (ExoImuState imu :
new ExoImuState[] {sample.value.payload.torsoImu, sample.value.payload.extraImu}) {
if (imu != null)
System.out.println("IMU sequence=" + sample.sequence + " acceleration="
+ imu.accelerationMps2 + " angularVelocity=" + imu.angularVelocityRadS
+ " quaternion=" + imu.orientationXyzw);
}
});
sdk.start();
sdk.runForever();
}
}
}Telemetry and status
Telemetry.run(...) subscribes to both glove poses, both glove status streams and the Exo telemetry and status, showing the complete data plane of all three members under one root Sdk.
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.CompositeExoGloveConfig;
import com.qnbot.sdk.config.SerialConnection;
import com.qnbot.sdk.config.Side;
import com.qnbot.sdk.exo.Exo;
import com.qnbot.sdk.exo.ExoConfig;
import com.qnbot.sdk.exo.ExoDevice;
import com.qnbot.sdk.glove.Glove;
import com.qnbot.sdk.glove.GloveConfig;
import com.qnbot.sdk.glove.GloveDevice;
import com.qnbot.sdk.glove.GloveFinger;
/**
* Reads combined telemetry from one composite Exo+Glove link: both glove poses, both glove status
* streams, Exo telemetry and Exo status.
*
* <p>Callers supply the authorized transport and the shared port. The root Sdk drives all three
* members.
*/
public final class Telemetry {
private Telemetry() {}
public static void run(Context context, SerialTransport transport, String port) {
SdkConfig config = SdkConfig.builder()
.device(CompositeExoGloveConfig.builder()
.connection(SerialConnection.port(port))
.devices(GloveConfig.builder().side(Side.LEFT).build(),
GloveConfig.builder().side(Side.RIGHT).build(),
ExoConfig.builder().build())
.build())
.build();
try (Sdk sdk = new Sdk(config, context, transport)) {
// One root Sdk exposes both member domains for the same composite link.
Glove glove = sdk.glove();
Exo exo = sdk.exo();
GloveDevice left = glove.device(Side.LEFT);
GloveDevice right = glove.device(Side.RIGHT);
ExoDevice exoDevice = exo.device();
left.pose().subscribe(sample
-> System.out.println("left sequence=" + sample.sequence
+ " thumb=" + sample.value.payload.fingertipLocal.get(GloveFinger.THUMB).position
+ " index=" + sample.value.payload.fingertipLocal.get(GloveFinger.INDEX).position));
right.pose().subscribe(sample
-> System.out.println("right sequence=" + sample.sequence
+ " thumb=" + sample.value.payload.fingertipLocal.get(GloveFinger.THUMB).position
+ " index=" + sample.value.payload.fingertipLocal.get(GloveFinger.INDEX).position));
exoDevice.telemetry().subscribe(sample
-> System.out.println("telemetry sequence=" + sample.sequence
+ " leftEncoders=" + sample.value.payload.leftArm.encoderCounts
+ " rightEncoders=" + sample.value.payload.rightArm.encoderCounts
+ " leftRadians=" + sample.value.payload.leftArm.jointPositionsRad
+ " rightRadians=" + sample.value.payload.rightArm.jointPositionsRad));
left.status().subscribe(sample
-> System.out.println(
"left connected=" + sample.value.connected + " stale=" + sample.value.stale));
right.status().subscribe(sample
-> System.out.println(
"right connected=" + sample.value.connected + " stale=" + sample.value.stale));
exoDevice.status().subscribe(sample
-> System.out.println(
"exo connected=" + sample.value.connected + " stale=" + sample.value.stale));
// Start after subscribing, then let the root runner drive every scheduled task.
sdk.start();
sdk.runForever();
}
}
}Lifecycle
Lifecycle.run(...) starts the root Sdk, advances one update, reads the latest samples, then stops and closes. It is the shortest check of composite startup and cleanup ordering.
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.CompositeExoGloveConfig;
import com.qnbot.sdk.config.SerialConnection;
import com.qnbot.sdk.config.Side;
import com.qnbot.sdk.exo.Exo;
import com.qnbot.sdk.exo.ExoConfig;
import com.qnbot.sdk.exo.ExoDevice;
import com.qnbot.sdk.glove.Glove;
import com.qnbot.sdk.glove.GloveConfig;
import com.qnbot.sdk.glove.GloveDevice;
/**
* Runs one bounded composite lifecycle: start the root Sdk, advance one update, print the member
* sources and the latest glove pose and Exo telemetry samples, then stop and close. Callers supply
* an authorized transport and the shared port; the method returns after cleanup.
*/
public final class Lifecycle {
private Lifecycle() {}
public static void run(Context context, SerialTransport transport, String port) {
SdkConfig config = SdkConfig.builder()
.device(CompositeExoGloveConfig.builder()
.connection(SerialConnection.port(port))
.devices(GloveConfig.builder().side(Side.LEFT).build(),
GloveConfig.builder().side(Side.RIGHT).build(), ExoConfig.builder().build())
.build())
.build();
try (Sdk sdk = new Sdk(config, context, transport)) {
// One root Sdk owns the shared link and both member domains.
Glove glove = sdk.glove();
Exo exo = sdk.exo();
GloveDevice left = glove.device(Side.LEFT);
GloveDevice right = glove.device(Side.RIGHT);
ExoDevice exoDevice = exo.device();
sdk.start();
sdk.update();
System.out.println("started Left Glove=" + left.sourceId()
+ " Right Glove=" + right.sourceId() + " Exo=" + exoDevice.sourceId());
left.pose().latest().ifPresent(
sample -> System.out.println("left sequence=" + sample.sequence));
right.pose().latest().ifPresent(
sample -> System.out.println("right sequence=" + sample.sequence));
exoDevice.telemetry().latest().ifPresent(
sample -> System.out.println("Exo sequence=" + sample.sequence));
sdk.stop();
System.out.println("stopped");
}
System.out.println("closed");
}
}