From MultiWii
Revision as of 01:29, 16 September 2015 by Edsimmons3 (Talk | contribs) (Failsafe)

Jump to: navigation, search

explain what is in this file and what is in eeprom

The config.h file

How it works

The first configuration of MultiWii is done in the config.h file of the firmware source. With a programming IDE like Arduino or a simple text editor, you can change several options for your multicopter, flying wing or helicopter. This is done by adding or removing of the // in front of the #define parameters which comment or uncomment the line so it is included or not in the final firmware.

For instance, in the config file you choose the type of multicopter, minimum throttle for motors, i2c speed, internal pullup resistors (if needed), controller board with at least gyroscope, remove the // in front of the #define and you have the simplest configuration to fly in ACRO mode. No need do change any other line:

#define QUADX
#define MINTHROTTLE 1180
#define I2C_SPEED 400000L
#define CRIUS_SE

The next step is to upload the firmware to the controller board with Arduino IDE or other means like an ISP programmer but the latest is more suited for experienced users that will know how to do it. For now we will keep this simple and use the Arduino IDE to upload the firmware do the controller board.

Basic Setup

Here we will present some of the more usual configurations used in the config.h to help the beginners with their first configuration. More advanced users can read the comments and the information in the MultiWii forum regarding the other settings.

Attention: The config.h described here is from the upcoming version 2.1 (dev_20120622). Beware of this if you are configuring an older version of MultiWii, basic concept should apply also.

Type of multicopter

In this section we choose what type of multicopter, helicopter or airplane you are configuring MultiWii too. You can select only one option here.

/**************************    The type of multicopter    ****************************/
  //#define GIMBAL
  //#define BI
  //#define TRI
  //#define QUADP
  #define QUADX
  //#define Y4
  //#define Y6
  //#define HEX6
  //#define HEX6X
  //#define OCTOX8
  //#define OCTOFLATP
  //#define OCTOFLATX
  //#define FLYING_WING
  //#define VTAIL4
  //#define AIRPLANE     // Howto setup =>>>
  // Heli is  beta test ......!
  // Howto setup =>>>
  //#define HELI_120_CCPM  // PatrikE Experimental
  //#define HELI_90_DEG    // PatrikE Experimental

Motor minimum throttle

This is were you choose your minimum throttle speed when you arm the motors. You may have to configure the value according to your ESCs (speed controllers) and motors. This setting will prevent the motors from stopping in flight and having a crash. Test if the value is ok with the motors running (armed) without propellers and moving the aircraft around to see if any the motors stop when changing speed.

/****************************    Motor minthrottle    *******************************/
  /* Set the minimum throttle command sent to the ESC (Electronic Speed Controller)
     This is the minimum value that allow motors to run at a idle speed  */
  //#define MINTHROTTLE 1300 // for Turnigy Plush ESCs 10A
  //#define MINTHROTTLE 1120 // for Super Simple ESCs 10A
  //#define MINTHROTTLE 1220
  //#define MINTHROTTLE 1150
  #define MINTHROTTLE 1180 // for RCTimer ESCs 30A

I2C bus speed

Choose the bus speed according to your sensors or if you are having i2c errors.

/**********************************    I2C speed   ************************************/
  //#define I2C_SPEED 100000L     //100kHz normal mode, this value must be used for a genuine WMP
  #define I2C_SPEED 400000L   //400kHz fast mode, it works only with some WMP clones and with most current boards

Enable or disable I2C resistor pullups

This setting depends of your controller build or board that you are using. With complete flight controllers you can disable the internal pullup resistors. Verify if you have I2C bus errors or strange sensors values.

 /***************************    Internal i2c Pullups   ********************************/
   //enable internal I2C pull ups (in most cases it is better to use external pullups)

FC boards configuration

Simply select your flight controller board here and the sensors will be configured for you, no need to configure individual sensors.

 /***************************    Combined IMU Boards    ********************************/
   /* if you use a specific sensor board:
      please submit any correction to this list.
        Note from Alex: I only own some boards
                        for other boards, I'm not sure, the info was gathered via rc forums, be cautious */
   //#define FFIMUv1         // first 9DOF+baro board from Jussi, with HMC5843                   <- confirmed by Alex
   //#define FFIMUv2         // second version of 9DOF+baro board from Jussi, with HMC5883       <- confirmed by Alex
   //#define FREEIMUv1       // v0.1 & v0.2 & v0.3 version of 9DOF board from Fabio
   //#define FREEIMUv03      // FreeIMU v0.3 and v0.3.1
   //#define FREEIMUv035     // FreeIMU v0.3.5 no baro
   //#define FREEIMUv035_MS  // FreeIMU v0.3.5_MS                                                <- confirmed by Alex
   //#define FREEIMUv035_BMP // FreeIMU v0.3.5_BMP
   //#define FREEIMUv04      // FreeIMU v0.4 with MPU6050, HMC5883L, MS561101BA                  <- confirmed by Alex
   //#define FREEIMUv043     // same as FREEIMUv04 with final MPU6050 (with the right ACC scale)
   //#define NANOWII         // the smallest multiwii FC based on MPU6050 + pro micro based proc <- confirmed by Alex
   //#define PIPO            // 9DOF board from erazz
   //#define QUADRINO        // full FC board 9DOF+baro board from witespy  with BMP085 baro     <- confirmed by Alex
   //#define QUADRINO_ZOOM   // full FC board 9DOF+baro board from witespy  second edition
   //#define QUADRINO_ZOOM_MS// full FC board 9DOF+baro board from witespy  second edition       <- confirmed by Alex
   //#define ALLINONE        // full FC board or standalone 9DOF+baro board from CSG_EU
   //#define AEROQUADSHIELDv2
   //#define ATAVRSBIN1      // Atmel 9DOF (Contribution by EOSBandi). requires 3.3V power.
   //#define SIRIUS          // Sirius Navigator IMU                                             <- confirmed by Alex
   //#define SIRIUS600       // Sirius Navigator IMU  using the WMP for the gyro
   //#define MINIWII         // Jussi's MiniWii Flight Controller                                <- confirmed by Alex
   //#define CITRUSv2_1      // CITRUS from
   //#define CHERRY6DOFv1_0
   //#define DROTEK_10DOF    // Drotek 10DOF with ITG3200, BMA180, HMC5883, BMP085, w or w/o LLC
   //#define DROTEK_10DOF_MS // Drotek 10DOF with ITG3200, BMA180, HMC5883, MS5611, LLC
   //#define DROTEK_6DOFv2   // Drotek 6DOF v2
   //#define DROTEK_6DOF_MPU // Drotek 6DOF with MPU6050
   //#define DROTEK_10DOF_MPU//
   //#define MONGOOSE1_0     // mongoose 1.0
   //#define CRIUS_LITE      // Crius MultiWii Lite
   #define CRIUS_SE        // Crius MultiWii SE
   //#define OPENLRSv2MULTI  // OpenLRS v2 Multi Rc Receiver board including ITG3205 and ADXL345
   //#define BOARD_PROTO_1   // with MPU6050 + HMC5883L + MS baro
   //#define BOARD_PROTO_2   // with MPU6050 + slave  MAG3110 + MS baro
   //#define GY_80           // Chinese 10 DOF with  L3G4200D ADXL345 HMC5883L BMP085, LLC
   //#define GY_85           // Chinese 9 DOF with  ITG3205 ADXL345 HMC5883L LLC
   //#define GY_86           // Chinese 10 DOF with  MPU6050 HMC5883L MS5611, LLC
   //#define INNOVWORKS_10DOF // with ITG3200, BMA180, HMC5883, BMP085 available here
   //#define INNOVWORKS_6DOF // with ITG3200, BMA180 available here
   //#define IOI_MINI_MULTIWII//
   //#define Bobs_6DOF_V1    // BobsQuads 6DOF V1 with ITG3200 & BMA180
   //#define Bobs_9DOF_V1	 // BobsQuads 9DOF V1 with ITG3200, BMA180 & HMC5883L
   //#define Bobs_10DOF_BMP_V1 // BobsQuads 10DOF V1 with ITG3200, BMA180, HMC5883L & BMP180 - BMP180 is software compatible with BMP085
   //#define FLYDUINO_MPU

Individual sensor configuration

