IMU sensor upside down

Firmware/software/electronics/mechanics
Post Reply
Yaro
Member
Posts: 31
Joined: Wed May 20, 2015 11:28 am

IMU sensor upside down

Post by Yaro » Wed Dec 09, 2015 4:44 pm

Hi all,

I want to ask if someone have tryed this with current crazyflie firmware. I want to ask, if I flip motors and I have sensors upside down, stabilization algorithm will still work? if no, it's is possible to make it work with something like changing some signs or it's more complex?

Thank you!

arnaud
Bitcraze
Posts: 1928
Joined: Tue Feb 06, 2007 12:36 pm

Re: IMU sensor upside down

Post by arnaud » Thu Dec 10, 2015 7:44 am

Hi,

It is definitely possible and it should just be matter of changing some sign at the output of the IMU. I think we have been trying that at some point but I cannot remember the result.

The stabilizer gets the orientation here https://github.com/bitcraze/crazyflie-f ... zer.c#L278 so by modifying this function you will be able to flip the imu orientation: https://github.com/bitcraze/crazyflie-f ... #L232-L246

Yaro
Member
Posts: 31
Joined: Wed May 20, 2015 11:28 am

Re: IMU sensor upside down

Post by Yaro » Mon Mar 21, 2016 6:30 pm

arnaud wrote:Hi,

It is definitely possible and it should just be matter of changing some sign at the output of the IMU. I think we have been trying that at some point but I cannot remember the result.

The stabilizer gets the orientation here https://github.com/bitcraze/crazyflie-f ... zer.c#L278 so by modifying this function you will be able to flip the imu orientation: https://github.com/bitcraze/crazyflie-f ... #L232-L246
I've tried but I've an unexpected result.
Without any change drone goes crazy and didn't respond to RPY commands, just two motors running at maximum.
But adding this:

Code: Select all

  //Upside down
  gz = -gz;
in this function inside sensfusion6.c

Code: Select all

void sensfusion6GetEulerRPY(float* roll, float* pitch, float* yaw)
{
  float gx, gy, gz; // estimated gravity direction

  gx = 2 * (q1*q3 - q0*q2);
  gy = 2 * (q0*q1 + q2*q3);
  gz = q0*q0 - q1*q1 - q2*q2 + q3*q3;
  
  //Upside down
  gz = -gz;

  if (gx>1) gx=1;
  if (gx<-1) gx=-1;
  
  //*yaw = atan2f(2*(q0*q3 + q1*q2), q0*q0 + q1*q1 - q2*q2 - q3*q3) * 180 / M_PI_F;
  *yaw = atan2(2*(q0*q3 + q1*q2), q0*q0 + q1*q1 - q2*q2 - q3*q3) * 180 / M_PI_F;
  *pitch = asinf(gx) * 180 / M_PI_F; //Pitch seems to be inverted
  //*roll = atan2f(gy, gz) * 180 / M_PI_F;
  *roll = atan2(gy, gz) * 180 / M_PI_F;
}
It seems quite when not flying. Next step I've done is to test if Motors position and drone direction are the same.
I've found that, using front direction as reference and X mode, if I roll the drone on right or left it act as expected giving more power to right or left motors. But If I pitch drone in front direction or on back direction, power to motors is given in alternate way.

Here's an explanation image:
Image
BLUE motors and RED motors activate together.
On the left is what I get if I ROLL, on the right is what I get if I PITCH and it's not as expected. Correct should be as in the center.

Where should I make changes to solve this problem?

Thank you!

Yaro
Member
Posts: 31
Joined: Wed May 20, 2015 11:28 am

Re: IMU sensor upside down

Post by Yaro » Tue Mar 22, 2016 9:53 am

I've done more tests and seems pitch and yaw inverted. I've also this problem if I try to place drone in correct position with IMU upside. That's problematic to solve for me, since I can't just flip motors order or change axis sings. Any advice on where is the problem?

Yaro
Member
Posts: 31
Joined: Wed May 20, 2015 11:28 am

Re: IMU sensor upside down

Post by Yaro » Tue Mar 22, 2016 11:26 am

Solved with changing signs in limitThurst function. Now motors seems rotating correctly.
A new problems is that when I start stabilizer function, without altHold but with manually setting thrust, I've two propeller that rush power about 20%-25% for some seconds, then calming down in some seconds. After that drone acts normally(moving it manually to see how reacts stabilizer).
But this is not a heavy problem. Main problem is that when I try to fly drone, after it reached enought speed to take fly, it start to spin on itself. I need some kind of calibration?

arnaud
Bitcraze
Posts: 1928
Joined: Tue Feb 06, 2007 12:36 pm

Re: IMU sensor upside down

Post by arnaud » Wed Mar 23, 2016 9:49 am

This sounds like you need to look at the distribute power function.

The rush you are describing could come from the yaw control loop. Since you inverted everything you should make sure that the power distribution function is still right and for example for the yaw the correction should go in the right direction.

Also for the axis, normally you should inverse 2 axis in order to keep the orientation right (ie. see right hand rule).

Yaro
Member
Posts: 31
Joined: Wed May 20, 2015 11:28 am

Re: IMU sensor upside down

Post by Yaro » Thu Mar 24, 2016 6:34 pm

arnaud wrote:This sounds like you need to look at the distribute power function.

The rush you are describing could come from the yaw control loop. Since you inverted everything you should make sure that the power distribution function is still right and for example for the yaw the correction should go in the right direction.

Also for the axis, normally you should inverse 2 axis in order to keep the orientation right (ie. see right hand rule).
Thanks for your answer. I've corrected distributePower function to have correct Yaw and Pitch. I've also checked that when Yaw movement occours then correct motors turn(ex. clockwise movement - anti-clockwise motors activates).

I've changed only dz = -dz and setted motors IDs in right order for the second axis to respect hand rule. I know that I should change axis read value sign instead to flip motors, but in this way seems the same.

But nothing changed about my main problem that two motors(that motors used for ROLL movement) starts with high thrust and then go slowly to normal 0 thrust. I've tryed to change also dy and dx sign in sensfusion6GetEulerRPY but nothing changed(just dx or dy axis are flipped like if I flip motor position).

Do you have other ideas or where can be the problem? Tomorrow I'll post sensor readings to check if it's all correct.

Yaro
Member
Posts: 31
Joined: Wed May 20, 2015 11:28 am

Re: IMU sensor upside down

Post by Yaro » Fri Mar 25, 2016 1:14 pm

I'm here again! I've solved this problem, I was not correctly changing sings and not in the right place. Now after calibration is done, drone is calm an no motors running with low trust, I've also checked again if correct motor activates on each movement of roll, pitch and yaw.

But this not solved my problem that drone when going to leave ground start to slowly rotate on itself(I've noticed that is always anti-clockwise) and when have reached enough power to take off it trasforms in a flying spinning top. I hope that is becouse I should calibrate PID, but if someone have advices they are welcome!
In the case, I'll open another thread about PID calibration if I'll need help.

Thank you!

arnaud
Bitcraze
Posts: 1928
Joined: Tue Feb 06, 2007 12:36 pm

Re: IMU sensor upside down

Post by arnaud » Tue Mar 29, 2016 7:23 am

great that you solved some problems!

Are you based on a recent version of the firmware? The rotation at take-off was a problem and has been fixed by this code: https://github.com/bitcraze/crazyflie-f ... #L217-L226: the yaw control is done on an internal setpoint. Previously the yaw control was only on rate (degrees per seconds) and there was some drift at take-off which look like what you are observing.

Post Reply