Up:[[Tutorial]]    Previous:[[ロボット・ダイナミクス(ヒューマノイド)]]     Next: [[距離センサ]]  
Up:[[Tutorial]]    Previous:[[Control of humanoid agent by BVH file]]     Next: [[Distance sensor]]  

----
#contents

*車輪移動ロボット [#oab43195]
ここでは車輪移動ロボットを操作するサンプルを紹介します。
* Wheeled mobile robot [#y0590a3f]

※このサンプルはバージョン2.1.1以降で動作します。
This tutorial explains how to control a wheeled mobile robot.

**車両モデル [#hfb27269]
このチュートリアルでは以下の車両モデルを使用します。
(※This sample code is valid only for later than v2.1.1)

#ref(車輪移動ロボット(v120330 v1.4.8)/syaryou1.jpg)
      上から見た車輪移動ロボット
** Model of a mobile robot [#ce581e96]

The following model is used in this tutorial.

#ref(./mobile_robot_top_view.jpg)
            Figure from overhead view

#br
#ref(車輪移動ロボット(v120330 v1.4.8)/syaryou2.jpg)
      ひっくり返した車輪移動ロボット
#ref(./mobile_robot_bottom_view.jpg)
            Figure from bottom view

車体の両サイドに車輪が2つついていて、前と後ろには球のキャスターが付いています。
左右の車輪は"JOINT_LWHEEL"と"JOINT_RWHEEL"という関節名でつながれています。この関節の角速度を設定して、車輪を回転させます。このモデルの車輪の半径は8cm。車体のサイズは 20×8×25(cm)。
車体や車輪の質量、サイズ、色等はすべて形状ファイルで設定されています。
This mobile robot has two wheels on both sides and two casters attached on back and forth.
The both of two wheels are connected to the main body with joint name "JOINT_LWHEEL" and "JOINT_RWHEEL", respectively.
In this example, the wheels are rotated by setting the angular velocity of these joint angles.
The radius of the wheel (8cm) and the size of the robot 20x8x25(cm) are defined in a 3D model file such as "mobile_base.xml"
The mass, color and so on are also defined in the 3D model file.

// Download the 3D model file and extract it on the working directory.
// #ref(MobileBase_2.1.0.tar.gz)
//  $ cd ~/MyWorld
//  $ tar zxvf MobileBase_2.1.0.tar.gz
//
//
// v2.1.0 では標準で配布されていなかったが,v2.2.0 以降ではモデルが標準装備されているので上記の説明は必要ない by inamura 2013-12-03


**コントローラ作成 [#y57ebc89]
まずは車輪移動ロボットを操作するコントローラを作成します。
** Creating a controller [#l40b0896]

 $ emacs wheelController.cpp

wheelController.cpp

#highlight(cpp){{
#include <Controller.h>
#include <ControllerEvent.h>
#include <Logger.h>
 
/**
 * 車両モデルのサンプル
 * Sample controller of a wheeled mobile robot
 */
class MobileController : public Controller {
public:
  void onInit(InitEvent &evt);
  double onAction(ActionEvent&);
  void onRecvMsg(RecvMsgEvent &evt);
 
private:
  double maxForce;
}; 
 
void MobileController::onInit(InitEvent &evt) {
  maxForce = 500.0;
}
 
double MobileController::onAction(ActionEvent &evt) {
  return 10.0;
}
 
//メッセージ受信時に呼び出される関数
// Callback function which is called when messages comes
void MobileController::onRecvMsg(RecvMsgEvent &evt)
{

  //メッセージを取得します。
  // Receiving a message
  std::string msg = evt.getMsg(); 
  SimObj *my = getObj(myname());
 
  //メッセージ" "が含まれていると左右の車輪の角速度を設定します。
  // Set the angular velocity of the two wheels
  if (strstr(msg.c_str(), " "))
    {
      //メッセージを左と右の角速度に分けます.
      // Separate the two elements by a space separator ' '
      std::string left_vel;
      std::string right_vel;
      int n = 0;
      n = msg.find(" ");
      left_vel = msg.substr(0,n);
      right_vel = msg.substr(n+1);
      double lvel = atof(left_vel.c_str());
      double rvel = atof(right_vel.c_str());

      // 速度を設定します。
      // Set velocity
      my->setJointVelocity("JOINT_LWHEEL", lvel, maxForce);
      my->setJointVelocity("JOINT_RWHEEL", rvel, maxForce);
    }
}
 
extern "C" Controller * createController() {
  return new MobileController;
}

}}
これはビューワーで車輪移動ロボットを操作できるサンプルです。車輪移動ロボットは左右の車輪の角速度[rad/s]のメッセージを受け取って車輪の角速度を設定します。メッセージの送信方法は左と右の角速度をスペースで区切るだけです。例えば左の車輪を角速度1.5(rad/s)、右の車輪の角速度を2(rad/s)に設定したいときは"1.5 2"というメッセージを送信します。

コンパイルします。
You can control the velocity of the two wheels by sending messages. For example, if you want to set the velocity of the left wheel as 1.5[rad/s] and the right wheel as 2.0[rad/s], you should send "1.5 2" to the robot agent.

Compile the controller by the following command.

 $ ./sigmake.sh wheelController.cpp

**世界ファイル [#j6edad8f]
次に世界ファイルを作成します。
** World file [#oe6c7a97]

 $ emacs wheelWorld.xml

wheelWorld.xml

#highlight(xml){{
<?xml version="1.0" encoding="utf8"?>
 <world name="myworld">

  <gravity x="0.0" y="-980.7" z="0.0"/>

  <instanciate class="mobile_base.xml">
    <set-attr-value name="name" value="mobile_base_001"/>
    <set-attr-value name="dynamics" value="true"/>

    <set-attr-value name="x" value="0.0"/>
    <set-attr-value name="y" value="7.5"/>
    <set-attr-value name="z" value="0.0"/>

    <set-attr-value name="language" value="c++"/>
    <set-attr-value name="implementation"  value="./wheelController.so"/>
    <set-attr-value name="collision" value="true"/>

    <camera id="1" 
            link="LINK_CENTER"
            position="0.0 0.0 10.0"/>  

  </instanciate>

  <instanciate class="sePetBottle2LEmpty.xml">
    <set-attr-value name="name" value="petbottle_0"/>
    <set-attr-value name="dynamics" value="true"/>

    <set-attr-value name="x" value="0.0"/>
    <set-attr-value name="y" value="16.67"/>
    <set-attr-value name="z" value="100.0"/>
    <set-attr-value name="collision" value="true"/>
  </instanciate>

  <instanciate class="sePetBottle2LEmpty.xml">
    <set-attr-value name="name" value="petbottle_1"/>
    <set-attr-value name="dynamics" value="true"/>

    <set-attr-value name="x" value="0.0"/>
    <set-attr-value name="y" value="16.67"/>
    <set-attr-value name="z" value="200.0"/>
    <set-attr-value name="collision" value="true"/>
  </instanciate>
 </world>
}}
この世界ファイルでは"mobile_base.xml"を指定しています。
カメラはロボットの車体"LINK_CENTER"に設置しました。
車輪移動ロボット以外にも障害物としてペットボトルを置きました。

**実行 [#e2f1dd3c]
それでは実行してみましょう。
This world file specifies the 3D model file of the mobile robot as "mobile_base.xml"
A camera is attached on a link named "LINK_CENTER" which is the main body of the mobile robot.
A plastic bottle is also appeared as an obstacle.

** Execution [#ncada848]

 $ sigserver.sh -w ./wheelWorld.xml
ビューワーで接続して見てみると車輪移動ロボットの前方にペットボトルが置かれています。

例えばビューワーからメッセージ"1 0.5"を送信してみます。
すると車両は右前方向に進み始めます。
You can see a plastic bottle in front of the mobile robot.

#ref(車輪移動ロボット_v2.1.0/syaryou_4.PNG,40%)
For example, send a message "1 0.5" from the SIGViewer. The mobile robot will move to the right ahead.

バックすることもできます。
#ref(./mobile_robot_result.PNG,40%)

The robot can go backward.

#highlight(end)

*Old Version [#i2524b22]
-[[車輪移動ロボット(v120330 v1.4.8)]]
Up:[[Tutorial]]    Previous:[[Control of humanoid agent by BVH file]]     Next: [[Distance sensor]]  

Up:[[Tutorial]]    Previous:[[ロボット・ダイナミクス(ヒューマノイド)]]     Next: [[距離センサ]]  
#counter


Front page   New List of pages Search Recent changes   Help   RSS of recent changes