|
|||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--CaptureData
A class to deal with the raw Bird data that comes out. One of things it does is take the raw data and write it to a file.
NOTE This code assumes that all of the birds in the flock return data in the same format, eg. quaternions. Technically, different birds could return different kinds of data. So, if we want to know the kind of data coming in, we need look only at the first (or any one) bird.
ANOTHER NOTE The SerialConnectionListener interface has a callback that gets called by another thread. So far, none of the variables are synchronized in this application. We are just trusting in timing to make everything work correctly. We will add sychronization when it seems absolutely necessary.
ISSUES: Not sure if the way that we check phase bits is the best way. Maybe it should be that we read in the next byte, we know if the next byte is supposed to have a 1 or 0 phase bit, and we check that it really does.
Why is it that the capture file often doesn't have a complete last line? What is getting dropped and why?
In this version, the data are recorded as floats.
Inner Class Summary | |
(package private) class |
CaptureData.ReadableSensorFile
An Inner class for writing out the raw sensor data in a human readable format. |
(package private) class |
CaptureData.SensorFile
An inner class for writing the raw bird records to a binary file. |
Field Summary | |
private int |
acount
The number of valid addresses stored in the address array |
private byte[] |
address
An array to hold the addresses corresponding to the data |
private int |
badBytes
Keep track of number of bytes with wrong phasing bit |
private int |
bcount
A counter to keep track of the bytes in a record |
private Bird[] |
birds
Reference to the birds in the flock |
private int |
bparity
A counter to keep track of the bytes in a short |
private boolean |
captureMode
Indicates whether the data coming in is meant to be saved as a capture file or not. |
private Flock |
flock
A reference to the flock that this data comes from |
static java.lang.String |
l_elbow
|
static java.lang.String |
l_shoulder
|
static java.lang.String |
l_wrist
|
private int |
maxAddrs
Maximum entries in address array |
private int |
maxData
Maximum number of values in data array |
private int |
npoints
A count of the number of orientation points are read in. |
private short |
nsteps
The number of records reported by each bird |
private int |
ocount
Size of valid data in orientation array |
private float[] |
orientation
An array to hold the orientation values returned by the sensors. |
private Capture |
parent
A reference to the application Capture |
private float[] |
pointData
Holds the last point data that came from the birds |
private short |
rate
The rate at which the birds measured data |
private byte[] |
records
The unprocessed data from the birds |
private int |
recordSize
The size of the record of the current data format |
private int |
tcount
The size of the array transform . |
private short |
totalTime
The total time for this caputure |
private float[] |
transform
The array to hold the transformed records |
Constructor Summary | |
(package private) |
CaptureData()
Default contructor starts out empty |
(package private) |
CaptureData(Capture parent,
Flock fl,
Bird[] birds)
Constructor that has all the information it needs to process data. |
Method Summary | |
static float[] |
birdQuatToJava(float[] v)
Rotates an array of floats from wxyz format to xyzw format. |
private float[] |
birdReferenceFrameToVRML(float[] q)
Takes a an array that represents a quaternion in Java order, ie x y z w, and changes its reference frame from the Flock transmitter frame of reference to the avatar's. |
static short |
bytePairToShort(byte msbyte,
byte lsbyte)
Convert a pair of raw bytes which have been right shifted into a single raw short. |
private boolean |
checkPhaseBit(byte b)
|
void |
clearData()
Destroy all the previous capture data, and make new clean arrays to hold a new capture. |
void |
dataAvailable(java.io.InputStream str)
Reads the raw records as they come in from the birds. |
static short |
floatAngleToShort(float angle)
Converts an angle value in degrees into a short. |
static float[] |
javaQuatToBird(float[] v)
Rotates an array of floats from xyzw format to wxyz format. |
private int |
nextAddress(java.io.DataInputStream in)
Reads the next byte from the input stream and interprets it as an addres. |
private float[] |
nextAngles(java.io.DataInputStream in)
Reads the next angles record from the input stream. |
private byte |
nextByte(java.io.DataInputStream in)
Reads and validates the next byte to come from the input stream. |
private float[] |
nextQuaternion(java.io.DataInputStream in)
Reads the next quaterion from the input stream. |
int |
numBadBytes()
|
private void |
printQuaternion(java.io.DataInputStream in)
Reads the next record from the stream, then prints it to the message window |
private void |
readQuaternionIntoArray(java.io.DataInputStream in)
Read the next 8 (or 9 if in group mode) bytes from the data, interpret as a quaternion, and put it into the orientation array. |
static short[] |
recordsToShorts(byte[] rec,
int dataSize)
Converts the raw bird data from record bytes to integer words; assuming that the bytes coming back have been shifted right. |
void |
setCaptureMode(boolean mode)
Set captureMode. |
void |
setRate(short r)
|
void |
setSteps(short s)
|
void |
setTotalTime(short time)
|
static float |
shortAngleToFloat(short val)
Converts short value to degrees. |
static byte |
shortLSB(short val)
Extracts the Least Significant Byte of this short |
static float |
shortMatrixToFloat(short val)
|
static byte |
shortMSB(short val)
Extracts the Most Significant Byte of this short. |
static float |
shortPosToInches(short val)
|
private static float |
shortQuaternionToFloat(short val)
Converts a short quaternion field value to its float equivalent |
private void |
storeAddress(byte a)
Adds a value to the address array |
private void |
storeOrientation(float[] o)
Adds values to the orientation array. |
private void |
storeTransform(float[] t,
byte a)
Adds values to the transform and address arrays. |
boolean |
writeOrientationsToFile(java.lang.String filename)
Write out the orientations in regular text. |
boolean |
writeReadableSensorDataToFile(java.lang.String filename)
A method that writes the transoformation data in human readable format. |
Methods inherited from class java.lang.Object |
|
Field Detail |
private Capture parent
private Flock flock
private Bird[] birds
private byte[] records
private int recordSize
private float[] transform
private int tcount
transform
.private float[] orientation
private int ocount
orientation
arrayprivate final int maxData
private byte[] address
private int acount
address
arrayprivate boolean captureMode
private final int maxAddrs
private float[] pointData
private short nsteps
private short totalTime
private short rate
private int bcount
private int bparity
private int badBytes
private int npoints
public static java.lang.String l_shoulder
public static java.lang.String l_elbow
public static java.lang.String l_wrist
Constructor Detail |
CaptureData()
CaptureData(Capture parent, Flock fl, Bird[] birds)
parent
- A reference to the parent application.fl
- The flock.birds
- And array of references to the birds in the flock.Method Detail |
public void clearData()
public void setTotalTime(short time)
public void setSteps(short s)
public void setRate(short r)
public int numBadBytes()
public void setCaptureMode(boolean mode)
captureMode
public boolean writeReadableSensorDataToFile(java.lang.String filename)
filename
- A string which is the name of a file to write to.public boolean writeOrientationsToFile(java.lang.String filename)
private void printQuaternion(java.io.DataInputStream in) throws java.io.IOException
private byte nextByte(java.io.DataInputStream in) throws java.io.IOException
bcount
counter.private float[] nextQuaternion(java.io.DataInputStream in) throws java.io.IOException
private float[] nextAngles(java.io.DataInputStream in) throws java.io.IOException
an
- array of three floats representing the angles.private int nextAddress(java.io.DataInputStream in) throws java.io.IOException
private void readQuaternionIntoArray(java.io.DataInputStream in) throws java.io.IOException
transform
.private float[] birdReferenceFrameToVRML(float[] q)
The Flock frame has +X to the front, +Z going down and +Y going to the right.
The VRML hanim avatar has +Z to the front, +Y going up and +X to the left.
We rearrange the axes as follows, where the new axes are the avatar's:
X' <- -Y Z' <- +X Y' <- -Z
q
- An array of floats in the flock's reference frame.private void storeAddress(byte a)
private void storeTransform(float[] t, byte a)
private void storeOrientation(float[] o)
public static byte shortMSB(short val)
val
- The short to be decomposed.public static byte shortLSB(short val)
public static short bytePairToShort(byte msbyte, byte lsbyte)
public static short[] recordsToShorts(byte[] rec, int dataSize)
public static float shortAngleToFloat(short val)
public static short floatAngleToShort(float angle)
shortAngleToFloat(short)
public static float shortMatrixToFloat(short val)
private static float shortQuaternionToFloat(short val)
public static float shortPosToInches(short val)
private boolean checkPhaseBit(byte b)
public static float[] birdQuatToJava(float[] v)
v
- an array of floats to convert.public static float[] javaQuatToBird(float[] v)
v
- an array of floats to convert.public void dataAvailable(java.io.InputStream str)
Quaternion format:
The quaternion record consists of four words which represent the
four parameters of the quaternion: q0 is the scalar parameter;
q1-q3 are the vector components. Each word consists of two
bytes.
Phasing bits:
The very first bit of the first byte of the record is a 1.
The first bit of all other bytes is 0. If there is an address
byte appended to the end of the record (because the flock is in
GROUP mode) this byte will have no phasing bit.
dataAvailable
in interface SerialConnectionListener
|
|||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |