The main purpose of this repo is to host the abcvlib development. This is the library governing the OIST Smartphone Robot Android Framework. The framework is designed to provide a simple and easy to use interface for developing Android applications for the OIST Smartphone Robot.
This repo itself is an Android project, so opening the root of the repo in Android Studio will provide all build tools necessary to build the library and the example applications located in the apps directory.
Although abcvlib can be used as an external dependency (see Using abcvlib as an external dependency), it is likely easier to get to know the API by looking at the example applications. The example applications are located in the apps directory and are designed to be simple examples of how to use core features of the library.
The following is a list of tools needed to build either abcvlib or any of the demo applications.
- Java opensdk v17 or higher, with environmental variable JAVA_HOME set to the root of this sdk e.g.
/usr/lib/jvm/java-1.17.0-openjdk-amd64
(a requirement by modern Android gradle plugin versions) - BOTH git and GitHub command line interface (used to download packages and other larger assets from GitHub Packages)
- Local environment variables GITHUB_USER and GITHUB_TOKEN (see Managing your personal access tokens for more information on how to create a token. The token must have full "repo" permissions.
- Android SDK Tools (If you prefer the command line, you can use the Android Command Line Tools and avoid using Android Studio)
- (Optional) Android Studio
- (Optional) Docker can be used to provide all the above tools in a single ready-made image. See the Docker README for more information.
Start by cloning the repository
From here you have two choices. You can either use Android Studio or the command line to build the project.
- Open the root of the repository in Android Studio
- Build the project by clicking the hammer icon in the toolbar
- Choose one of the build targets (backAndForth, basicSubscriber, basicAssembler) from the dropdown menu in the toolbar
- Ensure you have a smartphone connected to your computer via adb, see Pairing with a smartphone via wireless debugging for more information
- Click the green play button in the toolbar to install the APK on your device
There is an automated script to perform most of what is listed below, but it has only been tested on Ubuntu 22.04. This script lies here Manually, this does the following:
- Download and unzip the Android Command Line Tools from the Android Developer website
- Unzip this to a location of your choice (e.g. ~/android_sdk)
- Follow the silly manual directory restructuring steps here
- Install platform-tools, build-tools, and Android platform (
./sdkmanager "platform-tools" "platforms;android-30" "build-tools;33.0.1"
) - Accept all licenses (
y | ./sdkmanager --licenses
) - Set ANDROID_HOME env variable (
export ANDROID_HOME=~/android_sdk
) - Add platform-tools to your PATH (
export PATH=$PATH:$ANDROID_HOME/platform-tools
)
From here you can start building the project. There is also a terminal application to automate the below steps, and this is found at ./bi (build and install).
- Navigate to the root of the repository
- Run
./gradlew assembleDebug
to build the project (it will take a few minutes the first time as it downloads all the necessary dependencies) - You can build individual APKs by running
./gradlew <app_name>:assembleDebug
where<app_name>
is one of the following:backAndForth
,basicSubscriber
,basicAssembler
- You may need to uninstall the previous version of the APK before installing the new one. You can do this by running
adb uninstall jp.oist.abcvlib.backandforth
wherejp.oist.abcvlib.backandforth
is the package name of the APK you want to uninstall - Install the APK on your device by running
adb install -r <path_to_apk>
where<path_to_apk>
is the path to the APK you just built e.g../apps/backAndForth/build/outputs/apk/debug/backAndForth-debug.apk
- Run the APK on your device via
adb shell am start -n jp.oist.abcvlib.backandforth/.MainActivity
- Camera a. Raw Images b. Hybrid Sensors (QR Code Boolean, coords of target, etc.)
- Microphone a. Raw audio samples
- Spatial sensors a. Accelerometer b. Gyroscope c. GPS d. Hybrid Sensors combining these
- Wheels a. Raw encoder counts b. Hybrid Sensors (Relative position, speed, acceleration)
- Power a. Internal battery voltage b. Charger voltage c. Wireless coil voltage
- Low Level Controller
a. Direct control of motors via
outputs.setWheelOutput(float left, float right, boolean leftBrake, boolean rightBrake)
- Mid-level controllers b. e.g. See basicAssembler's ActionSpace c. Balance, Turn Left/Right, Move Forward/Backward 10mm
All state variables are published by the robot and can be subscribed to either directly within your MainActivity class (See apps/basicSubscriber) or via a TimeStepDataBuffer (See apps/basicAssembler) for examples of each. The following diagram shows the architecture of this system.
Three demo applications exemplify the basic use of the API:
- backAndForth a. Intentionally VERY bare-bones as a Hello World app for communicating between Android & Robot b. No feedback, just output via outputs.setWheelOutput
- basicSubscriber a. Adding a minimal subscribe+read operation to all possible publishers. b. onCreate-->usbInitialize-->onSerialReady-->initializeOutputs-->onOutputsReady-->abcvlibMainLoop starts. c. Careful! There are several chronological dependencies in the initialization, so changing the order of any of these should be done with caution. d. Note: every onXXX method is called from a separate thread, so synchronization on shared variables can be messy
- basicAssembler a. Assembles all subscribed data into TimeStepData objects (holder for all sampled state info within a single timestep) b. Takes the burden of synchronizing all the threads away. (See TimeStepDataBuffer) i. Synchronized get/set methods ii. Circular buffer for writing data, with read data separately c. Adds a high-level RL framework (StateSpace, ActionSpace, etc.)
- Ensure your smartphone is connected to the same network as your computer
- Enable wireless debugging on your smartphone by following the instructions here
- Run
adb pair <ip_address>:<port>
where<ip_address>
is the IP address of your smartphone and<port>
is the port number displayed on your smartphone - Run
adb connect <ip_address>:<port>
to connect to your smartphone
APK builds and abcvlib .aar files are stored in Github Releases.
-
Download any versioned release in the releases page
-
Install the APK on your device by running
adb install -r <path_to_apk>
. You may also find the following adb flags helpful:- -r: replace existing application
- -t: allow test packages
- -d: allow version code downgrade (debuggable packages only)
- -g: grant all runtime permissions
-
Run the APK on your device via
adb shell am start -n jp.oist.abcvlib.<AppName>/.MainActivity
where<AppName>
is the name of the APK you just installed (e.g.backandforth
) -
Alternatively to step 3, you can open the app from the app drawer on your device
Currently the package is hosted on GitHub Packages. To use it as a dependency in your project, add the following to your build.gradle file:
repositories {
maven {
url = uri("https://maven.pkg.github.com/topherbuckley/smartphone-robot-android")
credentials {
username = project.findProperty("gpr.user") ?: System.getenv("GITHUB_USER")
password = project.findProperty("gpr.key") ?: System.getenv("GITHUB_TOKEN")
}
}
}
dependencies {
implementation 'jp.oist:abcvlib:v1.1.3'
}
See more information on how to use GitHub Packages here.