Ask Your Question
1

Using roscpp in existing app on Android/iOS

asked 2019-11-21 12:29:55 -0600

peetonn gravatar image

updated 2019-11-21 12:36:26 -0600

Hi there. I have an existing app, or rather a shared library, that I compile for mobile platforms (currently Android, but iOS will come very soon too). It is a C++ library that have heavy dependencies (“heavy” in terms of cross-compiling and amount of code). Now, I need to publish (and consume) some ROS topics. I was looking at ROS client libraries page and it seems to me that I should use roscpp for my project. However, after following through all the android ndk tutorials I’m still confused on how I would incorporate roscpp into my existing code. I would expect to have a set of .so or .a libraries compiled for the target platform (btw, I use arm64 while docker container compiles for arm7) and a headers folder to include in my source code. My question is – how can I use roscpp in my existing C++ android library? I am not using Android studio, I use ndk-build directly. I noticed there’re Application.mk and Android.mk files in “roscpp_android_ndk” folder, is that shall be used ultimately?

edit retag flag offensive close merge delete

Comments

Could you elaborate a bit more on your hardware setup? Are you running ROS on a robot and you want to read /publish topics from it from Android/iOS? Or you want to actually run ROS nodes on Android/iOS?

lucascoelho gravatar imagelucascoelho ( 2019-11-21 15:29:19 -0600 )edit

ROS runs on multple OpenPTrack machines. My mobile client needs to publish specific topics that will be consumed by a ROS node. Mobile client will also need to subscribe for few topics. I have a c++ library that I NDK-compile and incorporate in mobile application in a third-party framework (not a Java/Swift app).

peetonn gravatar imagepeetonn ( 2019-11-21 15:35:32 -0600 )edit

2 Answers

Sort by » oldest newest most voted
1

answered 2019-11-21 16:40:36 -0600

duck-development gravatar image

you may use the http://wiki.ros.org/rosbridge_suite

and you have only json and some web sicket tcp oder udp connection und your done

edit flag offensive delete link more

Comments

is this the de-facto way to go in the cases like mine? we used ros bridge C# implementation in previous project for Unity app, this time wanted to go bare C++ with no WebSocket intermediary...

peetonn gravatar imagepeetonn ( 2019-11-21 16:48:09 -0600 )edit

It is the easy way to get ros connection. With lowest dependecys. You can use a TCP connection without the websockets. Und you Code ist easy Portable from kinetic to melodic.

duck-development gravatar imageduck-development ( 2019-11-21 18:00:52 -0600 )edit
0

answered 2019-11-26 04:29:28 -0600

iliis gravatar image

You can use the rosjava API even with otherwise fully native code by using the JNI.

If you really don't want to use Java then I have some hints here (I hope I have time in the future to write that down properly). Be warned tough that it took me many weeks of fighting various build systems, fixing code and hunting down the right flags!

All you actually need to communicate is roscpp and its dependencies. Basically you start with rosinstall_generator roscpp --rosdistro melodic --deps and go from there. Throw out everything you don't really really need. Some libraries that ROS uses are cumbersome to cross-compile but easily stripped out by removing a few lines.

I had successs with Boost 1.69 using https://github.com/moritz-wundke/Boos... (1.70 didn't work) and a current cmake (3.15.5 for me).

I have a folder where I make install all third party dependencies into (like boost or eigen). Everything else is in a normal catkin workspace using the following config:

catkin config --install --cmake-args \
    -DCMAKE_BUILD_TYPE=RelWithDebInfo \
    -DANDROID_ABI=arm64-v8a \
    -DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK_HOME/build/cmake/android.toolchain.cmake \
    -DANDROID_TOOLCHAIN=clang \
    -DANDROID_NDK=$ANDROID_NDK_HOME \
    -DANDROID_NATIVE_API_LEVEL=26 \
    -DCMAKE_FIND_ROOT_PATH=<a whole bunch of paths here> \
    -DANDROID_STL=c++_shared \
    -DBoost_DEBUG=ON \
    -DBoost_COMPILER=-clang \
    -DBoost_ARCHITECTURE=-a64 \
    -DBUILD_SHARED_LIBS=ON \
    -DBoost_USE_STATIC_LIBS=ON

CMAKE_FIND_ROOT_PATH is a list of paths where all the third party libraries are installed to, as well as the catkin install folder. Every .so that's ever needed is in there basically so other packages can find it.

I spent a long time getting a working python 2 for Android. I got python itself running, but haven't managed to get pip and python libraries to cross-compile. You actually don't need any python just for roscpp tough ;)

I haven't gotten image_transport working, because that relies on some python modules. So I have to transmit uncompressed images which quickly saturates even a gigabit link!

Some ROS packages didn't compile out of the box and needed a few small fixes.


As for linking everything into our Android application: I'm using Android's cmake (with Android Studio 3.5.1 and NDK 20.0.5594570) which makes integration of a catkin package quite easy actually: If you've set your CMAKE_FIND_ROOT_PATH properly in the Android project you can just use find_package(roscpp). I don't have any experience using the old ndk-build based system and I warmly recommend cmake instead ;)

But basically: If you use an install layout in your catkin workspace (catkin config --install) you will get an install folder that contains all the .so and header files that you can just link to your code.


Another option might be to use Termux and compile everything you need on the device itself.

Good luck!

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

Asked: 2019-11-21 12:29:55 -0600

Seen: 30 times

Last updated: Nov 26