ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
1

rosjava(pure) pubsub tutorial

asked 2011-06-15 12:24:41 -0500

hughie gravatar image

Hi~

I'm using the new, pure-java rosjava. I installed ros(diamonback) and rosjava by rosinstall in my ubuntu(lucid). and build rosjava.jar successfully.

I want talk to other node using pubsub tutorial in rosjava. I imported rosjava.jar and other libraries in eclipse project and modified the source as below. (commons-codec-1.3.jar, commons-httpclient-3.1.jar, commons-loggin-1.1.1.jar, dnsjava-2.1.1.jar, guava-r07.jar, junit-4.8.2.jar, mockito-all-1.8.5.jar, netty-3.2.4.Final.jar, rosjava.jar)

When I run below program by java application, I got this error message.

Hello
java.lang.NullPointerException
    at org.ros.Node.<init>(Node.java:95)
    at Hell.main(Hell.java:19)
    at Hell.main(Hell.java:43)

I also tried to debugging with eclipse but, I couldn't debugging with source with this message

Source not found, [Edit Source Lookup Path ...] button.

I tried to connect ros source directory(ros/rosjava/rosjava/src) and include the rosjava source(org.ros), but It also fail to find the source.

Please help me. I'm beginner of the java language. If this question is too sil7ly, Please understand me.

Thanks!


/*
 * Copyright (C) 2011 Google Inc.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

import com.google.common.base.Preconditions;


import org.ros.Node;
import org.ros.NodeConfiguration;
import org.ros.NodeMain;
import org.ros.Publisher;

public class Hell implements NodeMain {
    private Node node;
    /**
     * @param args
     */
    public void main(NodeConfiguration configuration){
        Preconditions.checkState(node == null);
        Preconditions.checkNotNull(configuration);
        try {
          node = new Node("talker", configuration);
          Publisher<org.ros.message.std_msgs.String> publisher =
              node.createPublisher("chatter", org.ros.message.std_msgs.String.class);
          int seq = 0;
          while (true) {
            org.ros.message.std_msgs.String str = new org.ros.message.std_msgs.String();
            str.data = "Hello world! " + seq++;
            publisher.publish(str);
            Thread.sleep(1000);
          }
        } catch (Exception e) {
          if (node != null) {
            node.getLog().fatal(e);
          } else {
            e.printStackTrace();
          }
        }
    }
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        System.out.println("Hello");

        Hell h = new Hell();
        NodeConfiguration node_cfg = new NodeConfiguration();
        h.main(node_cfg);
    }

    public void shutdown() {
        node.shutdown();
        node = null;
      }

}

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
6

answered 2011-06-16 00:26:58 -0500

damonkohler gravatar image

I see a couple of issues:

First, you should pull the latest version. Your line numbers don't match up with my source.

To view the source, you should be able to attach the source to rosjava.jar as you described. Make sure you select "External folder" and select the "rosjava/src" folder not the "org" folder beneath it.

Finally, I believe your problem is that you have an invalid NodeConfiguration. Admittedly, the error message could be better.

Try using: NodeConfiguration node_cfg = NodeConfiguration.createDefault();

edit flag offensive delete link more

Comments

Now, everything is fine. Thanks.
hughie gravatar image hughie  ( 2011-06-20 00:37:28 -0500 )edit
Please accept the answer if it works for you. Thanks!
damonkohler gravatar image damonkohler  ( 2011-06-20 05:40:41 -0500 )edit
0

answered 2011-06-27 20:46:41 -0500

david gravatar image

Hi Hughie,

Can you provide a working set of elementary project files for communication between Android and ROS? I am definitely asking for too much, but I would appreciate a lot of your help, because I am just another student just recently started learning the ROS and the Android. Thanks! My address is david3.1413@gmail.com

David

edit flag offensive delete link more

Comments

There are Android tutorials in the rosjava project: /trunk/android/tutorials.
damonkohler gravatar image damonkohler  ( 2011-06-29 01:29:59 -0500 )edit
Yes, I downloaded from that place. and it is changing very frequently.
hughie gravatar image hughie  ( 2011-06-29 18:57:36 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2011-06-15 12:24:41 -0500

Seen: 1,765 times

Last updated: Jun 27 '11