Subversion Repositories FlightCtrl

Compare Revisions

Ignore whitespace Rev 2098 → Rev 2099

/branches/dongfang_FC_fixedwing/configuration.h
4,153 → 4,246
#include <inttypes.h>
#include <avr/io.h>
 
#define MAX_CHANNELS 10
#define MAX_MOTORS 12
 
// bitmask for VersionInfo_t.HardwareError[0]
#define FC_ERROR0_GYRO_PITCH 0x01
#define FC_ERROR0_GYRO_ROLL 0x02
#define FC_ERROR0_GYRO_YAW 0x04
#define FC_ERROR0_ACC_X 0x08
#define FC_ERROR0_ACC_Y 0x10
#define FC_ERROR0_ACC_Z 0x20
#define FC_ERROR0_PRESSURE 0x40
#define FC_ERROR1_RES0 0x80
// bitmask for VersionInfo_t.HardwareError[1]
#define FC_ERROR1_I2C 0x01
#define FC_ERROR1_BL_MISSING 0x02
#define FC_ERROR1_SPI_RX 0x04
#define FC_ERROR1_PPM 0x08
#define FC_ERROR1_MIXER 0x10
#define FC_ERROR1_RES1 0x20
#define FC_ERROR1_RES2 0x40
#define FC_ERROR1_RES3 0x80
 
typedef struct {
/*PMM*/uint8_t HeightD;
/* P */uint8_t MaxHeight;
/*PMM*/uint8_t HeightP;
/* P */uint8_t Height_ACC_Effect;
/* P */uint8_t CompassYawEffect;
uint8_t SWMajor;
uint8_t SWMinor;
uint8_t protoMajor;
uint8_t protoMinor;
uint8_t SWPatch;
uint8_t hardwareErrors[5];
}__attribute__((packed)) VersionInfo_t;
 
/* P */uint8_t GyroPitchP;
/* P */uint8_t GyroRollP;
/* P */uint8_t GyroYawP;
extern VersionInfo_t versionInfo;
 
/* P */uint8_t UserParams[8];
/* P */uint8_t ServoPitchControl;
typedef struct {
/*PMM*/uint8_t gyroPitchD;
/* P */uint8_t gyroRollD;
/* P */uint8_t gyroYawD;
 
/* P */uint8_t GyroPitchD; // LoopGasLimit in tool
/* P */uint8_t GyroRollD; // AxisCoupling1 in tool
/* P */uint8_t GyroYawD; // AxisCoupling2 in tool
// Control
/* P */uint8_t externalControl;
 
/* P */uint8_t ExternalControl;
/*PMM*/uint8_t J16Timing;
/*PMM*/uint8_t J17Timing;
} dynamicParam_t;
extern dynamicParam_t dynamicParams;
// Height control
/*PMM*/uint8_t heightP;
/* P */uint8_t heightI;
/*PMM*/uint8_t heightD;
/* P */uint8_t heightSetting;
 
// Output and servo
/*PMM*/uint8_t output0Timing;
/*PMM*/uint8_t output1Timing;
 
uint8_t servoManualControl[2];
 
/* P */uint8_t userParams[8];
} DynamicParams_t;
 
extern volatile DynamicParams_t dynamicParams;
 
typedef struct {
uint8_t sourceIdx, targetIdx;
uint8_t min, max;
} MMXLATION;
 
/*
typedef struct {
uint8_t sourceIdx, targetIdx;
} XLATION;
*/
 
// values above 250 representing poti1 to poti4
typedef struct {
uint8_t ChannelAssignment[8]; // see upper defines for details
uint8_t GlobalConfig; // see upper defines for bitcoding
uint8_t HeightMinGas; // Value : 0-100
uint8_t HeightD; // Value : 0-250
uint8_t MaxHeight; // Value : 0-32
uint8_t HeightP; // Value : 0-32
uint8_t Height_Gain; // Value : 0-50
uint8_t Height_ACC_Effect; // Value : 0-250
uint8_t channels[MAX_CHANNELS];
} channelMap_t;
extern channelMap_t channelMap;
 
uint8_t StickElevatorP;
uint8_t StickAileronsP;
uint8_t StickRudderP;
typedef struct {
char name[12];
int8_t motor[MAX_MOTORS][4];
}__attribute__((packed)) mixerMatrix_t;
extern mixerMatrix_t mixerMatrix;
 
uint8_t PIDGyroFilter;// Value: 1-8
typedef struct {
int16_t offsets[3];
} sensorOffset_t;
 
typedef struct {
uint8_t manualControl;
uint8_t stabilizationFactor;
uint8_t minValue;
uint8_t maxValue;
uint8_t flags;
} servo_t;
 
#define SERVO_STABILIZATION_REVERSE 1
 
typedef struct {
uint8_t bitmask;
uint8_t timing;
} output_flash_t;
 
typedef struct {
uint8_t gyroQuadrant;
uint8_t accQuadrant;
uint8_t imuReversedFlags;
uint8_t DGyroFilter; // Value: 1-8
uint8_t attitudeGyroFilter; // Value: 1-8
uint8_t gyroPIDFilterConstant;
uint8_t gyroDWindowLength;
uint8_t gyroDFilterConstant;
uint8_t accFilterConstant;
 
uint8_t accFilter;
uint8_t zerothOrderCorrection;
uint8_t rateTolerance;
 
uint8_t GyroPitchP;
uint8_t GyroRollP;
uint8_t GyroYawP;
uint8_t gyroActivityDamping;
uint8_t driftCompDivider; // 1/k (Koppel_ACC_Wirkung)
uint8_t driftCompLimit; // limit for gyrodrift compensation
} IMUConfig_t;
 
uint8_t UserParams[8]; // Value : 0-250
extern IMUConfig_t IMUConfig;
 
uint8_t LowVoltageWarning; // Value : 0-250
// values above 250 representing poti1 to poti4
typedef struct {
// Global bitflags
uint8_t bitConfig; // see upper defines for bitcoding
 
uint8_t servoDirections;
uint8_t ServoRefresh; // Value: 0-250 // Refreshrate of servo pwm output
// uint8_t axisCoupling1; // Value: 0-250 Faktor, mit dem Yaw die Achsen Roll und Nick koppelt (NickRollMitkopplung)
// uint8_t axisCoupling2; // Value: 0-250 Faktor, mit dem Nick und Roll verkoppelt werden
// uint8_t axisCouplingYawCorrection;// Value: 0-250 Faktor, mit dem Nick und Roll verkoppelt werden
 
uint8_t GyroPitchD;
uint8_t GyroRollD;
uint8_t GyroYawD;
uint8_t levelCorrection[2];
 
uint8_t zerothOrderGyroCorrectionZAccLimit;
uint8_t zerothOrderGyroCorrectionFactorx1000;
// Control
uint8_t gyroPitchP;
uint8_t gyroPitchI;
uint8_t gyroPitchD;
 
uint8_t secondOrderGyroCorrectionDivisor;
uint8_t secondOrderGyroCorrectionLimit;
uint8_t CompassYawEffect; // Value : 0-32
uint8_t gyroRollP;
uint8_t gyroRollI;
uint8_t gyroRollD;
 
uint8_t J16Bitmask; // for the J16 Output
uint8_t J16Timing; // for the J16 Output
uint8_t J17Bitmask; // for the J17 Output
uint8_t J17Timing; // for the J17 Output
uint8_t gyroYawP;
uint8_t gyroYawI;
uint8_t gyroYawD;
 
uint8_t ExternalControl; // for serial Control
} paramset_t;
uint8_t stickIElevator;
uint8_t stickIAilerons;
uint8_t stickIRudder;
 
#define PARAMSET_STRUCT_LEN sizeof(paramset_t)
uint8_t externalControl; // for serial Control
 
extern paramset_t staticParams;
uint8_t IFactor;
 
typedef struct {
uint8_t Revision;
int8_t Name[12];
int8_t Motor[16][4];
}__attribute__((packed)) MixerTable_t;
uint8_t batteryVoltageWarning;
uint8_t emergencyThrottle;
uint8_t emergencyFlightDuration;
 
extern MixerTable_t Mixer;
// Servos
uint8_t servoCount;
uint8_t servoManualMaxSpeed;
servo_t servoConfigurations[2]; // [PITCH, ROLL]
 
// Outputs
output_flash_t outputFlash[2];
uint8_t outputDebugMask;
uint8_t outputFlags;
 
// User params
uint8_t userParams[8];
 
// Name
char name[12];
} ParamSet_t;
 
extern ParamSet_t staticParams;
 
// MKFlags
#define MKFLAG_MOTOR_RUN (1<<0)
#define MKFLAG_FLY (1<<1)
#define MKFLAG_CALIBRATE (1<<2)
#define MKFLAG_START (1<<3)
#define MKFLAG_EMERGENCY_LANDING (1<<4)
#define MKFLAG_RESERVE1 (1<<5)
#define MKFLAG_RESERVE2 (1<<6)
#define MKFLAG_RESERVE3 (1<<7)
#define MKFLAG_MOTOR_RUN (1<<0)
//#define MKFLAG_FLY (1<<1)
#define MKFLAG_CALIBRATE (1<<2)
#define MKFLAG_START (1<<3)
#define MKFLAG_EMERGENCY_FLIGHT (1<<4)
#define MKFLAG_LOWBAT (1<<5)
#define MKFLAG_RESERVE2 (1<<6)
#define MKFLAG_RESERVE3 (1<<7)
 
