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

Start another Node from pythonscript

asked 2018-05-29 07:29:12 -0500

Baumboon gravatar image

Hello Guys,

first of all here is my setup : Ubuntu 16.04 with ROS kinetic and Gazebo 7.0.

I have a Scenario where a simulated turtlebot drives to several objects. Actual i need some pointcloud data from him but only from the approach.

Now i use :

rosrun pcl_ros pointcloud_to_pcd input:=/depth/points

I would prefere something how i can integrate this in my code and only save pcd files in the approach of the objects. So i need something that i can start the pointcloud to pcd node and something how i can stop the node after the approach.

An code example would help me a lot.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2018-05-29 08:02:13 -0500

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:

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.

edit flag offensive delete link more



Thats a very good idea, but i have some questions how to republish the pointcloud from /depth/points. I will open a new question.

Baumboon gravatar image Baumboon  ( 2018-05-29 09:18:31 -0500 )edit

Question Tools

1 follower


Asked: 2018-05-29 07:29:12 -0500

Seen: 161 times

Last updated: May 29 '18