mirror of
https://github.com/felis/USB_Host_Shield_2.0.git
synced 2024-03-22 11:31:26 +01:00
Updated getAngle()
This commit is contained in:
parent
e60ddbac5a
commit
95a797e735
1 changed files with 24 additions and 30 deletions
50
PS3BT.cpp
50
PS3BT.cpp
|
@ -507,45 +507,39 @@ double PS3BT::getAngle(Angle a) {
|
||||||
|
|
||||||
if(PS3BTConnected) {
|
if(PS3BTConnected) {
|
||||||
// Data for the Kionix KXPC4 used in the DualShock 3
|
// Data for the Kionix KXPC4 used in the DualShock 3
|
||||||
double sensivity = 204.6; // 0.66/3.3*1023 (660mV/g)
|
const double zeroG = 511.5; // 1.65/3.3*1023 (1,65V)
|
||||||
double zeroG = 511.5; // 1.65/3.3*1023 (1,65V)
|
accXval = -((double)getSensor(aX)-zeroG);
|
||||||
accXval = ((double)getSensor(aX)-zeroG) / sensivity; // Convert to g's
|
accYval = -((double)getSensor(aY)-zeroG);
|
||||||
accXval *= 2;
|
accZval = -((double)getSensor(aZ)-zeroG);
|
||||||
accYval = ((double)getSensor(aY)-zeroG) / sensivity; // Convert to g's
|
|
||||||
accYval *= 2;
|
|
||||||
accZval = ((double)getSensor(aZ)-zeroG) / sensivity; // Convert to g's
|
|
||||||
accZval *= 2;
|
|
||||||
} else if(PS3MoveBTConnected) {
|
} else if(PS3MoveBTConnected) {
|
||||||
// It's a Kionix KXSC4 inside the Motion controller
|
// It's a Kionix KXSC4 inside the Motion controller
|
||||||
const uint16_t sensivity = 28285; // Find by experimenting
|
const uint16_t zeroG = 0x8000;
|
||||||
accXval = (double)getSensor(aXmove)/sensivity;
|
accXval = getSensor(aXmove);
|
||||||
accYval = (double)getSensor(aYmove)/sensivity;
|
accYval = getSensor(aYmove);
|
||||||
accZval = (double)getSensor(aZmove)/sensivity;
|
accZval = getSensor(aZmove);
|
||||||
|
|
||||||
if(accXval < -1) // Convert to g's
|
if(accXval < 0)
|
||||||
accXval = ((1+accXval)-(1-1.15))*(-1/0.15);
|
accXval += zeroG;
|
||||||
else if(accXval > 1)
|
else
|
||||||
accXval = ((1+accXval)-(1+1.15))*(-1/0.15);
|
accXval -= zeroG;
|
||||||
|
if(accYval < 0)
|
||||||
if(accYval < -1) // Convert to g's
|
accYval += zeroG;
|
||||||
accYval = ((1+accYval)-(1-1.15))*(-1/0.15);
|
else
|
||||||
else if(accYval > 1)
|
accYval -= zeroG;
|
||||||
accYval = ((1+accYval)-(1+1.15))*(-1/0.15);
|
if(accZval < 0)
|
||||||
|
accZval += zeroG;
|
||||||
if(accZval < -1) // Convert to g's
|
else
|
||||||
accZval = ((1+accZval)-(1-1.15))*(-1/0.15);
|
accZval -= zeroG;
|
||||||
else if(accZval > 1)
|
|
||||||
accZval = ((1+accZval)-(1+1.15))*(-1/0.15);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert to 360 degrees resolution
|
// Convert to 360 degrees resolution
|
||||||
// atan2 outputs the value of -π to π (radians)
|
// atan2 outputs the value of -π to π (radians)
|
||||||
// We are then converting it to 0 to 2π and then to degrees
|
// We are then converting it to 0 to 2π and then to degrees
|
||||||
if (a == Pitch) {
|
if (a == Pitch) {
|
||||||
double angle = (atan2(-accYval,-accZval)+PI)*RAD_TO_DEG;
|
double angle = (atan2(accYval,accZval)+PI)*RAD_TO_DEG;
|
||||||
return angle;
|
return angle;
|
||||||
} else {
|
} else {
|
||||||
double angle = (atan2(-accXval,-accZval)+PI)*RAD_TO_DEG;
|
double angle = (atan2(accXval,accZval)+PI)*RAD_TO_DEG;
|
||||||
return angle;
|
return angle;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue