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

  <!-- xarm_gripper -->
  <xacro:include filename="$(find xarm_description)/urdf/gripper/xarm_gripper.ros2_control.xacro" />
  <xacro:include filename="$(find xarm_description)/urdf/gripper/xarm_gripper.urdf.xacro" />
  <xacro:include filename="$(find xarm_description)/urdf/gripper/xarm_gripper.transmission.xacro" />
  <xacro:include filename="$(find xarm_description)/urdf/gripper/xarm_gripper.gazebo.xacro" />

  <xacro:macro name="xarm_gripper_macro" params="prefix:='' attach_to:='' ns:='xarm' xyz:='0 0 0' rpy:='0 0 0' effort_control:='false' velocity_control:='false' 
    load_gazebo_plugin:='false' ros2_control_plugin:='uf_robot_hardware/UFRobotFakeSystemHardware' ros2_control_params:='' ">

    <!-- gazebo_plugin -->
    <xacro:if value="${load_gazebo_plugin}">
      <xacro:include filename="$(find xarm_description)/urdf/common/common.gazebo.xacro" />
      <xacro:gazebo_ros_control_plugin prefix="${prefix}" ros2_control_params="${ros2_control_params}"/>
    </xacro:if>

    <xacro:if value="${ros2_control_plugin != 'uf_robot_hardware/UFRobotSystemHardware'}">
      <xacro:xarm_gripper_ros2_control prefix="${prefix}" ros2_control_plugin="${ros2_control_plugin}" />
    </xacro:if>

    <xacro:xarm_gripper_urdf prefix="${prefix}" attach_to="${attach_to}" xyz="${xyz}" rpy="${rpy}" />

    <xacro:xarm_gripper_transmission prefix="${prefix}" hard_interface="${'EffortJointInterface' if effort_control else 'VelocityJointInterface' if velocity_control else 'PositionJointInterface'}" />

    <xacro:xarm_gripper_gazebo prefix="${prefix}" />

    <!-- mimic_joint_plugin has to be installed: -->
    <xacro:mimic_joint_plugin_gazebo name_prefix="${prefix}left_finger_joint"
      following_joint="${prefix}drive_joint" mimic_joint="${prefix}left_finger_joint"
      has_pid="true" multiplier="1.0" max_effort="10.0" />

    <xacro:mimic_joint_plugin_gazebo name_prefix="${prefix}left_inner_knuckle_joint"
      following_joint="${prefix}drive_joint" mimic_joint="${prefix}left_inner_knuckle_joint"
      has_pid="true" multiplier="1.0" max_effort="10.0" />

    <xacro:mimic_joint_plugin_gazebo name_prefix="${prefix}right_outer_knuckle_joint"
      following_joint="${prefix}drive_joint" mimic_joint="${prefix}right_outer_knuckle_joint"
      has_pid="true" multiplier="1.0" max_effort="10.0" />

    <xacro:mimic_joint_plugin_gazebo name_prefix="${prefix}right_finger_joint"
      following_joint="${prefix}drive_joint" mimic_joint="${prefix}right_finger_joint"
      has_pid="true" multiplier="1.0" max_effort="10.0" />

    <xacro:mimic_joint_plugin_gazebo name_prefix="${prefix}right_inner_knuckle_joint"
      following_joint="${prefix}drive_joint" mimic_joint="${prefix}right_inner_knuckle_joint"
      has_pid="true" multiplier="1.0" max_effort="10.0" />

  </xacro:macro>
</robot>
