Pages: 1 ... 5 6 [7]   Go Down
 Author Topic: BlueCopter - Arduino Quadcopter  (Read 11066 times) 0 Members and 3 Guests are viewing this topic.
Offline
Newbie
Karma: 2
Posts: 1
 « Reply #90 on: December 05, 2013, 12:09:39 pm » Bigger Smaller Reset

Hi Basel!

For a school Project i'm making a Arduino Based Quadcopter, I'm working with a Arduino Uno so your code doesn't work out of the box for me. I'm making my own code based on yours. Now when the stabilization part begins, i don't understand the PID's.

First you got the angle mode?
Code:
if (rateAngleSwitch == 0){
setX=(int)PIDangleX.Compute((float)setX+angles[0],gy_aver,(float)setX/RX_ANGLE_DAMPNING);
setY=(int)PIDangleY.Compute((float)setY-angles[1],gx_aver,(float)setY/RX_ANGLE_DAMPNING);
}
I don't understand what this part does, Can you explain what each part of the PID does? The confusing part is the gy_aver in the SetX-part and the gx_aver in de SetY part.

Then there is the rate mode?
Code:
int PIDroll_val= (int)PIDroll.Compute((float)setX-gy_aver);
int PIDpitch_val= (int)PIDpitch.Compute((float)setY-gx_aver);
int PIDyaw_val= (int)PIDyaw.Compute((float)setZ-gz_aver);
Here you calculate the adjustments of the roll/pitch/yaw part, i understand that, but why do you do SetX-gy_aver? and not SetY-gy_aver?

 « Last Edit: December 05, 2013, 12:37:41 pm by Jenzaah » Logged

Sweden
Offline
Full Member
Karma: 8
Posts: 207
 « Reply #91 on: December 07, 2013, 01:16:57 am » Bigger Smaller Reset

Hey,

Well, I don't know if you read the whole thread or not.. But if you go back and look at page 2, you'll see a picture that explains the whole flight control part.. Still I'll try to answer your questions as best as I can..

Now when the stabilization part begins, i don't understand the PID's.

First you got the angle mode?
Code:
if (rateAngleSwitch == 0){
setX=(int)PIDangleX.Compute((float)setX+angles[0],gy_aver,(float)setX/RX_ANGLE_DAMPNING);
setY=(int)PIDangleY.Compute((float)setY-angles[1],gx_aver,(float)setY/RX_ANGLE_DAMPNING);
}
I don't understand what this part does, Can you explain what each part of the PID does? The confusing part is the gy_aver in the SetX-part and the gx_aver in de SetY part.

If you look at the picture on page 2 you'll see that the flight control is made by two loops.. Let us call them the rate loop and the angle loop.. The rate loop is always running and the angle loop is only turned on when you're in angle mode... You can think of it as if the rate PID's are the only ones existing in code and and the set points for these PID's are simply the receiver input.. When you switch over to angle mode you simply turn on two more PID's that auto-pilots your quadcopter (keep it leveled).. So the receiver input will instead be controlling the angles (set point for the angle PID's) and the angle-PID's will in turn control the set-points for the rate PID's.... I hope I didn't confuse you there =), but it's really hard to explain it better without a whiteboard =P... Now the reason for me doing it this way is because of the hardware! Gyro's are accurate at high frequency's (faster updates -> continuous loop) and accelerometers are accurate at low frequency's (slower updates == as slow as the receiver updates == 50Hz)..

The reason for the gy_aver on setX and vice versa is simply the way I've set up my coordinate system and the way I chose to set up the calculations.. See page 6, I've explained it there...

Then there is the rate mode?
Code:
int PIDroll_val= (int)PIDroll.Compute((float)setX-gy_aver);
int PIDpitch_val= (int)PIDpitch.Compute((float)setY-gx_aver);
int PIDyaw_val= (int)PIDyaw.Compute((float)setZ-gz_aver);
Here you calculate the adjustments of the roll/pitch/yaw part, i understand that, but why do you do SetX-gy_aver? and not SetY-gy_aver?

