Sensors orientations

This forum is dedicated to software development related to MultiWii.
It is not the right place to submit a setup problem.
Software download
Post Reply
fax8
Posts: 61
Joined: Mon Feb 14, 2011 5:29 pm

Sensors orientations

Post 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

Alexinparis
Posts: 1630
Joined: Wed Jan 19, 2011 9:07 pm

Re: Sensors orientations

Post 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...

User avatar
Hamburger
Posts: 2578
Joined: Tue Mar 01, 2011 2:14 pm
Location: air
Contact:

Re: Sensors orientations

Post 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.

fax8
Posts: 61
Joined: Mon Feb 14, 2011 5:29 pm

Re: Sensors orientations

Post 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?

User avatar
Hamburger
Posts: 2578
Joined: Tue Mar 01, 2011 2:14 pm
Location: air
Contact:

Re: Sensors orientations

Post 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

fax8
Posts: 61
Joined: Mon Feb 14, 2011 5:29 pm

Re: Sensors orientations

Post by fax8 »

Sure, that's my opinion.

dpackham
Posts: 16
Joined: Wed Mar 23, 2011 8:50 pm

Re: Sensors orientations

Post 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 :)

timecop
Posts: 1880
Joined: Fri Sep 02, 2011 4:48 pm

Re: Sensors orientations

Post by timecop »

Yes, all orientations have been fixed in 2.0.
The defines per-board should be changed (mostly have been) to match.

dpackham
Posts: 16
Joined: Wed Mar 23, 2011 8:50 pm

Re: Sensors orientations

Post 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.

dpackham
Posts: 16
Joined: Wed Mar 23, 2011 8:50 pm

Re: Sensors orientations

Post 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

dpackham
Posts: 16
Joined: Wed Mar 23, 2011 8:50 pm

Re: Sensors orientations

Post 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

crazyal
Posts: 84
Joined: Tue Sep 04, 2012 11:25 pm

Re: Sensors orientations

Post by crazyal »

just to be clear, the sensor orientation issue has never been resolved ?

Tomek
Posts: 14
Joined: Thu Sep 05, 2013 3:46 am

Re: Sensors orientations

Post by Tomek »

+1
But nobody is willing to answer ?
Tom

Alexinparis
Posts: 1630
Joined: Wed Jan 19, 2011 9:07 pm

Re: Sensors orientations

Post by Alexinparis »

crazyal wrote:just to be clear, the sensor orientation issue has never been resolved ?

it was solved in 2.0

Post Reply