Laelaps  2.3.5
RoadNarrows Robotics Small Outdoor Mobile Robot Project
laeBatt.cxx File Reference

Laelaps battery management and energy monitoring class implementation. More...

#include <sys/types.h>
#include <unistd.h>
#include <string>
#include "rnr/rnrconfig.h"
#include "rnr/log.h"
#include "Laelaps/laelaps.h"
#include "Laelaps/laeUtils.h"
#include "Laelaps/laeTune.h"
#include "Laelaps/laeMotor.h"
#include "Laelaps/laeDb.h"
#include "Laelaps/laeBatt.h"

Go to the source code of this file.

Classes

struct  LiIonCellSoCVEntry
 Lithium-Ion State of Charge - Cell Voltage table. More...
 
struct  LiIonCellCSoCEntry
 Specific Current - State of Charge/Battery Voltage table entry. More...
 

Functions

static double linearInterp (double x, double x0, double x1, double y0, double y1)
 Linear interpolate. More...
 
static double lookupSoC (double fV, LiIonCellSoCVEntry tbl[], size_t n)
 Lookup State of Charge, given the battery voltage. More...
 

Variables

static const double OdroidXU3MinAmps = 1.0
 
static const double OdroidXU3Volts = 1.8
 
static const double OdroidXU4MinAmps = 1.0
 
static const double OdroidXU4Volts = 1.8
 
static const double RoboClaw2x30AAmps = 0.03
 
static const double RoboClaw2x30AVolts = 5.0
 
static const double Naze32Amps = 0.50
 
static const double Naxe32Volts = 5.0
 
static const double BattChargerAmps = 0.0
 
static const double BattChargerVolts = 0.0
 
static const double ArduinoAmps = 0.01
 
static const double ArduinoVolts = 5.0
 
static const double OtherAmps = 0.01
 
static const double OtherVolts = 5.0
 
static LiIonCellSoCVEntry LiIonCellSoCVTbl_0C []
 SoC-V table for an 0C unloaded single cell. More...
 
static LiIonCellSoCVEntry LiIonCellSoCVTbl_1C []
 SoC-V table for an 1C single cell. More...
 
static LiIonCellSoCVEntry LiIonCellSoCVTbl_2C []
 SoC-V table for an 2C single cell. More...
 
static LiIonCellSoCVEntry LiIonCellSoCVTbl_3C []
 SoC-V table for an 3C single cell. More...
 
static LiIonCellCSoCEntry LiIonCellSoCTbls []
 C - SoC-V table of tables. More...
 

Detailed Description

Laelaps battery management and energy monitoring class implementation.

LastChangedDate
2016-03-02 11:18:30 -0700 (Wed, 02 Mar 2016)
Rev
4337

A class instance runs under the control of the WatchDog thread.

Author
Robin Knight (robin.nosp@m..kni.nosp@m.ght@r.nosp@m.oadn.nosp@m.arrow.nosp@m.s.co.nosp@m.m)
Copyright
© 2015-2017. RoadNarrows LLC.
http://www.roadnarrows.com
All Rights Reserved

Definition in file laeBatt.cxx.

Function Documentation

static double linearInterp ( double  x,
double  x0,
double  x1,
double  y0,
double  y1 
)
static

Linear interpolate.

Parameters
xX input in [x0, x1].
x0Lower domain value.
x1Upper domain value.
y0Lower range value.
y1Upper range value.
Returns
Interpolated Y output in [y0, y1].

Definition at line 195 of file laeBatt.cxx.

Referenced by laelaps::LaeBattery::estimateBatteryStateOfCharge(), and lookupSoC().

196 {
197  return y0 + (x - x0)/(x1 - x0) * (y1 - y0);
198 }
static double lookupSoC ( double  fV,
LiIonCellSoCVEntry  tbl[],
size_t  n 
)
static

Lookup State of Charge, given the battery voltage.

Linear interpolation is performed as necessary.

Parameters
fVInput battery voltage.
tblSoC - V table.
nNumber of table entries.
Returns
Interpolated SoC.

Definition at line 211 of file laeBatt.cxx.

References linearInterp(), and LiIonCellSoCVEntry::m_fSoC.

