2014-09-21

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 !