Page 1 of 1

I have some confusion when reading the code

Posted: Mon Sep 01, 2014 8:31 am
by xylitol
Hi~
I'm have some confusion about this code

Code: Select all

/**
 * Compensate for a miss-aligned accelerometer. It uses the trim
 * data gathered from the UI and written in the config-block to
 * rotate the accelerometer to be aligned with gravity.
 */
static void imuAccAlignToGravity(Axis3i16* in, Axis3i16* out) //
{
  Axis3i16 rx;
  Axis3i16 ry;

  // Rotate around x-axis
  rx.x = in->x;
  rx.y = in->y * cosRoll - in->z * sinRoll;
  rx.z = in->y * sinRoll + in->z * cosRoll;

  // Rotate around y-axis
  ry.x = rx.x * cosPitch - rx.z * sinPitch;
  ry.y = rx.y;
  ry.z = -rx.x * sinPitch + rx.z * cosPitch;

  out->x = ry.x;
  out->y = ry.y;
  out->z = ry.z;
}
The function of this code is used to correct the installation error????And how can we get the cosroll ,sinroll,......., If there was any algorithm??? I want designe a quadrotor,So the reference code here!!!!!!!can give me some help about algorithm of quadrotor,like some book or PDF, :D Thank you !!!!!!! Code with you

Re: I have some confusion when reading the code

Posted: Mon Sep 01, 2014 8:58 am
by arnaud
Hi,

This code is used for timing the accelerometer pitch and roll. Historically in the project we have experienced that some time the accelerometer behaves as if it was not flat. This was mostly the case with home-soldered component and the early analog accelerometer but can still happen sometime.

This code is basically implementing a rotation matrix (https://en.wikipedia.org/wiki/Rotation_matrix) and cosPitch, sinPitch, ..., are cos(pitch), sin(pitch), ... They are always the same so they are calculated only one time at startup. This is just optimisation.

The two main algorithm that flies a quadcopter are the sensor fusion and the stabilisation, you can find both the Crazyflie code.

Re: I have some confusion when reading the code

Posted: Mon Sep 01, 2014 10:07 am
by xylitol
Thank you for you answer,as you said ,if we can not use this function ????how can we kown the sensor is flat or may be no ? and i can't find any code about the associated with data fusion ,like complementary or KF .As you kown ,i am a noob.so Thanks for you again

Re: I have some confusion when reading the code

Posted: Fri Sep 05, 2014 7:01 am
by tobias
You should look in stabalizer.c and sensorfuson6.c