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

	<!-- parameters -->
	<xacro:arg name="name" default="ur_manipulator"/>
	<!-- import main macro -->
	<xacro:include filename="$(find ur_description)/urdf/ur_macro.xacro"/>
	<xacro:include filename="$(find robotiq_2f_description)/urdf/robotiq_2f_140_macro.urdf.xacro" />

	<!-- possible 'ur_type' values: ur3, ur3e, ur5, ur5e, ur10, ur10e, ur16e, ur20 -->
	<!-- the default value should raise an error in case this was called without defining the type -->
	<xacro:arg name="ur_type" default="ur3e"/>

	<!-- parameters -->
	<xacro:arg name="tf_prefix" default="" />
	<xacro:arg name="joint_limit_params" default="$(find ur_description)/config/$(arg ur_type)/joint_limits.yaml"/>
	<xacro:arg name="kinematics_params" default="$(find ur_description)/config/$(arg ur_type)/default_kinematics.yaml"/>
	<xacro:arg name="physical_params" default="$(find ur_description)/config/$(arg ur_type)/physical_parameters.yaml"/>
	<xacro:arg name="visual_params" default="$(find ur_description)/config/$(arg ur_type)/visual_parameters.yaml"/>
	<xacro:arg name="transmission_hw_interface" default=""/>
	<xacro:arg name="safety_limits" default="false"/>
	<xacro:arg name="safety_pos_margin" default="0.15"/>
	<xacro:arg name="safety_k_position" default="20"/>
	<!-- ros2_control related parameters -->
	<xacro:arg name="headless_mode" default="false" />
	<xacro:arg name="robot_ip" default="0.0.0.0" />
	<xacro:arg name="script_filename" default=""/>
	<xacro:arg name="output_recipe_filename" default=""/>
	<xacro:arg name="input_recipe_filename" default=""/>
	<xacro:arg name="reverse_ip" default="0.0.0.0"/>
	<xacro:arg name="script_command_port" default="50004"/>
	<xacro:arg name="reverse_port" default="50001"/>
	<xacro:arg name="script_sender_port" default="50002"/>
	<xacro:arg name="trajectory_port" default="50003"/>
	<!--   tool communication related parameters-->
	<xacro:arg name="use_tool_communication" default="true" />
	<xacro:arg name="tool_voltage" default="24" />
	<xacro:arg name="tool_tcp_port" default="63352" />

	<!-- Simulation parameters -->
	<xacro:arg name="use_fake_hardware" default="false" />
	<xacro:arg name="fake_sensor_commands" default="false" />
	<xacro:arg name="sim_gazebo" default="false" />
	<xacro:arg name="sim_ignition" default="false" />
	<xacro:arg name="simulation_controllers" default="" />

	<!-- initial position for simulations (Fake Hardware, Gazebo, Ignition) -->
	<xacro:arg name="initial_positions_file" default="$(find ur_robotiq_moveit_config)/config/initial_positions.yaml"/>

	<!-- convert to property to use substitution in function -->
	<xacro:property name="initial_positions_file" default="$(arg initial_positions_file)"/>	

 	<link name="world"/>

	<xacro:ur_robot
     name="$(arg name)"
     tf_prefix="$(arg tf_prefix)"
     parent="world"
     joint_limits_parameters_file="$(arg joint_limit_params)"
     kinematics_parameters_file="$(arg kinematics_params)"
     physical_parameters_file="$(arg physical_params)"
     visual_parameters_file="$(arg visual_params)"
     transmission_hw_interface="$(arg transmission_hw_interface)"
     safety_limits="$(arg safety_limits)"
     safety_pos_margin="$(arg safety_pos_margin)"
     safety_k_position="$(arg safety_k_position)"
     use_fake_hardware="$(arg use_fake_hardware)"
     fake_sensor_commands="$(arg fake_sensor_commands)"
     sim_gazebo="$(arg sim_gazebo)"
     sim_ignition="$(arg sim_ignition)"
     headless_mode="$(arg headless_mode)"
     initial_positions="${xacro.load_yaml(initial_positions_file)}"
     use_tool_communication="$(arg use_tool_communication)"
     tool_voltage="$(arg tool_voltage)"
     tool_tcp_port="$(arg tool_tcp_port)"
     robot_ip="$(arg robot_ip)"
     script_filename="$(arg script_filename)"
     output_recipe_filename="$(arg output_recipe_filename)"
     input_recipe_filename="$(arg input_recipe_filename)"
     reverse_ip="$(arg reverse_ip)"
     script_command_port="$(arg script_command_port)"
     reverse_port="$(arg reverse_port)"
     script_sender_port="$(arg script_sender_port)"
     trajectory_port="$(arg trajectory_port)"
     >
    <origin xyz="0 0 0" rpy="0 0 0" />          <!-- position robot in the world -->
    </xacro:ur_robot>

   <xacro:robotiq_gripper name="$(arg tf_prefix)gripper"
    prefix="$(arg tf_prefix)"
    parent="$(arg tf_prefix)tool0"
    use_fake_hardware="$(arg use_fake_hardware)"
    robot_ip="$(arg robot_ip)"
    robot_port="$(arg tool_tcp_port)"
    >
    <origin xyz="0 0 0" rpy="0 0 0" />
    </xacro:robotiq_gripper>

</robot>
