Quick start
Android Java SDK: Quick start
Current version · 1.4.0
Quick start
Finish installation and USB permission. The public QuickStart example uses automatic discovery, so pass the app Context and an authorized transport, and run 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.exo.Exo;
import com.qnbot.sdk.exo.ExoConfig;
import com.qnbot.sdk.exo.ExoDevice;
/**
* Streams the automatically discovered Exo's telemetry.
*
* <p>Supply an Android {@link Context} and an authorized {@link SerialTransport}. Subscribe before
* start so the channel is ready when the first sample arrives; the subscription prints each
* sequence.
*/
public final class QuickStart {
private QuickStart() {}
public static void run(Context context, SerialTransport transport) {
SdkConfig config = SdkConfig.builder().device(ExoConfig.builder().build()).build();
try (Sdk sdk = new Sdk(config, context, transport); Exo exo = sdk.exo()) {
ExoDevice device = exo.device();
device.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));
exo.start();
exo.runForever();
}
}
}QuickStart.run(context, transport) takes no port: it discovers the only connected Exo, subscribes before start so the first sample is not missed, and prints each telemetry sequence= with left/right encoder counts and joint radians. runForever() blocks the calling worker and does not return on its own; to stop, close the Sdk from another worker or end the process. Do not call it on the UI thread. See Examples for explicit ports, discovery, device information and other workflows.