Making a flight controller

Started by clickdelete, September 16, 2016, 09:02:02 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

clickdelete

Greetings to one and all . I am new to this forum and to RC flying in general and this is my first post. I have never owned any serious RC equipment so far. But I have been an Arduino enthusiast for the past few years and have made a couple of Remote controlled things using blue tooth radios and X-bees.

While fiddling around with an idea of making an RC buggy I felt why not try to make something which flies and the first thing which came to my mind was a Quadcopter. But then I realised that equipments required to make one comes at a cost.

I did not have a transmitter or a receiver. All flight controllers I came across required an RC Rx and Tx.  So I decided to make my own flight controller from an Arduino Mega.

The mode of control was chosen to be blue tooth. Yes I agree with most of you out there that it has a very low range but my initial copter is not expected to go beyond a basketball court below my building. 

One major advantage it had as far as my building abilities go was that I was conversant with blue tooth controls as I have already used it in some of my previous builds.  And yes it eliminates the requirement to have a transmitter. Almost all android phones have built in Bluetooth and I have used my phone as transmitter for the Quad.


A blue tooth receiver HC-05 is damn cheap and comes for around 250 Bucks. Considering all the advantages I was more than willing to sacrifice the range considering that the only place I have to fly it is a basketball court.



My first goal was to achieve a stable take off without toppling which I have achieved today after almost 25 crashes, multitude of code revisions, 65 days and 4 sets of broken propellers.  For stabilisation I chose an MPU6050 6 axis IMU. But so far I have only used the gyros to measure the rate of turn. I want to add an auto levelling mode at a later stage and will also utilise the accelerometers to calculate the angle of turn.


Since I am new to the black art of stabilising Quadcopters i wanted to make things simple to start with and further complicate it later. For the motors and ESCs i ordered from ebay and got a package delivered which consisted of 4 unbranded A2212, 13T, 1000 KV motors and four unbranded red coloured ESCs which only had one thing written on them “Simon 30A” .

With a lot of reference from the internet about the physics of Quadcopter stability and implementation of PID controls with particular reference to videos provided under the name YMFC 3D I was able to develop a not so inefficient code which had a loop time of 4 milliseconds. Ie, I could provide a refresh rate of 250Hz to the ESCs.



I chose 250 Hz because i read in one of the references that almost all quad ESCs operate at refresh frequencies above 250 Hz. Most of the advanced ESCs can even operate at 8Khz. Since i didn’t know the exact refresh rate of my red unbranded ESC i stuck to the value it will definitely support. Aso a loop time of 4 milli seconds was not hard to achieve on the Arduino mega. I’ll upload a pic of the Esc in my post so that someone can identify the brand and possibly indicate a data sheet which describes the refresh rate. Any how with 250 hz it stabilises pretty decent in the Pitch and roll axis.



Presently my transmitter has only one channel and that is for throttle. I have made an android app which will communicate with the HC 05 blue tooth receiver through simple serial communication.


The app consists of only two items. One button to connect to the Bluetooth receiver and one slider, which will transmit the throttle value. (750 for stopped and 2000 for full speed) When the receiver gets these throttle  numbers it generates PWM for each ESC input and supplies this PWM through 04 digital pins of the Mega.

The onboard gyro senses the pitch and roll and provides this to the mega via  I2C and the code alters the throttle pulse widths going to the corresponding motors. That is, if the quad copter rolls to left , the gyro senses a negative rate of roll.


This value is provided to the roll axis PID controller. The out put of the PID controller is used as Roll motor correction. So in this example the motor correction is added to the left motor throttle value and subtracted from the right motor throttle value. The left motor speed increases and the right motor speed decreases there by correcting the roll to the left which kick started the whole business.
With only the throttle control from my android device, presently i can only move the quad skywards. Since the PID constants are not fine tuned the quad moves upwards and veers left/right. Since I do not have a yaw PID running , it does slowly spin in the Yaw axis too.  These are the things I look forward to fixing in the forth coming days.  Will keep all of you updated on the progress and  ill be glad to help someone who is trying to develop a flight controller with whatever i know presently. My controller is in a very nascent stage but it is showing promise.

