4,16 → 4,17 |
#include <inttypes.h> |
#include <avr/io.h> |
|
#define MAX_CHANNELS 10 |
#define MAX_MOTORS 12 |
#define MAX_CONTROLCHANNELS 8 |
#define MAX_I2CCHANNELS 8 |
#define MAX_PWMCHANNELS 8 |
|
// 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_GYRO_X 0x01 |
#define FC_ERROR0_GYRO_Y 0x02 |
#define FC_ERROR0_GYRO_Z 0x04 |
#define FC_ERROR0_ACCEL_X 0x08 |
#define FC_ERROR0_ACCEL_Y 0x10 |
#define FC_ERROR0_ACCEL_Z 0x20 |
#define FC_ERROR0_PRESSURE 0x40 |
#define FC_ERROR1_RES0 0x80 |
// bitmask for VersionInfo_t.HardwareError[1] |
26,12 → 27,14 |
#define FC_ERROR1_RES2 0x40 |
#define FC_ERROR1_RES3 0x80 |
|
#define PID_NORMAL_VALUE 100 |
|
typedef struct { |
uint8_t SWMajor; |
uint8_t SWMinor; |
uint8_t SWPatch; |
uint8_t protoMajor; |
uint8_t protoMinor; |
uint8_t SWPatch; |
uint8_t hardwareErrors[5]; |
}__attribute__((packed)) VersionInfo_t; |
|
38,26 → 41,34 |
extern VersionInfo_t versionInfo; |
|
typedef struct { |
/*PMM*/uint8_t gyroP; |
/* P */uint8_t gyroI; |
/* P */uint8_t gyroD; |
/* P */uint8_t compassControlHeading; |
uint8_t flightMode; |
|
uint8_t attGyroP; // Attitude mode Proportional (attitude error to control) |
uint8_t attGyroI; // Attitude mode Integral (attitude error integral to control. Serves to eliminate permanent attitude errors) |
uint8_t attGyroD; // Attitude mode rate |
|
uint8_t rateGyroP; // Rate mode Proportional |
uint8_t rateGyroI; // Rate mode Integral (serves to eliminate slow rotation errors in rate mode) |
uint8_t rateGyroD; // Rate mode Differential (GyroD) |
|
uint8_t yawGyroP; |
uint8_t yawGyroI; |
uint8_t yawGyroD; |
|
// Control |
/* P */uint8_t externalControl; |
/* P */uint8_t dynamicStability; |
uint8_t externalControl; |
uint8_t attitudeControl; |
|
// Height control |
/*PMM*/uint8_t heightP; |
/* P */uint8_t heightI; |
/*PMM*/uint8_t heightD; |
/* P */uint8_t heightSetting; |
uint8_t heightP; |
uint8_t heightI; |
uint8_t heightD; |
uint8_t heightSetting; |
|
uint8_t attitudeControl; |
|
// Output and servo |
/*PMM*/uint8_t output0Timing; |
/*PMM*/uint8_t output1Timing; |
uint8_t output0Timing; |
uint8_t output1Timing; |
|
uint8_t servoManualControl[2]; |
|
87,18 → 98,59 |
uint8_t RCPolarity; // 1=positive, 0=negative. Use positive with Futaba receiver, negative with FrSky. |
uint8_t HWTrim; |
uint8_t variableOffset; |
uint8_t channels[MAX_CHANNELS]; |
uint8_t channels[MAX_CONTROLCHANNELS]; |
} ChannelMap_t; |
|
extern ChannelMap_t channelMap; |
|
#define LOG_MOTOR_MIXER_UNIT 6 |
#define LOG_DYNAMIC_STABILITY_SCALER 6 |
|
typedef enum { |
MIXER_SOURCE_ROLL = 0, |
MIXER_SOURCE_PITCH = 1, |
MIXER_SOURCE_THROTTLE = 2, |
MIXER_SOURCE_YAW = 3 |
} MixerSource_Control; |
|
typedef enum { |
MIXER_SOURCE_AUX_GIMBAL_ROLL = 0, |
MIXER_SOURCE_AUX_GIMBAL_PITCH = 1, |
MIXER_SOURCE_AUX_RCCHANNEL = 2, |
MIXER_SOURCE_AUX_END = 2 + MAX_CONTROLCHANNELS |
} MixerSourceAux; |
|
typedef enum { |
I2C0 = 0, |
I2C1 = 1, |
I2C2 = 2, |
I2C3 = 3, |
I2C4 = 4, |
I2C5 = 5, |
I2C6 = 6, |
I2C7 = 7, |
SERVO0 = MAX_I2CCHANNELS, |
NUM_OUTPUTS = 8 + MAX_PWMCHANNELS |
} MixerDestination; |
|
typedef struct { |
char name[12]; |
int8_t matrix[MAX_MOTORS][5]; |
//int8_t oppositeMotor[MAX_MOTORS]; |
}__attribute__((packed)) MotorMixer_t; |
extern MotorMixer_t motorMixer; |
uint8_t outputType; |
uint8_t minValue; |
uint8_t maxValue; |
int8_t flightControls[4]; |
uint8_t auxSource; // for selecting a gimbal axis or an RC channel. |
uint8_t oppositeMotor; // only relevant where used to control a multicopter motor. |
}__attribute__((packed)) MixerMatrixRow_t; |
|
typedef MixerMatrixRow_t OutputMixer_t[NUM_OUTPUTS]; |
extern OutputMixer_t outputMixer; |
|
typedef enum { |
OUTPUT_TYPE_UNDEFINED, |
OUTPUT_TYPE_MOTOR, |
OUTPUT_TYPE_SERVO |
} outputTypes; |
|
typedef struct { |
int16_t offsets[3]; |
} sensorOffset_t; |
106,8 → 158,6 |
typedef struct { |
uint8_t manualControl; |
uint8_t stabilizationFactor; |
uint8_t minValue; |
uint8_t maxValue; |
uint8_t flags; |
} Servo_t; |
|
119,21 → 169,24 |
} output_flash_t; |
|
typedef struct { |
/* Set up so that |
* Nose-up is positive on pitch |
* Roll-right is positive on roll |
* Turn-ccw is positive on yaw |
*/ |
uint8_t gyroQuadrant; |
/* |
* Set up so that: |
* Acc. Z is +1g in normal attitude |
* Acc. X gets positive in a left roll |
* Acc. Y gets positive in a nose-up attitude. |
*/ |
uint8_t accQuadrant; |
uint8_t imuReversedFlags; |
|
uint8_t gyroPIDFilterConstant; |
uint8_t gyroDWindowLength; |
// uint8_t gyroDFilterConstant; |
uint8_t accFilterConstant; |
|
uint8_t zerothOrderCorrection; |
uint8_t rateTolerance; |
|
uint8_t gyroActivityDamping; |
uint8_t driftCompDivider; // 1/k (Koppel_ACC_Wirkung) |
uint8_t driftCompLimit; // limit for gyrodrift compensation |
} IMUConfig_t; |
|
extern IMUConfig_t IMUConfig; |
143,6 → 196,8 |
// Global bitflags |
uint8_t bitConfig; // see upper defines for bitcoding |
|
uint8_t flightMode; |
|
// 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 |
150,11 → 205,23 |
uint8_t levelCorrection[2]; |
|
// Control |
uint8_t gyroP; |
uint8_t gyroI; |
uint8_t gyroD; |
uint8_t attGyroP; // Attitude mode Proportional (attitude error to control) |
uint8_t attGyroI; // Attitude mode Integral (attitude error integral to control. Serves to eliminate permanent attitude errors) |
uint8_t attGyroIMax; // Attitude mode Integral max. limit |
uint8_t attGyroD; // Attitude mode rate |
|
uint8_t rateGyroP; // Rate mode Proportional |
uint8_t rateGyroI; // Rate mode Integral (serves to eliminate slow rotation errors in rate mode) |
uint8_t rateGyroIMax; // Rate mode Integral max. limit |
uint8_t rateGyroD; // Rate mode Differential (GyroD) |
|
uint8_t yawGyroP; |
uint8_t yawGyroI; |
uint8_t yawGyroD; |
|
uint8_t externalControl; // for serial Control |
uint8_t attitudeControl; |
uint8_t dynamicStability; |
|
uint8_t stickP; |
uint8_t stickD; |
161,16 → 228,11 |
uint8_t stickYawP; |
uint8_t stickThrottleD; |
|
// Idle throttle. Affects the throttle stick only. |
uint8_t minThrottle; |
// Value of max. throttle stick. |
uint8_t maxThrottle; |
|
uint8_t externalControl; // for serial Control |
uint8_t motorSmoothing; |
uint8_t dynamicStability; // PID limit for Attitude controller |
|
uint8_t IFactor; |
uint8_t yawIFactor; |
|
uint8_t compassMode; // bitflag thing. |
uint8_t compassYawCorrection; |
uint8_t compassBendingReturnSpeed; |
232,31 → 294,29 |
// MKFlags |
#define MKFLAG_MOTOR_RUN (1<<0) |
//#define MKFLAG_FLY (1<<1) |
#define MKFLAG_CALIBRATE (1<<2) |
#define MKFLAG_START (1<<3) |
//#define MKFLAG_CALIBRATE (1<<2) |
#define MKFLAG_EMERGENCY_FLIGHT (1<<4) |
#define MKFLAG_LOWBAT (1<<5) |
#define MKFLAG_RESERVE2 (1<<6) |
#define MKFLAG_RESERVE3 (1<<7) |
//#define MKFLAG_RESERVE2 (1<<6) |
//#define MKFLAG_RESERVE3 (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_UNUSED (1<<2) |
#define CFG_COMPASS_ENABLED (1<<3) |
#define CFG_UNUSED (1<<4) |
#define CFG_UNUSED2 (1<<4) |
#define CFG_NAVI_ENABLED (1<<5) |
#define CFG_AXIS_COUPLING_ENABLED (1<<6) |
#define CFG_UNUSED3 (1<<6) |
#define CFG_GYRO_SATURATION_PREVENTION (1<<7) |
|
#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 IMU_REVERSE_GYRO_XY (1<<0) |
#define IMU_REVERSE_GYRO_Z (1<<1) |
#define IMU_REVERSE_ACCEL_XY (1<<2) |
#define IMU_REVERSE_ACCEL_Z (1<<3) |
|
#define ATMEGA644 0 |
#define ATMEGA644P 1 |
#define SYSCLK F_CPU |
|
// 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);} |
267,16 → 327,10 |
#define GRN_FLASH PORTB ^= (1<<PORTB1) |
|
// Mixer table |
#define MIX_PITCH 0 |
#define MIX_ROLL 1 |
#define MIX_THROTTLE 2 |
#define MIX_YAW 3 |
#define MIX_OPPOSITE_MOTOR 4 |
|
#define VARIABLE_COUNT 8 |
|
extern volatile uint8_t MKFlags; |
extern uint8_t requiredMotors; |
extern int16_t variables[VARIABLE_COUNT]; // The "Poti"s. |
extern uint8_t boardRelease; |
extern uint8_t CPUType; |
287,10 → 341,10 |
void IMUConfig_default(void); |
void channelMap_default(void); |
void paramSet_default(uint8_t setnumber); |
void motorMixer_default(void); |
void outputMixer_default(void); |
|
void configuration_setNormalFlightParameters(void); |
void configuration_setFailsafeFlightParameters(void); |
void configuration_setNormalFlightMode(void); |
void configuration_setFailsafeFlightMode(void); |
void configuration_applyVariablesToParams(void); |
|
void setCPUType(void); |