Go Down

Topic: [UPDATES] Bicopter stabilization algorith (PLEASE HELP NEEDED!!!) (Read 7024 times) previous topic - next topic

MartinL

#30
Apr 12, 2017, 05:07 pm Last Edit: Apr 12, 2017, 05:36 pm by MartinL
Hi Marco,

Quote
read some articules that say that you need a digital compass but in some other places say that the mpu6050 can do it.
You don't require a compass. In either rate or auto-level modes, yaw is controlled by rate (degrees/s) and is measured using only your gyroscope's Z-axis.

The compass is required when you need to know the aircraft's heading and is really only necessary in conjunction with a GPS for automated flight.

Quote
I know that i should add the yaw correction on the servos positions but what i can figure out yet is how to calculate the yaw using the mpu6050.
Convert your pilot's yaw rate input to degrees/s and use this as the setpoint of your yaw rate PID. Take the gyroscope Z-axis (also in degrees/s) and make this the input to the yaw rate PID.

For a bicopter, the motor mixing for yaw axis should make the servos move the propellers in opposing directions. As the servos are opposite to each other, you can just add (100% of) the yaw rate PID output directly to your servos' centre signals. Usually the centre signal is around 1500us or thereabouts. If the yaw rate is too weak or too strong then just adjust the yaw rate PID's gain.

rossi86m

#31
Apr 13, 2017, 04:05 pm Last Edit: Apr 13, 2017, 04:15 pm by rossi86m
Hi Marco,

You don't require a compass. In either rate or auto-level modes, yaw is controlled by rate (degrees/s) and is measured using only your gyroscope's Z-axis.

The compass is required when you need to know the aircraft's heading and is really only necessary in conjunction with a GPS for automated flight.

Convert your pilot's yaw rate input to degrees/s and use this as the setpoint of your yaw rate PID. Take the gyroscope Z-axis (also in degrees/s) and make this the input to the yaw rate PID.

For a bicopter, the motor mixing for yaw axis should make the servos move the propellers in opposing directions. As the servos are opposite to each other, you can just add (100% of) the yaw rate PID output directly to your servos' centre signals. Usually the centre signal is around 1500us or thereabouts. If the yaw rate is too weak or too strong then just adjust the yaw rate PID's gain.

I am working on this but after converting gz to angle i am getting this result

As you will see on the numbers below first i am getting nan (i do not know why) and then after reseting the arduino i start getting something but the number is always decreasing, then i turn it 90 degrees to the right and i get a value that doesn't make sense at least for me.

I attached the test code that i am using.

Any help is welcome

| GyZ = nan
| GyZ = nan
| GyZ = nan
| GyZ = nan
| GyZ = nan
| GyZ = nan
| GyZ = nan
| GyZ = nan
| GyZ = nan
| GyZ = nan

I reset the arduino and it start working

| GyZ = -2.83
| GyZ = -5.28
| GyZ = -5.13
| GyZ = -8.03
| GyZ = -7.60
| GyZ = -8.30
| GyZ = -10.74
| GyZ = -10.34
| GyZ = -12.50

I turn it 90 degrees to the right

| GyZ = -160.43
| GyZ = -253.56
| GyZ = -256.15
| GyZ = -248.79
| GyZ = -244.95
| GyZ = -241.60
| GyZ = -238.36
| GyZ = -234.93
| GyZ = -232.15
| GyZ = -229.19
| GyZ = -226.04
| GyZ = -223.43
| GyZ = -220.55
| GyZ = -217.62
| GyZ = -215.33
| GyZ = -212.67
| GyZ = -210.09
| GyZ = -207.72
| GyZ = -204.91
| GyZ = -202.63
| GyZ = -200.52
| GyZ = -197.89

MartinL

Hi Marco,

Quote
I am working on this but after converting gz to angle i am getting this result
You don't need to convert the gz to angle. Just divide the raw gz value by 131 (for the gyro set at its default of ±250°/s full scale) to get the yaw rate in degrees/s.

To get the bicopter flying initially you only need the gyroscope measuring degrees/s, the calculations shouldn't have anything to do with angle.

rossi86m

#33
Apr 15, 2017, 08:09 pm Last Edit: Apr 15, 2017, 08:16 pm by rossi86m
Hi Marco,

You don't need to convert the gz to angle. Just divide the raw gz value by 131 (for the gyro set at its default of ±250°/s full scale) to get the yaw rate in degrees/s.

To get the bicopter flying initially you only need the gyroscope measuring degrees/s, the calculations shouldn't have anything to do with angle.

I finally implement it as you suggested

The yaw control seems to work well. But i am still having problems with the pitch, controlingthe servos.

I attache my code and also a youtube video link so you have a better idea of what i am talking about.
https://youtu.be/8EgRYQz5AjI