// bit mask for staticParams.GlobalConfig
#define CFG_HEIGHT_CONTROL (1<<0)
#define CFG_HEIGHT_SWITCH (1<<1)
#define CFG_HEADING_HOLD (1<<2)
#define CFG_COMPASS_ACTIVE (1<<3)
#define CFG_COMPASS_FIX (1<<4)
#define CFG_GPS_ACTIVE (1<<5)
#define CFG_AXIS_COUPLING_ACTIVE (1<<6)
#define CFG_ROTARY_RATE_LIMITER (1<<7)
// bit mask for staticParams.bitConfig
#define CFG_SIMPLE_HEIGHT_CONTROL (1<<0)
#define CFG_SIMPLE_HC_HOLD_SWITCH (1<<1)
#define CFG_HEADING_HOLD (1<<2)
#define CFG_COMPASS_ENABLED (1<<3)
#define CFG_UNUSED (1<<4)
#define CFG_NAVI_ENABLED (1<<5)
#define CFG_AXIS_COUPLING_ENABLED (1<<6)
#define CFG_GYRO_SATURATION_PREVENTION (1<<7)
 
// bit mask for staticParams.ServoDirections
#define SERVO_DIRECTION_ELEVATOR (1<<0)
#define SERVO_DIRECTION_AILERONS (1<<1)
#define SERVO_DIRECTION_RUDDER (1<<2)
#define IMU_REVERSE_GYRO_PR (1<<0)
#define IMU_REVERSE_GYRO_YAW (1<<1)
#define IMU_REVERSE_ACC_XY (1<<2)
#define IMU_REVERSE_ACC_Z (1<<3)
 
#define ATMEGA644 0
#define ATMEGA644P 1
#define ATMEGA644 0
#define ATMEGA644P 1
#define SYSCLK F_CPU
 
// Not really a part of configuration, but LEDs and HW version test are the same.
#define RED_OFF {if((BoardRelease == 10) || (BoardRelease == 20)) PORTB &=~(1<<PORTB0); else PORTB |= (1<<PORTB0);}
#define RED_ON {if((BoardRelease == 10) || (BoardRelease == 20)) PORTB |= (1<<PORTB0); else PORTB &=~(1<<PORTB0);}
// Not really a part of configuration, but LEDs and HW s test are the same.
#define RED_OFF {if((boardRelease == 10) || (boardRelease == 20)) PORTB &=~(1<<PORTB0); else PORTB |= (1<<PORTB0);}
#define RED_ON {if((boardRelease == 10) || (boardRelease == 20)) PORTB |= (1<<PORTB0); else PORTB &=~(1<<PORTB0);}
#define RED_FLASH PORTB ^= (1<<PORTB0)
#define GRN_OFF {if(BoardRelease < 12) PORTB &=~(1<<PORTB1); else PORTB |= (1<<PORTB1);}
#define GRN_ON {if(BoardRelease < 12) PORTB |= (1<<PORTB1); else PORTB &=~(1<<PORTB1);}
#define GRN_OFF {if(boardRelease < 12) PORTB &=~(1<<PORTB1); else PORTB |= (1<<PORTB1);}
#define GRN_ON {if(boardRelease < 12) PORTB |= (1<<PORTB1); else PORTB &=~(1<<PORTB1);}
#define GRN_FLASH PORTB ^= (1<<PORTB1)
 
// Mixer table
#define MIX_THROTTLE 0
#define MIX_PITCH 1
#define MIX_ROLL 2
#define MIX_YAW 3
#define MIX_THROTTLE 0
#define MIX_PITCH 1
#define MIX_ROLL 2
#define MIX_YAW 3
 
#define VARIABLE_COUNT 8
 
extern volatile uint8_t MKFlags;
extern int16_t variables[8]; // The "Poti"s.
extern uint8_t BoardRelease;
extern uint8_t requiredMotors;
extern int16_t variables[VARIABLE_COUNT]; // The "Poti"s.
extern uint8_t boardRelease;
extern uint8_t CPUType;
 
void configuration_staticToDynamic(void);
uint8_t getCPUType(void);
uint8_t getBoardRelease(void);
extern volatile uint8_t MKFlags;
extern uint16_t isFlying;
 
void IMUConfig_default(void);
void channelMap_default(void);
void paramSet_default(uint8_t setnumber);
void mixerMatrix_default(void);
 
void configuration_setNormalFlightParameters(void);
void configuration_setFailsafeFlightParameters(void);
void configuration_applyVariablesToParams(void);
 
void setCPUType(void);
void setBoardRelease(void);
 
// Called after a change in configuration parameters, as a hook for modules to take over changes.
void configuration_paramSetDidChange(void);
#endif // _CONFIGURATION_H