sensors_for_ros

Introduction: An Android app that publishes sensor and camera data on ROS 2 topics
More: Author   ReportBugs   
Tags:

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.

Inspiration

These projects were extremely helpful, and used as a reference for this one:

How to install it

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.

How to build it from source

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.

Computer setup

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-on-Fedora-20) if you're using Fedora.

Create debug keys

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

Clone the repo

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

Download ROS dependencies

Use vcstool to download the ROS packages we need to cross compile into the deps folder.

vcs import --input ros.repos deps/

Building the App

Build the software

mkdir build
cd build
cmake ../ -DANDROID_HOME=$HOME/android-sdk/
make -j`nproc`

Installing the App on your Android Device

Install the APK in the build directory onto a device.

adb install -r sensors_for_ros.apk

Development tips

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/

Random lessons

During development I documented problems I encountered and fixes for them in the Problems Encountered document.

Apps
About Me
GitHub: Trinea
Facebook: Dev Tools