<launch>

  <arg name="model" default="$(find wpb_home_bringup)/urdf/wpb_home.urdf"/>
  <arg name="gui" default="true" />
  <arg name="rvizconfig" default="$(find wpb_home_tutorials)/rviz/slam.rviz" />

  <param name="robot_description" command="$(find xacro)/xacro.py $(arg model)" />
  <param name="use_gui" value="$(arg gui)"/>

  <node name="joint_state_publisher" pkg="joint_state_publisher" type="joint_state_publisher">
    <rosparam file="$(find wpb_home_bringup)/config/wpb_home.yaml" command="load" />
  </node>
  <node name="robot_state_publisher" pkg="robot_state_publisher" type="state_publisher"/>
  <node name="rviz" pkg="rviz" type="rviz" args="-d $(arg rvizconfig)" required="true" />

  <node pkg="hector_mapping" type="hector_mapping" name="hector_mapping" output="screen">
  <!-- Frame names -->
  <param name="pub_map_odom_transform" value="true"/>
  <param name="map_frame" value="map" />
  <param name="base_frame" value="base_footprint" />
  <param name="odom_frame" value="base_footprint" />

  <!-- Tf use -->
  <param name="use_tf_scan_transformation" value="true"/>
  <param name="use_tf_pose_start_estimate" value="false"/>

  <!-- Map size / start point -->
  <param name="map_resolution" value="0.05"/>
  <param name="map_size" value="1024"/>
  <param name="map_start_x" value="0.5"/>
  <param name="map_start_y" value="0.5" />
  <param name="laser_z_min_value" value = "-1.0" />
  <param name="laser_z_max_value" value = "1.0" />
  <param name="map_multi_res_levels" value="2" />

  <param name="map_pub_period" value="2" />
  <param name="laser_min_dist" value="0.4" />
  <param name="laser_max_dist" value="5.5" />
  <param name="output_timing" value="false" />
  <param name="pub_map_scanmatch_transform" value="true" />
  <param name="tf_map_scanmatch_transform_frame_name" value="base_footprint" />

  <!-- Map update parameters -->
  <param name="update_factor_free" value="0.4"/>
  <param name="update_factor_occupied" value="0.7" />    
  <param name="map_update_distance_thresh" value="0.2"/>
  <param name="map_update_angle_thresh" value="0.06" />

  <!-- Advertising config --> 
  <param name="advertise_map_service" value="true"/>
  <param name="scan_subscriber_queue_size" value="5"/>
  <param name="scan_topic" value="scan"/>

  <remap from="/scanmatcher_frame" to="/base_footprint" />
  </node>

  <!--- Run Rplidar -->
  <node pkg="rplidar_ros" type="rplidarNode" name="rplidar" output="screen">
  <param name="serial_port"         type="string" value="/dev/rplidar"/>  
  <param name="serial_baudrate"     type="int"    value="115200"/>
  <param name="frame_id"            type="string" value="laser"/>
  <param name="inverted"            type="bool"   value="false"/>
  <param name="angle_compensate"    type="bool"   value="true"/>
  <remap from="scan" to="scan_raw"/>
  </node>
  
  <!-- Run lidar filter -->
  <node pkg="wpb_home_bringup" type="wpb_home_lidar_filter" name="wpb_home_lidar_filter">
    <param name="pub_topic" value="/scan"/>
  </node>

</launch>
