Class Flock

java.lang.Object
  |
  +--Flock
Direct Known Subclasses:
FlockStub

public class Flock
extends java.lang.Object

Provides sort of a java API to the Flock of Birds. Things to remember about the flock:

The flock addresses are numbered starting at 1.
Each time the baud rate changes in the code, the dipswitch settings on the flock electronics box must be set.

This class handles the high level commands that can be sent to an individual bird or to the flock Master.

It is currently configured so that only the Master sends data back to the host. That is as soon as the flock starts flying, it is put into GROUP MODE. However, settings for individual birds are sent through their respective serial lines.

In this version, as soon as a capture is completed, the data is written to an ascii file called "readable.dat"


Inner Class Summary
(package private)  class Flock.DefaultListener
          This class provides a default serial port listener for the flock.
(package private)  class Flock.ExamineListener
          A class for listening to data elicited by the EXAMINE command.
 
Field Summary
private  int ANGLE_ALIGN2_DATA_SIZE
           
private  byte ANGLE_ALIGN2_PARAM
           
static byte ANGLES_DATA
           
private  byte AUTOCONFIG_PARAM
           
private  float azimReference
          The azimuth (Z) angle for the orientation of the transmitter reference frame
private  Bird[] birds
          An array to hold all of the birds
private  CaptureData captureData
          Holds the sensor data stream and process it.
private  byte CHANGEVALUE_COMMAND
           
private  boolean debug
           
private  Flock.DefaultListener defaultListener
          Default listener to catch bytes coming from any serial line.
private  short defaultMeasurementRate
          The default measurement rate [Hz] for the birds
private  float elevReference
          The elevation (Y) angle for the orientation of the transmitter reference frame
private  Flock.ExamineListener[] eListener
          ExamineListeners for each bird
private  byte EXAMINE_VALUE_COMMAND
           
private  short flockSize
          Number of birds in the flock.
private  byte GROUP_MODE_PARAM
           
private  boolean groupMode
          Indicates that the flock is in GROUP mode.
private  boolean isConnected
          Indicates that the host is talking to the flock
private  Bird master
          A reference to the flock master
private  byte MATRIX_MODE
           
private  int maxFlockSize
          The total number of birds we own.
private  byte MEASUREMENT_RATE_PARAM
           
private  short measurementRate
          The current measurement rate for the birds
private  Capture parent
           
private  byte POINT_COMMAND
           
private  java.lang.String[] portNames
          The 6 port names that we can use
private  byte POSITION_ANGLES_MODE
           
private  int POSITION_ANGLES_NUM_BYTES
           
private  byte POSITION_MATRIX_MODE
           
private  int POSITION_MATRIX_NUM_BYTES
           
private  byte POSITION_MODE
           
private  int POSITION_NUM_BYTES
           
static byte QUATERNION_DATA
           
private static java.lang.String readableFileName
          Name of ascii file that data gets written to.
private  boolean reconfig
          Indicates that the flock size needs to be set.
private  byte REFERENCE_FRAME2_PARAM
           
private  boolean referenceFrameChanged
          Indicates that the reference frame has been changed using the CHANGE REFERENCE FRAME2 command
private  float rollReference
          The roll (X) angle for the orientation of the transmitter reference frame
private  byte RS232_TO_FBB
           
private  byte RUN_COMMAND
           
private  byte SLEEP_COMMAND
           
private  boolean sleeping
          Indicates flock has been put to sleep with the SLEEP command
private  long startTime
          The time in millis that the streaming started
private  long stopTime
          The time in millis that the streaming stopped
private  byte STREAM_COMMAND
           
private  boolean streaming
          Indicates that the STREAM command is in effect
 
Constructor Summary
Flock()
          kind of a dummy constructor
Flock(Capture app)
          Default constructor for Flock.
 
Method Summary
 void beginCapture()
          Starts capturing data.
 void calibrate(int addr, float[] angles)
          Sends the ALIGN2 change command to the bird at this angle.
private  void changeAngleAlign2(int addr, float[] angles)
          Changes the alignment angles.
private  void changeAngleAlign2(int addr, float azim, float elev, float roll)
          Change the X, Y and Z axes of the the sensor for this bird.