The thing is that the pitch control is not smooth

Any suggestion is welcome. I feel that i am almost there

Thanks,
Marco

MartinL

#34
Apr 17, 2017, 10:50 am Last Edit: Apr 17, 2017, 10:52 am by MartinL
Hi Marco

Pitch works in the same way as yaw, except that the servos need to point the motors in the same direction, (as opposed to yaw that points them in the opposite direction). To do this add (100% of) your pitch rate PID output to the centre point (1500us) of one servo and subtract (100% of) your pitch rate PID output from the other.

In your code you also need plug Gx and Gy into your PID roll and pitch rate control loops rather than Ax and Ay.

Ax and Ay from the complementary filter are required for auto-level, but the first step is to get the bicopter flying in rate mode that only uses the gyroscope, as this is the basis for flight stability.

So, initially you only need 3 PID control loops for roll, pitch and yaw each taking Gx, Gy and Gz as inputs. The pilot PID setpoints for roll, pitch and yaw should also be in degrees/s.


rossi86m

Thanks for the answer you are helping me a lot.

The thing is, and correct me if i am wrong, if i use Gy i am not sure if the bicopter will go back to a 0 degrees position if something alter the pitch same thing with Gx.

I tried it yesterday but as i mentioned when i alter the pitch the bicopter reacts but it doesn't go back to 0 degrees position

I do not know if i am clear,

Thanks,
Marco

MartinL

#36
Apr 18, 2017, 10:36 am Last Edit: Apr 18, 2017, 11:13 am by MartinL
Hi Marco,

Quote
The thing is, and correct me if i am wrong, if i use Gy i am not sure if the bicopter will go back to a 0 degrees position if something alter the pitch same thing with Gx.

I tried it yesterday but as i mentioned when i alter the pitch the bicopter reacts but it doesn't go back to 0 degrees position
That's right. Nowadays multi-rotor aircraft have a number of different flight modes, this includes rate mode and auto-level.

The most basic mode is rate mode. This uses only the 3-axis gyroscope measuring rotational speed (degrees/s) in the X, Y and Z axes. The pilot setpoint for roll, pitch and yaw is also in rotational speed (degrees/s). This gives a very free flowing, natural style of flight and is the flight mode of choice for most experienced pilots.

As you mentioned, in this mode the flight controller isn't using the accelerometer, as such it has no way of knowing which way is up and therefore how to level the aircraft. Levelling must be maintained by the pilot.

Even though flying in rate mode is initially much more difficult than auto-level, it's necessary to tune and fly the bicopter in this mode before moving on to auto-level. This is because the rate mode PIDs are the basis of stable flight and are also used in auto-level mode.

In auto-level mode you use two outer roll and pitch angle (degrees) PID control loops to control the inner rate (degrees/s) PID control loops. In this mode the pilot setpoint for roll and pitch is an angle, for instance in degrees, between ±45°. The input for these two outer PID loops is the roll and pitch angle, taken from the complementary filter, (that fuses the integral of the gyroscope with the angle generated from the accelerometer to give a reliable angle estimate). The output from these outer PID loops is then used as the input to the roll and pitch rate PID controllers. The inner, nested rate control loops still provide the flight stability, but rather than the pilot driving them directly, as in rate mode, they're now driven by the outer control loops that maintain angle.

In auto-level mode when you let go of the controls the aircraft self levels. This makes it easier to fly, as the flight computer removes the burden of the pilot having to control every aspect of the aircraft's rotational motion (attitude).

