CHAMPをROS 2 Humbleへアップグレードした際にやったこと

4脚ロボット制御用のROSパッケージであるCHAMPを、ROS 2 Humbleに対応させるためにPull Requestを作成しました。その際に遭遇した内容については、その他のROS 2パッケージにおいてもROS 2 GalacticからROS 2 Humbleに移行する際に影響する可能性がありそうなので共有します。
(※ROS 1からROS 2への移行ではありません)

この記事はROS 2 Advent Calendar 2022の19日目として投稿しています。

目次

CHAMP

CHAMPは4脚ロボット制御をROSでもできるようにしようというプロジェクトで、2020年のROS WorldでJuanさんが発表したものです。入出力がmove_base互換なので移動ロボット用のパッケージもだいたいそのまま使うことができ、またMoveItのようにsetup_assistantもあるため、手軽に4脚ロボットをROS対応できるようになっています。当時はROS Kinetic/Melodicのみでしたが、その後AlexKaravaevさんの貢献によって2022年春にはROS 2 Galacticにも部分的に対応していました。

CHAMPについては、日本語の内容だと、nisshan_さんの記事が有名です。

Qiita
Mini Pupperの動かし方(Gazebo) - Qiita ROS Advent Calendar 2021 19日目の記事です。こんにちは、にっしゃんです。Mini Pupperとは「Mini Pupperは、学校、ホームスクール家庭、愛好家、そしてそ…
Qiita
M5Stack+ROSで4脚ロボットを作る - Qiita この記事はM5Stack Advent Calendar 2022の16日目の記事であり、ROS Advent Calendar 2022の16日目の記事でもあります。記事1本で2つのアドベントカレ…

CHAMPのROS 2 Galacticでの課題

ROS 2 GalacticはCHAMPで使う上では、ros2_controllers周りに課題がありました。具体的には、公式のros2_controllersのGalactic向けリリースにはJointTrajectoryControllerにeffortのcommand_interfacesが含まれていませんでした。

ROS 1でいうところのeffort_controllers::JointTrajectoryControllerだと思われます。ros2_controllersではHardwareInterfaceをposition, velocity, effort以外にも指定できるようです。

ros(1)_control only allowed three hardware interface types: position, velocity, and effort. ros2_control allows you to create any interface type by defining a custom string. For example, you might define a position_in_degrees or a temperature interface. The most common (position, velocity, acceleration, effort) are already defined as constants in hardware_interface/types/hardware_interface_type_values.hpp.

ros-controls/ros2_control_demos https://github.com/ros-controls/ros2_control_demos/blob/master/README.md

effortのcommand_interfacesのためのコード自体が存在しなかったというではなく、masterブランチでは取り込まれていたため、ros2_controllersをforkしてeffortのcommand_interfacesに対応するためのパッチを当てたjoint_trajectory_controllerパッケージをGalactic向けに公開したユーザがいました。

GitHub
[JTC] Implement effort-only command interface by Ace314159 · Pull Request #225 · ros-controls/ros2_c... This addresses the effort part of #135 and #171. I've tested this on our team's robot and it works identically to the ROS1 version from our testing. I just real...
GitHub
GitHub - rohitmenon86/ros2_controllers: Generic robotic controllers to accompany ros2_control Generic robotic controllers to accompany ros2_control - rohitmenon86/ros2_controllers

CHAMPでは上記の有志がパッチを当てたros2_controllersをソースからビルドして使うような実装になっていました。APTでインストールできるパッケージはそのままでは使えないので、構成がややこしいです。

GitHub
added auto installation of effort controllers · chvmp/champ@3689dfb MIT Cheetah I Implementation. Contribute to chvmp/champ development by creating an account on GitHub.

ROS 2 ControlについてはyoutalkさんのROSCon JP 2021のスライドがわかりやすく、とても勉強になりました。

CHAMPのROS 2 Humble対応

ROS 2 Galacticが2022年11月でEOLを迎えるため、ROS 2 Humbleで使いたいと思い、CHAMPをROS 2 Humbleで動かすためのPull Requestを作成しました。

このPull Requestを作成することでROS 2 Humble+GazeboでCHAMPを動かせるようになりました!

このPull Requestの修正内容は主に3つです。

  1. C++17への対応
  2. ros2 control load_controllerのコマンド更新
  3. Gazebo用自作センサビルドエラー修正

C++17への対応

ROS 2 Galactic以降ではC++のバージョンがC++17に変わっています。

どういうわけかROS 2 GalacticのときはCMakeLists.txtでadd_compile_options(-std=c++14)としてC++14を指定していても問題なくビルドできていたのですが、今回ROS 2 Humbleではビルドエラーが出たのでlibchampとあわせてC++17に対応するためにC++のソースの一部とCMakeLists.txtを修正しています。

GitHub
Fix build error on ROS 2 humble by Tiryoh · Pull Request #6 · chvmp/libchamp This pull request fixes the following error while colcon build --- stderr: champ_base In file included from /home/ubuntu/ros2_w...
GitHub
Fix build error on ROS 2 humble by Tiryoh · Pull Request #109 · chvmp/champ This pull request fixes the following errors. This fix depends on chvmp/libchamp#6. champ_base while colcon build $ head -n30 log/build_2022-11-27_23-20-32/cham...

ros2 control load_controllerのコマンド更新

CHAMPのlaunchファイルの中で、Gazeboを起動した後にROS 2 Controlのコントローラを読み込むため、ros2controlcliを使っています。

ROS 2 Galacticではload_controlerでset_stateするときに{configure,start}で指定していました。

Command Line Interface — ROS2_Control: Galactic documentation
https://control.ros.org/galactic/doc/ros2_control/ros2controlcli/doc/userdoc.html#load-controller

しかし、ROS 2 Humbleではload_conrollerでset_stateするときに{configured,active}で指定します。

Command Line Interface — ROS2_Control: Humble documentation
https://control.ros.org/humble/doc/ros2_control/ros2controlcli/doc/userdoc.html#load-controller

これはROS 2 Controlの2.12.0で変更された内容です。

GitHub
Deprecate and rename `start` and `stop` nomenclature toward user to `activate` and `deactivate` #ABI... Rename fileds and deprecated old nomenclature. New defines from SwitchController.srv

startactivateに変更するだけではありますが、この変更をしないと下記のようなエラーが出てしまうため、ROS 2 HumbleでROS 2 Controlを使うために重要な変更でした。

[ros2-9] ros2 control load_controller: error: argument --set-state: invalid choice: 'start' (choose from 'configured', 'active')
[ERROR] [ros2-9]: process has died [pid 104702, exit code 2, cmd 'ros2 control load_controller --set-state start joint_states_controller'].
GitHub
Fix build error on ROS 2 humble by Tiryoh · Pull Request #109 · chvmp/champ This pull request fixes the following errors. This fix depends on chvmp/libchamp#6. champ_base while colcon build $ head -n30 log/build_2022-11-27_23-20-32/cham...

Gazebo用自作センサビルドエラー修正

CHAMPではGazebo用にcontact_sensor(接触センサ)を自作して実装されています。

CMakeLists.txtの中でtarget_link_libraries(contact_sensor ${GAZEBO_LIBRARIES})としてリンクしている箇所があるのですが、これがROS 2 Humbleでビルドするときに下記のエラーの原因になっているようでした。

CMake Warning (dev) at /usr/share/cmake-3.22/Modules/FindPackageHandleStandardArgs.cmake:438 (message):
  The package name passed to `find_package_handle_standard_args` (PkgConfig)
  does not match the name of the calling package (gazebo).  This can lead to
  problems in calling code that expects `find_package` result variables
  (e.g., `_FOUND`) to follow a certain pattern.
Call Stack (most recent call first):
  /usr/share/cmake-3.22/Modules/FindPkgConfig.cmake:99 (find_package_handle_standard_args)
  /usr/lib/x86_64-linux-gnu/cmake/gazebo/gazebo-config.cmake:72 (include)
  CMakeLists.txt:12 (find_package)
This warning is for project developers.  Use -Wno-dev to suppress it.
/usr/bin/ld: CMakeFiles/contact_sensor.dir/src/contact_sensor.cpp.o: undefined reference to symbol '_ZN3tbb6detail2r114notify_waitersEm'
/usr/bin/ld: /lib/x86_64-linux-gnu/libtbb.so.12: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
gmake[2]: *** [CMakeFiles/contact_sensor.dir/build.make:238: contact_sensor] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:137: CMakeFiles/contact_sensor.dir/all] Error 2
gmake: *** [Makefile:146: all] Error 2

解決策は、以下のようにfind_packageでgazeboではなくgazebo_rosを指定することでした。
(これについては適当に変更したらたまたま解決できたので、パッケージ名の変更が必要だった理由についてはきちんとした調査はできていません。何かわかったら追記したいと思います。)

-find_package(gazebo REQUIRED)
+find_package(gazebo_ros REQUIRED)

おわりに

4脚ロボット制御用のROSパッケージであるCHAMPの簡単な紹介と、そのCHAMPをROS 2 Humbleに対応させるためにPull Requestを作成したことを紹介しました。また、Pull Requestの内容について、ROS 2 GalacticからROS 2 Humbleにアップグレードする際に必要になりそうな項目という視点でまとめてみました。ROS 2 FoxyからROS 2 Humbleにアップグレードする際に必要になりそうな項目とも一致する部分はありそうです。

ROS 2 Humbleは2027年までサポートがあるので、積極的にいろいろなパッケージを使って、機会があればIssue/Pull Requestの作成をしていきたいと思います。

更新履歴

2023年12月3日

ros2_control ドキュメントへのリンク修正

この記事が気に入ったら
フォローしてね!

よかったらシェアしていただけると励みになります!
  • URLをコピーしました!
  • URLをコピーしました!

この記事を書いた人

Memotekiの管理人です。このブログには学んだことや共有しておきたいことをマイペースにメモしていきます。2020年からは日記も書き始めました。

コメント

コメントする


The reCAPTCHA verification period has expired. Please reload the page.

目次