51 #include <sys/types.h> 56 #include "rnr/rnrconfig.h" 79 static const double OdroidXU3MinAmps = 1.0;
80 static const double OdroidXU3Volts = 1.8;
81 static const double OdroidXU4MinAmps = 1.0;
82 static const double OdroidXU4Volts = 1.8;
83 static const double RoboClaw2x30AAmps = 0.03;
84 static const double RoboClaw2x30AVolts = 5.0;
85 static const double Naze32Amps = 0.50;
86 static const double Naxe32Volts = 5.0;
87 static const double BattChargerAmps = 0.0;
88 static const double BattChargerVolts = 0.0;
89 static const double ArduinoAmps = 0.01;
90 static const double ArduinoVolts = 5.0;
91 static const double OtherAmps = 0.01;
92 static const double OtherVolts = 5.0;
138 { 0.0, 3.00}, { 10.0, 3.62}, { 20.0, 3.70}, { 30.0, 3.74}, { 40.0, 3.78},
139 { 50.0, 3.84}, { 60.0, 3.88}, { 70.0, 3.93}, { 80.0, 3.97}, { 90.0, 4.05},
148 { 0.0, 2.00}, { 10.0, 3.50}, { 20.0, 3.55}, { 30.0, 3.60}, { 40.0, 3.65},
149 { 50.0, 3.70}, { 60.0, 3.75}, { 70.0, 3.78}, { 80.0, 3.80}, { 90.0, 3.90},
158 { 0.0, 1.00}, { 10.0, 2.90}, { 20.0, 3.45}, { 30.0, 3.55}, { 40.0, 3.60},
159 { 50.0, 3.65}, { 60.0, 3.70}, { 70.0, 3.75}, { 80.0, 3.76}, { 90.0, 3.80},
168 { 0.0, 0.10}, { 10.0, 0.50}, { 20.0, 3.30}, { 30.0, 3.45}, { 40.0, 3.51},
169 { 50.0, 3.60}, { 60.0, 3.65}, { 70.0, 3.70}, { 80.0, 3.74}, { 90.0, 3.78},
195 static double linearInterp(
double x,
double x0,
double x1,
double y0,
double y1)
197 return y0 + (x - x0)/(x1 - x0) * (y1 - y0);
216 fV /= (double)LaeTuneBattCells;
219 for(i = 0; i < n; ++i)
221 if( tbl[i].m_fV >= fV )
241 tbl[i-1].m_fSoC, tbl[i].m_fSoC);
250 LaeBattery::LaeBattery()
252 m_bIsCharging =
false;
253 m_fBatteryVoltage = 0.0;
262 LaeBattery::~LaeBattery()
266 void LaeBattery::calcMotorEnergyState()
269 double fVolts, fAmps, fWatts;
271 m_fBatteryVoltage = 0.0;
278 if( RtDb.m_enable.m_bMotorCtlr )
283 for(nCtlr=0; nCtlr<LaeNumMotorCtlrs; ++nCtlr)
285 fVolts = RtDb.m_motorctlr[nCtlr].m_fBatteryVoltage;
286 for(nMotor=0; nMotor<LaeNumMotorsPerCtlr; ++nMotor)
288 fAmps = RtDb.m_motorctlr[nCtlr].m_fMotorCurrent[nMotor];
289 fWatts = fAmps * fVolts;
291 m_fMotorAmps += fAmps;
292 m_fMotorWatts += fWatts;
294 m_fBatteryVoltage += fVolts;
298 m_fBatteryVoltage /= (double)LaeNumMotorCtlrs;
311 else if( RtDb.m_product.m_uProdHwVer >=
LAE_VERSION(2, 1, 0) )
313 m_fBatteryVoltage = RtDb.m_energy.m_fBatteryVoltage;
317 void LaeBattery::calcLogicEnergyState()
323 m_fLogicWatts = m_fLogicAmps * 1.8;
326 double LaeBattery::estimateBatteryStateOfCharge()
333 fC = m_fTotalAmps / LaeTuneBattCapAh;
335 n = arraysize(LiIonCellSoCTbls);
338 for(i = 0; i < n; ++i)
340 if( LiIonCellSoCTbls[i].m_fC >= fC )
349 m_fBatterySoC =
lookupSoC(m_fBatteryVoltage, LiIonCellSoCTbls[i].m_pTbl,
350 LiIonCellSoCTbls[i].m_sizeTbl);
355 m_fBatterySoC =
lookupSoC(m_fBatteryVoltage, LiIonCellSoCTbls[i-1].m_pTbl,
356 LiIonCellSoCTbls[i-1].m_sizeTbl);
361 fSoC0 =
lookupSoC(m_fBatteryVoltage, LiIonCellSoCTbls[i-1].m_pTbl,
362 LiIonCellSoCTbls[i-1].m_sizeTbl);
363 fSoC1 =
lookupSoC(m_fBatteryVoltage, LiIonCellSoCTbls[i].m_pTbl,
364 LiIonCellSoCTbls[i].m_sizeTbl);
366 LiIonCellSoCTbls[i-1].m_fC, LiIonCellSoCTbls[i].m_fC,
370 return m_fBatterySoC;
373 void LaeBattery::update()
375 m_bIsCharging = RtDb.m_energy.m_bBatteryIsCharging;
378 calcMotorEnergyState();
381 calcLogicEnergyState();
386 m_fTotalAmps = m_fMotorAmps + m_fLogicAmps;
387 m_fTotalWatts = m_fMotorWatts + m_fLogicWatts;
392 estimateBatteryStateOfCharge();
397 if( RtDb.m_product.m_uProdHwVer <
LAE_VERSION(2, 1, 0) )
400 RtDb.m_energy.m_fBatteryVoltage = m_fBatteryVoltage;
402 RtDb.m_energy.m_fBatterySoC = m_fBatterySoC;
403 RtDb.m_energy.m_fTotalCurrent = m_fTotalAmps;
404 RtDb.m_energy.m_fTotalPower = m_fTotalWatts;
static double linearInterp(double x, double x0, double x1, double y0, double y1)
Linear interpolate.
static LiIonCellSoCVEntry LiIonCellSoCVTbl_0C[]
SoC-V table for an 0C unloaded single cell.
Laelaps battery management and energy monitoring class interface.
double m_fC
specific normalized current
static double lookupSoC(double fV, LiIonCellSoCVEntry tbl[], size_t n)
Lookup State of Charge, given the battery voltage.
static LiIonCellSoCVEntry LiIonCellSoCVTbl_1C[]
SoC-V table for an 1C single cell.
static LiIonCellSoCVEntry LiIonCellSoCVTbl_3C[]
SoC-V table for an 3C single cell.
Lithium-Ion State of Charge - Cell Voltage table.
The <b><i>Laelaps</i></b> namespace encapsulates all <b><i>Laelaps</i></b> related constructs...
size_t m_sizeTbl
number of entries
Laelaps common utilities.
static LiIonCellSoCVEntry LiIonCellSoCVTbl_2C[]
SoC-V table for an 2C single cell.
LiIonCellSoCVEntry * m_pTbl
SoC - V table.
Laelaps motors, encoder, and controllers hardware abstraction interfaces.
#define LAE_VERSION(major, minor, revision)
Convert version triplet to integer equivalent.
Specific Current - State of Charge/Battery Voltage table entry.
static LiIonCellCSoCEntry LiIonCellSoCTbls[]
C - SoC-V table of tables.
double m_fV
sensed battery voltage (V)
double m_fSoC
state of charge (%)
Laelaps real-time "database".
Top-level package include file.