The yaw axis remains unchanged from rate mode and is just driven by a single rate PID control loop (gyroscope's Z axis).


rossi86m

In auto-level mode you use two outer roll and pitch angle (degrees) PID control loops to control the inner rate (degrees/s) PID control loops. In this mode the pilot setpoint for roll and pitch is an angle, for instance in degrees, between ±45°. The input for these two outer PID loops is the roll and pitch angle, taken from the complementary filter, (that fuses the integral of the gyroscope with the angle generated from the accelerometer to give a reliable angle estimate). The output from these outer PID loops is then used as the input to the roll and pitch rate PID controllers. The inner, nested rate control loops still provide the flight stability, but rather than the pilot driving them directly, as in rate mode, they're now driven by the outer control loops that maintain angle.

You got exactly to the point of what i am trying to achieve.

Since i have a super basic self-made android app control y want to implement an auto-level mode on my bicopter

i was reading a little bit about this but i still do not get a clear example of how to combine the two pids that i need for pitch and roll.

I do not see how an output in degrees can be the input of a pid that works in degrees/s

Do you have some example that i can work with?

Thanks a lot for these clarifications as i mentions is exactly what i trying to do.

Cheers,
Marco

MartinL

#38
Apr 18, 2017, 06:18 pm Last Edit: Apr 18, 2017, 07:03 pm by MartinL
Hi Marco,

Quote
You got exactly to the point of what i am trying to achieve.
Yes, but to set up the flight controller correctly you'll still need to get it flying in rate mode first. Only once you have the correct rate PID gain values that allow the aircraft to fly, can you then add the additional auto-level control loops. The rate PID control loops and their associated P, I and D gain values are critical to the flight control system.

Quote
I do not see how an output in degrees can be the input of a pid that works in degrees/s
I struggled with this concept for quite a while, until I realised that the PID output doesn't represent any units in particular. You just adjust the outer PID's gain to scale the output until it matches required bounds for the next stage. The output can be what you want it to be, so you can just take the outer angle PID's output value and plug it straight into the rate PID control loop's setpoint.

For instance, the same principle can be used for automated flight with the GPS replacing the pilot and PID control loops nested like layers of an onion:

GPS Position PIDs -> GPS Speed PIDs -> Angle PIDs -> Rate PIDs -> Motors/Servos

Notice that the sensor input units from one PID has nothing in common with the units of the next. It's just that the gain of each stage is adjusted appropriately until it matches the expected bounds of the next stage.

In this case the effect is to drive the aircraft from where you are, or current GPS latitude/longitude position (PID input), to where you want to be (PID setpoint), your desired latitude/longitude position.

In the same way, auto-level drives the aircraft from you current roll and pitch angle (PID input), to your desired roll and pitch angle (setpoint):

Pilot -> Angle PIDs -> Rate PIDs -> Motors/Servos

Note that in both examples rate PIDs at the end are still providing your basic flight stability.

MartinL

#39
Apr 18, 2017, 06:50 pm Last Edit: Apr 18, 2017, 07:04 pm by MartinL
Quote
Do you have some example that i can work with?
The code shows how the roll and pitch PID outputs are plugged directly into the roll and pitch rate PIDs:

Code: [Select]
float roll = PID(pilotRollAngle - compFilterRollAngle);     // Outer roll angle PID
float pitch = PID(pilotPitchAngle - compFilterPitchAngle);  // Outer pitch angle PID
 
float rollRate = PID(roll - gyroRollRate);                  // Inner roll rate PID
float pitchRate = PID(pitch - gyroPitchRate);               // Inner pitch rate PID
float yawRate = PID(pilotYawRate - gyroYawRate);            // Inner yaw rate PID

rossi86m

#40
Apr 18, 2017, 09:00 pm Last Edit: Apr 18, 2017, 09:09 pm by rossi86m
Thanks for the info.

As you mentioned i will start with rate mode and then i will add the other pids to auto-level. When i do that i will bother you again to double check my understanding.

But at bird eye view i will need to do something like this

PIDrollAngleSetpoint = 0;
PIDrollAngleInput = rollAngle;
PIDrollAngle.compute();

PIDrollRateSetpoint = Question ;
PIDrollRateInput = PIDrollAngleOutput;
PIDrollRate.compute();

I am missing the Gy(degrees/s) from mpu i think. this is what i do not understand

Sorry for asking this over and over again but as you can see i am a little bit confuse in this particular point

Thanks,
Marco

MartinL

#41
Apr 18, 2017, 11:23 pm Last Edit: Apr 19, 2017, 12:05 am by MartinL
Hi Marco,

For auto-level the pilot's input is in degrees and the outer angle PID output is used as the setpoint to the inner rate PID:

PIDrollAngleSetpoint = pilot input (degrees), ±45° centred at 0°
PIDrollAngleInput = roll angle from the complementary filter
PIDrollAngle.compute();

PIDrollRateSetpoint = roll angle PID output
PIDrollRateInput = Gy;
PIDrollRate.compute();

For rate mode the pilot's input is in degrees/s and is used to drive the inner rate PID directly:

PIDrollRateSetpoint = pilot input (degrees/s), say ±180°/s centred at 0°/s
PIDrollRateInput = Gy;
PIDrollRate.compute();

Most flight controllers have a switch that allows you to switch been rate mode and auto-level in flight.


rossi86m

Thanks for the answer this clarify a lot of thing to me. I am still struggling with degrees and degrees/s all mixed

As you recommend me i will start with rate and after tuning the pids values i will add the nested loops.

Updates soon,

Thanks!

rossi86m

More updates.

Code adjustments made on martinl suggestions. Right now i am tunning pid values.

New motor mount made using the center of briken propelers. Opinions???

Next steps, implememt two pid loops for pithc and roll for auto level.

I am sharing code and some fotos of the new motor mounts

Pls feel free to give me more suggestions/opinions/whatever

Cheers,Marco

MartinL

Hi Marco,

The bicopter's looking good.

For my tricopter servo I use a clevis and push rod setup, please see image attached.

Go Up