Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 package org.ros;
00018
00019 import org.ros.concurrent.CancellableLoop;
00020 import org.ros.message.MessageFactory;
00021 import org.ros.message.MessageListener;
00022 import org.ros.namespace.GraphName;
00023 import org.ros.node.AbstractNodeMain;
00024 import org.ros.node.ConnectedNode;
00025 import org.ros.node.topic.Publisher;
00026 import org.ros.node.topic.Subscriber;
00027
00033 public class SlaveApiTestNode extends AbstractNodeMain {
00034
00035 @Override
00036 public GraphName getDefaultNodeName() {
00037 return GraphName.of("rosjava/slave_api_test_node");
00038 }
00039
00040 @Override
00041 public void onStart(final ConnectedNode connectedNode) {
00042
00043 final Publisher<std_msgs.String> pub_string =
00044 connectedNode.newPublisher("chatter_out", std_msgs.String._TYPE);
00045 MessageListener<std_msgs.String> chatter_cb = new MessageListener<std_msgs.String>() {
00046 @Override
00047 public void onNewMessage(std_msgs.String m) {
00048 System.out.println("String: " + m.getData());
00049 }
00050 };
00051
00052 Subscriber<std_msgs.String> stringSubscriber =
00053 connectedNode.newSubscriber("chatter_in", std_msgs.String._TYPE);
00054 stringSubscriber.addMessageListener(chatter_cb);
00055
00056
00057 final Publisher<std_msgs.Int64> pub_int64_pubsub =
00058 connectedNode.newPublisher("int64", std_msgs.Int64._TYPE);
00059 MessageListener<std_msgs.Int64> int64_cb = new MessageListener<std_msgs.Int64>() {
00060 @Override
00061 public void onNewMessage(std_msgs.Int64 m) {
00062 }
00063 };
00064
00065 Subscriber<std_msgs.Int64> int64Subscriber =
00066 connectedNode.newSubscriber("int64", "std_msgs/std_msgs.Int64");
00067 int64Subscriber.addMessageListener(int64_cb);
00068
00069
00070
00071 connectedNode.executeCancellableLoop(new CancellableLoop() {
00072 @Override
00073 protected void loop() throws InterruptedException {
00074 MessageFactory topicMessageFactory = connectedNode.getTopicMessageFactory();
00075 std_msgs.String chatter = topicMessageFactory.newFromType(std_msgs.String._TYPE);
00076 chatter.setData("hello " + System.currentTimeMillis());
00077 pub_string.publish(chatter);
00078
00079 std_msgs.Int64 num = topicMessageFactory.newFromType(std_msgs.Int64._TYPE);
00080 num.setData(1);
00081 pub_int64_pubsub.publish(num);
00082 Thread.sleep(100);
00083 }
00084 });
00085 }
00086 }