1
1

備忘録 ラズパイ5 ROS2 ③ Ubuntu Desktop 24.04LTSでROS2環境 Python その1 responder(セットアップ)

Last updated at Posted at 2024-07-25

 前回、メッセージを可視化するためのツール rqt_graphとturtlesimをインストールして動かしました。

環境

  • Raspberry Pi 5 8GB
  • 追加ボード;NVMe Base for Raspberry Pi 5 (NVMe Base by Pimoroni)
  • Crucial クルーシャル P2シリーズ 500GB 3D NAND NVMe PCIe M.2 SSD CT500P2SSD8
  • 初期;RaspberryPi OS Desktop 64bit (Debian version: 12 (bookworm) Release date: March 15th 2024)
  • 現在;Ubuntu Desktop 24.04LTS(64-bit)
  • ROS2 HumbleではなくJazzy

 Windows10で、検索窓にcmdと入れ、コマンドプロンプトを起動します。
 sshでログインします(第1回参照)。必要ならupdateします。

C:\Users\yoshi>ssh yoshi.local

Python仮想環境メモ
作る。一度だけ
yoshi@yoshi:~$ python3 -m venv ros2
仮想環境に入る。
yoshi@yoshi:~$ source ros2/bin/activate
(ros2) yoshi@yoshi:~$ pip list
Package Version
------- -------
pip 24.0
(ros2) yoshi@yoshi:~$

 抜ける。
deactivate

Pythonのプログラム responder(セットアップ)

 先頭に、import rclpyとか書いて、プログラムを作るのではないらしい。

ワークスペース

 最初にワークスペースを作ります。

(ros2) yoshi@yoshi:~$ mkdir -p ~/ros2_ws/src
パッケージ

 ワークスペースに入って、パッケージを作ります。responderという名称にしました。

$ source /opt/ros/jazzy/setup.bash
$ cd ros2_ws/src
$ ros2 pkg create responder

 ここで、```sudo apt install tree``で、ディレクトリの様子を表示するtreeコマンドをインストールしておきます。

 3種類の引数があって、用途に応じて使い分けをするようです。
$ ros2 pkg create responder
 最小限のファイルが作られる。いろいろと自分で記入をする
$ ros2 pkg create responder --build-type ament_python
 Pythonで記述するための必要なファイルが作られる。いろいろと自分で記入をする
$ ros2 pkg create responder --node-name responder --build-type ament_python
 package.xml、setup.cfg、setup.pyの中身の記述が追加される

 初めてなので、3番目の、いろいろファイルを作ってくれる方法を選びます。

ros2 pkg create responder --node-name responder --build-type ament_python

 できたディレクトリやファイルをtreeコマンドで表示します。

(ros2) yoshi@yoshi:~/ros2_ws/src$ tree
.
└── responder
    ├── package.xml
    ├── resource
    │   └── responder
    ├── responder
    │   ├── __init__.py
    │   └── responde.py
    ├── setup.cfg
    ├── setup.py
    └── test
        ├── test_copyright.py
        ├── test_flake8.py
        └── test_pep257.py

5 directories, 9 files

 インストールされたPythonのライブラリを見ます。

(ros2) yoshi@yoshi:~/ros2_ws/src$ pip list
Package                              Version
------------------------------------ -------
action-msgs                          2.0.2
action-tutorials-interfaces          0.33.4
action-tutorials-py                  0.33.4
actionlib-msgs                       5.3.5
ament-cmake-test                     2.5.2
ament-copyright                      0.17.1
ament-cppcheck                       0.17.1
ament-cpplint                        0.17.1
ament-flake8                         0.17.1
ament-index-python                   1.8.1
ament-lint                           0.17.1
ament-lint-cmake                     0.17.1
ament-package                        0.16.3
ament-pep257                         0.17.1
ament-uncrustify                     0.17.1
ament-xmllint                        0.17.1
angles                               1.16.0
builtin-interfaces                   2.0.2
composition-interfaces               2.0.2
cv-bridge                            4.1.0
demo-nodes-py                        0.33.4
diagnostic-msgs                      5.3.5
domain-coordinator                   0.12.0
example-interfaces                   0.12.0
examples-rclpy-executors             0.19.4
examples-rclpy-minimal-action-client 0.19.4
examples-rclpy-minimal-action-server 0.19.4
examples-rclpy-minimal-client        0.19.4
examples-rclpy-minimal-publisher     0.19.4
examples-rclpy-minimal-service       0.19.4
examples-rclpy-minimal-subscriber    0.19.4
geometry-msgs                        5.3.5
image-geometry                       4.1.0
interactive-markers                  2.5.4
laser-geometry                       2.7.0
launch                               3.4.2
launch-ros                           0.26.5
launch-testing                       3.4.2
launch-testing-ros                   0.26.5
launch-xml                           3.4.2
launch-yaml                          3.4.2
lifecycle-msgs                       2.0.2
logging-demo                         0.33.4
map-msgs                             2.4.1
message-filters                      4.11.1
nav-msgs                             5.3.5
osrf-pycommon                        2.1.4
pcl-msgs                             1.0.0
pendulum-msgs                        0.33.4
pip                                  24.0
python-qt-binding                    2.2.1
qt-dotgraph                          2.7.4
qt-gui                               2.7.4
qt-gui-cpp                           2.7.4
qt-gui-py-common                     2.7.4
quality-of-service-demo-py           0.33.4
rcl-interfaces                       2.0.2
rclpy                                7.1.1
rcutils                              6.7.1
resource-retriever                   3.4.3
rmw-dds-common                       3.1.0
ros2action                           0.32.1
ros2bag                              0.26.4
ros2bag-mcap-cli                     0.26.4
ros2bag-sqlite3-cli                  0.26.4
ros2cli                              0.32.1
ros2component                        0.32.1
ros2doctor                           0.32.1
ros2interface                        0.32.1
ros2launch                           0.26.5
ros2lifecycle                        0.32.1
ros2multicast                        0.32.1
ros2node                             0.32.1
ros2param                            0.32.1
ros2pkg                              0.32.1
ros2run                              0.32.1
ros2service                          0.32.1
ros2topic                            0.32.1
rosbag2-interfaces                   0.26.4
rosbag2-py                           0.26.4
rosgraph-msgs                        2.0.2
rosidl-adapter                       4.6.3
rosidl-cli                           4.6.3
rosidl-cmake                         4.6.3
rosidl-generator-c                   4.6.3
rosidl-generator-cpp                 4.6.3
rosidl-generator-py                  0.22.0
rosidl-generator-type-description    4.6.3
rosidl-parser                        4.6.3
rosidl-pycommon                      4.6.3
rosidl-runtime-py                    0.13.1
rosidl-typesupport-c                 3.2.2
rosidl-typesupport-cpp               3.2.2
rosidl-typesupport-fastrtps-c        3.6.0
rosidl-typesupport-fastrtps-cpp      3.6.0
rosidl-typesupport-introspection-c   4.6.3
rosidl-typesupport-introspection-cpp 4.6.3
rpyutils                             0.4.1
rqt-action                           2.2.0
rqt-bag                              1.5.3
rqt-bag-plugins                      1.5.3
rqt-console                          2.2.1
rqt-graph                            1.5.4
rqt-gui                              1.6.0
rqt-gui-py                           1.6.0
rqt-msg                              1.5.1
rqt-plot                             1.4.0
rqt-publisher                        1.7.2
rqt-py-common                        1.6.0
rqt-py-console                       1.2.2
rqt-reconfigure                      1.6.2
rqt-service-caller                   1.2.1
rqt-shell                            1.2.2
rqt-srv                              1.2.2
rqt-topic                            1.7.2
sensor-msgs                          5.3.5
sensor-msgs-py                       5.3.5
service-msgs                         2.0.2
shape-msgs                           5.3.5
sros2                                0.13.2
statistics-msgs                      2.0.2
std-msgs                             5.3.5
std-srvs                             5.3.5
stereo-msgs                          5.3.5
teleop-twist-keyboard                2.4.0
tf2-geometry-msgs                    0.36.4
tf2-kdl                              0.36.4
tf2-msgs                             0.36.4
tf2-py                               0.36.4
tf2-ros-py                           0.36.4
tf2-sensor-msgs                      0.36.4
tf2-tools                            0.36.4
topic-monitor                        0.33.4
trajectory-msgs                      5.3.5
turtlesim                            1.8.3
type-description-interfaces          2.0.2
unique-identifier-msgs               2.5.0
visualization-msgs                   5.3.5

 Pythonのバージョンです。

(ros2) yoshi@yoshi:~/ros2_ws/src$ python -V
Python 3.12.3

Filesで/optを見たい
$ sudo nautilus /opt


備忘録 ラズパイ5 ROS2

① ハードの用意とUbuntu Desktop 24.04LTS

② Ubuntu Desktop 24.04LTSでROS2環境 rqt_graphとturtlesim

③ Ubuntu Desktop 24.04LTSでROS2環境 Python その1 responder(セットアップ)

④ Ubuntu Desktop 24.04LTSでROS2環境 Pythonその2responder(コーディングと実行;失敗)

⑤ Ubuntu Desktop 24.04LTSでROS2環境 C++ その1 セットアップ main.c

⑥ Ubuntu Desktop 24.04LTSでROS2環境 C++ その2 セットアップ pub.cpp rqt_graph


1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1