Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redefining Axis for different orientation #2

Open
ssamm95 opened this issue Jul 13, 2018 · 3 comments
Open

Redefining Axis for different orientation #2

ssamm95 opened this issue Jul 13, 2018 · 3 comments

Comments

@ssamm95
Copy link

ssamm95 commented Jul 13, 2018

Hi Lebarsfa,

I have a question concerning the orientation of the chip. I am using the razor-9dof-ahrs Arduino sketches with the 9DoF Razor IMU M0 from SparkFun.

If I want to operate the Razor in a different orientation compared to what is defined in the original code, what parts of the code would need to be changed?

Let me clarify. For example, say the chip is flat on surface surface, sparkfun logo upright, facing forward (see below)

20180713_102807

Here, using the Arduino sketch, yaw would be a rotation around the Z-axis, pitch would be a rotation around the Y-axis, and roll would be a rotation around the X-axis, as expected. As such, the Euler angles expected would be yaw=some value, pitch~=0, and roll~=0. This is fine for that orientation and values I get make sense, however, for my application I wish to operate the Razor in an upright position (see below)

20180713_103529

In this case, the axis definitions change. X now points to the sky, Y points behind and Z point right. In this position, yaw would be a rotation around the X-axis, pitch would be a rotation around the Z-axis, and roll would be a rotation around the Y-axis. This differs from the original code and I am wondering what modifications are needed to adjust for this. I expect Euler angles again to be yaw=some value, pitch~=0, and roll~=0 in the new orientation.

Does this require redefining the direction of gravity in reference to the chip? If so how do I go about doing that?

Please let me know what you think. Thanks.

@lebarsfa
Copy link
Owner

lebarsfa commented Jul 13, 2018

Hello,

You will probably have to play with the lines here (change the 0,1,2 indices to something like 1,2,0 and possibly the signs, or maybe another combination...) :

// Conversion from g to similar unit as older versions of Razor...
accel[0] = -250.0f*imu.calcAccel(imu.ax);
accel[1] = 250.0f*imu.calcAccel(imu.ay);
accel[2] = 250.0f*imu.calcAccel(imu.az);
// Conversion from degrees/s to rad/s.
gyro[0] = imu.calcGyro(imu.gx)*PI/180.0f;
gyro[1] = -imu.calcGyro(imu.gy)*PI/180.0f;
gyro[2] = -imu.calcGyro(imu.gz)*PI/180.0f;
// Conversion from uT to mGauss.
magnetom[0] = (10.0f*imu.calcMag(imu.my));
magnetom[1] = (-10.0f*imu.calcMag(imu.mx));
magnetom[2] = (10.0f*imu.calcMag(imu.mz));

You might also be interested in checking what is said in these posts :
Razor-AHRS#57 (comment)
Razor-AHRS#57 (comment)

There might be a risk that the acceleros and gyros make some kind of internal assumptions such as "the device is likely to be horizontal at startup" or "the device is likely to be horizontal most of the time", but maybe not since it is supposed to be a general purpose sensor...

@ssamm95
Copy link
Author

ssamm95 commented Jul 16, 2018

Great advice. Thanks, lebarsfa. Changing the indices to match the new orientation actually seemed to work quite well. I am seeing the results I expected.

I have one last question. If I want to change the range of the Euler angles from the standard set in the original code (i.e. yaw = -180 to +180, pitch = -90 to +90, and roll = -180 to 180), do you know what part of the code must be modified?

Thanks again!

@lebarsfa
Copy link
Owner

For that, I would try to change this (if you use the default output options) :

LOG_PORT.print(TO_DEG(yaw)); LOG_PORT.print(",");
LOG_PORT.print(TO_DEG(pitch)); LOG_PORT.print(",");
LOG_PORT.print(TO_DEG(roll)); LOG_PORT.println();

For the other output options there is also :
ypr[0] = TO_DEG(yaw);
ypr[1] = TO_DEG(pitch);
ypr[2] = TO_DEG(roll);
and
LOG_PORT.print(TO_DEG(yaw)); LOG_PORT.print(",");
LOG_PORT.print(TO_DEG(pitch)); LOG_PORT.print(",");
LOG_PORT.print(TO_DEG(roll)); LOG_PORT.print(",");

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants