These days I’ve been figuring out how to load URDF-based models in Android without having to re-write too much code. Instead, the idea was to take profit of all the code already existing in ROS. Viewing URDF models in ROS basically involves four packages:
- ogre, a wrapper around OGRE3D: the open-source graphics rendering engine used by rviz and gazebo.
- ogre_tools, that contains code for rendering basic geometric primitives and loading meshes with OGRE3D.
- urdf_interface and urdf_parser, which basically parse an URDF file and build up a data structure from it.
- rviz, concretely the code under the robot/ folder, which calls ogre_tools and urdf_parser and actually builds the scene graph.
So, it wouldn’t be an easy task ;). Doing it with rosjava was one of the possibilities, but would have involved re-writing much of the code, specially for urdf parsing and, even more important: 3D visualization. It is a common practice in Android (and guess others too!) to perform 3D rendering using native code in C/C++, mainly because of the high performance required.
Fortunately, OGRE3D has been improving Android support in the last weeks (check this forum thread). This became my first option, since having OGRE in Android would allow to re-use much of the code existing in ROS. Cross-compiling Ogre with the Android NDK was not easy, but worked fine after some fixes. I was able to get the demos running on my Galaxy Tab 10.1, and actually got surprised because of the number of examples and nice features already supported!
The next step was to cross-compile ogre_tools, urdf_parser, urdf_interface and the robot part of rviz. These mainly depend on ros/console, tinyxml and…. libboost 😦 I got rid of the first dependency by re-defining the macros ROS_ERROR, ROS_WARN and ROS_DEBUG. Tinyxml fortunately is tiny, as the name indicates 😉 I could cross-compile it without many problems (which doesn’t mean I didn’t have any!). My main concern was boost, but guess what?? there is a github project that downloads and cross-compiles a number of common open-source libraries for you! and boost is there! that really saved me a lot of time.
With all the dependencies installed I was able to cross-compile the ROS packages, and put everything into a proof-of-concept OGRE demo that takes an .urdf file as input and renders the robot. Check how the PR2 looks like in Android!:
Next I would like to check how to run OGRE as a native part inside a rosjava app. rosjava could receive ROS messages from the ROS network and update the visualization on the native part.