If you somehow added a sensor to your controller board or have built your one, you can configure the MultiWii supported sensors here. Also you can change the sensors reported directions below an check them in the MultiWiiConf graphical user interface.

  /***************************    independent sensors    ********************************/
    //leave it commented if you already checked a specific board above
    /* I2C gyroscope */
    //#define WMP
    //#define ITG3200
    //#define L3G4200D
    //#define MPU6050       //combo + ACC
     /* I2C accelerometer */
    //#define NUNCHUCK  // if you want to use the nunckuk connected to a WMP
    //#define MMA745
    //#define ADXL345
    //#define BMA020
    //#define BMA180
    //#define NUNCHACK  // if you want to use the nunckuk as a standalone I2C ACC without WMP
    //#define LIS3LV02
    //#define LSM303DLx_ACC
     /* I2C barometer */
    //#define BMP085
    //#define MS561101BA
     /* I2C magnetometer */
    //#define HMC5843
    //#define HMC5883
    //#define AK8975
    //#define MAG3110

    // use the Devantech SRF i2c sensors, SRF08, SRF02
    // (for now, there is no difference in the SRF0x code, but we may want to differentiate in the future.)
    //#define SRF02
    //#define SRF08
    //#define SRF10
    //#define SRF23

    /* ADC accelerometer */ // for 5DOF from sparkfun, uses analog PIN A1/A2/A3
    //#define ADCACC

     /* enforce your individual sensor orientation - even overrides board specific defaults */
     //#define FORCE_ACC_ORIENTATION(X, Y, Z)  {accADC[ROLL]  =  Y; accADC[PITCH]  = -X; accADC[YAW]  = Z;}
     //#define FORCE_GYRO_ORIENTATION(X, Y, Z) {gyroADC[ROLL] = -Y; gyroADC[PITCH] =  X; gyroADC[YAW] = Z;}
     //#define FORCE_MAG_ORIENTATION(X, Y, Z)  {magADC[ROLL]  =  X; magADC[PITCH]  =  Y; magADC[YAW]  = Z;}
     /* Board orientation shift */
     /* If you have frame designed only for + mode and you cannot rotate FC phisycally for flying in X mode (or vice versa)
      * you can use one of of this options for virtual sensors rotation by 45 deegres, then set type of multicopter according to flight mode.
      * Check motors order and directions of motors rotation for matching with new front point!  Uncomment only one option! */
     //#define SENSORS_TILT_45DEG_RIGHT        // rotate the FRONT 45 degres clockwise
     //#define SENSORS_TILT_45DEG_LEFT         // rotate the FRONT 45 degres counterclockwise

RC System setup

For most users with standard RC receivers there is no need to change settings in config.h for the RC system.

Other settings exist for special receiver types:

 /********                       special receiver types             ********************/
   /****************************    PPM Sum Reciver    ***********************************/
     /* The following lines apply only for specific receiver with only one PPM sum signal, on digital PIN 2
        Select the right line depending on your radio brand. Feel free to modify the order in your PPM order is different */
     //#define SERIAL_SUM_PPM         PITCH,YAW,THROTTLE,ROLL,AUX1,AUX2,AUX3,AUX4,8,9,10,11 //For Graupner/Spektrum
     //#define SERIAL_SUM_PPM         ROLL,PITCH,THROTTLE,YAW,AUX1,AUX2,AUX3,AUX4,8,9,10,11 //For Robe/Hitec/Futaba
     //#define SERIAL_SUM_PPM         ROLL,PITCH,YAW,THROTTLE,AUX1,AUX2,AUX3,AUX4,8,9,10,11 //For Multiplex
     //#define SERIAL_SUM_PPM         PITCH,ROLL,THROTTLE,YAW,AUX1,AUX2,AUX3,AUX4,8,9,10,11 //For some Hitec/Sanwa/Others
     // Uncommenting following line allow to connect PPM_SUM receiver to standard THROTTLE PIN on MEGA boards (eg. A8 in CRIUS AIO)
     //#define PPM_ON_THROTTLE
   /**********************    Spektrum Satellite Reciver    *******************************/
     /* The following lines apply only for Spektrum Satellite Receiver
        Spektrum Satellites are 3V devices.  DO NOT connect to 5V!
        For MEGA boards, attach sat grey wire to RX1, pin 19. Sat black wire to ground. Sat orange wire to Mega board's 3.3V (or any other 3V to 3.3V source).
        For PROMINI, attach sat grey to RX0.  Attach sat black to ground. */
     //#define SPEKTRUM 1024
     //#define SPEKTRUM 2048
     //#define RX_SERIAL_PORT 1    // Forced to 0 on Pro Mini and single serial boards; Set to your choice of 0, 1, or 2 on any Mega based board (defaults to 1 on Mega).
     // Defines that allow a "Bind" of a Spektrum or Compatible Remote Receiver (aka Satellite) via Configuration GUI.
     //   Bind mode will be same as declared above, if your TX is capable.
     //   Ground, Power, and Signal must come from three adjacent pins. 
     //   By default, these are Ground=4, Power=5, Signal=6.  These pins are in a row on most MultiWii shield boards. Pins can be overriden below.  
     //   Normally use 3.3V regulator is needed on the power pin!!  If your satellite hangs during bind (blinks, but won't complete bind with a solid light), go direct 5V on all pins. 
     //   For Pro Mini, the connector for the Satellite that resides on the FTDI can be unplugged and moved to these three adjacent pins. 
     //#define SPEK_BIND             //Un-Comment for Spektrum Satellie Bind Support.  Code is ~420 bytes smaller without it. 
     //#define SPEK_BIND_GROUND 4
     //#define SPEK_BIND_POWER  5
     //#define SPEK_BIND_DATA   6
   /*******************************    SBUS RECIVER    ************************************/
     /* The following line apply only for Futaba S-Bus Receiver on MEGA boards or PROMICRO boards.
        You have to invert the S-Bus-Serial Signal e.g. with a Hex-Inverter like IC SN74 LS 04 */
     //#define SBUS     PITCH,YAW,THROTTLE,ROLL,AUX1,AUX2,AUX3,AUX4,8,9,10,11,12,13,14,15,16,17  // dsm2 orangerx
     //#define SBUS     ROLL,PITCH,THROTTLE,YAW,AUX1,AUX2,AUX3,AUX4,8,9,10,11,12,13,14,15,16,17  // T14SG
     //#define RX_SERIAL_PORT 1
     #define SBUS_MID_OFFSET 988 //SBUS Mid-Point at 1500
   /******************************* HOTT RECIVER ************************************/
   /* Graupner Hott HD */
   //#define RX_SERIAL_PORT 1

Uncomment only one block of options to suit your needs.


An out of control multirotor is dangerous - it is your responsibility to ensure the correct operation of your radio equipment etc.

Failsafe is disabled by default, but *must* be enabled when you have completed the setup and testing of you radio control equipment. Failsafe itself can be dangerous if wrongly configured.

To enable failsafe uncomment:

 #define FAILSAFE

and configure the parameters to suit your radio system.

/********                          Failsafe settings                 ********************/
   /* Failsafe check pulses on four main control channels CH1-CH4. If the pulse is missing or bellow 985us (on any of these four channels) 
      the failsafe procedure is initiated. After FAILSAFE_DELAY time from failsafe detection, the level mode is on (if ACC is avaliable),
      PITCH, ROLL and YAW is centered and THROTTLE is set to FAILSAFE_THROTTLE value. You must set this value to descending about 1m/s or so
      for best results. This value is depended from your configuration, AUW and some other params.  Next, after FAILSAFE_OFF_DELAY the copter is disarmed, 
      and motors is stopped. If RC pulse coming back before reached FAILSAFE_OFF_DELAY time, after the small quard time the RC control is returned to normal. */
   #define FAILSAFE                                // uncomment  to activate the failsafe function
   #define FAILSAFE_DELAY     1                     // Guard time for failsafe activation after signal lost. 1 step = 0.1sec - 1sec in example
   #define FAILSAFE_OFF_DELAY 200                    // Time for Landing before motors stop in 0.1sec. 1 step = 0.1sec - 20sec in example
   #define FAILSAFE_THROTTLE  (MINTHROTTLE + 50)    // (*) Throttle level used for landing - may be relative to MINTHROTTLE - as in this case

Copter specific options

Servos configuration

Here you can configure the behavior of the servos for copters with servos.

