2014-09-21

DIY drone - tutorial for developers | Part 10 - Preflight checkups and maiden flight !

Before putting the props on, you have to calibrate the accelerometers.

Find a quiet and flat place to put your quadcopter on.

Fire up ez gui, connect it and go to the calibration menu.


And click AccCalibration...


Once it is done (it takes a few seconds), arm your quadcopter (still with no props) and put a little bit of throttle.

Then tilt it towards one motor putting your ear against it.

Everytime a motor is lower than the other ones it should accelerate by itself (this is how the quad stabilizes it by itself). Check the 4 motors one by one then 2 by 2.

Now that you are quite sure it won't do something crazy, put the props on !

Look carefully at the profile of the props to be sure you make them push air downwards !

-> / ->  or <- \ <-

Also try to put a different color for the front ones so you can spot the front of the quad easily in flight.

Now you still need to do some sanity/preflight checks :
  1. put it on the floor, outside, far away from anything alive, preferably on something soft as it might flip over.
  2. put the minimum of throttle possible to make the motor turn
  3. try slowly the 4 directions with your right stick to see if the right (opposite) side of the quad is lifting up and stop once you have determined that it is all OK.
You are ready, like the initial flight lesson of part 2, just hop vertically a few times to get the feeling around the new weight and throttle sensitivity and continue from there.

Next up, we will add some add ons to your quadcopter : bluetooth/screen, GPS !

DIY drone - tutorial for developers | Part 9 - Calibrating your ESCs and fix the throttle

Connect your ESCs to the FC.

Again, be careful and connect the signal wires (white) on the inside.

You should use 2, 3, 5, and 6.


They should match those numbers for the motors :


** do not mount any propeller on the motors **
I don't say that because I consider you a 5 yo but because the motors might go full throttle during the calibration if the ESC doesn't catch up the calibration signal and really hurt you. It happened to me with the propellers off so it happens don't do it.

Go to your config.h, uncomment the symbol : ESC_CALIB_CANNOT_FLY (here)

Build and flash.

Disconnect all power (USB / battery) then connect the battery.

The 4 ESCs should make a triple beep, then a long beep. Done, your ESCs are calibrated for the inputs the FC will give them. Disconnect the battery.

Rebuild a normal firmware (with the ESC_CALIB_CANNOT_FLY commented out), and reflash.

Reconnect the battery.

Now you need to learn how to arm / disarm your quadcopter.

There is a security to prevent you from accidentally powering up your quadcopter.

You can arm your quadcopter doing this :



You should see the leds A and C on the FC switching to solid ON.

Now you should be able to play with the throttle on your TX and see how it reacts (still props off).

Ideally the motors should be off at minimum throttle and start off slowly once you push it up.

Once you want to check out a setting or do something else, don't forget to disarm it :


The leds A and C should be off when it is disarmed.

A last settings you need to fiddle with is the MIN_THROTTLE and MIN_COMMAND.

This is in the Misc Menu and/or config.h :


Note: here there is a trick you have to click to the upload arrow once you have change anything otherwise it won't be taken into account (yeah it took me 3 or 4 tries to figure that out !)


Remember the motors are actually compatible with the input from the RX. But here you can change the RX values Multiwii will emulate for you.

The motors won't run if the throttle is too low, to preserve a full resolution you need to find the minimum value of MinThrottle that you can have where the motors will start to rotate when you just started to push the throttle. Try to dychotomize it to its perfect value.

MinCommand is the level Multiwii will send to the ESC when you disarm it. It has to be a safe value you are sure no motor will rotate.

You are almost ready to fly your quadcopter !

DIY drone - tutorial for developers | Part 8 - Hooking up the FC

Testing out the receiver (RX) with the flight controller (FC)


Let's connect the RX to the FC and test it out like that.

First upload the firmware to the FC, then leaving the USB cable plugged in you can actually power up the FC and try to see if the RX works with it.

Here is the cabling detail :



Some explanations
First the RX needs to be powered this time, by the FC.
The red and black wires are connected to the 2 first pins : 5V and GND on the FC
They connect on the RX side to the BATT +- (it is not obvious to see from the marking, check out the picture).

