Zenn
Open18

Raspberry Pi 4 + Ubuntu 24.04 + ROS 2 Jazzy (May, 2024)

tiryohtiryoh

Raspberry Pi 4(RAM 2GB)にUbuntu 24.04 + ROS 2 JazzyをインストールしてTurtleBot3 Burgerを動かすまで

  • ubuntu-24.04-preinstalled-server-arm64+raspi.img.xzではSSHのパスワード認証が初期状態で無効化されていたので、セットアップの途中まではモニタとキーボード接続が必須
  • メモリ2GBのRaspberry Piだとcolcon build時にメモリが不足するためswapを用意しておくか、メモリ4GB以上のRaspberry Piを使うことを推奨
tiryohtiryoh

OS初期設定

モニタとキーボードを接続した状態で操作する

無線LAN

vimは入っていたので、netplanを設定し、最初から無線LANに接続する

network:
    version: 2
    ethernets:
        eth0:
            dhcp4: true
            optional: true
    wifis:
        wlan0:
            dhcp4: true
            optional: true
            access-points:
              "SSID":
                  password: "WIFI-PASSWORD"

SSHのパスワード認証を有効化する

パスワード認証が無効化されているので有効化する

  • sudo vi /etc/ssh/sshd_config.d/50-cloud-init.conf
    • PasswordAuthentication noyesにする
  • sudo systemctl reload ssh

Gitのインストール

  • sudo apt update && sudo apt install git

いったんここで再起動しておく

tiryohtiryoh

ROSのインストール

インストーラ( https://github.com/Tiryoh/ros2_setup_scripts_ubuntu )を使用してROS 2 Jazzyのros-testingのリポジトリをupstreamとしてインストールする

  • git clone https://github.com/Tiryoh/ros2_setup_scripts_ubuntu.git
  • cd ros2_setup_scripts_ubuntu && git switch feature/add-ros2-jazzy
  • ./ros2-jazzy-ros-base-testing.sh

ros-testingとmainの違いは下記資料参照

https://docs.ros.org/en/iron/Installation/Testing.html

tiryohtiryoh

チュートリアルROSパッケージのインストール

  • cd ~/ros2_setup_scripts_ubuntu && ./tutorial.sh
    • パッケージ不足のエラーが出たので下記を追加でインストールしてtutorial.shをやり直し
      • sudo apt install ros-jazzy-example-interfaces
    • メモリが不足してcolcon buildに相当時間かかるので途中で停止してswapを増やす
tiryohtiryoh

setup.py周りでめっちゃワーニング出てる……

Starting >>> examples_rclpy_minimal_action_server
--- stderr: examples_rclpy_minimal_action_server
/usr/lib/python3/dist-packages/setuptools/command/develop.py:40: EasyInstallDeprecationWarning: easy_install command is deprecated.
!!

        ********************************************************************************
        Please avoid running ``setup.py`` and ``easy_install``.
        Instead, use pypa/build, pypa/installer or other
        standards-based tools.

        See https://github.com/pypa/setuptools/issues/917 for details.
        ********************************************************************************

!!
  easy_install.initialize_options(self)
---
Finished <<< examples_rclpy_minimal_action_server [5.46s]
Starting >>> examples_rclpy_minimal_client
--- stderr: examples_rclpy_minimal_client
/usr/lib/python3/dist-packages/setuptools/command/develop.py:40: EasyInstallDeprecationWarning: easy_install command is deprecated.
!!

        ********************************************************************************
        Please avoid running ``setup.py`` and ``easy_install``.
        Instead, use pypa/build, pypa/installer or other
        standards-based tools.

        See https://github.com/pypa/setuptools/issues/917 for details.
        ********************************************************************************

!!
  easy_install.initialize_options(self)
---
Finished <<< examples_rclpy_minimal_client [7.90s]
Starting >>> examples_rclpy_minimal_publisher
--- stderr: examples_rclpy_minimal_publisher
/usr/lib/python3/dist-packages/setuptools/command/develop.py:40: EasyInstallDeprecationWarning: easy_install command is deprecated.
!!

        ********************************************************************************
        Please avoid running ``setup.py`` and ``easy_install``.
        Instead, use pypa/build, pypa/installer or other
        standards-based tools.

        See https://github.com/pypa/setuptools/issues/917 for details.
        ********************************************************************************

!!
  easy_install.initialize_options(self)
---
Finished <<< examples_rclpy_minimal_publisher [5.50s]
Starting >>> examples_rclpy_minimal_service
--- stderr: examples_rclpy_minimal_service
/usr/lib/python3/dist-packages/setuptools/command/develop.py:40: EasyInstallDeprecationWarning: easy_install command is deprecated.
!!

        ********************************************************************************
        Please avoid running ``setup.py`` and ``easy_install``.
        Instead, use pypa/build, pypa/installer or other
        standards-based tools.

        See https://github.com/pypa/setuptools/issues/917 for details.
        ********************************************************************************

!!
  easy_install.initialize_options(self)
---
Finished <<< examples_rclpy_minimal_service [5.41s]
Starting >>> examples_rclpy_minimal_subscriber
--- stderr: examples_rclpy_minimal_subscriber
/usr/lib/python3/dist-packages/setuptools/command/develop.py:40: EasyInstallDeprecationWarning: easy_install command is deprecated.
!!

        ********************************************************************************
        Please avoid running ``setup.py`` and ``easy_install``.
        Instead, use pypa/build, pypa/installer or other
        standards-based tools.

        See https://github.com/pypa/setuptools/issues/917 for details.
        ********************************************************************************

!!
  easy_install.initialize_options(self)
---
Finished <<< examples_rclpy_minimal_subscriber [8.32s]
Starting >>> examples_rclpy_pointcloud_publisher
--- stderr: examples_rclpy_pointcloud_publisher
/usr/lib/python3/dist-packages/setuptools/command/develop.py:40: EasyInstallDeprecationWarning: easy_install command is deprecated.
!!

        ********************************************************************************
        Please avoid running ``setup.py`` and ``easy_install``.
        Instead, use pypa/build, pypa/installer or other
        standards-based tools.

        See https://github.com/pypa/setuptools/issues/917 for details.
        ********************************************************************************

!!
  easy_install.initialize_options(self)
---
Finished <<< examples_rclpy_pointcloud_publisher [6.99s]
Starting >>> launch_testing_examples
--- stderr: launch_testing_examples
/usr/lib/python3/dist-packages/setuptools/command/develop.py:40: EasyInstallDeprecationWarning: easy_install command is deprecated.
!!

        ********************************************************************************
        Please avoid running ``setup.py`` and ``easy_install``.
        Instead, use pypa/build, pypa/installer or other
        standards-based tools.

        See https://github.com/pypa/setuptools/issues/917 for details.
        ********************************************************************************

!!
  easy_install.initialize_options(self)
---
Finished <<< launch_testing_examples [5.37s]
tiryohtiryoh

export PYTHONWARNINGS="ignore:easy_install command is deprecated::setuptools.command.develop"と書いたらワーニングが表示されなくなった

(これでよいのか?と言う気はするがいったんこれで乗り切る)

tiryohtiryoh

ドキュメントはまだリリースされていないが、colcon workspaceにYAMLをおくだけでcolconのデフォルトオプションを設定できるようになっているらしい。colcon-defautlsの0.2.7からの機能で、現状のROS 2 Jazzyでは0.2.8がインストールされていた。

https://github.com/colcon/colcon.readthedocs.org/pull/89

~/ros2_ws/colcon_defaults.yamlとして下記の内容を貼り付け。

build:
  symlink-install: true
  executor: sequential
  event-handlers:
    - console_stderr+
test:
  executor: sequential
  event-handlers:
    - console_cohesion+
    - desktop_notification+
  return-code-on-test-failure: true
tiryohtiryoh

colcon-defaults自体は、2018年頃から存在するプロジェクトでROS 2 Humbleの頃から使えていた(その前も存在したはずだが試していないので不明)

colcon-defautlsの0.2.7からはROSのワークスペースごとに切り替えができるようになっている。いままでは$HOME/.colcon/defualts.yamlに配置するなど使用している環境(≠ワークスペース)で共通だった。

tiryohtiryoh

TurtleBot3用ROSパッケージのインストール(Raspberry Pi)

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

上記資料を参照してROSパッケージのインストールを実施

※もしもLDS-01を使っている場合はld08_driverの代わりにhls_lfcd_lds_driver( https://github.com/ROBOTIS-GIT/hls_lfcd_lds_driver )を指定する

mkdir -p ~/.colcon
vim ~/.colcon/defaults.yaml
mkdir -p ~/ros2_ws/src
git clone -b ros2-devel https://github.com/ROBOTIS-GIT/ld08_driver.git
sudo apt install libudev-dev # https://github.com/ROBOTIS-GIT/ld08_driver/pull/9
git clone -b ros2-devel https://github.com/ROBOTIS-GIT/turtlebot3_msgs.git
git clone -b ros2-devel https://github.com/ROBOTIS-GIT/turtlebot3.git
touch turtlebot3/turtlebot3_cartographer/COLCON_IGNORE
touch turtlebot3/turtlebot3_navigation2/COLCON_IGNORE
rosdep install -riy --from-paths .
cd ~/ros2_ws
colcon build
source install/setup.bash

~/.colcon/defaults.yamlの中身は下記の通り最小限だけ記載

~/.colcon/defaults.yaml
build:
  executor: sequential
test:
  executor: sequential
  return-code-on-test-failure: true

追加でUSBデバイス用のudev rulesの設定とROS_DOMAIN_IDの設定

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
echo 'export ROS_DOMAIN_ID=30 #TURTLEBOT3' >> ~/.bashrc
echo 'export LDS_MODEL=LDS-02' >> ~/.bashrc
echo 'export OPENCR_PORT=/dev/ttyACM0' >> ~/.bashrc
echo 'export OPENCR_MODEL=burger' >> ~/.bashrc
echo 'export TURTLEBOT3_MODEL=burger' >> ~/.bashrc
gaijingeekgaijingeek

こちらのステップは、Raspberry でなく、Remote PCでのUbuntu Jazzyをおこなったのか?

tiryohtiryoh

Raspberry Piです。ここまでの流れでRemote PCは登場しません。

gaijingeekgaijingeek

ご返事ありがとうございます!!では、Remote PCの設定も教えていただけますか。現在Jazzyを使っていますが、TurtleBot 3のパッケージはHumbleまでです。どうすればいいですか?

tiryohtiryoh

Raspberry Piでソースコードからビルドしたのと同じように、PCでもソースコードからビルドしてみてください。

tiryohtiryoh

OpenCRの更新

sudo dpkg --add-architecture armhf
sudo apt update
sudo apt install libc6:armhf
mkdir -p ~/Downloads && cd ~/Downloads
wget https://github.com/ROBOTIS-GIT/OpenCR-Binaries/raw/master/turtlebot3/ROS2/latest/opencr_update.tar.bz2 -O opencr_update_ros2.tar.bz2
tar -xvf ./opencr_update_ros2.tar.bz2
cd opencr_update
source ~/.bashrc
./update.sh $OPENCR_PORT $OPENCR_MODEL.opencr
tiryohtiryoh

Bringup(Turtlebot3 Only)

起動できるところまで確認する

cd ~/ros2_ws
source install/setup.bash
ros2 launch turtlebot3_bringup robot.launch.py

PCでSSHでログインして下記を実行してモータが回ることを確認する(モータが回転するので、機体を浮かせる。不要であれば省略。)

 ros2 topic pub -1 /cmd_vel geometry_msgs/msg/Twist '{linear:{x: 0.05,y: 0.0,z: 0.0},angular:{x: 0.0,y: 0.0,z: 0.0}}'
 ros2 topic pub -1 /cmd_vel geometry_msgs/msg/Twist '{linear:{x: 0.0,y: 0.0,z: 0.0},angular:{x: 0.0,y: 0.0,z: 0.0}}'
ログインするとコメントできます