<?xml version="1.0"?>
<robot xmlns:xacro="http://ros.org/wiki/xacro" name="lite6" >
  <xacro:macro name="lite6_robot" params="prefix:='' namespace:='xarm' limited:='false' effort_control:='false' 
    velocity_control:='false' attach_to:='world' xyz:='0 0 0' rpy:='0 0 0' load_gazebo_plugin:='false' 
    ros2_control_plugin:='uf_robot_hardware/UFRobotSystemHardware' ros2_control_params:='' add_gripper:='false' 
    robot_ip:='' report_type:='normal' baud_checkset:='true' default_gripper_baud:=2000000 ">

    <!-- include lite6 relative macros: -->
    <xacro:include filename="$(find custom_xarm_description)/urdf/lite6/lite6.ros2_control.xacro" />
    <xacro:include filename="$(find custom_xarm_description)/urdf/lite6/lite6.urdf.xacro" />
    <xacro:include filename="$(find custom_xarm_description)/urdf/lite6/lite6.transmission.xacro" />
    <xacro:include filename="$(find custom_xarm_description)/urdf/lite6/lite6.gazebo.xacro" />

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

    <!-- add one world link if no 'attach_to' specified  -->
    <xacro:if value="${attach_to == 'world'}">
      <link name="world" />
    </xacro:if>

    <joint name="${prefix}world_joint" type="fixed">
      <parent link="${attach_to}" />
      <child link = "${prefix}link_base" />
      <origin xyz="${xyz}" rpy="${rpy}" />
    </joint>

    <xacro:if value="${limited}">
      <xacro:lite6_ros2_control prefix="${prefix}"
        velocity_control="${velocity_control}"
        ros2_control_plugin="${ros2_control_plugin}"
        hw_ns="${namespace}" add_gripper="${add_gripper}"
        robot_ip="${robot_ip}" report_type="${report_type}"
        baud_checkset="${baud_checkset}" default_gripper_baud="${default_gripper_baud}"
        joint1_lower_limit="${-pi}"   joint1_upper_limit="${pi}"
        joint2_lower_limit="${-2.61799}"  joint2_upper_limit="${2.61799}"
        joint3_lower_limit="${-0.061087}" joint3_upper_limit="${5.235988}"
        joint4_lower_limit="${-pi}"   joint4_upper_limit="${pi}"
        joint5_lower_limit="${-2.1642}"   joint5_upper_limit="${2.1642}"
        joint6_lower_limit="${-pi}"   joint6_upper_limit="${pi}"/>
      <xacro:lite6_urdf prefix="${prefix}"
        joint1_lower_limit="${-pi}"   joint1_upper_limit="${pi}"
        joint2_lower_limit="${-2.61799}"  joint2_upper_limit="${2.61799}"
        joint3_lower_limit="${-0.061087}" joint3_upper_limit="${5.235988}"
        joint4_lower_limit="${-pi}"   joint4_upper_limit="${pi}"
        joint5_lower_limit="${-2.1642}"   joint5_upper_limit="${2.1642}"
        joint6_lower_limit="${-pi}"   joint6_upper_limit="${pi}"/>
    </xacro:if>
    <xacro:unless value="${limited}">
      <xacro:lite6_ros2_control prefix="${prefix}" velocity_control="${velocity_control}"
        ros2_control_plugin="${ros2_control_plugin}"
        hw_ns="${namespace}" add_gripper="${add_gripper}"
        robot_ip="${robot_ip}" report_type="${report_type}"
        baud_checkset="${baud_checkset}" default_gripper_baud="${default_gripper_baud}" />
      <xacro:lite6_urdf prefix="${prefix}"/>
    </xacro:unless>

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

  </xacro:macro>

</robot>