Referenced by laelaps::LaeBattery::estimateBatteryStateOfCharge().

212 {
213  size_t i;
214 
215  // table list voltage for single cell
216  fV /= (double)LaeTuneBattCells;
217 
218  // search accending table for nearest entries
219  for(i = 0; i < n; ++i)
220  {
221  if( tbl[i].m_fV >= fV )
222  {
223  break;
224  }
225  }
226 
227  // lower boundary case
228  if( i == 0 )
229  {
230  return tbl[i].m_fSoC;
231  }
232  // upper boundary case
233  else if( i == n )
234  {
235  return tbl[i-1].m_fSoC;
236  }
237  // interpolate
238  else
239  {
240  return linearInterp(fV, tbl[i-1].m_fV, tbl[i].m_fV,
241  tbl[i-1].m_fSoC, tbl[i].m_fSoC);
242  }
243 }
static double linearInterp(double x, double x0, double x1, double y0, double y1)
Linear interpolate.
Definition: laeBatt.cxx:195
double m_fSoC
state of charge (%)
Definition: laeBatt.cxx:118

Variable Documentation

LiIonCellCSoCEntry LiIonCellSoCTbls[]
static
Initial value:
=
{
}
static LiIonCellSoCVEntry LiIonCellSoCVTbl_0C[]
SoC-V table for an 0C unloaded single cell.
Definition: laeBatt.cxx:136
static LiIonCellSoCVEntry LiIonCellSoCVTbl_1C[]
SoC-V table for an 1C single cell.
Definition: laeBatt.cxx:146
static LiIonCellSoCVEntry LiIonCellSoCVTbl_3C[]
SoC-V table for an 3C single cell.
Definition: laeBatt.cxx:166
static LiIonCellSoCVEntry LiIonCellSoCVTbl_2C[]
SoC-V table for an 2C single cell.
Definition: laeBatt.cxx:156

C - SoC-V table of tables.

Definition at line 176 of file laeBatt.cxx.

LiIonCellSoCVEntry LiIonCellSoCVTbl_0C[]
static
Initial value:
=
{
{ 0.0, 3.00}, { 10.0, 3.62}, { 20.0, 3.70}, { 30.0, 3.74}, { 40.0, 3.78},
{ 50.0, 3.84}, { 60.0, 3.88}, { 70.0, 3.93}, { 80.0, 3.97}, { 90.0, 4.05},
{100.0, 4.20}
}

SoC-V table for an 0C unloaded single cell.

Definition at line 136 of file laeBatt.cxx.

LiIonCellSoCVEntry LiIonCellSoCVTbl_1C[]
static
Initial value:
=
{
{ 0.0, 2.00}, { 10.0, 3.50}, { 20.0, 3.55}, { 30.0, 3.60}, { 40.0, 3.65},
{ 50.0, 3.70}, { 60.0, 3.75}, { 70.0, 3.78}, { 80.0, 3.80}, { 90.0, 3.90},
{100.0, 4.05}
}

SoC-V table for an 1C single cell.

Definition at line 146 of file laeBatt.cxx.

LiIonCellSoCVEntry LiIonCellSoCVTbl_2C[]
static
Initial value:
=
{
{ 0.0, 1.00}, { 10.0, 2.90}, { 20.0, 3.45}, { 30.0, 3.55}, { 40.0, 3.60},
{ 50.0, 3.65}, { 60.0, 3.70}, { 70.0, 3.75}, { 80.0, 3.76}, { 90.0, 3.80},
{100.0, 4.00}
}

SoC-V table for an 2C single cell.

Definition at line 156 of file laeBatt.cxx.

LiIonCellSoCVEntry LiIonCellSoCVTbl_3C[]
static
Initial value:
=
{
{ 0.0, 0.10}, { 10.0, 0.50}, { 20.0, 3.30}, { 30.0, 3.45}, { 40.0, 3.51},
{ 50.0, 3.60}, { 60.0, 3.65}, { 70.0, 3.70}, { 80.0, 3.74}, { 90.0, 3.78},
{100.0, 4.00}
}

SoC-V table for an 3C single cell.

Definition at line 166 of file laeBatt.cxx.