Skip to content

Add array spawn service.#20

Open
michalpelka wants to merge 3 commits intoros-simulation:mainfrom
michalpelka:mp/spawn_array
Open

Add array spawn service.#20
michalpelka wants to merge 3 commits intoros-simulation:mainfrom
michalpelka:mp/spawn_array

Conversation

@michalpelka
Copy link
Contributor

Simulation interfaces can be used to populate scene with assets or props, depending on the scenario.
I would like to propose the way to ask underlying simulator to spawn multiple objects.

Motivation:

  • with such API client code can be simpler - one call to a service.
  • with such API simulator can optimize spawning process and do it swift.

Signed-off-by: Michał Pełka <michal.pelka@robotec.ai>
@ayushgnv
Copy link
Member

ayushgnv commented Dec 4, 2025

I think this is a great addition for sim interfaces package and would vote to merge this in. @azeey @peci1 any thoughts on this?

Copy link

@jhanca-robotecai jhanca-robotecai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please bump the version of the package.

Copy link
Contributor

@peci1 peci1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I don't like this approach of making each field an array. However, given the fact that a service request (IMO) cannot be reused elsewhere, it is probably the best possible solution without going awkward (like specifying a standalone message type for the request part).

Please, see the inline comments.

@peci1
Copy link
Contributor

peci1 commented Jan 7, 2026

Please bump the version of the package.

I guess version bumps are done when releasing the package, so I wouldn't expect the bump to be a part of this PR.

@ayushgnv
Copy link
Member

Hi @michalpelka, when you get a chance could you review the comments by @peci1? Once we have those resolved I think it would be good to merge this in soon!

Signed-off-by: Michał Pełka <michal.pelka@robotec.ai>
@michalpelka
Copy link
Contributor Author

@ayushgnv @peci1 thanks for review I've updated contribution candidate.

Copy link
Contributor

@peci1 peci1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few style changes and more info, but otherwise it looks good now!

Co-authored-by: Martin Pecka <peci1@seznam.cz>
Comment on lines +35 to +37
uint8 BATCH_SPAWN_MISMATCH = 110 # There is a mismatch in number of elements in names, allow_renaming, entity_resources,
# entity_namespaces, initial_poses.
uint8 BATCH_SPAWN_FAILED = 120 # There was at least one failed spawn request. Check individual results in results.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should these error codes start from a larger number (e.g. 150 or 200) so that there's more room for error codes in

# Additional result.result_code values for this service. Check result.error_message for further details.
uint8 NAME_NOT_UNIQUE = 101 # Given name is already taken by entity and allow_renaming is false.
uint8 NAME_INVALID = 102 # Given name is invalid in the simulator (e.g. does not meet naming
# requirements such as allowed characters). This is also returned if name is
# empty and allow_renaming is false.
uint8 UNSUPPORTED_FORMAT = 103 # Format for uri or resource string is unsupported. Check supported formats
# through GetSimulatorFeatures service, in spawn_formats field.
uint8 NO_RESOURCE = 104 # Both uri and resource string are empty.
uint8 NAMESPACE_INVALID = 105 # Namespace does not meet namespace naming standards.
uint8 RESOURCE_PARSE_ERROR = 106 # Resource file or string failed to parse.
uint8 MISSING_ASSETS = 107 # At least one of resource assets (such as meshes) was not found.
uint8 UNSUPPORTED_ASSETS = 108 # At least one of resource assets (such as meshes) is not supported.
uint8 INVALID_POSE = 109 # initial_pose is invalid, such as when the quaternion is invalid or position
to expand? Also, any reason why the two error codes are incremented by 10?

# Support for this interface is indicated through the SPAWNING_BATCH value in GetSimulationFeatures.

string names[] # A list of names given to every entity
# If string is empty, a name field in the uri file or resource_string will be used,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this saying the names array can be empty or that individual elements of the array can be the empty string?

@tfoote
Copy link
Member

tfoote commented Mar 6, 2026

At a high level I have a few questions. I agree that the parallel construction of arrays in this case doesn't really make sense. It would make more sense to support a single array with all the variables captured in a single message aka make

string name # A name to give to the spawned entity.
# If empty, a name field in the uri file or resource_string will be used,
# if supported and not empty (e.g. "name" field in SDFormat, URDF).
# If the name is still empty or not unique (as determined by the simulator),
# the service returns a generated name in the entity_name response field if the
# allow_renaming field is set to true. Otherwise, the service call fails and an
# error is returned.
bool allow_renaming # Determines whether the spawning succeeds with a non-unique name.
# If it is set to true, the user should always check entity_name response field
# and use it for any further interactions.
Resource entity_resource # Resource such as SDFormat, URDF, USD or MJCF file, a native prefab, etc.
# Valid URIs can be determined by calling GetSpawnables first.
# Check simulator format support via the spawn_formats field in GetSimulatorFeatures.
# Using resource_string is supported if GetSimulatorFeatures includes
# the SPAWNING_RESOURCE_STRING feature.
string entity_namespace # Spawn the entity with all its interfaces under this namespace.
geometry_msgs/PoseStamped initial_pose # Initial entity pose.
# The header contains a reference frame, which defaults to global "world" frame.
# This frame must be known to the simulator, e.g. of an object spawned earlier.
# The timestamp field in the header is ignored.

into SpawningEntity.msg and then have SpawnEntities contain SpawningEntity [] entities

And if we do that. Is there a reason to support two interfaces one for a single entity and one for batch processing. Can the single entity not just be the redundant case of multiple entities where the iterator is just length 1.

If the message is supporting multiple entities, then you can also group the return type as per entity and return an array of { Results + name } => EntitySpawnResult [] results

With a multiple entity spawning capability defined this way I would then suggest deprecating the singular version of the interface as it will increase the burden for all implementations. And for the deprecation cycle the implementers can provide backwards compatibilty by wrapping the single version into an array and reuse the batch processing interface.

@peci1
Copy link
Contributor

peci1 commented Mar 6, 2026

Is there a reason to support two interfaces one for a single entity and one for batch processing.

At least in CLI usage there may be a big difference. Usually tab completion just completes an empty array and that's it.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants