TurtleBot3にミニPCを搭載した際のセットアップ

## はじめに

TurtleBot3にラズパイではなくミニPCを搭載し，RvizなどもこのPCで動かしたいときのセットアップ方法です．

## ROS 2 Humbleのインストール

「Try some examples」の実行まで

https://docs.ros.org/en/humble/Installation/Ubuntu-Install-Debs.html

## TurtleBot3のセットアップ

### PCのセットアップ

https://emanual.robotis.com/docs/en/platform/turtlebot3/quick-start/#pc-setup

「Humble」を選択

### SBCのセットアップ

通常ラズパイが使用されるSBCの役割をミニPCに担わせます．
必要であろうコマンドを実行していきます．

https://emanual.robotis.com/docs/en/platform/turtlebot3/sbc_setup/#sbc-setup

5. Enter the command below to edit automatic update setting file.

    ```bash
    sudo vi /etc/apt/apt.conf.d/20auto-upgrades
    ```

6. Change the update settings as below.

    ```bash:/etc/apt/apt.conf.d/20auto-upgrades
    APT::Periodic::Update-Package-Lists "0";
    APT::Periodic::Unattended-Upgrade "0";
    ```

8. Set the `systemd` to prevent boot-up delay even if there is no network at startup. Run the command below to set mask the `systemd` process using the following command.

    ```bash
    systemctl mask systemd-networkd-wait-online.service
    ```

9. Disable Suspend and Hibernation

    ```bash
    sudo systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.target
    ```

10. Reboot the Raspberry Pi.

    ```bash
    reboot
    ```

2. Install and Build ROS Packages.

    Building the `turtlebot3` package may take longer than an hour. Please use the SMPS to ensure the system is always powered.

    ```bash
    sudo apt install python3-argcomplete python3-colcon-common-extensions libboost-system-dev build-essential
    sudo apt install ros-humble-hls-lfcd-lds-driver
    sudo apt install ros-humble-turtlebot3-msgs
    sudo apt install ros-humble-dynamixel-sdk
    sudo apt install libudev-dev
    mkdir -p ~/turtlebot3_ws/src && cd ~/turtlebot3_ws/src
    #git clone -b humble https://github.com/ROBOTIS-GIT/turtlebot3.git
    git clone -b humble https://github.com/ROBOTIS-GIT/ld08_driver.git
    cd ~/turtlebot3_ws/src/turtlebot3
    rm -r turtlebot3_cartographer turtlebot3_navigation2
    cd ~/turtlebot3_ws/
    #echo 'source /opt/ros/humble/setup.bash' >> ~/.bashrc
    source ~/.bashrc
    colcon build --symlink-install --parallel-workers 1
    #echo 'source ~/turtlebot3_ws/install/setup.bash' >> ~/.bashrc
    source ~/.bashrc
    ```

3. USB Port Setting for OpenCR

    ```bash
    sudo cp `ros2 pkg prefix turtlebot3_bringup`/share/turtlebot3_bringup/script/99-turtlebot3-cdc.rules /etc/udev/rules.d/
    sudo udevadm control --reload-rules
    sudo udevadm trigger
    ```

### OpenCRのセットアップ

https://emanual.robotis.com/docs/en/platform/turtlebot3/opencr_setup/#opencr-setup

の３〜６

1. Arduino IDEのインストール
    - 「2. Install Arduino IDE.」は
        ```bash
        wget -P ~/Downloads https://downloads.arduino.cc/arduino-1.8.19-linux64.tar.xz
        tar xvf ~/Downloads/arduino-1.8.19-linux64.tar.xz
        mkdir -p ~/.local
        mv arduino-1.8.19 ~/.local
        cd ~/.local/arduino-1.8.19
        bash arduino-linux-setup.sh $USER
        sudo systemctl reboot
        ```

        再起動後

        ```bash
        cd ~/.local/arduino-1.8.19
        sudo bash install.sh
        ```

        https://qiita.com/ma2shita/items/927aa9e55962b4137518

    - 「6. Open the TurtleBot3 firmware.」以降は [Setup DYNAMIXELs for TurtleBot3](https://emanual.robotis.com/docs/en/platform/turtlebot3/faq/#setup-dynamixels-for-turtlebot3) を参考に進める
        - 「Tools > Board > Boards Manager」で「OpenCR」と検索し，バージョン `1.5.2` をインストール
        - 「Tools > Board」を "OpenCR Board"，「Tools > Port」を "/dev/ttyACM0"に設定

2. OpenCR Test

    5. Upload firmware to the OpenCR.

        ```bash
        cd ~/opencr_update
        ./update.sh $OPENCR_PORT $OPENCR_MODEL.opencr
        ```

    6. A successful firmware upload for TurtleBot3 Burger will look like below.

    を行った後に「3.3.1. OpenCR Test」

### Bringup

https://emanual.robotis.com/docs/en/platform/turtlebot3/bringup/

「Dynamixel」モーターなどのエラーが出ているときは「OpenCR Test」を再実行

#### Bringup TurtleBot3

```bash
export TURTLEBOT3_MODEL=waffle_pi
ros2 launch turtlebot3_bringup robot.launch.py
```

#### Rviz

```bash
ros2 launch turtlebot3_bringup rviz2.launch.py  
```

#### Teleoperation

Bringupした状態で

- キーボード

    ```bash
    export TURTLEBOT3_MODEL=waffle_pi
    ros2 run turtlebot3_teleop teleop_keyboard
    ```

- リモコン

#### Topic Monitor

```bash
rqt
```

## LiDARのセットアップ

https://github.com/Slamtec/sllidar_ros2

https://qiita.com/pei_pei_/items/1d9011da23eeb8f049fc

### 1. パッケージをクローン・ビルド

```bash
mkdir -p ~/ros2_ws/src

cd ~/ros2_ws/src
git clone https://github.com/Slamtec/sllidar_ros2.git

cd ~/ros2_ws
source /opt/ros/humble/setup.bash
colcon build --symlink-install
```

### 2. 権限を付与

```bash
ls -l /dev | grep ttyUSB
sudo chmod 666 /dev/ttyUSB0
```

:::note info
LiDARと接続するUSBを抜き差ししながら `ls -l /dev | grep ttyUSB` を実行するとデバイスを確認できます
:::


### 3. Rvizで確認

```bash
source ~/ros2_ws/install/setup.bash
ros2 launch sllidar_ros2 view_sllidar_s3_launch.py
```