Ask Your Question

Connect to master URI and launch ROSJava nodes

asked 2012-05-30 08:19:27 -0500

amittleider gravatar image

updated 2014-01-28 17:12:30 -0500

ngrennan gravatar image

I asked a similar question before, but I don't think I was clear enough as no one had a response. I've dug around a ton in the javadocs to figure out how to launch the master URI and register ROS nodes within straight java code (not android, just rosjava). I found some old tutorials here: but it appears that they are outdated and the code no longer compiles.

Here is my attempt, but note that I create new Talker(), but I never use it. Obviously this is incorrect as I should be required to pass the talker node as a parameter somewhere:

    RosCore rosCore = RosCore.newPublic();
    NodeConfiguration nodeConfiguration = NodeConfiguration.newPrivate();
    try {
    } catch (Exception e) {
      throw new RuntimeException(e);
    Talker talker = new Talker();

    GraphName nodeName = new GraphName("Talker");
    GraphName topicName = new GraphName("chatter");
    String topicMessageType = "String";

    rosCore.getMasterServer().registerPublisher(nodeName, rosCore.getUri(), topicName, topicMessageType);

    int i = 0;
    while(i < 5)
        try {
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block


I just want this to publish the chatter topic with a hello world message. Thanks for helping.


edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2012-05-31 16:46:29 -0500

amittleider gravatar image

updated 2012-05-31 16:48:32 -0500

I am surprised that I couldn't find detailed documentation for this anywhere (There is some at the project home, but you definitely cannot just copy/paste to get it working). I read a lot of the source code to attempt to figure this out. So far, so good. Here is some code that you can run in Java to launch your nodes. Keep in mind that you have to first compile all the nodes that come with the rosjava source... This will create the JAR files. Then you must add the JAR files to your project (in this example, I took the Talker and Listener source files from the rosjava_tutorial_pubsub and added them to my project as well).

public class RosConnect {

RosCore rosCore;
NodeMainExecutor e = DefaultNodeMainExecutor.newDefault();

public RosConnect()
    rosCore = RosCore.newPublic(13111); //13111 is the ROS port.  if you are launching ros files from roscpp or rospy make sure to  specify the argument '-p 13111' when you run the launch file.

    try {
    } catch (Exception e) {
        throw new RuntimeException(e);

public void publishChatter()
    System.out.println("Starting talker node...");
    NodeConfiguration talkerConfig = NodeConfiguration.newPrivate();
    NodeMain talker = new Talker();
    e.execute(talker, talkerConfig);

    System.out.println("Starting listener node....");
    NodeConfiguration listenerConfig = NodeConfiguration.newPrivate();
    NodeMain listener = new Listener();
    e.execute(listener, listenerConfig);


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


Asked: 2012-05-30 08:19:27 -0500

Seen: 2,281 times

Last updated: May 31 '12