Humanoid agent operations
[
Front page
] [
New
|
List of pages
|
Search
|
Recent changes
|
Help
]
Start:
Up:[[Tutorial]] Previous:[[Samples of the dynami...
----
#contents
*Operations on the movement of agents [#v2485f29]
Describes how to operate the joints of agents or anthropo...
** Operations of joints of robots[#f5cb7768]
Here is the sample code to change the angle of joint of ...
***Creating the Controller [#oc032119]
Let's create a controller file AgentController.cpp in the...
$ emacs AgentController.cpp
AgentController.cpp
#highlight(cpp){{
#include "Controller.h"
#include "Logger.h"
#define PI 3.141592
//Coverts angles to radians
#define DEG2RAD(DEG) ( (PI) * (DEG) / 180.0 )
class AgentController : public Controller
{
public:
double onAction(ActionEvent &evt);
};
//This function is called on regular basis
double AgentController::onAction(ActionEvent &evt)
{
try {
// get handle for the agent
SimObj *my = getObj(myname());
if (!my->dynamics()) {
// "LARM_JOINT2" is set to 45 degrees
my->setJointAngle("LARM_JOINT2", DEG2RAD(45));
}
} catch(SimObj::Exception &) {
;
}
return 5.0;
}
extern "C" Controller * createController ()
{
return new AgentController;
}
}}
In this controller, the avatar agent bend the left arm to...
*** Compilation [#p15fd2cd]
The same script sigmake.sh should be used for the compila...
$ ./sigmake.sh AgentController.cpp
*** Creating world files [#l5dd7972]
Then create a world file in the same workspace.
$ emacs AgentWorld.xml
AgentWorld.xml
#highlight(xml){{
<?xml version="1.0" encoding="utf8"?>
<world name="AgentWorld">
<!--Set gravity-->
<gravity x="0.0" y="-9.8" z="0.0"/>
<!--object of agent Man-nii-->
<instanciate class="Man-nii.xml">
<!--Agent Name-->
<set-attr-value name="name" value="man_000"/>
<!--C++ is the programming language-->
<set-attr-value name="language" value="c++"/>
<!--Controller file for the object-->
<set-attr-value name="implementation" value="./A...
<!--put the flag of dynamics to false-->
<set-attr-value name="dynamics" value="false"/>
<!--setting the initial position of agent (x,y,z)-->
<set-attr-value name="x" value="0.0"/>
<set-attr-value name="y" value="50.0"/>
<set-attr-value name="z" value="0.0"/>
</instanciate>
</world>
}}
The file specifies Man-nii.xml as humanoid avatar. Dynami...
Please be careful that you cannot specify such concrete j...
*** Starting SIGVerse [#g6cf60e0]
So let's start SIGVerse.
$ sigserver.sh -w ./AgentWorld.xml
Connect to the SIGServer and push the "START" button to s...
You can see that the agent holds the left arm to 45 degre...
#ref(./man_1.PNG,40%)
We use setJointAngle to set the angle of "LARM_JOINT2" to...
Joint names of these files are defined in sigverse-x3d <v...
Joint names and join definitions of the sample model desc...
Man-nii humanoid agent is an object that inherits from th...
$ less xml/Agent.xml
#highlight(xml){{
<?xml version="1.0" encoding="utf8"?>
<define-class name="Agent" inherit="Entity.xml">
<attr name="language" type="string" group="model"/>
<attr name="implementation" type="string" group="model"/>
<!-- view point(agent coordinate) -->
<attr name="vpx" type="double" group="viewpoint" value="...
<attr name="vpy" type="double" group="viewpoint" value="...
<attr name="vpz" type="double" group="viewpoint" value="...
<!-- view vector(view coordinate) -->
<attr name="vvx" type="double" group="viewvector" value=...
<attr name="vvy" type="double" group="viewvector" value=...
<attr name="vvz" type="double" group="viewvector" value=...
}}
Furthermore, Agent class has inherited the Entity class. ...
***Agents, basic attributes of an entity[#g14c1ee2]
Entities introduces the basic properties of the agent.
Attribute of an entity
| Attribute Name | Meaning | Remarks |
| x, y, z | position of the entity | global coordinates. ...
| fx, fy, fz | force on the entity | |
| vx, vy, vz | speed of the entity | |
| qw, qx, qy, qz | direction of the entity | Quaternion n...
| scalex, scaley, scalez | the size of the entity | |
Agent attributes
| Attribute Name | Meaning | Remarks |
| vpx, vpy, vpz | position of the viewpoint of the agent ...
| vvx, vvy, vvz | gaze direction (non-humanoid) | vector ...
| elnk1, elnk2, ... elnk9 | viewpoint (camera) to establi...
| epx1, epy1, epz1, ... epx9, epy9, epz9 | viewpoint (cam...
| evx1, evy1, evz1, ... evx9, evy9, evz9 | viewpoint (cam...
| FOV | Agent viewing angle (height) | |
| voiceReachRadius | Agent voices reach | |
These attributes can be set in all the world files.
** Operating agents with a Command [#t5a2daa5]
In the above example, a function onAction was used to rai...
Let's create another controller file named AgentControlle...
$ emacs AgentController2.cpp
AgetnController2.cpp
#highlight(cpp){{
#include <string> //include string header files
#include "Controller.h"
#include "Logger.h"
#include "ControllerEvent.h"
#define PI 3.141592
#define DEG2RAD(DEG) ( (PI) * (DEG) / 180.0 )
using namespace std; //Using namespace definitions
class AgentController : public Controller
{
public:
double onAction(ActionEvent &evt);
// Declare the use of onRecvMessage function when it re...
void AgentController::onRecvMsg(RecvMsgEvent &evt)
};
double AgentController::onAction(ActionEvent &evt)
{
try {
SimObj *my = getObj(myname());
if (!my->dynamics()) {
// Lower down the left.
my->setJointAngle("LARM_JOINT2", DEG2RAD(-90));
// Lower down the right
my->setJointAngle("RARM_JOINT2", DEG2RAD(90));
}
} catch(SimObj::Exception &) {
;
}
return 5.0;
}
void AgentController::onRecvMsg(RecvMsgEvent &evt)
{
//get an handle to agent
SimObj *my = getObj(myname());
// string message is received
std::string value(evt.getMsg());
if (value =="Hello"){
//bend the hip joint to 45[deg]
my->setJointAngle("WAIST_JOINT1", DEG2RAD(45));
}
}
extern "C" Controller * createController ()
{
return new AgentController;
}
}}
agent puts its hands down when onAction function is calle...
The onRecvMessage function will be called when a message ...
Compile the new controller file.
$ ./sigmake.sh AgentController2.cpp
*** World file [#md72d91d]
You should modify the world file to use the new controlle...
#highlight(xml:firstline[16]){{
<!--Controller file for the object-->
<set-attr-value name="implementation"
value="./AgentController.so"/>
}}
↓
#highlight(xml:firstline[16]){{
<!--Controller file for the object-->
<set-attr-value name="implementation"
value="./AgentController2.so"/>
}}
*** Execute the server [#p73b3ced]
Input the following command to execute the SIGVerse server.
$ sigserver.sh -w ./AgentWorld.xml
Start the SIGViewer, and connect to the SIGServer. When y...
#ref(./man_2.PNG,40%)
*** Sending a message [#hb68ba23]
Click the "Message" button on the right bottom of the SIG...
Select the target agent "man_000" in the TargetEntity fie...
#ref(./man_3.PNG,70%)
Click the "Send" button if you input the message.
#ref(./man_4.PNG,40%)
You can see the avator bows.
** Joint rotation with quaternion [#ecbdc67b]
Rotation of the joint can also be set by the quaternion.
AgentController2.cpp
#highlight(cpp:firstline[52]){{
//Bend the Hip joint to 45[deg]
my->setJointAngle("WAIST_JOINT1", DEG2RAD(45));
}}
↓
#highlight(cpp:firstline[52]){{
//Rotate 90 degree around X axis for the hip joint
my->setJointQuaternion("WAIST_JOINT1", 0.707, 0.707, ...
}}
setJointquaternion function sets the joint angle using qu...
Please try to make sure the joint is rotated correctly.
Up:[[Tutorial]] Previous:[[Samples of the dynami...
#highlight(end)
#counter
End:
Up:[[Tutorial]] Previous:[[Samples of the dynami...
----
#contents
*Operations on the movement of agents [#v2485f29]
Describes how to operate the joints of agents or anthropo...
** Operations of joints of robots[#f5cb7768]
Here is the sample code to change the angle of joint of ...
***Creating the Controller [#oc032119]
Let's create a controller file AgentController.cpp in the...
$ emacs AgentController.cpp
AgentController.cpp
#highlight(cpp){{
#include "Controller.h"
#include "Logger.h"
#define PI 3.141592
//Coverts angles to radians
#define DEG2RAD(DEG) ( (PI) * (DEG) / 180.0 )
class AgentController : public Controller
{
public:
double onAction(ActionEvent &evt);
};
//This function is called on regular basis
double AgentController::onAction(ActionEvent &evt)
{
try {
// get handle for the agent
SimObj *my = getObj(myname());
if (!my->dynamics()) {
// "LARM_JOINT2" is set to 45 degrees
my->setJointAngle("LARM_JOINT2", DEG2RAD(45));
}
} catch(SimObj::Exception &) {
;
}
return 5.0;
}
extern "C" Controller * createController ()
{
return new AgentController;
}
}}
In this controller, the avatar agent bend the left arm to...
*** Compilation [#p15fd2cd]
The same script sigmake.sh should be used for the compila...
$ ./sigmake.sh AgentController.cpp
*** Creating world files [#l5dd7972]
Then create a world file in the same workspace.
$ emacs AgentWorld.xml
AgentWorld.xml
#highlight(xml){{
<?xml version="1.0" encoding="utf8"?>
<world name="AgentWorld">
<!--Set gravity-->
<gravity x="0.0" y="-9.8" z="0.0"/>
<!--object of agent Man-nii-->
<instanciate class="Man-nii.xml">
<!--Agent Name-->
<set-attr-value name="name" value="man_000"/>
<!--C++ is the programming language-->
<set-attr-value name="language" value="c++"/>
<!--Controller file for the object-->
<set-attr-value name="implementation" value="./A...
<!--put the flag of dynamics to false-->
<set-attr-value name="dynamics" value="false"/>
<!--setting the initial position of agent (x,y,z)-->
<set-attr-value name="x" value="0.0"/>
<set-attr-value name="y" value="50.0"/>
<set-attr-value name="z" value="0.0"/>
</instanciate>
</world>
}}
The file specifies Man-nii.xml as humanoid avatar. Dynami...
Please be careful that you cannot specify such concrete j...
*** Starting SIGVerse [#g6cf60e0]
So let's start SIGVerse.
$ sigserver.sh -w ./AgentWorld.xml
Connect to the SIGServer and push the "START" button to s...
You can see that the agent holds the left arm to 45 degre...
#ref(./man_1.PNG,40%)
We use setJointAngle to set the angle of "LARM_JOINT2" to...
Joint names of these files are defined in sigverse-x3d <v...
Joint names and join definitions of the sample model desc...
Man-nii humanoid agent is an object that inherits from th...
$ less xml/Agent.xml
#highlight(xml){{
<?xml version="1.0" encoding="utf8"?>
<define-class name="Agent" inherit="Entity.xml">
<attr name="language" type="string" group="model"/>
<attr name="implementation" type="string" group="model"/>
<!-- view point(agent coordinate) -->
<attr name="vpx" type="double" group="viewpoint" value="...
<attr name="vpy" type="double" group="viewpoint" value="...
<attr name="vpz" type="double" group="viewpoint" value="...
<!-- view vector(view coordinate) -->
<attr name="vvx" type="double" group="viewvector" value=...
<attr name="vvy" type="double" group="viewvector" value=...
<attr name="vvz" type="double" group="viewvector" value=...
}}
Furthermore, Agent class has inherited the Entity class. ...
***Agents, basic attributes of an entity[#g14c1ee2]
Entities introduces the basic properties of the agent.
Attribute of an entity
| Attribute Name | Meaning | Remarks |
| x, y, z | position of the entity | global coordinates. ...
| fx, fy, fz | force on the entity | |
| vx, vy, vz | speed of the entity | |
| qw, qx, qy, qz | direction of the entity | Quaternion n...
| scalex, scaley, scalez | the size of the entity | |
Agent attributes
| Attribute Name | Meaning | Remarks |
| vpx, vpy, vpz | position of the viewpoint of the agent ...
| vvx, vvy, vvz | gaze direction (non-humanoid) | vector ...
| elnk1, elnk2, ... elnk9 | viewpoint (camera) to establi...
| epx1, epy1, epz1, ... epx9, epy9, epz9 | viewpoint (cam...
| evx1, evy1, evz1, ... evx9, evy9, evz9 | viewpoint (cam...
| FOV | Agent viewing angle (height) | |
| voiceReachRadius | Agent voices reach | |
These attributes can be set in all the world files.
** Operating agents with a Command [#t5a2daa5]
In the above example, a function onAction was used to rai...
Let's create another controller file named AgentControlle...
$ emacs AgentController2.cpp
AgetnController2.cpp
#highlight(cpp){{
#include <string> //include string header files
#include "Controller.h"
#include "Logger.h"
#include "ControllerEvent.h"
#define PI 3.141592
#define DEG2RAD(DEG) ( (PI) * (DEG) / 180.0 )
using namespace std; //Using namespace definitions
class AgentController : public Controller
{
public:
double onAction(ActionEvent &evt);
// Declare the use of onRecvMessage function when it re...
void AgentController::onRecvMsg(RecvMsgEvent &evt)
};
double AgentController::onAction(ActionEvent &evt)
{
try {
SimObj *my = getObj(myname());
if (!my->dynamics()) {
// Lower down the left.
my->setJointAngle("LARM_JOINT2", DEG2RAD(-90));
// Lower down the right
my->setJointAngle("RARM_JOINT2", DEG2RAD(90));
}
} catch(SimObj::Exception &) {
;
}
return 5.0;
}
void AgentController::onRecvMsg(RecvMsgEvent &evt)
{
//get an handle to agent
SimObj *my = getObj(myname());
// string message is received
std::string value(evt.getMsg());
if (value =="Hello"){
//bend the hip joint to 45[deg]
my->setJointAngle("WAIST_JOINT1", DEG2RAD(45));
}
}
extern "C" Controller * createController ()
{
return new AgentController;
}
}}
agent puts its hands down when onAction function is calle...
The onRecvMessage function will be called when a message ...
Compile the new controller file.
$ ./sigmake.sh AgentController2.cpp
*** World file [#md72d91d]
You should modify the world file to use the new controlle...
#highlight(xml:firstline[16]){{
<!--Controller file for the object-->
<set-attr-value name="implementation"
value="./AgentController.so"/>
}}
↓
#highlight(xml:firstline[16]){{
<!--Controller file for the object-->
<set-attr-value name="implementation"
value="./AgentController2.so"/>
}}
*** Execute the server [#p73b3ced]
Input the following command to execute the SIGVerse server.
$ sigserver.sh -w ./AgentWorld.xml
Start the SIGViewer, and connect to the SIGServer. When y...
#ref(./man_2.PNG,40%)
*** Sending a message [#hb68ba23]
Click the "Message" button on the right bottom of the SIG...
Select the target agent "man_000" in the TargetEntity fie...
#ref(./man_3.PNG,70%)
Click the "Send" button if you input the message.
#ref(./man_4.PNG,40%)
You can see the avator bows.
** Joint rotation with quaternion [#ecbdc67b]
Rotation of the joint can also be set by the quaternion.
AgentController2.cpp
#highlight(cpp:firstline[52]){{
//Bend the Hip joint to 45[deg]
my->setJointAngle("WAIST_JOINT1", DEG2RAD(45));
}}
↓
#highlight(cpp:firstline[52]){{
//Rotate 90 degree around X axis for the hip joint
my->setJointQuaternion("WAIST_JOINT1", 0.707, 0.707, ...
}}
setJointquaternion function sets the joint angle using qu...
Please try to make sure the joint is rotated correctly.
Up:[[Tutorial]] Previous:[[Samples of the dynami...
#highlight(end)
#counter
Page: