Step 24: Tuning

Due to variance in the individual motors / frame, you may need to alter the p and d values in the code above. The variable p controls how much the quadrotor will alter motor speeds to correct for an offset from the desired tilt. The variable d controls how much the quadrotor will resist sudden rotation. An incorrect ratio of p to d could cause the quadrotor to be unstable either by being less responsive than desired or by causing oscillations of increasing magnitude. Scaling up both p and d by the same value would increase the magnitude of the current effects.

Our tuning method involved a lot of trial and error. We would support 2 opposite corners of the quadrotor leaving the other 2 free to rotate. Then we would check for stability by first observing if the quadrotor was keeping itself level, then secondly by injecting disturbances to observe if it would return to a level position. If the p and d values permitted the quadrotor to pass both of these tests, we would repeat the procedure and on the other axis. When the quadrotor was stable on both axis, we then were ready to fly!
I'm buying an Arduino Uno. I'm not sure if you know, but would you connect the same pins on the uno? Or do they have numbers and voltage correlations?
The Arduino Uno has a lightly different layout then the Pro Mini being used here. One plus is that you can skip that 3.3v regulator because there is one on the board already. You'll notice that there is a pin labelled &quot;3.3v&quot; to which you can connect the corresponding 3.3v port on your sensor board.<br><br>So the pins for the sensor board the line up as such;<br>3.3v = 3.3v<br>GND = GND<br>Gx4 Y = Analogue5<br>Gx4 X = Analogue4<br>Gx4 Z = Analogue3<br>A Z = Analogue2<br>A Y = Analogue1<br>A X = Analogue0<br><br>The rest of the pins should correspond plainly to the ones on your UNO <br>Digital pins 6,7,8,9 to the control pin on your ESCs. Human controls are on pins 2,3,4,5 to your receiver. Personally I am using an Xbee module instead so I will not be using that last set.
<p>Hi, I came across your project and I am doing almost the same. However, I am using and arduino UNO and an MPU6050. The Pin alignment that you mentioned above; I am a little confuse about it.</p><p>I can not find the Gx4 Y, Gx4 X, Gx4 Z or the A Z - X pins on my MPU6050 board. THe only way I connect it to it is by connecting SCL - Analog 5 and SDA - Analog 4. So can you please explain how can I implement it?</p>
<p>Hi, I am also using the same equipments : arduino uno and mpu 6050.</p><p>I have just interfaced mpu6050 with arduino and could read the yaw pitch roll values on serial monitor.</p><p>Instead of using RC Radio Controller, I want to use a bluetooth module and android app to control the flight controller.</p><p>Can you help me about how to use the onboaard sensors to give values and correspondingly how to make arduino give instructions to ESC and motors?</p><p>Really need help, reply asap.</p>
<p>Hi SarveshT1,</p><p>I'm too using an Arduino Uno R3 for making a quadcopter. I however use a MPU-9150 instead of an MPU-6050. But I do use the library called &quot;MPU6050.h&quot;. You can download this library from github. It's part of the I2Cdev repo. Download this library and run some tests.</p><p>Like you've probably already guessed the MPU6050 runs on I2C. This protocol runs on digital signals, not on analog signals as described in this tutorial. For my quadcopter, I want to know the angle the drone's flying in, and from there calculate what to do with the motors. I think this is better because it makes the drone possible to fly on its own. I'm also planning to build an android app, and calculating the exact angle is needed for that too.</p><p>But let's not talk too much about dreams. I use the gyroscope and the accelerometer to calculate this angle. I use a 'Complementary Filter' to calculate this angle as good as possible. This filter picks the best of both worlds. The gyroscope can drift, and the accelerometer is unsteady. How I've implemented it is like this:</p><p>#include &lt;Wire.h&gt;</p><p>#include &lt;I2Cdev.h&gt;</p><p>#include &lt;MPU6050.h&gt;</p><p>//This one is the same for MPU9150 and MPU6050</p><p>#define GYROSCOPE_SENSITIVITY 32.8</p><p>#define RADIANS_TO_DEGREES 57.29577951</p><p>MPU6050 mpu = MPU6050();</p><p>//The timer which is needed for the Complementary Filter</p><p>long timer;</p><p>//The variables where the data from the imu is stored in</p><p>int16_t ax, ay, az, gx, gy, gz;</p><p>//Variables to store the calculated pitch and roll in</p><p>double pitch = 0;</p><p>double roll = 0;</p><p>void setup() {</p><p> Serial.begin(115200); //Personal favor</p><p> Wire.begin(); //The library doesn't do this by itself</p><p> mpu.initialize();</p><p> delay(100);</p><p> //Check if the MPU-6050 is connected, and wait one second before checking again</p><p> while (!mpu.testConnection()) {</p><p> Serial.println(&quot;MPU not found!&quot;);</p><p> delay(1000);</p><p> }</p><p> mpu.setFIFOEnabled(false); //Make sure you always get the newest messages</p><p> Serial.println(&quot;Setup executed!&quot;);</p><p>}</p><p>void loop() {</p><p> long begin = micros();</p><p> //Get the accel and gyro data from the mpu6050</p><p> mpu.getMotion6(&amp;ax, &amp;ay, &amp;az, &amp;gx, &amp;gy, &amp;gz);</p><p> //First calculating the angle of the accelerometer for the pitch.</p><p> //More information google 'Accelerometers and gyroscopes on a chip'</p><p> long squareSum = (long) ay*ay + (long) az*az;</p><p> double accelAngle = atan(ax / sqrt(squareSum)) * RADIANS_TO_DEGREES; //I want my angle in degrees</p><p> pitch += (-gy / GYROSCOPE_SENSITIVITY) * ((micros() - begin) / 1000000.0);</p><p> pitch = 0.98 * pitch + 0.02 * accelAngle;</p><p> //And all the same for the roll but different formula</p><p> squareSum = (long) ax*ax + (long) az*az;</p><p> accelAngle = atan(ay / sqrt(squareSum)) * RADIANS_TO_DEGREES;</p><p> roll += (-gx / GYROSCOPE_SENSITIVITY) * ((micros() - begin) / 1000000.0);</p><p> roll = 0.98 * roll + 0.02 * accelAngle;</p><p> //And print the values to the terminal</p><p> Serial.print(&quot;Pitch: &quot;);</p><p> Serial.print(pitch);</p><p> Serial.print(&quot; Roll: &quot;);</p><p> Serial.println(roll);</p><p>}</p><p>Upload this to your Arduino and it will print the angle of your mpu to the screen. Check the baudrate! </p><p>About the ESC's I can't tell you very much now, I'm still figuring this one out. I've found out how to get angle, but now translating that angle to a pulse is the difficulty. I wish you good luck with your project!</p>
Can you send me all the code? I'm using arduino uno and mpu6050.. Please send all code and the Diagram wires esc to arduino and arduino to receiver... My email is rvalent86@gmail.com
<p>did u got the code?</p>
<p>What code do you want?</p>
<p>thank u so much for responding me. i'm making project on quadcopter and that should be controlled by using hand gestures. If u send me your email,I can tell u the details. Please help me on this. I want complete arduino code for quadcopter. I'm using arduino mega. </p>
<p>This is al the code...</p>
<p>Can you send me all the code? I'm using arduino uno and mpu6050.. Please send all code and the Diagram wires esc to arduino and arduino to receiver... My email is rvalent86@gmail.com</p>
<p>1. This is all the code for reading an MPU6050, which was the question. Download the MPU6050 library from <a href="http://www.varesano.net/files/FreeIMU-20121122_1126.zip" rel="nofollow">http://www.varesano.net/files/FreeIMU-20121122_112...</a> .</p><p>2. MPU:</p><p>Arduino 3.3v - MPU6050 Vcc</p><p>Arduino GND - MPU6050 GND</p><p>Arduino A5 - MPU6050 SCL</p><p>Arduino A4 - MPU6050 SDA</p><p>3. ESC</p><p>ESC-Signal wire - Arduino uno random programmed output port</p><p>ESC-Signal wire - Arduino uno random programmed output port</p><p>ESC-Signal wire - Arduino uno random programmed output port</p><p>ESC-Signal wire - Arduino uno random programmed output port</p><p>ESC-Ground wire - Arduino GND (Only do this with one ESC)</p><p>(Check if your ESC is a BEC or you have a 2nd battery)</p><p>ESC 5v (Only do this with one ESC!) - Arduino 5v (This ESC will power the Arduino and the Receiver)</p><p>4: Remote</p><p>Remote GND - Arduino GND</p><p>Remote 5v - Arduino 5v</p><p>Remote CH1 - Arduino input port</p><p>Remote CH2 - Arduino input port</p><p>Remote CH3 - Arduino input port</p><p>Remote CH4 - Arduino input port</p><p>I wish you good luck finding better sources with such an ungrateful attitude.</p>
I2C bus son
<p>I am also using xbee...can you please share the code with me...please</p><p>my email id is dhrvjsh102189@gmail.com</p>
What is a good way to get started with learning the Arduino?
Getting your hands dirty. Personally, I got myself the <a href="http://adafruit.com/products/68" rel="nofollow">starter kit</a> from Adafruit; and they also have an excellent set of <a href="http://learn.adafruit.com/category/learn-arduino" rel="nofollow">tutorials</a> .<br> <br> I had some programing experience at the time already, so for me it was an exercise in learning how to bring code into the physical realm. The Adafruit tutorial were good for me to shore up on the electronics side of things.<br> <br> Did you have a project in mind already? I find that having a specific goal when learning something new greatly increases your chances of success and I'm more than happy to take a stab at it if you have any specific questions.
Thank you. That's very useful. The project I want to build is a semi-autonomous ground rover with a remotely fired paintball gun.
<p>I want the complete code for quadcopter using arduino and also the parts list for my final year project. Can anyone help me?</p>
<p>nice work sir. sir i am using arduino uno and mu6050 </p><p>sir can u plz provide me the connections schematic and the code . my email</p><p>talhapervez317@gmail.com</p>
<p>Nice Article </p>
Can u jst tell me how much this project will cost....
<p>Genius. Thanks for sharing.</p>
<p>In esc has three wires which wire can i connect to arduino </p>
<p>hello friends, </p><p>can anyone help more about 'step19' please.I want more information about circuit diagram and how to wire Adurino and IMU ? and also I want to know about the first image at 'step 19', is this battrey ?!</p>
<p>Hi :)</p><p>https://www.youtube.com/watch?v=lEjDbypSjDE</p><p><a href="http://www.france-helico.com/topic/22816-homemade-quadcopterc-code-sans-arduinomultiwii/" rel="nofollow">http://www.france-helico.com/topic/22816-homemade-...</a></p>
<p>Hi , we want design flight controller with arduino through model based design for a quad rotor , what sort of quadcopter is suitable for this aim ? a provided one or assembling separate parts ?</p>
Can you post a picture showing the position of the motors and to the pins they are connected to.I'm also on facebook as yawgyakobo
Thanks sanderv3. I will keep all that in mind. Be in touch. And update me if you utilize the android app and bluetooth.
Great job but I am having a hard time understanding the interface between the radio receiver and the Arduino. The individual channel outputs from the receiver are pulse width modulated-- usually about 1us for low, 1.5 us for neutral, 2 us for high. Yet you read in the channels using analogRead() so I take it that the Arduino is reading in the analog value of a pulse width modulated signal. I would have thought that would be a very inaccurate way of reading in the channels but you appear to have made it work. Is this by design, chance, or ?<br><br>Could this be contributing to the instability at takeoff since changing signal values might take more time to register through the pulse width to analog transition?
The analogReads are only used to read in the values from the accelerometers and gyros which are voltages.<br><br>The inputs from the radio receiver are read by the pulseIn commands a few lines of code below.
<p>hey, If I want to use a Bluetooth module instead of reciever and android app instead of transmitter, is it fine? I want less range.</p><p>As shown in step 19, if I use Bluetooth module, then I have to connect it pin 2,3,4,5(Human input)?</p>
<p>sir i m using arduinouno r3 for quadcopter and i have 10 dof plz tell me which pins should be connected between arduino and 10 dof. and tell me if there is a some need to modify above code. thank you</p>
<p>can you please share the code with me...please</p><p>my email id is <a href="mailto:jhongudyy@gmail.com" rel="nofollow">jhongudyy@gmail.com</a></p>
<p>sir i m making quad copter by using arduino uno r3, and i have 10 dof, i doesnt have idea how to connect them plz told me. and also tell me what is which i should use is the above code is useful for me? my email id is praveenkhatri831@gmail.com. </p>
Hello i want to ask you dose your code move the quad forward ,backward ,right and left where in the code dose it do this moving ??<br>And if it dose not how could i move it ??<br>Regards.
<p>Is this all of the code necessary to create a working quadrotor?</p>
<p>thanks this is a very good post! I just have a question: you said</p><p>&quot;To find the current amounts of tilt on the X and Y axis from <br>accelerometer and gyro data, we used an algorithm that would average <br>previous accelerometer data and combine it with gyro data to reach an <br>angle measurement that was fairly resilient to linear acceleration.&quot;</p><p>Would it be possible to know where we can find this code? </p>
<p>Hi, thanks so much for your post! I have a quick question. Do I need the transmitter and receiver? Is there anyway I can make it work without it? I'm a physics student getting ready for a final project- I have everything but those parts. So a quick reply would be ideal, thank you SO much!</p>
<p>i dont have motor, can it made by two different pair of motor</p>
<p>too little comments in your code such that it is difficult for me to understand your code. can you please explain me what does variables &quot;GYRO_CON ACCEL_CON TIME_CON SEN_CON zhuman xaverage yaverage blah&quot; mean? and how did you get the formulas like &quot;xaverage= SEN_CON *( xaverage + TIME_CON * pitch) + ( 1 - SEN_CON ) * xin;&quot; or &quot;speeds[0] = zhuman - p*(xaverage - pitchin) - p*(yawin) - d*pitch;&quot; ? Many thanks if you can explain me in detail!</p>
I'm missing something;two questions <br>1. is this in inches? <br>2. is it 2&quot; each side of the center line? <br>3. mark at points (.875,2.125), (1.375,.875), (2.125,.875), (2.125,0), (1.5, 1.5) from the origin or the point where the center lines intersect. <br>what is the two measurements?from center line i.e .875 from cl and 2.125 from cl?measured from which axis?
can i replace sparkfun mpu -6050 by inven sense mpu-6050? it costs less than sparkfun....
Hi, you can use whatever you like with MPU 6050. Sparkfun uses the MPU6050 IC manufactured from Inven Sense. From Inven Sense you can buy just the IC. From Sparkfun you can buy the chip soldered on a board and ready-to-use. The choice is yours :)
Hello, I was wondering how motor speed from the speeds[] array corresponds to the motors of the construction. Which equation is for the front, back, left and right motor. <br>Thank You in advance
i want all the details of this quadrotor plzzzzz help me futurescientist10@gmail.com
hi,i wanna build one,how can i estimate it's weight?
any one help? <br>
hello nice work. i have the data of the gyro x, gyro y and gyro z, and the inclination of pitch and roll too but i only want to make it stable in the air without using a remote control. ongly vertical takeoff and landing wo what do i have to change in the code?
sir, <br>the matter that u posted inspired me to make own quad rotor , <br>i am bech final year student of SKU , i am doing project on quad rotor and i want to make quad rotor integrated with camera to send a signal to laptop... <br> can u pls help me with some guide lines... <br> thank you sir..

About This Instructable




More by jjdream:quadrotor 
Add instructable to: