I have some confusion when reading the code

Firmware/software/electronics/mechanics
Post Reply
xylitol
Beginner
Posts: 3
Joined: Mon Sep 01, 2014 8:20 am

I have some confusion when reading the code

Post 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
arnaud
Bitcraze
Posts: 2538
Joined: Tue Feb 06, 2007 12:36 pm

Re: I have some confusion when reading the code

Post 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.
xylitol
Beginner
Posts: 3
Joined: Mon Sep 01, 2014 8:20 am

Re: I have some confusion when reading the code

Post 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
tobias
Bitcraze
Posts: 2339
Joined: Mon Jan 28, 2013 7:17 pm
Location: Sweden

Re: I have some confusion when reading the code

Post by tobias »

You should look in stabalizer.c and sensorfuson6.c
Post Reply