ARDUINO MICRO QUADCOPTER
(ONGOING Project, currently need to solder the circuit)
This is Arduino based, 3D printed micro Quadcopter project for 8.5 mm diameter DC motors. However if you have some experience (or just have an hour of free time) you can adapt the design to fit to a different size motors.
I am doing this during my free time while I study in the university, thus I think it should take quite some time to finish (exams approaching!).
I decided to control the Quadcopter through Bluetooth using an Android phone/tablet. In the future I might redesign a bit to control it using Wifi or some radio communication. I will also write and publish an Android App for the control using bluetooth.
So lets get it started@!
P.S. The robot is dedicated for M.O.N.T.E. (Mobile Omnidirectional Neutralization and Termination Eradicator) killer robot from The Big Bang Theory :D
I wanted the frame to be light-weight and strong, thus decided to use a 3D printer. This also saved me loads of time. Which printer to use I'll leave up to you as I do not actually own a 3D printer myself and use the one that is in the University. The total wight of the design was around 10 - 15 g (The University didn't have any scales...) but it will vary depending on the printer and the plastic
For the design I used a free web design tool TinkerCAD, which is probably the best design tool for beginners or for smaller projects.
I added the files here so that you could go and print it right away. However if you want to look into the design from all angles then visit Thingiverse. Likewise, you can visit TinkerCAD to modify my previous design the way you like it (change the name of the Quadcopter?).
For a single quadcopter you need to print oneQuadcopter_bottom_3.stl and oneQuadcopter_top_2.stl. I tried printing everything myself and noticed that the printer I had did not print the screws very well (I could not fit the screws in the holes), so I do not even suggest printing them as well... You could of course try doing that thus I also add Quadcopter_screw_2.stl if you're curious... I redesigned the bottom part so that you could stick in the top part and then you could simply use some plastic ties to hold everything together.
Step 2: The Rest of the Parts + Price
Microcontroller
We need some small chip/microcontroller board for this Micro Quadcopter. A cheap option is to use Arduino Nano, which from China cost ~£1-2. Additionally, to lower the weight, alternatives could be Arduino Beetle or Arduino USB chip, which is a Chinese copy of original Beetle (Cheaper, works (tested) the same way and connectors are easier to solder). You could also follow this tutorial to program bare chips of ATMEL ATmega328/168, which you can get for free from ATMEL website (If you're a student go to Atmel -> samples -> order a sample) or ebay otherwise. As for prototyping I will use Arduino Nano as it is easier to deal with. I think the next stage would be either use bare metal Atmel chip or look into Arduino Beetle BLE as you can also find them cheaply in some places, however they only have 2xPWM output, thus a register shifter might have to be used in addition. The weight of each chip varies depending on the microcontroller: Arduino Micro ~13g, Arduino Beetle ~5g, bare chip + crystal ~4-5g(?).
Motors
I myself used a little more expensive motors from here. They are supposed to be a lot faster than the original Hubsan X4 motors. I plan to use custom made hardware thus I need fast motors to lift the weight. If I was to buy a new motor set now, I would most likely buy them from the same shop, however the ones which say speed: insane. There are a few types of those as well, so choose the ones with the best reviews. The difference is quite significant with speed: insane as they can reach at max 3.2 A instead of 2.75 A with speed: fast (somehow still says that thrust is 40g/motor for both motor types). For those you can't afford expensive motor, there is always an alternative from ebay or even cheaper from China. They, of course do not fly that fast, at least I assume that from performance curves. I haven't tried myself, but max current is 1.85 A and thrust is 34g/motor, which is lower than on previous motors. (Total weight ~20g)
Bluetooth
For the project I used the usual HC-06 Bluetooth module. It works as a slave only, which is what we need if we want to control it using a smart phone. As you can see from the added picture, I bent the connectors and then shortened them. I might look into an option of adding a Bluetooth 4.0 module later, which has opposite connections so then you won't need to do that. (Total weight ~5g)
MPU
For the project I used MPU6050 which I already had bought some long time ago. It has 3 axis Gyroscope and a 3 axis Accelerometer only. In later releases I might use some more expensive MPU, which would have Barometer and a Magnetometer. (Total weight ~1.4g)
Batteries
For the motors and electronics you will need two 1S 3.7V LiPo batteries. One is used to power up the motors and another only the electronics. Finding a battery for electronics is easy. Simply choose the smallest available battery on the market (e.g. 1s 3.7V 100mAh(3g)). You can also buy them from HobbyKing pretty cheaply.
Getting a battery for the motors is more tricky. There are a few important points to note when buying them, capacity (mAh), max allowed discharge (C) and average discharge rate (C). The larger the capacity, the longer the quadcopter will run on a single charge and the larger the discharge rate, the more power it will be able to provide for the motors (larger currents for constant and for peak times). There is often a rule of thumb that multiplication of both, the discharge rate and the capacity, will give the current that the batteries can supply. For example, you have a battery with 500 mAh and 10 C of average/constant discharge. 500 mAh * 10 C = 5 A. Thus on average such a battery can supply 5 A. Then add around 20 % safe margin and you should be good to go. Well, this might work in some cases, however we have extremely powerful motors, thus discharge rate MUST be a lot higher than that. I Previously tried Turnigy nano-tech 650mAh 1S 15c (13g) with absolutely no luck. They only managed to fully power a single motor and didn't even turn up 4 motors a bit, which meant that the discharge rate was simply too small (capacity surely was enough). I then looked into Turnigy nano-tech 1s 260mAh 35-70C (14g) batteries. They managed to power up all 4 motors, however at the time when I bought them they cost half the price you see here. I suggest looking into HobbyKing for similar or alternative batteries e.g. Turnigy nano-tech 300mah 1S 45~90C (9g) or even Turnigy Graphene 600mAh 1S 65C (15g) which seem to be very promising. If you have a few $/£ extra, buy Graphene batteries as they are lighter when compared to alternative batteries with the same capacity and provide a lot higher discharge rates (at least on the paper). I didn't try them myself but would be really interesting to see how they compare in reality as I think the currently provided 35C discharge rate is a bit smallish as well.
Let's calculate how long the batteries will last. Lets say that apart from the motors the rest of electronics uses around 100 mA of current constantly. Total current = 2.75 * 4 + 0.1 = 11.1 A = 11.1 * 1000 = 11100 mAh. The batteries I bought have capacity of 260mAh, thus Time (min) = 260 * 60 / 11100 = 1.4 min. Doesn't seem a lot at all does it? I tested when I attached the quadcopter with the threads to the ground and it seems like the numbers are reasonable, I really couldn't hold the quadcopter in the air even 2min. Well, for longer flight rates you will have to either add bigger batteries, use cheaper Hubsan X4 motors or somehow lower the weight of the whole thing. (Total weight ~16 g)
Motor Connectors
The motors usually use mini JST type connectors, thus you would need to get some (4 pcs) from either Farnell or ebay to be able to connect the motors to the whole circuit. Make sure you buy the connectors as the ones in the image. There are very similar ones (e.g. micro JST), however they ARE different.
Battery Connectors
Many of the batteries from ebay and HobbyKing use micro JST connectors. The charger I used (given in later sections) has a slightly different JST connector (I know, a bit confusing as al of them have the same name), so I decided to order some of these from ebay and solder them on every battery instead. This also allowed later nicely connecting the battery to the PCB.
Propellers
Many of you might want to use Hubsan X4 propellers and you can do that if you want to, however I will use Walkera LadyBird props. They are a little pricey if you buy them in UK (around 5 times more when comparing with original Hubsan X4 props), however really cheap from China. If you yet do not have props, then I would recommend using them either - if I am correct, I read somewhere that they provide more thrust, thus giving our little beast more speed (Well, after all, Walkera LadyBird is known to be the best micro quadcopter up to date! I wonder who tested that but lets just trust them for now...) (A few grams in total ~3-5g)
Transistors
We need 4x MOSFET transistors and choosing one might be tricky. Firstly, they need to withstand the used power and current by the motors and secondly, the threshold voltage has to be quite low, otherwise Arduino won't be able to turn them ON fully (in the case of N-type MOSFET). In my case the max current is 2.75 A with voltage of 3.7 V. This means I need a MOSFET, which would at least withstand around 4 - 5 A just in case (will also heat up less). I ordered some from Farnell (MOSFET Transistor, N Channel, 6 A, 20 V) but you are free to look into alternatives such as MOSFET Transistor, N Channel, 8 A, 20 V (these are actually identical to the previous ones but they have additional legs to be soldered to ground to work as a heat-sink. This isn't needed as previous ones didn't heat up at all). Both of them had threshold voltages of 600mV, which is good. If you are to look for alternatives, try not to go more than 1V, but also if you want to use the provided PCB, make sure the sizing is the same, plus the given transistors in here already have a free-wheeling diodes inside thus will save some space on the PCB. (Total weight <1g).
Resistors
For the project I needed a 6x10 kOhm and 2x56 kOhm resistors (to be decided, but this is not needed until the end), which you can find in any electronics shop. (Total weight <1g)
Capacitors
A single electrolytic capacitor will be used to smooth the voltage on the battery used for mottors of size 47uF, 50V. It can be bought at any electronics shop. (Total weight <1g)
Charger
You might already have a good chargers, however in case you don't you can always get something like this. It uses JST type connectors, thus you will have to get the connectors mentioned before. Alternatively you could get a chip based charger module like this. This might be useful in later projects as the chip can become part of the circuit in that case.
Price
Probably many of you would like to know the price of the thingy. Well, lets just calculate that using some rough calculations as the price will depend on the supplier:
Expensive motors:
Expensive motors:
£2 (Arduino) + £3 (MPU6050) + £20 (Motors) + £3 (Motor Battery) + £2 (Electronics Battery) + £2 (Propellers) + £2 (MOSFETs) + £5 (HC-06) + £2 (The rest of electronics + plastic) + £1 (Connectors) + £3 (Charger) = £45 (adding only the used components, when they are bought in multiples)
Cheap Motors:
£45 - £15 = £30
Conclusions:
Overall price is not that big and if you have the connectors and the charger, it will decrease significantly! Using very fast motor implementation I managed to fit into £50 price range if all the parts had to be bought.
Step 3: Weight Calculations
Expensive motors:
For our quadcopter to fly nicely there is a rule of thumb that 50 % of the max thrust of motors should be equal to the weight of the quadcopter itself. Thus meaning that the quadcopter will be in the constant height when giving 50% of its full power. The motors that I bought have 40g/motor of thrust. In total that adds up to 160g. 50% of that is 80g. Now lets add up all of the electronics + the frame:
15g (frame) + 20g (motors) + 23g (battery) + 5g (bluetooth module) + 5g (microcontroller) + 1.4g (MPU) + 2g (transistors) + 1g (diodes) + 1g (resistors) = 73.4g, which is more or less what we need! Of course there will be some additional weight from wires, etc. but they are small and at most it will increase the weight until 75g, which is still 6% lighter than what we could afford.
Cheap motors:
Total thrust from motors is 4 * 34g/motor = 136g. 50% of that is 68g. Total electronics will be more or less the same, just the battery will be 10g lighter, giving around 65g in total with everything, which is still lighter than 50% of the thrust! Actually, it will not fly as good as with faster motors, but oh well, you are using at least 4 times cheaper motors!
Conclusion:
The quadcopter should fly! With more expensive motors it will fly better/faster, but yet still both quadcopter should fly.
Step 4: Circuit Diagram
I left the previous circuit using Arduino Beetle but also added Arduino nano connections. Most of the things should be the same just using Beetle I found several problems. Firstly, there is not enough of dedicated pins. So for example some PWM pins are being used as I2C, therefore it is difficult to decide which of the connections should be fixed using code and which using the provided pins. Also I only had an option of making a single sided PCB, thus it was difficult to make connections for Beetle board. I ended up using Arduino nano.
Arduino nano has a two-battery solution and Beetle doesn't. This is very important as Bluetooth won't work using a single battery. Additionally, if Beetle board is used, using two batteries, another >10uF capacitor should be added between positive and negative pins.
At the bottom of Arduino nano circuit I added the alternative connections for the transistor which was being used for the PCB instead of the one making connections.
Step 5: PCB
It is a lot easier to solder all the components on an already prepared PCB (Printed Circuit Board). Sadly, getting an access to a machine to make one is not always possible. We had one at the University, thus I designed a PCB using Target 3001! Software. To open the *.T3001 file you will have to download Target 3001 software, which is sadly, only Windows compatible. I might export the project to Eagle later. Adding Target3001, .xps, .tif and .src (export to Eagle) for those who intend to make a PCB at home.
The printed and soldered result looks as in the provided image. I added red circles showing the soldered transistors, yellow circles showing the JST connectors for the motors, green circle marking the battery connectors, supplying power to the motor ONLY, and blue circle marking the battery connectors, supplying the power to the rest of the electronics (Arduino, MPU6050, etc.). As you can see, there is some fixes made next to both of the power connectors. You don't need to do that as the PCB was updated after making the first working model. Basically, the problem was that at first the PCB only had a single power supply. During the testing it appeared that the Bluetooth module kept constantly disconnecting from the phone as the battery voltage was dropping to low levels (< 3V). Not only that but Arduino also had issues with that, which were fixed by lowering brownout voltage. You can do that easily yourself as it only required modifying a single file in the Arduino IDE, however it is more of a hack as the higher the frequency, the higher voltage is needed. In the end, something else might break in the future or you might loose all available power, etc. Anyway, implementing two-battery system worked nicely, especially that the battery, powering electronics weight only around 3g.
When soldering on the motor connectors, make sure that they are soldered the correct way! On each side one of the connector is facing one way and another another way. Either check which is positive, which is negative or connect motors prior to soldering and solder according to the image (red/white wire colour is positive and black/blue is negative terminals)
On the other side of the PCB I added a green square showing the not compulsory 1x02 connectors. I thought it would be nice to be able to connect something to the quadcopter in the future thus I made available PWM and Analogue pins easily accessible. I additionally marked the positive connector on both batteries.
Step 6: Code
I wrote a library and an example program using mbed for a quadcopter which you can find in here. Mbed is a lot faster than Arduino and it has more memory thus it could be used for larger quadcopter. In here I adapted everything to Arduino, plus used the available libraries.
Reading Battery Voltage
As a reference point Arduino uses the power supply voltage, thus if we connected two resistors in series between the power and ground and read the voltage in the middle, it would always be constant. In here we use a two-battery system, thus there are two approaches for reading the voltage on motor battery.
1) We can always keep the battery, powering electronics charged. This means that we always ensure that the voltage on it is around 4.2V. This approach would require charging both of the batteries all the time. Additionally, what would happen if we also wanted to monitor the electronics battery?
2) Use interval voltage reference. This is equal to 1.1V on Atmega328, however we then need to ensure that whatever is connected to A0, doesn't go more than 1.1V. Therefore I added X kOhm resistor in series with Y kOhm resistor to create a potential divider circuit. The code for reading and smoothing the battery voltage is:
#define ALPHA 0.1 #define MULTIPLIER 6.67 float motorBattery; void setup () { pinMode(A0, INPUT); analogReference(INTERNAL); // Set internal reference source of 1.1V // float tmp = analogRead(A0) / 1023.0 * MULTIPLIER; // make units Voltage motorBattery = 5.0; } void loop () { motorBattery = smoothBattery(motorBattery, analogRead(A0) / 1023.0 * MULTIPLIER, ALPHA); } float smoothBattery (float prevEntry, float newEntry, float alpha) { return (1-alpha) * prevEntry + alpha * newEntry; }
MPU6050
MPU6050 library is available by Jeff Rowberg 2012. The provided example code MPU6050_DMP6 is used as the main code for the project.
If you decided to use my frame & motors, most likely you won't need to modify the code any more as the PID controller was already set for more or less good performance. However if you use a different frame, you will need to set new values for the PID controller. It takes quite some time if you're doing it for the first time.
Stabilising Motors
In the control systems a PID controller is a very popular way to stabilise the system. In here we will want to stabilise the pitch and roll of MPU6050. I used library PID_v1 for this purpose. In the code given below I will setup both motors and PID controller. I will then add a function to stabilise the motors depending on the required speed.
#define FL_MOTOR 3 #define FR_MOTOR 9 #define BR_MOTOR 10 #define BL_MOTOR 11 //---------------------------------PID------------------------------------ //Define Variables we'll be connecting to double rollSetpoint, rollInput, rollOutput; double pitchSetpoint, pitchInput, pitchOutput; //Define the aggressive and conservative Tuning Parameters<br>double consKp = 1, consKi = 0.05, consKd = 0.25; PID pitchPID(&rollInput, &rollOutput, &rollSetpoint, consKp, consKi, consKd, DIRECT); PID rollPID(&pitchInput, &pitchOutput, &pitchSetpoint, consKp, consKi, consKd, DIRECT); void setup() { //------------------------------PID---------------------------------- pitchInput = 0.0; rollInput = 0.0; pitchSetpoint = 0.0; rollSetpoint = 0.0; //turn the PID on pitchPID.SetMode(AUTOMATIC); rollPID.SetMode(AUTOMATIC); pitchPID.SetOutputLimits(-20, 20); rollPID.SetOutputLimits(-20, 20); //------------------------------------------------------------------- for (int i = 0; i < 4; i++) { targetSpeed[i] = 0; } pinMode(FL_MOTOR, OUTPUT); pinMode(FR_MOTOR, OUTPUT); pinMode(BR_MOTOR, OUTPUT); pinMode(BL_MOTOR, OUTPUT); void loop() { pitchPID.Compute(); rollPID.Compute(); int actSpeed[4]; stabilise (targetSpeed, actSpeed, rollOutput, pitchOutput); // targetSpeed = actSpeed; // should this be here or not } void stabilise (int* currSpeed, int* actSpeed, float rollDiff, float pitchDiff) { //actual Speed is calculated as follows +- half rollDiff +- half pitchDiff actSpeed[0] = (int) currSpeed[0] + (rollDiff / 2) - (pitchDiff / 2); actSpeed[1] = (int) currSpeed[1] + (rollDiff / 2) + (pitchDiff / 2); actSpeed[2] = (int) currSpeed[2] - (rollDiff / 2) + (pitchDiff / 2); actSpeed[3] = (int) currSpeed[3] - (rollDiff / 2) - (pitchDiff / 2); for (int i = 0; i < 4; i ++) { if (actSpeed[i] < 0) actSpeed[i] = 0; } } void runIndividual (int* actSpeed) { analogWrite(FL_MOTOR, actSpeed[0]); analogWrite(FR_MOTOR, actSpeed[1]); analogWrite(BR_MOTOR, actSpeed[2]); analogWrite(BL_MOTOR, actSpeed[3]); }
Bluetooth Module
Communication from the quadcopter to the phone will be through HC-06 Bluetooth module. The good thing about it is that there is no need to hack anything around as the module uses serial RS232 communication to talk to Arduino, thus you will use it identically the same way as you would Arduino Serial library. For this purpose you will need Arduino SoftwareSerial library. In the code given below I will send the speed which is to be set for all of the motors.
SoftwareSerial mySerial (7, 8); //RX, TX void setup() { mySerial.begin(9600); } void loop () { if (mySerial.available()) { myReading = mySerial.parseInt(); for (int i = 0; i < 4; i++) { targetSpeed[i] = myReading; } //flushing anything that wasn't read while (mySerial.available()) mySerial.read(); } }
Adding Bits Together
As for the whole code, I am always working on it, so I decided not to add it here. You can find the latest version of code in GitHub. I will notify in this Instructable when the code is finished. At the moment I need to setup correct PID constants...
No comments:
Post a Comment