Open4

ROS2チートシート

horie-thorie-t

実行準備

source /<ROSインストールディレクトリ>/<ROSディストリビューション名>/install/local_setup.bash
# 例
source /opt/ros/jazzy/setup.bash                      # debianパッケージインストールの場合
source ~/ros2_jazzy/install/local_setup.bash    # インストールガイドに従った場合
cd /<ROSのワークスペース>/
# 例
cd ~/ros2_ws/

source ./install/local_setup.bash
horie-thorie-t

コーディング関連

パッケージの作成からビルドまで

パッケージの作成(python版)

cd /<rosのワークスペース>/src
ros2 pkg create --build-type ament_python --license Apache-2.0 --node-name <ノード名> <パッケージ名>

ビルド

colcon build --symlink-install --packages-select パッケージ名

ビルドしたパッケージのインストール

cd /<ROSのワークスペース>/
# 例
cd ~/ros2_ws/

source ./install/local_setup.bash

package.xml

<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format2.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="2">
  <name>パッケージ名</name>
  <version>バージョン</version>

  <description>パッケージの説明</description>

  <maintainer email="メールアドレス">名前</maintainer>
  <license>ライセンス名(Apache-2.0など)</license>
  <url type="repository">ソースコードのリポジトリURL</url>
  <url type="bugtracker">バグトラッキングシステムのURL</url>
  <author>著者名</author>

  <buildtool_depend>ビルドツール名(ament_cmake_ros)</buildtool_depend>

  <depend>依存するROSパッケージ名</depend>

  <test_depend>テストで依存するパッケージ名</test_depend>

  <export>
    <build_type>ビルドタイプ(ament_cmake, ament_python)</build_type>
  </export>
</package>

horie-thorie-t

実行関連

ノードの実行

ros2 run <パッケージ名> <ノード名>
# トピックをリマッピング
ros2 run <パッケージ名> <ノード名> --ros-args --remap <元のトピック>:=<マップ先のトピック>
# 例: /turtle1/cmd_velを/cmd_velに変更
ros2 run turtlesim turtlesim_node --ros-args --remap /turtle1/cmd_vel:=/cmd_vel

トピック

# トピックのリストを表示
ros2 topic list
# トピックを購読して、メッセージをターミナルに出力
ros2 topic echo /cmd_vel
horie-thorie-t

ROS2のPythonのビルドに /usr/bin/python が固定で使われている対応方法?

/etc/pip.conf に以下を追加すればbuildできるかも。

/etc/pip.conf
[global]
break-system-packages = true