https://github.com/sloretz/sensors_for_ros
An Android app that publishes sensor and camera data on ROS 2 topics
https://github.com/sloretz/sensors_for_ros
android ros-humble ros2
Last synced: about 1 month ago
JSON representation
An Android app that publishes sensor and camera data on ROS 2 topics
- Host: GitHub
- URL: https://github.com/sloretz/sensors_for_ros
- Owner: sloretz
- Created: 2022-04-01T19:44:07.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2024-04-02T16:45:29.000Z (about 1 year ago)
- Last Synced: 2025-03-25T09:04:04.056Z (about 2 months ago)
- Topics: android, ros-humble, ros2
- Language: C++
- Homepage:
- Size: 206 KB
- Stars: 92
- Watchers: 3
- Forks: 9
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Sensors for ROS
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
* MagnetometerThis 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:
* https://github.com/cnlohr/rawdrawandroid
* https://github.com/ocornut/imgui/tree/master/examples/example_android_opengl3
* https://www.sisik.eu/blog/android/ndk/camera## 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](https://docs.ros.org/en/humble/Installation.html).### Computer setup
Download the [Android SDK "Command-line tools only" version](https://developer.android.com/studio#command-tools).
Other versions may work, but this is the minimum needed.Make a folder for the SDK and extract the archive.
```bash
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`
```bash
# 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
```bash
# 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](https://developer.android.com/studio/run/device#setting-up) instructions if you're using Ubuntu, or follow [the instructions in this thread](https://forums.fedoraforum.org/showthread.php?298965-HowTo-set-up-adb-(Android-Debug-Bridge)-on-Fedora-20) if you're using Fedora.### Create debug keys
You'll need to install openjdk to get access to `keytool`.
```bash
sudo apt install openjdk-11-jre-headless
```Create a debug keystore
```bash
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`](https://github.com/sloretz/sensors_for_ros).
```
git clone https://github.com/sloretz/sensors_for_ros.git
```Next initialize the git submodules.
```bash
git submodule init
git submodule update
```### Download ROS dependencies
Use [vcstool](https://github.com/dirk-thomas/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](docs/problems_encountered.md) document.