Yes, i made my own flight controller, including best of all features. I have upgraded till now, so lets break those limitations. Music. A flight controller mainly contains four segments input segments. Take the instruction from the user where to move the drone and the output segments sends the pwm signal to the acs and control the motor speed in order to fly according to the instructions. The imu simply measures the tilt angle in three axis. The processing unit collects all data and corrects the tilt angle using the pid controller. We can also include peripheral devices like gps compass, but that would be for another video for the processing unit. Nodemcu had laid around since long so im gon na use that, since the node ensure has a lower processing power. Actually this little device is way more powerful than i thought it has wi fi. It runs on 80 megahertz. It has inbuilt floating point processor, so thats quite awesome for the imu im gon na use mp6050. It comes with a gyroscope and an accelerometer sensor here: im not using any transmitter, then receiver ill use, wi fi for communication and the reason wait a bit for the rest of the drone im gon na use, my drone, which ive made two years back. So i gathered all the things and started with the coding the sensor uses ascot to communicate. So i connected serial data and serial clock to the d1 and d2 of the node mcu, as described in the datasheet.

It has three modes for each sensor. I am going to use 500 degree scale range of the gyroscope and 8g scale range for the accelerometer to get the angles from it. I have to configure these registers. The y library of the arduino ide will easily do this job. Then i request 14 bytes from the sensor and read the angles in series: make sure that you have defined the integers as 16 bit as the data is a twos complement value. The accelerometer provides real time angle, but the gyroscope provides angular velocity. If i want to get angles from the gyroscope, then i have to integrate the angular velocity in each loop, so i got angles from two different sensors. While the motors generate lots of vibrations which will significantly affect the accelerometer, so i have used a complementary filter to overcome this problem, which uses both sensor data to generate a stable angle, but the gyro sensors have little errors to get resolved. I have placed the drone level and rate that data for four thousand times then took the average, and i got the zero errors in this way. I can calibrate once and use every time then i subtract a detail in each loop. So now i get the perfect real time angles before getting into the escs. We need to know about the pwm pwm is a method of producing pulse of high and low state of a pin the data transferred through. It is the time between the rising edge and the falling edge of the pulse, and it is refreshed periodically, which is the frequency of the pwm signal.

If you pull the signal pin of the ac to high and pull it down after 1000 microseconds, then the throttle input to the ac is zero percent. If you increase that time up to two thousand microseconds, then the speed of the motor will increase accordingly. So here, after defining the pin as output in the loop section, i set the pin to high and after 1000 micro seconds, i pulled it down. If i increase the high state time, then the motor speed increases. Normally. This range is 1000 to 2000 micro seconds. I use direct resistor control to minimize the delay of sitting the pin, high and low. Then i used micro timer instead of the data function now, whatever the value is, it will be always in range of thousand to two thousand micro seconds. So after setting the pin high, i have to wait at least thousand micro seconds and its a waste of time, so i put the mq6050 code in that waiting portion. So at first i set the pin high then hit the mpu 6050 angles as it roughly takes. 400 micro seconds, then it wait until the thousand microseconds is over then pull down each of the four pin connected to the escs. According to the throttle to be sent to the acs in this portion, we got 600 microseconds, so i can put other codes here and still the refresh rate will be 2000 microseconds, giving us a pwm frequency of 500 hertz.

So now we can control the speed of individual motors, but to sync it with the angles in order to correct the tilt angles: im gon na use, pid controller. It uses three types of controller. The p controller changes its values proportional to the angle. Using this formula, the more you tilt the drone, the more it will increase and will reduce if the tilt angle decrease, but only with it. The tone will be wobbly, something like this, so we need some breaking system, and here the d controller comes into place. It only reacts to changes in the angle, but when the angle is close to 0 degree, the p controller will not work for the d controller. As the p controller value will be very low compared to the d controller value at that angle. So we need another controller eye controller which will integrate the values until the tilt angle is perfectly zero degree, and the pid is the sum of those three controllers. I created pid controller for each of the three axis of the drone roll piece and yaw. The calculation takes very short time, so i put the codes in 600 microsecond waiting state while generating the pwm signal for the acs. Now the drone is stable, but i need something to communicate with it and control. I could use commercial transmitter receiver, but theres a speed of lamp, but i dont want to mess up with it again. Since the nodemcu has inbuilt wi fi, i can use it for communication.

I used udp communication to communicate with the python script running on my laptop. That script is very simple, just some keys to increase and decrease the throttle, control direction and changing the pid, constant values and the whole data is 28 byte long, causing a significant amount of delay in the loop for reading the characters from the buffer array. So i have to compress the data, then i got something crazy as key keys, since the data only contains integer, so they can be presented with some specific characters. The wi fi udp library uses 7 bit character array as buffer, so we can use 0 to 127 ascii values, but what will happen to those number which are greater than 127 well, for that i divided the integer in two parts then presented it with two ascii Keys and decoded it again in the arduino loop section, but still i cant, send all data at once. So i used another character to define the data type. The type on contents rule pitch throttle and your values and type 2 contains the pid constants. So it will check the first byte and then read the data accordingly. Also, i want to stream angles and run data to the python script. So i used one loop for receiving the data and next one is for translation and so on and as you can see, it seriously reduces the loop time about 2200 microseconds maximum. Then i started the drone and configured the pd tuning increase the d controller until it becomes wide Music then same to the p, constant Music, Music and set the eye controller to minimum values, and that gives me a very good result: Music.

Well, this is a very simple pid controller ill make an advanced version of the pid controller later in another video, so lets see how it flies: Music, Music, so Music. This is a very simple flight controller ill upgrade it in upcoming videos like adding gps compass autopilot. Although and a lot more things and talking about this, i have used wi fi instead of the transmitter. So, yes, it can provide unlimited range. Dont worry ill, make a dedicated video on transmitter communication, ill upload the codes and make it open source. For all of you.

https://www.youtube.com/watch?v=OMMk6xxYXTc