[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
[![Build](https://github.com/SMBU-PolarBear-Robotics-Team/hik_camera_ros2_driver/actions/workflows/ci.yml/badge.svg)](https://github.com/SMBU-PolarBear-Robotics-Team/hik_camera_ros2_driver/actions/workflows/ci.yml)

# hik_camera_ros2_driver

## Overview

The `hik_camera_ros2_driver` package provides a ROS 2 driver for controlling and interfacing with Hikvision cameras. It supports functionalities such as camera initialization, parameter configuration, and image publishing. This package is intended for applications requiring reliable and configurable image data acquisition in a ROS 2 environment.

### Executables

The package includes the `hik_camera_node`, which manages the camera and publishes image data along with camera information to ROS 2 topics.

### Subscribed Topics

None.

### Published Topics

- `<camera_topic>` (sensor_msgs/msg/Image)
  - The image data captured by the Hikvision camera.

- `<camera_topic>/camera_info` (sensor_msgs/msg/CameraInfo)
  - Camera calibration information.

### Parameters

- `exposure_auto` (bool, default: `false`)
  - Enable continuous auto exposure. When `true`, the camera controls exposure automatically and `exposure_time` is ignored.

- `exposure_time` (double, default: `5000`)
  - Manual exposure time in microseconds. Used only when `exposure_auto` is `false`.

- `exposure_auto_target_brightness` (int, default: `128`, range: `0-255`)
  - Target brightness for auto exposure. Active only when `exposure_auto` is `true`. Can be changed at runtime:
    ```bash
    ros2 param set /hik_camera_ros2_driver exposure_auto_target_brightness 100
    ```

- `exposure_auto_min` (double, default: `100.0`)
  - Auto exposure lower limit in microseconds. Active only when `exposure_auto` is `true`. Can be changed at runtime.

- `exposure_auto_max` (double, default: `10000.0`)
  - Auto exposure upper limit in microseconds. Active only when `exposure_auto` is `true`. Can be changed at runtime.

- `gain` (double)
  - Manual gain. Auto gain is always disabled. Can be changed at runtime:
    ```bash
    ros2 param set /hik_camera_ros2_driver gain 2.0
    ```

- `acquisition_frame_rate` (double, default: `165`)
  - The acquisition frame rate in hz for the camera.

- `pixel_format` (string, default: `RGB8Packed`)
  - The pixel format for the image data. Supported values: `Mono8`, `Mono10`, `Mono12`, `RGB8Packed`, `BGR8Packed`, `YUV422_YUYV_Packed`, `YUV422Packed`, `BayerRG8`, `BayerRG10`, `BayerRG10Packed`, `BayerRG12`, `BayerRG12Packed`.

- `adc_bit_depth` (string, default: `Bits_8`)
  - The ADC bit depth for the camera. Supported values: `Bits_8`, `Bits_12`.

- `use_sensor_data_qos` (bool, default: true)
  - Whether to use the `sensor_data` QoS profile for image topic publication.

- `camera_name` (string, default: `camera`)
  - The name of the camera for identification purposes.

- `frame_id` (string, default: `<camera_name>_optical_frame`)
  - The frame_id assigned to the published image data.

- `camera_topic` (string, default: `<camera_name>/image`)
  - The topic name for publishing image and info data.

- `camera_info_url` (string, default: `package://hik_camera_ros2_driver/config/camera_info.yaml`)
  - The URL for the camera calibration information file.

- `trigger_enable` (bool, default: `false`)
  - Enable hardware trigger mode (LINE0). When `true`, frame rate is controlled by the trigger signal.

- `use_trigger_timestamp` (bool, default: `false`)
  - Use the shared memory timestamp written by the LiDAR driver instead of system time.

- `serial_number` (string, default: `""`)
  - Select a specific camera by serial number. If empty, the first detected camera is used.

- `enable_interval_log` (bool, default: `false`)
  - Print per-frame timestamp interval logs (`[TS]`). Also prints a rolling summary every 10 frames (avg / min / max / jitter). Can be toggled at runtime:
    ```bash
    ros2 param set /hik_camera_ros2_driver enable_interval_log true
    ```

### Usage

#### Installation

To use this package, build it from source or include it in your ROS 2 workspace. Ensure that all dependencies are installed. You **don't** need to install the Hikvision camera SDK and include its libraries in your environment.

```bash
mkdir -p ~/ros_ws/src
cd ~/ros_ws/src
```

```bash
git clone https://github.com/SMBU-PolarBear-Robotics-Team/hik_camera_ros2_driver.git
```

```bash
cd ~/ros_ws
rosdep install -r --from-paths src --ignore-src --rosdistro $ROS_DISTRO -y
```

```bash
colcon build --symlink-install --cmake-args -DCMAKE_BUILD_TYPE=Release
```

#### Run

You can use the provided launch file for starting the camera node with default or custom parameters:

```bash
ros2 launch hik_camera_ros2_driver hik_camera_launch.py
```
