Up:Tutorial?     Previous:テスト実行     Next:人間型エージェントの操作


Creating our first simulation :A falling virtual object .

In this simulation dynamics is added to a virtual object which causes it to fall down due to gravity . The virtual object used here is the model of penguin.

Directory Structure

Here we represent the structure of the directories of the Sigverse package that is installed on your system .

sigverse-<version>

      |
      |---bin
      |---include
      |     +----sigverse       
      +---shared 
            +----sigverse
                    +----data
                    |     |----xml
                    |     +----shape
                    |----etc
                    |----jar
                    +----samples  

First step is to create a directory that will be your workspace.

※In this tutorial , we set up our workspace in the directory the sigverse-<version> / bin.

Creating an agent controller

What is controller ?

This section has to be written.

Create a simple agent controller.

An agent is an object upon which the autonomous operation is performed in the virtual world. We create our agent controller in the workspace directory that will created in sigverse-<version>/bin

$ mkdir NewWorld 
$ cd NewWorld

Creating our agent controller named MoveController.cpp using some editor e.g Vi or Emacs . We chose emacs .

$ emacs MoveController.cpp

MoveController.cpp

※ファイル保存時にコードシステムを聞かれたら今後すべてutf-8を指定してください。( could not translate )

Basically, the agent controller creates a class named "MoveController" by inheriting Contoroller class . onAction function is called every 5 seconds does nothing.

Compiling

Create a makefile for compiling the code we have created.

$ emacs Makefile

Makefile

#Specifying the location of Sigverse header files
SIG_SRC  = /home/<username>/sigverse-<version>/include/sigverse

#Specify the object file
OBJS     = MoveController.so

all: $(OBJS)

#Compile
./%.so: ./%.cpp
        g++ -DCONTROLLER -DNDEBUG -DUSE_ODE -DdDOUBLE -I$(SIG_SRC) -I$(SIG_SRC)/comm/controller  -fPIC -shared -o $@   $<

※<username> and 、<version> has to be adjusted to your username and sigverse you are using . To remind yourself the <version> of your Sigverse please look at the directory sigverse-<version> .

Note : In front of 'g++ -DCONTROLLER' line please remove the whitespaces and insert a TAB. otherwise you may get the following error

Run make

$ make

On successful make MoveController.so file should be created , which we can be verfied using "ls" command .

$ ls
Makefile  MoveController.cpp  MoveController.so

Creating a world file

What is a world file ?

World file describes the configuration of the virtual world including the configuration of agent . We describe the configuration in XML format.

The location of world files is : sigverse-<version>/share/sigverse/data/xml

$ cd ~/sigverse-<version>/share/sigverse/data/xml
$ emacs NewWorld.xml

NewWorld.xml

The world file reads thefile seToy_D.xml as an agent. Shape files of various agents and entities (x3d, wrl files) are placed in sigverse-<version>/share/sigverse/data/shapes. The xml file is prepared to use the shapes. We specify the programming language of the agent controller and attached it to the agent in world file. The flag to simulate "dynamics" was set to "true" .

Specifying the controller and its location within workspace directory

The script sigserver.sh is used to run the simulation and it placed in sigverse-<version>/bin directory . Since our workspace directory "NewWorld" is located in sigverse-<version>/bin , we have written the relative path for the agent controller. You may need to write the full path depending on the placement of your workspace directory.

Starting the si

The shell script sigserver.sh is located at sigverse-<version>/bin . You reduce the need of changing directories , we can add it to our path.

$ export PATH=$PATH:/home/<username>/sigverse-<version>/bin

Moving to the directory where execution is located

$ cd ~/sigverse-<version>/bin
$ ./sigserver.sh -w NewWorld.xml -p 9001
      :
      :
[SYS]  waiting for connection...
[SYS]  Controller attached to "Toy_D"
[SYS]  127.0.0.1 connected
[SYS]  Toy_D : dataport
[SYS]  127.0.0.1 connected

この時-wオプションで作成した世界ファイルを指定します。(何も指定しないときはMyWorld.xmlが読み込まれます。)

Since the agent controller is specified in the xml file you just created, the agent "Toy_D" starts automatically with attached controller.

Open Sigviewer and enter the host name and port number to connect to the Simserver . Please use the button "Connect to SimServer" by single click.

toy_1.jpg

World position for the agent Toy_D is described in the file as (0.0, 18.0, 5.0) . You can verify it . The height is in they direction in SIGVerse.

Start the simulation by using the framework of SIM_CTRL_CMD and the menu option START and press the button "Send"

toy_2.jpg

The simulation starts, you can confirm that the agent (toy_D) falls to the ground and bounces.

Move agents

We make some changes in the agent controller MoveController.cpp so that agent can move upon application of force.

$ cd NewWorld
$ emacs MoveController.cpp

Add the following code in agent controller.

MoveController.cpp

     ↓

Compile and Run

$ make
$ cd ..
$ ./sigserver.sh -w NewWorld.xml -p 9001

If you check SIGViewer, you can see agent moving in the z-direction where force is applied to the agent once every five seconds .

toy_3.jpg

It would be a fun exercise to use the following functions as well.

物理演算用の形状、大きさ、位置の設定

物理演算で用いるオブジェクトの形状は見た目の形状と異なり、sphere,cube, cylinderで近似されています。デフォルトでは見た目と大体同じ形状、大きさに設定されていますが、これらを設定ファイルで修正することができます。

設定ファイル修正

まず、オブジェクトの設定ファイルを編集します。

$ cd ~/sigverse-<version>/share/sigverse/data/xml
$ emacs seToy_D.xml

seToy_D.xmlの中の

 <body filename="dummy-body.xml"/>

の下に以下のいずれかを追加します。

box

一辺が10の立方体に設定しました。

sphere

sphereに設定する場合は以下のように設定します。

半径10の球に設定しました。

cylinder

※2011/10時点ではシリンダ形状の代わりにカプセル型形状を作ります。

底面の円の半径3、円筒の高さ10のシリンダーに設定しました。

実行

再度シグバースを実行してエージェントが落下した時や、力を加えた時の動きの違いを確認してみてください。

単位系

SIGVerseでは単位系は角度(ラジアン)以外は特に決まっていませんが、このチュートリアルでは世界標準の国際(SI)単位系を用います。

名称記号
長さメートルm
質量キログラムkg
時間s
角度ラジアンrad
速度メートル毎秒m/s
加速度メートル毎秒毎秒m/s^2
ニュートンN
トルクニュートン・メートルNm

Up:Tutorial?     Previous:テスト実行     Next:人間型エージェントの操作

English version?


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