What is the difference between robot_name, namespac, and frame prefix?

#!/usr/bin/env python3
#
# Copyright 2019 ROBOTIS CO., LTD.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Authors: Darby Lim

import os

from ament_index_python.packages import get_package_share_directory
from launch import LaunchDescription
from launch.actions import IncludeLaunchDescription
from launch.launch_description_sources import PythonLaunchDescriptionSource
from launch.substitutions import ThisLaunchFileDir
from launch.actions import ExecuteProcess
from launch.substitutions import LaunchConfiguration
from launch_ros.actions import Node
from launch.substitutions import Command
import xacro

TURTLEBOT3_MODEL = "waffle_pi"

def generate_launch_description():
    use_sim_time = LaunchConfiguration('use_sim_time', default='true')
    world_file_name = 'turtlebot3_tc_two_robots.world'
    world = os.path.join(get_package_share_directory('turtlebot3_gazebo'), 'worlds', world_file_name)
    robot_desc_path = os.path.join(get_package_share_directory("turtlebot3_description"), "urdf", "turtlebot3_waffle_pi.urdf")

    entity_name_0="tb3_0"
    entity_name_1="tb3_1"

    return LaunchDescription([
        ExecuteProcess(
            cmd=['gazebo', '--verbose', world, '-s', 'libgazebo_ros_init.so'],
            output='screen'),
        
        Node(
            package='robot_state_publisher',
            executable='robot_state_publisher',
            name='robot_state_publisher',
            namespace=entity_name_0,
            parameters=[{
            'frame_prefix': entity_name_0+'/', 
            'use_sim_time': use_sim_time, 
            'robot_description': Command([
            'xacro ', robot_desc_path, 
            ' robot_name:=', entity_name_0])}],
            output="screen"
        ),

        Node(
            package='robot_state_publisher',
            executable='robot_state_publisher',
            name='robot_state_publisher',
            namespace=entity_name_1,
            parameters=[{
            'frame_prefix': entity_name_1+'/', 
            'use_sim_time': use_sim_time, 
            'robot_description': Command([
            'xacro ', robot_desc_path, 
            ' robot_name:=', entity_name_1])}],
            output="screen"
        )

    ])

I’ve taken the code from open class #163, multirobot navigation
Could anyone please explain:

what does the + in do ‘frame_prefix’: entity_name_1+'/

Why is there a need to add a robot name AND name space.
Shouldnt putting the namespace add tb3_0 in front all of the frames by default
E.g odom becomes tb3_0/odom

Also when I try to run this launch file on my own system I get an error that there is No such file or directory: ‘xacro’ -

The ‘+’ sign in the line {'frame_prefix': entity_name_1+'/'} is used for concatenating the entity_name_1 variable with the string ‘/’. In this context, it is used to create a frame prefix for the robot state publisher node. The frame prefix is added to the beginning of each frame name published by the robot state publisher. So, if entity_name_1 is ‘tb3_1’, the resulting frame prefix will be ‘tb3_1/’.

The reason for adding both a robot name and a namespace is to provide unique identifiers for each robot instance in the launch file. By specifying a different robot name and namespace for each robot, you can run multiple instances of the same robot model in a simulation. The namespace allows you to isolate the topics, services, and parameters of each robot instance, preventing conflicts between them.

And no, it is not absolutely necessary to do this. When you put the namespace in front of the frame names, it does add the namespace to the frames published by the robot state publisher. For example, if the namespace is ‘tb3_0’ and the frame name is ‘odom’, it will become ‘tb3_0/odom’. The frame prefix, in this case, is not necessary for adding the namespace to the frames.

The error you encountered, “No such file or directory: ‘xacro’”, it indicates that the ‘xacro’ command is not found on your system.
Check to see if the ‘xacro’ package installed on the system. If it’s already installed, you may need to check the PATH environment variable to ensure that the directory containing the ‘xacro’ executable is included.

Thank you bro this is an amazing explanation

No problem @oei.nick . Hope the explanation about namespaces helped as well.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.