ラベル OpenRTM-aist の投稿を表示しています。 すべての投稿を表示
ラベル OpenRTM-aist の投稿を表示しています。 すべての投稿を表示

2011年11月19日土曜日

RT ミドルウエアコンテスト 2011 参加(ただしお金だけ)

突然ですが、RTミドルウェアコンテストに参加することにしました。

ただし、ミドルウェアはまじめに書いたこと無いので協賛のほうです。(こんなんで審査していいんだろうか)
http://www.openrtm.org/rt/RTMcontest/2011/award.html
勢いでつい本名で出してしまいました。

一応このブログに関係あるっぽくしようと思って、「グローバルスタンダード賞」としました。
ROSに負けない、国際的に認められそうなモジュールがあるといいなぁ。

2011年8月16日火曜日

OpenRTM-asit ROSパッチ(ros port)を使ってルンバを操縦する

前回OpenRTM-aistからROSを使えるようにしました。
次はお決まりですがルンバを動かします。

今回はOpenRTM-aistの仮想ジョイスティックコンポーネントを利用してルンバを動かします。

構成としては

TkJoyStick(RTC) -> JoyRTM2velROS(今回作ったコンポーネント)(RTC/ROS) -> いつもの自作ルンバノード(ROS)

という感じです。
TkJoyStickはOpenRTM-aistのサンプルに入っていて、ジョイスティックっぽいGUIです。

面倒なのでビデオ解説です。



JoyRTM2velROSのソースはTkJoyStickからの入力(TimedFloatSeq)をROSのgeometry_msgs/Twist型に変換しているだけです。
やはりOpenRTMとROSは非常に似ていますね。

OpenRTM-aistのコードの自動生成は便利だけど修正がめんどくさいです。
とくにRosPortのように標準ツールでサポートされていないと大変です。
なにかいい方法があれば教えてください。

参考程度にcppのソースファイルだけ貼りつけておきます。
いつも通り適当です。

一応リポジトリに
otl-ros-pkg/otl_nav/JoyRTM2velROS
としておいておきました。

【参考サイト】
http://code.google.com/p/rtm-ros-robotics/wiki/rosport_Example
http://code.google.com/p/rtm-ros-robotics/wiki/RTM_HelloWorldSample



ヘッダファイル

// -*- C++ -*-
/*!
 * @file  JoyRTM2velROS.h
 * @brief convert Joystick sample port to ROS twist msg
 * @date  $Date$
 *
 * $Id$
 */

#ifndef JOYRTM2VELROS_H
#define JOYRTM2VELROS_H

#include <rtm/Manager.h>
#include <rtm/DataFlowComponentBase.h>
#include <rtm/CorbaPort.h>
#include <rtm/DataInPort.h>
#include <rtm/DataOutPort.h>
#include <rtm/idl/BasicDataTypeSkel.h>
#include <rtm/idl/ExtendedDataTypesSkel.h>
#include <rtm/idl/InterfaceDataTypesSkel.h>
#include <rtm/RosOutPort.h>
#include "geometry_msgs/Twist.h"

using namespace RTC;

/*!
 * @class JoyRTM2velROS
 * @brief convert Joystick sample port to ROS twist msg
 *
 */
class JoyRTM2velROS
  : public RTC::DataFlowComponentBase
{
 public:
  /*!
   * @brief constructor
   * @param manager Maneger Object
   */
  JoyRTM2velROS(RTC::Manager* manager);

  /*!
   * @brief destructor
   */
  ~JoyRTM2velROS();

  /***
   *
   * The initialize action (on CREATED->ALIVE transition)
   * formaer rtc_init_entry() 
   *
   * @return RTC::ReturnCode_t
   * 
   * 
   */
   virtual RTC::ReturnCode_t onInitialize();

  /***
   *
   * The execution action that is invoked periodically
   * former rtc_active_do()
   *
   * @param ec_id target ExecutionContext Id
   *
   * @return RTC::ReturnCode_t
   * 
   * 
   */
   virtual RTC::ReturnCode_t onExecute(RTC::UniqueId ec_id);

 protected:

  // Configuration variable declaration
  // 
  /*!
   * 
   * - Name:  max_linear_velocity
   * - DefaultValue: 0.1
   */
  double m_max_linear_velocity;
  /*!
   * 
   * - Name:  max_angular_velocity
   * - DefaultValue: 0.2
   */
  double m_max_angular_velocity;
  // 

  // DataInPort declaration
  // 
  TimedFloatSeq m_joyInput;
  /*!
   */
  InPort m_joyInputIn;
  
  // ROS Port
  geometry_msgs::Twist m_rosVel;
  RosOutPort m_rosVelOut;

 private:

};


extern "C"
{
  DLL_EXPORT void JoyRTM2velROSInit(RTC::Manager* manager);
};

#endif // JOYRTM2VELROS_H

実体(.cpp)

// -*- C++ -*-
/*!
 * @file  JoyRTM2velROS.cpp
 * @brief convert Joystick sample port to ROS twist msg
 * @date $Date$
 *
 * $Id$
 */

#include "JoyRTM2velROS.h"

// Module specification
// <rtc-template block="module_spec">
static const char* joyrtm2velros_spec[] =
  {
    "implementation_id", "JoyRTM2velROS",
    "type_name",         "JoyRTM2velROS",
    "description",       "convert Joystick sample port to ROS twist msg",
    "version",           "1.0.0",
    "vendor",            "OTL",
    "category",          "Sample",
    "activity_type",     "PERIODIC",
    "kind",              "DataFlowComponent",
    "max_instance",      "1",
    "language",          "C++",
    "lang_type",         "compile",
    // Configuration variables
    "conf.default.max_linear_velocity", "0.2",
    "conf.default.max_angular_velocity", "0.4",
    // Widget
    "conf.__widget__.max_linear_velocity", "slider",
    "conf.__widget__.max_angular_velocity", "slider",
    // Constraints
    ""
  };
// </rtc-template>

/*!
 * @brief constructor
 * @param manager Maneger Object
 */
JoyRTM2velROS::JoyRTM2velROS(RTC::Manager* manager)
    // <rtc-template block="initializer">
  : RTC::DataFlowComponentBase(manager),
    m_joyInputIn("joy_input", m_joyInput)

    // </rtc-template>
    ,
    m_rosVelOut("cmd_vel", "rtm2ros", m_rosVel)
{
}

/*!
 * @brief destructor
 */
JoyRTM2velROS::~JoyRTM2velROS()
{
}



RTC::ReturnCode_t JoyRTM2velROS::onInitialize()
{
  // Registration: InPort/OutPort/Service
  // <rtc-template block="registration">
  // Set InPort buffers
  addInPort("joy_input", m_joyInputIn);

  // Set OutPort buffer

  // Set service provider to Ports

  // Set service consumers to Ports

  // Set CORBA Service Ports

  // </rtc-template>

  // <rtc-template block="bind_config">
  // Bind variables and configuration variable
  bindParameter("max_linear_velocity", m_max_linear_velocity, "0.2");
  bindParameter("max_angular_velocity", m_max_angular_velocity, "0.4");
  // </rtc-template>

  addRosOutPort("ros_velocity", m_rosVelOut);

  return RTC::RTC_OK;
}


RTC::ReturnCode_t JoyRTM2velROS::onExecute(RTC::UniqueId ec_id)
{
  if(m_joyInputIn.isNew()) {
    m_joyInputIn.read();

    m_rosVel.linear.x = m_joyInput.data[1] * 0.005;
    m_rosVel.angular.z = -m_joyInput.data[0] * 0.010;

    if ( m_max_linear_velocity < m_rosVel.linear.x) {
      m_rosVel.linear.x = m_max_linear_velocity;
    } else if (-m_max_linear_velocity > m_rosVel.linear.x) {
      m_rosVel.linear.x = -m_max_linear_velocity;
    } else if (fabs(m_rosVel.linear.x) < 0.01) {
      m_rosVel.linear.x = 0.0;
    }
    if ( m_max_angular_velocity < m_rosVel.angular.z) {
      m_rosVel.angular.z = m_max_angular_velocity;
    } else if (-m_max_angular_velocity > m_rosVel.angular.z) {
      m_rosVel.angular.z = -m_max_angular_velocity;
    } else if (fabs(m_rosVel.angular.z) < 0.01) {
      m_rosVel.angular.z = 0.0;
    }

    m_rosVelOut.write();
  }
  return RTC::RTC_OK;
}



extern "C"
{

  void JoyRTM2velROSInit(RTC::Manager* manager)
  {
    coil::Properties profile(joyrtm2velros_spec);
    manager->registerFactory(profile,
                             RTC::Create<JoyRTM2velROS>,
                             RTC::Delete<JoyRTM2velROS>);
  }

};

OpenRTM-asit ROSパッチを試す(インストール編)

OpenRTMにROS通信を追加するパッチがあります。
これを使ってみます。

環境はUbuntu10.04、ROSはdiamondbackです。
かなり苦労しました。

http://www.openrtm.org/OpenRTM-aist/html/E3839EE3838BE383A5E382A2E383AB2Frosport.html

ソースからOpenRTM-aistをビルドする必要ああるのでソースをゲットします。
1.0.0です。

$ wget http://www.openrtm.org/pub/OpenRTM-aist/cxx/1.0.0/OpenRTM-aist-1.0.0-RELEASE.tar.bz2

パッチもゲット
$ wget http://www.openrtm.org/pub/OpenRTM-aist/cxx/1.0.0/ros_transport.patch-1.0.1.tar.gz


aptでいれたOpenRTM-aistは削除しておきます。
$ sudo apt-get remove openrtm-aist-example openrtm-aist openrtm-aist-dev

パッケージの展開
$ tar jxvf OpenRTM-aist-1.0.0-RELEASE.tar.bz2
$ tar zxvf ros_transport.patch-1.0.1.tar.gz
$ cd OpenRTM-aist-1.0.0

パッチを当てます。

$ patch -p0 < ../ros_transport.patch

そしてautoconfができるようにlibtool.m4を現在使っているシステムのものと入れ替えます(ここ重要)
$ find . -name libtool.m4 -exec cp /usr/share/aclocal/libtool.m4 {} \;

