Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #132 from kh4/bm_for_3.0.2

Bm for 3.0.2
  • Loading branch information...
commit b3f7a08265329e2b0226c3e54690f8c0f03c713b 2 parents aa00184 + fa64eae
@Kenny9999 Kenny9999 authored
View
38 AeroQuad/AeroQuad.ino
@@ -169,8 +169,7 @@
// Battery Monitor declaration
#ifdef BattMonitor
- struct BatteryData batteryData[] = {
- BM_DEFINE_BATTERY_V(BattCellCount, 0, ((5.0 / 1024.0) * (15.0 + 7.5) / 7.5), 0.9)};
+ #define BattDefaultConfig DEFINE_BATTERY(0, 0, 15, 0.9, BM_NOPIN, 0, 0)
#else
#undef BattMonitorAutoDescent
#undef BattCellCount
@@ -233,8 +232,7 @@
// Battery Monitor declaration
#ifdef BattMonitor
- struct BatteryData batteryData[] = {
- BM_DEFINE_BATTERY_V(BattCellCount, 0, ((5.0 / 1024.0) * (15.0 + 7.5) / 7.5), 0.53)};
+ #define BattDefaultConfig DEFINE_BATTERY(0, 0, 15.0, 0.53, BM_NOPIN, 0, 0)
#else
#undef BattMonitorAutoDescent
#undef BattCellCount
@@ -355,11 +353,9 @@
// Battery Monitor declaration
#ifdef BattMonitor
#ifdef POWERED_BY_VIN
- struct BatteryData batteryData[] = {
- BM_DEFINE_BATTERY_V(BattCellCount, 0, ((5.0 / 1024.0) * (15.0 + 7.5) / 7.5), 0.0)};// v2 shield powered via VIN (no diode)
+ #define BattDefaultConfig DEFINE_BATTERY(0, 0, 15.0, 0, BM_NOPIN, 0, 0) // v2 shield powered via VIN (no diode)
#else
- struct BatteryData batteryData[] = {
- BM_DEFINE_BATTERY_V(BattCellCount, 0, ((5.0 / 1024.0) * (15.0 + 7.5) / 7.5),0.82)}; // v2 shield powered via power jack
+ #define BattDefaultConfig DEFINE_BATTERY(0, 0, 15.0, 0.82, BM_NOPIN, 0, 0) // v2 shield powered via power jack
#endif
#else
#undef BattMonitorAutoDescent
@@ -444,11 +440,9 @@
// Battery Monitor declaration
#ifdef BattMonitor
#ifdef POWERED_BY_VIN
- struct BatteryData batteryData[] = {
- BM_DEFINE_BATTERY_V(BattCellCount, 0, ((5.0 / 1024.0) * (15.0 + 7.5) / 7.5), 0.0)};// v2 shield powered via VIN (no diode)
+ #define BattDefaultConfig DEFINE_BATTERY(0, 0, 15.0, 0, BM_NOPIN, 0, 0) // v2 shield powered via VIN (no diode)
#else
- struct BatteryData batteryData[] = {
- BM_DEFINE_BATTERY_V(BattCellCount, 0, ((5.0 / 1024.0) * (15.0 + 7.5) / 7.5),0.82)}; // v2 shield powered via power jack
+ #define BattDefaultConfig DEFINE_BATTERY(0, 0, 15.0, 0.82, BM_NOPIN, 0, 0) // v2 shield powered via power jack
#endif
#else
#undef BattMonitorAutoDescent
@@ -533,8 +527,7 @@
// Battery monitor declaration
#ifdef BattMonitor
- struct BatteryData batteryData[] = {
- BM_DEFINE_BATTERY_V(BattCellCount, 0, ((3.27 / 1024.0) * (10.050 + 3.26) / 3.26), 0.306)};
+ #define BattDefaultConfig DEFINE_BATTERY(0, 0, 13.35, 0.31, BM_NOPIN, 0, 0)
#else
#undef BattMonitorAutoDescent
#undef BattCellCount
@@ -666,8 +659,7 @@
// Battery monitor declaration
#ifdef BattMonitor
- struct BatteryData batteryData[] = {
- BM_DEFINE_BATTERY_V(BattCellCount, 0, ((5.0 / 1024.0) * (15.0 + 7.5) / 7.5), 0.9)};
+ #define BattDefaultConfig DEFINE_BATTERY(0, 0, 15.0, 0.9, BM_NOPIN, 0, 0)
#else
#undef BattMonitorAutoDescent
#undef BattCellCount
@@ -742,8 +734,7 @@
// Battery monitor declaration
#ifdef BattMonitor
- struct BatteryData batteryData[] = {
- BM_DEFINE_BATTERY_V(BattCellCount, 0, ((3.27 / 1024.0) * (10.050 + 3.260) / 3.260), 0.9)};
+ #define BattDefaultConfig DEFINE_BATTERY(0, 0, 13.35, 0.9, BM_NOPIN, 0, 0)
#else
#undef BattMonitorAutoDescent
#undef BattCellCount
@@ -822,8 +813,7 @@
// Battery monitor declaration
#ifdef BattMonitor
- struct BatteryData batteryData[] = {
- BM_DEFINE_BATTERY_V(BattCellCount, 0, ((3.27 / 1024.0) * (10.050 + 3.260) / 3.260), 0.306)};
+ #define BattDefaultConfig DEFINE_BATTERY(0, 0, 13.35, 0.31, BM_NOPIN, 0, 0)
#else
#undef BattMonitorAutoDescent
#undef BattCellCount
@@ -957,6 +947,10 @@
//********************************************************
#ifdef BattMonitor
#include <BatteryMonitor.h>
+ #ifndef BattCustomConfig
+ #define BattCustomConfig BattDefaultConfig
+ #endif
+ struct BatteryData batteryData[] = {BattCustomConfig};
#endif
//********************************************************
//************** CAMERA CONTROL DECLARATION **************
@@ -1328,7 +1322,7 @@ void loop () {
measureMagnetometer(kinematicsAngle[XAXIS], kinematicsAngle[YAXIS]);
#endif
#if defined(BattMonitor)
- measureBatteryVoltage(G_Dt);
+ measureBatteryVoltage(G_Dt*1000.0);
#endif
// Listen for configuration commands and reports telemetry
@@ -1357,4 +1351,4 @@ void loop () {
}
-
+
View
2  AeroQuad/SerialCom.h
@@ -531,7 +531,7 @@ void sendSerialTelemetry() {
PrintValueComma(0); // zero out unused motor channels
}
#ifdef BattMonitor
- PrintValueComma(batteryData[0].voltage);
+ PrintValueComma(batteryData[0].voltage/100.0);
#else
PrintValueComma(0);
#endif
View
2  AeroQuad/UserConfiguration.h
@@ -95,11 +95,9 @@
//#define BattMonitor // Enable Battery monitor
//#define BattMonitorAutoDescent // if you want the craft to auto descent when the battery reach the alarm voltage
//#define POWERED_BY_VIN // Uncomment this if your v2.x is powered directly by the vin/gnd of the arduino
-//#define BattBuzzer // Enable for low battery buzzer/LED
//
// Advanced configuration. Please refer to wiki for instructions
//#define BattCustomConfig DEFINE_BATTERY(cellcount,vpin,vscale,vbias,cpin,cscale,cbias) // cpin=BM_NOPIN if no sensor
-//#define BattCustomBuzzer pin1[,pin2]...
//
// *******************************************************************************************************************************
View
45 Libraries/AQ_BatteryMonitor/BatteryMonitor.h
@@ -27,25 +27,28 @@
byte numberOfBatteries = 0;
boolean batteryAlarm = false;
+boolean batteryWarning = false;
-float batteryAlarmCellVoltage = 3.33; // 10.0V on 3S
-float batteryWarningCellVoltage = 3.66; // 11.0V on 3S
+unsigned short batteryAlarmCellVoltage = 333; // 9.9V on 3S
+unsigned short batteryWarningCellVoltage = 366; // 11.0V on 3S
void setBatteryCellVoltageThreshold(float alarmVoltage) {
- batteryAlarmCellVoltage = alarmVoltage;
- batteryWarningCellVoltage = alarmVoltage*BM_WARNING_RATIO;
+ batteryAlarmCellVoltage = alarmVoltage*100.0;
+ batteryWarningCellVoltage = alarmVoltage*BM_WARNING_RATIO*100.0;
}
// Reset Battery statistics
void resetBattery(byte batno) {
if (batno < numberOfBatteries) {
- batteryData[batno].voltage = 12.0;
- batteryData[batno].minVoltage = 99.0;
- batteryData[batno].current = 0.0;
- batteryData[batno].maxCurrent = 0.0;
- batteryData[batno].usedCapacity = 0.0;
+ batteryData[batno].voltage = 1200;
+#ifdef BM_EXTENDED
+ batteryData[batno].minVoltage = 9900;
+ batteryData[batno].current = 0;
+ batteryData[batno].maxCurrent = 0;
+ batteryData[batno].usedCapacity = 0;
+#endif
}
}
@@ -56,17 +59,17 @@ void initializeBatteryMonitor(byte nb, float alarmVoltage) {
for (int i = 0; i < numberOfBatteries; i++) {
resetBattery(i);
}
- measureBatteryVoltage(0.0); // Initial measurement
+ measureBatteryVoltage(0); // Initial measurement
}
byte batteryGetCellCount(byte batNo) {
if (batteryData[batNo].cells) {
return batteryData[batNo].cells;
}
- else if (batteryData[batNo].voltage<5.0) {
+ else if (batteryData[batNo].voltage < 500) {
return 1;
}
- else if (batteryData[batNo].voltage<8.6) {
+ else if (batteryData[batNo].voltage < 860) {
return 2;
}
else {
@@ -90,25 +93,31 @@ boolean batteryIsWarning(byte batNo) {
return false;
}
-
-void measureBatteryVoltage(float deltaTime) {
+void measureBatteryVoltage(unsigned short deltaTime) {
batteryAlarm = false;
+ batteryWarning = false;
for (int i = 0; i < numberOfBatteries; i++) {
- batteryData[i].voltage = (float)analogRead(batteryData[i].vPin) * batteryData[i].vScale + batteryData[i].vBias;
+ batteryData[i].voltage = (long)analogRead(batteryData[i].vPin) * batteryData[i].vScale / 1024 + batteryData[i].vBias;
+#ifdef BM_EXTENDED
if (batteryData[i].voltage < batteryData[i].minVoltage) {
batteryData[i].minVoltage = batteryData[i].voltage;
}
if (batteryData[i].cPin != BM_NOPIN) {
- batteryData[i].current = (float)analogRead(batteryData[i].cPin) * batteryData[i].cScale + batteryData[i].cBias;
+ batteryData[i].current = (long)analogRead(batteryData[i].cPin) * batteryData[i].cScale * 10 / 1024 + batteryData[i].cBias * 10;
if (batteryData[i].current > batteryData[i].maxCurrent) {
batteryData[i].maxCurrent = batteryData[i].current;
}
- batteryData[i].usedCapacity += batteryData[i].current * deltaTime / 3.6; // current(A) * 1000 * time(s) / 3600 -> mAh
+ // current in 10mA , time in ms -> usedCapacity in uAh // i.e. / 360 <=> * ( 91 / 32768 )
+ batteryData[i].usedCapacity += (long)batteryData[i].current * (long)deltaTime * 91 / 32768;
}
+#endif
if (batteryIsAlarm(i)) {
batteryAlarm = true;
}
+ if (batteryIsWarning(i)) {
+ batteryWarning = true;
+ }
}
}
-#endif
+#endif
View
42 Libraries/AQ_BatteryMonitor/BatteryMonitorTypes.h
@@ -21,32 +21,40 @@
#ifndef _AQ_BATTERY_MONITOR_TYPES
#define _AQ_BATTERY_MONITOR_TYPES
+#if ! defined (__AVR_ATmega328P__) && ! defined(__AVR_ATmegaUNO__)
+ #define BM_EXTENDED
+#endif
+
#define BM_NOPIN 255
struct BatteryData {
- byte vPin,cPin; // A/D pins for voltage and current sensors (255 = BM_NOPIN <=> no sensor)
- byte cells; // Number of Cells (used for alarm/warning voltage
- float vScale,vBias; // voltage polynom V = vbias + AnalogIn(vpin)*vscale
- float cScale,cBias; // current polynom C = cbias + AnalogIn(cpin)*cscale
- float voltage; // Current battery voltage
- float current; // Current battery current
- float minVoltage; // Minimum voltage since reset
- float maxCurrent; // Maximum current since reset
- float usedCapacity; // Capacity used since reset (in mAh)
+ byte vPin; // A/D pin for voltage sensor
+ byte cells; // Number of Cells (used for alarm/warning voltage
+ short vScale,vBias; // voltage polynom V = vbias + AnalogIn(vpin)*vscale
+ unsigned short voltage; // Current battery voltage (in 10mV:s)
+#ifdef BM_EXTENDED
+ unsigned short minVoltage; // Minimum voltage since reset
+ byte cPin; // A/D pin for current sensor (255 = BM_NOPIN <=> no sensor)
+ short cScale,cBias; // current polynom C = cbias + AnalogIn(cpin)*cscale
+ short current; // Current battery current (in 10mA:s)
+ short maxCurrent; // Maximum current since reset
+ long usedCapacity; // Capacity used since reset (in uAh)
+#endif
};
-extern struct BatteryData batteryData[]; // BatteryMonitor config, !! MUST BE DEFINED BY MAIN SKETCH !!
+extern struct BatteryData batteryData[]; // BatteryMonitor config, !! MUST BE DEFINED BY MAIN SKETCH !!
extern byte numberOfBatteries; // number of batteries monitored, defined by BatteryMonitor
extern boolean batteryAlarm; // any battery in alarm state used for e.g. autodescent
+extern boolean batteryWarning; // any battery in warning state
// Helper macros to make battery definitions cleaner
-// for defining battery with just voltage sensing
-#define BM_DEFINE_BATTERY_V(CELLS,VPIN,VSCALE,VBIAS) {VPIN,BM_NOPIN,CELLS,VSCALE,VBIAS, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0},
-
-// for defining battery with voltage and current sensors
-#define BM_DEFINE_BATTERY_VC(CELLS,VPIN,VSCALE,VBIAS,CPIN,CSCALE,CBIAS) {VPIN,CPIN,CELLS,VSCALE,VBIAS, CSCALE, CBIAS, 0.0, 0.0, 0.0, 0.0, 0.0},
-
+// for defining battery with voltage and optional current sensors
+#ifdef BM_EXTENDED
+#define DEFINE_BATTERY(CELLS,VPIN,VSCALE,VBIAS,CPIN,CSCALE,CBIAS) {(VPIN),(CELLS),(VSCALE*100.0),(VBIAS*100.0),0,0,(CPIN),(CSCALE*10.0),(CBIAS*10.0),0,0,0}
+#else
+#define DEFINE_BATTERY(CELLS,VPIN,VSCALE,VBIAS,CPIN,CSCALE,CBIAS) {(VPIN),(CELLS),(VSCALE*100.0),(VBIAS*100.0),0}
+#endif
// Function declarations
boolean batteryIsAlarm(byte batteryNo);
@@ -54,5 +62,5 @@ boolean batteryIsWarning(byte batteryNo);
void resetBattery(byte batteryNo);
void initializeBatteryMonitor(byte numberOfMonitoredBatteries, float alarmVoltage);
void setBatteryCellVoltageThreshold(float alarmVoltage);
-void measureBatteryVoltage(float deltaTime);
+void measureBatteryVoltage(unsigned short deltaTime);
#endif
View
12 Libraries/AQ_OSD/MAX7456_BattMonitor.h
@@ -42,10 +42,10 @@ void displayVoltage(byte areMotorsArmed) {
int currentValue;
if (osdBatMinMax) {
- currentValue = batteryData[osdBatNo].minVoltage*10.0;
+ currentValue = batteryData[osdBatNo].minVoltage/10.0;
}
else {
- currentValue = batteryData[osdBatNo].voltage*10.0;
+ currentValue = batteryData[osdBatNo].voltage/10.0;
}
char buf[12];
@@ -58,17 +58,17 @@ void displayVoltage(byte areMotorsArmed) {
if (batteryData[osdBatNo].cPin != BM_NOPIN) {
// current sensor installed
if (osdBatMinMax) {
- currentValue = batteryData[osdBatNo].maxCurrent*10.0;
+ currentValue = batteryData[osdBatNo].maxCurrent/10.0;
}
else {
- currentValue = batteryData[osdBatNo].current*10.0;
+ currentValue = batteryData[osdBatNo].current/10.0;
}
if (abs(currentValue)>=100) { // > 10A only display whole amps
- snprintf(buf,12,"%4dA%5d\24 ", currentValue/10, (int)batteryData[osdBatNo].usedCapacity);
+ snprintf(buf,12,"%4dA%5ld\24 ", currentValue/10, batteryData[osdBatNo].usedCapacity/1000);
}
else {
- snprintf(buf,12,"%c%1d.%1dA%5d\24 ", currentValue<0?'-':' ',abs(currentValue/10),abs(currentValue%10),(int)batteryData[osdBatNo].usedCapacity);
+ snprintf(buf,12,"%c%1d.%1dA%5ld\24 ", currentValue<0?'-':' ',abs(currentValue/10),abs(currentValue%10),batteryData[osdBatNo].usedCapacity/1000);
}
writeChars( buf, 11, 0, VOLTAGE_ROW+osdBatNo, VOLTAGE_COL+6 );
Please sign in to comment.
Something went wrong with that request. Please try again.