dLife Home Page

dlife.robot.player
Class StageSimulationControl

java.lang.Object
  extended by dlife.robot.player.StageSimulationControl

public class StageSimulationControl
extends Object

A StageSimulationControl object allows direct access to robots within the Stage simulation. This will allow to user to place a specific robot anywhere in the world or read its absolute position. Robots are identified by the name that was given to them when creating the simulation. Only one object can be created per host and connects to the simulation via port 6665. The call to 'getStageSimulationControl' will return a reference to a StageSimulationControl for the given host.

Version:
April 25, 2010
Author:
Russell Toris, Dickinson College

Method Summary
 void connect()
          Connect to the Stage simulation if a connection has not already been made.
 void disconnect()
          Disconnect from the Stage simulation if a connection has already been made.
 StagePositionData getPosition(String identifier, int timeout)
          Get the StagePositionData for the robot with the given identifier.
static StageSimulationControl getStageSimulationControl(String host)
          Get a reference to a StageSimulationControl.
 double getStageTime()
          Get the amount of simulated time in seconds that have passed since Stage was started.
 boolean isConnected()
          Returns if there is a connection to the Stage simulation.
 void setPosition(String identifier, StagePositionData pos)
          Set the position of the robot with the given identifier to the position specified in the given StagePositionData.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getStageSimulationControl

public static StageSimulationControl getStageSimulationControl(String host)
Get a reference to a StageSimulationControl. Only one StageSimulationControl can be created per host. The first call to this method with that host will create a new StageSimulationControl. All other calls with the same host will give a reference to that object.

Parameters:
host - the host the Player/Stage simulation is running on
Returns:
a reference to a StageSimulationControl object connected to the given host

connect

public void connect()
Connect to the Stage simulation if a connection has not already been made. Calling this method after a connection has been made will have no effect.


disconnect

public void disconnect()
Disconnect from the Stage simulation if a connection has already been made. Calling this method before a connection has been made or after disconnecting will have no effect.


isConnected

public boolean isConnected()
Returns if there is a connection to the Stage simulation.

Returns:
if there is a connection to the Stage simulation

getPosition

public StagePositionData getPosition(String identifier,
                                     int timeout)
Get the StagePositionData for the robot with the given identifier. This method will attempt to read the data for the time given in timeout in milliseconds. If the given identifier does not exist on the server or no response is heard within 'timeout', null is returned. A timeout of 0 will attempt once to get the data and return either the data if available or null immediately. A timeout of -1 will try an infinite amount of times to get the data. A timeout greater than 0 will indicate the maximum number of milliseconds to wait attempting several tries every few milliseconds between calls.

Parameters:
identifier - the name of the robot to get the position data from
timeout - the maximum number of time in milliseconds to wait
Returns:
the position data from the given robot, or null
Throws:
RobotCommunicationException - thrown if no connection to Player has been made, or if communication to Player has been lost.

setPosition

public void setPosition(String identifier,
                        StagePositionData pos)
Set the position of the robot with the given identifier to the position specified in the given StagePositionData. If a robot with the given identifier does not exist in the simulation, no effect will be seen.

Parameters:
identifier - the name of the robot to move
pos - the position information to move the robot
Throws:
RobotCommunicationException - thrown if we are not connected or we loose communication with Player in this call

getStageTime

public double getStageTime()
Get the amount of simulated time in seconds that have passed since Stage was started.

Returns:
the amount of simulated time in seconds that have passed since Stage was started

dLife Home Page