Main Page Class Hierarchy Compound List File List Compound Members File Members

# Communicator Class Reference

`#include <Communicator.h>`

Inheritance diagram for Communicator:

List of all members.

## Detailed Description

This class implements the local communication behavior of the robot. It is only needed when using local communication. First the robot is justified so that it faces the other robot at a close distance. Then it is tried to exchange data with the other robot. If successful their cluster points will be exchanged and the older or denser of the two cluster points is chosen as common cluster point. A new cluster point is set by resetting the robot position. (0,0) is always used as cluster point position as it is easier to push cubes to that position. Thus if a new cluster point is chosen the current robot position is adapted.

Author:
  Jia L. Du

## Public Member Functions
| Communicator ()
int | activate ()
bool | getHaveClusterPoint ()
bool | setClusterPoint (double x, double y)
## Static Public Attributes
const int | DONE = 0
const int | NOT_ONE_RESPONSE = 1
const int | ROBOT_LEFT = 2
## Private Member Functions
bool | justify ()
bool | exchangeData ()
void | int2BYTEArray (int valueToConvert, BYTE *arrayToContainValue)
void | intArray2BYTEArray (int numberOfValues, int *values, BYTE *arrayToContainValues)
void | BYTEArray2Int (BYTE *arrayContainingValue, int &value)
void | BYTEArray2IntArray (int numberOfValues, BYTE *arrayContainingValues, int values[])
void | emptyMessageQueue (void)
## Private Attributes
bool | haveClusterPoint
int | waitingPeriod
Radio * | radio
Timer | timer
Compass * | compass

## Constructor & Destructor Documentation

Communicator::Communicator | ( |  | ) |

## Member Function Documentation

int Communicator::activate | ( |  | ) |

| Activates this behavior Returns: A result code indicating why this behavior terminated. Communicator.DONE or Communicator.NOT_ONE_ RESPONSE or Communicator.ROBOT_LEFT

void Communicator::BYTEArray2Int | ( | BYTE * | arrayContainingValue,
|  | int & | value
| ) | `[private]`

  | Converts an array of BYTEs into an int. The passed array must have enough have at least 4 bytes Parameters:
  arrayContainingValue | the array that is to be converted into an int
  value | a reference to the int that is to contain the int value from the converted array

void Communicator::BYTEArray2IntArray | ( | int | numberOfValues,
|  | BYTE * | arrayContainingValues,
|  | int | values[]
| ) | `[private]`

  | Converts an array of BYTEs into an array of ints. The passed array must have enough have at least 4 bytes for each int that is to be converted Parameters:
  numberOfValues | the number of int values to be converted
  arrayContainingValues | the array that is to be converted into a ints
  values | a pointer to the array of ints that is to contain the int values from the converted BYTE array

void Communicator::emptyMessageQueue | ( | void |  | ) | `[private]`

| Empties the message queue of the radio by reading all messages in the queue. The messages are not retained!

bool Communicator::exchangeData | ( |  | ) | `[private]`

| Tries to exchange data with the robot that we met by sending out messages to all nearby robots and waiting for incoming messages. If exactly one incoming message is received we know that it is probably from the robot facing us. The cluster point age or density and the cluster point location are exchanged. Based on the exchanged data the older or the denser of the two cluster points is chosen as cluster point for this robot Returns: true if the exchange was completed successfully

bool Communicator::getHaveClusterPoint | ( |  | ) |

| Returns: true if the robot does already have a cluster point

void Communicator::int2BYTEArray | ( | int | valueToConvert,
|  | BYTE * | arrayToContainValue
| ) | `[private]`

  | Converts an int into an array of BYTEs. The passed array must have enough space for an int, i.e. at least 4 bytes Parameters:
  valueToConvert | the int value that is to be converted into an array of BYTEs
  arrayToContainValue | a pointer to the array that is to contain the converted int

void Communicator::intArray2BYTEArray | ( | int | numberOfValues,
|  | int * | values,
|  | BYTE * | arrayToContainValues
| ) | `[private]`

  | Converts an array of ints into an array of BYTEs. The passed array of BYTEs must have enough space for the number of ints that are to be converted, i.e. at least 4 bytes for each int Parameters:
  numberOfValues | the number of int values to be converted
  values | the int values that are to be converted into an array of BYTEs
  arrayToContainValues | a pointer to the array that is to contain the converted ints

bool Communicator::justify | ( |  | ) | `[private]`

| Tries to justify this robot so that it faces the robot it tries to communicate with at a close distance Returns: true if justification was successful

bool Communicator::setClusterPoint | ( | double | x,
|  | double | y
| ) |

  | Used to tell the communicator to set the robot's cluster point to the passed position. This is only done if Communicator::getHaveClusterPoint() returns false, i.e. if no cluster point was chosen yet. Otherwise the communicator ignores this command and decides himself which cluster point to use Parameters:
  x | x position of the new cluster point
  y | y position of the new cluster point
Returns: true if new cluster point accepted and set

## Member Data Documentation

Compass* Communicator::compass`[private]`

| The Communicator needs the Compass to correctly exchange its position with the other robot

const int Communicator::DONE = 0`[static]`

| Used as result code for Communicator::activate()

bool Communicator::haveClusterPoint`[private]`

| Stores if the robot does already have a cluster point

const int Communicator::NOT_ONE_RESPONSE = 1`[static]`

| Used as result code for Communicator::activate()

Radio* Communicator::radio`[private]`

| The Communicator uses the Radio to communicate

const int Communicator::ROBOT_LEFT = 2`[static]`

| Used as result code for Communicator::activate()

Timer Communicator::timer`[private]`

| The Communicator has a Timer to determine cluster point ages and to wait for incoming messages

int Communicator::waitingPeriod`[private]`

| Determines how long the robot waits for incoming responses when exchanging data with other robots See also: Communicator::exchangeData()