0

I have this sensor fused data coming from a GYRO-ACC-MAG-hardware sensor.

It's data (YAW-PITCH-ROLL) goes from -180 to +180 or -90 to +90

Which algorithm helps me offset this to an arbitrary position and also have no sign change to minus?

What I mean is: -180 to +180 for instance leads to 0 to 359. And I want 0 not where 0 of the sensor is but also offset to a certain position. In other words, picture a circle. Now put a zero at an arbitrary position on that circle. Now rotate that circle around it's center point. The zero rotates along, so it is now at a different position than it was before, right? That's the idea.

What I did:

YAW + 180 leads to 0 to 359. Pitch + 90 leads to 0 to 179. Roll + 180 leads to 0 to 359.

Brutus Cruciatus
  • 404
  • 3
  • 18

1 Answers1

1

If I understand you correctly, you want to make use of the modulo operator:

double YAW360 =  (YAW+180)%360;

See http://msdn.microsoft.com/en-us/library/0w4e0fzs.aspx

The modulo operator makes a division and returns the division remainder:

17 / 5 = 3 rest 2

Therefore:

17 % 5 = 2
joe
  • 8,344
  • 9
  • 54
  • 80
  • Where does `And I want 0 not where 0 of the sensor is but also offset to a certain position.` come into play? – Brutus Cruciatus May 24 '14 at 18:09
  • Also, what are you doing? How did you understand my question? – Brutus Cruciatus May 24 '14 at 18:12
  • @PeakReconstructionWavelength: I don't know how to parse that sentence, so probably nowhere... – Oliver Charlesworth May 24 '14 at 18:12
  • That depends on what you add to the value *before* taking the modulo. In your case, you don't add 180 like my example, you add 360 to ensure a positibe value. Example values: `(0+360) % 360 = 0`, `(-90+180) % 360 = 270` – joe May 24 '14 at 18:13
  • @OliCharlesworth Alright, picture a Circle. Now put a zero at an arbitrary position on that circle. Now rotate that circle around it's center point. The zero rotates along, so it is now at a different position than it was before, right? That's the idea. – Brutus Cruciatus May 24 '14 at 18:21
  • @joe I am afraid, we are talking about different things. – Brutus Cruciatus May 24 '14 at 18:22
  • 3
    I don't think so. There are two questions here: (1) make an offset to the *zero* angle, this can be solved by simply subtract an `offset` from the original sensor angle. (2) To ensure that the angle has a positive value, use the modulo operator using 360 or 180°. So please think about this or try the two steps in your program and let us see your results. – joe May 24 '14 at 18:28
  • @joe I thought about it and your modulo seems like a limiter for values to stay within a certain area(here 360). That's a great idea if I understood it right. But thinking back to my education - as you write it - modulo delivers the rest. I don't really understand in how far this mathematical method acts as a limiter. Maybe you can elaborate... – Brutus Cruciatus May 24 '14 at 19:12
  • And sorry - when I say *rest* I meant *remainder* – joe May 24 '14 at 19:34