Up:Tutorial     Previous:Humanoid agent operations     Next:Vision sensor


Exchange of messages between agents.

※This tutorial is valid only for later than v2.1.0.

Sending and receiving messages

Controller of message sender

Create a controller for sending messages.

$ cd ~/MyWorld
$ emacs SendController.cpp

This controller send a message "Hello!" to the robot agent every second.

If you want to send a message to all of the agents in the world, you should use broadcastMsg instead of sendMsg.

Old

New

Controller to receive messages

Create a controller to receive messages.

$ emacs RecvController.cpp

This controller put the agent's hand up if a message "Hello!!" comes. The agent will put the hand down every 0.5 second.

Compiling the controller.

$ ./sigmake.sh SendController.cpp RecvController.cpp

Creating a worldfile

$ emacs MessageWorld.xml

In this controller, a human avator will send a message to a humanoid agent.

Execution

$ sigserver.sh -w ./MessageWorld.xml 

First, the avatar agent put a hand down and turn back by onInit function. Then, you can see that the agent put it's hand up every second with receiving a message.

message_1.PNG

Specification of message reachable area

This part explains how to specify the maximum length of the reachable area of the message sending function.

Controller of text message sender

Create another controller to send messages.

$ emacs SendController2.cpp 

SendController2.cpp

The second argument of the broadcastMsg, 300, means that the maximum distance of the message reachable area is 3 meters. If you omit the secnod argument, the message will be reached to all of the agents irrespective of the distance.

This agent keeps on sending a message and moving to z-axis.

Compiling

$ ./sigmake.sh SendController2.cpp

Modification of the world file

$ emacs MessageWorld.xml

Modify the MessageWorld.xml to change the controller for sending agent

Old

New

Execution

$ sigserver.sh -w ./MessageWorld.xml
message_3.PNG

You can see the agent sending messages with backing away from the receiver. Please check how far the message reaches to the receiver.

Sending message to the SIGViewer

If the broadcastMsg is used, the message will be reached to all of the agents, SIGViewer and SIGVerse services. The SIGViewer will show the received message as log message.

You can send messages to the SIGViewer using sendMsg. In this case, you should specify a service name which is determined when the SIGViewer connected to the SIGverse server. If the service name is "SIGViewer", the following modification will change the sending target from the agent to the SIGViewer.

SendController.so

Old

New

Up:Tutorial     Previous:Humanoid agent operations     Next:Vision sensor

Counter: 2203, today: 3, yesterday: 0

Attach file: filemessage_1.PNG 852 download [Information] filemessage_3.PNG 810 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: 2016-03-31 (Thu) 15:55:35 (541d)