Wrapping your native code as a rosjava node

Hi,

I would like to test this idea with Java 8 but this tutorial put the focus on Android.
http://wiki.ros.org/android_ndk/Tutorials/WrappingNativeRosjavaNode

Some example to begin?

I would like to use this technique on a raspberry pi 2 with Jade installed to run some ROS node on that host and later use RVIZ remotely from my OSX

Cheers

Juan Antonio

Juan Antonio,

Just curious, why do you need to use Java at all in this case? Why not just run the cross-compiled binary?

Julian

Hi Juan Antonio!
This technique is for using native code from your Rosjava program. It will work in a similar way if you are in Android or not.

First you need to compile your native code using the Java Native Interface specification. To learn how to do this, you can see for example this. You should compile and link your code to generate a shared library targeting the system you are working on.

After that, you need to write a java class extending the NativeRosjavaNode. This class must have defined native methods that match the exported functions in the native library. This way Java will redirect the calls to those methods as calls to the library functions. You load the library passing the a string containing the name of the library to the NativeNodeMain constructor.

I can implement a simple example if you want.

Ernesto

1 Like

Good night Ernesto,

Yes, if you can implement a simplest example, I could continue later

If the test goes nice, I would like to create a Gradle library to publish some info from Mindstorms robots: http://ev3dev-lang-java.github.io/#/ to a remote ROS Master to visualize data later with RViz.

Cheers

Juan Antonio

Hi ecorbellini !
Can you share a simple example to me? As for the JNI, I recommand this;Getting Started with the NDK

Thank you

Hi @tony10012,

The example for Wrapping a native rosjava node has been updated recently with a simple example, wrapping a native publisher as a rosjava node, and showing how to execute it. Please take a look there.
As @ecorbellini points out, the technique works out for Android and for pure rosjava, but if you are not using it on Android, using the cross compiled library would seem a simpler solution to me.