Okdo LiDAR Module with Bracket開発キット LiDAR_LD06のROS1ビルド方法を解説

  • URLをコピーしました!

※本ページはアフィリエイト広告を利用しています

Raspberry PiのHATとして使用でき、1万円以下で購入できる安価なLiDAR「Okdo Lidar Module with Bracket開発キット LiDAR_LD06」を使用する際に必要となるROS(Robot Operating System)のビルド方法について解説します。

2024年1月現在、ライブラリのバージョンアップなどにより、公式のセットアップスクリプトを実行してビルドを行うとインタフェース不整合などの原因でエラーが出てしまうため、その対処法についてまとめました。

目次

Okdo LiDAR公式チュートリアル

以下がOkdo LiDAR公式のチュートリアルとなります。こちらの手順に沿ってビルドを進めていきます。

Raspberry Pi OSのダウンロード

ROSを動作させるためには、Raspberry Pi OSはbusterでなければいけないということで、以下のサイトからダウンロードしてブートイメージを作成しました。

ページにアクセスしたら「2021-05-07-raspios-buster-armhf-full.zip」ダウンロードしてください。

ROSをビルドする

ここからは実際にROSをビルドする手順を解説します

ビルドを実行する

GitHubからリポジトリをクローンし、ビルドを行うためのlidar_ros_setup.shというスクリプトを実行します。(かなり時間がかかります)

git clone https://github.com/LetsOKdo/sdk_ld06_raspberry_ros.git
cd sdk_ld06_rasberry_ros 
./lidar_ros_setup.sh

公式チュートリアルによるとこれだけでビルドが完了すると書かれているのですが、実際はビルドエラーが発生します。

発生したビルドエラー

私の環境では、ビルド中に以下のようなエラーが発生しました。

==> Processing catkin package: 'actionlib_msgs'
==> Building with env: '/opt/ros/melodic/env.sh'
==> cmake /home/pi/ros_catkin_ws/src/common_msgs/actionlib_msgs -DCATKIN_DEVEL_PREFIX=/home/pi/ros_catkin_ws/devel_isolated/actionlib_msgs -DCMAKE_INSTALL_PREFIX=/opt/ros/melodic -DCMAKE_BUILD_TYPE=Release -G Unix Makefiles in '/home/pi/ros_catkin_ws/build_isolated/actionlib_msgs'
-- Using CATKIN_DEVEL_PREFIX: /home/pi/ros_catkin_ws/devel_isolated/actionlib_msgs
-- Using CMAKE_PREFIX_PATH: /opt/ros/melodic
-- This workspace overlays: /opt/ros/melodic
-- Found PythonInterp: /usr/bin/python2 (found suitable version "2.7.16", minimum required is "2") 
-- Using PYTHON_EXECUTABLE: /usr/bin/python2
-- Using Debian Python package layout
-- Using empy: /usr/bin/empy
-- Using CATKIN_ENABLE_TESTING: ON
-- Call enable_testing()
-- Using CATKIN_TEST_RESULTS_DIR: /home/pi/ros_catkin_ws/build_isolated/actionlib_msgs/test_results
-- Forcing gtest/gmock from source, though one was otherwise available.
-- Found gtest sources under '/usr/src/googletest': gtests will be built
-- Found gmock sources under '/usr/src/googletest': gmock will be built
-- Found PythonInterp: /usr/bin/python2 (found version "2.7.16") 
-- Using Python nosetests: /usr/bin/nosetests-2.7
-- catkin 0.7.29
-- BUILD_SHARED_LIBS is on
-- Using these message generators: gencpp;geneus;genlisp;gennodejs;genpy
CMake Error at /home/pi/ros_catkin_ws/build_isolated/actionlib_msgs/cmake/actionlib_msgs-genmsg.cmake:3 (message):
  Could not find messages which
  '/home/pi/ros_catkin_ws/src/common_msgs/actionlib_msgs/msg/GoalStatusArray.msg'
  depends on.  Did you forget to specify generate_messages(DEPENDENCIES ...)?

  Cannot locate message [Header] in package [std_msgs] with paths
  [['/home/pi/ros_catkin_ws/devel_isolated/std_msgs/share/std_msgs/cmake/../msg']]
Call Stack (most recent call first):
  /home/pi/ros_catkin_ws/devel_isolated/genmsg/share/genmsg/cmake/genmsg-extras.cmake:307 (include)
  CMakeLists.txt:12 (generate_messages)


-- Configuring incomplete, errors occurred!
See also "/home/pi/ros_catkin_ws/build_isolated/actionlib_msgs/CMakeFiles/CMakeOutput.log".
See also "/home/pi/ros_catkin_ws/build_isolated/actionlib_msgs/CMakeFiles/CMakeError.log".
<== Failed to process package 'actionlib_msgs': 
  Command '['/opt/ros/melodic/env.sh', 'cmake', '/home/pi/ros_catkin_ws/src/common_msgs/actionlib_msgs', '-DCATKIN_DEVEL_PREFIX=/home/pi/ros_catkin_ws/devel_isolated/actionlib_msgs', '-DCMAKE_INSTALL_PREFIX=/opt/ros/melodic', '-DCMAKE_BUILD_TYPE=Release', '-G', 'Unix Makefiles']' returned non-zero exit status 1

Reproduce this error by running:
==> cd /home/pi/ros_catkin_ws/build_isolated/actionlib_msgs && /opt/ros/melodic/env.sh cmake /home/pi/ros_catkin_ws/src/common_msgs/actionlib_msgs -DCATKIN_DEVEL_PREFIX=/home/pi/ros_catkin_ws/devel_isolated/actionlib_msgs -DCMAKE_INSTALL_PREFIX=/opt/ros/melodic -DCMAKE_BUILD_TYPE=Release -G 'Unix Makefiles'

Command failed, exiting.

ビルドエラーの対策

エラーメッセージから、actionlib_msgs パッケージのビルド中に、依存するメッセージが見つからないという問題が発生しています。

具体的には、GoalStatusArray.msg が依存する std_msgs/Header が見つからないというエラーが出ています。

依存関係の確認とインストール

rosdep を使用して、必要な依存関係がすべてインストールされているか確認し、足りないものがあればインストールします。

rosdep install --from-paths src --ignore-src -r -y

再ビルド

再ビルドを行います。

cd ~/ros_catkin_ws
catkin_make_isolated -j1

以下のように再びビルド中にエラーが発生しました。

==> Processing catkin package: 'actionlib_msgs'
==> Building with env: '/opt/ros/melodic/env.sh'
==> cmake /home/pi/ros_catkin_ws/src/common_msgs/actionlib_msgs -DCATKIN_DEVEL_PREFIX=/home/pi/ros_catkin_ws/devel_isolated/actionlib_msgs -DCMAKE_INSTALL_PREFIX=/opt/ros/melodic -DCMAKE_BUILD_TYPE=Release -G Unix Makefiles in '/home/pi/ros_catkin_ws/build_isolated/actionlib_msgs'
-- Using CATKIN_DEVEL_PREFIX: /home/pi/ros_catkin_ws/devel_isolated/actionlib_msgs
-- Using CMAKE_PREFIX_PATH: /opt/ros/melodic
-- This workspace overlays: /opt/ros/melodic
-- Found PythonInterp: /usr/bin/python2 (found suitable version "2.7.16", minimum required is "2") 
-- Using PYTHON_EXECUTABLE: /usr/bin/python2
-- Using Debian Python package layout
-- Using empy: /usr/bin/empy
-- Using CATKIN_ENABLE_TESTING: ON
-- Call enable_testing()
-- Using CATKIN_TEST_RESULTS_DIR: /home/pi/ros_catkin_ws/build_isolated/actionlib_msgs/test_results
-- Forcing gtest/gmock from source, though one was otherwise available.
-- Found gtest sources under '/usr/src/googletest': gtests will be built
-- Found gmock sources under '/usr/src/googletest': gmock will be built
-- Found PythonInterp: /usr/bin/python2 (found version "2.7.16") 
-- Using Python nosetests: /usr/bin/nosetests-2.7
-- catkin 0.7.29
-- BUILD_SHARED_LIBS is on
-- Using these message generators: gencpp;geneus;genlisp;gennodejs;genpy
CMake Error at /home/pi/ros_catkin_ws/build_isolated/actionlib_msgs/cmake/actionlib_msgs-genmsg.cmake:3 (message):
  Could not find messages which
  '/home/pi/ros_catkin_ws/src/common_msgs/actionlib_msgs/msg/GoalStatusArray.msg'
  depends on.  Did you forget to specify generate_messages(DEPENDENCIES ...)?

  Cannot locate message [Header] in package [std_msgs] with paths
  [['/home/pi/ros_catkin_ws/devel_isolated/std_msgs/share/std_msgs/cmake/../msg']]
Call Stack (most recent call first):
  /home/pi/ros_catkin_ws/devel_isolated/genmsg/share/genmsg/cmake/genmsg-extras.cmake:307 (include)
  CMakeLists.txt:12 (generate_messages)


-- Configuring incomplete, errors occurred!
See also "/home/pi/ros_catkin_ws/build_isolated/actionlib_msgs/CMakeFiles/CMakeOutput.log".
See also "/home/pi/ros_catkin_ws/build_isolated/actionlib_msgs/CMakeFiles/CMakeError.log".
<== Failed to process package 'actionlib_msgs': 
  Command '['/opt/ros/melodic/env.sh', 'cmake', '/home/pi/ros_catkin_ws/src/common_msgs/actionlib_msgs', '-DCATKIN_DEVEL_PREFIX=/home/pi/ros_catkin_ws/devel_isolated/actionlib_msgs', '-DCMAKE_INSTALL_PREFIX=/opt/ros/melodic', '-DCMAKE_BUILD_TYPE=Release', '-G', 'Unix Makefiles']' returned non-zero exit status 1

Reproduce this error by running:
==> cd /home/pi/ros_catkin_ws/build_isolated/actionlib_msgs && /opt/ros/melodic/env.sh cmake /home/pi/ros_catkin_ws/src/common_msgs/actionlib_msgs -DCATKIN_DEVEL_PREFIX=/home/pi/ros_catkin_ws/devel_isolated/actionlib_msgs -DCMAKE_INSTALL_PREFIX=/opt/ros/melodic -DCMAKE_BUILD_TYPE=Release -G 'Unix Makefiles'

Command failed, exiting.
==> Processing catkin package: 'actionlib_msgs'
==> Building with env: '/opt/ros/melodic/env.sh'
==> cmake /home/pi/ros_catkin_ws/src/common_msgs/actionlib_msgs -DCATKIN_DEVEL_PREFIX=/home/pi/ros_catkin_ws/devel_isolated/actionlib_msgs -DCMAKE_INSTALL_PREFIX=/opt/ros/melodic -DCMAKE_BUILD_TYPE=Release -G Unix Makefiles in '/home/pi/ros_catkin_ws/build_isolated/actionlib_msgs'
-- Using CATKIN_DEVEL_PREFIX: /home/pi/ros_catkin_ws/devel_isolated/actionlib_msgs
-- Using CMAKE_PREFIX_PATH: /opt/ros/melodic
-- This workspace overlays: /opt/ros/melodic
-- Found PythonInterp: /usr/bin/python2 (found suitable version "2.7.16", minimum required is "2") 
-- Using PYTHON_EXECUTABLE: /usr/bin/python2
-- Using Debian Python package layout
-- Using empy: /usr/bin/empy
-- Using CATKIN_ENABLE_TESTING: ON
-- Call enable_testing()
-- Using CATKIN_TEST_RESULTS_DIR: /home/pi/ros_catkin_ws/build_isolated/actionlib_msgs/test_results
-- Forcing gtest/gmock from source, though one was otherwise available.
-- Found gtest sources under '/usr/src/googletest': gtests will be built
-- Found gmock sources under '/usr/src/googletest': gmock will be built
-- Found PythonInterp: /usr/bin/python2 (found version "2.7.16") 
-- Using Python nosetests: /usr/bin/nosetests-2.7
-- catkin 0.7.29
-- BUILD_SHARED_LIBS is on
-- Using these message generators: gencpp;geneus;genlisp;gennodejs;genpy
CMake Error at /home/pi/ros_catkin_ws/build_isolated/actionlib_msgs/cmake/actionlib_msgs-genmsg.cmake:3 (message):
  Could not find messages which
  '/home/pi/ros_catkin_ws/src/common_msgs/actionlib_msgs/msg/GoalStatusArray.msg'
  depends on.  Did you forget to specify generate_messages(DEPENDENCIES ...)?

  Cannot locate message [Header] in package [std_msgs] with paths
  [['/home/pi/ros_catkin_ws/devel_isolated/std_msgs/share/std_msgs/cmake/../msg']]
