EDU.gatech.cc.is.abstractrobot
Class SocSmallSim

java.lang.Object
  |
  +--EDU.gatech.cc.is.abstractrobot.Simple
        |
        +--EDU.gatech.cc.is.abstractrobot.SocSmallSim

public class SocSmallSim
extends Simple
implements SocSmall, SimulatedObject

Implements SocSmall for simulation. You should see the specifications in SocSmall for details on how to use these methods.

Copyright (c)1997, 1998 Tucker Balch

See Also:
SocSmall

Field Summary
static boolean DEBUG
           
 
Fields inherited from class EDU.gatech.cc.is.abstractrobot.Simple
dictionary, displayVectors, unique_id
 
Fields inherited from interface EDU.gatech.cc.is.abstractrobot.SocSmall
KICKER_SPEED, KICKER_SPOT_RADIUS, MAX_STEER, MAX_TRANSLATION, RADIUS
 
Constructor Summary
SocSmallSim()
          Instantiate a SocSmallSim object.
 
Method Summary
 void broadcast(Message m)
          Broadcast a message to all teammates, except self.
 boolean canKick(long timestamp)
          Reveals whether or not the ball is in a position to be kicked.
 boolean checkCollision(Circle2 c)
          determine if the object is intersecting with a specified circle.
 boolean checkCollision(Polygon2 p)
          determine if the object is intersecting with a specified polygon.
 void clearTrail()
          Clear the trail.
 boolean connected()
          Check to see if the transceiver is connected to the server.
 void draw(java.awt.Graphics g, int w, int h, double t, double b, double l, double r)
          Draw the robot.
 void draw(Vec2 pos, java.awt.Graphics g, int w, int h, double t, double b, double l, double r)
          Draw the robot in a specific spot.
 void drawIcon(java.awt.Graphics g, int w, int h, double t, double b, double l, double r)
          Draw the object as an icon.
 void drawID(java.awt.Graphics g, int w, int h, double t, double b, double l, double r)
          Draw the robot's ID.
 void drawState(java.awt.Graphics g, int w, int h, double t, double b, double l, double r)
          Draw the robot's state.
 void drawTrail(java.awt.Graphics g, int w, int h, double t, double b, double l, double r)
          Draw the robot's Trail.
 java.awt.Color getBackgroundColor()
          Gets the background color of the robot.
 Vec2 getBall(long timestamp)
          Get a Vec2 that points to the ball.
 Vec2 getCenter(Vec2 from)
          Find the center point of the object from a particular location.
 Vec2 getClosestPoint(Vec2 from)
          Find the closest point on the object from a particular location.
 java.awt.Color getForegroundColor()
          Gets the foreground color of the robot.
 int getJustScored(long timestamp)
          Get an integer that indicates whether a scoring event just occured.
 Vec2[] getObstacles(long timestamp)
          Get an array of Vec2s that point egocentrically from the center of the robot to the obstacles currently sensed by the bumpers and sonars.
 Vec2[] getOpponents(long timestamp)
          Get an array of Vec2s that point egocentrically from the center of the robot to the Opponents currently sensed by the robot.
 Vec2 getOpponentsGoal(long timestamp)
          Get a Vec2 that points to the opponent's goal.
 Vec2 getOurGoal(long timestamp)
          Get a Vec2 that points to the team's goal.
 int getPlayerNumber(long timestamp)
          Return an int represting the player's ID on the team.
 Vec2 getPosition()
          Get the position of the robot in global coordinates.
 Vec2 getPosition(long timestamp)
          Get the position of the robot in global coordinates.
 CircularBufferEnumeration getReceiveChannel()
          Get an enumeration of the incoming messages.
 double getSteerHeading(long timestamp)
          Get the current heading of the steering motor.
 Vec2[] getTeammates(long timestamp)
          Get an array of Vec2s that point egocentrically from the center of the robot to the teammates currently sensed by the robot.
 long getTime()
          Gets time elapsed since the robot was instantiated.
 int getVisionClass()
          Return the vision class of the object.
 void init(double xp, double yp, double tp, double ignore, java.awt.Color f, java.awt.Color b, int v, int i, long s)
          Initialize a SocSmallSim object.
 boolean isObstacle()
          true if the object should be considered an obstacle, false otherwise.
 boolean isPickupable()
          true if the object can be picked up, false otherwise.
 boolean isPushable()
          true if the object is pushable false otherwise.
 void kick(long timestamp)
          If the ball can be kicked, kick it.
 void multicast(int[] ids, Message m)
          Transmit a message to specific teammates.
 void pickUp(SimulatedObject o)
          Try to pick up the object.
 void push(Vec2 d, Vec2 v)
          Try to push the object.
 void putDown(Vec2 p)
          Try to put down the object.
 void quit()
          Clean up.
 void receive(Message m)
          Receive a message.
 void resetPosition(Vec2 posit)
          Reset the odometry of the robot in global coordinates.
 void resetSteerHeading(double heading)
          Reset the steering odometry of the robot in global coordinates.
 void setBaseSpeed(double speed)
          Set the base speed for the robot (translation) in meters per second.
 void setCommunicationMaxRange(double m)
          Set the maximum range at which communication can occur.
 void setDisplayString(java.lang.String s)
          Set the String that is printed on the robot's display.
 void setKinMaxRange(double range)
          Set the maximum range at which a sensor reading should be considered kin.
 void setObstacleMaxRange(double range)
          Set the maximum range at which a sensor reading should be considered an obstacle.
 void setSpeed(long timestamp, double speed)
          Set the desired speed for the robot (translation).
 void setSteerHeading(long timestamp, double heading)
          Set the desired heading for the steering motor.
 void setTrailLength(int l)
          Set the length of the trail (in movement steps).
 void setVisionClass(int v)
          Change the way the object is perceived by vision hardware.
 void takeStep(long time_increment, SimulatedObject[] all_objs)
          Take a simulated step;
 void unicast(int id, Message m)
          Transmit a message to just one teammate.
 