Then, you'll need to connect the signal lines for the channel (do you remember from the previous parts, the internal ones), to the correct channels on the FC.

There is some terminology translation from the plane jargon to the helicopter jargon to do :

ELEV (elevator) connects to PITCH on the FC
AILE (ailerons) connects to ROLL
THRO (throttle) connects to THROTTLE
RUDD (rudder) connects to YAW

4 channels + 2 power = 6 wires.

Now fire up multiwii GUI or, like I prefer, use an OTG cable and connect your FC to your android phone and use this app.

Pair your RX with your TX.

Go to the Config Tab of Ez-Gui and set it up to connect through USB like this :



On the Ez-Gui click MW Connect (at the top) then once it has done that successfully, click Radio from the main menu :


You should see this screen :


Check if the commands are moving the same way you are moving them on your controller.

If they are reversed, setup the channel reversed on your controller.
On the Devo 10 you need to :

Press ENT to enter in the menu ...



then ENT again to enter in Function ...


then ENT again to enter in Reverse switch ...


then UP/DN to select the channel and R/L to change them ...

I had to put Reverse for Aileron and Rudder.

(to exit the menus press EXT)

Now in the RC world, the input are normalized between 1000 and 2000.

Try to adjust, in the similar fashion, Travel Adjust so all your sticks shows ariund 1000 at their minimum and 2000 at their maximum.

For this I had to set them up at around 125% and for one channel it did not have any effect. Try to make it as good as possible.

Then it is time to put it all together and make the ESC final calibration

DIY drone - tutorial for developers | Part 7 - Motors + ESCs setup and test

Charging up a battery

It is a 3S which means 3 elements of 3.7 volts adding up to 11.1v.
When you'll charge it up through the little connector, you'll see that the charger will show you the state of those 3 sub-batteries one by one and charge them up :


Then it will show the total charge: 


Note: don't put that to charge during the night and forget it, it will beep like crazy at the end of the charge.

Trying your motors directly 

What you need to understand is that your RX (receiver) and ESCs are originally made to work directly together in the classical RC world.

So you can try them out !

Here is the overview :


Always start with no power and connect the battery at the very end !
  1. connect the 3 outputs of the ESC to a motor
  2. connect the ESC to the RX. Be careful, the signal wire (white) on the inside.
    like this :



It is connected on the THRO (throttle) input. The ESC will power the RX.
Be sure your TX throttle is at 0.

Check the polarity of the ESC power, connect black with black, CHECK IT AGAIN OR IT MIGHT BLOW UP AT YOUR FACE IF YOU DON'T. Connect black with black, CHECK AGAIN.
Connect red with red.

You'll hear your ESC beeping, it is normal as they initialize then wonder why they have no input.

Switch on your TX.

The RX should stop blinking, telling you that it paired correctly with the TX.

Play with the throttle to see if the ESC and Motor work correctly.

Take this opportunity to be sure you are in this configuration :



If a motor is reversed, don't panic, swap 2 of the 3 outputs from the ESC and it should start to turn to the other side.

Check your 4 motors and ESC to be sure everything is fine before complicating the system.

Now the ESCs are for anything : cars, boats, propeller hats etc... they are not tuned by default to be for a quadcopter.

Instead of your RX, connect one to the ESC programming card THEN power it up.
Again, be extra careful about all the polarities : be sure that you have connected the signal wire on the right side on the programming card.

The card will switch the ESC into programming mode and will show the factory parameters they have, mine arrived like this :



Play with the little controls at the bottom until it looks like that :


And press ok to push the configuration.

That 4 times, don't be impatient otherwise you'll fry something.

Once everything is tested, you can attach your ESC to the arms of the frame (underneath is better to leave some clearance to the propellers) :


then mount the power bus on the frame. I opened up the bottom and enclosed the power bus inside :



You can then do an integration test with the power bus : 
(hooking the RX to the ESC one by one)


Check the conductivity everywhere between different points of the power bus before that with your multimeter, also check if there is absolutely no conductivity between reds and blacks.

The low level stuff is done, let's take care of the mid level stuff, the flight controller (FC).

DIY drone - tutorial for developers | Part 6 - Mechanical assembly

The frame itself is quite obvious to mount as its documentation is quite clear.

But the motor assembly is not.

Here is the end result.


- use the carbon fiber mounting plate and mount the motor bottom first with the small philips screw. Just flat on it, nothing fancy.
- mount the motor + mounting plate on the frame with the 3 small TORX screws.

Here you can mount the wires either to the left or the right, I suggest to take a convention to show to which side the motor should turn. Look at this view as a reference (from the multiwii site) :





Then mount the axis (from the mounting kit) on the top of the motor with 3 TORX screws (again) but be careful they might be a little bit different from the frame ones.

Like this :



Then the little support for the propeller (from the mounting kit too).

Like this :


Then you need to pick the propeller adaptor which fits the best the axle (from the propeller package this time).

Like this :

And finally you'll put the cone at the top (from the mounting kit).



Now let's power up those motors !

DIY drone - tutorial for developers | Part 5 - Assembling the power components

Here is an overview of what we gonna need to do:


The convention is always the same to avoid shorting cable:  anything with live power is female, everything slave of those is male.

From the bottom to up :

  1. the battery (female) will be hooked to the main power bus (male)
  2. the power bus will be split in parallel in 4 other connectors like the battery had (female) and hooked to the ESC (male)
  3. The ESCs doubles as BECs so have 3 functions :
    - the first one is to take this power (male connectors) and modulate it in a way that drives the brushless motors through the 3 motor connectors (female)
    - the second one is to transform this 12v power to 5v and output it on the small female connectors
    - the third one is to interpret the amplitude from the third signal pin of those small 3-pin female connector (here it is white) and apply it to the motors 


Here is my intermediate step for the power bus :


I used the inside of those household connectors to do that :

Then I soldered those 2 by 2 : 2 blacks with 2 blacks, 2 reds with 2 reds.

And soldered the input from the battery on top of them (you'll need to heat the thing quite high to be sure it is correctly soldered).

Some shaterton to secure each side, soldered the connectors and added the shrink tubing.

Tip to solder those connectors : holding them with the pliers, fill them up first then reheat them up and plug the wire in and wait a bit that the melted metal goes it the wire by capilarity.
  

Same thing for the connectors on the ESCs, on the power side male connectors, on the motor side female.
You might wonder why the 3 wires on the motor side are all red. It is because they are basically all the same. The order of their connections to the motor will only determine if the motor will turn clockwise or counter clockwise.

Jargon : CW = clockwise CCW = counter clockwise.



DIY drone - tutorial for developers | Part 4 - Dev environment

Development environment

Ha, finally the easy part ;)

Toolchain 

The FC is programmed like an arduino so you'll need the arduino toolchain.

On linux Arch for example it means you need to install :
community/avr-binutils
community/avr-gcc
community/avr-libc
community/avrdude


Source Code

No need to use the java UI with sketches etc ... I have adapted a cmake environment to compile Multiwii. This is the onboard flying software we gonna use.

git clone https://github.com/gbin/multiwii-cmake.git
cd multiwii-cmake

Here you'll find :
cmake : a plugin for cmake to compile arduino stuff
src :  a mirror of multiwii
CMakeLists.txt : the source file for cmake to make a Makefile

The branch master is a vanilla multiwii but the branch gbin-quad has a config tuned for the components of this tutorial.

Edit src/config.h and adapt it with the basic components. Start with something minimal, don't try to make your GPS work on the first flight.


Compile it

One shot operation : generate the Makefile
mkdir build
cd build
cmake ..

Then to compile it :
make

This should generate a file called quad.hex in the build/src/ directory. This is a string version of the firmware you'll need to flash to the FC. Yeah it looks like a weird hexdump but this is the one you need to use.


Flash it

One shot operation: make you a couple of handy shortcuts 
> cat mw_backup
avrdude -v -c wiring -p ATmega2560 -P /dev/ttyUSB0 -b 115200 -U flash:r:flash_backup.hex:i

This will backup whatever you currently have flashed (it is also a good test that your toolchain can talk to the controller without touching anything yet)

> cat mw_flash    
avrdude -v -D -p ATmega2560 -c wiring -P /dev/ttyUSB0 -b 115200 -U flash:w:$1:i

This will flash the .hex file you give as parameter. chmod 755 them and put them in your path somewhere.

Flashing operation:
connect the FC only by the USB port, then from the root
mw_flash build/src/quad.hex

This is physically doing some magic knocking on the serial interface through the USB port to ask the controller to reboot then push the file through it when it is in programming mode just after reboot.

The parts finally arrived ? Let's start assembling it !

DIY drone - tutorial for developers | Part 3 - Ordering the parts

I used hobbyking.com but I am not affiliated with them in any way, you can take this as the baseline of stuff that work together

The order is very budget constrained but espect to spend at least $400-500 just on RC parts.

Frame




Hobbyking SK450 Glass Fiber Quadcopter Frame 450mm

Rationale : This is a pretty solid and standard frame.


Motors and their mounting kits




4x NTM Prop Drive Series 28-30S 900kv / 270w (short shaft version)
4x NTM Prop Drive 28 Series Accessory Pack
Rationale : you'll need something around 1000kv, that can lift between 1.5 and 2x the weight of the quadcopter.


Electronic Speed Controllers


... and something to program them (more like tuning them in reality)

Jargon:
ESC = Electronic Speed Controller
BEC = Battery Eliminator Circuit (This is included in this same device, I'll explain later what it exactly means)



4x TURNIGY Plush 30amp Speed Controller
1x TURNIGY BESC Programming Card

Rationale: this is a slightly overkill (30A) but it provides us some security in case of electrical FUs. For example I reverted their polarity once, the battery almost exploded on me but they stayed alive.

Propellers


2 sets of different rotations and different colors are recommended


10x4.5 SF Props 2pc Standard Rotation/2 pc RH Rotation (Red)
10x4.5 SF Props 2pc Standard Rotation/2 pc RH Rotation (Flouro Yellow)

Rationale:  this needs to be a combination that works well with the motors, the weight, it can also influence the stability of the quad.

The Flight Controller


RC Jargon :
FC = Flight Controller
AIO = All In One

Multiwii and Megapirate AIO Flight Controller w/FTDI (ATmega 2560) V2.0

Rationale: this packs a lot of goodies that simplifies your life, the main ones are 
- Arduino based (this is a very standard and simple toolchain)
- USB : basically this allows you to connect, program directly from the mini usb port.
- FTDI : this is a serial port, the one behind the USB port is exposed (so you can use one or the other)
- Accelerometer : to stabilize itself and find where "down" is.
- Gyroscopes : to tell if it is currently rotating
- Barometer : so it can calculate by itself its altitude from the air pressure

Batteries 


+ something to hold them securely and something to charge them.
Note: you will need a separate 12V power source for the charger, a multipurpose wall charger should do it.



2x Turnigy 2200mAh 3S 40C Lipo Pack
1x Hobbyking® DC-4S Balance Charger & Cell Checker 30w 2s~4s
1x Turnigy Battery Strap 330mm

Rationale : something cheap that works with it.

Radio



Be sure to take one with the receiver that goes with it.

RC jargon : 
TX = Radio
RX = Receiver



1x Walkera Devo 10
1x RX1002

Rationale: You want some room for expansion : 10 means 10 channels with 4 already used with throttle, yaw, roll, pitch. More on this jargon later.

Wires and connectors







2x HXT 3.5mm Gold Connector
1x XT60 Female w/ 12AWG Silicon Wire 10cm (5pcs/bag)
1x Turnigy Pure-Silicone Wire 12AWG (1mtr) (blue or black)
1x Turnigy Pure-Silicone Wire 12AWG (1mtr) Red

Some other stuff you'll need... Nylon cable ties ... (small ones like 2.3x60mm)


I also used those household connectors :


While you are waiting for your bits and pieces, lets be prepared to program the beast.