ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Using rosjava nodes inside non-rosjava projects.

asked 2014-09-22 23:21:42 -0500

kritchie gravatar image

updated 2014-09-23 01:01:40 -0500


I am trying to adapt an existing complex java application using a rosjava node. I succesfully included my rosjava test class "" into my other java project so I can access the class and create an instance of the rosjava object. The problem happens here :

 public class Listener extends AbstractNodeMain {
     public void onStart(ConnectedNode connectedNode) { ... }

This method is the onStart method of the auto-generated class of my rosjava project.

How could I access the ConnectedNode object from a non-rosjava class or method and pass it to the rosjava object in order to correctly use it.

Or maybe there's another way around to adapt non rosjava projects ? Did you guys encounter the same problem as me ? I want to hear what you've done to solve this problem.

Thank you very much !

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2014-09-23 12:55:21 -0500

paulbovbel gravatar image

This seems like an architecture issue. You cannot access ConnectedNode from your external code, since that code doesn't have a dependency on rosjava, and doesn't know what a ConnectedNode is.

Instead you have to try to wrap the external code inside your rosjava nodes, the official name for that is the Adapter pattern. That means the external code needs to expose all necessary functions and data in its public API.

edit flag offensive delete link more

answered 2014-09-24 09:03:15 -0500

kramer gravatar image

You could use ROS messages as the abstraction enabler. If your non-java code is already a ROS node, just create pub/sub or service messages to exchange the data. If it's not already a ROS node, wrap it in code that makes it a ROS node (which is good design for non-trivial code anyway). In effect, the messages then define your API.

I did this for a java/c++ project; rosjava integrated with/into an external project, c++ for robot control on my end. ROS communication worked without a hitch, as expected.

edit flag offensive delete link more


Hi, can i use a java application to launch the roslaunch file in ROS or run a node with several line in java?

isabellezheng gravatar image isabellezheng  ( 2016-08-18 08:09:05 -0500 )edit

roslaunch is a command-line command (a python script). You could, of course, execute the roslaunch file as a java.lang.Process, but it seems to me that unless there are extraordinary circumstances, ur doing it wrong.

kramer gravatar image kramer  ( 2016-08-18 15:52:45 -0500 )edit

ok, thank you, i shoud make a API java for the robot but i dont really understand how to do it to make the java code choose the action of the robot, so i am trying to write different roslaunch file and use java to open it ... if u have some advice for me, pls tell me, thank you so much

isabellezheng gravatar image isabellezheng  ( 2016-08-19 06:59:14 -0500 )edit

I may be wrong, but I get the impression that you don't understand what roslaunch does. It starts ROS nodes. If you want to use java, look at rosjava (indigo), possibly using messages to communicate with other (non-java?) ROS nodes.

kramer gravatar image kramer  ( 2016-08-19 09:31:04 -0500 )edit

yeah i understood the roslaunch is to start multi ros nodes in the same time. for example, if i want to use aruco_ros and usb_cam and publish the info of position of the aruco symbole , at the same time the info is subscribed by a rosserial node serving for arduino, so i should step by step

isabellezheng gravatar image isabellezheng  ( 2016-08-19 16:16:16 -0500 )edit

first start the usb_cam_node and the single.launch file in the aruco_ros and also start the serial_node in the package rosserial and so on, what i want to ask is can i do all of this with just a java program? and thank you for your reply ^ ^

isabellezheng gravatar image isabellezheng  ( 2016-08-19 16:19:55 -0500 )edit

As mentioned, of course you can start processes (e.g., roslaunch) as a java.lang.Process. But it seems to me you'd be better served using a bash script that also starts your java code, if that's what you need.

kramer gravatar image kramer  ( 2016-08-20 08:11:50 -0500 )edit

OK, i ll try to learn it , thank you so much for your advice ^ ^

isabellezheng gravatar image isabellezheng  ( 2016-08-20 12:49:24 -0500 )edit

Question Tools

1 follower


Asked: 2014-09-22 23:21:42 -0500

Seen: 796 times

Last updated: Sep 24 '14