0
$\begingroup$

Rosanswers logo

Hello,

at the moment I am developing an Android application that publishes data into a ROS environment. For this, I use rosandroid-core which is included with Maven from the following repository: https://github.com/rosjava/rosjava_mvn_repo.

By commands like

compile 'org.ros.rosjava_messages:std_msgs:0.5.11'

I am able to generate all standard messages that are defined in the repository. The String-message is defined like the following:

package std_msgs;

import org.ros.internal.message.Message;

public interface String extends Message {

public static final String _DEFINITION = "string data\n";
public static final String _TYPE = "std_msgs/String";

String getData();

void setData(String str);

}

Now I want to create my own message type. So I created a Java interfaces that extends the org.ros.internal.message.Message class.

When I initalize a message from the custom type in the code, everything is fine. But as soon as I want to publish a message from this custom message type, I get a NoClassFoundException.

Do you know where the error is? How can I include the compilation of my custom message type in the Gradle file?

Thanks and best regards.


Originally posted by MrNicolas3003 on ROS Answers with karma: 11 on 2019-04-20

Post score: 1

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

Hi!

That's not how ROS messages work in Java. Note that those interfaces are just empty placeholders; the actual objects that you use to exchange data are generated in runtime.

Those interfaces are generated automatically if you source genjava when building inside a catkin workspace. The standard ROS tutorial to create messages applies.

You can check rosjava_messages repository for reference. It should help you creating custom messages. If you want to use the messages in Android Studio:

  • Create a ROS package with message definitions in your workspace. Configure your CMakeLists file to generate the workspace.
  • Generate the message artifacts by building the workspace. You will need to have genjava installed.
  • Source the workspace.
  • Launch Android Studio. The Maven paths will enable the IDE to find the artifacts you've just generated in the step above.

Hope it helps!

Extra: I don't have a complete example at hand for messages, but generating service interfaces is analogous. You can check how it's done for services here: https://github.com/jubeira/rosjava_srv_test


Originally posted by jubeira with karma: 1054 on 2019-04-22

This answer was ACCEPTED on the original site

Post score: 1


Original comments

Comment by MrNicolas3003 on 2019-04-23:
Hello,

thank you for your fast answer! Is there also a way to generate custom ROS messages in Java without a ROS environment?

Comment by jubeira on 2019-04-23:
Hmm not that I know of nor I would recommend... In any case you'll need genjava to translate the msg files to the interfaces.

Comment by MrNicolas3003 on 2019-04-24:
Okay, I am going to install a ROS environment. Thank you very much!

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.