Enquiries about codings: Data units and Gyro & acc

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
aaarthur
Posts: 19
Joined: Sat May 04, 2013 12:05 pm

Enquiries about codings: Data units and Gyro & acc

Post by aaarthur »

Hi guys,

I am a beginner of MultiWii and now studying it with my poor programming

1. The data of the attitude and acceleration is collected and computed like:

Code: Select all

PTerm -= ((int32_t)gyroData[axis]*dynP8[axis])>>6; // 32 bits is needed for calculation   

Could anyone tell me what is the physical unit for the gyroData? Degrees or 0.1 degrees or what?

2. If my understanding is right, both the function: angle[axis] and gyroData[axis] indicating the attitude of the flight. But why don't we use only gyroData[axis] to be computed as attitude?
I see the program using both angle[axis] and gyroData to derive PTerm :

Code: Select all

      errorAngle = constrain((rcCommand[axis]<<1) + GPS_angle[axis],-500,+500) - angle[axis] + conf.angleTrim[axis]; //16 bits is ok here
      PTermACC = ((int32_t)errorAngle*conf.P8[PIDLEVEL])>>7;                          // 32 bits is needed for calculation: errorAngle*P8[PIDLEVEL] could exceed 32768   16 bits is ok for result
      PTermACC = constrain(PTermACC,-conf.D8[PIDLEVEL]*5,+conf.D8[PIDLEVEL]*5);

Code: Select all

      PTerm -= ((int32_t)gyroData[axis]*dynP8[axis])>>6; // 32 bits is needed for calculation   

What is the difference between these two?
Thank you guys for all your help!!!

User avatar
NikTheGreek
Posts: 348
Joined: Thu Dec 08, 2011 4:17 pm
Location: Greece
Contact:

Re: Enquiries about codings: Data units and Gyro & acc

Post by NikTheGreek »

I would like to take the chance of this question to address a request to admin/moderators of this forum.

Please add a new category under SOFTWARE named "CODE EXPLANATIONS" or something else more "catchy" in order all unexperienced "future" programmers to have a single place to make questions.
This way we will have all code explanations gathered in the same place handy to those looking for more informations.

Thank you .

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

Re: Enquiries about codings: Data units and Gyro & acc

Post by crazyal »

+1 I'd also like to see an eplanation to that obfuscated code ;)

iosonologio
Posts: 13
Joined: Sun Sep 22, 2013 5:46 pm

Re: Enquiries about codings: Data units and Gyro & acc

Post by iosonologio »

I will try to answer. Please more experienced developers correct me.
Your questions refer to the old-stile Alex PID controller.
The PID works in three possible modes. The standard ACRO mode, ANGLE_MODE and HORIZON_MODE. HORIZON mode is actually only a combination of the other two (and i will not discuss it)
In ACRO mode the code relative to PTermACC etc is not executed. The IMU controls propellers such that the angular velocities (gyroData) are the ones requested by the pilot by a combination of:

Code: Select all

PTerm = (int32_t)rc*conf.pid[axis].P8>>6;
PTerm -= ((int32_t)imu.gyroData[axis]*dynP8[axis])>>6;


In ANGLE_MODE the RC value is interpreted as a desired angle (rc)

Code: Select all

errorAngle         = constrain(rc + GPS_angle[axis],-500,+500) - att.angle[axis] + conf.angleTrim[axis];

and the P and I parts of the controller stabilize the angle. (and conf.pid[PIDLEVEL].D8 is just used to fix a limit to the controller)
The D part of the controller still works to keep the angular speed as smooth as possible

