# Introduction to rs_driver's Parameters 


## 1 Parameter File

The parameters are defined in the file `rs_driver/src/rs_driver/driver_param.h`.

Basically, there are 3 structures: RSDriverParam, RSDecoderParam, and RSInputParam.

## 2 RSDriverParam

RSDriverParam contains RSDecoderParam and RSInputParam.

```c++
typedef struct RSDriverParam
{
  LidarType lidar_type = LidarType::RS16;  ///< Lidar type
  InputType input_type = InputType::ONLINE_LIDAR; ///< Input type
  RSInputParam input_param;
  RSDecoderParam decoder_param;
} RSDriverParam;
```

+ lidar_type - Lidar Type
  + There are two classes of Lidars: Mechanical Lidar and MEMS Lidar. Some paramters of RSDecoderParam is only for mechanical Lidars.

```c++
enum LidarType
{
  RS16 = 1,
  RS32,
  RSBP,
  RS128,
  RS80,
  RSHELIOS,
  RSROCK,
  RSM1
};
```

+ input_type - Where the Lidar packets is from.
  + ONLINE_LIDAR means from online Lidar; PCAP_FILE means from PCAP file, which is captured with 3rd party tool; RAW_PACKET is used for recording/replaying packets.

```c++
enum InputType
{
  ONLINE_LIDAR = 1,
  PCAP_FILE,
  RAW_PACKET
};
```


## 3 RSDecoderParam

RSDecoderParam specifies how rs_driver decode Lidar's packets.

```c++
typedef struct RSDecoderParam
{
  bool use_lidar_clock = false;
  bool dense_points = false;
  bool wait_for_difop = true;
  RSTransformParam transform_param;
  bool config_from_file = false;
  std::string angle_path = "";
  float min_distance = 0.2f;
  float max_distance = 200.0f;

  // The following parameters are only for mechanical Lidars.
  SplitFrameMode split_frame_mode = SplitFrameMode::SPLIT_BY_ANGLE;
  float split_angle = 0.0f;
  uint16_t num_blks_split = 1;
  float start_angle = 0.0f;
  float end_angle = 360.0f;

} RSDecoderParam;
```

The following parameters are for all Lidars。
+ use_lidar_clock - Where the point cloud's timestamp is from. From the lidar, or from rs_driver on the host? 
  + If `use_lidar_clock`=`true`，use the Lidar timestamp, else use the host one.
+ dense_points - Whether the point cloud is dense.
  + If `dense_points`=`false`, then point cloud contains NAN points, else discard them.
+ wait_for_difop - Whether wait for DIFOP Packet, before parse MSOP packets.
  + DIFOP Packet contains angle calibration parameters. If it is unavailable, the point cloud is flat.
  + If you get no point cloud, try `wait_for_difop`=`false`. It might help to locate the problem.
+ transform_param - paramters of coordinate transformation. It is only valid when the CMake option `ENABLE_TRANSFORM`=`ON`.

```c++
typedef struct RSTransformParam
{
  float x = 0.0f;      ///< unit, m
  float y = 0.0f;      ///< unit, m
  float z = 0.0f;      ///< unit, m
  float roll = 0.0f;   ///< unit, radian
  float pitch = 0.0f;  ///< unit, radian
  float yaw = 0.0f;    ///< unit, radian
} RSTransformParam;
```

+ config_from_file - Where to get Lidar config parameters. From extern files, or from DIFOP packet. Internal use only.
+ angle_path - File of angle calibration. Internal use only.
+ min_distance、max_distance - Measurement Range. Internal use only.

The following paramters are only for mechanical Lidars.
+ split_frame_mode - How to split frame.
  + `SPLIT_BY_ANGLE` is by user requested angle;`SPLIT_BY_FIXED_BLKS` is by blocks/round theologically; `SPLIT_BY_CUSTOM_BLKS` is by user requested blocks/frame. `SPLIT_BY_ANGLE` is default, and the other two values are not suggested.

```c++
enum SplitFrameMode
{
  SPLIT_BY_ANGLE = 1,
  SPLIT_BY_FIXED_BLKS,
  SPLIT_BY_CUSTOM_BLKS
};
```
+ split_angle - If `split_frame_mode`=`SPLIT_BY_ANGLE`, then `split_angle` is the requested angle to split.
+ num_blks_split - If `split_frame_mode`=`SPLIT_BY_CUSTOM_BLKS`，then `num_blks_split` is blocks/frame.

+ start_angle、end_angle - Generally, mechanical Lidars's point cloud's azimuths are in the range of [`0`, `360`]. Here you may assign a smaller range of [`start_angle`, `end_angle`).

## 4 RSInputParam

RSInputParam specifies the detail paramters of packet source.

The following parameters are for `ONLINE_LIDAR` and `PCAP_FILE`.
+ msop_port - The UDP port on the host, to receive MSOP packets.
+ difop_port - The UDP port on the host, to receive DIFOP Packets.

The following parameters are only for ONLINE_LIDAR.
+ host_address - The host's IP, to receive MSOP/DIFOP Packets
+ group_address - A multicast group to receive MSOP/DIFOP packts. rs_driver make `host_address` join it.

The following parameters are only for PCAP_FILE.
+ pcap_path - Full path of the PCAP file.
+ pcap_repeat - Whether to replay PCAP file repeatly
+ pcap_rate - rs_driver replay the PCAP file by the theological frame rate. `pcap_rate` gives a rate to it, so as to speed up or slow down.
+ use_vlan - If the PCAP file contains VLAN layer, use `use_vlan`=`true` to skip it.

```c++
typedef struct RSInputParam
{
  uint16_t msop_port = 6699;
  uint16_t difop_port = 7788;
  std::string host_address = "0.0.0.0";
  std::string group_address = "0.0.0.0";

  // The following parameters are only for PCAP_FILE
  std::string pcap_path = "";
  bool pcap_repeat = true;
  float pcap_rate = 1.0;
  bool use_vlan = false;
} RSInputParam;

```
