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

Running ROSJAVA as a thread in a larger app.

asked 2011-10-18 03:07:23 -0600

morrowsend gravatar image

updated 2011-10-18 03:25:19 -0600

How might the ROSJAVA talker example be spawned as a separate thread since it must be passed the NodeConfiguration at startup? I get an error stating that I cannot cast my main file to org.ros.node.NodeMain.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
0

answered 2011-10-18 18:39:35 -0600

morrowsend gravatar image

updated 2011-10-18 18:39:56 -0600

I figured it out. I have to implement NodeMain in the main java file, save the passed NodeConfiguration to a global volatile, and read it from the runnable() which contains the RosNode. I am sure there is a better way of doing it (such as simply passing the NodeConfiguration to the run() method) but this works for now. If I run into problems with it, I will post an update.

edit flag offensive delete link more
1

answered 2011-10-18 23:58:26 -0600

Lorenz gravatar image

updated 2011-10-18 23:59:04 -0600

The easiest way to run a RosMain instance in a thread is to use the NodeRunner class.

NodeConfiguration nodeConfiguration =
        NodeConfiguration.newPublic(InetAddressFactory.newNonLoopback().getHostName(),
                getMasterUri());
FooNodeMain foo = new FooNodeMain();
DefaultNodeRunner.newDefault().run(foo, nodeConfiguration);

In the above example, the class FooNodeMain needs to implement org.ros.node.NodeMain. NodeRunner's run method is non-blocking and just runs your node in a new thread and you can call it multiple times to spawn different nodes.

edit flag offensive delete link more

Question Tools

Stats

Asked: 2011-10-18 03:07:23 -0600

Seen: 341 times

Last updated: Oct 18 '11