Class Bird

java.lang.Object
  |
  +--SerialConnection
        |
        +--Bird
All Implemented Interfaces:
java.util.EventListener, javax.comm.SerialPortEventListener

public class Bird
extends SerialConnection

A class to handle state information for each bird. Birds can either have their own serial lines to the host, or they may send all their data through master.

Some assumptions about use:
We assume that the flock is being controlled by the master, and that all serial communications come through the master. Each bird may manage it's own data, but when in flock mode, all of the communication goes through the master bird.

Data rates: We calculated the size of the data using the following assumptions.


Field Summary
private  boolean active
          Field indicates that the bird is actively part of the flock.
private  int addr
          This is the bird's address within the flock and follows the addreses set on the dipswitches on the back of the flock of birds hardware.
private  boolean angleAlign2Changed
          Indicates that the ANGLE ALIGN2 parameters have been set
private  float[] angles
          This stores the last reported ANGLES measurement
static int ANGLES_NUM_BYTES
          The number of bytes in an angles record
static java.lang.String anglesData
          Type of data that may be coming from the bird.
static java.lang.String axisAngleData
          Type of data that may be coming from the bird.
private  java.lang.String currentDataType
          Indicates the type of data that the bird is currently processing
static java.lang.String examineData
          Type of data that may be coming from the bird.
private  Flock flock
          A reference to the flock this bird belongs to.
private  boolean isMaster
          Field indicates if this bird is a flock master.
static java.lang.String matrixData
          Type of data that may be coming from the bird.
private  int measurementRate
          The measurement rate in cyles/sec
private  java.lang.String portName
          The port where the bird serial connection is.
static java.lang.String positionData
          Type of data that may be coming from the bird.
static java.lang.String positionMatrixData
          Type of data that may be coming from the bird.
private static int QUATERNION_NUM_BYTES
          The number of bytes in a quaternion record
static java.lang.String quaternionData
          Type of data that may be coming from the bird.
private  boolean streaming
          Indicates that the bird is in the streaming mode
 
Fields inherited from class SerialConnection
appName, baudRate, inStream, listener, open, outStream, portId, portList, serialPort, timeout
 
Constructor Summary
Bird(Flock fl, boolean master, int addr, java.lang.String port, boolean active)
          Create a bird at the specified address and the specified port name.
 
Method Summary
 void connect()
          Open the serial connection.
 float[] getAngles()
          Get the last set orientation of the Bird in ANGLES mode.
 java.lang.String getDataType()
          Get the current data type
 boolean isAngleAlign2Changed()
          Find out if Angle Align2 was set.
 boolean isConnected()
          Says whether or not this bird is connected.
static int recordSizeOfDataType(java.lang.String type)
          Returns the record size of the given dataType.
 void setActive(boolean fl)
          Sets the active flag.
 void setAngleAlign2Changed()
          Set the angle align2 change to true.
 void setAngles(float[] a)
          Set the orientation of the Bird in ANGLES mode.
 void setDataType(java.lang.String type)
          Sets the data type
 void setMeasurementRate(int r)
          This should correspond to the measurement rate that the bird has been set to.
 void setStreaming(boolean b)
          Used by the flock to tell the bird that it is in streaming mode.
 
Methods inherited from class SerialConnection
closeConnection, getSerialConectionListener, isOpen, openConnection, serialEvent, setSerialConnectionListener, writeByte, writeByte
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

portName

private java.lang.String portName
The port where the bird serial connection is.

addr

private int addr
This is the bird's address within the flock and follows the addreses set on the dipswitches on the back of the flock of birds hardware. Note: addresses start at 1 (not 0). The master bird has address 1 and all others have sequential contiguous addresses

angles

private float[] angles
This stores the last reported ANGLES measurement

flock

private Flock flock
A reference to the flock this bird belongs to.

isMaster

private boolean isMaster
Field indicates if this bird is a flock master. true if this is a master; false if this is a slave

active

private boolean active
Field indicates that the bird is actively part of the flock. If it is active, then when the bird is asked to fly its serial connection will be opened. Otherwise, no serial connection set up

streaming

private boolean streaming
Indicates that the bird is in the streaming mode

currentDataType

private java.lang.String currentDataType
Indicates the type of data that the bird is currently processing

angleAlign2Changed

private boolean angleAlign2Changed
Indicates that the ANGLE ALIGN2 parameters have been set

measurementRate

private int measurementRate
The measurement rate in cyles/sec

matrixData

public static final java.lang.String matrixData
Type of data that may be coming from the bird.
See Also:
currentDataType

positionData

public static final java.lang.String positionData
Type of data that may be coming from the bird.
See Also:
currentDataType

quaternionData

public static final java.lang.String quaternionData
Type of data that may be coming from the bird.
See Also:
currentDataType

positionMatrixData

public static final java.lang.String positionMatrixData
Type of data that may be coming from the bird.
See Also:
currentDataType

examineData

public static final java.lang.String examineData
Type of data that may be coming from the bird.
See Also:
currentDataType

axisAngleData

public static final java.lang.String axisAngleData
Type of data that may be coming from the bird.
See Also:
currentDataType

anglesData

public static final java.lang.String anglesData
Type of data that may be coming from the bird.
See Also:
currentDataType

QUATERNION_NUM_BYTES

private static final int QUATERNION_NUM_BYTES
The number of bytes in a quaternion record

ANGLES_NUM_BYTES

public static final int ANGLES_NUM_BYTES
The number of bytes in an angles record
Constructor Detail

Bird

public Bird(Flock fl,
            boolean master,
            int addr,
            java.lang.String port,
            boolean active)
Create a bird at the specified address and the specified port name.
Parameters:
fl - The flock class that this bird belongs to.
master - Indicates whether this is a master bird or a slave bird.
addr - is the address of this bird within the flock
port - is the name of the COM port this bird is communicating through.
active - indicates whether or not the bird is actively part of the flock.
Method Detail

isConnected

public boolean isConnected()
Says whether or not this bird is connected.

connect

public void connect()
Open the serial connection. Effectively connects the bird to the host.

setMeasurementRate

public void setMeasurementRate(int r)
This should correspond to the measurement rate that the bird has been set to. If it has never been set, it will return -1. Note, this does not return the value that an EXAMINE MEASUREMENT RATE might return. This just says what we tried to set it to.

setStreaming

public void setStreaming(boolean b)
Used by the flock to tell the bird that it is in streaming mode.

setAngles

public void setAngles(float[] a)
Set the orientation of the Bird in ANGLES mode.

getAngles

public float[] getAngles()
Get the last set orientation of the Bird in ANGLES mode.

setAngleAlign2Changed

public void setAngleAlign2Changed()
Set the angle align2 change to true.

isAngleAlign2Changed

public boolean isAngleAlign2Changed()
Find out if Angle Align2 was set.

setDataType

public void setDataType(java.lang.String type)
Sets the data type

setActive

public void setActive(boolean fl)
Sets the active flag.

getDataType

public java.lang.String getDataType()
Get the current data type

recordSizeOfDataType

public static int recordSizeOfDataType(java.lang.String type)
Returns the record size of the given dataType.