Because setX is the angular rate of the X axis (Roll) and it corresponds to the gyro's measurement on the Y axis.. I know it's confusing but look at the coordinate system I've attached on page 6 and you'll get it..

//Basel
 « Last Edit: December 07, 2013, 01:18:28 am by baselsw » Logged

Offline
Newbie
Karma: 0
Posts: 16
 « Reply #92 on: December 08, 2013, 10:27:45 am » Bigger Smaller Reset

Basel,
tried to fly with him today, but I could not! look in the test cavalote shaped "U" with a degree of freedom, he was responding well! then calibrated it on the floor and went testing in bed! but soon noticed that the speeds quickly changed and increased acceleration when it rose and fell quickly in bed as if a hand was unbalanced! how do I raise the flight! start angle mode or rate mode? you think I should change the values ​​of PID?
 Logged

Sweden
Offline
Full Member
Karma: 8
Posts: 207
 « Reply #93 on: December 08, 2013, 10:34:20 am » Bigger Smaller Reset

Basel,
tried to fly with him today, but I could not! look in the test cavalote shaped "U" with a degree of freedom, he was responding well! then calibrated it on the floor and went testing in bed! but soon noticed that the speeds quickly changed and increased acceleration when it rose and fell quickly in bed as if a hand was unbalanced! how do I raise the flight! start angle mode or rate mode? you think I should change the values ​​of PID?

That sounds like you need to calibrate your PID.. You always start with rate mode (because it's the main loop in code).. If rate mode isn't calibrated correctly you'll never get a stable copter with angle mode.. If you go back to page 3 you'll see a small guide to how to calibrate the PID's.. Anyway here is the same guide:

1 ) Put the quadcopter in rate mode
2 ) Increase the throttle until the quadcopter starts to hover on its own..
3 ) Increase the P-term until you observe oscillations..  Now subtract 10% of the value and set it as your P-term ..
4 ) Increase the D-term until you observe oscillations..  Now subtract 10-20% of the value (this is your D-term now)..
5 ) Now go back and increase the P-term with small steps until you observe oscillations.. Then subtract a couple of steps..
6 ) Increase the I-term until you observe oscillations.. These oscillations will have a lower frequency, so step up the I-term slowly.. And be careful when it starts to oscillate.. Because the P- and D-term will kick in, and increase the frequency of the oscillations.. So be careful! After that, substract approx. 10-15% of the value...
7 ) If you are satisfied with the results, then go out and take it for a spin, and observe how it flies and reacts to the wind etc.. Then go back and fine tune your copter if you observed any types of oscillations/control problems..
8 ) Do the same for Angle Mode..
9 ) Buy me a beer!!!!!

//Basel
 « Last Edit: December 08, 2013, 10:36:08 am by baselsw » Logged

Offline
Newbie
Karma: 0
Posts: 16
 « Reply #94 on: December 08, 2013, 03:17:55 pm » Bigger Smaller Reset

Basel,
where to start! I reset the values ​​of ki and kd in terms config.h to PID.pitch, PIDRoll, PIDyaw, PIDAngleX, PIDAngleY​​? create a tab to send the data kp, ki and kd the serial to keep up? I find three sets values ​​of kp, ki, and kd correct, since the symmetry guarantees that the values ​​of pitch and roll are the same! the same for the angles X and Y. Look, attached below a picture of my Quad in CAVALOTE shaped "U".

At the exit of the engine, just let m1 = trottle + PIDpitch and m2 = trottle-PIDpitch? and I'm varying the values ​​of P until he started to oscillate as his Palace to palace? I'll start with P = 1, and see if it fluctuates.
 Quadsapo.jpg (342.01 KB, 2044x1532 - viewed 15 times.) « Last Edit: December 08, 2013, 03:29:08 pm by satiro » Logged

Sweden
Offline
Full Member
Karma: 8
Posts: 207
 « Reply #95 on: December 08, 2013, 03:56:30 pm » Bigger Smaller Reset

Basel,
where to start! I reset the values ​​of ki and kd in terms config.h to PID.pitch, PIDRoll, PIDyaw, PIDAngleX, PIDAngleY​​? create a tab to send the data kp, ki and kd the serial to keep up? I find three sets values ​​of kp, ki, and kd correct, since the symmetry guarantees that the values ​​of pitch and roll are the same! the same for the angles X and Y. Look, attached below a picture of my Quad in CAVALOTE shaped "U".

The simplest way is to change the values and re-upload..  The harder way is to open a new tab and write something that will change the values through serial.. Here is an UN-TESTED example:

Create a new tab and name the file: PID_Change_Serial.ino, type this code in the newly created file:
Code:
int kp=0;
int ki=0;
int kd=0;

if(Serial.available()>0){
a = a-'0';
switch (a) {
case 0:
kp=kp+100;
break;
case 1:
kp=kp-100;
break;
case 2:
ki=ki+10;
break;
case 3:
ki=ki-10;
break;
case 4:
kd=kd+1;
break;
case 5:
kd=kd-1;
break;
}
PIDroll.ChangeParameters((float)kp/1000.0,(float)ki/1000.0,(float)kd/1000.0,ROLL_PID_MIN,ROLL_PID_MAX);
PIDpitch.ChangeParameters((float)kp/1000.0,(float)ki/1000.0,(float)kd/1000.0,PITCH_PID_MIN,PITCH_PID_MAX);
Serial.print("Kp: ");
Serial.print(kp);
Serial.print('\t');
Serial.print("Ki: ");
Serial.print(ki);
Serial.print('\t');
Serial.print("Kd: ");
Serial.println(kd);
}
}

And in BlueCopter.ino, put this in the loop:

Code:
void loop() {
FlightControl();
#ifdef DEBUG
debugProcess();
#endif
}

Don't forget to enable DEBUG-mode from the config.h.. Set all the P, I and D values to zero in config.h..

Now hook up your quadcopter through USB, upload the code and turn everything on (power to the motors etc).. Open the Serial-monitor and type the following to change the P, I and D values for the roll and pitch.. When you've got everything stable on these axis we will go on and calibrate the YAW..

Now send the following through the Serial-monitor to adjust the P,I and D values:

Increase P: send a "0"
Decrease P: send a "1"
Increase I: send a "2"
Decrease I: send a "3"
Increase D: send a "4"
Decrease D: send a "5"

For each change the quadcopter will send the current P, I and D values..

//Basel
 Logged

Offline
Newbie
Karma: 0
Posts: 16
 « Reply #96 on: December 08, 2013, 08:52:52 pm » Bigger Smaller Reset

Basel , both! In the palace the palace of PID tuning the palace 3 is not equal to the Palace 5 ? And the other in PID_Change_Serial I have done as you indicated , but the figures are more fast ! is not the case for adding the Serial.print PID_Change_Serial the tab next to Debug_Angle ! I can enchergar there ! else doing all values ​​equal to " zero " .

# define ROLL_PID_KP 0
# define ROLL_PID_KI 0
# define ROLL_PID_KD 0
# define ROLL_PID_MIN -50.0
# define ROLL_PID_MAX 50.0

# define PITCH_PID_KP 0
# define PITCH_PID_KI 0
# define PITCH_PID_KD 0
# define PITCH_PID_MIN -50.0
# define PITCH_PID_MAX 50.0

# define YAW_PID_KP 0
# define YAW_PID_KI 0
# define YAW_PID_KD 0
# define YAW_PID_MIN -50.0
# define YAW_PID_MAX 50.0

# define ANGLEX_KP 0
# define ANGLEX_KI 0
# define ANGLEX_KD 0
# define ANGLEX_MIN -100.0
# define ANGLEX_MAX 100.0