private  void changeAutoconfig()
          Initialize the flock to be a certain size.
 void changeMeasurementRate(int addr, short rate)
          Change the measurement rate that the bird returns.
 void changeMeasurementRate(short rate)
          Change the measurement rate for the whole flock.
private  void changeReferenceFrame2(float azimuth, float elevation, float roll)
          Change the reference frame that is used to measure orientation.
 void enableGroupMode()
          Tells the flock to go into group mode.
 void endCapture()
          Ends the capture.
private  void examineAngleAlign2(int addr)
          Examine the angles sent in the last CHANGE ANGLE ALIGN2 command.
 void examineMeasurementRate()
          Examine the measurement rate for the whole flock
 void examineMeasurementRate(int addr)
          Send the EXAMINE command with parameter MEASUREMENT RATE.
private  void examineReferenceFrame2()
          Examine the angles that were sent to the birds using the CHANGE REFERENCE FRAME2 command.
 void fly()
          When the flock is running with a master and slaves, this method is used to tell the flock to start flying.
 SerialConnectionListener getDefaultListener()
          Default listener accessor.
 int getFlockSize()
          Returns the number of active birds in the flock.
private  java.lang.String getQuaternion(byte[] rec)
          Interprets the byte data as a record, and then returns a String representation of it, as well as of the birds address.
 boolean isGroupMode()
          Returns true if the flock is in groupMode, false otherwise.
 boolean isStreaming()
          Returns true if the flock is in streaming mode, false otherwise.
 boolean saveCaptureToFile(java.lang.String filename)
          Saves the last capture to a file.
 void sendAutoconfig()
          Send the changeAutoconfig command as a way to reset the flock if it seems to be having problems.
 void sendPointCommand()
          Sends the point command to the Master bird.
private  void sendPointCommand(int addr)
          Sends the point command to the bird at the particular address
 void sendSleepCommand()
          Sends the sleep command to the Master bird.
private  void sendStreamCommand()
          Sends the stream command to all of the birds in the flock.
 void setAnglesMode()
          Put the whole flock into ANGLES mode
 void setAnglesMode(int addr)
          Put the bird at this address into ANGLES mode.
 void setFlockSize(short size)
          Sets the size of the flock.
 void setMatrixMode()
          Put the whole flock into matrix mode
 void setMatrixMode(int addr)
          Put bird at this address into matrix mode.
 void setQuaternionMode()
          Put the whole flock into QUATERNION mode
 void setQuaternionMode(int addr)
          Put bird at this address into QUATERNION mode.
 void shutdown()
          Puts the birds to sleep and closes the serial connections to the flock.
private  void stopStream()
          Stops the birds from streaming data.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

debug

private final boolean debug

parent

private Capture parent

flockSize

private short flockSize
Number of birds in the flock.

maxFlockSize

private final int maxFlockSize
The total number of birds we own. 6

defaultMeasurementRate

private final short defaultMeasurementRate
The default measurement rate [Hz] for the birds

measurementRate

private short measurementRate
The current measurement rate for the birds

birds

private Bird[] birds
An array to hold all of the birds

master

private Bird master
A reference to the flock master

portNames

private final java.lang.String[] portNames
The 6 port names that we can use

captureData

private CaptureData captureData
Holds the sensor data stream and process it.

eListener

private Flock.ExamineListener[] eListener
ExamineListeners for each bird

defaultListener

private Flock.DefaultListener defaultListener
Default listener to catch bytes coming from any serial line. It exists as a sanity check. Usually a specialized listener will be catching bytes and processing them

isConnected

private boolean isConnected
Indicates that the host is talking to the flock

sleeping

private boolean sleeping
Indicates flock has been put to sleep with the SLEEP command

streaming

private boolean streaming
Indicates that the STREAM command is in effect

startTime

private long startTime
The time in millis that the streaming started

stopTime

private long stopTime
The time in millis that the streaming stopped

reconfig

private boolean reconfig
Indicates that the flock size needs to be set.

groupMode

private boolean groupMode
Indicates that the flock is in GROUP mode.

referenceFrameChanged

private boolean referenceFrameChanged
Indicates that the reference frame has been changed using the CHANGE REFERENCE FRAME2 command

azimReference

private final float azimReference
The azimuth (Z) angle for the orientation of the transmitter reference frame

elevReference

private final float elevReference
The elevation (Y) angle for the orientation of the transmitter reference frame

rollReference

private final float rollReference
The roll (X) angle for the orientation of the transmitter reference frame

readableFileName

private static java.lang.String readableFileName
Name of ascii file that data gets written to.

POSITION_ANGLES_MODE

private final byte POSITION_ANGLES_MODE

POSITION_ANGLES_NUM_BYTES

private final int POSITION_ANGLES_NUM_BYTES

POSITION_MATRIX_MODE

private final byte POSITION_MATRIX_MODE

POSITION_MATRIX_NUM_BYTES

private final int POSITION_MATRIX_NUM_BYTES

POSITION_MODE

private final byte POSITION_MODE

POSITION_NUM_BYTES

private final int POSITION_NUM_BYTES

MATRIX_MODE

private final byte MATRIX_MODE

QUATERNION_DATA

public static final byte QUATERNION_DATA

ANGLES_DATA

public static final byte ANGLES_DATA

CHANGEVALUE_COMMAND

private final byte CHANGEVALUE_COMMAND

EXAMINE_VALUE_COMMAND

private final byte EXAMINE_VALUE_COMMAND

POINT_COMMAND

private final byte POINT_COMMAND

RUN_COMMAND

private final byte RUN_COMMAND

SLEEP_COMMAND

private final byte SLEEP_COMMAND

STREAM_COMMAND

private final byte STREAM_COMMAND

ANGLE_ALIGN2_PARAM

private final byte ANGLE_ALIGN2_PARAM

ANGLE_ALIGN2_DATA_SIZE

private final int ANGLE_ALIGN2_DATA_SIZE

AUTOCONFIG_PARAM

private final byte AUTOCONFIG_PARAM

GROUP_MODE_PARAM

private final byte GROUP_MODE_PARAM

MEASUREMENT_RATE_PARAM

private final byte MEASUREMENT_RATE_PARAM

REFERENCE_FRAME2_PARAM

private final byte REFERENCE_FRAME2_PARAM

RS232_TO_FBB

private final byte RS232_TO_FBB
Constructor Detail

Flock

public Flock()
kind of a dummy constructor

Flock

public Flock(Capture app)
Default constructor for Flock. Assumes that the flock size is 3.
Method Detail

isGroupMode

public boolean isGroupMode()
Returns true if the flock is in groupMode, false otherwise.

getFlockSize

public int getFlockSize()
Returns the number of active birds in the flock.

isStreaming

public boolean isStreaming()
Returns true if the flock is in streaming mode, false otherwise.

getDefaultListener

public SerialConnectionListener getDefaultListener()
Default listener accessor.

setMatrixMode

public void setMatrixMode()
Put the whole flock into matrix mode

setMatrixMode

public void setMatrixMode(int addr)
Put bird at this address into matrix mode. Remember that the bird addresses and the index into the array birds are off by one.
Parameters:
addr - is the address of the bird whose data mode is being set.

calibrate

public void calibrate(int addr,
                      float[] angles)
Sends the ALIGN2 change command to the bird at this angle.
Parameters:
addr - The address of the bird whose sensor is being aligned.
angles - the Z Y X angles that give the new sensor orientation frame.

changeAngleAlign2

private void changeAngleAlign2(int addr,
                               float azim,
                               float elev,
                               float roll)
Change the X, Y and Z axes of the the sensor for this bird. The angle outputs from the Bird are measured in the transmitter's coordinate frame with respect to the sensors's coordinate frame.

We use this command in order to calibrate the sensors. If we measure the sensor's orientation, and then send that orientation to this command without moving the sensors, the next time we measure, the sensor output will all be zero.

The parameters are the difference between the sensor's current orientation and a zeroed orientation.

Parameters:
addr - The address of the bird whose sensor is being changed.
azim - The azimuth (Z) angle.
elev - The elevevation (Y) angle.
roll - The roll (X) angle.
See Also:
"The Flock of Birds Installation and Operation Guide"

changeAngleAlign2

private void changeAngleAlign2(int addr,
                               float[] angles)
Changes the alignment angles.
Parameters:
addr - is the address of the bird to be aligned.
angles - the new angles in order Z Y X.
See Also:
changeAngleAlign2(int, float, float, float)

examineAngleAlign2

private void examineAngleAlign2(int addr)
Examine the angles sent in the last CHANGE ANGLE ALIGN2 command.
See Also:
changeAngleAlign2(int, float, float, float)

changeReferenceFrame2

private void changeReferenceFrame2(float azimuth,
                                   float elevation,
                                   float roll)
Change the reference frame that is used to measure orientation. This aligns the physical axes of the tranmitter to the X,Y,Z axes of the new reference frame. The alignment angles are rotations about the Z, Y, X axes of the transmitter. This does not affect the reference frame used to measure position. For further information on what exactly this does, see the Flock of Birds reference manual under CHANGE/EXAMINE REFERENCE FRAME2.

Parameters:
azimuth - The alignment angle in degrees about the transmitter Z axis.
elevation - The alignment angle in degrees about the transmitter Y axis.
roll - The alignment angle in degrees about the transmitter X axis.

examineReferenceFrame2

private void examineReferenceFrame2()
Examine the angles that were sent to the birds using the CHANGE REFERENCE FRAME2 command.

changeMeasurementRate

public void changeMeasurementRate(int addr,
                                  short rate)
Change the measurement rate that the bird returns. The data parameter is a word containing the desired measurement rate times 256. The LSB is sent first, the the MSB.

(Note: This member is named changeMeasurementRate instead of setMeasurementRate since it uses the CHANGE VALUE form of bird command.)

Parameters:
addr - The address of the bird the command is being sent to.
rate - The rate in cycles/second.

changeMeasurementRate

public void changeMeasurementRate(short rate)
Change the measurement rate for the whole flock.
See Also:
changeMeasurementRate(int,short)

examineMeasurementRate

public void examineMeasurementRate(int addr)
Send the EXAMINE command with parameter MEASUREMENT RATE. It should have the side effect of the measurement rate appearing in the messages window.

examineMeasurementRate

public void examineMeasurementRate()
Examine the measurement rate for the whole flock

setQuaternionMode

public void setQuaternionMode()
Put the whole flock into QUATERNION mode

setQuaternionMode

public void setQuaternionMode(int addr)
Put bird at this address into QUATERNION mode. Remember that the bird addresses and the index into the array birds are off by one.
Parameters:
addr - is the address of the bird whose data mode is being set.

setAnglesMode

public void setAnglesMode()
Put the whole flock into ANGLES mode
See Also:
setAnglesMode(int)

setAnglesMode

public void setAnglesMode(int addr)
Put the bird at this address into ANGLES mode.

sendPointCommand

public void sendPointCommand()
Sends the point command to the Master bird.

sendPointCommand

private void sendPointCommand(int addr)
Sends the point command to the bird at the particular address
Parameters:
addr - is the flock address, range [1-6]

fly

public void fly()
When the flock is running with a master and slaves, this method is used to tell the flock to start flying. It also configures several aspects of the flock mode such as the default data (quaternions), the default measurement rate, and the orientation of the transmitter reference frame.

setFlockSize

public void setFlockSize(short size)
Sets the size of the flock.
Parameters:
size - is the number of birds in the flock.

enableGroupMode

public void enableGroupMode()
Tells the flock to go into group mode. The flock has to be in group mode in order to use the STREAM command.

sendStreamCommand

private void sendStreamCommand()
Sends the stream command to all of the birds in the flock.

stopStream

private void stopStream()
Stops the birds from streaming data.

sendAutoconfig

public void sendAutoconfig()
Send the changeAutoconfig command as a way to reset the flock if it seems to be having problems.

changeAutoconfig

private void changeAutoconfig()
Initialize the flock to be a certain size. changeAutoconfig is also useful for clearing any errors which might occur.

sendSleepCommand

public void sendSleepCommand()
Sends the sleep command to the Master bird.

beginCapture

public void beginCapture()
Starts capturing data. It sets up the data structure to save the sensor data to, and starts a timer, then sends the STREAM command to the flock.

endCapture

public void endCapture()
Ends the capture. Stops the timer for this stream. Tells the birds to stop streaming.

saveCaptureToFile

public boolean saveCaptureToFile(java.lang.String filename)
Saves the last capture to a file.
Parameters:
filename - The file that the data will be written to.

shutdown

public void shutdown()
Puts the birds to sleep and closes the serial connections to the flock.

getQuaternion

private java.lang.String getQuaternion(byte[] rec)
Interprets the byte data as a record, and then returns a String representation of it, as well as of the birds address.