My ultimate aim is to make Quadcopter building affordable to the common man. No expensive tx/Rx/Controller.  Infact once I settle down to a decent controller code I intend to jump from brushless motors to coreless DC motors which are priced way lesser than esc /BLDC combos. I can use a ULN2003 and driver for 4 motors and the whole Motor and driver package can reduce in price many fold. But those are for later, i shouldn’t count chickens before they hatch.


I am attaching a video of my Quad with only throttle control and PID control on Pitch and Yaw alone.

Cheers
Clickdelete

saikat

I can see that you are enthusiastic .....

welcome to the forum .... may your quest be succesfull !


little advice ,... your post is too long and no para spacing , very few will have the inclination to read.


summarize and simplify ....

Balakrishna Reddy

Your work is good and instead of using Arduino mega you can use uno to save space and money which is you goal.

However i would rather suggest to go with Atmel studio rather arduino ide because its libraries take up more space and are also slow.
As you have mentioned the frequency of operation as 250. The point here in ESC is the PWM operating frequency. You can have higher PWM operating frequecies at that loop time by carefully choosing prescaler. But that is no problem everything works as usual.
But generally PWM frequency must be higher than refresh rate.

clickdelete

@saikat , point taken. Wilco henceforth.
@balakrishna reddy. Totally agree with you regarding kiting out the mega for a no.in fact I'm pro for a mini pro too.. I'm using the mega because of the multiple serial ports . Since my Bluetooth requires one serial port and I needed another for de bugging I chose the mega. Software serial interferes with servo library.

But anyways now I'm no longer using the servo library for PWM.

I read about prescalers to change pwm frequency but later decided to use direct port access to switch on and off four digital pins to generate own with code. One of the sites I referred to was praising this method and proved on oscilloscope that it's pretty fast avoiding the overheads caused by servo.writemicroseconds


I guess refresh rate of esc should be greater than loop time / loop frequency so that result of calculations of each loop reaches the esc and esc acts upon it. This way we ensure that no loop calculations go unattended and therefore crisp response. There is an article by Oscar Lang on this topic which I found pretty amazing.

In case of my esc I'm assuming that it's refresh rate is already 250 hz . So it will be awaiting one signal pulse every 4000 microseconds.  So my code provides a pulse every 4000 microseconds. If I later find that the esc can work at 300 hz I'll accordingly reduce my loop time to provide signals to the esc at that rate.

Atmel studio I haven't used yet. Will try out. But I'm in love with some library fun times of arduino , he he.



clickdelete

over the week end i revised the code again and made two mods which seems to have greatly improved the stability. due to excessive rains here in mumbai , i did not get much chance to do an extensive flight test. however a short trial video is attached. the mods i did are as follows.


i) Cascaded PID : The stabilisation algorithm now consists of two loops in each roll and pitch . The outer loop consist of an angle PID. ie the setpoint is zero degrees and the input is actual tilt angle measured in degrees. The out put of this calculation is used as set point of the inner loop PID which is a rate PID. ie, it measures the rate of turn and uses it as input. the output of the rate PIDs is finally used for motor correction. I tried using only angle PID however it was much more unstable than the Rate PID i was using earlier. This cascaded PID seems to be the best choice so far. the best part is that in the video below im using only the Propotional component of the PID. constants for Derivative and Integral are still zero. Without them the quad stabilises quite well but will be required once i add steering controls in my code.

ii) Additional Yaw PID. Those of you who saw the previous video must have seen that the quad keeps rotating in yaw axis. This was because i had no PID running on yaw axis. I added a single stage rate PID on yaw axis and that rotation has stopped now.


ill post a longer video when there is light and when the weather clears up

cheers





Voice of deaf

Those are unbranded escs
You can flash simonK
The mcu is atmega8l
Born for FPV, Forced to LOS.

Voice of deaf

I think thema x frequency for the stock firmware  is 400 hz
Born for FPV, Forced to LOS.