Methods inherited from class EDU.gatech.cc.is.abstractrobot.Simple
getDictionary, getID, getID, setDictionary, setID
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEBUG

public static final boolean DEBUG
Constructor Detail

SocSmallSim

public SocSmallSim()
Instantiate a SocSmallSim object. Be sure to also call init with proper values.
See Also:
init(double, double, double, double, java.awt.Color, java.awt.Color, int, int, long)
Method Detail

init

public void init(double xp,
                 double yp,
                 double tp,
                 double ignore,
                 java.awt.Color f,
                 java.awt.Color b,
                 int v,
                 int i,
                 long s)
Initialize a SocSmallSim object. Some of the parameters are ignored because soccer robots have specific starting places and headings.
Specified by:
init in interface SimulatedObject
Parameters:
xp - if negative, it means this robot is on the west team, east team otherwise.
yp - ignored.
tp - ignored.
ignore - ignored.
f - color 1 for the robot.
b - color 2 for the robot.
v - vision class of the robot (usually 1 or 2 depending on whether on west team or east team).
i - unique simulation id (NOT the same as player number!).

takeStep

public void takeStep(long time_increment,
                     SimulatedObject[] all_objs)
Take a simulated step;
Specified by:
takeStep in interface SimulatedObject
Tags copied from interface: SimulatedObject
Parameters:
time_increment - how much time has elapsed since the last call.
all_objects - the other objects in the simulation.

isObstacle

public boolean isObstacle()
Description copied from interface: SimulatedObject
true if the object should be considered an obstacle, false otherwise.
Specified by:
isObstacle in interface SimulatedObject
Tags copied from interface: SimulatedObject
Returns:
true if the object should be considered an obstacle, false otherwise.

isPushable

public boolean isPushable()
Description copied from interface: SimulatedObject
true if the object is pushable false otherwise.
Specified by:
isPushable in interface SimulatedObject
Tags copied from interface: SimulatedObject
Returns:
true if the object is pushable, false otherwise.

isPickupable

public boolean isPickupable()
Description copied from interface: SimulatedObject
true if the object can be picked up, false otherwise.
Specified by:
isPickupable in interface SimulatedObject
Tags copied from interface: SimulatedObject
Returns:
true if the object can be picked up, false otherwise.

getClosestPoint

public Vec2 getClosestPoint(Vec2 from)
Description copied from interface: SimulatedObject
Find the closest point on the object from a particular location. This is useful for obstacle avoidance and so on.
Specified by:
getClosestPoint in interface SimulatedObject
Tags copied from interface: SimulatedObject
Parameters:
from - the place from which the point is determined.
Returns:
the closest point.

checkCollision

public boolean checkCollision(Circle2 c)
determine if the object is intersecting with a specified circle. This is useful for obstacle avoidance and so on.
Specified by:
checkCollision in interface SimulatedObject
Parameters:
c - the circle which may be intersecting the current object.
Returns:
true if collision detected.

checkCollision

public boolean checkCollision(Polygon2 p)
determine if the object is intersecting with a specified polygon. This is useful for obstacle avoidance and so on.
Specified by:
checkCollision in interface SimulatedObject
Parameters:
p - the polygon which may be intersecting the current object.
Returns:
true if collision detected.

getCenter

public Vec2 getCenter(Vec2 from)
Description copied from interface: SimulatedObject
Find the center point of the object from a particular location.
Specified by:
getCenter in interface SimulatedObject
Tags copied from interface: SimulatedObject
Parameters:
from - the place from which the point is determined.
Returns:
the center point.

push

public void push(Vec2 d,
                 Vec2 v)
Description copied from interface: SimulatedObject
Try to push the object.
Specified by:
push in interface SimulatedObject
Tags copied from interface: SimulatedObject
Parameters:
d - the direction and distance of the push.
v - the velocity of the push.

pickUp

public void pickUp(SimulatedObject o)
Description copied from interface: SimulatedObject
Try to pick up the object.
Specified by:
pickUp in interface SimulatedObject
Tags copied from interface: SimulatedObject
Parameters:
o - the object picking it up - this is used for drawing purposes.

putDown

public void putDown(Vec2 p)
Description copied from interface: SimulatedObject
Try to put down the object.
Specified by:
putDown in interface SimulatedObject
Tags copied from interface: SimulatedObject
Parameters:
p - the location of deposit.

setVisionClass

public void setVisionClass(int v)
Description copied from interface: SimulatedObject
Change the way the object is perceived by vision hardware. This can be used to make old targets invisible (a simulation hack.... sorry).
Specified by:
setVisionClass in interface SimulatedObject
Tags copied from interface: SimulatedObject
Parameters:
v - the new vision class.

getVisionClass

public int getVisionClass()
Description copied from interface: SimulatedObject
Return the vision class of the object.
Specified by:
getVisionClass in interface SimulatedObject
Tags copied from interface: SimulatedObject
Parameters:
v - the new vision class.

getForegroundColor

public java.awt.Color getForegroundColor()
Description copied from interface: SimpleInterface
Gets the foreground color of the robot.
Overrides:
getForegroundColor in class Simple

getBackgroundColor

public java.awt.Color getBackgroundColor()
Description copied from interface: SimpleInterface
Gets the background color of the robot.
Overrides:
getBackgroundColor in class Simple

draw

public void draw(Vec2 pos,
                 java.awt.Graphics g,
                 int w,
                 int h,
                 double t,
                 double b,
                 double l,
                 double r)
Draw the robot in a specific spot.
Specified by:
draw in interface SimulatedObject
Tags copied from interface: SimulatedObject
Parameters:
p - location to draw it at.
g - graphics area to draw the object.
w - the width in pixels of g.
h - the height in pixels of g.
t - the y coordinate represented by the top boundary of the drawing area.
b - the y coordinate represented by the bottom boundary of the drawing area.
l - the x coordinate represented by the left boundary of the drawing area.
r - the x coordinate represented by the right boundary of the drawing area.

drawTrail

public void drawTrail(java.awt.Graphics g,
                      int w,
                      int h,
                      double t,
                      double b,
                      double l,
                      double r)
Draw the robot's Trail.
Specified by:
drawTrail in interface SimulatedObject
Tags copied from interface: SimulatedObject
Parameters:
g - graphics area to draw the object.
w - the width in pixels of g.
h - the height in pixels of g.
t - the y coordinate represented by the top boundary of the drawing area.
b - the y coordinate represented by the bottom boundary of the drawing area.
l - the x coordinate represented by the left boundary of the drawing area.
r - the x coordinate represented by the right boundary of the drawing area.

setDisplayString

public void setDisplayString(java.lang.String s)
Set the String that is printed on the robot's display. For simulated robots, this appears printed below the agent when view "Robot State" is selected.
Overrides:
setDisplayString in class Simple
Parameters:
s - String, the text to display.

drawState

public void drawState(java.awt.Graphics g,
                      int w,
                      int h,
                      double t,
                      double b,
                      double l,
                      double r)
Draw the robot's state.
Specified by:
drawState in interface SimulatedObject
Tags copied from interface: SimulatedObject
Parameters:
g - graphics area to draw the object.
w - the width in pixels of g.
h - the height in pixels of g.
t - the y coordinate represented by the top boundary of the drawing area.
b - the y coordinate represented by the bottom boundary of the drawing area.
l - the x coordinate represented by the left boundary of the drawing area.
r - the x coordinate represented by the right boundary of the drawing area.

setTrailLength

public void setTrailLength(int l)
Set the length of the trail (in movement steps).
Specified by:
setTrailLength in interface SimulatedObject
Parameters:
l - int, the length of the trail.

clearTrail

public void clearTrail()
Clear the trail.
Specified by:
clearTrail in interface SimulatedObject

drawID

public void drawID(java.awt.Graphics g,
                   int w,
                   int h,
                   double t,
                   double b,
                   double l,
                   double r)
Draw the robot's ID.
Specified by:
drawID in interface SimulatedObject
Tags copied from interface: SimulatedObject
Parameters:
g - graphics area to draw the object.
w - the width in pixels of g.
h - the height in pixels of g.
t - the y coordinate represented by the top boundary of the drawing area.
b - the y coordinate represented by the bottom boundary of the drawing area.
l - the x coordinate represented by the left boundary of the drawing area.
r - the x coordinate represented by the right boundary of the drawing area.

drawIcon

public void drawIcon(java.awt.Graphics g,
                     int w,
                     int h,
                     double t,
                     double b,
                     double l,
                     double r)
Draw the object as an icon. Default is just to do a regular draw.
Specified by:
drawIcon in interface SimulatedObject
Tags copied from interface: SimulatedObject
Parameters:
g - graphics area to draw the object.
w - the width in pixels of g.
h - the height in pixels of g.
t - the y coordinate represented by the top boundary of the drawing area.
b - the y coordinate represented by the bottom boundary of the drawing area.
l - the x coordinate represented by the left boundary of the drawing area.
r - the x coordinate represented by the right boundary of the drawing area.

draw

public void draw(java.awt.Graphics g,
                 int w,
                 int h,
                 double t,
                 double b,
                 double l,
                 double r)
Draw the robot.
Specified by:
draw in interface SimulatedObject
Tags copied from interface: SimulatedObject
Parameters:
g - graphics area to draw the object.
w - the width in pixels of g.
h - the height in pixels of g.
t - the y coordinate represented by the top boundary of the drawing area.
b - the y coordinate represented by the bottom boundary of the drawing area.
l - the x coordinate represented by the left boundary of the drawing area.
r - the x coordinate represented by the right boundary of the drawing area.

quit

public void quit()
Clean up.
Specified by:
quit in interface SimulatedObject
Overrides:
quit in class Simple

getTime

public long getTime()
Gets time elapsed since the robot was instantiated. Since this is simulation, it may not match real elapsed time.
Overrides:
getTime in class Simple

getOpponents

public Vec2[] getOpponents(long timestamp)
Get an array of Vec2s that point egocentrically from the center of the robot to the Opponents currently sensed by the robot.
Parameters:
timestamp - only get new information if timestamp > than last call or timestamp == -1 .
Returns:
the sensed Opponents.

getTeammates

public Vec2[] getTeammates(long timestamp)
Get an array of Vec2s that point egocentrically from the center of the robot to the teammates currently sensed by the robot.
Parameters:
timestamp - only get new information if timestamp > than last call or timestamp == -1 .
Returns:
the sensed teammates.

getBall