To finish answering your question gyroData[axis] is a measurement of the angular velocity. att.angle[axis] is the angle in 0.1 degrees (please somebody correct me here. att.angle[axis] is calculated by averaging the angle calculated by integrating the gyroData and the angle calculated from the accelerator data.

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

Re: Enquiries about codings: Data units and Gyro & acc

Post by Alexinparis »

iosonologio wrote:I will try to answer. Please more experienced developers correct me.
Your questions refer to the old-stile Alex PID controller.
The PID works in three possible modes. The standard ACRO mode, ANGLE_MODE and HORIZON_MODE. HORIZON mode is actually only a combination of the other two (and i will not discuss it)
In ACRO mode the code relative to PTermACC etc is not executed. The IMU controls propellers such that the angular velocities (gyroData) are the ones requested by the pilot by a combination of:

Code: Select all

PTerm = (int32_t)rc*conf.pid[axis].P8>>6;
PTerm -= ((int32_t)imu.gyroData[axis]*dynP8[axis])>>6;


In ANGLE_MODE the RC value is interpreted as a desired angle (rc)

Code: Select all

errorAngle         = constrain(rc + GPS_angle[axis],-500,+500) - att.angle[axis] + conf.angleTrim[axis];

and the P and I parts of the controller stabilize the angle. (and conf.pid[PIDLEVEL].D8 is just used to fix a limit to the controller)
The D part of the controller still works to keep the angular speed as smooth as possible

To finish answering your question gyroData[axis] is a measurement of the angular velocity. att.angle[axis] is the angle in 0.1 degrees (please somebody correct me here. att.angle[axis] is calculated by averaging the angle calculated by integrating the gyroData and the angle calculated from the accelerator data.


I think it's a fairly nice and accurate explanation :)

If you take a common sensor like MPU6050:

in Sensors part:
imu.gyroADC[] unit: // range: +/- 8192; +/- 2000 deg/sec

in IMU part:
same unit for imu.gyroData[]

so, 1 unit = 0.244 deg/s
It's more or less the same for other gyros

about PITCH/ROLL angles: 1 unit = 0.1 deg

aaarthur
Posts: 19
Joined: Sat May 04, 2013 12:05 pm

Re: Enquiries about codings: Data units and Gyro & acc

Post by aaarthur »

Alexinparis wrote:
iosonologio wrote:I will try to answer. Please more experienced developers correct me.
Your questions refer to the old-stile Alex PID controller.
The PID works in three possible modes. The standard ACRO mode, ANGLE_MODE and HORIZON_MODE. HORIZON mode is actually only a combination of the other two (and i will not discuss it)
In ACRO mode the code relative to PTermACC etc is not executed. The IMU controls propellers such that the angular velocities (gyroData) are the ones requested by the pilot by a combination of:

Code: Select all

PTerm = (int32_t)rc*conf.pid[axis].P8>>6;
PTerm -= ((int32_t)imu.gyroData[axis]*dynP8[axis])>>6;


In ANGLE_MODE the RC value is interpreted as a desired angle (rc)

Code: Select all

errorAngle         = constrain(rc + GPS_angle[axis],-500,+500) - att.angle[axis] + conf.angleTrim[axis];

and the P and I parts of the controller stabilize the angle. (and conf.pid[PIDLEVEL].D8 is just used to fix a limit to the controller)
The D part of the controller still works to keep the angular speed as smooth as possible

To finish answering your question gyroData[axis] is a measurement of the angular velocity. att.angle[axis] is the angle in 0.1 degrees (please somebody correct me here. att.angle[axis] is calculated by averaging the angle calculated by integrating the gyroData and the angle calculated from the accelerator data.


I think it's a fairly nice and accurate explanation :)

If you take a common sensor like MPU6050:

in Sensors part:
imu.gyroADC[] unit: // range: +/- 8192; +/- 2000 deg/sec

in IMU part:
same unit for imu.gyroData[]

so, 1 unit = 0.244 deg/s
It's more or less the same for other gyros

about PITCH/ROLL angles: 1 unit = 0.1 deg


Thank you guys!!!
You all helped me a lot.
I am studying Control Theory and would like to build a model using Multiwii code for interest.
I believe I can make a confident start now :D

Post Reply