Sensors for ROS is an app that publishes sensor data from an Android device onto ROS 2 topics. Currently it supports ROS Humble.
Supported sensors
- Accelerometer
- Barometer
- Camera(s)
- Gyroscope
- Illuminance
- Magnetometer
This app is built using only CMake and C++.
It does not use Java or Kotlin.
ROS 2 packages up to rclcpp
are cross-compiled.
A successful build produces an .apk
file called sensors_for_ros.apk
in the build directory.
These projects were extremely helpful, and used as a reference for this one:
- https://github.com/cnlohr/rawdrawandroid
- https://github.com/ocornut/imgui/tree/master/examples/example_android_opengl3
- https://www.sisik.eu/blog/android/ndk/camera
Currently the only way to get Sensors for ROS is to build it from source. It is not yet available on Google's app store.
You do not need ROS installed on your machine to build the Sensors for ROS app. However, it's needed to use the sensor data being published by your Android device. Follow these instructions to install ROS Humble.
Download the Android SDK "Command-line tools only" version. Other versions may work, but this is the minimum needed.
Make a folder for the SDK and extract the archive.
mkdir ~/android-sdk
cd ~/android-sdk
unzip ~/Downloads/commandlinetools-linux-8512546_latest.zip
Install some Android SDK components
(If it gives linkage error try installing sudo apt install openjdk-17-jre-headless
)
./cmdline-tools/bin/sdkmanager --sdk_root=$HOME/android-sdk "build-tools;33.0.0" "platforms;android-30" "ndk;25.1.8937393"
Install adb
# If you're using Ubuntu
sudo apt install adb android-sdk-platform-tools-common
# If you're using Fedora
sudo dnf install android-tools
Install catkin-pkg, empy, and lark
# If you're using ubuntu
sudo apt install python3-catkin-pkg-modules python3-empy python3-lark-parser
# If you're using Fedora
sudo dnf install python3-catkin_pkg python3-empy python3-lark-parser
You may need to do additional setup to use adb. Follow the Set up a device for development instructions if you're using Ubuntu, or follow the instructions in this thread if you're using Fedora.
You'll need to install openjdk to get access to keytool
.
sudo apt install openjdk-11-jre-headless
Create a debug keystore
mkdir ~/.android
keytool -genkey -v -keystore ~/.android/debug.keystore -alias adb_debug_key -keyalg RSA -keysize 2048 -validity 10000 -storepass android -keypass android
The official repo is sloretz/sensors_for_ros
.
git clone https://github.com/sloretz/sensors_for_ros.git
Next initialize the git submodules.
git submodule init
git submodule update
Use vcstool to download the ROS packages we need to cross compile into the deps
folder.
vcs import --input ros.repos deps/
Build the software
mkdir build
cd build
cmake ../ -DANDROID_HOME=$HOME/android-sdk/
make -j`nproc`
Install the APK in the build directory onto a device.
adb install -r sensors_for_ros.apk
Use logcat to view the logs from the app
adb logcat
Sometimes you may want to try out a permission without writing the code to request it. The app must be installed, but not running already for this command to work.
adb shell pm grant com.github.sloretz.sensors_for_ros android.permission.CAMERA
The main activity can be started directly from the CLI
adb shell am start -n com.github.sloretz.sensors_for_ros/android.app.NativeActivity
Getting stack traces
adb logcat | $HOME/android-sdk/ndk/*/ndk-stack -sym lib/arm64-v8a/
During development I documented problems I encountered and fixes for them in the Problems Encountered document.