Skip to content

Add entity_namespace support for spawned entities - #925

Draft
C88-YQ wants to merge 12 commits into
gazebosim:ros2from
C88-YQ:ns_support
Draft

Add entity_namespace support for spawned entities#925
C88-YQ wants to merge 12 commits into
gazebosim:ros2from
C88-YQ:ns_support

Conversation

@C88-YQ

@C88-YQ C88-YQ commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

🎉 New feature

Related to gazebosim/gz-sim#3871

Summary

This PR adds entity_namespace support to:

  • create node
  • gz_spawn_model.launch
  • gz_spawn_model.launch.py
  • ros_gz_spawn_model.launch.py
  • GzSpawnModel launch action
  • simulation interfaces spawn_entity service

The create node now uses Gazebo's /create_with_ns service and sends EntityFactoryWithNs requests. When entity_namespace is set, it is passed to Gazebo as the spawned entity namespace. When it is empty, the spawn behavior stays the same as before.

Backport Policy

  • This is safe to backport to the following versions:
    • Jetty
    • Ionic
    • Harmonic
    • Fortress
  • This should not be backported
  • I am not sure
  • Other (fill in yourself)

Test it

First start a Gazebo world. For example, use a world named default.

Then test spawning models with entity_namespace from the supported entry points.

1. Test ros_gz_sim create

export VEHICLE_SDF="$(ros2 pkg prefix --share ros_gz_sim_demos)/models/vehicle/model.sdf"

ros2 run ros_gz_sim create \
  -world default \
  -file "$VEHICLE_SDF" \
  -name robot1 \
  -ns robot1 \
  -y 0.0

2. Test gz_spawn_model.launch

export VEHICLE_SDF="$(ros2 pkg prefix --share ros_gz_sim_demos)/models/vehicle/model.sdf"

ros2 launch ros_gz_sim gz_spawn_model.launch.py \
  world:=default \
  file:="$VEHICLE_SDF" \
  entity_name:=robot2 \
  entity_namespace:=robot2 \
   y:=2.0

ros2 launch ros_gz_sim gz_spawn_model.launch \
  world:=default \
  file:="$VEHICLE_SDF" \
  entity_name:=robot3 \
  entity_namespace:=robot3 \
  x:=0.0 \
  y:=4.0 \
  z:=0.0

3. Test ros_gz_spawn_model.launch.py

export VEHICLE_SDF="$(ros2 pkg prefix --share ros_gz_sim_demos)/models/vehicle/model.sdf"

ros2 launch ros_gz_sim ros_gz_spawn_model.launch.py \
  world:=default \
  file:="$VEHICLE_SDF" \
  entity_name:=robot4 \
  entity_namespace:=robot4 \
  y:=6.0 \
  bridge_name:=default \
  config_file:=test.yaml

4. Test ROS 2 Simulation Interfaces

export VEHICLE_SDF="$(ros2 pkg prefix --share ros_gz_sim_demos)/models/vehicle/model.sdf"

ros2 service call /gzserver/spawn_entity simulation_interfaces/srv/SpawnEntity "{
  name: 'robot5',
  entity_resource: {
    uri: '$VEHICLE_SDF'
  },
  entity_namespace: 'robot5',
  allow_renaming: false,
  initial_pose: {
    pose: {
      position: {x: 0.0, y: 8.0, z: 0.0},
      orientation: {w: 1.0, x: 0.0, y: 0.0, z: 0.0}
    }
  }
}"

5. Test GzSpawnModel launch action

Create a test launch file, for example:

test_gz_spawn_model_action.launch.xml
<launch>
  <gz_spawn_model
    world="default"
    file="$(find-pkg-share ros_gz_sim_demos)/models/vehicle/model.sdf"
    entity_name="robot6"
    entity_namespace="{name}"
    allow_renaming="false"
    x="0.0"
    y="6.0"
    z="1.0"
    yaw="0.0">
  </gz_spawn_model>
</launch>

Run it with:

ros2 launch ./test_gz_spawn_model_action.launch.xml

After each command, check that the entity is created successfully. Also check the Gazebo GUI side panel and confirm that the displayed namespace matches the namespace used in the spawn command.

Checklist

  • Signed all commits for DCO
  • Added a screen capture or video to the PR description that demonstrates the feature
  • Added tests
  • Added example and/or tutorial
  • Updated documentation (as needed)
  • Updated migration guide (as needed)
  • Consider updating Python bindings (if the library has them)
  • codecheck passed (See contributing)
  • All tests passed (See test coverage)
  • Updated Bazel files (if adding new files). Created an issue otherwise.
  • While waiting for a review on your PR, please help review another open pull request to support the maintainers
  • Was GenAI used to generate this PR? If so, make sure to add "Assisted-by" to your commits. (See this policy for more info.)

Assisted-by: Codex(gpt-5.4)

C88-YQ added 11 commits August 8, 2026 23:06
Signed-off-by: C88-YQ <1409947012@qq.com>
Signed-off-by: C88-YQ <1409947012@qq.com>
Signed-off-by: C88-YQ <1409947012@qq.com>
Signed-off-by: C88-YQ <1409947012@qq.com>
Signed-off-by: C88-YQ <1409947012@qq.com>
Signed-off-by: C88-YQ <1409947012@qq.com>
Signed-off-by: C88-YQ <1409947012@qq.com>
Signed-off-by: C88-YQ <1409947012@qq.com>
Signed-off-by: C88-YQ <1409947012@qq.com>
This reverts commit dfd7e39.

Signed-off-by: C88-YQ <1409947012@qq.com>
Signed-off-by: C88-YQ <1409947012@qq.com>
Signed-off-by: C88-YQ <1409947012@qq.com>
@C88-YQ

C88-YQ commented Aug 8, 2026

Copy link
Copy Markdown
Contributor Author

EntityFactory already has entity_namespace support in gazebosim/gz-msgs#612, but that commit cannot be backported to older branches.

gazebosim/gz-msgs#595 will be backported to older branches, and EntityFactoryWithNs is planned to be deprecated in gazebosim/gz-msgs#616

To make this PR easier to backport, it mainly uses the /create_with_ns service and sends EntityFactoryWithNs requests. It does not handle entity_namespace in EntityFactory yet.

A follow-up PR will update the code to use EntityFactory with entity_namespace support and the /create service

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Inbox

Development

Successfully merging this pull request may close these issues.

2 participants