This section explains how to make world file to let object fall with gravity.
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 let this directory as working space.
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 don't control anything. Idel function onAction is called in every 5 seconds.
The following Makefile is recommended to compile the controller.
$ 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 succeeded if you can see MoveController.so
$ ls Makefile MoveController.cpp MoveController.so
Create a world file on 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.
$ 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(): File not found: "toy_1.jpg" at page "Samples/Dynamics simulation"
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 is SIGVerse.
Next click the Send button after changing the state of frame SIM_CTRL_CMD as START to start the simulation.
#ref(): File not found: "toy_2.jpg" at page "Samples/Dynamics simulation"
You can see the agent Toy_D is falling down and vaulting on the follow.
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(): File not found: "toy_3.jpg" at page "Samples/Dynamics simulation"
You can use setAccel and setTorque not only setForce.