# define ANGLEY_KP 0
# define ANGLEY_KI 0
# define ANGLEY_KD 0
# define ANGLEY_MIN -100.0
# define ANGLEY_MAX 100.0
No need to disable PID_int ( ) ? void setup there .
I can not understand how as the two PIDs will live together!
You can change my code ! He follows in the Annex !

Sweden
Offline
Full Member
Karma: 8
Posts: 207
 « Reply #97 on: December 09, 2013, 11:14:00 am » Bigger Smaller Reset

Basel , both! In the palace the palace of PID tuning the palace 3 is not equal to the Palace 5 ? And the other in PID_Change_Serial I have done as you indicated , but the figures are more fast ! is not the case for adding the Serial.print PID_Change_Serial the tab next to Debug_Angle ! I can enchergar there ! else doing all values ​​equal to " zero " .

No need to disable PID_int ( ) ? void setup there .
I can not understand how as the two PIDs will live together!
You can change my code ! He follows in the Annex !

No offence, but I'm having a really hard time to understand what you wrote here.. What is palace/place 3 or 5?

Anyway, you did the right thing to set all the PID's to zero.. While calibrating the PID's you can't debug anything else, like DEBUG_ANGLE and such, that explains why the values disappears so fast.. turn them all off.. Only leave DEBUG mode on... You don't need to touch the PID_init(), leave everything there as is.. Which two PID's do you mean??? Angle and rate PID's? What do you need me to change? Your code looks okay...

//Basel
 Logged

Offline
Newbie
Karma: 0
Posts: 16
 « Reply #98 on: December 09, 2013, 12:01:15 pm » Bigger Smaller Reset

Basel,
sorry for not making myself clear! Look, I can tell you from afar you'd make a great teacher! it is pasciente and can explain things difficult even for those who do not know much! Parabens! But back ... Steps 3 and 5 of PID tuning you repeated twice in the topic seems a repeat! In step 5 you do not put values ​​... Type a percentage% but increase and decrease step ... How to change the P, as in 1, you can no longer get away with the term P?

Basel would not be appropriate to change the PID tab there writing :

PIDroll.ChangeParameters((float)kp/1000.0,(float)ki/1000.0,(float)kd/1000.0,ROLL_PID_MIN,ROLL_PID_MAX);
// PIDpitch.ChangeParameters((float)kp/1000.0,(float)ki/1000.0,(float)kd/1000.0,PITCH_PID_MIN,PITCH_PID_MAX);

//PIDyaw.ChangeParameters((float)kp/1000.0,(float)ki/1000.0,(float)kd/1000.0,ROLL_PID_MIN,ROLL_PID_MAX);
//PIDAngleX.ChangeParameters((float)kp/1000.0,(float)ki/1000.0,(float)kd/1000.0,PITCH_PID_MIN,PITCH_PID_MAX);
//PIDAngleY.ChangeParameters((float)kp/1000.0,(float)ki/1000.0,(float)kd/1000.0,ROLL_PID_MIN,ROLL_PID_MAX);
There Degug_Angle write :
Serial.print ( " Kp " ) ;
Serial.print ( (float ) kp/1000.0 ) ;
Serial.print ( '\ t ' ) ;
Serial.print ( " Ki " ) ;
Serial.print ( (float ) ki/1000.0 ) ;
Serial.print ( '\ t ' ) ;
Serial.print ( " KD " ) ;
Serial.println ( (float ) kd/1000.0 ) ;
And Debug_Angle enabled to view real-time adjustment ?

For work with only one degree of freedom , so I need only two opposite motors ! hence the value found is for the two angles of pitch and roll !

Another thing is how will I be able to adjust PID Yaw , it is not necessary that the quad is suspended by a thread ? pos is the movement of yaw direction!
 « Last Edit: December 09, 2013, 12:11:50 pm by satiro » Logged

Sweden
Offline
Full Member
Karma: 8
Posts: 207
 « Reply #99 on: December 09, 2013, 12:57:52 pm » Bigger Smaller Reset

