using roslaunch api for running the same nodes under different namespaces formultiple robots

asked 2019-06-25 10:47:59 -0500

Tahir Mehmood gravatar image

updated 2019-06-26 12:49:33 -0500

I have a working software for navigation of a single robot. I am trying the run the same nodes under different namespaces for multiple homogenous robots. I am doing all the stuff to have a better control over the code (As I have to remap multiple yaml files, topics and paramters as desired).

When running the code I pass namespace of the robot running in the simulation. for 2 robots now it should be like:

/agv_01/node_1
/agv_01/node_2

/agv_02/node_1
/agv_02/node_2

node_1 and node_2 are the same files for 2 different namespaces, after running the script for agv_01, when I run the same by changing the argument agv_02 I get the error:

shutdown request: new node registered with same name

import roslaunch
import rospy
import sys
ns = sys.argv[1]
package = 'webots_communication'

class webots_components(object):
    def __init__(self):
        global package
        global ns
        self.device_enable_node = roslaunch.core.Node(package = package, node_type = 'device_enable_webots',
                                                name = 'webots_ros_communicator', namespace = ns,
                                                respawn = True, output= 'screen')

        self.webots_remapping_node = roslaunch.core.Node(package = package, node_type = 'fts_webots_remapping',
                                                name = 'fts_ros_controller', namespace = ns,
                                                respawn = True, output= 'screen')

        self.webots_joint_states_node = roslaunch.core.Node(package = package, node_type = 'webots_joint_states',
                                                name = 'webots_joint_states_publisher', namespace = ns,
                                                respawn = True, output= 'screen')

        self.webots_localization_node = roslaunch.core.Node(package = package, node_type = 'localization',
                                                name = 'webots_pose_publisher', namespace = ns, args = ns,
                                                respawn = True, output= 'screen')

        self.webots_fts_velocity_bridge_node = roslaunch.core.Node(package = package, node_type = 'fts_velocity_bridge',
                                                name = 'webots_fts_velocity_bridge', namespace = ns, args = ns,
                                                respawn = True, output= 'screen')
    def run(self):
        launch = roslaunch.scriptapi.ROSLaunch()
        launch.start()

        device_enable_process = launch.launch(self.device_enable_node)
        webots_remapping_process = launch.launch(self.webots_remapping_node)
        webots_joint_states_process = launch.launch(self.webots_joint_states_node)
        webots_localization_process = launch.launch(self.webots_localization_node)
        webots_fts_velocity_bridge_process = launch.launch(self.webots_fts_velocity_bridge_node)

if __name__ == '__main__':
    rospy.init_node('launch_files')

    webots = webots_components()
    webots.run()
    rospy.spin()

Edit 1:

THe same script does not work under multiple namespaces, ONe script with namespace i.e. AGV_01 works but after running that when I run the same script in another termial with namespace i.e. AGV_02 the nodes asssoiated wirh AGV_01 are killed by giving the error .

shutdown request: new node registered with same name

Edit 2:

I dont have any launch file. Instead of launch files I have written the above script to run all the nodes desired because it gives more control than launch files.

I run the scripts for 2 AGVs by the follwing commands in the shell.

rosrun communicator communicator "agv_01"

rosrun communicator communicator "agv_02"

edit retag flag offensive close merge delete

Comments

What is your question?

jayess gravatar imagejayess ( 2019-06-25 11:07:49 -0500 )edit

@jayess I have edited the question.

Tahir Mehmood gravatar imageTahir Mehmood ( 2019-06-26 02:48:32 -0500 )edit

How are you running this? Can you please update your question with the commands that you use to run this and your launch file(s) if your using any?

jayess gravatar imagejayess ( 2019-06-26 12:34:16 -0500 )edit

Edit 2 added

Tahir Mehmood gravatar imageTahir Mehmood ( 2019-06-26 12:48:47 -0500 )edit