Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

9
  • Hi, Teja Allani, Thanks for sharing the code. It works. One issue puzzles me though, in the offset subroutine, the code takes the 2nd MPUread() for the initialization. Is there any reason for doing so? I did some tests by marking the 2nd MPUread out and my tests do reveal different results. Commented Sep 3, 2016 at 4:05
  • Further, it seems that the code yields angles that are limited to (-45, 45). Where do I need to change for angle computation extended to (-90, 90)? Commented Sep 3, 2016 at 11:40
  • Hello :) @Jesse , The 2nd MPUread() because the first couple of readings are not stable it takes some time for MPU to give stable results, for this same reason I put i>100 in the loop so 1st 100 readings are not used for calibration. Commented Sep 4, 2016 at 14:32
  • and for that angles use atan2() instead of atan() to change the limits of the angles. This code still needs some improvement because I found that when roll or pitch cross 90 degrees they seemed to effect each other( I can't explain this phenomenon clearly test it out after replacing atan() with atan2() ) maybe its because the values of Ax and Ay become negative after crossing 90 degrees and this sudden change from +ve to -ve and effects filter. _Also try changing gain value and observe results _ Commented Sep 4, 2016 at 14:32
  • Thanks for the feedback. I did check that atan() takes one argument and the angle can be between [-90,90], leading me to think that some improvements are needed. Anyway, you got most of it in one sleepless night is quite impressive. Best wishes. Commented Sep 4, 2016 at 14:41