simbad.sim
Class SimpleAgent

java.lang.Object
  extended by simbad.sim.BaseObject
      extended by simbad.sim.SimpleAgent
Direct Known Subclasses:
Agent, BallAgent, CherryAgent

public class SimpleAgent
extends BaseObject

This is the base class for all kinds of physical agents.
Implementation note : the agent doesnt have synchronized methods. All thread refering to the agent should do explicit synchronization with synchronized(agent){...}..


Field Summary
private  java.util.ArrayList actuators
          The agent's actuators
protected  javax.vecmath.Vector3d angularAcceleration
          Current angular acceleration about the center of mass.
protected  javax.vecmath.Vector3d angularVelocity
          Current angular velocity about the center of mass.
protected  javax.media.j3d.Node body
           
private  javax.media.j3d.BoundingSphere collisionBounds
           
private  javax.vecmath.Point3d collisionBoundsCenter
           
(package private)  boolean collisionDetected
          Collision flag
protected  double[] collisionDistance
          Used for collision picking
private  javax.media.j3d.PickBounds collisionPickBounds
          Bounds for collision detection
protected  double collisionRadius
           
private  int counter
          Counter incremented on each simulation step
protected  float dynamicFrictionCoefficient
           
protected  float height
          Agent's Height in meters
protected  javax.vecmath.Vector3d instantRotation
          Current rotation step.
protected  javax.vecmath.Vector3d instantTranslation
          Current translation step.
private  java.util.ArrayList interactingAgents
          List of currently interacting agent
(package private)  boolean interactionDetected
          Interagent interaction indicator
private  double lifetime
          Lifetime in seconds since last reset
protected  javax.vecmath.Vector3d linearAcceleration
          Current linear acceleration of the center of mass.
protected  javax.vecmath.Vector3d linearVelocity
          Current linear velocity of the center of mass.
protected  float mass
          Agent's mass in kilogram
protected  java.lang.String name
          Agent's printable name
protected  double odometer
           
protected  boolean positionChanged
          Position has changed between two steps.
protected  float radius
          Agent's radius in meters
private  java.util.ArrayList sensors
          The agent's sensors
private  Simulator simulator
          Parent simulator.
private  javax.vecmath.Vector3d startPosition
          Start and restart position of the agent
protected  float staticFrictionCoefficient
          Agent's static friction coefficient - 0 = no friction
protected  javax.media.j3d.Transform3D t3d1
           
protected  javax.media.j3d.Transform3D t3d2
           
protected  javax.media.j3d.Transform3D t3d3
           
protected  javax.vecmath.Vector3d v1
          for intermediate computations and to minimize Gargabe collection
private  javax.vecmath.Vector3d v2
           
(package private)  SimpleAgent veryNearAgent
          Keeps track of agent in physical contact with this agent.
 
Fields inherited from class simbad.sim.BaseObject
black, branchGroup, canBeTraversed, compilable, detachedFromSceneGraph, group, localBounds, material, rotation, rotationGroup, translation, translationGroup, white, world
 
Constructor Summary
SimpleAgent(javax.vecmath.Vector3d pos, java.lang.String name)
          Constructs a SimpleAgent.
 
Method Summary
protected  int addActuatorDevice(ActuatorDevice ad, javax.vecmath.Vector3d position, double angle)
          Adds a actuator device to the agent.
protected  int addSensorDevice(SensorDevice sd, javax.vecmath.Vector3d position, double angle)
          Adds a sensor device to the agent.
 boolean anOtherAgentIsVeryNear()
          Returns true if this agent is in physical contact with an other SimpleAgent.
 java.lang.String asString()
          Returns printable description of the agent.
protected  void checkCollision(javax.media.j3d.BranchGroup pickableSceneBranch, boolean checkGeometry)
          Checks for 3D geometrical collisions Note : this is used in case PhysicalEngine is disabled.
protected  void clearVeryNear()
          called back by simulator to clear physical interaction other agent.
 boolean collisionDetected()
          Returns the state of the geometric collision indicator.
protected  void create()
          Creation phase - called once by the simulator.
protected  void create3D()
           
protected  void dispose()
          Dispose all resources
protected  double distanceToGround()
          returns the distance from agent base to ground .
 ActuatorDevice getActuatorDevice(int num)
          Returns the actuator device designated by num.
 java.util.ArrayList getActuatorList()
           
 void getCoords(javax.vecmath.Point3d coord)
          Return agents coordinates.
 void getCoords(javax.vecmath.Vector3d coord)
          Return agents coordinates.
 int getCounter()
          Returns the agent counter.
 float getHeight()
          Returns the agent's height in meters.
 double getLifeTime()
          Returns the agent total lifetime since last reset (in seconds).
 float getMass()
          Gets the agent's mass.
 java.lang.String getName()
          Returns the agent's name.
 float getRadius()
          Returns the agent's radius in meters.
 SensorDevice getSensorDevice(int num)
          Returns the sensor device designated by num.
 java.util.ArrayList getSensorList()
           
 SimpleAgent getVeryNearAgent()
          Returns the currently touched agent - null if no agent near.
