Page 1 of 1

Sensors orientations

Posted: Sat Jul 23, 2011 11:14 am
by fax8
I've been digging a bit into the most recent svn MultiWii version to understand how sensors are being read, especially with respect to their orientation with respect to the holding IMU and the quadcopter itself.

Well, I think that the current code has quite some strange things happening. Let's make an example with the HMC5883:
If I do define the orientation of my magnetometer to be as:

Code: Select all

#define MAG_ORIENTATION(X, Y, Z)  {magADC[ROLL]  =  X; magADC[PITCH]  = Y; magADC[YAW]  = Z;}


I would then expect that the magnetometer axis would be in line with the quadricopter axis such as that magnetometer X is pointing left, Y is pointing forward and Z is pointing the sky.

But this is really not the case, because the invocation of MAG_ORIENTATION treat them in a completely different way:

Code: Select all

MAG_ORIENTATION( ((rawADC[4]<<8) | rawADC[5]) ,
                    -((rawADC[0]<<8) | rawADC[1]) ,
                    -((rawADC[2]<<8) | rawADC[3]) );


So basically, magADC[ROLL] will read sensor's Y axis, magADC[PITCH] will read sensor's -X axis and magADC[YAW] will read sensor's -Z axis.

In my opinion, sensor reading code should be transparent and should really just read the raw data from the sensors, without doing any rotations/negations on the sensors axis. The above code would then become:

Code: Select all

MAG_ORIENTATION( ((rawADC[0]<<8) | rawADC[1]) ,
                    ((rawADC[4]<<8) | rawADC[5]) ,
                    ((rawADC[2]<<8) | rawADC[3]) );


The place in which rotations should happen is definitely in def.h in the various boards declarations. For example, FreeFlight IMU v1.22 doesn't have the axis of the magnetometer aligned with those of the other two sensors: there is a clockwise 90 deg rotation on the magnetometer Z axis with respect to the accel and gyro. Thus, a correct def.h definition of such board would then define such rotation:

Code: Select all

#if defined(FFIMUv2)
  #define ITG3200
  #define BMA180
  #define BMP085
  #define HMC5883
  #define ACC_ORIENTATION(X, Y, Z)  {accADC[ROLL]  =  X; accADC[PITCH]  = Y; accADC[YAW]  = Z;}
  #define GYRO_ORIENTATION(X, Y, Z) {gyroADC[ROLL] =  X; gyroADC[PITCH] = Y; gyroADC[YAW] = Z;}
  #define MAG_ORIENTATION(X, Y, Z)  {magADC[ROLL]  =  Y; magADC[PITCH]  = -X; magADC[YAW]  = Z;}
  #define BMA180_ADDRESS 0x80
  #define ITG3200_ADDRESS 0XD0
#endif


Also, I don't really understand why all the sensors have their Z axis negated.

Hope this helps,

Fabio

Re: Sensors orientations

Posted: Sun Jul 24, 2011 11:14 am
by Alexinparis
Hi Fabio,

The original reference for X / Y / Z was not taken from the spec of each sensor, but from the original implementation of FFIMU because it was the first one in multiwii.
However the FFIMU has not the axis aligned according to the specs.
That explains the difference between the real alignment and what you can find in the code.

But I understand the concern.
For a proper work, I think all the definition should be reviewed to match the sensor specs.
It should ease the integration of future sensors.
I didn't do this yet because there is a risk of errors in the translation of what is working fine today...

Re: Sensors orientations

Posted: Sun Jul 24, 2011 8:36 pm
by Hamburger
should we call it MultiWii version 2.0 and correct the sensor orientation once and be done?
The coming version has so many changes compared to last v1.7 that for once people will have to read the README anyway.
For transiition help it could contain hints on how to set *_ORIENTATION without correcting physical sensor orientation , if it was working with defaults of former versions.

just a thought, as I cannot help much here.

Re: Sensors orientations

Posted: Sun Jul 24, 2011 11:38 pm
by fax8
Ok, I'd say that this has to be done then. Of course, errors will happen but in the end we will have a much better software to understand and extend.

Alex, would you please comment on why all the sensors reading come with the Z axis negated?

Re: Sensors orientations

Posted: Mon Jul 25, 2011 9:15 am
by Hamburger
Ok, I'd say that this has to be done then. Of course, errors will happen but in the end we will have a much better software to understand and extend.


Well, as Alex is our Linus it would be up to him to decide.
Hamburger

Re: Sensors orientations

Posted: Mon Jul 25, 2011 5:42 pm
by fax8
Sure, that's my opinion.

Re: Sensors orientations

Posted: Wed Apr 04, 2012 1:04 am
by dpackham
did this get resolved? my FFIMU 1.22 is not flying with JussiH's seeeduino mega shield and the 2.0 software. wants to flip :)

Re: Sensors orientations

Posted: Wed Apr 04, 2012 2:44 am
by timecop
Yes, all orientations have been fixed in 2.0.
The defines per-board should be changed (mostly have been) to match.

Re: Sensors orientations

Posted: Wed Apr 04, 2012 4:19 am
by dpackham
hmmm.. then why does it want to yaw like mad and flip? ill keep looking. also i think the JussiH's Mega Shield has the FFIMU mounted so the signal pins are in the rear of the craft.

Re: Sensors orientations

Posted: Thu Apr 05, 2012 3:00 am
by dpackham
So mounted on JussiH's mega shield the FFIMU is sideways by 90 degrees for MWC code. the signal pins are in the back and leds on the side and the board and sits lengthwise along the pitch axis on the shield. as far as I could find for MWC code the FFIMU needs to sit led's front or lengthwise along the roll access. am i correct?

#if defined(FFIMUv2) // for JussiH's mega shield with FFIMU twisted 90
#define ITG3200
#define BMA180
#define BMP085
#define HMC5883
#define ACC_ORIENTATION(X, Y, Z) {accADC[ROLL] = Y; accADC[PITCH] = -X; accADC[YAW] = Z;}
#define GYRO_ORIENTATION(X, Y, Z) {gyroADC[ROLL] = X; gyroADC[PITCH] = Y; gyroADC[YAW] = -Z;}
#define MAG_ORIENTATION(X, Y, Z) {magADC[ROLL] = -Y; magADC[PITCH] = X; magADC[YAW] = -Z;}
#define BMA180_ADDRESS 0x80
#define ITG3200_ADDRESS 0XD0
#endif

Re: Sensors orientations

Posted: Fri Apr 06, 2012 4:07 pm
by dpackham
interesting quick thing. when i try to fly in headfree mode it works well... until it gets pointed nose in. then is wants to flip forward... hmmm. still need some more flight testing

Re: Sensors orientations

Posted: Fri Sep 13, 2013 1:39 am
by crazyal
just to be clear, the sensor orientation issue has never been resolved ?

Re: Sensors orientations

Posted: Fri Sep 13, 2013 4:14 am
by Tomek
+1
But nobody is willing to answer ?
Tom

Re: Sensors orientations

Posted: Sat Sep 14, 2013 10:19 pm
by Alexinparis
crazyal wrote:just to be clear, the sensor orientation issue has never been resolved ?

it was solved in 2.0