ROS MelodicでFLIRやPOINTGRAYのカメラを使う方法

# はじめに
FLIRなどの特殊なカメラを動かす。ドライバのインストールなどでつまずいたり下ので備忘録として残す。

# 環境
・　ubuntu18.04
・　ros melodic

## カメラの用意
まず一般の誤家庭にあるFLIR (BFS=U3−13Y3C-C)を用意します．
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2687692/ec22cd47-fd56-6129-e090-979f148e071c.png)


## Spinnaker SDKのインストール
https://www.flir.jp/products/spinnaker-sdk/

より Spinnaker Linuxをダウンロードする。ダウンロードしたらファイルを解凍し、以下コマンドを実行。
```bash:terminal
cd spinnaker-2.7.0.128-amd64/
./install_spinnaker.sh 
``` 
実行すると色々聞かれるのでとりあえず全部YESにする。

途中
```bash:terminal
This script will assist users in configuring their udev rules to allow
access to USB devices. The script will create a udev rule which will
add FLIR USB devices to a group called flirimaging. The user may also
choose to restart the udev daemon. All of this can be done manually as well.

Adding new members to usergroup flirimaging...
Current members of flirimaging group: usr
To add a new member please enter username (or hit Enter to continue):
$ 

``` 
と聞かれるので、user名を記入
```bash:terminal
This script will assist users in configuring their udev rules to allow
access to USB devices. The script will create a udev rule which will
add FLIR USB devices to a group called flirimaging. The user may also
choose to restart the udev daemon. All of this can be done manually as well.

Adding new members to usergroup flirimaging...
Current members of flirimaging group: usr
To add a new member please enter username (or hit Enter to continue):
$ 　user_name(任意の名前)
``` 
これを入れえ損なうとカメラ動かないので注意！！！！

あとはrebootして、動作をチェック！

## 動作確認
Spinnaker SDKを実行して確認！

![Screenshot from 2022-10-12 15-20-25.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2687692/a8f385a4-e934-d9cb-9eb4-9b7202b3a0b0.png)

このときカメラのS/Nシリアルナンバーを確認（あとで使う）！！

## ROSパッケージをインストール

http://wiki.ros.org/spinnaker_sdk_camera_driver

https://github.com/neufieldrobotics/spinnaker_sdk_camera_driver

まずパッケージをインストール

```bash:terminal
cd catkin_ws/src/
git clone https://github.com/neufieldrobotics/spinnaker_sdk_camera_driver.git
Cloning into 'spinnaker_sdk_camera_driver'...
cd ..
catkin b
``` 

インストールしたらパラメータを変更
```bash:~/catkin_ws/src/spinnaker_sdk_camera_driver/params/test_params.yaml
cam_ids:
- 17197559　(さっき調べたシリアルナンバーに変更)
cam_aliases:
- cam0
master_cam: 17197559 (さっき調べたシリアルナンバーに変更)
skip: 20
delay: 1.0

# Assign all the follwing via launch file to prevent confusion and conflict

#save_path: ~/projects/data
#save_type: .bmp #binary or .tiff or .bmp
#binning: 1 # going from 2 to 1 requires cameras to be unplugged and replugged
#color: false
#frames: 50
#soft_framerate: 20 # this frame rate reflects to the software frame rate set using ros::rate
#exp: 997
#to_ros: true  #When to_ros is not selected, but live is selected, pressing 'space' exports single image to ROS

#Camera info message details
distortion_model: plumb_bob
image_height: 1080
image_width: 1440
distortion_coeffs:
- [-0.021141875266089592, -0.3733872931278025, 2.385982550579459, 3.2824571732099725]


#specified as [fx  0 cx 0 fy cy 0  0  1]
intrinsic_coeffs:
- [1886.9232141485886, 0.0, 604.7214878709341, 0.0, 1886.6668765711668, 493.47726714719823, 0.0, 0.0, 1.0]

rectification_coeffs:
- [1.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 1.000000]

projection_coeffs:
- [913.700317, 0.000000, 953.448302, 0.000000, 0.000000, 1063.296631, 777.871993, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000]

flip_horizontal:
- false

flip_vertical:
- false

region_of_interest:
  width: 0
  height: 0
  x_offset: 0
  y_offset: 0
``` 
変更できたらroslaunchしてみよう！


```bash:terminal1
roslaunch spinnaker_sdk_camera_driver node_acquisition.launch 
``` 

``` bash:terminal2
rviz
``` 

## 結果
![Screenshot from 2022-10-12 16-04-55.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2687692/f95797f3-c8ae-249e-b957-d51d6a287785.png)


## まとめ
・ubuntu18.04でspinnakerSDKを実行
・rosのパッケージの実行