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

rosjava listener.

asked 2013-12-27 16:37:48 -0600

this post is marked as community wiki

This post is a wiki. Anyone with karma >75 is welcome to improve it.

I am trying to build a listener in rosjava. I used the code found at the rosjava core snapshot documentation and changed the GraphName() to GraphNmae.of(). I also added these lines to the code:

package com.github.rosjava.dude.Listener;(The name of my project is dude as it was given in the tutorial)

import org.ros.rosjava_tutorial_pubsub;

When I build this using catkin_make , I get two errors. THe errors and the code is given below. Can somebody please help me fix this. THanks a ton.

1st error:

/home/uahmed9/rosjava/src/rosjava_foo/dude/src/main/java/com/github/rosjava/dude/Listener.java:2: cannot find symbol symbol : class rosjava_tutorial_pubsub location: package org.ros import org.ros.rosjava_tutorial_pubsub;

The dot between ros and rosjava in the import statement is creating error.

2nd error:

/home/uahmed9/rosjava/src/rosjava_foo/dude/src/main/java/com/github/rosjava/dude/Listener.java:21: cannot find symbol symbol : class of location: class org.ros.namespace.GraphName return new GraphName.of("rosjava_tutorial_pubsub/listener");

The dot between GraphName and of in the getDefaultNodeName() method is creating error. The Code:

package com.github.rosjava.dude.Listener;

import org.ros.rosjava_tutorial_pubsub;

import org.apache.commons.logging.Log;

import org.ros.message.MessageListener;

import org.ros.namespace.GraphName;

import org.ros.node.AbstractNodeMain;

import org.ros.node.ConnectedNode;

import org.ros.node.NodeMain;

import org.ros.node.topic.Subscriber;

public class Listener extends AbstractNodeMain {

@Override

public GraphName getDefaultNodeName() {

return new GraphName.of("rosjava_tutorial_pubsub/listener");

}

@Override

public void onStart(ConnectedNode connectedNode) {

final Log log = connectedNode.getLog();

Subscriber<std_msgs.String> subscriber = connectedNode.newSubscriber("chatter",

std_msgs.String._TYPE);

subscriber.addMessageListener(new MessageListener<std_msgs.String>() {

  @Override

  public void onNewMessage(std_msgs.String message) {

    log.info("I heard: \"" + message.getData() + "\"");

  }

});

}

}

edit retag flag offensive close merge delete

Comments

1. Where did you find the `GraphNmae.of().` error? 2. Where did the code for Listener come from? The current create project script doesn't add this, so not sure where your dot error is coming from. 3. What do your dependency settings look like?

Daniel Stonier gravatar image Daniel Stonier  ( 2014-01-01 21:39:55 -0600 )edit

I am sorry for the mistake in pointing the GraphName.of error. I found it in the getDefaultNodeName() method. I fountd the code for the listener form the rosjava_core 0.1.6 documentation. I created the rosjava package and rosjava project using the tutorials on the rosjava wiki. My projects name was dude and hence I was provided with the Dude.java file when i built my project. I changed the name from Dude.java to Listener.java and also removed the statement public class Dude { } to replace it with public class Listener extends AbstractNodeMain { } and added these lines to the code. 1)package com.github.rosjava.dude.Listener; 2)import org.ros.rosjava_tutorial_pubsub; For the dependency settings, I opened the gradle file in my project folder and uncommented "compile 'org.ros.rosjava_core:rosjava:[0.1,)' ". Before I did this, I was geting a lot of errors but now it ...(more)

uzair gravatar image uzair  ( 2014-01-02 08:32:06 -0600 )edit

Why are you trying to import org.ros.rosjava_tutorial_pubsub? That shouldn't be necessary. I don't think you have that as a dependency either, so that will break your build.

Daniel Stonier gravatar image Daniel Stonier  ( 2014-01-02 14:05:58 -0600 )edit

For reference, you could just copy the working code https://github.com/rosjava/rosjava_core/blob/hydro/rosjava_tutorial_pubsub/src/main/java/org/ros/rosjava_tutorial_pubsub/Listener.java directly from the sources. If that works, and there is differences with the doc code, let us know.

Daniel Stonier gravatar image Daniel Stonier  ( 2014-01-02 14:09:18 -0600 )edit

THe codes are identical. After I copy the code from github, where do i paste it? I was creating a project called dude following the rosjava tutorials and then making all the changes in the Dude.java class . Today i tried to create a project whith name Listener. The projects name was listener but the name of the class was again Dude.java. How do I make Dude.java to behave like a listener? If I just delete everything in the Dude.java file and paste the listener code, then I am getting an error "Could not copy Manifest.MF". Before this I was trying how i stated above in the question.

uzair gravatar image uzair  ( 2014-01-02 22:20:58 -0600 )edit

All you should have to do is copy Listener.java in, change the package name in Listener.java to match your folder structure, make sure your build.gradle dependencies match those in the original rosjava_tutorial_pubsub and add rosjava_core to your package.xml.

Daniel Stonier gravatar image Daniel Stonier  ( 2014-01-02 23:31:23 -0600 )edit

After doing all this, my project builds without any errors. But when i make Listener.java executable and execute the file.. i get a number of errors. THese are the errors i get now ./Listener.java: line 2: package: command not found ./Listener.java: line 4: import: command not found ./Listener.java: line 5: import: command not found ./Listener.java: line 6: import: command not found ./Listener.java: line 7: import: command not found ./Listener.java: line 8: import: command not found ./Listener.java: line 9: import: command not found ./Listener.java: line 10: import: command not found ./Listener.java: line 12: public: command not found ./Listener.java: line 14: @Override: command not found ./Listener.java: line 15: syntax error near unexpected token `(' ./Listener.java: line 15: ` public GraphName getDefaultNodeName() {' What am i missing?

uzair gravatar image uzair  ( 2014-01-14 17:44:11 -0600 )edit

I even tried to download the entire rosjava_core package from github and tried to run the Listener.java class in the pubsub package. When I tried to build, this is all I saw-----#### #### Running command: "make cmake_check_build_system" in "/home/uahmed9/rosjava_core-hydro/rosjava_tutorial_pubsub/build" #### #### #### Running command: "make -j4 -l4" in "/home/uahmed9/rosjava_core-hydro/rosjava_tutorial_pubsub/build" #### When I tried to execute the Listener.java class i got the following errors-----------./Listener.java: line 1: /bin: Is a directory ./Listener.java: line 2: syntax error near unexpected token `(' ./Listener.java: line 2: ` * Copyright (C) 2011 Google Inc.'

uzair gravatar image uzair  ( 2014-01-15 13:29:44 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2014-01-28 23:08:40 -0600

Daniel Stonier gravatar image

Does this discussion thread help you uzair?

edit flag offensive delete link more

Comments

yes yes..i was lost. I figured it out. Thanks to you and everybody on the forum. I downloaded the package from github and modified the gradle file to support my external jar instead of creating a new project altogehter. I have a new problem now. If you can take a look here http://answers.ros.org/question/124096/subscribing-and-publishing-at-the-same-time-in-rosjava/ ..thanks

uzair gravatar image uzair  ( 2014-01-29 07:17:10 -0600 )edit

And also I found that package.xml doesnt play any role for rosjava hydro. Its all about the build.gradle file in this version of ros.

uzair gravatar image uzair  ( 2014-01-29 07:27:17 -0600 )edit

The package.xml allows you to string builds of an entire workspace consisting of multiple gradle repositories together in one build sequence using catkin_make. Under the hood, individual gradle repos and projects are handled by gradle alone.

Daniel Stonier gravatar image Daniel Stonier  ( 2014-02-02 08:36:31 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2013-12-27 16:37:48 -0600

Seen: 1,373 times

Last updated: Jan 28 '14