Up:Tutorial?     Previous:Image capture from agent's perspective     Next:Grasping Function

Collision detection

A sample code in this tutorial make the agent detect collision event and turn around after the collision detection.

Creation of controller

$ cd ~/MyWorld
$ emacs Collision.cpp


This controller displays the name of other's agent name if a collision event is detected. After the collision detection, the agent will change the moving direction (making U-turn). The callback function onCollision is called in the collision event. The function onAction keeps going forward to the current direction. In this world file, two agents appear and they have different velocity.

World file

Create a world file.

$ emacs ./CollisionWorld.xml


The two robot agents use the same controller "Collision.so" The flag for collision detection should be set as "true" if you want to use the collision detection function. Please be careful that the initial state of this flag is "false".


$ ./sigserver.sh -w CollisionWorld.xml

Connect to the server with SIGViewer.

You will see two robots and a human avatar in the world. Let's push the start button to start the simulation.


First, a robot agent which stands in front of the human avatar will make U-turn after collides with the human avatar.


Next, the robots collide each other, then make U-turn.

After that, the two robots will repeat the U-turn behavior.

Addtion of attribute

In the above controller samples, two velocity values are set to two robot agents respectively. It is a little bit troublesome to change the velocity because the compilation is required. So, the following section introduces how to change the velocity using attribution in the worldfile.

Modification of entity file

First, copy the original file to your working space.

$ cp ~/sigverse-<version>/share/sigverse/data/xml/Robot-nii.xml .

Edit the configuration of the robot agent.

$ emacs ./Robot-nii.xml

Add the following line.

<attr name="vel" type="double" group="velocity" value="0.0"/>


Modification of the world file

Next, set velocity values in the world file.

$ emacs CollisionWorld.xml

Add the line

     <set-attr-value name="vel" value="5.0"/>

after the line which sets the the attribution of "robot_000"

Add the following one line at set of attribution for "robot_001" as well as the above way.

    <set-attr-value name="vel" value="7.0"/>

Modification of controller

Since the velocity is already set by the world file, remove the setting of velocity as follows:

$ emacs Collision.cpp




After the compilation, the velocity could be set by the worldfile.

$ ./sigmake.sh Collision.cpp

Please test the behavior of the controller file and the world file.

Up:Tutorial?     Previous:Image capture from agent's perspective     Next:Grasping Function

Counter: 3934, today: 1, yesterday: 1

Attach file: fileColli_3.PNG 2127 download [Information] fileColli_2.PNG 2073 download [Information] fileColli_1.PNG 2190 download [Information]

Front page   Edit Freeze Diff Backup Upload Copy Rename Reload   New List of pages Search Recent changes   Help   RSS of recent changes
Last-modified: 2014-02-07 (Fri) 14:47:00 (3586d)