masenga01 / aeroquad

Automatically exported from code.google.com/p/aeroquad
0 stars 0 forks source link

Multiple battery support #121

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
The, current battery monitor only follows the battery powering arduino.

I think quite a few of us are using multiple powersources like 1x2S for 
electronics and 1-2x3S for motors.

Battery monitor should be made scalable to support at least 3 batteries and 
preferably also current sensors.

Current sensors would enable counting remainin bat capacity which would be very 
useful with the OSD coming later.

I might have some time to work on 'JuiceMonitor' so there might be some code at 
some point.

Original issue reported on code.google.com by khau...@gmail.com on 15 May 2011 at 6:03

GoogleCodeExporter commented 9 years ago
I have now some code in testing.
- based on BatteryMonitor but heavy rewrite at places
- supports arbitary number of batteries (usually 2 thou)
- only Aeroquad v2 (for simplicity)
- 'OR' alarm (any battery going to alarm state causes global alarm/auto descent)
- measures voltage and current (with external voltage output sensors)
- OSD pieces done

Still going to add capacity (mAh) counter before publishing.

Original comment by khau...@gmail.com on 14 Jun 2011 at 8:12

GoogleCodeExporter commented 9 years ago
Preliminary code, not really tested

diff -ru AeroQuad.callsign/AeroQuad.pde AeroQuad/AeroQuad.pde
--- AeroQuad.callsign/AeroQuad.pde      2011-06-05 16:45:48.000000000 +0300
+++ AeroQuad/AeroQuad.pde       2011-06-14 22:04:37.000000000 +0300
@@ -60,14 +60,15 @@
 // *******************************************************************************************************************************
 #define HeadingMagHold // Enables HMC5843 Magnetometer, gets automatically selected if CHR6DM is defined
 #define AltitudeHold // Enables BMP085 Barometer (experimental, use at your own risk)
-#define BattMonitor //define your personal specs in BatteryMonitor.h! Full 
documentation with schematic there
+//#define BattMonitor //define your personal specs in BatteryMonitor.h! Full 
documentation with schematic there
+#define JuicMonitor //define your personal specs in BatteryMonitor.h! Full 
documentation with schematic there
 //#define RateModeOnly // Use this if you only have a gyro sensor, this will disable any attitude modes.
 // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 // You must define *only* one of the following 2 flightAngle calculations
 // if you only want DCM, then don't define either of the below
 // flightAngle recommendations: use FlightAngleARG if you do not have a magnetometer, use DCM if you have a magnetometer installed
 // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-//#define FlightAngleMARG // Experimental!  Fly at your own risk! Use this if 
you have a magnetometer installed and enabled HeadingMagHold above
+#define FlightAngleMARG // Experimental!  Fly at your own risk! Use this if 
you have a magnetometer installed and enabled HeadingMagHold above
 //#define FlightAngleARG // Use this if you do not have a magnetometer installed
 //#define WirelessTelemetry  // Enables Wireless telemetry on Serial3  // Wireless telemetry enable
 //#define BinaryWrite // Enables fast binary transfer of flight data to Configurator
@@ -83,10 +84,10 @@
 // D13 to D35 for yaw, connect servo to SERVO3
 // Please note that you will need to have battery connected to power on servos with v2.0 shield
 // *******************************************************************************************************************************
-//#define CameraControl
+#define CameraControl

 // On screen display implementation using MAX7456 chip. See OSD.h for more info and configuration.
-//#define MAX7456_OSD
+#define MAX7456_OSD

 /****************************************************************************
  ********************* End of User Definition Section ***********************
@@ -262,6 +263,10 @@
     #include "BatteryMonitor.h"
     BatteryMonitor_AeroQuad batteryMonitor;
   #endif
+  #ifdef JuicMonitor
+    #include "JuiceMonitor.h"
+    JuiceMonitor_AeroQuad juiceMonitor;
+  #endif
   #ifdef CameraControl
     #include "Camera.h"
     Camera_AeroQuad camera;
@@ -532,6 +537,11 @@
   #ifdef BattMonitor
     batteryMonitor.initialize();
   #endif
+
+  // Juice Monitor
+  #ifdef JuicMonitor
+    juiceMonitor.initialize();
+  #endif

   // Camera stabilization setup
   #ifdef CameraControl
@@ -762,6 +772,9 @@
         #if defined(BattMonitor)
           batteryMonitor.measure(armed);
         #endif
+        #if defined(JuicMonitor)
+          juiceMonitor.measure(armed);
+        #endif
       }
       // Listen for configuration commands and reports telemetry
       if (telemetryLoop == ON) {
Only in AeroQuad: JuiceMonitor.h
diff -ru AeroQuad.callsign/OSD.h AeroQuad/OSD.h
--- AeroQuad.callsign/OSD.h     2011-06-15 07:40:53.000000000 +0300
+++ AeroQuad/OSD.h      2011-06-14 22:19:18.000000000 +0300
@@ -40,11 +40,11 @@
 #define ShowFlightTimer        //Displays how long the motors have been armed for since the Arduino was last reset
 #define ShowAttitudeIndicator
 #define ShowCallSign
-#define feet                   //Comment this line out for altitude measured 
in metres, uncomment it for feet
+//#define feet                   //Comment this line out for altitude measured 
in metres, uncomment it for feet

 //Choose your video standard:
-#define NTSC
-//#define PAL
+//#define NTSC
+#define PAL

 //You can configure positioning of various display elements below. #defines for elements which will not be displayed, can be ignored.
 //The MAX7456 overlays characters in a grid 30 characters wide, 16/13 high (PAL/NTSC respectively). The row/column defines below
@@ -72,6 +72,12 @@
 byte *callsign = (byte*)"OH2FXR";
 #endif

+//Juice monitor, two battery config
+#define JUICE_ROW 0
+#define JUICE_COL 0
+#define JUICE_ROWS 2
+#define JUICE_SYMBOL(x) (((x)==0)?0x04:0x0a)
+
 /********************** End of user configuration section ********************************/

 //OSD pins on AQ v2 shield:
@@ -227,9 +233,9 @@
     #endif

     #ifdef ShowCallSign
-      writeChars( callsign, strlen((char*)callsign), CALLSIGN_ROW, 
CALLSIGN_COL );
-    #endif
-
+    writeChars( callsign, strlen((char*)callsign), CALLSIGN_ROW, CALLSIGN_COL 
);
+    #endif
+
     #ifdef ShowFlightTimer
     updateTimer();
     #endif
@@ -245,6 +251,10 @@
     #ifdef BatteryMonitor
     updateVoltage();
     #endif
+
+    #ifdef JuicMonitor
+    updateJuice();
+    #endif
   }

@@ -356,6 +366,24 @@
   }
 #endif

+#ifdef JuicMonitor
+  void updateJuice(void) {
+     byte buf[13] = {0,0,0,0,0,0,0,0,0,0,0,0,0}; // Sxx.xVxxx.xA
+     for (byte i=0; i<JUICE_ROWS; i++) {
+       if (juiceMonitor.isI(i)) {
+         unsigned _u = 10.0 * juiceMonitor.getU(i);
+         unsigned _i = 10.0 * juiceMonitor.getI(i);
+         
snprintf((char*)buf,13,"%c%2u.%1uV%3u.%1uA",JUICE_SYMBOL(i),_u/10,_u%10,_i/10,_i
%10);
+       } else {
+         unsigned _u = 10.0 * juiceMonitor.getU(i);
+         snprintf((char*)buf,13,"%c%2u.%1uV",JUICE_SYMBOL(i),_u/10,_u%10);
+       }
+       writeChars( buf, 12, JUICE_ROW+i, JUICE_COL );
+     }
+   }
+#endif
+
+
 #ifdef AltitudeHold
   float currentAltitude;
   void updateAltitude(void) {
@@ -485,6 +513,10 @@
       }
     #endif

+    #ifdef JuicMonitor
+        updateJuice();
+    #endif
+
     #ifdef AltitudeHold
       if( (unsigned)(altitude.getData()) != (unsigned)(currentAltitude) ) {
         updateAltitude();

Original comment by khau...@gmail.com on 15 Jun 2011 at 6:29

Attachments:

GoogleCodeExporter commented 9 years ago
Added capacity counter

diff -ru AeroQuad.callsign/AeroQuad.pde AeroQuad/AeroQuad.pde
--- AeroQuad.callsign/AeroQuad.pde      2011-06-05 16:45:48.000000000 +0300
+++ AeroQuad/AeroQuad.pde       2011-06-14 22:04:37.000000000 +0300
@@ -60,14 +60,15 @@
 // *******************************************************************************************************************************
 #define HeadingMagHold // Enables HMC5843 Magnetometer, gets automatically selected if CHR6DM is defined
 #define AltitudeHold // Enables BMP085 Barometer (experimental, use at your own risk)
-#define BattMonitor //define your personal specs in BatteryMonitor.h! Full 
documentation with schematic there
+//#define BattMonitor //define your personal specs in BatteryMonitor.h! Full 
documentation with schematic there
+#define JuicMonitor //define your personal specs in BatteryMonitor.h! Full 
documentation with schematic there
 //#define RateModeOnly // Use this if you only have a gyro sensor, this will disable any attitude modes.
 // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 // You must define *only* one of the following 2 flightAngle calculations
 // if you only want DCM, then don't define either of the below
 // flightAngle recommendations: use FlightAngleARG if you do not have a magnetometer, use DCM if you have a magnetometer installed
 // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-//#define FlightAngleMARG // Experimental!  Fly at your own risk! Use this if 
you have a magnetometer installed and enabled HeadingMagHold above
+#define FlightAngleMARG // Experimental!  Fly at your own risk! Use this if 
you have a magnetometer installed and enabled HeadingMagHold above
 //#define FlightAngleARG // Use this if you do not have a magnetometer installed
 //#define WirelessTelemetry  // Enables Wireless telemetry on Serial3  // Wireless telemetry enable
 //#define BinaryWrite // Enables fast binary transfer of flight data to Configurator
@@ -83,10 +84,10 @@
 // D13 to D35 for yaw, connect servo to SERVO3
 // Please note that you will need to have battery connected to power on servos with v2.0 shield
 // *******************************************************************************************************************************
-//#define CameraControl
+#define CameraControl

 // On screen display implementation using MAX7456 chip. See OSD.h for more info and configuration.
-//#define MAX7456_OSD
+#define MAX7456_OSD

 /****************************************************************************
  ********************* End of User Definition Section ***********************
@@ -262,6 +263,10 @@
     #include "BatteryMonitor.h"
     BatteryMonitor_AeroQuad batteryMonitor;
   #endif
+  #ifdef JuicMonitor
+    #include "JuiceMonitor.h"
+    JuiceMonitor_AeroQuad juiceMonitor;
+  #endif
   #ifdef CameraControl
     #include "Camera.h"
     Camera_AeroQuad camera;
@@ -532,6 +537,11 @@
   #ifdef BattMonitor
     batteryMonitor.initialize();
   #endif
+
+  // Juice Monitor
+  #ifdef JuicMonitor
+    juiceMonitor.initialize();
+  #endif

   // Camera stabilization setup
   #ifdef CameraControl
@@ -762,6 +772,9 @@
         #if defined(BattMonitor)
           batteryMonitor.measure(armed);
         #endif
+        #if defined(JuicMonitor)
+          juiceMonitor.measure(armed);
+        #endif
       }
       // Listen for configuration commands and reports telemetry
       if (telemetryLoop == ON) {
Only in AeroQuad: JuiceMonitor.h
diff -ru AeroQuad.callsign/OSD.h AeroQuad/OSD.h
--- AeroQuad.callsign/OSD.h     2011-06-15 07:40:53.000000000 +0300
+++ AeroQuad/OSD.h      2011-06-15 10:37:50.000000000 +0300
@@ -40,11 +40,11 @@
 #define ShowFlightTimer        //Displays how long the motors have been armed for since the Arduino was last reset
 #define ShowAttitudeIndicator
 #define ShowCallSign
-#define feet                   //Comment this line out for altitude measured 
in metres, uncomment it for feet
+//#define feet                   //Comment this line out for altitude measured 
in metres, uncomment it for feet

 //Choose your video standard:
-#define NTSC
-//#define PAL
+//#define NTSC
+#define PAL

 //You can configure positioning of various display elements below. #defines for elements which will not be displayed, can be ignored.
 //The MAX7456 overlays characters in a grid 30 characters wide, 16/13 high (PAL/NTSC respectively). The row/column defines below
@@ -54,13 +54,13 @@
 // columns remaining on the row you specify.

 //Battery voltage - 5 characters long
-#define VOLTAGE_ROW 0
+#define VOLTAGE_ROW 1
 #define VOLTAGE_COL 0
 //Compass reading - 5 characters long
 #define COMPASS_ROW 0
 #define COMPASS_COL 13
 //Altitude reading - up to 8 characters long (32768 max)
-#define ALTITUDE_ROW 2
+#define ALTITUDE_ROW 0
 #define ALTITUDE_COL 0
 //Flight timer - 6 characters long
 #define TIMER_ROW 0
@@ -72,6 +72,12 @@
 byte *callsign = (byte*)"OH2FXR";
 #endif

+//Juice monitor, two battery config
+#define JUICE_ROW 1
+#define JUICE_COL 0
+#define JUICE_ROWS 2
+#define JUICE_SYMBOL(x) (((x)==0)?0x04:0x0a)
+
 /********************** End of user configuration section ********************************/

 //OSD pins on AQ v2 shield:
@@ -227,9 +233,9 @@
     #endif

     #ifdef ShowCallSign
-      writeChars( callsign, strlen((char*)callsign), CALLSIGN_ROW, 
CALLSIGN_COL );
-    #endif
-
+    writeChars( callsign, strlen((char*)callsign), CALLSIGN_ROW, CALLSIGN_COL 
);
+    #endif
+
     #ifdef ShowFlightTimer
     updateTimer();
     #endif
@@ -245,6 +251,10 @@
     #ifdef BatteryMonitor
     updateVoltage();
     #endif
+
+    #ifdef JuicMonitor
+    updateJuice();
+    #endif
   }

@@ -356,6 +366,24 @@
   }
 #endif

+#ifdef JuicMonitor
+  void updateJuice(void) {
+     byte buf[20] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; // Sxx.xVxxx.xA
+     for (byte i=0; i<JUICE_ROWS; i++) {
+       if (juiceMonitor.isI(i)) {
+         unsigned _u = 10.0 * juiceMonitor.getU(i);
+         unsigned _i = 10.0 * juiceMonitor.getI(i);
+         
snprintf((char*)buf,20,"%c%2u.%1uV%3u.%1uA%4umAh",JUICE_SYMBOL(i),_u/10,_u%10,_i
/10,_i%10,(unsigned)juiceMonitor.getC(i));
+       } else {
+         unsigned _u = 10.0 * juiceMonitor.getU(i);
+         snprintf((char*)buf,20,"%c%2u.%1uV",JUICE_SYMBOL(i),_u/10,_u%10);
+       }
+       writeChars( buf, 19, JUICE_ROW+i, JUICE_COL );
+     }
+   }
+#endif
+
+
 #ifdef AltitudeHold
   float currentAltitude;
   void updateAltitude(void) {
@@ -485,6 +513,10 @@
       }
     #endif

+    #ifdef JuicMonitor
+        updateJuice();
+    #endif
+
     #ifdef AltitudeHold
       if( (unsigned)(altitude.getData()) != (unsigned)(currentAltitude) ) {
         updateAltitude();

Original comment by family.h...@gmail.com on 15 Jun 2011 at 11:02

Attachments:

GoogleCodeExporter commented 9 years ago
I'm thinking about making it possible to swap only engine battery keeping CPU 
running (and GPS which may take long time to initialize) and thus reset the 
capacity when voltage goes to zero for some time.

Original comment by family.h...@gmail.com on 16 Jun 2011 at 7:50

GoogleCodeExporter commented 9 years ago
Thanks for the recommendations.  We'll look at getting it into v3 or future 
version.

Original comment by CaranchoEngineering@gmail.com on 25 Jun 2011 at 4:52