See also
Overview | C++ | Python | .Net | Java | Matlab | Urbi
Java SDK | Java installation guide | Compiling and running the examples | Compiling the Java bindings from source | Java troubleshooting | Java SDK changelog
JNAOqi is an open source project that allows you to call any NAOqi module method from Java. The call syntax is the same as in Python or .Net.
JNAOqi project contains both binary and source code that needs to be compiled with Naoqi C++ SDK.
Please make sure to have read the NAOqi Framework section first.
The basic approach is:
This can be seen in the following example:
import com.aldebaran.proxy.ALTextToSpeechProxy;
public class SayHello {
public static String NAO_IP = "nao.local";
public static int NAO_PORT = 9559;
public static void main(String[] args) {
ALTextToSpeechProxy tts = new ALTextToSpeechProxy(NAO_IP, NAO_PORT);
tts.say("Hello, world");
}
}
The underlying modules of NAOqi use C++ types. All the basic types of C++ that are used in bound methods have very similar types in Java so need no special translation.
More complex C++ types such as std::vector<type> and AL::ALValue are mapped as follows (where Variant is a custom implementation of a variant type in the com.aldebaran.proxy package)
C++ | JNI | Java | Variant conversion |
---|---|---|---|
bool | jbool | Boolean | Variant::toBool() |
int | jint | int | Variant::toInt() |
float | jfloat | float | Variant::toFloat() |
string | jstring | String | Variant::toString() |
ALValue::binary | jbytearray | byte[] | Variant::toByteArray() |
vector<float> | jfloatarray | float[] | Variant::toFloatArray() |
vector<int> | jintarray | int[] | Variant::toIntArray() |
vector<string> | jobjectarray | String[] | Variant::toStringArray() |
ALValue | None | Variant | Any conversion method |
Please read the Java installation guide section, then proceed to the Compiling and running the examples tutorial.