0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

ROS 2 Humbleでaudio_commonパッケージをビルドする方法

Posted at

はじめに

audio_commonパッケージは、音声の再生や録音など可能な音声関連のパッケージである。

ROS 1ではバイナリ提供されており、ROS 2 Foxyでは、audio_commonパッケージのros2ブランチをビルドすることで利用可能である。

しかし、ROS 2 Humbleでは、バイナリ提供はされていなく、また、audio_commonパッケージのros2ブランチをビルドするとエラーになってしまう。本記事では、ROS 2 Humbleでaudio_commonパッケージをビルドする方法を紹介する。

動作確認環境

エラー内容

audio_commonパッケージのros2ブランチ最新版をビルドすると以下のようになりエラーとなる。

例:ワークスペースが~/ros2_wsの場合
cd ~/ros2_ws/src
git clone -b ros2 https://github.com/ros-drivers/audio_common
cd ~/ros2_ws
sudo apt update
rosdep install --from-paths src --ignore-src -r -y 
colcon build --symlink-install --packages-up-to audio_common
audio_commonのビルドエラー内容
Starting >>> audio_common_msgs
Finished <<< audio_common_msgs [7.42s]                     
Starting >>> audio_capture
Starting >>> audio_play
Starting >>> sound_play
--- stderr: sound_play                                                                                                     
CMake Error at /opt/ros/humble/share/ament_cmake_python/cmake/ament_python_install_package.cmake:106 (add_custom_target):
  add_custom_target cannot create target
  "ament_cmake_python_symlink_sound_play" because another target with the
  same name already exists.  The existing target is a custom target created
  in source directory "/root/ros2_ws/src/audio_common/sound_play".  See
  documentation for policy CMP0002 for more details.
Call Stack (most recent call first):
  /opt/ros/humble/share/ament_cmake_python/cmake/ament_python_install_package.cmake:39 (_ament_cmake_python_install_package)
  CMakeLists.txt:36 (ament_python_install_package)


CMake Error at /opt/ros/humble/share/ament_cmake_python/cmake/ament_python_install_package.cmake:141 (add_custom_target):
  add_custom_target cannot create target
  "ament_cmake_python_build_sound_play_egg" because another target with the
  same name already exists.  The existing target is a custom target created
  in source directory "/root/ros2_ws/src/audio_common/sound_play".  See
  documentation for policy CMP0002 for more details.
Call Stack (most recent call first):
  /opt/ros/humble/share/ament_cmake_python/cmake/ament_python_install_package.cmake:39 (_ament_cmake_python_install_package)
  CMakeLists.txt:36 (ament_python_install_package)


---
Failed   <<< sound_play [2.92s, exited with code 1]
Aborted  <<< audio_capture [13.5s]                                                                             
Aborted  <<< audio_play [16.5s]                                  

Summary: 1 package finished [24.7s]
  1 package failed: sound_play
  2 packages aborted: audio_capture audio_play
  3 packages had stderr output: audio_capture audio_play sound_play
  1 package not processed

エラーの詳細は、以下のissueで議論されている。

方法

issueにあるように、audio_commonのフォークブランチ「teapfw/audio_common humble_hotfixブランチ」を利用する。

このhumble_hotfixブランチは、2025年7月23日時点で本家audio_commonにはまだマージされていない。

例:ワークスペースが~/ros2_wsの場合
cd ~/ros2_ws/src
git clone -b humble_hotfix https://github.com/teapfw/audio_common
cd ~/ros2_ws
sudo apt update
rosdep install --from-paths src --ignore-src -r -y 
colcon build --symlink-install --packages-up-to audio_common

以下のようなメッセージが表示されれば成功。

Starting >>> audio_common_msgs
Finished <<< audio_common_msgs [7.50s]                     
Starting >>> audio_capture
Starting >>> audio_play                     
Starting >>> sound_play
Finished <<< sound_play [9.23s]                                                                                                 
--- stderr: audio_capture                                                                           
/root/ros2_ws/src/audio_common/audio_capture/src/audio_capture_node.cpp: In static member function ‘static gboolean audio_capture::AudioCaptureNode::onMessage(GstBus*, GstMessage*, gpointer)’:
/root/ros2_ws/src/audio_common/audio_capture/src/audio_capture_node.cpp:238:42: warning: unused parameter ‘bus’ [-Wunused-parameter]
  238 |       static gboolean onMessage (GstBus *bus, GstMessage *message, gpointer userData)
      |                                  ~~~~~~~~^~~
---
Finished <<< audio_capture [12.4s]
--- stderr: audio_play                                
/root/ros2_ws/src/audio_common/audio_play/src/audio_play_node.cpp: In static member function ‘static void audio_play::AudioPlayNode::cb_newpad(GstElement*, GstPad*, gpointer)’:
/root/ros2_ws/src/audio_common/audio_play/src/audio_play_node.cpp:158:41: warning: unused parameter ‘decodebin’ [-Wunused-parameter]
  158 |      static void cb_newpad (GstElement *decodebin, GstPad *pad,
      |                             ~~~~~~~~~~~~^~~~~~~~~
---
Finished <<< audio_play [16.7s]
Starting >>> audio_common
Finished <<< audio_common [1.35s]                   

Summary: 5 packages finished [26.5s]
  2 packages had stderr output: audio_capture audio_play

まとめ

ROS 2 Humbleでaudio_commonパッケージをビルドする手順を紹介した。ROS2 Humbleで音声関連のパッケージを利用したい場合は参考にしてほしい。音声再生の方法については、私の記事も参照してほしい。

参考

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?