MAV'RIC
/home/travis/build/lis-epfl/MAVRIC_Library/boards/megafly_rev4/megafly_rev4.hpp
00001 /*******************************************************************************
00002  * Copyright (c) 2009-2016, MAV'RIC Development Team
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions are met:
00007  *
00008  * 1. Redistributions of source code must retain the above copyright notice,
00009  * this list of conditions and the following disclaimer.
00010  *
00011  * 2. Redistributions in binary form must reproduce the above copyright notice,
00012  * this list of conditions and the following disclaimer in the documentation
00013  * and/or other materials provided with the distribution.
00014  *
00015  * 3. Neither the name of the copyright holder nor the names of its contributors
00016  * may be used to endorse or promote products derived from this software without
00017  * specific prior written permission.
00018  *
00019  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00020  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00021  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00022  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
00023  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00024  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00025  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00026  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00027  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00028  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00029  * POSSIBILITY OF SUCH DAMAGE.
00030  ******************************************************************************/
00031 
00032 /*******************************************************************************
00033  * \file    megafly_rev4.hpp
00034  *
00035  * \author  MAV'RIC Team
00036  *
00037  * \brief   Autopilot board based on AVR32
00038  *
00039  ******************************************************************************/
00040 
00041 
00042 #ifndef MEGAFLY_REV4_HPP_
00043 #define MEGAFLY_REV4_HPP_
00044 
00045 #include "hal/avr32/adc_avr32.hpp"
00046 #include "hal/avr32/file_flash_avr32.hpp"
00047 #include "hal/avr32/file_fat_fs.hpp"
00048 #include "hal/avr32/gpio_avr32.hpp"
00049 #include "hal/avr32/i2c_avr32.hpp"
00050 #include "hal/avr32/led_avr32.hpp"
00051 #include "hal/avr32/pwm_avr32.hpp"
00052 #include "hal/avr32/serial_avr32.hpp"
00053 #include "hal/avr32/serial_usb_avr32.hpp"
00054 
00055 #include "drivers/airspeed_analog.hpp"
00056 #include "drivers/battery.hpp"
00057 #include "drivers/barometer_bmp085.hpp"
00058 #include "drivers/gps_ublox.hpp"
00059 #include "drivers/hmc5883l.hpp"
00060 #include "drivers/lsm330dlc.hpp"
00061 #include "drivers/servo.hpp"
00062 #include "drivers/sonar_i2cxl.hpp"
00063 #include "drivers/px4flow_i2c.hpp"
00064 #include "drivers/px4flow_serial.hpp"
00065 #include "drivers/spektrum_satellite.hpp"
00066 #include "drivers/state_display_megafly_rev4.hpp"
00067 
00068 #include "sensing/imu.hpp"
00069 
00070 extern "C"
00071 {
00072 #include "hal/avr32/twim_default_config.h"
00073 #include "util/streams.h"
00074 #include "hal/analog_monitor.h"
00075 }
00076 
00077 
00078 // Preprocessor definitions
00079 
00080 /*
00081  * Should the ESC be calibrated?
00082  * 0 for false (normal flight)
00083  * 1 for true (calibration)
00084  * !!!IMPORTANT!!!
00085  * IF CALIBRATING, TAKE OFF PROPS
00086  */
00087 #define CALIBRATE_ESC 0
00088 
00092 typedef struct
00093 {
00094     gpio_avr32_conf_t       dsm_receiver_pin_config;
00095     gpio_avr32_conf_t       dsm_power_pin_config;
00096     battery_conf_t          battery_config;
00097     serial_avr32_conf_t     uart0_config;
00098     serial_avr32_conf_t     uart1_config;
00099     serial_avr32_conf_t     uart3_config;
00100     serial_usb_avr32_conf_t uart_usb_config;
00101     i2c_avr32_conf_t        i2c0_config;
00102     i2c_avr32_conf_t        i2c1_config;
00103     imu_conf_t              imu_config;
00104     servo_conf_t            servo_config[8];
00105     PX4Flow_i2c::conf_t     px4flow_i2c_config;
00106     PX4Flow_serial::conf_t  px4flow_serial_config;
00107 } megafly_rev4_conf_t;
00108 
00109 
00115 static inline megafly_rev4_conf_t megafly_rev4_default_config();
00116 
00117 
00122 class Megafly_rev4
00123 {
00124 public:
00130     Megafly_rev4(megafly_rev4_conf_t config = megafly_rev4_default_config());
00131 
00132 
00138     virtual bool init(void);
00139 
00143     Gpio_avr32                  dsm_receiver_pin;               
00144     Gpio_avr32                  dsm_power_pin;                  
00145     Serial_avr32                uart0;                          
00146     Serial_avr32                uart1;                          
00147     Serial_avr32                uart3;                          
00148     Serial_usb_avr32            uart_usb;                       
00149     I2c_avr32                   i2c0;                           
00150     I2c_avr32                   i2c1;                           
00151     Hmc5883l                    hmc5883l;                       
00152     Lsm330dlc                   lsm330dlc;                      
00153     Barometer_BMP085            barometer;                      
00154     Spektrum_satellite          spektrum_satellite;             
00155     Led_avr32                   red_led;                        
00156     Led_avr32                   green_led;                      
00157     State_display_megafly_rev4  state_display_megafly_rev4_;    
00158     Imu                         imu;                            
00159     File_flash_avr32            file_flash;                     
00160     Gps_ublox                   gps_ublox;                      
00161     Sonar_i2cxl                 sonar_i2cxl;                    
00162     PX4Flow_i2c                 flow_i2c;                       
00163     PX4Flow_serial              flow_serial;                    
00164     analog_monitor_t            analog_monitor;                 
00165     Adc_avr32                   adc_battery;                    
00166     Adc_avr32                   adc_airspeed;                   
00167     Battery                     battery;                        
00168     Airspeed_analog             airspeed_analog;                
00169     Pwm_avr32                   pwm_0;                          
00170     Pwm_avr32                   pwm_1;                          
00171     Pwm_avr32                   pwm_2;                          
00172     Pwm_avr32                   pwm_3;                          
00173     Pwm_avr32                   pwm_4;                          
00174     Pwm_avr32                   pwm_5;                          
00175     Pwm_avr32                   pwm_6;                          
00176     Pwm_avr32                   pwm_7;                          
00177     Servo                       servo_0;                        
00178     Servo                       servo_1;                        
00179     Servo                       servo_2;                        
00180     Servo                       servo_3;                        
00181     Servo                       servo_4;                        
00182     Servo                       servo_5;                        
00183     Servo                       servo_6;                        
00184     Servo                       servo_7;                        
00185 
00186 private:
00187     byte_stream_t   dbg_stream_;  
00188 
00189 
00197     bool boardsupport_init(void);
00198 
00199 };
00200 
00201 
00207 static inline megafly_rev4_conf_t megafly_rev4_default_config()
00208 {
00209     megafly_rev4_conf_t conf = {};
00210 
00211     // -------------------------------------------------------------------------
00212     // GPIO dsm receiver pin configuration
00213     // -------------------------------------------------------------------------
00214     conf.dsm_receiver_pin_config     = gpio_avr32_default_config();
00215     conf.dsm_receiver_pin_config.pin = AVR32_PIN_PD12;
00216 
00217 
00218     // -------------------------------------------------------------------------
00219     // GPIO dsm power pin configuration
00220     // -------------------------------------------------------------------------
00221     conf.dsm_power_pin_config     = gpio_avr32_default_config();
00222     conf.dsm_power_pin_config.pin = AVR32_PIN_PC01;
00223 
00224     // -------------------------------------------------------------------------
00225     // Battery config
00226     // -------------------------------------------------------------------------
00227     conf.battery_config = battery_default_config();
00228 
00229     // -------------------------------------------------------------------------
00230     // UART0 configuration
00231     // -------------------------------------------------------------------------
00232     conf.uart0_config                       = {};
00233     conf.uart0_config.serial_device         = AVR32_SERIAL_0;
00234     conf.uart0_config.mode                  = AVR32_SERIAL_IN_OUT;
00235     conf.uart0_config.options               = {};
00236     conf.uart0_config.options.baudrate      = 57600;
00237     conf.uart0_config.options.charlength    = 8;
00238     conf.uart0_config.options.paritytype    = USART_NO_PARITY;
00239     conf.uart0_config.options.stopbits      = USART_1_STOPBIT;
00240     conf.uart0_config.options.channelmode   = USART_NORMAL_CHMODE;
00241     conf.uart0_config.rx_pin_map            = {AVR32_USART0_RXD_0_0_PIN, AVR32_USART0_RXD_0_0_FUNCTION};
00242     conf.uart0_config.tx_pin_map            = {AVR32_USART0_TXD_0_0_PIN, AVR32_USART0_TXD_0_0_FUNCTION};
00243 
00244 
00245     // -------------------------------------------------------------------------
00246     // UART1 configuration
00247     // -------------------------------------------------------------------------
00248     conf.uart1_config                       = {};
00249     conf.uart1_config.serial_device         = AVR32_SERIAL_1;
00250     conf.uart1_config.mode                  = AVR32_SERIAL_IN_OUT;
00251     conf.uart1_config.options               = {};
00252     conf.uart1_config.options.baudrate      = 115200;
00253     conf.uart1_config.options.charlength    = 8;
00254     conf.uart1_config.options.paritytype    = USART_NO_PARITY;
00255     conf.uart1_config.options.stopbits      = USART_1_STOPBIT;
00256     conf.uart1_config.options.channelmode   = USART_NORMAL_CHMODE;
00257     conf.uart1_config.rx_pin_map            = {AVR32_USART1_RXD_0_1_PIN, AVR32_USART1_RXD_0_1_FUNCTION};
00258     conf.uart1_config.tx_pin_map            = {AVR32_USART1_TXD_0_1_PIN, AVR32_USART1_TXD_0_1_FUNCTION};
00259 
00260 
00261     // -------------------------------------------------------------------------
00262     // UART3 configuration
00263     // -------------------------------------------------------------------------
00264     conf.uart3_config                       = {};
00265     conf.uart3_config.serial_device         = AVR32_SERIAL_3;
00266     conf.uart3_config.mode                  = AVR32_SERIAL_IN_OUT;
00267     conf.uart3_config.options               = {};
00268     conf.uart3_config.options.baudrate      = 38400;
00269     conf.uart3_config.options.charlength    = 8;
00270     conf.uart3_config.options.paritytype    = USART_NO_PARITY;
00271     conf.uart3_config.options.stopbits      = USART_1_STOPBIT;
00272     conf.uart3_config.options.channelmode   = USART_NORMAL_CHMODE;
00273     conf.uart3_config.rx_pin_map            = {AVR32_USART3_RXD_0_0_PIN, AVR32_USART3_RXD_0_0_FUNCTION};
00274     conf.uart3_config.tx_pin_map            = {AVR32_USART3_TXD_0_0_PIN, AVR32_USART3_TXD_0_0_FUNCTION};
00275 
00276 
00277     // -------------------------------------------------------------------------
00278     // UART USB configuration
00279     // -------------------------------------------------------------------------
00280     conf.uart_usb_config        = {};
00281 
00282 
00283     // -------------------------------------------------------------------------
00284     // I2C0 configuration
00285     // -------------------------------------------------------------------------
00286     conf.i2c0_config            = {};
00287     conf.i2c0_config.i2c_device = AVR32_I2C0;
00288     conf.i2c0_config.twi_opt    = twim_default_config();
00289     conf.i2c0_config.tenbit     = false;
00290     conf.i2c0_config.sda_pin    = AVR32_TWIMS0_TWD_0_0_PIN;
00291     conf.i2c0_config.clk_pin    = AVR32_TWIMS0_TWCK_0_0_PIN;
00292 
00293 
00294     // -------------------------------------------------------------------------
00295     // I2C1 configuration
00296     // -------------------------------------------------------------------------
00297     conf.i2c1_config            = {};
00298     conf.i2c1_config.i2c_device = AVR32_I2C1;
00299     conf.i2c1_config.twi_opt    = twim_default_config();
00300     conf.i2c1_config.twi_opt.speed = 100000;
00301     conf.i2c1_config.tenbit     = false;
00302     conf.i2c1_config.sda_pin    = AVR32_TWIMS1_TWD_0_0_PIN;
00303     conf.i2c1_config.clk_pin    = AVR32_TWIMS1_TWCK_0_0_PIN;
00304 
00305 
00306     // -------------------------------------------------------------------------
00307     // Imu config
00308     // -------------------------------------------------------------------------
00309     conf.imu_config = imu_default_config();
00310     // Accelerometer
00311     // Bias
00312     conf.imu_config.accelerometer.bias[0] = 0.0f;           
00313     conf.imu_config.accelerometer.bias[1] = 0.0f;
00314     conf.imu_config.accelerometer.bias[2] = 0.0f;
00315 
00316     // Scale
00317     conf.imu_config.accelerometer.scale_factor[0] = 4000.0f;    
00318     conf.imu_config.accelerometer.scale_factor[1] = 4000.0f;
00319     conf.imu_config.accelerometer.scale_factor[2] = 4000.0f;
00320 
00321     // Axis and sign
00322     conf.imu_config.accelerometer.sign[0] = +1.0f;  
00323     conf.imu_config.accelerometer.sign[1] = -1.0f;
00324     conf.imu_config.accelerometer.sign[2] = -1.0f;
00325     conf.imu_config.accelerometer.axis[0] = 0;      
00326     conf.imu_config.accelerometer.axis[1] = 1;
00327     conf.imu_config.accelerometer.axis[2] = 2;
00328 
00329     // Gyroscope
00330     // Bias
00331     conf.imu_config.gyroscope.bias[0] = 0.0f;       
00332     conf.imu_config.gyroscope.bias[1] = 0.0f;
00333     conf.imu_config.gyroscope.bias[2] = 0.0f;
00334 
00335     // Scale
00336     conf.imu_config.gyroscope.scale_factor[0] = 818.5111f;      
00337     conf.imu_config.gyroscope.scale_factor[1] = 818.5111;
00338     conf.imu_config.gyroscope.scale_factor[2] = 818.5111f;
00339 
00340     // Axis and sign
00341     conf.imu_config.gyroscope.sign[0] = +1.0f;  
00342     conf.imu_config.gyroscope.sign[1] = -1.0f;
00343     conf.imu_config.gyroscope.sign[2] = -1.0f;
00344     conf.imu_config.gyroscope.axis[0] = 0;      
00345     conf.imu_config.gyroscope.axis[1] = 1;
00346     conf.imu_config.gyroscope.axis[2] = 2;
00347 
00348     // Magnetometer
00349     // Bias
00350     conf.imu_config.magnetometer.bias[0] = 0.0f;        
00351     conf.imu_config.magnetometer.bias[1] = 0.0f;
00352     conf.imu_config.magnetometer.bias[2] = 0.0f;
00353 
00354     // Scale
00355     conf.imu_config.magnetometer.scale_factor[0] = 600.0f;      
00356     conf.imu_config.magnetometer.scale_factor[1] = 600.0f;
00357     conf.imu_config.magnetometer.scale_factor[2] = 600.0f;
00358 
00359     // Axis and sign
00360     conf.imu_config.magnetometer.sign[0] = -1.0f;   
00361     conf.imu_config.magnetometer.sign[1] = -1.0f;
00362     conf.imu_config.magnetometer.sign[2] = -1.0f;
00363     conf.imu_config.magnetometer.axis[0] = 2;       
00364     conf.imu_config.magnetometer.axis[1] = 0;
00365     conf.imu_config.magnetometer.axis[2] = 1;
00366 
00367 
00368 
00369     // -------------------------------------------------------------------------
00370     // Servo config
00371     // -------------------------------------------------------------------------
00372     conf.servo_config[0] = servo_default_config_esc();
00373     conf.servo_config[1] = servo_default_config_esc();
00374     conf.servo_config[2] = servo_default_config_esc();
00375     conf.servo_config[3] = servo_default_config_esc();
00376     conf.servo_config[4] = servo_default_config_esc();
00377     conf.servo_config[5] = servo_default_config_esc();
00378     conf.servo_config[6] = servo_default_config_esc();
00379     conf.servo_config[7] = servo_default_config_esc();
00380 
00381     // -------------------------------------------------------------------------
00382     // Px4Flow config
00383     // -------------------------------------------------------------------------
00384     conf.px4flow_i2c_config     = PX4Flow_i2c::default_config();
00385     conf.px4flow_serial_config  = PX4Flow_serial::default_config();
00386 
00387     return conf;
00388 }
00389 
00390 
00391 #endif /* MEGAFLY_REV4_HPP_ */
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines