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 remap option to controller manager #442

Merged
merged 2 commits into from
Jan 21, 2025

Conversation

Tacha-S
Copy link
Contributor

@Tacha-S Tacha-S commented Nov 29, 2024

I made it possible to correctly set the node name of the controller_manager when launching gz_ros2_control as a composable node.

@Tacha-S Tacha-S requested a review from ahcorde as a code owner November 29, 2024 01:46
@Amronos
Copy link
Contributor

Amronos commented Jan 19, 2025

Any updates on this PR?

@christophfroehlich
Copy link
Contributor

@Amronos can you please test it and leave a review here? I don't have a working example of setting this up, maybe someone can provide one for gz_ros2_control_demos if this makes sense?

@christophfroehlich
Copy link
Contributor

@Mergifyio backport rolling

Copy link
Contributor

mergify bot commented Jan 19, 2025

backport rolling

✅ Backports have been created

@Amronos
Copy link
Contributor

Amronos commented Jan 20, 2025

This PR makes gz_ros2_control work for me when launching Gazebo as a composable node.
Note to anyone else testing: gazebosim/ros_gz#659 is required (I don't think it has been synced to Jazzy or Rolling yet).

@christophfroehlich I will try making a PR in a few days to modify the demos to use composable nodes, till then the below launch file can be used for testing:

from launch import LaunchDescription
from launch.actions import (
    DeclareLaunchArgument,
    ExecuteProcess,
    OpaqueFunction,
    RegisterEventHandler,
)
from launch.event_handlers import OnProcessExit
from launch.substitutions import (
    Command,
    FindExecutable,
    LaunchConfiguration,
    PathJoinSubstitution,
)
from launch_ros.actions import Node
from launch_ros.substitutions import FindPackageShare
from ros_gz_sim.actions import GzServer


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

    def robot_state_publisher(context):
        performed_description_format = LaunchConfiguration(
            "description_format"
        ).perform(context)
        # Get URDF or SDF via xacro
        robot_description_content = Command(
            [
                PathJoinSubstitution([FindExecutable(name="xacro")]),
                " ",
                PathJoinSubstitution(
                    [
                        FindPackageShare("gz_ros2_control_demos"),
                        performed_description_format,
                        f"test_diff_drive.xacro.{performed_description_format}",
                    ]
                ),
            ]
        )
        robot_description = {"robot_description": robot_description_content}
        node_robot_state_publisher = Node(
            package="robot_state_publisher",
            executable="robot_state_publisher",
            output="screen",
            parameters=[robot_description],
        )
        return [node_robot_state_publisher]

    robot_controllers = PathJoinSubstitution(
        [
            FindPackageShare("gz_ros2_control_demos"),
            "config",
            "diff_drive_controller.yaml",
        ]
    )

    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,
        ],
    )

    # Bridge
    bridge = Node(
        package="ros_gz_bridge",
        executable="parameter_bridge",
        arguments=["/clock@rosgraph_msgs/msg/Clock[gz.msgs.Clock"],
        output="screen",
    )

    ld = LaunchDescription(
        [
            # Launch gazebo environment
            GzServer(
                world_sdf_file="empty.sdf",
                use_composition="True",
                create_own_container="True",
                container_name="ros_gz_container",
            ),
            ExecuteProcess(cmd=["gz", "sim", "-g"]),
            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],
                )
            ),
            bridge,
            gz_spawn_entity,
            # Launch Arguments
            DeclareLaunchArgument(
                "use_sim_time",
                default_value=use_sim_time,
                description="If true, use simulated clock",
            ),
            DeclareLaunchArgument(
                "description_format",
                default_value="urdf",
                description="Robot description format to use, urdf or sdf",
            ),
        ]
    )
    ld.add_action(OpaqueFunction(function=robot_state_publisher))
    return ld

@Tacha-S
Copy link
Contributor Author

Tacha-S commented Jan 21, 2025

Thank you for testing.
I think the testing method is fine as it is.

@ahcorde ahcorde merged commit 0a44a08 into ros-controls:jazzy Jan 21, 2025
1 check passed
@ahcorde
Copy link
Collaborator

ahcorde commented Jan 21, 2025

do we need to forward port this to rolling ? or backport to humble?

mergify bot pushed a commit that referenced this pull request Jan 21, 2025
Co-authored-by: Christoph Fröhlich <[email protected]>
(cherry picked from commit 0a44a08)
ahcorde pushed a commit that referenced this pull request Jan 21, 2025
Co-authored-by: Christoph Fröhlich <[email protected]>
(cherry picked from commit 0a44a08)

Co-authored-by: Tatsuro Sakaguchi <[email protected]>
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