Up:Tutorial? Previous:Image capture from agent's perspective Next:Grasping Function
A sample code in this tutorial make the agent detect collision event and turn around after the collision detection.
$ cd ~/MyWorld $ emacs Collision.cpp
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.
Create a world file.
$ emacs ./CollisionWorld.xml
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.
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.
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"/>
Robot-nii.xml
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"/>
Since the velocity is already set by the world file, remove the setting of velocity as follows:
$ emacs Collision.cpp
Collision.cpp
Old:
New:
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