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

Bridge as a gz sim system #501

Closed
wants to merge 26 commits into from
Closed

Bridge as a gz sim system #501

wants to merge 26 commits into from

Conversation

caguero
Copy link
Contributor

@caguero caguero commented Feb 21, 2024

🎉 New feature

Summary

This PR runs the ROS<->Gz bridge as a gz sim system.

Test it

ros2 launch ros_gz_sim_demos ros_gz.launch.py

Verify the output to confirm that two topics are bridged:

[ruby $(which ign) gazebo-1] [INFO] [1708634732.070359776] [ros_gz_bridge]: Creating ROS->GZ Bridge: [ros_chatter (std_msgs/msg/String) -> gz_chatter (ignition.msgs.StringMsg)] (Lazy 1)
[ruby $(which ign) gazebo-1] [INFO] [1708634732.071384449] [ros_gz_bridge]: Creating GZ->ROS Bridge: [gz_chatter (ignition.msgs.StringMsg) -> ros_chatter (std_msgs/msg/String)] (Lazy 0)

Then, you should see a ROS topic /ros_chatter:

caguero@cold:~/ros_gz_ws$ ros2 topic list
/parameter_events
/ros_chatter
/rosout

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.

Signed-off-by: Carlos Agüero <[email protected]>
Signed-off-by: Carlos Agüero <[email protected]>
Signed-off-by: Carlos Agüero <[email protected]>
Signed-off-by: Carlos Agüero <[email protected]>
Signed-off-by: Carlos Agüero <[email protected]>
Signed-off-by: Carlos Agüero <[email protected]>
Signed-off-by: Carlos Agüero <[email protected]>
Signed-off-by: Carlos Agüero <[email protected]>
Signed-off-by: Carlos Agüero <[email protected]>
Signed-off-by: Carlos Agüero <[email protected]>
Signed-off-by: Carlos Agüero <[email protected]>
Signed-off-by: Carlos Agüero <[email protected]>
Signed-off-by: Carlos Agüero <[email protected]>
Signed-off-by: Carlos Agüero <[email protected]>
Signed-off-by: Carlos Agüero <[email protected]>
Signed-off-by: Carlos Agüero <[email protected]>
Signed-off-by: Carlos Agüero <[email protected]>
@@ -12,6 +12,8 @@ endif()

find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(rclcpp_components REQUIRED)
Copy link
Collaborator

Choose a reason for hiding this comment

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

you don't need to include this dependency, with rclcpp should be enough, you are not adding any component

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If I don't add it, the code doesn't compile. Maybe a dependency isn't exporting it correctly.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we determined that ros_gz_bridge isn't correctly exporting the dependency.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed!

ros_gz_sim/src/ros_gz.cpp Show resolved Hide resolved
}

// Sanity check: Make sure that the config file exists and it's a file.
std::filesystem::path configFile = _sdf->Get<std::string>("config_file");
Copy link
Collaborator

Choose a reason for hiding this comment

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

include <filesystem>

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That was already there :)

// Sanity check: Make sure that the config file exists and it's a file.
std::filesystem::path configFile = _sdf->Get<std::string>("config_file");
if (!std::filesystem::is_regular_file(configFile)) {
std::cerr << "[" << configFile << "] is not a regular file. Plugin disabled"
Copy link
Collaborator

Choose a reason for hiding this comment

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

include <iostream>

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Comment on lines 44 to 48
gz::sim::EventManager & _eventMgr) override;


/// \brief Private data pointer.
std::unique_ptr<ROSGzPluginPrivate> dataPtr;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
gz::sim::EventManager & _eventMgr) override;
/// \brief Private data pointer.
std::unique_ptr<ROSGzPluginPrivate> dataPtr;
gz::sim::EventManager & _eventMgr) override;
/// \brief Private data pointer.
std::unique_ptr<ROSGzPluginPrivate> dataPtr;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Signed-off-by: Carlos Agüero <[email protected]>
@caguero caguero requested a review from ahcorde February 22, 2024 17:21
Signed-off-by: Carlos Agüero <[email protected]>
Signed-off-by: Carlos Agüero <[email protected]>
Signed-off-by: Carlos Agüero <[email protected]>
Signed-off-by: Carlos Agüero <[email protected]>
@@ -14,6 +14,7 @@ find_package(ament_cmake REQUIRED)
find_package(image_transport REQUIRED)
find_package(ros_gz_bridge REQUIRED)
find_package(rclcpp REQUIRED)
find_package(rclcpp_components REQUIRED)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This PR should fix this issue #501

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed!

mjcarroll and others added 4 commits February 23, 2024 10:12
Signed-off-by: Carlos Agüero <[email protected]>
Signed-off-by: Carlos Agüero <[email protected]>
Signed-off-by: Carlos Agüero <[email protected]>
@caguero caguero marked this pull request as ready for review February 23, 2024 17:35
@mjcarroll
Copy link
Collaborator

Ah sorry, there was a bad merge there. Thanks for fixing that.

Copy link
Contributor

@azeey azeey left a comment

Choose a reason for hiding this comment

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

This looks great! I have a few comments that I think will make this more consistent with the ROS ecosystem as well as existing naming schemes in Gazebo.

One question I have is how this deals with models spawned at runtime. Would the user be able to add another bridge system as part of the model?

Comment on lines +14 to +27
filename="ignition-gazebo-physics-system"
name="gz::sim::systems::Physics">
</plugin>
<plugin
filename="ignition-gazebo-user-commands-system"
name="gz::sim::systems::UserCommands">
</plugin>
<plugin
filename="ignition-gazebo-scene-broadcaster-system"
name="gz::sim::systems::SceneBroadcaster">
</plugin>
<plugin
filename="ignition-gazebo-contact-system"
name="gz::sim::systems::Contact">
Copy link
Contributor

Choose a reason for hiding this comment

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

Use gz-sim instead of ignition-gazebo.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed in #511

Comment on lines +5 to +14
gz_type_name: "ignition.msgs.StringMsg"
subscriber_queue: 5
publisher_queue: 6
lazy: true
direction: ROS_TO_GZ

- ros_topic_name: "ros_chatter"
gz_topic_name: "gz_chatter"
ros_type_name: "std_msgs/msg/String"
gz_type_name: "ignition.msgs.StringMsg"
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe we can use gz.msgs for the gz_type_name.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed in #511.

std::string path = gz::common::findFile(filename);
if (!gz::common::isFile(path)) {
std::cerr << "Unable to open YAML file [" << filename
<< "], check your GAZEBO_RESOURCE_PATH settings." << std::endl;
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we use GAZEBO_RESOURCE_PATH? I thought that was for Gazebo-classic.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, that was a typo. Changed in #511.

Comment on lines +71 to +72
<plugin name="ros_gz_sim::ROSGzPlugin"
filename="libROSGzPlugin.so">
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we rename this to be name=ros_gz_sim::ROSGzBridge and filename=ros-gz-bridge-system to have bridge in the name and to be more consistent with our other systems (eg. we haven't used Plugin in any of our existing systems). For the filename, the shared library would need to be libros-gz-bridge-system.so. In the <plugin> tag the lib and .so can be dropped.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated in #511.


// Sanity check: Make sure that the config file exists and it's a file.
std::string filename = _sdf->Get<std::string>("config_file");
std::string path = gz::common::findFile(filename);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it would be better to use package:// URIs for the file name since this is all happening in the ROS ecosystem. Then, instead of calling gz::common::findFile, we can pass the file directly to RosGzBridge (so no need to call findFile here) and update RosGzBridge so it can use resource_retriever to find the file.

Copy link
Contributor Author

@caguero caguero Mar 15, 2024

Choose a reason for hiding this comment

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

resource_retriever is functional but the API is slightly different because as far as I know it can't resolve the path only. Instead, it resolves the path and read the content of the file, returning it as a byte array.

However I figured that we still can use the package:// approach. I guess findFile() is solving it for us?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, the API is different. That's why I was suggesting to pass the filename directly to RosGzBridge and use resource_retriever there where we are currently opening the file:

std::ifstream in(filename);

I don't know how common::findFile is handling package://. My guess is it ignores the package:// part and tries to find the path based on Gazebo environment variables, which is not what we want.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In any case I can tackle it in a separate PR as it affects mainly ros_gz_bridge. I already played with it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@caguero
Copy link
Contributor Author

caguero commented Mar 15, 2024

Replaced with #511 targeting ROS 2 rolling.

@caguero caguero closed this Mar 15, 2024
@caguero caguero mentioned this pull request Mar 20, 2024
9 tasks
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.

4 participants