"""
robot_description.launch.py — Publish SaltyBot robot description + static TF

Runs robot_state_publisher with the saltybot.urdf.xacro model.

Publishes:
  /robot_description   (std_msgs/String)  — full compiled URDF
  /tf_static           (tf2_msgs/TFMessage) — all fixed joints:
      base_footprint → base_link
      base_link → imu_link
      base_link → stem_link
      base_link → sensor_head_link
      sensor_head_link → laser
      sensor_head_link → camera_link
      sensor_head_link → camera_{front,left,rear,right}_link

Continuous joints (wheel_left_link_joint, wheel_right_link_joint) are
published only when /joint_states arrive from the motor controller.

Typical usage:
  ros2 launch saltybot_description robot_description.launch.py

Desktop visualisation (publishes dummy /joint_states for wheels):
  ros2 run joint_state_publisher_gui joint_state_publisher_gui

Note: When this launch file is running, the static TF publishers in
saltybot_cameras/launch/camera_tf.launch.py and the laser/camera TF
nodes in saltybot_bringup/launch/sensors.launch.py become redundant.
Remove or disable them to avoid TF tree conflicts.
"""

import os
import xacro
from launch import LaunchDescription
from launch_ros.actions import Node
from ament_index_python.packages import get_package_share_directory


def generate_launch_description():
    pkg_share = get_package_share_directory('saltybot_description')
    urdf_file = os.path.join(pkg_share, 'urdf', 'saltybot.urdf.xacro')

    # Compile xacro → URDF XML string at launch time
    robot_description_content = xacro.process_file(urdf_file).toxml()

    robot_state_publisher = Node(
        package='robot_state_publisher',
        executable='robot_state_publisher',
        name='robot_state_publisher',
        output='screen',
        parameters=[{
            'robot_description': robot_description_content,
            'use_sim_time': False,
        }],
    )

    return LaunchDescription([
        robot_state_publisher,
    ])
