UniversalRobots / Universal_Robots_ROS2_Description

ROS2 URDF description for Universal Robots
BSD 3-Clause "New" or "Revised" License
133 stars 111 forks source link

Support custom ROS2 `system_interfaces` #34

Closed stefanscherzinger closed 11 months ago

stefanscherzinger commented 2 years ago

Goal

By setting the use_custom_simulator parameter, users can specify their own ros2_control and hardware tags inside their robot description.

Motivation

This allows users to implement their own simulators with custom system_interfaces. I came across this necessity while implementing a MuJoCo-based system_interface. I couldn't find a way to do that with the current choice of simulators inside the xacro macros.

Example usage

Here's a use case with a custom UR5e:

<?xml version="1.0"?>
<robot name="robot" xmlns:xacro="http://ros.org/wiki/xacro">

        <!-- Parameters are passed to the includes -->
        <xacro:arg name="name" default="ur5e"/>
        <xacro:arg name="ur_type" default="ur5e"/>
        <xacro:arg name="use_custom_simulator" default="true"/>
        <xacro:arg name="prefix" default=""/>

        <!-- Includes -->
        <xacro:include filename="$(find ur_description)/urdf/ur.urdf.xacro"/>
        <xacro:include filename="$(find my_example_project)/urdf/joint_interface.xacro"/>

        <!-- The robot is connected to world by default -->

        <!-- We add our own MuJoCo-based simulator -->
        <ros2_control name="ur5e" type="system">
                <xacro:joint_interface name="shoulder_pan_joint" p="1000" d="100"/>
                <xacro:joint_interface name="shoulder_lift_joint" p="1000" d="100"/>
                <xacro:joint_interface name="elbow_joint" p="1000" d="50"/>
                <xacro:joint_interface name="wrist_1_joint" p="500" d="10"/>
                <xacro:joint_interface name="wrist_2_joint" p="50" d="1"/>
                <xacro:joint_interface name="wrist_3_joint" p="50" d="0.01"/>
                <hardware>
                        <plugin>my_example_project/Simulator</plugin>
                        <param name="mujoco_model">$(arg mujoco_model)</param>
                        <param name="mesh_directory">$(arg mesh_directory)</param>
                </hardware>
        </ros2_control>

</robot>

And here's the joint macro:

<?xml version="1.0"?>
<robot xmlns:xacro="http://www.ros.org/wiki/xacro">

        <!-- Individual joint. -->
        <xacro:macro name="joint_interface" params="name p d">
                <joint name="${name}">
                        <param name="p">${p}</param>
                        <param name="d">${d}</param>
                        <command_interface name="position"/>
                        <command_interface name="velocity"/>
                        <command_interface name="effort"/>
                        <state_interface name="position"/>
                        <state_interface name="velocity"/>
                        <state_interface name="effort"/>
                </joint>
        </xacro:macro>

</robot>
fmauch commented 2 years ago

I like the idea in general, but implementation-wise I think we can improve this. I haven't yet found a full solution, but Id prefer something that includes the correct files depending on the use case.

Ideally, the implementation-specific parameters for the simulator would live inside their respective repositories.

destogl commented 2 years ago

We could here work with strings for plugins and objects for parameters, similar how origin block is provided.

fmauch commented 11 months ago

@stefanscherzinger #114 (and the discussion there) might be relevant in this context, as well.

fmauch commented 11 months ago

Closing this in favor of #114 and #121