Ask Your Question
0

Android pubsub Listener custom message

asked 2014-08-19 05:49:50 -0500

stefan gravatar image

updated 2014-08-19 06:15:51 -0500

Hello,

can anybody tell me how to import a custom message into a java Listener for my Android Project?

I modified the Listeners and Talkers in rosjava_core tutorial_pubsub and did ./gradlew install to build a jar out of my files.

I managed to use custom messages in RosTextViews nad know how to build .java or .jar from my custom messages.

How does the Listerner has to look like? Where do i have to put the .java or .jar and how can i import them to this Listener.java?

Thanks

package 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;

import mypackage.mymessage;    ???????

public class Listener_mycustom_message extends AbstractNodeMain {

public int intVar_a=0;
public int intVar_b=0;


  @Override
  public GraphName getDefaultNodeName() {
  return GraphName.of("APP/listener_mycustom_message");
  }


 @Override
 public void onStart(ConnectedNode connectedNode) {

  final Log log = connectedNode.getLog();
  Subscriber<my_package.my_message> subscriber = connectedNode.newSubscriber("mytopic", my_package.my_message._TYPE);



 subscriber.addMessageListener(new MessageListener<my_package.my_message>() {
  @Override
  public void onNewMessage(my_package.my_message message) {
intVar_a      = message.getVar_a();
    intVar_b      = message.getVar_b();

      }
    });
   }
}

default Listener

package 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 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

1 Answer

Sort by ยป oldest newest most voted
0

answered 2014-08-19 09:06:36 -0500

stefan gravatar image

updated 2014-08-19 09:07:07 -0500

adding

compile project (':my_package') in pubsub's build.gradle solved my problem in the end

dependencies {
 compile project(':rosjava')
 compile project (':my_package')
}
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

1 follower

Stats

Asked: 2014-08-19 05:49:50 -0500

Seen: 470 times

Last updated: Aug 19 '14