<?xml version="1.0"?>
<!--

  Copyright (c) 2021 PAL Robotics S.L. All rights reserved.
  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at
      http://www.apache.org/licenses/LICENSE-2.0
  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->

<robot xmlns:xacro="http://ros.org/wiki/xacro">

  <xacro:include filename="$(find pmb2_description)/urdf/deg_to_rad.xacro"/>

  <xacro:include filename="$(find pmb2_description)/urdf/sensors/ir_emitter.urdf.xacro"/>

  <xacro:macro name="dock" params="name">

    <!-- Dock -->
    <link name="${name}_link">
      <inertial>
        <origin xyz="0.0 0.0 0.05" rpy="0 0 0" />
        <mass value="0.100" />
        <inertia ixx="0.1" ixy="0" ixz="0" iyy="0.1" iyz="0" izz="0.1" />
      </inertial>
      <visual>
        <origin xyz="0 0 0" rpy="0 0 0" />
        <geometry>
          <mesh filename="package://pmb2_description/meshes/dock/dock.stl" />
          <!--mesh filename="package://pmb2_description/meshes/dock/dock.dae" /-->
        </geometry>
        <material name="LightGrey" />
      </visual>
      <collision>
        <origin xyz="0 0 0" rpy="0 0 0" />
        <geometry>
          <mesh filename="package://pmb2_description/meshes/dock/dock_collision.stl" />
        </geometry>
        <material name="LightGrey" />
      </collision>
    </link>

    <!-- Dock footprint -->
    <link name="${name}_footprint">
      <collision>
        <origin xyz="0 0 0.05" rpy="0 0 0" />
        <geometry>
          <box size="0.001 0.001 0.001" />
        </geometry>
      </collision>
    </link>

    <joint name="${name}_footprint_joint" type="fixed">
      <origin xyz="0 0 0" rpy="0 0 0" />
      <child link="${name}_link" />
      <parent link="${name}_footprint"/>
    </joint>

    <!-- IR emitter -->
    <xacro:ir_emitter name="${name}_ir_emitter_01" parent="${name}" code="0" range_min="0.0" range_max="0.75" fov="0.5">
      <origin xyz="0.17131 0.0 0.280" rpy="0.0 0.0 0.0" />
    </xacro:ir_emitter>

    <!-- IR emitter -->
    <xacro:ir_emitter name="${name}_ir_emitter_02" parent="${name}" code="0" range_min="0.0" range_max="0.75" fov="0.5">
      <origin xyz="0.16919 0.14919 0.280" rpy="0.0 0.0 0.349" />
    </xacro:ir_emitter>

    <!-- IR emitter -->
    <xacro:ir_emitter name="${name}_ir_emitter_03" parent="${name}" code="0" range_min="0.0" range_max="0.75" fov="0.5">
      <origin xyz="0.16919 -0.14919 0.280" rpy="0.0 0.0 -0.349" />
    </xacro:ir_emitter>

  </xacro:macro>

</robot>
