<launch>

  <!-- General args -->
  <arg name="use_sim_time" default="true" doc="Use simulation time when replaying rosbags with '--clock' option."/>
  <arg name="rviz" default="true" doc="Visualize results with RViz."/>
  <arg name="gps" default="false" doc="If true, use GPS data to calibrate SLAM output. Otherwise, provide calibration."/>

  <!-- LiDAR pointclouds conversions args. These are only used to generate
       approximate point-wise timestamps if 'time' field is not usable).
       These parameters should be set to the same values as ROS Velodyne driver's. -->
  <arg name="rpm" default="600." doc="Velodyne sensor spinning speed."/>
  <arg name="timestamp_first_packet" default="false" doc="If Velodyne timestamping is based on the first or last packet of each scan."/>

  <!-- Sim Time, used when replaying rosbag files (with mandatory option 'clock') -->
  <param name="/use_sim_time" value="$(arg use_sim_time)"/>

  <!-- Run Rviz-->
  <group if="$(arg rviz)">
    <node pkg="rviz" type="rviz" name="rviz" args="-d $(find lidar_slam)/params/slam.rviz"/>
  </group>
  
  <!-- Velodyne points conversion -->
  <node name="velodyne_conversion" pkg="lidar_conversions" type="velodyne_conversion_node" output="screen">
    <param name="rpm" value="$(arg rpm)"/>
    <param name="timestamp_first_packet" value="$(arg timestamp_first_packet)"/>
  </node>

  <!-- LiDAR SLAM : compute TF slam_init -> velodyne -->
  <node name="lidar_slam" pkg="lidar_slam" type="lidar_slam_node" output="screen">
    <rosparam file="$(find lidar_slam)/params/slam_config.yaml" command="load"/>
    <param name="gps/use_gps" value="$(arg gps)"/>
  </node>

  <!-- Launch GPS/UTM conversions nodes -->
  <group if="$(arg gps)">
    <include file="$(find lidar_slam)/launch/gps_conversions.launch"/>
  </group>

  <!-- Moving base coordinates systems description            tf_FROM_to_TO           X  Y  Z  rZ rY rX  FROM     TO -->
  <node pkg="tf2_ros" type="static_transform_publisher" name="tf_base_to_lidar" args="0  0  0  0  0  0 base_link velodyne"/>
  <node pkg="tf2_ros" type="static_transform_publisher" name="tf_base_to_gps"   args="0  0  0  0  0  0 base_link gps"/>

</launch>