Ask Your Question
2

Calling launch file from node during runtime

asked 2014-09-22 04:57:09 -0500

bvbdort gravatar image

updated 2014-09-23 03:31:05 -0500

Hi all,

Based on some condition in node, I want to start and stop hector slam . (in parallel)

I had looked at different questions and rosspawn but couldn't figure it out.

if(start_node == true)
{
// start node in parallel 
// Here my case is hector SLAM
}
if (stop_node == true)
{
// Stop the node
}

Any suggestions ?

thanks.

Edit ::

I found starting node in another package in python code from Roslaunch-API Usage. I am looking for similar way in C++ also starting nodes with params and arguments.

import roslaunch

package = 'rqt_gui'
executable = 'rqt_gui'
node = roslaunch.core.Node(package, executable)

launch = roslaunch.scriptapi.ROSLaunch()
launch.start()

process = launch.launch(node)
print process.is_alive()
process.stop()
edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2014-09-22 08:00:07 -0500

paulbovbel gravatar image

updated 2014-09-22 08:57:50 -0500

AFAIK there is no right way to start and stop nodes dynamically. If you're writing the nodes yourself, it's much better to include pause/resume functionality via services.

As @Ricky stated, you can use the system call, however system will block until the command finishes, meaning you have to use the & control operator in the command to spin off a new process. Then you have the issue of trying to track down/parse the PID in order to shutdown when necessary.

I would recommend using Qt's QProcess, which will make it easier to manage the state of the process (destructing the object will kill the roslaunch process, thus shutting down the nodes).


EDIT: Poco also has nice looking Process management, if you want to avoid messing with Qt. ROS's class_loader CMakeLists is an example of how to include Poco in your package.

edit flag offensive delete link more

Comments

Hi Paul, thanks for answer, poco looks better than using direct linux commands, i will try it out. But its not the ROS way of doing.

bvbdort gravatar imagebvbdort ( 2014-09-22 14:30:31 -0500 )edit

The problem with writing everything as a service is that ROS can be a memory hog. Even small trivial nodes, doing nothing, can consume 4% of memory. Get a few dozen of those, and you're already out of memory even though your bot's just sitting there doing nothing.

Cerin gravatar imageCerin ( 2016-12-10 17:30:04 -0500 )edit
0

answered 2014-09-22 07:44:49 -0500

Maybe you can try system("roslaunch pkg_name launch_file_name"); in C++.

edit flag offensive delete link more

Comments

@Ricky Thanks for reply I tried this, but it stops current node i want to run it parallel with node which is executes system call ,also i want a way to stop it on some condition in runtime.

bvbdort gravatar imagebvbdort ( 2014-09-22 07:56:08 -0500 )edit

Thanks for the explanation~I think @paulbovbel's answer is quite nice.

Po-Jen Lai gravatar imagePo-Jen Lai ( 2014-09-22 08:31:13 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2014-09-22 04:57:09 -0500

Seen: 2,229 times

Last updated: Sep 23 '14