Up:[[Tutorial]]    Previous:[[Control of humanoid agent by BVH file]]     Next: [[Distance sensor]]  


* Wheeled mobile robot [#y0590a3f]

This tutorial explains how to control a wheeled mobile robot.

(※This sample code is valid only for later than v2.1.1)

** Model of a mobile robot [#ce581e96]

The following model is used in this tutorial.

            Figure from overhead view

            Figure from bottom view

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

** Creating a controller [#l40b0896]

 $ emacs wheelController.cpp


#include <Controller.h>
#include <ControllerEvent.h>
#include <Logger.h>
 * Sample controller of a wheeled mobile robot
class MobileController : public Controller {
  void onInit(InitEvent &evt);
  double onAction(ActionEvent&);
  void onRecvMsg(RecvMsgEvent &evt);
  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;


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

** World file [#oe6c7a97]

 $ emacs wheelWorld.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" 
            position="0.0 0.0 10.0"/>  


  <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 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"/>

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

You can see a plastic bottle in front of the mobile robot.

For example, send a message "1 0.5" from the SIGViewer. The mobile robot will move to the right ahead.


The robot can go backward.


Up:[[Tutorial]]    Previous:[[Control of humanoid agent by BVH file]]     Next: [[Distance sensor]]  


Up:[[Tutorial]]    Previous:[[Robot dynamics (humanoid)]]     Next: [[Distance sensor]]

Front page   Edit Diff Backup Upload Copy Rename Reload   New List of pages Search Recent changes   Help   RSS of recent changes