public Vec2 getBall(long timestamp)
Description copied from interface: BallSensor
Get a Vec2 that points to the ball.
Tags copied from interface: BallSensor
Parameters:
timestamp - only get new information if timestamp > than last call or timestamp == -1.
Returns:
the sensed location of the ball
See Also:
Vec2

getJustScored

public int getJustScored(long timestamp)
Get an integer that indicates whether a scoring event just occured.
Parameters:
timestamp - only get new information if timestamp > than last call or timestamp == -1.
Returns:
1 if team just scored, -1 if scored against, 0 otherwise.

getOurGoal

public Vec2 getOurGoal(long timestamp)
Description copied from interface: GoalSensor
Get a Vec2 that points to the team's goal. This is the one to defend.
Tags copied from interface: GoalSensor
Parameters:
timestamp - only get new information if timestamp > than last call or timestamp == -1.
Returns:
the sensed location of the goal
See Also:
Vec2

getOpponentsGoal

public Vec2 getOpponentsGoal(long timestamp)
Description copied from interface: GoalSensor
Get a Vec2 that points to the opponent's goal. This is the one to get the ball across to score.
Tags copied from interface: GoalSensor
Parameters:
timestamp - only get new information if timestamp > than last call or timestamp == -1.
Returns:
the sensed location of the goal
See Also:
Vec2

getPlayerNumber

public int getPlayerNumber(long timestamp)
Return an int represting the player's ID on the team. This value may not be valid if the simulation has not been "set up" yet. Do not use it during initialization.
Parameters:
timestamp - only get new information if timestamp > than last call or timestamp == -1 .
Returns:
the number.

canKick

public boolean canKick(long timestamp)
Description copied from interface: KickActuator
Reveals whether or not the ball is in a position to be kicked.
Tags copied from interface: KickActuator
Parameters:
timestamp - only get new information if timestamp > than last call or timestamp == -1.
Returns:
true if the ball can be kicked, false otherwise.

kick

public void kick(long timestamp)
Description copied from interface: KickActuator
If the ball can be kicked, kick it.
Tags copied from interface: KickActuator
Parameters:
timestamp - not used, but retained for compatibility.

getObstacles

public Vec2[] getObstacles(long timestamp)
Get an array of Vec2s that point egocentrically from the center of the robot to the obstacles currently sensed by the bumpers and sonars.
Overrides:
getObstacles in class Simple
Parameters:
timestamp - only get new information if timestamp > than last call or timestamp == -1 .
Returns:
the sensed obstacles.

setKinMaxRange

public void setKinMaxRange(double range)
Set the maximum range at which a sensor reading should be considered kin. Beyond this range, the readings are ignored. Also used by opponent sensor. The default range on startup is 1 meter.
Parameters:
range - the range in meters.

setObstacleMaxRange

public void setObstacleMaxRange(double range)
Set the maximum range at which a sensor reading should be considered an obstacle. Beyond this range, the readings are ignored. The default range on startup is 1 meter.
Overrides:
setObstacleMaxRange in class Simple
Parameters:
range - the range in meters.

getPosition

public Vec2 getPosition(long timestamp)
Get the position of the robot in global coordinates.
Overrides:
getPosition in class Simple
Parameters:
timestamp - only get new information if timestamp > than last call or timestamp == -1.
Returns:
the position.
See Also:
Simple.resetPosition(EDU.gatech.cc.is.util.Vec2)

getPosition

public Vec2 getPosition()
Get the position of the robot in global coordinates.
Specified by:
getPosition in interface SimulatedObject
Returns:
the position.
See Also:
Simple.resetPosition(EDU.gatech.cc.is.util.Vec2)

resetPosition

public void resetPosition(Vec2 posit)
Reset the odometry of the robot in global coordinates. This might be done when reliable sensor information provides a very good estimate of the robot's location, or if you are starting the robot in a known location other than (0,0). Do this only if you are certain you're right!
Overrides:
resetPosition in class Simple
Parameters:
position - the new position.
See Also:
Simple.getPosition(long)

getSteerHeading

public double getSteerHeading(long timestamp)
Description copied from interface: SimpleInterface
Get the current heading of the steering motor.
Overrides:
getSteerHeading in class Simple
Tags copied from interface: SimpleInterface
Parameters:
timestamp - only get new information if timestamp > than last call or timestamp == -1.
Returns:
the heading in radians.
See Also:
Simple.setSteerHeading(long, double)

resetSteerHeading

public void resetSteerHeading(double heading)
Description copied from interface: SimpleInterface
Reset the steering odometry of the robot in global coordinates. This might be done when reliable sensor information provides a very good estimate of the robot's heading. Do this only if you are certain you're right!
Overrides:
resetSteerHeading in class Simple
Tags copied from interface: SimpleInterface
Parameters:
heading - the new heading in radians.
See Also:
Simple.getSteerHeading(long), Simple.setSteerHeading(long, double)

setSteerHeading

public void setSteerHeading(long timestamp,
                            double heading)
Description copied from interface: SimpleInterface
Set the desired heading for the steering motor.
Overrides:
setSteerHeading in class Simple
Tags copied from interface: SimpleInterface
Parameters:
heading - the heading in radians.
timestamp - only get new information if timestamp > than last call or timestamp == -1.
See Also:
Simple.getSteerHeading(long)

setSpeed

public void setSpeed(long timestamp,
                     double speed)
Description copied from interface: SimpleInterface
Set the desired speed for the robot (translation). The speed must be between 0 and 1; where 0 is stopped and 1.0 is "full blast". It will be clipped to whichever limit it exceeds. Also, underlying software will keep the actual speed at zero until the steering motor is close to the desired heading. Use setBaseSpeed to adjust the top speed.
Overrides:
setSpeed in class Simple
See Also:
setSpeed(long, double)

setBaseSpeed

public void setBaseSpeed(double speed)
Description copied from interface: SimpleInterface
Set the base speed for the robot (translation) in meters per second. Base speed is how fast the robot will move when setSpeed(1.0) is called. The speed must be between 0 and MAX_TRANSLATION. It will be clipped to whichever limit it exceeds.
Overrides:
setBaseSpeed in class Simple
See Also:
setBaseSpeed(double)

multicast

public void multicast(int[] ids,
                      Message m)
               throws CommunicationException
Description copied from interface: Transceiver
Transmit a message to specific teammates. Transmission to self is allowed.
Tags copied from interface: Transceiver
Parameters:
ids - int[], the IDs of the agents to receive the message.
m - Message, the message to transmit.
Throws:
CommunicationException - if one of the receiving agents does not exist.

broadcast

public void broadcast(Message m)
Description copied from interface: Transceiver
Broadcast a message to all teammates, except self.
Tags copied from interface: Transceiver
Parameters:
m - Message, the message to be broadcast.

unicast

public void unicast(int id,
                    Message m)
             throws CommunicationException
Description copied from interface: Transceiver
Transmit a message to just one teammate. Transmission to self is allowed.
Tags copied from interface: Transceiver
Parameters:
id - int, the ID of the agent to receive the message.
m - Message, the message to transmit.
Throws:
CommunicationException - if the receiving agent does not exist.

getReceiveChannel

public CircularBufferEnumeration getReceiveChannel()
Description copied from interface: Transceiver
Get an enumeration of the incoming messages. The messages are automatically buffered by the implementation. Unless the implementation guarantees it, you cannot count on all messages being delivered. Example, to print all incoming messages:
 Transceiver c = new RobotComm();
 Enumeration r = c.getReceiveChannel();
 while (r.hasMoreElements())
 	System.out.println(r.nextElement());
 
Tags copied from interface: Transceiver
Returns:
the Enumeration.

setCommunicationMaxRange

public void setCommunicationMaxRange(double m)
Description copied from interface: Transceiver
Set the maximum range at which communication can occur. In simulation, this corresponds to a simulation of physical limits, on mobile robots it corresponds to a signal strength setting.
Tags copied from interface: Transceiver
Parameters:
r - double, the maximum range.

receive

public void receive(Message m)
Description copied from interface: SimulatedObject
Receive a message. This is principally for robot to robot communication. Most objects can safely ignore this.
Specified by:
receive in interface SimulatedObject
Tags copied from interface: SimulatedObject
Parameters:
m - the message.

connected

public boolean connected()
Description copied from interface: Transceiver
Check to see if the transceiver is connected to the server.