protected  void initBehavior()
          called by simulator init
protected  void initPreBehavior()
          called by simulator init
protected  void integratesPositionChange(double dt)
          Perform velocities integration step .¬
protected  void integratesVelocities(double dt)
          Perform acceleration integration step .
 boolean interactionDetected()
          Returns true if an interaction has been detected.
 void moveToPosition(double x, double z)
          Go to given XZ position.
 void moveToPosition(javax.vecmath.Vector3d position)
          Go to given position.
 void moveToStartPosition()
          Go to the start position of the agent.
protected  void performBehavior()
          called by simulator loop
protected  void performPreBehavior()
          called by simulator loop
protected  void reset()
          Resets agent variables and position
protected  void resetDevices()
          Resets all devices
protected  void resetPosition()
           
protected  void resetPositionAt(javax.vecmath.Vector3d newPosition)
           
protected  void setMotorsAcceleration(double dt)
          set acceleration applied by motors .
protected  void setSimulator(Simulator simulator)
          Sets the simulator in charge of this agent.
protected  void updateActuators(double elapsedSecond)
          Update actuators phase - called on each simulation step.
protected  void updateCounters(double elapsedSecond)
          Update all counters on each step.
protected  void updatePosition()
          Update the agent's position with instantTranslation and instantRotation
protected  void updateSensors(double elapsedSecond, javax.media.j3d.BranchGroup pickableSceneBranch)
          Update sensor phase - called on each simulation step.
protected  void veryNear(SimpleAgent a)
          called back by simulator when a physical interaction as occurred with an other agent.
 
Methods inherited from class simbad.sim.BaseObject
addChild, addChild, attach, compile, create3D, detach, getBounds, getCanBeTraversed, getGroup, getNode, getRotationTransform, getRotationTransformGroup, getTranslation, getTranslationTransform, getTranslationTransform, resetTransforms, rotateY, setBounds, setCanBeTraversed, setColor, setWorld, translateTo
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

name

protected java.lang.String name
Agent's printable name


collisionDetected

boolean collisionDetected
Collision flag


interactionDetected

boolean interactionDetected
Interagent interaction indicator


veryNearAgent

SimpleAgent veryNearAgent
Keeps track of agent in physical contact with this agent. null most of the time


simulator

private Simulator simulator
Parent simulator.


sensors

private java.util.ArrayList sensors
The agent's sensors


actuators

private java.util.ArrayList actuators
The agent's actuators


collisionPickBounds

private javax.media.j3d.PickBounds collisionPickBounds
Bounds for collision detection


collisionBounds

private javax.media.j3d.BoundingSphere collisionBounds

collisionBoundsCenter

private javax.vecmath.Point3d collisionBoundsCenter

v1

protected javax.vecmath.Vector3d v1
for intermediate computations and to minimize Gargabe collection


v2

private javax.vecmath.Vector3d v2

t3d1

protected javax.media.j3d.Transform3D t3d1

t3d2

protected javax.media.j3d.Transform3D t3d2

t3d3

protected javax.media.j3d.Transform3D t3d3

interactingAgents

private java.util.ArrayList interactingAgents
List of currently interacting agent


startPosition

private javax.vecmath.Vector3d startPosition
Start and restart position of the agent


counter

private int counter
Counter incremented on each simulation step


lifetime

private double lifetime
Lifetime in seconds since last reset


odometer

protected double odometer

positionChanged

protected boolean positionChanged
Position has changed between two steps.


body

protected javax.media.j3d.Node body

height

protected float height
Agent's Height in meters


radius

protected float radius
Agent's radius in meters


mass

protected float mass
Agent's mass in kilogram


staticFrictionCoefficient

protected float staticFrictionCoefficient
Agent's static friction coefficient - 0 = no friction


dynamicFrictionCoefficient

protected float dynamicFrictionCoefficient

linearAcceleration

protected javax.vecmath.Vector3d linearAcceleration
Current linear acceleration of the center of mass.


angularAcceleration

protected javax.vecmath.Vector3d angularAcceleration
Current angular acceleration about the center of mass.


linearVelocity

protected javax.vecmath.Vector3d linearVelocity
Current linear velocity of the center of mass.


angularVelocity

protected javax.vecmath.Vector3d angularVelocity
Current angular velocity about the center of mass.


instantTranslation

protected javax.vecmath.Vector3d instantTranslation
Current translation step.


instantRotation

protected javax.vecmath.Vector3d instantRotation
Current rotation step.


collisionDistance

protected double[] collisionDistance
Used for collision picking


collisionRadius

protected double collisionRadius
Constructor Detail

SimpleAgent

public SimpleAgent(javax.vecmath.Vector3d pos,
                   java.lang.String name)
Constructs a SimpleAgent.

Parameters:
pos - the starting position.
name - the name of the agent.
Method Detail

create3D

protected void create3D()

create

protected void create()
Creation phase - called once by the simulator.


reset

protected void reset()
Resets agent variables and position


resetPosition

protected void resetPosition()

resetPositionAt

protected void resetPositionAt(javax.vecmath.Vector3d newPosition)

resetDevices

protected void resetDevices()
Resets all devices


updateSensors

protected void updateSensors(double elapsedSecond,
                             javax.media.j3d.BranchGroup pickableSceneBranch)
Update sensor phase - called on each simulation step.


updateActuators

protected void updateActuators(double elapsedSecond)
Update actuators phase - called on each simulation step.


setMotorsAcceleration

protected void setMotorsAcceleration(double dt)
set acceleration applied by motors .


integratesVelocities

protected void integratesVelocities(double dt)
Perform acceleration integration step .


integratesPositionChange

protected void integratesPositionChange(double dt)
Perform velocities integration step .¬


distanceToGround

protected double distanceToGround()
returns the distance from agent base to ground .


updatePosition

protected void updatePosition()
Update the agent's position with instantTranslation and instantRotation


checkCollision

protected void checkCollision(javax.media.j3d.BranchGroup pickableSceneBranch,
                              boolean checkGeometry)
Checks for 3D geometrical collisions Note : this is used in case PhysicalEngine is disabled. Precondition : instantTranslation and instantRotaion are computed for the current step.

Parameters:
pickableSceneBranch - The scene branch containing all collidable objects.

updateCounters

protected void updateCounters(double elapsedSecond)
Update all counters on each step.


initPreBehavior

protected void initPreBehavior()
called by simulator init


initBehavior

protected void initBehavior()
called by simulator init


performPreBehavior

protected void performPreBehavior()
called by simulator loop


performBehavior

protected void performBehavior()
called by simulator loop


collisionDetected

public boolean collisionDetected()
Returns the state of the geometric collision indicator.

Returns:
collision indicator.

interactionDetected

public boolean interactionDetected()
Returns true if an interaction has been detected.

Returns:
interaction indicator.

moveToStartPosition

public void moveToStartPosition()
Go to the start position of the agent.


moveToPosition

public void moveToPosition(javax.vecmath.Vector3d position)
Go to given position. Caution : set y coords to agent.height/2 you want the agent to touch the floor.

Parameters:
position - - the new position.

moveToPosition

public void moveToPosition(double x,
                           double z)
Go to given XZ position. Y coords is left unchanged.

Parameters:
position - - the new position.

addSensorDevice

protected int addSensorDevice(SensorDevice sd,
                              javax.vecmath.Vector3d position,
                              double angle)
Adds a sensor device to the agent.

Parameters:
num - - the requested position in the sensor list.
sd - - the device.
position - - its position relative to agent's center.
angle - - its angle in the XZ plane.
Returns:
the num of the sensor

addActuatorDevice

protected int addActuatorDevice(ActuatorDevice ad,
                                javax.vecmath.Vector3d position,
                                double angle)
Adds a actuator device to the agent.

Parameters:
num - - the requested position in the sensor list.
sd - - the device.
position - - its position relative to agent's center.
angle - - its angle in the XZ plane.
Returns:
the num of the actuator

dispose

protected void dispose()
Dispose all resources


asString

public java.lang.String asString()
Returns printable description of the agent. This may be multiline and complex in subclasses.

Returns:
agent description as string.

setSimulator

protected void setSimulator(Simulator simulator)
Sets the simulator in charge of this agent.


getSensorList

public java.util.ArrayList getSensorList()

getActuatorList

public java.util.ArrayList getActuatorList()

getLifeTime

public double getLifeTime()
Returns the agent total lifetime since last reset (in seconds).

Returns:
lifetime in seconds.

getCoords

public void getCoords(javax.vecmath.Point3d coord)
Return agents coordinates.


getCoords

public void getCoords(javax.vecmath.Vector3d coord)
Return agents coordinates.


getCounter

public int getCounter()
Returns the agent counter. Counter is incrementented at each simulation step.

Returns:
agent step counter.

getName

public java.lang.String getName()
Returns the agent's name.

Returns:
agent's name .

getMass

public float getMass()
Gets the agent's mass.


getRadius

public float getRadius()
Returns the agent's radius in meters.

Returns:
the agent radius in meters.

getHeight

public float getHeight()
Returns the agent's height in meters.

Returns:
the agent height in meters.

getSensorDevice

public SensorDevice getSensorDevice(int num)
Returns the sensor device designated by num. User will have to cast to the appropriate class.

Returns:
a SensorDevice Object.

getActuatorDevice

public ActuatorDevice getActuatorDevice(int num)
Returns the actuator device designated by num. User will have to cast to the appropriate class.

Returns:
a ActuatorDevice Object.

clearVeryNear

protected void clearVeryNear()
called back by simulator to clear physical interaction other agent.


veryNear

protected void veryNear(SimpleAgent a)
called back by simulator when a physical interaction as occurred with an other agent.


anOtherAgentIsVeryNear

public boolean anOtherAgentIsVeryNear()
Returns true if this agent is in physical contact with an other SimpleAgent.


getVeryNearAgent

public SimpleAgent getVeryNearAgent()
Returns the currently touched agent - null if no agent near.