<?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/sensors/structure_sensor.urdf.xacro"/>
  <xacro:include filename="$(find pmb2_description)/urdf/sensors/elp_rgb.urdf.xacro"/>
  
  <xacro:property name="default_calibration_path" value="$(find pmb2_description)"/>
  <xacro:property name="calibration_path" value="$(optenv pmb2_description_calibration_path ${default_calibration_path})"/>

  <!-- base/roof RGBD calibratable characteristics -->
  <!-- spec: rgbd_z, rgbd_R and rgbd_P -->
  <xacro:include filename="${calibration_path}/urdf/base/base_pmb2_calib.urdf.xacro"/>

  <!-- base RGBD characteristics -->
  <xacro:property name="base_rgbd_x" value="0.22697"/>
  <xacro:property name="base_rgbd_y" value="0.0"/>
  <xacro:property name="base_rgbd_Y" value="0.0"/>

  <!-- roof RGBD characteristics -->
  <xacro:property name="roof_rgbd_x" value="0.18473"/>
  <xacro:property name="roof_rgbd_y" value="0.0"/>
  <xacro:property name="roof_rgbd_Y" value="0.0"/>

  <!-- RGB characteristics -->
  <xacro:property name="rgb_x" value="0.18752"/>
  <xacro:property name="rgb_y" value="0.0"/>
  <xacro:property name="rgb_z" value="0.3301"/>
  <xacro:property name="rgb_R" value="0.0"/>
  <xacro:property name="rgb_P" value="15.0"/>
  <xacro:property name="rgb_Y" value="0.0   "/>

  <!-- RGBD base -->
  <xacro:structure_sensor name="base_rgbd_camera" parent="base">
    <!-- Pose of sensor frame wrt to base -->
    <origin 
      xyz="${base_rgbd_x} ${base_rgbd_y} ${base_rgbd_z}" 
      rpy="${base_rgbd_R * deg_to_rad} ${base_rgbd_P * deg_to_rad} ${base_rgbd_Y * deg_to_rad}"/>
    <!-- Pose of optical frame wrt to sensor -->
    <origin 
      xyz="0 0 0" 
      rpy="${-90 * deg_to_rad} 0 ${-90 * deg_to_rad}"/>
  </xacro:structure_sensor>

  <!-- RGBD roof -->
  <xacro:structure_sensor name="roof_rgbd_camera" parent="base">
    <!-- Pose of sensor frame wrt to base -->
    <origin 
      xyz="${roof_rgbd_x} ${roof_rgbd_y} ${roof_rgbd_z}" 
      rpy="${roof_rgbd_R * deg_to_rad} ${roof_rgbd_P * deg_to_rad} ${roof_rgbd_Y * deg_to_rad}"/>
    <!-- Pose of optical frame wrt to sensor -->
    <origin 
      xyz="0 0 0" 
      rpy="${-90 * deg_to_rad} 0 ${-90 * deg_to_rad}"/>
  </xacro:structure_sensor>

  <!-- RGB -->
  <xacro:elp_rgb name="rgb_camera" parent="base">
    <!-- Pose of sensor frame wrt to base -->
    <origin 
      xyz="${rgb_x} ${rgb_y} ${rgb_z}" 
      rpy="${rgb_R * deg_to_rad} ${rgb_P * deg_to_rad} ${rgb_Y * deg_to_rad}"/>
    <!-- Pose of optical frame wrt to sensor -->
    <origin 
      xyz="0 0 0" 
      rpy="${-90 * deg_to_rad} 0 ${-90 * deg_to_rad}"/>
  </xacro:elp_rgb>

  <!-- RGBD Laser Link -->
  <joint name="rgbd_laser_joint" type="fixed">
      <parent link="base_footprint"/>
      <child link="rgbd_laser_link"/>
      <origin xyz="-0.9 0 0" rpy="0 0 0" />
  </joint>
  <link name="rgbd_laser_link">
      <inertial>
          <origin xyz="0 0 0" rpy="0 0 0"/>
          <mass value="0.0001" />
          <inertia ixx="0.0001"  ixy="0"  ixz="0" iyy="0.0001" iyz="0" izz="0.0001" />
      </inertial>
  </link>

</robot>

