Hi there, I need to correct aberrant IMU euler orientation values occurring secondary to Gimbal lock.

2 views (last 30 days)
I essentially have half the signal oscillating around the 0 degree mark and the other half around the 360mark. As true values will never exceed 180, I thought I could correct the output by reassigning all values > 360 to their original value subtracting 360. I have tried
Array Variable = yaw
yaw(yaw>180)=yaw-360
But this doesn't work, any have any ideas to correct this in an elegant way?

Answers (3)

David Ding
David Ding on 18 Oct 2017
Hi Luckshman,
I understand that you are trying to limit your angle data to between 0 and 360 degrees. You may make use of the "mod" function to take all your data modulo 360. For example:
% raw data
>> x = randi(500, 10, 1)
x =
346
158
344
418
10
376
495
375
141
395
Corrected data by setting all angles > 360 to their corresponding values < 360:
y = mod(x, 360)
y =
346
158
344
58
10
16
135
15
141
35
This is also more robust than subtraction by 360 because for example if an angle is > 720 (i.e. two revolutions), the angle can still be brought back accordingly to the value between 0 and 360.
More information about MATLAB's "mod" function can be found below:
Best,
David

James Tursa
James Tursa on 18 Oct 2017
Edited: James Tursa on 18 Oct 2017
The code you were using was not working because the rhs yaw was not indexed. E.g., to correct this
yaw(yaw>180) = yaw(yaw>180) - 360;

Luckshman Bavan
Luckshman Bavan on 27 Oct 2017
Thank you James and David! Both responses were very clear and helpful.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!