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

Revision history [back]

If there isn't an easier way I'm thinking I should create a python wrapper that takes a shell script as a parameter, and passes rospy.get_namespace() as a parameter to the script, or sets ROS_NAMESPACE for it as suggested above.

Launch the script with subprocess maybe like one of the scripts in http://answers.ros.org/question/10714/start-and-stop-rosbag-within-a-python-script/

TODO actually make this work and fill in the details here.

If there isn't an easier way I'm thinking I should create a python wrapper that takes a shell script as a parameter, and passes rospy.get_namespace() as a parameter to the script, or sets ROS_NAMESPACE for it as suggested above.

Launch the script with subprocess maybe like one of the scripts https://github.com/lucasw/testbot/blob/master/testbot_utils/scripts/wrap_shell_script.py

<launch>
   <group ns="nest">
      <node name="wrap_shell_script" pkg="testbot_utils" type="wrap_shell_script.py" 
            output="screen">
        <param name="pkg" value="testbot_utils" />
        <param name="script" value="test.sh" />
        <param name="test_param" value="have_correct_namespace" />
      </node>
   </group>
</launch>

And the wrapper script:

#!/usr/bin/env python

import rospy
import subprocess

rospy.init_node('wrap_shell_script')

# TODO get other script arguments?
#namespace = rospy.get_namespace()
# assume the shell script only wants private params
namespace = rospy.get_name()

script = rospy.get_param("~script")
pkg    = rospy.get_param("~pkg")

subprocess.call('ROS_NAMESPACE=' + namespace + ' rosrun ' + pkg + ' ' + script, shell=True)

So there the wrapper assumes the script will only want private params when it does a rosparam get, and the script can't use params named pkg or script because they are in http://answers.ros.org/question/10714/start-and-stop-rosbag-within-a-python-script/

TODO actually make this work and fill in the details here.

the same namespace.

If there isn't an easier way I'm thinking I should create made a python wrapper that takes a shell script as a parameter, and passes rospy.get_namespace() as a parameter to the script, or sets ROS_NAMESPACE for it as suggested above.

https://github.com/lucasw/testbot/blob/master/testbot_utils/scripts/wrap_shell_script.py

<launch>
   <group ns="nest">
      <node name="wrap_shell_script" pkg="testbot_utils" type="wrap_shell_script.py" 
            output="screen">
        <param name="pkg" value="testbot_utils" />
        <param name="script" value="test.sh" />
        <param name="test_param" value="have_correct_namespace" />
      </node>
   </group>
</launch>

And the wrapper script:

#!/usr/bin/env python

import rospy
import subprocess

rospy.init_node('wrap_shell_script')

# TODO get other script arguments?
#namespace = rospy.get_namespace()
# assume the shell script only wants private params
namespace = rospy.get_name()

script = rospy.get_param("~script")
pkg    = rospy.get_param("~pkg")

subprocess.call('ROS_NAMESPACE=' + namespace + ' rosrun ' + pkg + ' ' + script, shell=True)

So there the wrapper assumes the script will only want private params when it does a rosparam get, and the script can't use params named pkg or script because they are in the same namespace.

I made a python wrapper that takes a shell script as a parameter, and passes launches the script int the rospy.get_name() namespace (or should it optionally do rospy.get_namespace() as a parameter to the script, or sets ROS_NAMESPACE for it as suggested above.?) .

https://github.com/lucasw/testbot/blob/master/testbot_utils/scripts/wrap_shell_script.py

<launch>
   <group ns="nest">
      <node name="wrap_shell_script" pkg="testbot_utils" type="wrap_shell_script.py" 
            output="screen">
        <param name="pkg" value="testbot_utils" />
        <param name="script" value="test.sh" />
        <param name="test_param" value="have_correct_namespace" />
      </node>
   </group>
</launch>

And the wrapper script:

#!/usr/bin/env python

import rospy
import subprocess

rospy.init_node('wrap_shell_script')

# TODO get other script arguments?
#namespace = rospy.get_namespace()
# assume the shell script only wants private params
namespace = rospy.get_name()

script = rospy.get_param("~script")
pkg    = rospy.get_param("~pkg")

subprocess.call('ROS_NAMESPACE=' + namespace + ' rosrun ' + pkg + ' ' + script, shell=True)

So there the wrapper assumes the script will only want private params when it does a rosparam get, and the script can't use params named pkg or script because they are in the same namespace.