#contents * Maing of world file [#n81a6833] This section explains how to make world file to let object fall with gravity. ** Directory configuration [#r3d7f776] The initial directory configuration is shown in the following figure. sigverse-<version> | |---bin |---include | +----sigverse +---shared +----sigverse |----data | |----xml | +----shape |----etc |----jar +----samples This time, we create a new directory under sigverse-<version>/bin to use this directory as working space. ** Making of controller of the agent [#ld9ff52a] Move to the following directory to create new working space. $ cd ~/sigverse-<version>/bin $ mkdir NewWorld $ cd NewWorld Create MoveController.cpp with text editor such as emacs, vi and so on. $ emacs MoveController.cpp MoveController.cpp #include "Controller.h" #include "Logger.h" //Statement of MoveController which is subclass of Controller. class MoveController : public Controller { public: //Statement of usage of onAction which is called periodically. double onAction(ActionEvent&); }; double MoveController::onAction(ActionEvent &evt) { return 5.0; //次にonActionが呼ばれるまでの時間を返します。 } //自身のインスタンスをSIGVerseに返します。 extern "C" Controller * createController() { return new MoveController; } If you see Japanese code or strange character code, please delete those strange characters. This controller doesn't control anything. Idle function onAction is called every 5 seconds. ** Compile [#i712b58f] The following Makefile is recommended to compile the controller. // emacs make.sh //make.sh // #!/bin/sh // #SIGVerseソースの場所を指定します。 // export SIG_SRC="/home/<username>/sigverse-201003/include/sigverse" // #コンパイルを行います。 // make clean // make $ emacs Makefile Makefile #SIGVerse server source tree SIG_SRC = /home/<username>/sigverse-<version>/include/sigverse #Specifying of object file OBJS = MoveController.so all: $(OBJS) #compilation rule ./%.so: ./%.cpp g++ -DCONTROLLER -DNDEBUG -DUSE_ODE -I$(SIG_SRC) -I$(SIG_SRC)/comm/controller -fPIC -shared -o $@ $< You should replace <username> as your account ID, <version> as the version number respectively. Before the g++ in the above Makefile should be TAB (not space). Be careful on that point. Execute make to compile the controller $ make The compilation is successful if you can see MoveController.so $ ls Makefile MoveController.cpp MoveController.so ** Creation of the world file [#v5bbeb72] Create a world file in sigverse-<version>/share/sigverse/data/xml $ cd ~/sigverse-<version>/share/sigverse/data/xml $ emacs NewWorld.xml NewWorld.xml <?xml version="1.0" encoding="utf8"?> <world name="newworld"> <!--重力の設定--> <gravity x="0.0" y="-9.8" z="0.0"/> <!--エージェントToy_Dのインスタンス作成--> <instanciate class="seToy_D.xml"> <!--エージェント名--> <set-attr-value name="name" value="Toy_D"/> <!--C++言語の指定--> <set-attr-value name="language" value="c++"/> <!--作成したコントローラの指定--> <set-attr-value name="implementation" value="./NewWorld/MoveController.so"/> <!--動力学演算フラグ--> <set-attr-value name="dynamics" value="true"/> <!--エージェントの最初の位置(x,y,z)--> <set-attr-value name="x" value="0.0"/> <set-attr-value name="y" value="18.0"/> <set-attr-value name="z" value="5.0"/> </instanciate> In this process, this world file defines "dynamics" as "true" to execute dynamics simulation. ** Start the simulation [#vc9852fe] $ 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 You should specify the created world file with -w option. Since the world file specified the new controller, controller is attached automatically on the agent "Toy_D" without execution of sigrunac. Next, input target host name and port number to connect to the SIGVerse server. Click the "Connect to SimServer" button. #ref(toy_1.jpg) You can see the agent Toy_D stands at the position (0.0, 18.0, 5.0) which is defined in the world file. Y axis indicates vertical direction in SIGVerse. Next click the Send button after changing the state of frame SIM_CTRL_CMD as START to start the simulation. #ref(toy_2.jpg) You can see the agent Toy_D is falling down and bouncing on the floor. *Put force on the agent [#xebe42b6] Change the controller MoveController.cpp to put outer force on the agent. $ cd NewWorld $ emacs MoveController.cpp Add the following 2 lines after double MoveController::onAction(ActionEvent &evt) { SimObj *obj = getObj(myname()); //Get object ID of agent itself obj->setForce(0,0,300); //Put force on the z axis, quantity is 300. Compile and execute $ make $ cd .. $ ./sigserver.sh -w NewWorld.xml -p 9001 You can see the agent is moving every 5 seconds with receiving outer force on z sxis. #ref(toy_3.jpg) You can use setAccel and setTorque not only setForce. LEFT:[[Back>Tutorial/Execution of test]] RIGHT:[[Next>Agent control]]