Call Stack (most recent call first):
  /home/pi/ros_catkin_ws/devel_isolated/genmsg/share/genmsg/cmake/genmsg-extras.cmake:307 (include)
  CMakeLists.txt:12 (generate_messages)


-- Configuring incomplete, errors occurred!
See also "/home/pi/ros_catkin_ws/build_isolated/actionlib_msgs/CMakeFiles/CMakeOutput.log".
See also "/home/pi/ros_catkin_ws/build_isolated/actionlib_msgs/CMakeFiles/CMakeError.log".
<== Failed to process package 'actionlib_msgs': 
  Command '['/opt/ros/melodic/env.sh', 'cmake', '/home/pi/ros_catkin_ws/src/common_msgs/actionlib_msgs', '-DCATKIN_DEVEL_PREFIX=/home/pi/ros_catkin_ws/devel_isolated/actionlib_msgs', '-DCMAKE_INSTALL_PREFIX=/opt/ros/melodic', '-DCMAKE_BUILD_TYPE=Release', '-G', 'Unix Makefiles']' returned non-zero exit status 1

Reproduce this error by running:
==> cd /home/pi/ros_catkin_ws/build_isolated/actionlib_msgs && /opt/ros/melodic/env.sh cmake /home/pi/ros_catkin_ws/src/common_msgs/actionlib_msgs -DCATKIN_DEVEL_PREFIX=/home/pi/ros_catkin_ws/devel_isolated/actionlib_msgs -DCMAKE_INSTALL_PREFIX=/opt/ros/melodic -DCMAKE_BUILD_TYPE=Release -G 'Unix Makefiles'

Command failed, exiting.

エラーメッセージから、actionlib_msgs パッケージのビルド中に、依存するメッセージが見つからないという問題が発生しています。

具体的には、GoalStatusArray.msg が依存する std_msgs/Header が見つからないというエラーが出ています。

ビルドプロセスのエラーログを確認

以下のコマンドを実行してエラーログの確認を行います。

cat ~/ros_catkin_ws/build_isolated/std_msgs/CMakeFiles/CMakeError.log

以下のようなログが出力されていました。

pi@raspberrypi:~/ros_catkin_ws/build_isolated/std_msgs/CMakeFiles $ cat ~/ros_catkin_ws/build_isolated/std_msgs/CMakeFiles/CMakeError.log
Performing C SOURCE FILE Test CMAKE_HAVE_LIBC_PTHREAD failed with the following output:
Change Dir: /home/pi/ros_catkin_ws/build_isolated/std_msgs/CMakeFiles/CMakeTmp

Run Build Command(s):/usr/bin/make cmTC_d786d/fast && /usr/bin/make -f CMakeFiles/cmTC_d786d.dir/build.make CMakeFiles/cmTC_d786d.dir/build
make[1]: ディレクトリ '/home/pi/ros_catkin_ws/build_isolated/std_msgs/CMakeFiles/CMakeTmp' に入ります
Building C object CMakeFiles/cmTC_d786d.dir/src.c.o
/usr/bin/cc   -DCMAKE_HAVE_LIBC_PTHREAD   -o CMakeFiles/cmTC_d786d.dir/src.c.o   -c /home/pi/ros_catkin_ws/build_isolated/std_msgs/CMakeFiles/CMakeTmp/src.c
Linking C executable cmTC_d786d
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_d786d.dir/link.txt --verbose=1
/usr/bin/cc  -DCMAKE_HAVE_LIBC_PTHREAD    -rdynamic CMakeFiles/cmTC_d786d.dir/src.c.o  -o cmTC_d786d 
/usr/bin/ld: CMakeFiles/cmTC_d786d.dir/src.c.o: in function `main':
src.c:(.text+0x40): undefined reference to `pthread_create'
/usr/bin/ld: src.c:(.text+0x4c): undefined reference to `pthread_detach'
/usr/bin/ld: src.c:(.text+0x5c): undefined reference to `pthread_join'
collect2: error: ld returned 1 exit status
make[1]: *** [CMakeFiles/cmTC_d786d.dir/build.make:87: cmTC_d786d] エラー 1
make[1]: ディレクトリ '/home/pi/ros_catkin_ws/build_isolated/std_msgs/CMakeFiles/CMakeTmp' から出ます
make: *** [Makefile:121: cmTC_d786d/fast] エラー 2


Source file was:
#include <pthread.h>

void* test_func(void* data)
{
  return data;
}

int main(void)
{
  pthread_t thread;
  pthread_create(&thread, NULL, test_func, NULL);
  pthread_detach(thread);
  pthread_join(thread, NULL);
  pthread_atfork(NULL, NULL, NULL);
  pthread_exit(NULL);

  return 0;
}

Determining if the function pthread_create exists in the pthreads failed with the following output:
Change Dir: /home/pi/ros_catkin_ws/build_isolated/std_msgs/CMakeFiles/CMakeTmp

Run Build Command(s):/usr/bin/make cmTC_46b87/fast && /usr/bin/make -f CMakeFiles/cmTC_46b87.dir/build.make CMakeFiles/cmTC_46b87.dir/build
make[1]: ディレクトリ '/home/pi/ros_catkin_ws/build_isolated/std_msgs/CMakeFiles/CMakeTmp' に入ります
Building C object CMakeFiles/cmTC_46b87.dir/CheckFunctionExists.c.o
/usr/bin/cc   -DCHECK_FUNCTION_EXISTS=pthread_create   -o CMakeFiles/cmTC_46b87.dir/CheckFunctionExists.c.o   -c /usr/share/cmake-3.16/Modules/CheckFunctionExists.c
Linking C executable cmTC_46b87
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_46b87.dir/link.txt --verbose=1
/usr/bin/cc  -DCHECK_FUNCTION_EXISTS=pthread_create    -rdynamic CMakeFiles/cmTC_46b87.dir/CheckFunctionExists.c.o  -o cmTC_46b87  -lpthreads 
/usr/bin/ld: -lpthreads が見つかりません
collect2: error: ld returned 1 exit status
make[1]: *** [CMakeFiles/cmTC_46b87.dir/build.make:87: cmTC_46b87] エラー 1
make[1]: ディレクトリ '/home/pi/ros_catkin_ws/build_isolated/std_msgs/CMakeFiles/CMakeTmp' から出ます
make: *** [Makefile:121: cmTC_46b87/fast] エラー 2

エラーログを確認すると、pthread 関連の関数(特に pthread_create)が見つからないというリンクエラーが発生していることがわかります。

この問題は、pthreadライブラリが正しくリンクされていないことが原因で発生しています。

pthreadライブラリのインストール確認

pthreadライブラリがシステムにインストールされていることを確認します。通常はデフォルトでインストールされていますが、確認するには以下のコマンドを実行します。

sudo apt-get update
sudo apt-get install libpthread-stubs0-dev

ROS環境のソース化

そのままではビルドコマンドが実行できないため、ROSの環境を再度ソース化を行います。

source /opt/ros/melodic/setup.bash

ビルドコマンドの再実行

環境をソース化した後、再度ビルドコマンドを実行します。

catkin_make_isolated -j1

このように表示されたらビルド成功です。Raspberry Piを再起動してください。

ROSの動作テスト

Raspberry Piを再起動したら、ROSが正しく動作するかをテストするため、以下のコマンドを実行します。

roscore

以下のようにROSのバージョンなどが表示され、started core serviceと表示されたら正しく動作しています。

まとめ

今回はOkdo LiDARを使用する際のROSのビルド方法について解説しました。

ビルドエラーの解決にかなり苦労したため、同じようなエラーが発生している方は参考にしてみてください。

ROSのセットアップ後に行う、ld06 LiDARドライバのセットアップ方法については以下の記事で解説しています。

Raspberry Piの様々な活用方法について以下のページで解説していますので、あわせてご覧ください。

それでは、また次の記事でお会いしましょう。

参考

よかったらシェアしてね!
  • URLをコピーしました!

コメント

コメントする

CAPTCHA


目次