Subversion Repositories FlightCtrl

Compare Revisions

Ignore whitespace Rev 1964 → Rev 1965

/branches/dongfang_FC_rewrite/ADXRS610_FC2.0.c
5,6 → 5,7
const uint8_t ACC_REVERSED[3] = { 0, 1, 0 };
 
void gyro_calibrate(void) {
// Nothing to calibrate.
}
 
void gyro_setDefaults(void) {
/branches/dongfang_FC_rewrite/ENC-03_FC1.3.c
31,17 → 31,17
factor = GYRO_SUMMATION_FACTOR_PITCHROLL;
 
if (rawGyroSum[axis] < 510 * factor)
DACValues[axis]--;
DACValues.offsets[axis]--;
else if (rawGyroSum[axis] > 515 * factor)
DACValues[axis]++;
DACValues.offsets[axis]++;
else
numberOfAxesInRange++;
 
/* Gyro is defective. But do keep DAC within bounds (it's an op amp not a differential amp). */
if (DACValues[axis] < 10) {
DACValues[axis] = 10;
} else if (DACValues[axis] > 245) {
DACValues[axis] = 245;
if (DACValues.offsets[axis] < 10) {
DACValues.offsets[axis] = 10;
} else if (DACValues.offsets[axis] > 245) {
DACValues.offsets[axis] = 245;
}
}
 
/branches/dongfang_FC_rewrite/analog.c
103,8 → 103,9
* to be centered on zero.
*/
 
sensorOffset_t gyroOffset;
sensorOffset_t accOffset;
volatile sensorOffset_t gyroOffset;
volatile sensorOffset_t accOffset;
volatile sensorOffset_t DACValues;
 
/*
* This allows some experimentation with the gyro filters.
/branches/dongfang_FC_rewrite/analog.h
1,11 → 1,8
#ifndef _ANALOG_H
#define _ANALOG_H
#include <inttypes.h>
#include "configuration.h"
 
//#include "invenSense.h"
//#include "ENC-03_FC1.3.h"
//#include "ADXRS610_FC2.0.h"
 
/*
* How much low pass filtering to apply for gyro_PID.
* 0=illegal, 1=no filtering, 2=50% last value + 50% new value, 3=67% last value + 33 % new value etc...
188,13 → 185,10
// 1:11 voltage divider, 1024 counts per 3V, and result is divided by 3.
#define UBAT_AT_5V (int16_t)((5.0 * (1.0/11.0)) * 1024 / (3.0 * 3))
 
typedef struct {
int16_t offsets[3];
} sensorOffset_t;
extern volatile sensorOffset_t gyroOffset;
extern volatile sensorOffset_t accOffset;
extern volatile sensorOffset_t DACValues;
 
extern sensorOffset_t gyroOffset;
extern sensorOffset_t accOffset;
 
/*
* This is not really for external use - but the ENC-03 gyro modules needs it.
*/
/branches/dongfang_FC_rewrite/configuration.h
66,6 → 66,10
extern mixerMatrix_t mixerMatrix;
 
typedef struct {
int16_t offsets[3];
} sensorOffset_t;
 
typedef struct {
uint8_t manualControl;
uint8_t compensationFactor;
uint8_t minValue;
/branches/dongfang_FC_rewrite/eeprom.c
224,11 → 224,13
/* Sensor offsets */
/***************************************************/
uint8_t gyroOffset_readFromEEProm(void) {
return readChecksummedBlock(SENSOROFFSET_REVISION, (uint8_t*)&gyroOffset, EEPROM_ADR_GYROOFFSET, sizeof(sensorOffset_t));
return readChecksummedBlock(SENSOROFFSET_REVISION, (uint8_t*)&gyroOffset, EEPROM_ADR_GYROOFFSET, sizeof(sensorOffset_t)) |
readChecksummedBlock(SENSOROFFSET_REVISION, (uint8_t*)&DACValues, EEPROM_ADR_DACVALUES, sizeof(sensorOffset_t));
}
 
void gyroOffset_writeToEEProm(void) {
writeChecksummedBlock(SENSOROFFSET_REVISION, (uint8_t*)&gyroOffset, EEPROM_ADR_GYROOFFSET, sizeof(sensorOffset_t));
writeChecksummedBlock(SENSOROFFSET_REVISION, (uint8_t*)&DACValues, EEPROM_ADR_DACVALUES, sizeof(sensorOffset_t));
}
 
uint8_t accOffset_readFromEEProm(void) {
/branches/dongfang_FC_rewrite/eeprom.h
7,23 → 7,17
 
#define EEPROM_ADR_PARAM_BEGIN 0
 
#define PID_ACTIVE_SET 2 // byte
//#define PID_PRESSURE_OFFSET 3 // byte
//#define PID_ACC_PITCH 4 // word
//#define PID_ACC_ROLL 6 // word
//#define PID_ACC_Z 8 // word
#define PID_ACTIVE_SET 0 // byte
#define EEPROM_ADR_ACCOFFSET 1
#define EEPROM_ADR_GYROOFFSET (EEPROM_ADR_ACCOFFSET+sizeof(sensorOffset_t)+2)
#define EEPROM_ADR_DACVALUES (EEPROM_ADR_GYROOFFSET+sizeof(sensorOffset_t)+2)
#define EEPROM_ADR_CHANNELMAP (EEPROM_ADR_GYROOFFSET+sizeof(sensorOffset_t)+2)
#define EEPROM_ADR_MIXER_TABLE (EEPROM_ADR_CHANNELMAP+sizeof(channelMap_t)+2)
#define EEPROM_ADR_PARAMSET_BEGIN (EEPROM_ADR_CHANNELMAP+sizeof(mixerMatrix_t)+2)
 
#define EEPROM_ADR_ACCOFFSET 20
#define EEPROM_ADR_GYROOFFSET 40
#define EEPROM_ADR_CHANNELMAP 80
 
#define EEPROM_ADR_PARAMSET_BEGIN 100
 
#define EEPROM_ADR_MIXER_TABLE 1000
 
#define CHANNELMAP_REVISION 0
#define EEPARAM_REVISION 0
#define EEMIXER_REVISION 0
#define EEPARAM_REVISION 0
#define EEMIXER_REVISION 0
#define SENSOROFFSET_REVISION 0
 
extern void paramSet_readOrDefault(void);
/branches/dongfang_FC_rewrite/sensors.h
13,6 → 13,8
*/
extern const uint8_t ACC_REVERSED[3];
 
extern volatile sensorOffset_t DACValues;
 
/*
* Common procedures for all gyro types.
* FC 1.3 hardware: Searching the DAC values that return neutral readings.
/branches/dongfang_FC_rewrite/twimaster.c
53,10 → 53,9
#include <avr/interrupt.h>
#include <util/twi.h>
#include <util/delay.h>
//#include "eeprom.h"
#include "twimaster.h"
//#include "analog.h"
#include "configuration.h"
#include "analog.h"
#include "printf_P.h"
 
volatile uint8_t twi_state = TWI_STATE_MOTOR_TX;
66,9 → 65,8
volatile uint16_t I2CTimeout = 100;
uint8_t missingMotor = 0;
 
MotorData_t motor[MAX_MOTORS];
motorData_t motor[MAX_MOTORS];
 
volatile uint8_t DACValues[4];
uint8_t DACChannel = 0;
 
#define SCL_CLOCK 200000L
261,7 → 259,7
break;
 
case 9:
I2C_WriteByte(DACValues[DACChannel]);
I2C_WriteByte(DACValues.offsets[DACChannel]);
break;
 
case 10:
/branches/dongfang_FC_rewrite/twimaster.h
9,11 → 9,8
#define TWI_STATE_GYRO_OFFSET_TX 7
 
extern volatile uint8_t twi_state;
 
extern uint8_t missingMotor;
 
volatile extern uint8_t DACValues[4];
 
typedef struct {
uint8_t SetPoint; // written by attitude controller
uint8_t Present; // 0 if BL was found
20,9 → 17,9
uint8_t Error; // I2C error counter
uint8_t Current; // read byck from BL
uint8_t MaxPWM; // read back from BL
}__attribute__((packed)) MotorData_t;
}__attribute__((packed)) motorData_t;
 
extern MotorData_t motor[MAX_MOTORS];
extern motorData_t motor[MAX_MOTORS];
 
extern volatile uint16_t I2CTimeout;