Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SpawnEntity, DeleteEntity, & SetEntityPose Support #380

Merged
merged 8 commits into from
Mar 18, 2025

Conversation

retinfai
Copy link
Contributor

@retinfai retinfai commented Apr 7, 2023

🎉 New feature

Closes #363

Summary

Add support for SpawnEntity, DeleteEntity, & SetEntityPose services
Add support for EntityFactory

Test it

Spin up a parameter bridge for the service you are testing, and make a ros2 service call to it

Example for SpawnEntity

gz sim empty.sdf
ros2 run ros_gz_bridge parameter_bridge /world/empty/create@ros_gz_interfaces/srv/SpawnEntity
ros2 service call /world/empty/create ros_gz_interfaces/srv/SpawnEntity "{entity_factory: {name: "cool_sdf", sdf_filename: 'path/to/sdf'}}"

Checklist

  • Signed all commits for DCO
  • 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)
  • While waiting for a review on your PR, please help review another open pull request to support the maintainers

Note to maintainers: Remember to use Squash-Merge and edit the commit message to match the pull request summary while retaining Signed-off-by messages.

@retinfai retinfai requested a review from ahcorde as a code owner April 7, 2023 21:46
@retinfai retinfai closed this Apr 10, 2023
@azeey
Copy link
Contributor

azeey commented Apr 10, 2023

@retinfai Did you mean to close this PR?

@retinfai
Copy link
Contributor Author

I wasn't sure whether I had to have all the things checked off before opening the PR? Or can it be open, while I complete all the tasks

@azeey
Copy link
Contributor

azeey commented Apr 10, 2023

You can mark it as a draft PR if you're still working on it. Reviewers might give you initial feedback.

@retinfai retinfai reopened this Apr 10, 2023
@retinfai retinfai marked this pull request as draft April 10, 2023 19:03
@retinfai
Copy link
Contributor Author

Perfect, thanks

@jpvr20
Copy link

jpvr20 commented Jan 1, 2024

Is there any updates on this?

@azeey
Copy link
Contributor

azeey commented Jan 2, 2024

Is there any updates on this?

Not that I know if. It would be great to get this PR moving again.

@retinfai
Copy link
Contributor Author

retinfai commented Jan 2, 2024

Is there any updates on this?

Functionally everything in this PR works. I've been using it in my projects fine. Just haven't had time to go back and follow the process properly. Will try to move things along

@jpvr20
Copy link

jpvr20 commented Jan 2, 2024

@retinfai
I tried using the SetEntityPose service, but I'm not getting any response. any ideas? Using Gazebo Garden and Ros2 humble

ros2 run ros_gz_bridge parameter_bridge /world/bluerov2_heavy_underwater/set_pose@ros_gz_interfaces/srv/SetEntityPose

ros2 service call /world/bluerov2_heavy_underwater/set_pose ros_gz_interfaces/srv/SetEntityPose "{entity: {id: 8, name: "rgbd_camera2", type: 6}, pose: {position: {x: 0.2, y: 0.0, z: 0.0}, orientation: {x: 0.0, y: 0.0, z: 0.0, w: 1.0}}}"

It prints this, but no response after this,

requester: making request: ros_gz_interfaces.srv.SetEntityPose_Request(entity=ros_gz_interfaces.msg.Entity(id=8, name='rgbd_camera2', type=6), pose=geometry_msgs.msg.Pose(position=geometry_msgs.msg.Point(x=0.2, y=0.0, z=0.0), orientation=geometry_msgs.msg.Quaternion(x=0.0, y=0.0, z=0.0, w=1.0)))

@retinfai
Copy link
Contributor Author

retinfai commented Jan 3, 2024

It prints this, but no response after this,
I guess it doesn't all work haha. Haven't tried the services on sensors, there could be a gap

@retinfai I tried using the SetEntityPose service, but I'm not getting any response. any ideas? Using Gazebo Garden and Ros2 humble

ros2 run ros_gz_bridge parameter_bridge /world/bluerov2_heavy_underwater/set_pose@ros_gz_interfaces/srv/SetEntityPose

ros2 service call /world/bluerov2_heavy_underwater/set_pose ros_gz_interfaces/srv/SetEntityPose "{entity: {id: 8, name: "rgbd_camera2", type: 6}, pose: {position: {x: 0.2, y: 0.0, z: 0.0}, orientation: {x: 0.0, y: 0.0, z: 0.0, w: 1.0}}}"

It prints this, but no response after this,

requester: making request: ros_gz_interfaces.srv.SetEntityPose_Request(entity=ros_gz_interfaces.msg.Entity(id=8, name='rgbd_camera2', type=6), pose=geometry_msgs.msg.Pose(position=geometry_msgs.msg.Point(x=0.2, y=0.0, z=0.0), orientation=geometry_msgs.msg.Quaternion(x=0.0, y=0.0, z=0.0, w=1.0)))

Hmm, not quite sure. Everything looks fine; haven't tried services on things other than a model, so i guess it isn't all working haha. Can you verify that you get the correct expected behaviour calling the service from the gazebo side? gz service ....

@jpvr20
Copy link

jpvr20 commented Jan 3, 2024

@retinfai There was some problem in my package. The model is moving fine using the service.

Edit
The sensors doesn't work and the behavior is not same using gazebo service. It changes values of world pose cmd instead of pose. gazebo service doesn't do anything. Not sure if I'm using it right

retinfai and others added 2 commits January 5, 2024 18:50
Co-authored-by: Alejandro Hernández Cordero <[email protected]>
Signed-off-by: Afereti Pama <[email protected]>
Co-authored-by: Alejandro Hernández Cordero <[email protected]>
Signed-off-by: Afereti Pama <[email protected]>
@k12onoss
Copy link

Hi, is there any ETA as to when this will be merged?

@k12onoss
Copy link

@retinfai
I tried to run the SpawnEntity service, but it doesn't seem to work.
ros2 run ros_gz_bridge parameter_bridge /world/drone_world/create@ros_gz_interfaces/srv/SpawnEntity
Running the above command doesn't produce any response and even running ros2 service list shows nothing. (Which I've verified by trying to call the service from ROS).
P.S.: Calling the service from Gazebo side has no issues and works as expected.

@elmeripk
Copy link

@k12onoss Any solutions for this? I am trying to do the same but get the following response and the service is not displayed when calling ros2 service list. The WorldControl that has been available for a while works fine. I get the following, SpawnEntity}, gz request type {}, gz request type {}, gz reply type name {} in the terminal when trying to execute the command ros2 run ros_gz_bridge parameter_bridge /world/empty/create@ros_gz_interfaces/srv/SpawnEntity ros_gz_interfaces/srv/

@k12onoss
Copy link

@elmeripk apologies for late a reply.

Yes, I eventually got it working.
In your case, it seems you haven't sourced the workspace where you have cloned this package. I get the same output as you when I try to call the SpawnEntity service using the released version of ros_gz_bridge. But with this PR, it works as expected.

@Trana
Copy link

Trana commented Oct 3, 2024

I tested the create/remove/set_pose services on Jazzy and Harmonic and the changes in this PR worked fine for me.

@johnreb20
Copy link

@retinfai
ERROR: the following packages/stacks could not have their rosdep keys resolved
to system dependencies:
ros_gz_image: Cannot locate rosdep definition for [gz_transport_vendor]
ros_gz_sim_demos: Cannot locate rosdep definition for [gz_sim_vendor]
ros_gz_sim: Cannot locate rosdep definition for [gz_transport_vendor]
ros_gz_bridge: Cannot locate rosdep definition for [gz_transport_vendor]
Continuing to install resolvable dependencies...
#All required rosdeps installed successfully

getting this issues.Please can you help?

@TannerGilbert
Copy link

Any update on this? Would really like to have this feature also for older ROS and Gazebo combinations like Humble + Fortress.

@khaledgabr77
Copy link

Hello everyone,

I’ve been testing the SpawnEntity, DeleteEntity, and SetEntityPose functionalities using both ROS 2 Jazzy with Gazebo Harmonic and ROS 2 Rolling with Gazebo Iron, and everything has worked smoothly without any issues.

Steps I took:

  1. Pulled Docker images for both Rolling and Jazzy (ROS 2).
  2. Installed ros_gz and cloned the [ros_gz (ros2 branch)](https://github.com/UoA-CARES/ros_gz/tree/ros2) repository from source.
  3. Tested SpawnEntity, DeleteEntity, and SetEntityPose—all of which worked perfectly.
  4. Created a C++ package containing three separate source files for spawning, deleting, and setting an entity’s pose.
  5. Verified functionality with Gazebo and ROS 2, confirming that everything works as expected.

I plan to write documentation detailing the setup steps and usage instructions. Would it be helpful for me to create a new PR that includes the new package and documentation, or should I add these additions to the existing PR?

@j-rivero
Copy link
Contributor

Hello!

ℹ️ The Gazebo core team has included the review of PR into a community effort to attract new contributions, see the message in LinkdIn. I wrote some context and introduction about how to help in https://gist.github.com/j-rivero/9ea1abe2441c8dbf3cc4dffccfbdaff8.

Thanks @retinfai for the PR and sorry for not coming before. Let's try to get this merged and release. Could you please resolve the conflicts and accept the DCO bot signatures? If you don't have time anymore let me know. I'm marking the PR as ready to review.

Thanks @khaledgabr77 for the review, really appreciated.

Would it be helpful for me to create a new PR that includes the new package and documentation, or should I add these additions to the existing PR?

That is a good question, since it is external PR controlled by @retinfai probably the best way would be to open a new PR and I can merge both in order so we don't overload @retinfai with more actions.

@j-rivero j-rivero marked this pull request as ready for review March 13, 2025 10:59
@j-rivero j-rivero self-assigned this Mar 13, 2025
@TannerGilbert
Copy link

Thanks for starting the community effort @j-rivero. I wanted to ask what the Gazebo policy for backporting features such as this PR and https://community.gazebosim.org/t/ros-gz-bridge-improvements/3135 to older versions like ROS 2 Humble + Gazebo Fortress or ROS 2 Humble + Gazebo Harmonic are as I think users of these releases should also benefit from new features.

@j-rivero
Copy link
Contributor

Thanks for starting the community effort @j-rivero.

Thanks Gilbert, hopefully it can help the people to contribute easily.

I wanted to ask what the Gazebo policy for backporting features such as this PR and https://community.gazebosim.org/t/ros-gz-bridge-improvements/3135 to older versions like ROS 2 Humble + Gazebo Fortress or ROS 2 Humble + Gazebo Harmonic are as I think users of these releases should also benefit from new features.

The ros_gz bridge is a bit different from the rest of Gazebo libraries since it is a native ROS package. I think that we probably want to follow the general guidelines. My personal guideline for backports in the ROS packages is: not to breaking the API out of Rolling and not breaking the behavior of the software.

For this PR, please, backports are very welcome and fall under the community weekly effort.

For the https://docs.ros.org/en/dashing/Contributing/Developer-Guide.html#guidelines-for-backporting-prs), I replied there.

@retinfai retinfai reopened this Mar 15, 2025
@retinfai
Copy link
Contributor Author

retinfai commented Mar 15, 2025

Hi, I've resolved the merge conflicts. However, I'm having problems with the DCO, rebasing. I don't have alot of experience rebasing, and it's making me resolve conflicts of things I haven't touched at all, so am hesitant to try to do that.

If someone who knows what to do, wants access to try to resolve that. I'm happy to add them

@khaledgabr77
Copy link

Hello!
Thank you @j-rivero! My PR is ready and available here: #705 . Please let me know if any modifications are required.

@j-rivero
Copy link
Contributor

Hi, I've resolved the merge conflicts.

Thanks Afereti !

. I don't have alot of experience rebasing, and it's making me resolve conflicts of things I haven't touched at all, so am hesitant to try to do that. If someone who knows what to do, wants access to try to resolve that. I'm happy to add them

Yeah sometimes the rebase is not trivial. Don't worry I think I can deal with the bot with stashing the commits to merge it.

CI is not happy but the good news if that it is easy to fix. cpplint / uncrustify:

This patch provided by uncrustify will take care of most of the problems:

13: --- src/convert/ros_gz_interfaces.cpp
13: +++ src/convert/ros_gz_interfaces.cpp.uncrustify
13: @@ -157,2 +157,3 @@
13: -  gz::msgs::EntityFactory & gz_msg) {
13: -  
13: +  gz::msgs::EntityFactory & gz_msg)
13: +{
13: +
13: @@ -167,5 +168,8 @@
13: -  bool provided_two = has_sdf ? (has_sdf_filename || has_clone_name) : (has_sdf_filename && has_clone_name);
13: -
13: -  if (provided_two)
13: -    std::cout << "Warning: You should only provide ONE of sdf, sdf_filname, or clone_name" << std::endl;
13: -  
13: +  bool provided_two = has_sdf ? (has_sdf_filename || has_clone_name) : (has_sdf_filename &&
13: +    has_clone_name);
13: +
13: +  if (provided_two) {
13: +    std::cout << "Warning: You should only provide ONE of sdf, sdf_filname, or clone_name" <<
13: +      std::endl;
13: +  }
13: +

After appliying the uncrustify patch is probably the cpplint only needs the last suggestion of line 130.

9: /github/home/ws/src/ros_gz/ros_gz_bridge/src/convert/ros_gz_interfaces.cpp:158:  Line ends in whitespace.  Consider deleting these extra spaces.  [whitespace/end_of_line] [4]
9: /github/home/ws/src/ros_gz/ros_gz_bridge/src/convert/ros_gz_interfaces.cpp:158:  Redundant blank line at the start of a code block should be deleted.  [whitespace/blank_line] [2]
9: /github/home/ws/src/ros_gz/ros_gz_bridge/src/convert/ros_gz_interfaces.cpp:167:  Lines should be <= 100 characters long  [whitespace/line_length] [2]
9: /github/home/ws/src/ros_gz/ros_gz_bridge/src/convert/ros_gz_interfaces.cpp:170:  Lines should be <= 100 characters long  [whitespace/line_length] [2]
9: /github/home/ws/src/ros_gz/ros_gz_bridge/src/convert/ros_gz_interfaces.cpp:171:  Line ends in whitespace.  Consider deleting these extra spaces.  [whitespace/end_of_line] [4]
9: /github/home/ws/src/ros_gz/ros_gz_bridge/src/service_factories/ros_gz_interfaces.cpp:130:  Redundant blank line at the start of a code block should be deleted.  [whitespace/blank_line] [2]
9: Category 'whitespace/blank_line' errors found: 2
9: Category 'whitespace/end_of_line' errors found: 2
9: Category 'whitespace/line_length' errors found: 2
9: Total errors found: 6

@j-rivero
Copy link
Contributor

Thank you @j-rivero! My PR is ready and available here: #705 . Please let me know if any modifications are required.

Woow, that is great ! Thanks @khaledgabr77 let's follow in the PR.

@j-rivero
Copy link
Contributor

I'm going to merge this one and resolve the linters errors in a new PR

@j-rivero j-rivero merged commit dd36692 into gazebosim:ros2 Mar 18, 2025
1 of 4 checks passed
@ahcorde ahcorde mentioned this pull request Mar 18, 2025
8 tasks
voshch pushed a commit to voshch/ros_gz that referenced this pull request Mar 19, 2025
* Feat: add spawn, delete, set pose service and entity_factory to bridge
---------

Signed-off-by: Afereti Pama <[email protected]>
Co-authored-by: Alejandro Hernández Cordero <[email protected]>
(cherry picked from commit dd36692)
@j-rivero
Copy link
Contributor

@Mergifyio backport jazzy humble

Copy link
Contributor

mergify bot commented Mar 20, 2025

backport jazzy humble

✅ Backports have been created

mergify bot pushed a commit that referenced this pull request Mar 20, 2025
* Feat: add spawn, delete, set pose service and entity_factory to bridge
---------

Signed-off-by: Afereti Pama <[email protected]>
Co-authored-by: Alejandro Hernández Cordero <[email protected]>
(cherry picked from commit dd36692)
mergify bot pushed a commit that referenced this pull request Mar 20, 2025
* Feat: add spawn, delete, set pose service and entity_factory to bridge
---------

Signed-off-by: Afereti Pama <[email protected]>
Co-authored-by: Alejandro Hernández Cordero <[email protected]>
(cherry picked from commit dd36692)
ahcorde added a commit that referenced this pull request Mar 20, 2025
#712)

Signed-off-by: Alejandro Hernandez Cordero <[email protected]>
Co-authored-by: Afereti Pama <[email protected]>
Co-authored-by: Alejandro Hernández Cordero <[email protected]>
ahcorde added a commit that referenced this pull request Mar 20, 2025
#713)

Signed-off-by: Alejandro Hernandez Cordero <[email protected]>
Co-authored-by: Afereti Pama <[email protected]>
Co-authored-by: Alejandro Hernández Cordero <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

SpawnEntity, DeleteEntity, SetPose Services