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

gzserver Does not Find Some Gazebo Plugins #630

Closed
Amronos opened this issue Nov 2, 2024 · 3 comments · Fixed by #659
Closed

gzserver Does not Find Some Gazebo Plugins #630

Amronos opened this issue Nov 2, 2024 · 3 comments · Fixed by #659
Labels
bug Something isn't working

Comments

@Amronos
Copy link
Contributor

Amronos commented Nov 2, 2024

Environment

  • OS Version: Ubuntu 24.04
  • Source or binary build?
    Source - ad225a2

Description

  • Expected behavior: When launching gazebo through the gz_server.launch.py launch file, I expected gazebo to find the gz_ros2_control-system plugin and not report an error.
  • Actual behavior: Gazebo does not find the plugin and outputs Failed to load system plugin [gz_ros2_control-system] : Could not find shared library.

More information can be found in ros-controls/gz_ros2_control#390

Steps to reproduce

Use the following launch file (A slightly modified version of diff_drive_example.launch.py that uses gz_server.launch.py):

from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument, IncludeLaunchDescription
from launch.actions import RegisterEventHandler
from launch.event_handlers import OnProcessExit
from launch.launch_description_sources import PythonLaunchDescriptionSource
from launch.substitutions import Command, FindExecutable, LaunchConfiguration, PathJoinSubstitution

from launch_ros.actions import Node
from launch_ros.substitutions import FindPackageShare


def generate_launch_description():
    # Launch Arguments
    use_sim_time = LaunchConfiguration('use_sim_time', default=True)

    # Get URDF via xacro
    robot_description_content = Command(
        [
            PathJoinSubstitution([FindExecutable(name='xacro')]),
            ' ',
            PathJoinSubstitution(
                [FindPackageShare('gz_ros2_control_demos'),
                 'urdf', 'test_diff_drive.xacro.urdf']
            ),
        ]
    )
    robot_description = {'robot_description': robot_description_content}
    robot_controllers = PathJoinSubstitution(
        [
            FindPackageShare('gz_ros2_control_demos'),
            'config',
            'diff_drive_controller_velocity.yaml',
        ]
    )

    node_robot_state_publisher = Node(
        package='robot_state_publisher',
        executable='robot_state_publisher',
        output='screen',
        parameters=[robot_description]
    )

    gz_spawn_entity = Node(
        package='ros_gz_sim',
        executable='create',
        output='screen',
        arguments=['-topic', 'robot_description', '-name',
                   'diff_drive', '-allow_renaming', 'true'],
    )

    joint_state_broadcaster_spawner = Node(
        package='controller_manager',
        executable='spawner',
        arguments=['joint_state_broadcaster'],
    )
    diff_drive_base_controller_spawner = Node(
        package='controller_manager',
        executable='spawner',
        arguments=[
            'diff_drive_base_controller',
            '--param-file',
            robot_controllers,
            ],
    )

    return LaunchDescription([
        # Launch gazebo environment
        IncludeLaunchDescription(
            PythonLaunchDescriptionSource(
                [PathJoinSubstitution([FindPackageShare('ros_gz_sim'),
                                   'launch',
                                   'gz_server.launch.py'])]),
            launch_arguments=[('world_sdf_file', 'empty.sdf'),]),
        RegisterEventHandler(
            event_handler=OnProcessExit(
                target_action=gz_spawn_entity,
                on_exit=[joint_state_broadcaster_spawner],
            )
        ),
        RegisterEventHandler(
            event_handler=OnProcessExit(
                target_action=joint_state_broadcaster_spawner,
                on_exit=[diff_drive_base_controller_spawner],
            )
        ),
        node_robot_state_publisher,
        gz_spawn_entity,
        # Launch Arguments
        DeclareLaunchArgument(
            'use_sim_time',
            default_value=use_sim_time,
            description='If true, use simulated clock'),
    ])
@Amronos Amronos added the bug Something isn't working label Nov 2, 2024
@Amronos
Copy link
Contributor Author

Amronos commented Nov 17, 2024

I tested this with a binary installation of v1.0.7 (jazzy) from the testing repository. The result is the same: using gz_sim.launch.py, the plugin is found successfully while when using gz_server.launch.py, the plugin is not found.

@Tacha-S
Copy link
Contributor

Tacha-S commented Nov 26, 2024

I encountered the same issue. Assuming it was an environment variable problem, I added the following, and it seems the loading is working correctly.

class GazeboRosPaths:
@staticmethod
def get_paths():
gazebo_model_path = []
gazebo_plugin_path = []
gazebo_media_path = []
for package_name in get_package_names():
package_share_path = get_package_share_directory(package_name)
package_file_path = os.path.join(package_share_path, PACKAGE_MANIFEST_FILENAME)
if os.path.isfile(package_file_path):
try:
package = parse_package(package_file_path)
except InvalidPackage:
continue
for export in package.exports:
if export.tagname == 'gazebo_ros':
if 'gazebo_model_path' in export.attributes:
xml_path = export.attributes['gazebo_model_path']
xml_path = xml_path.replace('${prefix}', package_share_path)
gazebo_model_path.append(xml_path)
if 'plugin_path' in export.attributes:
xml_path = export.attributes['plugin_path']
xml_path = xml_path.replace('${prefix}', package_share_path)
gazebo_plugin_path.append(xml_path)
if 'gazebo_media_path' in export.attributes:
xml_path = export.attributes['gazebo_media_path']
xml_path = xml_path.replace('${prefix}', package_share_path)
gazebo_media_path.append(xml_path)
gazebo_model_path = os.pathsep.join(gazebo_model_path + gazebo_media_path)
gazebo_plugin_path = os.pathsep.join(gazebo_plugin_path)
return gazebo_model_path, gazebo_plugin_path
def launch_gz(context, *args, **kwargs):
model_paths, plugin_paths = GazeboRosPaths.get_paths()
env = {
"GZ_SIM_SYSTEM_PLUGIN_PATH": os.pathsep.join(
[
environ.get("GZ_SIM_SYSTEM_PLUGIN_PATH", default=""),
environ.get("LD_LIBRARY_PATH", default=""),
plugin_paths,
]
),
"GZ_SIM_RESOURCE_PATH": os.pathsep.join(
[
environ.get("GZ_SIM_RESOURCE_PATH", default=""),
model_paths,
]
),
}

However, there is still another problem.
When executed as a component, the controller manager is also started in the same container, causing the controller manager's name to be identical to the container name. This leads to the following issues:

  • The namespace specified in files like ros2_control.xacro is ignored.
  • Services like controller_manager/list_controllers are prefixed with container_name/***.

@Amronos
Copy link
Contributor Author

Amronos commented Nov 29, 2024

I encountered the same issue. Assuming it was an environment variable problem, I added the following, and it seems the loading is working correctly.

@Tacha-S could you make a PR with those changes?

@Amronos Amronos mentioned this issue Dec 3, 2024
8 tasks
@github-project-automation github-project-automation bot moved this from Inbox to Done in Core development Dec 5, 2024
@mergify mergify bot mentioned this issue Dec 5, 2024
8 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants