<launch>
    <!-- article about camera setup: https://clover.coex.tech/camera_setup -->

    <arg name="direction_z" default="down"/> <!-- direction the camera points: down, up -->
    <arg name="direction_y" default="backward"/> <!-- direction the camera cable points: backward, forward -->

    <node if="$(eval direction_z == 'down' and direction_y == 'backward')" pkg="tf2_ros" type="static_transform_publisher" name="main_camera_frame" args="0.05 0 -0.07 -1.5707963 0 3.1415926 base_link main_camera_optical"/>
    <node if="$(eval direction_z == 'down' and direction_y == 'forward')" pkg="tf2_ros" type="static_transform_publisher" name="main_camera_frame" args="0.05 0 -0.07 1.5707963 0 3.1415926 base_link main_camera_optical"/>
    <node if="$(eval direction_z == 'up' and direction_y == 'backward')" pkg="tf2_ros" type="static_transform_publisher" name="main_camera_frame" args="0.05 0 0.07 1.5707963 0 0 base_link main_camera_optical"/>
    <node if="$(eval direction_z == 'up' and direction_y == 'forward')" pkg="tf2_ros" type="static_transform_publisher" name="main_camera_frame" args="0.05 0 0.07 -1.5707963 0 0 base_link main_camera_optical"/>

    <!-- Template for custom camera orientation -->
    <!-- Camera position and orientation are represented by base_link -> main_camera_optical transform -->
    <!-- static_transform_publisher arguments: x y z yaw pitch roll frame_id child_frame_id -->
    <!-- <node pkg="tf2_ros" type="static_transform_publisher" name="main_camera_frame" args="0.05 0 -0.07 -1.5707963 0 3.1415926 base_link main_camera_optical"/> -->

    <!-- camera node -->
    <node pkg="nodelet" type="nodelet" name="main_camera" args="load cv_camera/CvCameraNodelet nodelet_manager" clear_params="true">
        <param name="device_path" value="/dev/video0"/> <!-- v4l2 device -->
        <param name="frame_id" value="main_camera_optical"/>
        <param name="camera_info_url" value="file://$(find clover)/camera_info/calibration.yaml"/>

        <param name="rate" value="100"/> <!-- poll rate -->
        <param name="cv_cap_prop_fps" value="40"/> <!-- camera FPS -->
        <param name="capture_delay" value="0.02"/> <!-- approximate delay on frame retrieving -->
        <param name="rescale_camera_info" value="true"/> <!-- automatically rescale camera calibration info -->

        <!-- camera resolution -->
        <param name="image_width" value="320"/>
        <param name="image_height" value="240"/>
    </node>

    <!-- camera visualization markers -->
    <node pkg="clover" type="camera_markers" ns="main_camera" name="main_camera_markers">
        <param name="scale" value="3.0"/>
    </node>
</launch>