#define YAW_DIRECTION 1 // this does NOT reverse the yaw correction direction for copters with servos. NOT anymore! It has been replaced with a much more powerful setup.
servo naming scheme and usage

Servos are numbered beginning with 1.

General rules:

  • SERVO1 is always used as Camstab PITCH servo (except HEXA on promini with A0_A1_PIN_HEX)
  • SERVO2 is always used as Camstab ROLL servo (except HEXA on promini with A0_A1_PIN_HEX)
  • SERVO3 is always used as CAMTRIG servo or traditional FLAPS servo
  • SERVO8 is always used as Motor output (if no MOTOR1 output is used for motor control)

SERVOS 4..7 are used depending on coptertype:

  • Flying Wing : 4-left wing, 5-right wing
  • Airplane : 4-left wing, 5-right wing, 6-rudder, 7-elevator
  • SingleCopter : 4,5-side servos, 6-front, 7-rear
  • DualCopter : 5-Pitch servo, 6-Roll servo
  • BI : 5-left servo, 6-right servo
  • TRI : YAW servo on servo 6 or servo 4 in MEGA2560 boards with HW_PWM's
  • HELI: 4,6,7 - swashplate servos, 5-rear servo or rear motor (MOTOR2 output can be used too for rear motor)
servo and motor pin assignments

For promini:

  • Motors : 9,10,11,3,6,5,A2,12
  • Servos : A0,A1,A2,12,11,3,10,9

For Mega:

  • Motors: 3,5,6,2,7,8,9,10
  • Servos SW_PWM : 34+44 , 35+45 , 33+46 , 37,6,2,5,3
  • Servos HW_PWM : 44,45,46,11,12,6,7,8

For promicro m32u4:

  • ...
servo min/max/middle values and reversing

Servo min/max/middle values are preset to 1020/2000/1500. You can override this by enabling the following code section and filling in your preferred values for min/max/middle for your servos.

/* if you want to preset min/middle/max values for servos right after flashing, because of limited physical
 * room for servo travel, then you must enable and set all three following options */
//#define SERVO_MIN  {1020, 1020, 1020, 1020, 1020, 1020, 1020, 1020}
//#define  SERVO_MAX {2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000}
//#define  SERVO_MID {1500, 1500, 1500, 1500, 1500, 1500, 1500, 1500} // (*)

To reverse a servo travel, set the corresponding value to 1

//#define FORCE_SERVO_RATES      {30,30,100,100,100,100,100,100} // 0 = normal, 1= reverse

The min/max/middle values and the reverse flags can be changed in the GUI.

Arm and disarm stick combinations

Because of the Yaw movement used in the most used combination of stick to arm multicopters can make the rear propeller touch the ground, an alternative method was created. You can configure here the alternative method to arm the motors of your tricopter.

/********************************    ARM/DISARM    *********************************/
/* optionally disable stick combinations to arm/disarm the motors.
  * In most cases one of the two options to arm/disarm via TX stick is sufficient */

Individual Mixing

If you built a copter with special geometry, different motor strengths or unconventional CoG, you may want to override an existing entry in the mixing table. To avoid repeated editing of the mixTable() in the Output.ino file for every version again and again, this feature is for you. Usage goes in 4 steps:

  1. enable the correct copter type which resembles correct number of motors&servos
  2. create a file with your choice of name which contains all the mixing code for motors and servos. To get an idea where to start, look at mixTable() function
  3. enable your mixing code with this define; replace filename with your chosen name
  4. optionally limit the 'leave headroom for gyro correction' to the first N motors - useful for unequal motors combinations
   //#define MY_PRIVATE_MIXING "filename.h"
   //#define LEAVE_HEADROOM_FOR_MOTORS 4 // leave room for gyro corrrections only for first 4 motors

Example myhex.h:

// hex with two big rotors front&rear used for lift:
#define LIFT_MIX(X,Y,Z) rcCommand[THROTTLE] + axisPID[PITCH]*Y
// for 4 small center motors - used for stabilization - roll and for yaw (their 'throttle' signal comes via AUX2, so those run at differenthigher speed):
#define STAB_MIX(X,Y,Z)  rcData[AUX2] + axisPID[ROLL]*X + YAW_DIRECTION * axisPID[YAW]*Z
motor[0] = STAB_MIX(-1, 0, +1); //REAR_R    ccw top
motor[2] = STAB_MIX(+1, 0, +1); //REAR_L    ccw top
motor[1] = STAB_MIX(-1, 0, -1); //FRONT_R   cw  
motor[3] = STAB_MIX(+1, 0, -1); //FRONT_L   cw 
motor[4] = LIFT_MIX(0, -1/2, 0); //FRONT    cw
motor[5] = LIFT_MIX(0, +1/2, 0); //REAR     ccw
// must enable LEAVE_HEADROOM_FOR_MOTORS to exclude front&rear motor

Individual defaults

This is best left to the experienced users! If you want to replace the hardcoded default values with your own model specific set of defaults (e.g. from a previous save to an .mwi file), you can replace the universal defaults. This brings the advantage to have proven copter specific good starting point of defaults for this copter in the firmware, available at touch of 'reset'. If tuning pids goes wrong, simply press reset and start all over with a proven set of good defaults for your copter. To convert a saved .mwi file into a suitable code section file, you may use the perl script provided here and enable the following

//#define MY_PRIVATE_DEFAULTS "filename.h"

Some more info may be found in the forum but beyond that you are pretty much on your own.

Alternate CPUs and boards

Aux2 pin configuration

Configure here the controller pins you want to use for Aux2 switch.

/*********************************    Aux 2 Pin     ***********************************/
  /* possibility to use PIN8 or PIN12 as the AUX2 RC input
     it deactivates in this case the POWER PIN (pin 12) or the BUZZER PIN (pin 8)
  #define RCAUXPIN8
  //#define RCAUXPIN12

Tuning and developer

Special throttle settings

Here you can configure the minimum and maximum value sent to the ESCs.

/* this is the value for the ESCs when they are not armed
   in some cases, this value must be lowered down to 900 for some specific ESCs */
#define MINCOMMAND 1000

/* this is the maximum value for the ESCs at full power
   this value can be increased up to 2000 */
//#define MAXTHROTTLE 1850
#define MAXTHROTTLE 1900

Motor and servo special configuration

If you don't want the motors to start immediately when you arm the motors you can use this define. Also if you radio has a center point different of 1500 you can change that here.

/* motors will not spin when the throttle command is in low position
   this is an alternative method to stop immediately the motors */
#define MOTOR_STOP

/* some radios have not a neutral point centered on 1500. can be changed here */
#define MIDRC 1500

Global Setting

list settings

IMU settings

sensors orientation

you can change orientation of individual sensor and for predefined boards with #define FORCE_* FORCE_sensor_ORIENTATION

Changing sensors orientation is done with C #define FORCE_* directive, here the default orientation to start with :

//default board orientation
#if !defined(ACC_ORIENTATION) 
 #define ACC_ORIENTATION(X, Y, Z)  {accADC[ROLL]  = X; accADC[PITCH]  = Y; accADC[YAW]  = Z;}
#if !defined(GYRO_ORIENTATION) 
 #define GYRO_ORIENTATION(X, Y, Z) {gyroADC[ROLL] = X; gyroADC[PITCH] = Y; gyroADC[YAW] = Z;}
#if !defined(MAG_ORIENTATION) 
 #define MAG_ORIENTATION(X, Y, Z)  {magADC[ROLL]  = X; magADC[PITCH]  = Y; magADC[YAW]  = Z;}

How should be the sensor axis directions

TILT the MULTI to the RIGHT (left side up):

  • MAG_ROLL, ACC_ROLL and GYRO_ROLL goes up
  • MAG_Z and ACC_Z goes down

TILT the MULTI forward (tail up):

  • MAG_Z and ACC_Z goes down

Rotating the copter clockwise (YAW):

  • GYRO_YAW goes up

The copter stays level:

  • MAG_Z is positive ; ACC_Z is positive

Magnetic sensors orientation

  • X MAG:
    • ROLL RIGHT = positive
    • ROLL LEFT = negative
  • Y MAG
    • PITCH FORWARD = positive
    • PITCH backward = negative
  • Z MAG
    • should be positive
    • not move a lot if the multi remains flat.