0
$\begingroup$

Rosanswers logo

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() + "\"");
   }
  });
 }
}

Originally posted by stefan on ROS Answers with karma: 15 on 2014-08-19

Post score: 0

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

adding

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

dependencies {
 compile project(':rosjava')
 compile project (':my_package')
}

Originally posted by stefan with karma: 15 on 2014-08-19

This answer was ACCEPTED on the original site

Post score: 0

$\endgroup$

Your Answer

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