Subversion Repositories FlightCtrl

Compare Revisions

Ignore whitespace Rev 1959 → Rev 1960

/branches/dongfang_FC_rewrite/configuration.h
4,40 → 4,46
#include <inttypes.h>
#include <avr/io.h>
 
 
#define MAX_CHANNELS 10
#define MAX_MOTORS 12
 
typedef struct {
/*PMM*/uint8_t HeightD;
/* P */uint8_t MaxHeight;
/*PMM*/uint8_t HeightP;
/* P */uint8_t Height_ACC_Effect;
/* P */uint8_t CompassYawEffect;
/* P */uint8_t GyroD;
/*PMM*/uint8_t GyroP;
/* P */uint8_t GyroI;
/* Never used */uint8_t StickYawP;
// IMU
/*PMM*/uint8_t gyroP;
/* P */uint8_t gyroD;
/* P */uint8_t gyroI;
/* P */uint8_t IFactor;
/* P */uint8_t UserParams[8];
/* P */uint8_t ServoPitchControl;
/* P */uint8_t LoopGasLimit;
/* P */uint8_t AxisCoupling1;
/* P */uint8_t AxisCoupling2;
/* P */uint8_t AxisCouplingYawCorrection;
/* P */uint8_t DynamicStability;
/* P */uint8_t ExternalControl;
/*PMM*/uint8_t J16Timing;
/*PMM*/uint8_t J17Timing;
/* P */uint8_t NaviGpsModeControl;
/* P */uint8_t NaviGpsGain;
/* P */uint8_t NaviGpsP;
/* P */uint8_t NaviGpsI;
/* P */uint8_t NaviGpsD;
/* P */uint8_t NaviGpsACC;
/*PMM*/uint8_t NaviOperatingRadius;
/* P */uint8_t NaviWindCorrection;
/* P */uint8_t NaviSpeedCompensation;
int8_t KalmanK;
int8_t KalmanMaxDrift;
int8_t KalmanMaxFusion;
uint8_t yawIFactor;
/* P */uint8_t compassYawEffect;
 
// Control
/* P */uint8_t externalControl;
 
/* P */uint8_t axisCoupling1;
/* P */uint8_t axisCoupling2;
/* P */uint8_t axisCouplingYawCorrection;
/* P */uint8_t dynamicStability;
uint8_t maxControlActivityForAcc;
 
// Height control
/*PMM*/uint8_t heightP;
/*PMM*/uint8_t heightD;
/* P */uint8_t heightSetting;
/* P */uint8_t heightACCEffect;
 
uint8_t attitudeControl;
 
// The rest...
/* P */uint8_t userParams[8];
/*PMM*/uint8_t output0Timing;
/*PMM*/uint8_t output1Timing;
 
uint8_t servoManualControl[2];
 
uint8_t motorSmoothing;
} dynamicParam_t;
 
extern dynamicParam_t dynamicParams;
 
typedef struct {
49,109 → 55,120
uint8_t sourceIdx, targetIdx;
} XLATION;
 
typedef struct {
uint8_t checksum;
uint8_t revisionNumber;
uint8_t channels[MAX_CHANNELS];
} channelMap_t;
extern channelMap_t channelMap;
 
typedef struct {
uint8_t checksum;
uint8_t revision;
int8_t name[12];
int8_t motor[MAX_MOTORS][4];
}__attribute__((packed)) mixerMatrix_t;
extern mixerMatrix_t mixerMatrix;
 
typedef struct {
uint8_t manualControl;
uint8_t compensationFactor;
uint8_t minValue;
uint8_t maxValue;
uint8_t flags;
} servo_t;
 
typedef struct {
uint8_t bitmask;
uint8_t timing;
} output_flash_t;
 
// 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 StickP; // Value : 1-6
uint8_t StickD; // Value : 0-64
uint8_t StickYawP; // Value : 1-20
uint8_t MinThrottle; // Value : 0-32
uint8_t MaxThrottle; // Value : 33-250
uint8_t GyroAccFactor; // Value : 1-64
uint8_t CompassYawEffect; // Value : 0-32
uint8_t GyroP; // Value : 10-250
uint8_t GyroI; // Value : 0-250
uint8_t GyroD; // Value : 0-250
uint8_t LowVoltageWarning; // Value : 0-250
uint8_t EmergencyGas; // Value : 0-250 //Gaswert bei Empüngsverlust
uint8_t EmergencyGasDuration; // Value : 0-250 // Zeitbis auf EmergencyGas geschaltet wird, wg. Rx-Problemen
uint8_t Unused0; //
// Global bitflags
uint8_t bitConfig; // see upper defines for bitcoding
uint8_t bitConfig2; // see upper defines for bitcoding
// Height Control
uint8_t heightP; // Value : 0-32
uint8_t heightD; // Value : 0-250
uint8_t heightSetting; // Value : 0-32
uint8_t heightMaxThrottleChange; // Value : 0-100
uint8_t heightSlewRate; // Value : 0-50
uint8_t heightACCEffect; // Value : 0-250
 
// Attitude Control
uint8_t attitudeControl;
 
// Control
uint8_t stickP; // Value : 1-6
uint8_t stickD; // Value : 0-64
uint8_t stickYawP; // Value : 1-20
uint8_t stickThrottleD;
uint8_t minThrottle; // Value : 0-32
uint8_t maxThrottle; // Value : 33-250
uint8_t externalControl; // for serial Control
uint8_t maxControlActivityForAcc;
 
// IMU
uint8_t gyroPIDFilterConstant;
uint8_t gyroATTFilterConstant;
uint8_t gyroDFilterConstant;
uint8_t accFilterConstant;
 
uint8_t gyroP; // Value : 10-250
uint8_t gyroI; // Value : 0-250
uint8_t gyroD; // Value : 0-250
 
