[译]可编程硬件Arduino初探(4)-MultiWii之config.h
0.前言
从可编程硬件初探(4)开始的一系列文章将集中进行一些优秀原文的翻译.本文为MultiWii系列的第一个翻译,Config.h
原文参考:http://www.multiwii.com/wiki/index.php?title=Config.h
config.h \文件
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.
MultiWii的最初设置是在config.h文件中完成的.使用类似arduino ide或者文本编辑器来为多轴\固定翼\直升机来调整各种设置.通过增加或删除在#defing前的// 来注释或取消注释掉这一行来使其生效.
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:
例如,在配置文件中选择你的飞行器模式,最小油门速度,I2C总线速度,上拉寄存器,控制板等信息.使用ACRO模式的最简单形式.除了像下面这样删除掉这几行前的//,不需要再做别的修改.
#define QUADX // 飞行模式(x四轴) #define MINTHROTTLE 1180 // 最小油门速度(电调的怠速速度) #define I2C_SPEED 400000L // I2C总线速度 #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.
下一步是使用arduino ide或其他isp将程序下载到版子中.目前,为了简单起见,我们使用arduino ide来完成下载工作.
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.
下面开始介绍一些更通用的配置来帮助初学者完成他们的第一个配置.高级玩家可以参考MultiWii forum来获取更多设置.
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.
注意:config.h文件是从2.1版本后引入的.如果你使用的是老版本的MultiWii,这点你应该小心,但基本原理也是一样的.
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.
这部分选择你的MultiWii是多轴,直升机,固定翼中的哪种类型.尽可以选择一种.
/************************** The type of multicopter ****************************/ //#define GIMBAL //#define BI //#define TRI //#define QUADP //+四轴 #define QUADX //x四轴 //#define Y4 //#define Y6 //#define HEX6 //#define HEX6X //#define OCTOX8 //#define OCTOFLATP //#define OCTOFLATX //#define FLYING_WING //#define VTAIL4 //#define AIRPLANE // Howto setup =>>>http://fotoflygarn.blogspot.com/2012/03/how-to-setup-multiwii-airplane-same.html // 固定翼 如何设置请参考=>>> //******************************************************* // Heli is beta test ......! // 下面开始的是测试 // Howto setup =>>> http://fotoflygarn.blogspot.se/2012/04/multiwii-helicopter.html //#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.
选择最小油门速度.也许必须通过ESCs来配置这个值.
/**************************** 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 \I2C总线速度
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 开启或关闭I2C寄存器上拉
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) //#define INTERNAL_I2C_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 qcrc.ca //#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 http://store.ckdevices.com/ //#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 //GY-80也使用过 //#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 http://www.diymulticopter.com //#define INNOVWORKS_6DOF // with ITG3200, BMA180 available here http://www.diymulticopter.com //#define IOI_MINI_MULTIWII// www.bambucopter.com //#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
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 */ #define ALLOW_ARM_DISARM_VIA_TX_YAW //#define ALLOW_ARM_DISARM_VIA_TX_ROLL
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:
- enable the correct copter type which resembles correct number of motors&servos
- 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
- enable your mixing code with this define; replace filename with your chosen name
- 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 http://code.google.com/p/multiwii/source/browse/#svn%2Fbranches%2FHamburger%2FmyMWiiDefaultsConverter and enable the following
//#define MY_PRIVATE_DEFAULTS "filename.h"
Some more info may be found in the forum http://www.multiwii.com/forum/viewtopic.php?f=8&t=3987 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\IMU设置
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;} #endif #if !defined(GYRO_ORIENTATION) #define GYRO_ORIENTATION(X, Y, Z) {gyroADC[ROLL] = X; gyroADC[PITCH] = Y; gyroADC[YAW] = Z;} #endif #if !defined(MAG_ORIENTATION) #define MAG_ORIENTATION(X, Y, Z) {magADC[ROLL] = X; magADC[PITCH] = Y; magADC[YAW] = Z;} #endif
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_PITCH, ACC_PITCH and GYRO_PITCH goes 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.