Sergio Valverde (A96452) (valverde791@gmail.com) ======EvvGC Gimbal Controller – Software port to libopencm3====== ====Description==== The EvvGC Gimbal Controller is a board that uses a STM32F103RC and an IMU to control brushless motors, in order to stabilize in 3-axis the desired objects. Its development has been open-sourced for the most part, but the development started on Microsoft Windows and the controllers’ code uses peripheral libraries with dubious open-source status. The EvvGC is lightweight, small and with great performance (according to users’ experience); it is well suited for quadcopter gimbals. ====Justification==== In order to make it fully functional for the ARCOS-Lab of the School of Electrical Engineering, the EvvGC needs to be ported to a complete open-source environment. That means that libopencm3 libraries will occupy the current place of the ST Peripherals libraries in the control software and that code will be built and flashed from GNU/Linux. ====Objectives==== ===General objective=== * Create complete open-source control software and development for EvvGC Gimbal Controller. ===Specific objectives=== ==First stage== • Build and flash code for the EvvGC, in Microsoft Windows. • Study the GNU/Linux development environment for STM32 microcontrollers. ==Second stage== • Build and flash code for the EvvGC, in GNU/Linux. • Adapt EvvGC’s control software to libopencm3 peripheral libraries. ====Contents==== ===EvvGC=== EvvGC is a 3-axis gimbal controller board, designed in an open-source environment to work with brushless motors. It is based on the STM32 (high processing power, even for complex algorithms, and with many peripherals available) and MPU6050, with components widely available on eBay, Farnell and other international stores. Code was initially written with KEIL but it was ported to Eclipse, all in Windows. ===Windows Experience=== Following the instructions from the github of the EvvGC project (in Microsoft Windows; for reference: https://github.com/EvvGC/Firmware), got to the following problems: {{ :ie0117_proyectos_i_2014:proyecto_1:eclipse_error.jpg?nolink&600 |}} {{ :ie0117_proyectos_i_2014:proyecto_1:eclipse_console.jpg?nolink&400 |}} The problem raises from the use of the .cproject from the original author, which points to an unknown compiler when Eclipse tries to build the code. When trying to manually build the code from Windows, the built is always unsuccessful due to errors reading some header files. After several hours of debugging, the problems have not been solved. Waiting for reply of EvvGC-related forum and emails sent to people that have had similar problems. ===Build and flash code to STM32VLF4DISCOVERY=== In order to familiarize with the STM32 microcontrollers, some examples were tested with the STM32VLF4DISCOVERY. These were the steps followed. ==1. Set multiarch in your system (Ubuntu has multiarch set by default)== a. Add i386 architecture to /var/lib/dpkg/arch. dpkg --add-architecture i386 b. Modify /etc/apt/sources.list with the appropriate syntax for each source. deb [arch=amd64,i386] http://site.example.com/debian distribution c. Update the system. sudo apt-get update d. Install dependencies for the compiler. sudo apt-get install libncurses5:i386 ==2. Install libftdi1== a. Open a terminal and type the following command: sudo apt-get install libftdi1 ==3. Install openocd== a. Open a terminal and type the following command: sudo apt-get install openocd b. Check that the installation was completed accordingly by checking that directory /usr/local/share/openocd/scripts was created. c. If necessary, install manually by downloading the latest version of the software here: http://sourceforge.net/projects/openocd/files/openocd/0.8.0/. d. Install it accordingly. cd untar –xvf openocd-0.8.0.tar.gz cd openocd-0.8.0 ./configure make make install ==4. Download the GNU Tools for ARM Embedded Processors compiler== a. Download, to directory ~/local/src, the latest version here: https://launchpad.net/gcc-arm-embedded. b. Uncompress the compiler there. cd ~/local/src tar –xjf gcc-arm-none-eabi-4_8-2014q1-20140314-linux.tar.bz2 c. Add bin directory to PATH, in order to make the toolchain executables available. echo ‘export PATH=$PATH:/home//local/src/gcc-arm-none-eabi-4_8_2014q1/bin/’ >> /home//.bashrc d. Reload .bashrc. . .bashrc ==5. Install STLink== a. Install xstow (follow the Using xstow for local installations tutorial if xstow is not yet installed). b. Download STLink. cd ~/local/src/ git clone https://github.com/texane/stlink cd stlink sudo apt-get install pkg-config ./autogen.sh ./configure –prefix=/home//local/DIR/stlink make make install cd cd local/DIR xstow stlink c. Copy the necessary rules. cd /local/src/stlink sudo cp 49-stlinkv1.rules /etc/udev/rules.d sudo cp 49-stlinkv2.rules /etc/udev/rules.d sudo /etc/init.d/udev restart ==6. Download libopencm3== a. Install python-yaml. sudo apt-get install python-yaml b. Build the library. cd ~/local/src/ git clone https://github.com/libopencm3/libopencm3-examples cd libopencm3-examples git submodule init git submodule update cd libopencm3 make c. Build and flash an example to an USB-connected STMVLF4DISCOVERY. cd ~/local/src/libopencm3-examples/examples/stm32/f4/stm32f4-discovery/miniblink/ make make flash ===Build code for EvvGC=== In order to build the code for EvvGC gimbal controller, the following steps were taken. ==1. Set multiarch in your system (Ubuntu has multiarch set by default)== a. Add i386 architecture to /var/lib/dpkg/arch. dpkg --add-architecture i386 b. Modify /etc/apt/sources.list with the appropriate syntax for each source. deb [arch=amd64,i386] http://site.example.com/debian distribution c. Update the system. sudo apt-get update d. Install dependencies for the compiler. sudo apt-get install libncurses5:i386 ==2. Download the GNU Tools for ARM Embedded Processors compiler== a. Download, to directory ~/local/src, the latest version here: https://launchpad.net/gcc-arm-embedded. b. Uncompress the compiler there. cd ~/local/src tar –xjf gcc-arm-none-eabi-4_8-2014q1-20140314-linux.tar.bz2 c. Add bin directory to PATH, in order to make the toolchain executables available. echo ‘export PATH=$PATH:/home//local/src/gcc-arm-none-eabi-4_8_2014q1/bin/’ >> /home//.bashrc d. Reload .bashrc. . .bashrc ==3. Download the source code to an appropriate location== cd ~/local/src/ mkdir EvvGC git clone https://github.com/EvvGC/Firmware/blob/master/ cd Firmware ==4. Build the code== make ==5. Check that STM32Gimbal.hex file was created in /out/ directory== ===Flash code to EvvGC=== These are the proposed steps for flashing code into the EvvGC gimbal controller. These steps have been tested to work with the EvvGC in Debian and in Ubuntu. There is an USB-way of uploading code to the EvvGC that has not been explored yet. ==1. Buy a USB/UART adapter. Make sure it works at 3.3 V (not 5 V); otherwise, you can damage the STM32 processor. This tutorial used the Silicon Labs CP2102 USB to UART chip== ==2. Download stm32 flash== cd ~/local/src/ svn checkout http://stm32flash.googlecode.com/svn/trunk/ stm32flash # this is a read-only copy ==3. Install stm32flash== cd ~/local/src/stm32flash sudo make install ==4. Disconnect everything from the EvvGC Gimbal Controller board. In general, disconnect motor power when UART1 is plugged to the board, otherwise there will be serious damage to the board== ==5. Start with the USB/UART adapter disconnected from the computer and connect UART1 from the EvvGC to the USB/UART adapter (3V3 to 3V3, TX to RX, RX to TX and GND to GND)== {{ :ie0117_proyectos_i_2014:proyecto_1:evvgc_diagram.jpg?nolink&800 |}} ==6. Jump BOOT0, connect UART1 to computer, reboot the board (jump NRST for a second) and flash the code== cd ~/local/src/EvvGC/Firmware/out/ sudo stm32flash –b 115200 –w STM32Gimbal.hex –v –g 0x0 /dev/ttyUSB0/ * Find appropriate port with "dmesg | grep tty" ==7. Disconnect UART1 when the process completes and remove the jumper in BOOT0== ===Gimbal PID=== To calibrate the PID of the EvvGC Gimbal Controller, follow the next steps, in Microsoft Windows. ==1. Start with the USB/UART adapter disconnected from the computer and connect UART4 from the EvvGC to the USB/UART adapter (3V3 to 3V3, TX to RX, RX to TX and GND to GND) == ==2. Connect motors to the EvvGC == ==3. Start the EvvGC GUI, found in the "Firmware" directory ([[https://github.com/EvvGC/Firmware/tree/master/GUI]]) == ==4. Select the correct COM port and start calibrating the Gimbal. Some start values and the general procedure can be found here: [[http://www.rcgroups.com/forums/showpost.php?p=25877612&postcount=4]] == ===Gimbal Hardware=== The need to upload code to the EvvGC and to actually see it working requires soldering of pins to the board. The board was soldered in the ARCOS-Lab. {{ :ie0117_proyectos_i_2014:proyecto_1:evvgc_before.jpg?nolink&800 |}} {{ :ie0117_proyectos_i_2014:proyecto_1:evvgc_after.jpg?nolink&800 |}} ===Port to libopencm3=== The work with the libopencm3 EvvGC is documented in the following link: [[https://bitbucket.org/vlvrd/evvgc-libopencm3]]. ===Next steps=== * PD tuning: Controller tuning from Linux. * Port to libopencm3: Currently, ST Standard Peripheral libraries are being used without changes. ===Additional work=== Gimbal Hardware To contribute further with the development of the use of quadcopter cameras stabilized with gimbals, a generic gimbal design is in progress. The main objectives of this gimbal are, in the short term, to be able to hold the EvvGC and three Quanum Gimbal Motor 2208, and to stabilize different cameras (tests will be held with iPhone 5s and GoPro HERO3+). In the long term, the goal is to place the gimbal in a quadcopter from the ARCOS-Lab. Design requirements are: * Lightweight and small design. * Adaptable platform for different cameras. * Sturdy and balanced hardware, in order to liberate the motors from unnecessary work. * 3D-printable design. * Segmented gimbal, allowing future development in specific pieces. * Edges that can distribute forces, for a high-quality gimbal. Design in Solidworks 2012; these are some of the parts in development: {{ :ie0117_proyectos_i_2014:proyecto_1:big_circle.jpg?nolink&800 |}} {{ :ie0117_proyectos_i_2014:proyecto_1:little_circle.jpg?nolink&800 |}} {{ :ie0117_proyectos_i_2014:proyecto_1:side_piece.jpg?nolink&800 |}} {{ :ie0117_proyectos_i_2014:proyecto_1:gimbal1.jpg?nolink&800 |}} {{ :ie0117_proyectos_i_2014:proyecto_1:gimbal2.jpg?nolink&800 |}} ===References=== http://en.wikipedia.org/wiki/Inertial_measurement_unit https://github.com/EvvGC/Firmware http://libopencm3.org/wiki/Main_Page http://www.rcgroups.com/forums/showthread.php?t=1872199 http://www.rcgroups.com/forums/showthread.php?t=1978860&highlight=startup&page=14 http://www.st.com/web/en/catalog/mmc/FM141/SC1169 https://wiki.arcoslab.eie.ucr.ac.cr/doku.php/stm32f4