さらにsrc/lib/rtm/Makefile.amの以下の変数を次のように書き換えます。(ここも重要)
(cturtleを使っている場合はこれなくても動くようです)

ros_cflags=`rospack export --lang=cpp --attrib=cflags roscpp`
ros_libs=`rospack export --lang=cpp --attrib=lflags roscpp`

そしたらautoreconfして、あとはお決まりの流れです。

$ autoreconf -ifv
$ ./configure
$ make

インストール
$ sudo make install 
これで/usr/local/以下にインストールされます。



@hyaguchijskさんに協力をいただきました。ありがとうございました。

次にサンプルをmakeします。
$ wget http://www.openrtm.org/pub/OpenRTM-aist/cxx/1.0.0/examples.ros-1.0.0.tar.gz
$ tar zxvf examples.ros-1.0.0.tar.gz
$ cd examples.ros
$ cd publisher
$ make

$ cd ../subscriber
$ make

この状態でpublisherCompとsubscriberCompを動かしてActivateすると
それぞれPub/Subしてくれます。

やっと動いた・・・。

続OpenRTM-aist

引き続きOpenRTMのサンプルを試してみました。
移動ロボットを仮想ジョイパッドで動かすことができます。




やっぱりかなりハマりました。
でも↓のサイトにだいたい書いてあります。
非常に参考になりました。
http://code.google.com/p/rtm-ros-robotics/wiki/RTM_2DSimulator_Example


とくに
$ sudo apt-get install tix
とか、実はバグがあるとか、ハマりどころを押さえていますね。

公式ドキュメントもアップデートしていただきたい所です。

2011年8月11日木曜日

OpenRTM-aistのインストール(自分用メモ)

日本で唯一OpenRTMではなくROS陣営と思われている(?)私ですが、
Electricがリリースされるまでネタがないので、
たまにはOpenRTMやってみようと思いました。
以下はメモ書きみたいなものです。

OpenRTMはまずこれやれ、っていうのがあったら教えてください。
ルンバをOpenRTMで動かせるか教えてください。


OpenRTM-aist 1.00(C++) on Ubuntu 10.04です。

http://www.openrtm.org/openrtm/ja/node/1001
に従いインストールしてみます。

OpenRTMはysugaさんが紹介していますね。

http://ysuga.net/robot/rtm

1.source.listの編集

/etc/apt/source.list.d/openrtm.list


deb http://www.openrtm.org/pub/Linux/ubuntu lucid main
を追加。

2.インストール

2.1.C++版インストール

以下のようにしてみました。成功したけど、これで動くかな。
$ sudo apt-get update

$ sudo apt-get install gcc g++ make uuid-dev
$ sudo apt-get install libomniorb4-dev omniidl4 ominiorb4-nameserver
$ sudo apt-get install openrtm-aist openrtm-aist-doc openrtm-aist-dev openrtm-aist-example
(公式どおりやると以下のようにエラーがでました。
$ apt-get install libomniorb4 libomniorb4-dev omniidl4 omniorb4-nameserver
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています                
状態情報を読み取っています... 完了
E: パッケージ libomniorb4 が見つかりません)
2.2.Python版インストール
Python版もいれてしまいましょう。
# apt-get install python-omniorb2-omg omniidl4-python
# apt-get install openrtm-aist-python openrtm-aist-python-example
2.3.Eclipseとツールのインストール
全部入りをダウンロードします。
$ tar zxvf eclipse342_rtmtools100release_linux_ja.tar.gz
$ cd eclipse
$ ./eclipse
で起動。
3.動作確認
次に何やればいいかわからなかったけどぐぐったらでました。
http://openrtm.org/openrtm/ja/content/%E5%8B%95%E4%BD%9C%E7%A2%BA%E8%AA%8D-linux%E7%B7%A8
3.1.ネームサーバの起動
$ rtm-naming
3.2 コンフィグ作成
$ mkdir ~/RTCwork
$ cd ~/RTCwork
して、以下の内容でrtc.confを作成.最初のnameserversのところはlocalhostでは動きませんでした。ipv6のせいだそうです。
corba.nameservers: 127.0.0.1
 naming.formats: %h.host_cxt/%n.rtc
 logger.enable: NO
 example.ConsoleOut.config_file: consout.conf
 example.ConsoleIn.config_file: consin.conf

3.3。サンプル実行

以下のようにしてインストールされているサンプルを実行

インプット側。
$ cd ~/RTCwork

$ /usr/share/OpenRTM-aist/examples/ConsoleInComp -f rtc.conf 

アウトプット側。
$ cd ~/RTCwork
$ /usr/share/OpenRTM-aist/examples/ConsoleOutComp -f rtc.conf 
(公式はexampsになっているので注意。)
また、必ずcd ~/RTCworkしてください。

あとはEclipseのSystemEditorから接続すればOK!
できたーーー!!

最後めっちゃ端折りましたが、SystemEditorが全く動かなくて困りました。
が、実はrtc.confにlocalhostと書いていたのが原因でした。

うーん疲れた。