But back ... Steps 3 and 5 of PID tuning you repeated twice in the topic seems a repeat! In step 5 you do not put values ​​... Type a percentage% but increase and decrease step ... How to change the P, as in 1, you can no longer get away with the term P?

The reason that you go back and adjust the P-term in step 5 is that the D-term stabilizes you quadcopter.. So you would be able to increase the P-term a little more...
Well a typical step in BlueCopter firmware is around (for the P-term) is 0.20.. So if your oscillations start at let us say 5.0 then back off two to three steps down to 4.6-4.4..

For the I-term a typical step is 0.05 to 0.10... For the D-term a typical step is 0.002...

Basel would not be appropriate to change the PID tab there writing :

PIDroll.ChangeParameters((float)kp/1000.0,(float)ki/1000.0,(float)kd/1000.0,ROLL_PID_MIN,ROLL_PID_MAX);
// PIDpitch.ChangeParameters((float)kp/1000.0,(float)ki/1000.0,(float)kd/1000.0,PITCH_PID_MIN,PITCH_PID_MAX);

//PIDyaw.ChangeParameters((float)kp/1000.0,(float)ki/1000.0,(float)kd/1000.0,ROLL_PID_MIN,ROLL_PID_MAX);
//PIDAngleX.ChangeParameters((float)kp/1000.0,(float)ki/1000.0,(float)kd/1000.0,PITCH_PID_MIN,PITCH_PID_MAX);
//PIDAngleY.ChangeParameters((float)kp/1000.0,(float)ki/1000.0,(float)kd/1000.0,ROLL_PID_MIN,ROLL_PID_MAX);

If you're calibrating only one axis at a time then yes, you can change them that way...

There Degug_Angle write :
Serial.print ( " Kp " ) ;
Serial.print ( (float ) kp/1000.0 ) ;
Serial.print ( '\ t ' ) ;
Serial.print ( " Ki " ) ;
Serial.print ( (float ) ki/1000.0 ) ;
Serial.print ( '\ t ' ) ;
Serial.print ( " KD " ) ;
Serial.println ( (float ) kd/1000.0 ) ;
And Debug_Angle enabled to view real-time adjustment ?

Another thing is how will I be able to adjust PID Yaw , it is not necessary that the quad is suspended by a thread ? pos is the movement of yaw direction!

You don't need to view the angle because your calibrating the angle-rate.. Meaning that the Angle won't have any influence on your calibration yet.. When calibrating the Angle-PID's you can enable them, but you'll have some problems seeing the P, I and D values when they change, because the angle's are printed on the serial monitor as fast as possible, whereas the P, I and D terms are only printed when you change them... You don't need to view the angles in real time while adjusting.. If you have a lot of trouble finding optimal P, I and D values then you can enable them to see if there is something wrong...

We will leave the Yaw as the last thing to calibrate.. When you've calibrated the Roll and Pitch then we'll go ahead and calibrate the YAW axis.. To calibrate the YAW axis you'll have to hold the quadcopter in your hand... But to be able to safely do that you need to have a stable quadcopter (meaning calibrate the Roll and Pitch)...

Edit: Here is a video of how to calibrate your quadcopter PID's:

//Basel
 « Last Edit: December 09, 2013, 01:01:40 pm by baselsw » Logged

Offline
Newbie
Karma: 0
Posts: 16
 « Reply #100 on: December 09, 2013, 06:32:33 pm » Bigger Smaller Reset

Basel, adjusting the values ​​of Kp, Ki and Kd for one degree of freedom you think that the values ​​can be inserted at angles of Pitch and Roll? or should I do both at the same time as the video? and another thing, after adjusting for the fly without the Yaw angle! because I'm thinking of adjust it only after adjusting the angles X and Y angle mode. What do you think?
 Logged

Offline
Newbie
Karma: 0
Posts: 1
 « Reply #101 on: December 10, 2013, 01:31:10 pm » Bigger Smaller Reset

Hi
I have a question for you.