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

Revision history [back]

There are a few ways one could do this. Likely the easiest is to use Python's subprocess module. Here's a small example:

import subprocess
cmd = "rosrun pcl_ros pointcloud_to_pcd input:=/depth/points"
proc = subprocess.Popen(cmd, shell=True)
# when ready to shutdown:
proc.kill()

You'd likely want to add some error/exception handling to make sure the process opened and closed successfully if you were really going to implement this.

One could also use the roslaunch Python API.

However, I personally think your proposed plan is not the optimal way to go about this. It takes time to start and stop nodes and for communications between publishers and subscribers to be established. Even if you could start and stop the pointcloud_to_pcd node on-the-fly, you'd likely be missing some clouds or saving clouds you don't want. Instead, what I would do is run the pointcloud_to_pcd node subscribing to a special topic that is only published when you actually want a particular point cloud saved to a PCD file. Then in the node where you are trying to start and stop the pointcloud_to_pcd node, you instead just publish any clouds that meet your criteria on that special topic.