Cubic Hand project for EECS 249A course.
Dependencies: MMA8451Q TSI cc3000_hostdriver_mbedsocket NVIC_set_all_priorities mbed Multi_WS2811
Diff: DataGlove.cpp
- Revision:
- 41:367cab0162de
- Parent:
- 37:996bd22a633f
- Child:
- 42:4e1aaab14886
diff -r bdd949fc3bc2 -r 367cab0162de DataGlove.cpp --- a/DataGlove.cpp Thu Dec 11 10:18:48 2014 +0000 +++ b/DataGlove.cpp Thu Dec 11 12:08:27 2014 +0000 @@ -9,23 +9,14 @@ DataGlove::DataGlove() { notConnectedCount = 0; - gl = new Glove; - correction = new Glove; - corrected = new Glove; ReceiveCount = 0; numReceived = 0; NewData = false; - //Initialize correction values to 0 - correction->roll = 0.0; - correction->pitch = 0.0; - correction->yaw = 0.0; - for (int i = 0; i < 5; i++) - correction->fingers[i] = 0.0; } DataGlove::~DataGlove() { - delete(gl); + //delete(gl); } void DataGlove::Init() @@ -62,7 +53,7 @@ Glove DataGlove::ReceiveBlocking() { while(Receive() == false); - return *gl; + return gl; } bool DataGlove::Receive() @@ -169,7 +160,7 @@ k += 4; for (y = 0; y < 5; y++) { - gl->fingers[y] = 0.1 * ((buffer[k] << 8) + buffer[k + 1]); + gl.fingers[y] = 0.1 * ((buffer[k] << 8) + buffer[k + 1]); k += 2; } q00 = q0 / 32768.0; @@ -184,10 +175,10 @@ pitch = 180.0 * asin(2 * (q00 * q22 - q33 * q11)) / 3.1415; yaw = 180.0 * atan2(2 * (q00 * q33 + q11 * q22), 1 - 2 * (q22 * q22 + q33 * q33)) / 3.1415; - gl->roll = roll; - gl->pitch = pitch; - gl->yaw = yaw; - gl->lastPkgTime = timeOfArrival; + gl.roll = roll; + gl.pitch = pitch; + gl.yaw = yaw; + gl.lastPkgTime = timeOfArrival; } void DataGlove::ExtractQuat() @@ -203,7 +194,7 @@ k += 4; for (y = 0; y < 5; y++) { - gl->fingers[y] = 0.0; + gl.fingers[y] = 0.0; } q00 = q0 / 32768.0; q11 = q1 / 32768.0; @@ -216,10 +207,10 @@ pitch = 180.0 * asin(2 * (q00 * q22 - q33 * q11)) / 3.1415; yaw = 180.0 * atan2(2 * (q00 * q33 + q11 * q22), 1 - 2 * (q22 * q22 + q33 * q33)) / 3.1415; - gl->roll = roll; - gl->pitch = pitch; - gl->yaw = yaw; - gl->lastPkgTime = timeOfArrival; + gl.roll = roll; + gl.pitch = pitch; + gl.yaw = yaw; + gl.lastPkgTime = timeOfArrival; } @@ -228,86 +219,86 @@ k = 7; for (j = 0; j < 3; j++) { - gl->gyro[j] = (buffer[k] << 8) + (buffer[k+1]); - if (gl->gyro[j] > 0x7fff) - gl->gyro[j] -= 0x10000; + gl.gyro[j] = (buffer[k] << 8) + (buffer[k+1]); + if (gl.gyro[j] > 0x7fff) + gl.gyro[j] -= 0x10000; k += 2; } for (j = 0; j < 3; j++) { - gl->magn[j] = (buffer[k] << 8) + (buffer[k+1]); - if (gl->magn[j] > 0x7fff) - gl->magn[j] -= 0x10000; + gl.magn[j] = (buffer[k] << 8) + (buffer[k+1]); + if (gl.magn[j] > 0x7fff) + gl.magn[j] -= 0x10000; k += 2; } for (j = 0; j < 3; j++) { - gl->accel[j] = (buffer[k] << 8) + (buffer[k+1]); - if (gl->accel[j]>0x7fff) - gl->accel[j] -= 0x10000; + gl.accel[j] = (buffer[k] << 8) + (buffer[k+1]); + if (gl.accel[j]>0x7fff) + gl.accel[j] -= 0x10000; k += 2; } for (y = 0; y < 5; y++) { - gl->fingers[y] = 0.1 * ((buffer[k] << 8) + buffer[k+1]); + gl.fingers[y] = 0.1 * ((buffer[k] << 8) + buffer[k+1]); k += 2; } - gl->roll = 0.0; - gl->pitch = 0.0; - gl->yaw = 0.0; - gl->lastPkgTime = timeOfArrival; + gl.roll = 0.0; + gl.pitch = 0.0; + gl.yaw = 0.0; + gl.lastPkgTime = timeOfArrival; } void DataGlove::ExtractRaw() { k = 7; for (j = 0; j < 3; j++){ - gl->gyro[j] = (buffer[k] << 8) + (buffer[k+1]); - if (gl->gyro[j] > 0x7fff) - gl->gyro[j] -= 0x10000; + gl.gyro[j] = (buffer[k] << 8) + (buffer[k+1]); + if (gl.gyro[j] > 0x7fff) + gl.gyro[j] -= 0x10000; k += 2; } for (j = 0; j < 3; j++){ - gl->magn[j] = (buffer[k] << 8) + (buffer[k+1]); - if (gl->magn[j] > 0x7fff) - gl->magn[j] -= 0x10000; + gl.magn[j] = (buffer[k] << 8) + (buffer[k+1]); + if (gl.magn[j] > 0x7fff) + gl.magn[j] -= 0x10000; k += 2; } for (j = 0; j < 3; j++){ - gl->accel[j] = (buffer[k] << 8) + (buffer[k+1]); - if (gl->accel[j] > 0x7fff) - gl->accel[j] -= 0x10000; + gl.accel[j] = (buffer[k] << 8) + (buffer[k+1]); + if (gl.accel[j] > 0x7fff) + gl.accel[j] -= 0x10000; k += 2; } int y = 0; for (y = 0; y < 5; y++){ - gl->fingers[y] = 0.0; + gl.fingers[y] = 0.0; } - gl->roll = 0.0; - gl->pitch = 0.0; - gl->yaw = 0.0; - gl->lastPkgTime = timeOfArrival; + gl.roll = 0.0; + gl.pitch = 0.0; + gl.yaw = 0.0; + gl.lastPkgTime = timeOfArrival; } void DataGlove::ExtractFingers() { k = 7; for (y = 0; y < 5; y++){ - gl->fingers[y] = 0.1 * ((buffer[k] << 8) + buffer[k+1]); + gl.fingers[y] = 0.1 * ((buffer[k] << 8) + buffer[k+1]); k += 2; } - gl->roll = 0.0; - gl->pitch = 0.0; - gl->yaw = 0.0; - gl->lastPkgTime = timeOfArrival; + gl.roll = 0.0; + gl.pitch = 0.0; + gl.yaw = 0.0; + gl.lastPkgTime = timeOfArrival; } Glove DataGlove::GetCurrentValues() { - return *gl; + return gl; } bool DataGlove::CheckForNewValues()