Guest User

Untitled

a guest
Oct 17th, 2013
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. @Override
  2. public void onSensorChanged(SensorEvent event) {
  3. switch (event.sensor.getType()) {
  4. case Sensor.TYPE_ACCELEROMETER:
  5. System.arraycopy(event.values, 0, valuesAccel, 0, 3);
  6. break;
  7.  
  8. case Sensor.TYPE_MAGNETIC_FIELD:
  9. System.arraycopy(event.values, 0, valuesMagnet, 0, 3);
  10. break;
  11.  
  12. case Sensor.TYPE_GRAVITY:
  13. System.arraycopy(event.values, 0, valuesGravity, 0, 3);
  14. break;
  15.  
  16. default:
  17. break;
  18. }
  19.  
  20. if (SensorManager.getRotationMatrix(rotationMatrixTemp, null, valuesAccel, valuesMagnet)) {
  21. SensorManager.getOrientation(rotationMatrixTemp, valuesOrientation);
  22.  
  23. if(valuesGravity[2] < 0) {
  24. if (valuesOrientation[1] > 0) {
  25. valuesOrientation[1] = (float) (Math.PI - valuesOrientation[1]);
  26. }
  27. else {
  28. valuesOrientation[1] = (float) (-Math.PI - valuesOrientation[1]);
  29. }
  30. }
  31.  
  32. for (int i = 0; i < valuesOrientation.length; i++) {
  33. valuesOrientation[i] /= Math.PI;
  34. valuesOrientation[i] *= 100;
  35. valuesOrientation[i] = (int)valuesOrientation[i];
  36. valuesOrientation[i] /= 100;
  37. }
  38.  
  39.  
  40. updateOrientationBuffer(valuesOrientation);
  41.  
  42. quadcopter.onEvent(new Event(Event.Codes.ORIENTATION_CHANGED, calculateSmoothedOrientation()));
  43. }
  44. else {
  45. Log.d("Quadcopter-SM", "Matrix rotate error");
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment