Communication

This is my simple distributed communications framework in Java. I developed this to let multiple independent agents synchronize its maps of coloured barrels.

So far, it still needs some documentation.

namespace de::cstahlhut::uni::project::communication

This package contains all base classes that provide the interface for the entire framework.

class Barrel

A Barrel that has to be transported to the nest.

Author
Chris Stahlhut

enum BarrelColor

Possible colors of a barrel.

Author
Chris Stahlhut

Public Functions

String de.cstahlhut.uni.project.communication.BarrelColor.toString()

Public Members

de.cstahlhut.uni.project.communication.BarrelColor.BLUE
de.cstahlhut.uni.project.communication.BarrelColor.GREEN
interface

Listens for new barrels.

Author
Chris Stahlhut

Public Functions

void de.cstahlhut.uni.project.communication.BarrelFoundListener.newBarrelFound(Barrel barrel)

Is called, if a new barrel is found.

Parameters
  • barrel -

    the found barrel

class MapPosition

Position in the global map.

Author
Chris Stahlhut

interface

Listens for new connections at the {}.

Author
Chris Stahlhut

Public Functions

void de.cstahlhut.uni.project.communication.NewConnectionListener.connectionEstablished(Exploration exploration)

Is called, if a new slave connected to the master.

Parameters
  • exploration -

    the object, which enables the communication back to the slave

interface

This map will get synchronized over the network with the master map.

Author
Chris Stahlhut

Public Functions

MapPosition de.cstahlhut.uni.project.communication.RobotMap.getPosForPos(GridPosition position)

Translates between GridPosition and the Position of the map.

Grid de.cstahlhut.uni.project.communication.RobotMap.getGrid()

Return
the grid

void de.cstahlhut.uni.project.communication.RobotMap.setBarrel(Barrel barrel)

Sets a Barrel to the specified position.

TODO 2011-12-19 are duplicates possible? What happens, if a barrel has been moved? Does it override the old position?

void de.cstahlhut.uni.project.communication.RobotMap.barrelPickedUp(Barrel barrel)

Marks the Barrel at the given position as picked up.

It can therefore be given another position.

MapPosition de.cstahlhut.uni.project.communication.RobotMap.getMaximumPosition()

Return
the “end” position in the map

void de.cstahlhut.uni.project.communication.RobotMap.setRobotMapPosition(MapPosition position)

Parameters
  • position -

    of the robot using this RobotMap

enum State

Possible states of a robot.

Author
Chris Stahlhut

Public Members

de.cstahlhut.uni.project.communication.State.EXPLORING

Default State.

Bot is explorating.

de.cstahlhut.uni.project.communication.State.TRANSPORTING

Bot is transporting a barrel to the nest.

namespace exploration

This package contains the interface to connect this framework with the exploration behaviour, which is implemented by another group.

interface

This interface ahs to be implemented by the Exploration group to make it possible to be accessed from the Behaviour Group.

Author
Chris Stahlhut

Public Functions

int de.cstahlhut.uni.project.communication.exploration.Exploration.getId()

Return
the id of this robot.

boolean de.cstahlhut.uni.project.communication.exploration.Exploration.hasGripper()

Return
true, if this explorer has a gripper

MapPosition de.cstahlhut.uni.project.communication.exploration.Exploration.getMapPosition()

Return
the position of this explorer on the map

void de.cstahlhut.uni.project.communication.exploration.Exploration.transportBarrelTo(Barrel barrelToTransport, MapPosition targetPositionOfBarrel)

Commands an Explorer to pickup a Barrel at the currentPositionOfBarrel and transport it to the nest at the targetPositionOfBarrel.

State de.cstahlhut.uni.project.communication.exploration.Exploration.getState()

Return
the State of this explorer

enum RobotState

Public Members

de.cstahlhut.uni.project.communication.exploration.Exploration.RobotState.ON_THE_WAY
de.cstahlhut.uni.project.communication.exploration.Exploration.RobotState.NEEDS_NEW_GOAL
de.cstahlhut.uni.project.communication.exploration.Exploration.RobotState.OPENING_GRIPPER
de.cstahlhut.uni.project.communication.exploration.Exploration.RobotState.GRIPPER_OPEN
de.cstahlhut.uni.project.communication.exploration.Exploration.RobotState.CLOSING_GRIPPER
de.cstahlhut.uni.project.communication.exploration.Exploration.RobotState.GRIPPER_CLOSE
de.cstahlhut.uni.project.communication.exploration.Exploration.RobotState.DRIVING_TO_BARREL
de.cstahlhut.uni.project.communication.exploration.Exploration.RobotState.BARREL_REACHED
de.cstahlhut.uni.project.communication.exploration.Exploration.RobotState.TRANSPORTING_BARREL
de.cstahlhut.uni.project.communication.exploration.Exploration.RobotState.BARREL_TARGET_REACHED
interface

Grid for the exploration group.

Has to be synchronized with every other bot.

Author
Chris Stahlhut

