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

Support loading resources from Fuel #1186

Draft
wants to merge 1 commit into
base: rolling
Choose a base branch
from

Conversation

nkoenig
Copy link

@nkoenig nkoenig commented Apr 12, 2024

sdformat_urdf supports the use of SDF files, and I'd like to utilize Fuel for resource hosting. With this PR, an SDF file can remain consistent when used between Gazebo and RViz. This will also give people the option of store meshes and models in a location other than a git repository.

I think it makes sense to support this capability here, rather than modify SDF files to use absolute paths. A user may run rviz on a separate machine from Gazebo, and wouldn't necessarily be able to resolve an absolute path.

It does add an additional dependency on gz-fuel_tools. This is required to resolve urls like https://fuel.gazebosim.org/1.0/openrobotics/models/backpack. If a resource is not in the local Fuel cache, then it's downloaded.

I'm new to adding dependencies like this. Please let me know what I should do to fix or improve things.

Test

Here is a simple launch file that you can use for testing

import os

from ament_index_python.packages import get_package_share_directory 
from launch import LaunchDescription
from launch.actions import (
  DeclareLaunchArgument,
  IncludeLaunchDescription,
  RegisterEventHandler,
)
from launch.event_handlers import OnProcessExit
from launch.launch_description_sources import PythonLaunchDescriptionSource
from launch.substitutions import LaunchConfiguration
from launch_ros.actions import Node

def generate_launch_description() -> LaunchDescription:
    use_sim_time = LaunchConfiguration('use_sim_time', default=True)

    # Get SDF via xacro
    robot_description_content = """<?xml version="1.0" encoding="UTF-8"?>
      <sdf version='1.9'>
        <model name="backpack">
          <static>true</static>
          <link name="base_link">
            <collision name="collision">
              <pose>0 0 2 0 0 0</pose>
              <geometry>
                <mesh>
                  <uri>https://fuel.gazebosim.org/1.0/openrobotics/models/backpack/tip/files/meshes/Backpack.dae</uri>
                </mesh>
              </geometry>
            </collision>

            <visual name="visual">
              <geometry>
                <mesh>
                  <uri>https://fuel.gazebosim.org/1.0/openrobotics/models/backpack/tip/files/meshes/Backpack.dae</uri>
                </mesh>
              </geometry>
            </visual>
          </link>
        </model>
      </sdf>"""

    robot_description = {'robot_description': robot_description_content}

   # The node to publish robot state information
    robot_state_publisher_node = Node(
        package='robot_state_publisher',
        executable='robot_state_publisher',
        output='both',
        parameters=[robot_description, {'publish_frequency': 1000.0}],
    )

    rviz_node = Node(
        package='rviz2',
        executable='rviz2',
        name='rviz2',
        output='log',
    )

    gz_spawn_entity = Node(
        package='ros_gz_sim',
        executable='create',
        output='screen',
        arguments=['-string', robot_description_content],
    )

    # Return the final launch description
    return LaunchDescription(
        [
          DeclareLaunchArgument(
              'use_sim_time',
              default_value=use_sim_time,
              description="If true, use simulation clock",
          ),
          # Launch gazebo environment
          IncludeLaunchDescription(
            PythonLaunchDescriptionSource(
              [
                os.path.join(
                  get_package_share_directory('ros_gz_sim'),
                  'launch',
                  'gz_sim.launch.py',
                )
              ]
            ),
            launch_arguments=[('gz_args', [' -r -v 4 empty.sdf'])],
          ),
          # Run the joint state publisher after the robot has been spawned
          RegisterEventHandler(
            event_handler=OnProcessExit(
              target_action=gz_spawn_entity,
              on_exit=[rviz_node],
            )
          ),
          robot_state_publisher_node,
          gz_spawn_entity,
      ]
    )

@nkoenig nkoenig requested a review from ahcorde as a code owner April 12, 2024 23:04
@clalancette
Copy link
Contributor

So the hardest bit about this is that we have to make more Gazebo dependencies core to ROS 2. In particular, gz_fuel_tools depends on:

  • gz_cmake_vendor
  • gz_common_vendor
  • gz_math_vendor
  • gz_msgs_vendor
  • gz_tools_vendor
  • gz_utils_vendor

Of those, we currently only depend on cmake, utils, and math in the core, so we'd have to add in common, msgs, and tools as new dependencies. Under the new OSRA rules (which aren't quite in effect yet, but will be soon), we'll have to get ROS PMC approval to add those dependencies in. I'll keep this on the list to review once we have the PMC totally up and running.

@mjcarroll
Copy link
Member

@nkoenig I'm also thinking about improvements to rviz mesh loading. Give me a few days to get a proposal out and maybe we can merge these two ideas in such a way that doesn't introduce dependencies.

@MichaelOrlov
Copy link

On the latest waffle triage meeting decided to move this issue to the backlog.

@clalancette
Copy link
Contributor

Setting this to backlog and a draft PR for now, as we will wait to see how this comes together with what @mjcarroll is working on.

@clalancette clalancette marked this pull request as draft April 26, 2024 15:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants