前回作成したPeriodicConsoleOutクラスに,int型のコンフィギュレーション変数を加えて,RtcLinkから設定した数値をコンソールに周期的に表示するプログラムに改造していきます.
まず,PeriodicConsoleOutクラスヘッダーのprotectedな領域に,int m_configとして,コンフィグ用の変数を宣言します.
// The action that is invoked when execution context's rate is changed
// no corresponding operation exists in OpenRTm-aist-0.2.0
// virtual RTC::ReturnCode_t onRateChanged(RTC::UniqueId ec_id);
protected:
int m_config;
// <rtc-template block="protected_attribute">
// </rtc-template>
つぎに,初期設定のための関数を利用しますので,onInitialize関数のコメントアウトを外します.
// </rtc-template>
// The initialize action (on CREATED->ALIVE transition)
// formaer rtc_init_entry()
virtual RTC::ReturnCode_t onInitialize();
// The finalize action (on ALIVE->END transition)
// formaer rtc_exiting_entry()
// virtual RTC::ReturnCode_t onFinalize();
これでヘッダファイルの変更は終了
次にCPPファイルです.こちらは変更する部分が多いです.
まず,ファイル冒頭のperiodicconsoleout_specという文字列の配列に,新たな文字列を加えます.コレによってコンポーネントの設定を変更できます.
追加するのは,"conf.default.config"と,"1"です.ちなみに最後の文字列は空白文字列にして置いてください.
// Module specification
// <rtc-template block="module_spec">
static const char* periodicconsoleout_spec[] =
{
"implementation_id", "PeriodicConsoleOut",
"type_name", "PeriodicConsoleOut",
"description", "Periodic Console Out Component",
"version", "0.1.0",
"vendor", "Yuki SUGA",
"category", "Test",
"activity_type", "COMMUTATIVE",
"max_instance", "1",
"language", "C++",
"lang_type", "compile",
"conf.default.config", "1",
""
};
// </rtc-template>
次に,onInitialize関数を編集します.まずはコメントアウトを外して,bindParameter関数を使って,先ほど宣言した変数をコンフィギュレーションパラメータとして登録します.
PeriodicConsoleOut::~PeriodicConsoleOut()
{
}
RTC::ReturnCode_t PeriodicConsoleOut::onInitialize()
{
bindParameter("config", m_config, "1");
return RTC::RTC_OK;
}
/*
RTC::ReturnCode_t PeriodicConsoleOut::onFinalize()
{
最後に,onExecute関数で,m_config変数を表示するように手を加えます.
{
return RTC::RTC_OK;
}
*/
RTC::ReturnCode_t PeriodicConsoleOut::onExecute(RTC::UniqueId ec_id)
{
std::cout << "Value is " << m_config << std::endl;
return RTC::RTC_OK;
}
/*
RTC::ReturnCode_t PeriodicConsoleOut::onAborting(RTC::UniqueId ec_id)
{
完成です.ビルドしてみてください.
実行する場合は,いつもどおりネームサーバーを起動してから実行します.rtc.configの設定についてもチェックしておいてください.
RtcLinkからコンフィギュレーションパラメータを設定します.
下記のようなコンフィギュレーションビューで,値を変更し,「適用」を行うとm_configの値を変更することができます.便利ですね.

次回は,コンポーネントをRtcLinkを使わないでアクティブ化できるプログラムを作ってみましょう♪
今回作成したファイル PeriodicConsoleOutR.zip(ver. 0.4.1)
PeriodicConsoleOutR.zip(ver. 0.4.2)