Public Functions

GridPosition de.cstahlhut.uni.project.communication.exploration.Grid.convertToGridPosition(MapPosition position)

Converts the given MapPosition to a position in the grid.

Return
Parameters
  • position -

void de.cstahlhut.uni.project.communication.exploration.Grid.setOwnRobotPosition(GridPosition position)

Sets the position of this grid.

GridPosition de.cstahlhut.uni.project.communication.exploration.Grid.getOwnRobotPosition()

Get own position as GridPosition.

boolean de.cstahlhut.uni.project.communication.exploration.Grid.isRobotOnWayToToken(GridPosition position)

Return
true, if there is already a bot on the way to the tokens on the specified position.

void de.cstahlhut.uni.project.communication.exploration.Grid.increaseToken(int token, GridPosition position)

Increases the number of tokens at the given position at the given amount.

token >= 0

int de.cstahlhut.uni.project.communication.exploration.Grid.getToken(GridPosition position)

Return
the number of tokens at the given position token >= 0

void de.cstahlhut.uni.project.communication.exploration.Grid.setRobotOnWayTo(Exploration robot, GridPosition position)

Sets the given robot as on the way to the specified position.

Parameters
  • robot -

    on the way

  • position -

    target position of the robot

boolean de.cstahlhut.uni.project.communication.exploration.Grid.isValuePosition(GridPosition position)

Return
true if the given position is e.g. not within a wall
Parameters
  • position -

class GridPosition

Position in the grid for the exploration group.

Author
Chris Stahlhut

namespace network

This package contains implementation of the network related parts, i.e.

the synchronisation server and synchronisable objects.

class Client

Client implementation.

Connects to the and send commands and data to it.

Server 
Author
Chris Stahlhut

enum CommandHeader

All possible commands between master, client and exploration group.

Author
Chris Stahlhut

Public Members

de.cstahlhut.uni.project.communication.network.CommandHeader.INCREASE_TOKEN
de.cstahlhut.uni.project.communication.network.CommandHeader.BARREL_PICKED_UP
de.cstahlhut.uni.project.communication.network.CommandHeader.SEND_BARREL_POSITION
de.cstahlhut.uni.project.communication.network.CommandHeader.UPDATE_MAP_LINE
de.cstahlhut.uni.project.communication.network.CommandHeader.UPDATE_GRID_LINE
de.cstahlhut.uni.project.communication.network.CommandHeader.SET_ROBOT_POSITION
de.cstahlhut.uni.project.communication.network.CommandHeader.SET_ROBOT_ON_WAY_TO_POSITION
de.cstahlhut.uni.project.communication.network.CommandHeader.EXPLORATION_SERVER_SETUP
de.cstahlhut.uni.project.communication.network.CommandHeader.GRIPPER_ASKED
de.cstahlhut.uni.project.communication.network.CommandHeader.TRANSPORT_BARREL_TO
class CommunicationFactory

Factory to create the master and slave maps.

Should be the only public classes in this package.

Author
Chris Stahlhut

class CommunicationOperations

Utility class for operations, that involve the transfer of objects over the network.

Author
Chris Stahlhut

class ExplorationClient

Client for the exploration group.

Bridges between the communication framework and the exploration group.

Author
Chris Stahlhut

class ExplorationCommandListener

Listener for the slave to get all commands for the exploration group.

Author
Chris Stahlhut

class MasterListener

Gets updated if any command has been received by the server.

Then takes the appropriate action.

Author
Chris Stahlhut

class MasterMap

The central.

which collects all the data of every slave and can be synchronized with a slave.

RobotMap 
Author
cstahlhut

class NetworkSynchronizedGrid

Simple implementation of a.

. Does not yet implement everything.

Grid 
Author
Chris Stahlhut

class NetworkSynchronizedMap

Implementation of the RobotMap interface.

This map synchronizes itself over the network with the master Map.

Author
Chris Stahlhut

class NetworkTransferableBarrel

Wrapper class for a.

so it can be send over the network

Barrel 
Author
cstahlhut

class NetworkTransferableGrid

Simple implementation of the behavior of a.

so it can be used.

Grid 
Author
cstahlhut

class NetworkTransferablePosition

Wrapper class for.

and for the network transfer.

MapPosition 
GridPosition 
Author
Chris Stahlhut

class NetworkTransferableRobotMap

Contains all data of a local map or the master map.

Can be send over the network.

Author
Chris Stahlhut

class NetworkTransferableToken

Wrapper class for a token, so it can be transfered over the network.

Author
Chris Stahlhut

interface

Gets updated if a command has been received.

Author
Chris Stahlhut

Public Functions

void de.cstahlhut.uni.project.communication.network.PeriodicTransferListener.update(CommandHeader header, Socket slaveSocket, int robotId)

Parameters
  • header -

  • slaveSocket -

  • robotId -

    id of the client robot

class Server

Waits for connections and informs the.

of incoming commands.

PeriodicTransferListener 
Author
Chris Stahlhut