Rev 2119 |
Go to most recent revision |
Blame |
Compare with Previous |
Last modification |
View Log
| RSS feed
#ifndef _CONFIGURATION_H
#define _CONFIGURATION_H
#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 {
uint8_t gyroQuadrant;
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;
typedef struct {
uint8_t P;
uint8_t I;
uint8_t D;
} PID_t;
typedef struct {
uint8_t P;
uint8_t I;
uint8_t D;
uint8_t iMax;
} PIDIM_t;
typedef enum {
FLIGHT_MODE_NONE,
FLIGHT_MODE_MANUAL,
FLIGHT_MODE_RATE,
FLIGHT_MODE_ANGLES
} FlightMode_t;
#define CONTROL_SERVO_REVERSE_ELEVATOR 1
#define CONTROL_SERVO_REVERSE_AILERONS 2
#define CONTROL_SERVO_REVERSE_RUDDER 4
typedef struct {
uint8_t SWMajor;
uint8_t SWMinor;
uint8_t protoMajor;
uint8_t protoMinor;
uint8_t SWPatch;
uint8_t hardwareErrors[5];
}__attribute__((packed)) VersionInfo_t;
extern VersionInfo_t versionInfo;
typedef struct {
// IMU stuff:
PID_t gyroPID[3];
// Control
/* P */uint8_t externalControl;
// 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;
*/
typedef struct {
uint8_t channels[MAX_CHANNELS];
} channelMap_t;
extern channelMap_t channelMap;
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;
// values above 250 representing poti1 to poti4
typedef struct {
// Global bitflags
uint8_t bitConfig; // see upper defines for bitcoding
// Control
PIDIM_t gyroPID[3];
uint8_t stickIElevator;
uint8_t stickIAilerons;
uint8_t stickIRudder;
uint8_t externalControl; // for serial Control
uint8_t IFactor;
uint8_t batteryVoltageWarning;
uint8_t emergencyThrottle;
uint8_t emergencyFlightDuration;
// Airspeed
uint8_t airspeedCorrection;
uint8_t isFlyingThreshold;
// Servos
uint8_t controlServosReverse;
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;
// bit mask for staticParams.bitConfig
#define CFG_GYRO_SATURATION_PREVENTION (1<<0)
#define CFG_USE_AIRSPEED_PID (1<<1)
#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 SYSCLK F_CPU
// Not really a part of configuration, but LEDs and HW s test are the same.
#define RED_OFF {PORTD &=~(1<<PORTD6);}
#define RED_ON {PORTD |= (1<<PORTD6);}
#define RED_FLASH PORTD ^= (1<<PORTD6)
#define GRN_OFF {PORTD &=~(1<<PORTD7);}
#define GRN_ON {PORTD |= (1<<PORTD7);}
#define GRN_FLASH PORTD ^= (1<<PORTD7)
// Mixer table
#define MIX_THROTTLE 0
#define MIX_PITCH 1
#define MIX_ROLL 2
#define MIX_YAW 3
#define VARIABLE_COUNT 8
extern int16_t variables[VARIABLE_COUNT]; // The "Poti"s.
extern uint8_t CPUType;
extern volatile uint16_t isFlying;
extern FlightMode_t currentFlightMode;
void IMUConfig_default(void);
void channelMap_default(void);
void paramSet_default(uint8_t setnumber);
void configuration_setFlightParameters(uint8_t newFlightMode);
void configuration_applyVariablesToParams(void);
void setCPUType(void);
// Called after a change in configuration parameters, as a hook for modules to take over changes.
void configuration_paramSetDidChange(void);
#endif // _CONFIGURATION_H