ここでは、Armadillo上で実行するRTコンポーネントのビルド方法をについて説明します。 コンポーネントのビルドは、旧式 (RTCBuilder-1.0) のMakefileベースの方法と、新式 (RTCBuilder-1.1以降) のCMakeベースの方法の2通りがあります。
古いRTCBuilderで生成したコンポーネントには、UNIX系システム用のMakefileが付属していました。この場合は、非常に簡単で、環境変数CXXにarm用コンパイラ /usr/bin/arm-linux-gnu-g++ を指定するだけでも可能です。
$ CC=/usr/bin/arm-linux-gnu-g++ make
ただし、ATDE2 for OpenRTM-aist に付属の rtc-make-cross を使用すると、Armadillo-400シリーズでRTコンポーネントをビルドするときなども、同じ方法でビルドが可能です。 ここでは、rtc-make-cross を使用した方法について説明します。
OpenRTM-aistに付属のサンプルコンポーネント SeqOutComp を例に、ソースからクロスコンパイルしてみます。
OpenRTM-aistをインストールすると ${prefix}/share/openrtm-x.y/example/src 以下にサンプルコンポーネントのソースコードがインストールされます。 ATDE2 for OpenRTM-aist では、/usr/arm-linux-gnu/share/openrtm-1.1/example/src/ 以下にソースコードがインストールされています。これをコピーします。
atmark@atde:~$ mkdir tmp atmark@atde:~$ cd tmp atmark@atde:~/tmp$ atmark@atde:~/tmp$ cp -r /usr/arm-linux-gnu/share/openrtm-1.1/example/src/SeqIO . cd SeqIO atmark@atde:~/tmp/SeqIO$ ls Makefile.SeqIn README.SeqOut SeqInComp.cpp SeqOutComp.cpp rtc.conf Makefile.SeqOut SeqIn.cpp SeqOut.cpp component.conf README.SeqIn SeqIn.h SeqOut.h gen.sh
ディレクトリにはSeqInComopとSeqOutCompのソースコードが含まれています。
ここで、コンポーネントをビルド剃るには rtc-make-cross を使用します。 ATDE2 for OpenRTM-aist にすでにインストールされていますが、こちらからもダウンロードできます。
ダウンロードした場合、以下のようにして /usr/bin 等にインストールするとよいでしょう。
$ chmod 755 rtc-make-cross $ sudo install rtc-make-cross /usr/bin
-h オプションで rtc-make-cross のヘルプを見てみます。
atmark@atde:~/tmp/SeqIO$ rtc-make-cross -h Usage: rtc-make-cross -a <arch_name> [make options] -a target architecture name -h print this help Available architectures: arm powerpc
-a オプションでターゲットのアーキテクチャを指定して、makeコマンドの代わりに使用します。利用できるアーキテクチャのキーワードはここでは、arm と powerpc の2種類のようです。 rtc-make-cross は環境にインストールされているクロス開発環境を調べて、どのアーキテクチャのクロスコンパイルが可能かをヘルプで表示します。 ATDE2はデフォルトで arm と powerpc 用のクロス開発がインストールされているので、このように表示されます。Armadillo-200シリーズ用の実行ファイルは arm アーキテクチャとしてコンパイルする必要がありますので -a arm というオプションを指定します。
また、SeqOutComp をコンパイルするには Makefile.SeqOut という Makefile を使用します。makeコマンドでは特定のMakefileを指定するには -f オプションを使用しますので、-f Makefile.SeqOutを指定します。
atmark@atde:~/tmp/SeqIO$ rtc-make-cross -a arm -f Makefile.SeqOut Target architecture is arm (arm-linux-gnu) Toolchain found. CC: /usr/bin/arm-linux-gcc CXX: /usr/bin/arm-linux-g++ AR: /usr/bin/arm-linux-ar LD: /usr/bin/arm-linux-ld rm -f SeqOut.o /usr/bin/arm-linux-g++ `rtm-config --cflags` -c -o SeqOut.o SeqOut.cpp rm -f SeqOut.so /usr/bin/arm-linux-g++ -shared -o SeqOut.so SeqOut.o `rtm-config --libs` rm -f SeqOutComp.o /usr/bin/arm-linux-g++ `rtm-config --cflags` -c -o SeqOutComp.o SeqOutComp.cpp /usr/bin/arm-linux-g++ -o SeqOutComp SeqOut.o SeqOutComp.o `rtm-config --libs atmark@atde:~/tmp/SeqIO$ ls -al SeqOutComp -rwxr-xr-x 1 atmark atmark 283828 2012-09-08 01:32 SeqOutComp
作成された SeqOutComp というファイルがSeqOutCompコンポーネントの実行ファイルです。
作成されたコンポーネントをUSBメモリへコピーします。USBメモリへのコピーには、ATDE2 for OpenRTM-aist に付属の rtc2usbmem コマンドを使用します。
ATDE2 for OpenRTM-aist にすでにインストールされていますが、こちらからもダウンロードできます。
ダウンロードした場合、以下のようにして /usr/bin 等にインストールするとよいでしょう。
$ chmod 755 rtc-2usbmem $ sudo install rtc2usbmem /usr/bin
rtc2usbmemコマンドは、指定したRTコンポーネントとその依存ライブラリを探して、指定したディレクトリへコピーします。また、Armadilloに挿入した際にRTCを自動起動するためのブートスクリプトとrtc.confも指定ディレクトリへコピーします。 RTCが依存するライブラリを調べ、一つ一つコピーする必要が無いので、非常に簡単にArmadilloに挿入するUSBメモリファイルセットを作成することができます。
-hオプションを指定してヘルプを見てます。
atmark@atde:~/tmp/SeqIO$ rtc2usbmem -h Usage: rtc2usbmem -d <dir> -r <rtc> -l <libdir> This script creates a directory to be copied to USB memory for Armadillo execution environment. One or more RTCs can be specified by -r and are copied to rtc directory. Dependent libraries are automatically analyzed and copied to lib directory. boot.sh to launch RTCs and rtc.conf for RTCs are also created. -a Target architecture name -d <dir> Target directory -r <rtc> Target RTC binary -l <libdir> Library search path -x Do not copy RTM related libraries -h Print this help Available architectures: arm powerpc EXAMPLE $ cd my_component_dir $ ls mycomponent mycomponent.so $ rtc2usbmem -d /tmp/usbmem -r mycomponent -l . -l ../deplibdir
オプションの意味は以下のとおりです。
オプション | 意味 |
-a | ターゲットアーキテクチャ名を指定。-rで指定されるRTCのアーキテクチャと同一である必要がある。指定しなければRTCのアーキテクチャが利用される。 |
-d <dir> | ファイルをコピーする先のディレクトリ。既にディレクトリがある場合、削除するかどうか途中で尋ねられる。デフォルトは /tmp/usbmem。 |
-r <rtc> | 対象となるRTコンポーネント。複数指定可能。 |
-l <libdir> | 依存ライブラリを検索するパスを指定。複数指定可能。 |
-x | libRTM,libcoiなどRTミドルウエア関連ライブラリをコピーしない。RTC以外のプログラムとその依存ライブラリファイルセットを作成するときなどに利用。 |
-h | ヘルプの表示。 |
必須なのは、RTCを指定する -r オプションです。ここでは、ホームディレクトリに seqout というディレクトリを作成しそこに必要なファイルセットをコピーすることにします。 実行結果は以下のようになります。
atmark@atde:~/tmp/SeqIO$ rtc2usbmem -r SeqOutComp -d ~/seqout Now Armadillo's USB memory image is created. Target architecture: arm Target directory: /home/atmark/seqout Target RTCs: SeqOutComp Library search path: /usr/arm-linux-gnu Searching lib under /usr/arm-linux-gnu copying /usr/arm-linux-gnu/lib/libRTC-1.1.0.so -> /home/atmark/seqout/lib Searching lib under /usr/arm-linux-gnu copying /usr/arm-linux-gnu/lib/libcoil-1.1.0.so -> /home/atmark/seqout/lib copying /usr/arm-linux-gnu/lib/libuuid.so.1 -> /home/atmark/seqout/lib copying /usr/arm-linux-gnu/lib/libdl.so.2 -> /home/atmark/seqout/lib copying /usr/arm-linux-gnu/lib/libpthread.so.0 -> /home/atmark/seqout/lib copying /usr/arm-linux-gnu/lib/libomniORB4.so.1 -> /home/atmark/seqout/lib copying /usr/arm-linux-gnu/lib/libomnithread.so.3 -> /home/atmark/seqout/lib copying /usr/arm-linux-gnu/lib/libomniDynamic4.so.1 -> /home/atmark/seqout/lib copying /usr/arm-linux-gnu/lib/debug/libstdc++.so.6 -> /home/atmark/seqout/lib copying /usr/arm-linux-gnu/lib/libm.so.6 -> /home/atmark/seqout/lib copying /usr/arm-linux-gnu/lib/libc.so.6 -> /home/atmark/seqout/lib copying /usr/arm-linux-gnu/lib/libgcc_s.so.1 -> /home/atmark/seqout/lib copying SeqOutComp -> /home/atmark/seqout/rtc /home/atmark/seqout/boot.sh created. /home/atmark/seqout/rtc.conf created. NOTE: Edit /home/atmark/seqout/rtc.conf for your environment. Target binaries have been copied to: /home/atmark/seqout
コピーされたファイルを見てみます。
atmark@atde:~/tmp/SeqIO$ cd /home/atmark/seqout/ atmark@atde:~/seqout$ ls -R .: boot.sh lib rtc rtc.conf ./lib: libRTC-1.1.0.so libdl.so.2 libomniDynamic4.so.1 libpthread.so.0 libc.so.6 libgcc_s.so.1 libomniORB4.so.1 libstdc++.so.6 libcoil-1.1.0.so libm.so.6 libomnithread.so.3 libuuid.so.1 ./rtc: SeqOutComp
libディレクトリに依存ライブラリ、rtcディレクトリにRTコンポーネントがコピーされています。
このディレクトリをUSBメモリにコピーしてArmadilloに挿入すると、コンポーネントが自動的に起動します。
コンポーネントのトップディレクトリにCMakeList.txtがある場合は、RTCBuilder-1.1以降で作成されたコンポーネントになります。 ビルドにはCMakeを使用します。CMakeはMakefileやVisual C++用のプロジェクトファイル等様々なプラットフォームで様々なビルドシステムのためのファイルを生成するためのツールです。
Linux上では主にMakefileを生成するために使用されます。ビルド環境の様々な設定を判別し、最適なMakefileを生成します。コマンドは、バッチ的に処理するcmakeと、(テキストベースの)GUIで対話的に処理するccmakeの2つがあります。 RTコンポーネントのクロス開発には rtc-cmake-cross/rtc-ccmake-crossを利用します。
ATDE2 for OpenRTM-aist にすでにインストールされていますが、こちらからもダウンロードできます。
なお、rtc-cmake-cross/rtc-ccmake-cross は中身はrtc-make-crossと同一です。名前を変えると、それぞれの名前どおりの動作を刷るようになっています。ダウンロードした場合、以下のようにして /usr/bin 等にインストールするとよいでしょう。
$ chmod 755 rtc-make-cross $ sudo install rtc-make-cross /usr/bin $ sudo ln -s /usr/bin/rtc-make-cross /usr/bin/rtc-cmake-cross $ sudo ln -s /usr/bin/rtc-make-cross /usr/bin/rtc-ccmake-cross
-hオプションを与えてヘルプを見てみます。
Usage: rtc-cmake-cross -a <arch_name> [cmake options] -a target architecture name -h print this help Available architectures: arm powerpc
ターゲットアーキテクチャをしていする -a オプションを使用するところ以外は、使い方はcmakeとほとんど同じです。 rtc-make-cross同様、サポートしているアーキテクチャが arm と powerpc の2種類あることがわかります。
ここでは、Geofrey Biggs氏作の rtchokusyoaist コンポーネントのビルドを例に取り説明します。 rtchokuyoaistコンポーネントは北陽電機製レーザ測域センサ URG シリーズ用のRTコンポーネントです。URGセンサとArmadilloを組み合わせることで、分散センサコンポーネントを容易に実現することができます。
rtchokuyoaistコンポーネントは次の3つのパッケージをコンパイルする必要があります。
上記のURLから、ZIPボタンを押してダウンロードしてください。
tmark@atde:~/tmp/rtchokuyoaist$ ls gbiggs-flexiport-7ff727e.zip gbiggs-hokuyoaist-3.0.1-0-g69df78b.zip gbiggs-rtchokuyoaist-2.0.0-12-g43f93c7.zip atmark@atde:~/tmp/rtchokuyoaist$ find ./ -name '*zip' -exec unzip {} \; atmark@atde:~/tmp/rtchokuyoaist$ mv gbiggs-flexiport-7ff727e flexiport atmark@atde:~/tmp/rtchokuyoaist$ mv gbiggs-hokuyoaist-69df78b hokuyoaist atmark@atde:~/tmp/rtchokuyoaist$ mv gbiggs-rtchokuyoaist-43f93c7 rtchokuyoaist
まず、flexiport からビルドします。cmakeの習慣として build ディレクトリを作成し、その中でビルドします。
atmark@atde:~/tmp/rtchokuyoaist$ cd flexiport atmark@atde:~/tmp/rtchokuyoaist/flexiport$ mkdir build-cross atmark@atde:~/tmp/rtchokuyoaist/flexiport$ cd build-cross/ atmark@atde:~/tmp/rtchokuyoaist/flexiport/build-cross$ rtc-cmake-cross -a arm .. / Target architecture is arm (arm-linux-gnu) Toolchain found. CC: /usr/bin/arm-linux-gcc CXX: /usr/bin/arm-linux-g++ : 中略 -- Found Doxygen: /usr/bin/doxygen (found version "1.5.1") CMake Error at doc/CMakeLists.txt:8 (message): Sphinx was not found. Set SPHINX_PATH to the directory containing the sphinx-build executable, or disable BUILD_DOCUMENTATION. -- Configuring incomplete, errors occurred! Configure failed. Check CMake options and configuration variables.
どうやらSphinxが足りないようです。ドキュメントは不要なので、BUILD_DOCUMENTATION 変数を OFFに設定してみましょう。
atmark@atde:~/tmp/rtchokuyoaist/flexiport/build-cross$ rtc-cmake-cross -a arm -DBUILD_DOCUMENTATION=OFF ../ Target architecture is arm (arm-linux-gnu) : 中略 -- Configuring done -- Generating done CMake Warning: Manually-specified variables were not used by the project: CMAKE_TOOLCHAIN_FILE -- Build files have been written to: /home/atmark/tmp/rtchokuyoaist/flexiport/build-cross Configure done. Type 'make' and build program.
今度はうまくいったようです。Makefileができたのでmakeします。
atmark@atde:~/tmp/rtchokuyoaist/flexiport/build-cross$ make Scanning dependencies of target flexiport [ 7%] Building CXX object src/CMakeFiles/flexiport.dir/flexiport.cpp.o [ 15%] Building CXX object src/CMakeFiles/flexiport.dir/port.cpp.o : 中略 Linking CXX executable flexiport_udp_example [100%] Built target flexiport_udp_example
これで、libflexiport.so というライブラリファイルが出来ました。 これをシステムのクロス開発環境にインストールします。
atmark@atde:~/tmp/rtchokuyoaist/flexiport/build-cross$ ls src/libflexiport.so* src/libflexiport.so src/libflexiport.so.2 src/libflexiport.so.2.0.0」 tmark@atde:~/tmp/rtchokuyoaist/flexiport/build-cross$ sudo make install Password: [ 69%] Built target flexiport : 中略 -- Installing: /usr/arm-linux-gnu/lib/flexiport/flexiportDepends.cmake -- Installing: /usr/arm-linux-gnu/lib/flexiport/flexiportDepends-noconfig.cmake
flexiport同様にrtc-cmake-crossを実行、ライブラリをビルドします。
atmark@atde:~/tmp/rtchokuyoaist$ cd hokuyoaist/ atmark@atde:~/tmp/rtchokuyoaist/hokuyoaist$ mkdir build-cross atmark@atde:~/tmp/rtchokuyoaist/hokuyoaist$ cd build-cross/ atmark@atde:~/tmp/rtchokuyoaist/hokuyoaist/build-cross$ rtc-cmake-cross -a arm -DBUILD_DOCUMENTATION=OFF ../ Target architecture is arm (arm-linux-gnu) : 中略 -- Build files have been written to: /home/atmark/tmp/rtchokuyoaist/hokuyoaist/build-cross Configure done. Type 'make' and build program. atmark@atde:~/tmp/rtchokuyoaist/hokuyoaist/build-cross$ make Scanning dependencies of target hokuyoaist [ 16%] Building CXX object src/CMakeFiles/hokuyoaist.dir/hokuyo_errors.cpp.o : 中略 [100%] Building CXX object examples/CMakeFiles/hokuyoaist_getid.dir/getid.cpp.o Linking CXX executable hokuyoaist_getid [100%] Built target hokuyoaist_getid atmark@atde:~/tmp/rtchokuyoaist/hokuyoaist
これもライブラリなので、インストールします。
atmark@atde:~/tmp/rtchokuyoaist/hokuyoaist/build-cross$ sudo make install [ 66%] Built target hokuyoaist [ 83%] Built target hokuyoaist_example : 中略 -- Installing: /usr/arm-linux-gnu/lib/hokuyoaist/hokuyoaistDepends.cmake -- Installing: /usr/arm-linux-gnu/lib/hokuyoaist/hokuyoaistDepends-noconfig.cmake atmark@atde:~/tmp/rtchokuyoaist/hokuyoaist/build-cross$
最後にRTコンポーネントであるrtchokuyoaistをビルドします。
atmark@atde:~/tmp/rtchokuyoaist/hokuyoaist/build-cross$ cd ../../rtchokuyoaist/ atmark@atde:~/tmp/rtchokuyoaist/rtchokuyoaist$ mkdir build-cross atmark@atde:~/tmp/rtchokuyoaist/rtchokuyoaist$ cd build-cross/ atmark@atde:~/tmp/rtchokuyoaist/rtchokuyoaist/build-cross$ rtc-cmake-cross -a arm -DBUILD_DOCUMENTATION=OFF ../ Target architecture is arm (arm-linux-gnu) Toolchain found. CC: /usr/bin/arm-linux-gcc :中略 CMake Error at /usr/share/cmake-2.8/Modules/FindPackageHandleStandardArgs.cmake:97 (MESSAGE): Could NOT find OpenRTM (missing: OPENRTM_INCLUDE_DIR COIL_INCLUDE_DIR) (Required is at least version "1") Call Stack (most recent call first): /usr/share/cmake-2.8/Modules/FindPackageHandleStandardArgs.cmake:288 (_FPHSA_FAILURE_MESSAGE) cmake/Modules/FindOpenRTM.cmake:75 (find_package_handle_standard_args) CMakeLists.txt:39 (find_package) -- Configuring incomplete, errors occurred! Configure failed. Check CMake options and configuration variables.
おや、エラーが出ました。missing OPENRTM_INCLUDE_DIR COIL_INCLUDE_DIR とあるので、これらの変数が上手くセット出来なかったようです。 それぞれOpenRTMとcoilのインクルードディレクトリなので場所は以下のとおりになります。
ですので、以下のように変数を指定します。
$ rtc-cmake-cross -a arm -DBUILD_DOCUMENTATION=OFF -DOPENRTM_INCLUDE_DIR=/usr/arm-linux-gnu/include/openrtm-1.1/ -DCOIL_INCLUDE_DIR=/usr/arm-linux-gnu/include/coil-1.1/ ../
あるいは、ccmake を利用して対話的にこれらの変数を与えることもできて、
atmark@atde:~/tmp/rtchokuyoaist/rtchokuyoaist/build-cross$ rtc-ccmake-cross -a arm -DBUILD_DOCUMENTATION=OFF ../
のように rtc-ccmake-crossを実行して、ccmakeを起動します。
Page 1 of 1 BUILD_EXAMPLES ON CMAKE_BUILD_TYPE COIL_INCLUDE_DIR /usr/arm-linux-gnu/include/coil-1.1 COIL_LIBRARY /usr/arm-linux-gnu/lib/libcoil.so OPENRTM_IDL_DIR /usr/arm-linux-gnu/include/openrtm-./rtm/idl OPENRTM_INCLUDE_DIR /usr/arm-linux-gnu/include/openrtm-1.1/ OPENRTM_LIBRARY /usr/arm-linux-gnu/lib/libRTC.so PROJECT_VERSION 3.0.0 STATIC_LIBS OFF BUILD_EXAMPLES: Build and install examples Press [enter] to edit option CMake Version 2.8.9 Press [ c ] to configure Press [ h ] for help Press [ q ] to quit without generating Press [ t ] to toggle advanced mode (Currently Off)
OPENRTM_INCLUDE_DIR、COIL_INCLUDE_DIRそれぞれの場所でReturnキーを押して、パスを入力します。 cを押しconfigureをします。cを再度押し、次にgを押してMakefileを生成 (generate) します。最後にeを押して対話画面を抜けます。 これで、Makefileが生成されているはずですので、makeします。
atmark@atde:~/tmp/rtchokuyoaist/rtchokuyoaist/build-cross$ make Scanning dependencies of target hokuyoaist_TGT [ 10%] Compiling /home/atmark/tmp/rtchokuyoaist/rtchokuyoaist/idl/hokuyoaist.idl :中略 [ 80%] Building CXX object src/CMakeFiles/rtchokuyoaist.dir/__/idl/hokuyoaistSK.cc.o [ 90%] Building CXX object src/CMakeFiles/rtchokuyoaist.dir/__/idl/hokuyoaistDynSK.cc.o Linking CXX shared library librtchokuyoaist.so [ 90%] Built target rtchokuyoaist Scanning dependencies of target rtchokuyoaist_standalone atmark@atde:~/tmp/rtchokuyoaist/rtchokuyoaist/build-cross$ ls src/ CMakeFiles cmake_install.cmake rtchokuyoaist_standalone Makefile librtchokuyoaist.so
上述の SeqOutComp と同様 rtc2usbmem コマンドを使って、USBメモリにコピーするためのファイルセットを作成します。ターゲットディレクトリは ~/rtchokuyo とします。
atmark@atde:~/tmp/rtchokuyoaist/rtchokuyoaist/build-cross$ rtc2usbmem -d ~/rtchokuyo -r src/rtchokuyoaist_standalone Now Armadillo's USB memory image is created. Target architecture: arm Target directory: /home/atmark/rtchokuyo Target RTCs: src/rtchokuyoaist_standalone Library search path: /usr/arm-linux-gnu Searching lib under /usr/arm-linux-gnu copying /usr/arm-linux-gnu/lib/libRTC-1.1.0.so -> /home/atmark/rtchokuyo/lib Searching lib under /usr/arm-linux-gnu copying /usr/arm-linux-gnu/lib/libcoil-1.1.0.so -> /home/atmark/rtchokuyo/lib :中略 copying src/rtchokuyoaist_standalone -> /home/atmark/rtchokuyo/rtc copying /usr/arm-linux-gnu/lib/libhokuyoaist.so.3 -> /home/atmark/rtchokuyo/lib copying /usr/arm-linux-gnu/lib/libflexiport.so.2 -> /home/atmark/rtchokuyo/lib /home/atmark/rtchokuyo/boot.sh created. /home/atmark/rtchokuyo/rtc.conf created. NOTE: Edit /home/atmark/rtchokuyo/rtc.conf for your environment. Target binaries have been copied to: /home/atmark/rtchokuyo
ご覧のように、rtchokuyoaist コンポーネントの依存ライブラリである、libflexiport.soやlibhokuyoaist.soなどもコピーされています。
~/rtchokuyo ディレクトリ以下のファイルをUSBメモリにコピーし、rtc.confを編集してからArmadilloに挿入するとコンポーネントが起動します。
次章では、USBメモリファイルセットを実際にUSBメモリにコピーしコンポーネントを起動してみます。