Connect to master URI and launch ROSJava nodes
I asked a similar question before, but I don't think I was clear enough as no one had a response. I've dug around a ton in the javadocs to figure out how to launch the master URI and register ROS nodes within straight java code (not android, just rosjava). I found some old tutorials here: https://mirror.umd.edu/roswiki/rosjava(2f)Overview(2f)Nodes.html but it appears that they are outdated and the code no longer compiles.
Here is my attempt, but note that I create new Talker(), but I never use it. Obviously this is incorrect as I should be required to pass the talker node as a parameter somewhere:
RosCore rosCore = RosCore.newPublic(); NodeConfiguration nodeConfiguration = NodeConfiguration.newPrivate(); rosCore.start(); try { rosCore.awaitStart(); } catch (Exception e) { throw new RuntimeException(e); } Talker talker = new Talker(); nodeConfiguration.setMasterUri(rosCore.getUri()); GraphName nodeName = new GraphName("Talker"); GraphName topicName = new GraphName("chatter"); String topicMessageType = "String"; rosCore.getMasterServer().registerPublisher(nodeName, rosCore.getUri(), topicName, topicMessageType); int i = 0; while(i < 5) { try { Thread.sleep(1000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } i++; } rosCore.shutdown();
I just want this to publish the chatter topic with a hello world message. Thanks for helping.
-Andrew