Where is the main function in Rosjava
Hello,
rosjava is still very mysterious for me, maybe because I'm also not very familiar with java yet. I understand how the simple listener talker are working but the thing is that there is no main function like in C++ that will run the program and create all the instances. Now I have both classes talker.java and listener.java both have their onStart methods which implement a cancellable loop and keep sending/listening. Running them with rosrun is easy but My question is : who calls these functions onStart?? and what is this parameter : onStart(final ConnectedNode connectedNode) where does it come from. I'm asking this because I want to run such a code from eclipse but it keeps saying there is no main function defined.
This is the talker.java code:
package com.github.rosjava_catkin_package_a.my_pub_sub_tutorial;
import org.ros.concurrent.CancellableLoop;
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.Publisher;
/**
* A simple {@link Publisher} {@link NodeMain}.
*/
public class Talker extends AbstractNodeMain {
@Override
public GraphName getDefaultNodeName() {
return GraphName.of("rosjava/talker");
}
@Override
public void onStart(final ConnectedNode connectedNode) {
final Publisher<std_msgs.String> publisher =
connectedNode.newPublisher("chatter", std_msgs.String._TYPE);
// This CancellableLoop will be canceled automatically when the node shuts
// down.
connectedNode.executeCancellableLoop(new CancellableLoop() {
private int sequenceNumber;
@Override
protected void setup() {
sequenceNumber = 0;
}
@Override
protected void loop() throws InterruptedException {
std_msgs.String str = publisher.newMessage();
str.setData("Hello world! " + sequenceNumber);
publisher.publish(str);
sequenceNumber++;
Thread.sleep(1000);
}
});
}
}
thanks