uint8_t zerothOrderCorrection; // Value : 1-64
uint8_t driftCompDivider; // 1/k (Koppel_ACC_Wirkung)
uint8_t driftCompLimit; // limit for gyrodrift compensation
 
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 dynamicStability; // PID limit for Attitude controller
uint8_t IFactor; // Value : 0-250
uint8_t UserParams1[4]; // Value : 0-250
/*
uint8_t UserParam2; // Value : 0-250
uint8_t UserParam3; // Value : 0-250
uint8_t UserParam4; // Value : 0-250
*/
uint8_t ServoPitchControl;
uint8_t ServoPitchComp;
uint8_t ServoPitchMin;
uint8_t ServoPitchMax; // Value : 0-250 // Anschlag
uint8_t ServoRefresh; // Value: 0-250 // Refreshrate of servo pwm output
uint8_t LoopGasLimit; // Value: 0-250 max. Gas wührend Looping
uint8_t LoopThreshold; // Value: 0-250 Schwelle für Stickausschlag
uint8_t LoopHysteresis; // Value: 0-250 Hysterese für Stickausschlag
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 unused0;
uint8_t unused1;
uint8_t GyroAccTrim; // 1/k (Koppel_ACC_Wirkung)
uint8_t DriftComp; // limit for gyrodrift compensation
uint8_t DynamicStability; // PID limit for Attitude controller
uint8_t UserParams2[4]; // Value : 0-250
/*
uint8_t UserParam6; // Value : 0-250
uint8_t UserParam7; // Value : 0-250
uint8_t UserParam8; // Value : 0-250
*/
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 NaviGpsModeControl; // Parameters for the Naviboard
uint8_t NaviGpsGain; // overall gain for GPS-PID controller
uint8_t NaviGpsP; // P gain for GPS-PID controller
uint8_t NaviGpsI; // I gain for GPS-PID controller
uint8_t NaviGpsD; // D gain for GPS-PID controller
uint8_t NaviGpsPLimit; // P limit for GPS-PID controller
uint8_t NaviGpsILimit; // I limit for GPS-PID controller
uint8_t NaviGpsDLimit; // D limit for GPS-PID controller
uint8_t NaviGpsACC; // ACC gain for GPS-PID controller
uint8_t NaviGpsMinSat; // number of sattelites neccesary for GPS functions
uint8_t NaviStickThreshold; // activation threshild for detection of manual stick movements
uint8_t NaviWindCorrection; // streng of wind course correction
uint8_t NaviSpeedCompensation; // D gain fefore position hold login
uint8_t NaviOperatingRadius; // Radius limit in m around start position for GPS flights
uint8_t NaviAngleLimitation; // limitation of attitude angle controlled by the gps algorithm
uint8_t NaviPHLoginTime; // position hold logintimeout
uint8_t ExternalControl; // for serial Control
uint8_t BitConfig; // see upper defines for bitcoding
uint8_t ServoPitchCompInvert; // Value : 0-250 0 oder 1 // WICHTIG!!! am Ende lassen
uint8_t Reserved[4];
int8_t Name[12];
} paramset_t;
uint8_t yawIFactor;
uint8_t compassYawEffect; // Value : 0-32
 
#define PARAMSET_STRUCT_LEN sizeof(paramset_t)
// Servos
servo_t servoConfigurations[2]; // [PITCH, ROLL]
uint8_t servoCount;
 
extern paramset_t staticParams;
// Battery warning and emergency flight
uint8_t batteryVoltageWarning; // Value : 0-250
uint8_t emergencyThrottle; // Value : 0-250 //Gaswert bei Empüngsverlust /*
uint8_t emergencyFlightDuration; // Value : 0-250 // Zeitbis auf EmergencyGas geschaltet wird, wg. Rx-Problemen
 
typedef struct {
uint8_t Revision;
int8_t Name[12];
int8_t Motor[16][4];
}__attribute__((packed)) MixerTable_t;
// Outputs
output_flash_t outputFlash[2];
uint8_t outputDebugMask;
// bit0: Test all OFF
// bit1: Test all ON
// bit2: flash when beeping
uint8_t outputFlags;
 
extern MixerTable_t Mixer;
// User params
uint8_t userParams[8]; // Value : 0-250
 
// Name
uint8_t 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_EMERGENCY_FLIGHT (1<<4)
#define MKFLAG_RESERVE1 (1<<5)
#define MKFLAG_RESERVE2 (1<<6)
#define MKFLAG_RESERVE3 (1<<7)
 
// bit mask for staticParams.GlobalConfig
// bit mask for staticParams.bitConfig
#define CFG_HEIGHT_CONTROL (1<<0)
#define CFG_HEIGHT_SWITCH (1<<1)
#define CFG_HEADING_HOLD (1<<2)
159,9 → 176,9
#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)
#define CFG_GYRO_SATURATION_PREVENTION (1<<7)
 
// bit mask for staticParams.BitConfig
// bit mask for staticParams.bitConfig2
#define CFG_LOOP_UP (1<<0)
#define CFG_LOOP_DOWN (1<<1)
#define CFG_LOOP_LEFT (1<<2)
173,11 → 190,11
#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);}
#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
187,10 → 204,15
#define MIX_YAW 3
 
extern volatile uint8_t MKFlags;
extern uint8_t requiredMotors;
extern int16_t variables[8]; // The "Poti"s.
extern uint8_t BoardRelease;
extern uint8_t boardRelease;
extern uint8_t CPUType;
 
void channelMap_default(void);
void paramSet_default(uint8_t setnumber);
void mixerMatrix_default(void);
 
void configuration_applyVariablesToParams(void);
uint8_t getCPUType(void);
uint8_t getBoardRelease(void);