OpenHRP3講座(その3)
コントローラ作成
コントローラの作成を行います。WindowsVistaとVC2008で作ります。サンプルプログラムはここ。
まず、RtcLink・RtcTemplate が要ります。OpenRTM-aistのRtcLink・RtcTemplateのダウンロードのページから、前部入りパッケージのいちばん上のEclipse3.2+RtcLink(0.4.1)+RtcTemplate(0.4.2)Windows用全部入りをダウンロードして解凍して、好きなところにおいてください。OpenHRP3.1.0betaのインストールのときにすでに入れてるかな?
OpenHRP3のページに
"C:\Program Files\OpenRTM-aist\0.4\utils\rtc-template\rtc-template.py"
-bcxx ^ --module-name=SamplePD --module-desc="SamplePD component"
^ --module-version=0.1 --module-vendor=AIST --module-category=Generic ^
--module-comp-type=DataFlowComponent --module-act-type=SPORADIC ^ --module-max-inst=1
^ --inport=angle:TimedDoubleSeq ^ --outport=torque:TimedDoubleSeq
というパッチを用意しろと書いてるのでとりあえず用意します。これを実行すれば勝手にVCプロジェクトファイルを作ってくれます。
RtcTemplateで作る場合は以下のように入力します。
Programming language selection | C++ | |
モジュール定義 | Module name | SamplePD |
Module description | SamplePD component | |
Module version | 0.1 | |
Module vender | あなたの名前 | |
Module category | Generic | |
Component type | DataFlowComponent | |
Component's activity type | SPORADIC | |
Number of maximum instance | 1 | |
InPort definition | angle | |
TimedDoubleSeq | ||
OutPort definition | torque | |
TimedDoubleSeq | ||
Output directory | 適当なフォルダ |
プロジェクトファイルを作ったフォルダのcopypropsというパッチを実行してください。
そのあとSamplePD_vc9.slnを開いてください。
そのあと、下の図の赤で囲んでいるところをDebugからReleaseにしてください。
そして、SamplePD.hの150行目のvoid SamplePDInit(RTC::Manager* manager)の先頭にDLL_EXPORTを付け加えてください。
あとは、49行目のvirtual RTC::ReturnCode_t onInitialize()、65行目の virtual RTC::ReturnCode_t
onActivated(RTC::UniqueId ec_id);、73行目のvirtual RTC::ReturnCode_t onExecute(RTC::UniqueId
ec_id);のコメント文をはずしてください。
SamplePD.cppの50行目付近に m_torque.data.length(NUM); m_angle.data.length(NUM);を付け加えてください。
ただし、NUMは制御するアクチュエータの個数で自由に決めてください。今回は1でもいいです。
あとは65行目付近のRTC::ReturnCode_t SamplePD::onInitialize()、93行目付近のRTC::ReturnCode_t
SamplePD::onActivated(RTC::UniqueId ec_id)、103行目付近のRTC::ReturnCode_t SamplePD::onExecute(RTC::UniqueId
ec_id)のコメント文はずしてください。
onExecute(RTC::UniqueId ec_id)にm_torque.data[0] = 0; m_torqueOut.write();と付け加えてください。
これで0番のアクチュエータに0のトルクが働きます。すなわち蛇型ロボットのサンプルでいえば先頭と2番目のリンクの間の関節が駆動します。
あとは
とSamplePDとSamplePDCompを選択後、右クリックでビルドを選択してください。
エラーが0なら成功です。警告の数は気にしないでください。
あとは3.0系であればOpenHRP3のサンプルコントローラのSamplePDのbridge.conf、rtc.confを、3.1系であればSamplePD.batとrtc.confをコントローラ作ったフォルダのconponentsにコピーしてください。
SamplePDと名前を付けながら全くPD制御してませんが、今回は形だけしか作らないので構いません。
あとはTemplate、bridge.conf(またはSamplePD.bat)内の名前を変えるだけですし、C++ができれば制御用のプログラムも書けます。
次回はGrxUIでこのコントローラを使ってみます。