Quantcast
Channel: ROS Answers: Open Source Q&A Forum - RSS feed
Viewing all articles
Browse latest Browse all 49

Android pubsub Listener custom message

$
0
0
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 subscriber = connectedNode.newSubscriber("mytopic", my_package.my_message._TYPE); subscriber.addMessageListener(new MessageListener() { @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 subscriber = connectedNode.newSubscriber("chatter", std_msgs.String._TYPE); subscriber.addMessageListener(new MessageListener() { @Override public void onNewMessage(std_msgs.String message) { log.info("I heard: \"" + message.getData() + "\""); } }); } }

Viewing all articles
Browse latest Browse all 49

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>