check direction using quaternion, compare do action

Hello
I want to use quaternions instead of yaw, pitch , roll as its more accurate.

what I wand to do is to remember direction of movement when certain event occures (like press button). Next compare this direction with actual direction and do action (like turn on LED) if different by certain amount (eg. 5* off the course)

Mainly direction that I'll be testing is heading (yaw) but I dont want to use yaw angles because of few issues - less accurate when tilted, gimbal lock, issue with close to north - if direction of movement is 359* then 356* is easy to compare but 5* is not...

or maybe there is another better option. rescale direction - after event occur direction of movement is remembered as new 180* and do action if movement is outside 175-185 range.

Module I'm using is BNO055

thank you for advise.

The quaternion represents sensor orientation, not direction of motion.

Motion and orientation are completely independent.

Give this site a look over https://os.mbed.com/users/onehorse/

jremington:
The quaternion represents sensor orientation, not direction of motion.

Motion and orientation are completely independent.

Same thing. if sensor is fixed to device (lets say X facing front of device) and device is moving forward then orientation of board will be direction of movement...

Following up that stunningly brilliant exposition, if the device is moving sideways instead of forward, orientation of board will be about 90 degrees to the direction of movement.

Have fun with your project!

Assume the IMU produces a currentHeading and it does that with some definable accuracy. (Maybe it has a compass and you have placed it in a magnetically quiet spot on the robot.)

Further, assume there is a desiredHeading. And both of them are in degrees.

  int headingError = currentHeading - desiredHeading;
  if(headingError > 180) headingError -= 360;
  if(headingError < -180) headingError += 360;

Now you know if you have to turn left or right and how far.