dLife Home Page

dlife.robot.aibo
Class WorldState

java.lang.Object
  extended by java.lang.Thread
      extended by dlife.robot.aibo.WorldState
All Implemented Interfaces:
Runnable

public class WorldState
extends Thread

The WorldState class is a threaded data structure that constantly filters through the streaming output from the Aibo's WorldStateSerializer. The constructor makes a connection that opens the WorldState port to start the streaming. Once the port is open, the run method continuously reads the sensor data and stores the latest readings in the appropriate array.

Version:
Feb. 18, 2008, Oct 3, 2008, June 14,2010
Author:
Mike Olasin, Luke Maffey, Alex Diehl, Nate Mitchell, Grant Braught

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
 
Field Summary
static int WORLD_STATE_PORT
          The standard port on which the Aibo runs its World State Serializer.
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
WorldState(Aibo aibo)
          Create a WorldState object for the provided Aibo.
 
Method Summary
protected  String buttonsString()
          Converts the button array to a readable string
 void clear()
          Will empty out a WorldState structure by setting all values to 0 and the model name to "".
 void connect()
          Send the command to the Aibo to start up its World State Serializer, connect to it and start reading the data that it is sending.
 void disconnect()
          Stop reading the Aibo's sensor data from the World State Serializer, disconnect from the World State Serializer and ask the Aibo to shutdown its Serializer.
protected  String dutiesString()
          Converts the duties array to a readable string
 float getButton_pawLFront()
          Returns the float value of the left front paw button
 float getButton_pawLRear()
          Returns the float value of the left rear paw button
 float getButton_pawRFront()
          Returns the float value of the right front paw button
 float getButton_pawRRear()
          Returns the float value of the right rear paw button
 float getButton(int index)
          Accessor that returns a requested value from the button array
 float getButtonBackF()
          Returns the float value of the front back button
 float getButtonBackM()
          Returns the float value of the middle back button
 float getButtonBackR()
          Returns the float value of the rear back button
 float getButtonChin()
          Returns the float value of the chin button
 float getButtonHead()
          Returns the float value of the head button
 float getDuty(int index)
          Accessor that returns a requested value from the duties array
 long getFrame()
          Accessor that returns the frame of the Aibo
 float getHeadNod()
          Get the Aibo's head nod.
 float getHeadPan()
          Get the Aibo's head pan.
 float getHeadTilt()
          Get the Aibo's head tilt.
 float getJoint(int index)
          Returns the specific joint information requested through the index input
 String getModelName()
          Accessor that returns the model name of the Aibo
 float getPID(int index)
          Accessor that returns a requested value from the pid array
 float getSensor(int index)
          Accessor that returns a requested value from the sensor array
 float getSensorAccelFB()
          Returns the float value of the front to back accelerometer
 float getSensorAccelRL()
          Returns the float value of the right to left accelerometer
 float getSensorAccelUD()
          Returns the float value of the up and down accelerometer
 float getSensorBattery()
          Returns the float value of the battery sensor
 float getSensorCurrent()
          Returns the float value of the current sensor
 float getSensorIRChest()
          Returns the float value of the chest IR sensor
 float getSensorIRFar()
          Returns the float value of the far IR sensor
 float getSensorIRNear()
          Returns the float value of the near IR sensor
 float getSensorPower()
          Returns the float value of the power sensor
 float getSensorTemperature()
          Returns the float value of the temperature sensor
 float getSensorVoltage()
          Returns the float value of the voltage sensor
 long getTimestamp()
          Accessor that returns the current timestamp
 void parseStream(DataInputStream fromServer)
          Parses a data stream of information on sensors, joints, and buttons based on the Tekkotsu data stream format.
protected  String pidString()
          Converts the pid array to a readable string
 char readChar(InputStream in)
          Returns a single character read from the input stream supplied
 long readUnsignedInt(InputStream in)
          Returns a long containing an unsigned int read in from the input stream
 void run()
          Read data from the Aibo's World State Serializer in a continuous loop until the done flag is set.
 void scalePIDs()
           
protected  String sensorsString()
          Converts the sensor array to a readable string
 void setDone()
          Shut down the read loop for this WorldState object.
 String toString()
          Returns a string representation of the WorldState, combining all other methods converting the arrays to strings
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, yield
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

WORLD_STATE_PORT

public static final int WORLD_STATE_PORT
The standard port on which the Aibo runs its World State Serializer.

See Also:
Constant Field Values
Constructor Detail

WorldState

public WorldState(Aibo aibo)
Create a WorldState object for the provided Aibo. The WorldState does not start the World State Serializer on the Aibo until the connect method is invoked.

Parameters:
aibo - the Aibo on which to start and connect to the World State Serializer
Method Detail

clear

public void clear()
Will empty out a WorldState structure by setting all values to 0 and the model name to "".


connect

public void connect()
Send the command to the Aibo to start up its World State Serializer, connect to it and start reading the data that it is sending. After invoking this method the data from the Aibo's sensors should be available via the accessor methods in this class.


disconnect

public void disconnect()
Stop reading the Aibo's sensor data from the World State Serializer, disconnect from the World State Serializer and ask the Aibo to shutdown its Serializer.


setDone

public void setDone()
Shut down the read loop for this WorldState object. This simply sets a flag that causes the loop in the run method to exit.


getTimestamp

public long getTimestamp()
Accessor that returns the current timestamp

Returns:
timestamp, the timestamp associated with the data.

getModelName

public String getModelName()
Accessor that returns the model name of the Aibo

Returns:
modelName, the model name associated with the data

getFrame

public long getFrame()
Accessor that returns the frame of the Aibo

Returns:
frame, the frame associated with the data

getPID

public float getPID(int index)
Accessor that returns a requested value from the pid array

Parameters:
index - the desired index of the array to retrieve
Returns:
the value at the desired index of the pid array

getSensor

public float getSensor(int index)
Accessor that returns a requested value from the sensor array

Parameters:
index - the desired index of the array to retrieve
Returns:
the value at the desired index of the sensor array

getButton

public float getButton(int index)
Accessor that returns a requested value from the button array

Parameters:
index - the desired index of the array to retrieve
Returns:
the value at the desired index of the button array

getDuty

public float getDuty(int index)
Accessor that returns a requested value from the duties array

Parameters:
index - the desired index of the array to retrieve
Returns:
the value at the desired index of the duties array

pidString

protected String pidString()
Converts the pid array to a readable string

Returns:
a readable string of pid values

dutiesString

protected String dutiesString()
Converts the duties array to a readable string

Returns:
a readable string of duties' values

sensorsString

protected String sensorsString()
Converts the sensor array to a readable string

Returns:
a readable string of sensor values

buttonsString

protected String buttonsString()
Converts the button array to a readable string

Returns:
a readable string of button values

toString

public String toString()
Returns a string representation of the WorldState, combining all other methods converting the arrays to strings

Overrides:
toString in class Thread
Returns:
a string representation of WorldState

getButton_pawLFront

public float getButton_pawLFront()
Returns the float value of the left front paw button

Returns:
a float value of pressure on the left front paw button

getButton_pawRFront

public float getButton_pawRFront()
Returns the float value of the right front paw button

Returns:
a float value of pressure on the right front paw button

getButton_pawLRear

public float getButton_pawLRear()
Returns the float value of the left rear paw button

Returns:
a float value of pressure on the left rear paw button

getButton_pawRRear

public float getButton_pawRRear()
Returns the float value of the right rear paw button

Returns:
a float value of pressure on the right rear paw button

getSensorBattery

public float getSensorBattery()
Returns the float value of the battery sensor

Returns:
a float value of battery power remaining

getSensorTemperature

public float getSensorTemperature()
Returns the float value of the temperature sensor

Returns:
a float value of the aibo's temperature

getSensorPower

public float getSensorPower()
Returns the float value of the power sensor

Returns:
a float value of the aibo's power

getSensorVoltage

public float getSensorVoltage()
Returns the float value of the voltage sensor

Returns:
a float value of the aibo's voltage

getSensorCurrent

public float getSensorCurrent()
Returns the float value of the current sensor

Returns:
a float value of the aibo's current

getButtonChin

public float getButtonChin()
Returns the float value of the chin button

Returns:
a float value of pressure on chin button

getButtonHead

public float getButtonHead()
Returns the float value of the head button

Returns:
a float value of pressure on the head button

getButtonBackF

public float getButtonBackF()
Returns the float value of the front back button

Returns:
a float value of pressure on the front back button

getButtonBackM

public float getButtonBackM()
Returns the float value of the middle back button

Returns:
a float value of pressure on the middle back button

getButtonBackR

public float getButtonBackR()
Returns the float value of the rear back button

Returns:
a float value of pressure on the rear back button

getSensorAccelFB

public float getSensorAccelFB()
Returns the float value of the front to back accelerometer

Returns:
a float value of acceleration in the front to back direction

getSensorAccelRL

public float getSensorAccelRL()
Returns the float value of the right to left accelerometer

Returns:
a float value of acceleration in the right to left direction

getSensorAccelUD

public float getSensorAccelUD()
Returns the float value of the up and down accelerometer

Returns:
a float value of acceleration in the up to down direction

getJoint

public float getJoint(int index)
Returns the specific joint information requested through the index input

Parameters:
index - an integer that determines which joint information is returned
Returns:
the float value of a specific joint

getHeadPan

public float getHeadPan()
Get the Aibo's head pan.

Returns:
the pan.

getHeadTilt

public float getHeadTilt()
Get the Aibo's head tilt.

Returns:
the tilt.

getHeadNod

public float getHeadNod()
Get the Aibo's head nod.

Returns:
the nod.

getSensorIRNear

public float getSensorIRNear()
Returns the float value of the near IR sensor

Returns:
a float value of aibo's near IR sensor data

getSensorIRFar

public float getSensorIRFar()
Returns the float value of the far IR sensor

Returns:
a float value of aibo's far IR sensor data

getSensorIRChest

public float getSensorIRChest()
Returns the float value of the chest IR sensor

Returns:
a float value of aibo's chest IR sensor data

scalePIDs

public void scalePIDs()

parseStream

public void parseStream(DataInputStream fromServer)
Parses a data stream of information on sensors, joints, and buttons based on the Tekkotsu data stream format.

Parameters:
fromServer - the data stream containing component information

run

public void run()
Read data from the Aibo's World State Serializer in a continuous loop until the done flag is set. The data being read is available via the accessor methods in this class.

Specified by:
run in interface Runnable
Overrides:
run in class Thread

readChar

public char readChar(InputStream in)
              throws IOException
Returns a single character read from the input stream supplied

Parameters:
in - the input stream to be read from
Returns:
a character from the input stream
Throws:
IOException

readUnsignedInt

public long readUnsignedInt(InputStream in)
                     throws IOException
Returns a long containing an unsigned int read in from the input stream

Parameters:
in - an input stream of bits
Returns:
an unsigned integer contained in a long
Throws:
IOException

dLife Home Page