mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-14 03:50:02 +03:00
renamed orient to align for sensor orientation
implemented battery cell count auto detect (DJI, you can steal this source from me for your next product). automatically finds 2S..6S battery, and sets warning voltage accordingly added new battery config -related stuff in cli, min/max cell voltage for non-lipo users. Defaults for lipo are 4.3V/cell (max) and 3.3V/cell (min). added pid setting stuff into cli from nicodh added 'status' command to cli to print out system info. added build date/time to 'version' in cli, to track down stupid users. config version bumped, settings are cleared again. refactored battery voltage stuff a bit, and got rid of 3 levels of warnings. don't see any benefit at all. git-svn-id: https://afrodevices.googlecode.com/svn/trunk/baseflight@121 7c89a4a9-59b9-e629-4cfe-3a2d53b20e61
This commit is contained in:
parent
8bcbf5e41e
commit
c526d2f3b9
13 changed files with 2612 additions and 2350 deletions
|
@ -13,6 +13,8 @@ extern int16_t AccInflightCalibrationArmed;
|
|||
extern uint16_t AccInflightCalibrationMeasurementDone;
|
||||
extern uint16_t AccInflightCalibrationSavetoEEProm;
|
||||
extern uint16_t AccInflightCalibrationActive;
|
||||
extern uint16_t batteryWarningVoltage;
|
||||
extern uint8_t batteryCellCount;
|
||||
|
||||
sensor_t acc; // acc access functions
|
||||
sensor_t gyro; // gyro access functions
|
||||
|
@ -45,6 +47,34 @@ void sensorsAutodetect(void)
|
|||
gyro.init();
|
||||
}
|
||||
|
||||
uint16_t batteryAdcToVoltage(uint16_t src)
|
||||
{
|
||||
// calculate battery voltage based on ADC reading
|
||||
// result is Vbatt in 0.1V steps. 3.3V = ADC Vref, 4095 = 12bit adc, 110 = 11:1 voltage divider (10k:1k) * 10 for 0.1V
|
||||
return (((src) * 3.3f) / 4095) * cfg.vbatscale;
|
||||
}
|
||||
|
||||
void batteryInit(void)
|
||||
{
|
||||
uint8_t i;
|
||||
uint32_t voltage = 0;
|
||||
|
||||
for (i = 0; i < 32; i++) {
|
||||
voltage += adcGetBattery();
|
||||
delay(10);
|
||||
}
|
||||
|
||||
voltage = batteryAdcToVoltage((uint16_t)(voltage / 32));
|
||||
|
||||
// autodetect cell count, going from 2S..6S
|
||||
for (i = 2; i < 6; i++) {
|
||||
if (voltage < i * cfg.vbatmaxcellvoltage)
|
||||
break;
|
||||
}
|
||||
batteryCellCount = i;
|
||||
batteryWarningVoltage = i * cfg.vbatmincellvoltage; // 3.3V per cell minimum, configurable in CLI
|
||||
}
|
||||
|
||||
static void ACC_Common(void)
|
||||
{
|
||||
static int32_t a[3];
|
||||
|
@ -132,7 +162,7 @@ static void ACC_Common(void)
|
|||
void ACC_getADC(void)
|
||||
{
|
||||
acc.read(accADC);
|
||||
acc.orient(accADC);
|
||||
acc.align(accADC);
|
||||
|
||||
ACC_Common();
|
||||
}
|
||||
|
@ -237,7 +267,7 @@ void Gyro_getADC(void)
|
|||
{
|
||||
// range: +/- 8192; +/- 2000 deg/sec
|
||||
gyro.read(gyroADC);
|
||||
gyro.orient(gyroADC);
|
||||
gyro.align(gyroADC);
|
||||
|
||||
GYRO_Common();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue