Laelaps  2.3.5
RoadNarrows Robotics Small Outdoor Mobile Robot Project
laelaps::LaeBattery Class Reference

Battery Management and System Energy Monitoring (BMSEM) Class. More...

#include <laeBatt.h>

Public Member Functions

 LaeBattery ()
 Default constructor.
 
virtual ~LaeBattery ()
 Destructor.
 
bool getChargingState ()
 Get the most recently updated battery charging state. More...
 
double getBatteryVoltage ()
 Get the most recently sensed battery voltage. More...
 
double getBatteryStateOfCharge ()
 Get the most recently estimated battery state of charge. More...
 
double getMotorCurrent ()
 Get most recently sensed current pulled by all motors. More...
 
double getMotorPowerElec (const double fMotorWatts)
 Get most recently calculated power used by all motors. More...
 
double getTotalCurrent ()
 Get most recently estimated total current pulled by the robot. More...
 
double getTotalPower ()
 Get most recently estimated power consumed by robot. More...
 
virtual void calcMotorEnergyState ()
 Calculate the present energy state of the robot motors. More...
 
virtual void calcLogicEnergyState ()
 Calculate the present energy state of all logic curcuitry. More...
 
virtual double estimateBatteryStateOfCharge ()
 Estimate batteries State of Charge given the present energy state. More...
 
virtual void update ()
 Update the energy state for all of the robot's subsystems.
 

Protected Attributes

bool m_bIsCharging
 the battery is [not] being charged
 
double m_fBatteryVoltage
 sensed battery output voltage (V)
 
double m_fBatterySoC
 battery state of charge (0% - 100%)
 
double m_fMotorAmps
 sensed current for all motors (A)
 
double m_fMotorWatts
 sensed power for all motors (watts)
 
double m_fLogicAmps
 current consumed by logic circuitry (A)
 
double m_fLogicWatts
 power consumed by logic circuitry (watts)
 
double m_fTotalAmps
 total system current draw (A)
 
double m_fTotalWatts
 total system power used (watts)
 

Detailed Description

Battery Management and System Energy Monitoring (BMSEM) Class.

Definition at line 65 of file laeBatt.h.

Member Function Documentation

void LaeBattery::calcLogicEnergyState ( )
virtual

Calculate the present energy state of all logic curcuitry.

Logic circuitry includes odroid, motor controllers, battery chargers, IMU, watchdog sub-processor, sensors, and supporting hardware.

Definition at line 317 of file laeBatt.cxx.

Referenced by getTotalPower().

318 {
319  //
320  // TODO See https://github.com/hardkernel/EnergyMonitor
321  //
322  m_fLogicAmps = 0.5;
323  m_fLogicWatts = m_fLogicAmps * 1.8;
324 }
double m_fLogicAmps
current consumed by logic circuitry (A)
Definition: laeBatt.h:185
double m_fLogicWatts
power consumed by logic circuitry (watts)
Definition: laeBatt.h:186
void LaeBattery::calcMotorEnergyState ( )
virtual

Calculate the present energy state of the robot motors.

Note
The motor controllers have battery voltage sensors, so the battery voltage is determined here also.

Definition at line 266 of file laeBatt.cxx.

References LAE_VERSION.

Referenced by getTotalPower().

267 {
268  int nCtlr, nMotor;
269  double fVolts, fAmps, fWatts;
270 
271  m_fBatteryVoltage = 0.0;
272  m_fMotorAmps = 0.0;
273  m_fMotorWatts = 0.0;
274 
275  //
276  // Motor controllers have the best voltage sense accuracy. Use if possible.
277  //
279  {
280  //
281  // Batteries and motors
282  //
283  for(nCtlr=0; nCtlr<LaeNumMotorCtlrs; ++nCtlr)
284  {
285  fVolts = RtDb.m_motorctlr[nCtlr].m_fBatteryVoltage;
286  for(nMotor=0; nMotor<LaeNumMotorsPerCtlr; ++nMotor)
287  {
288  fAmps = RtDb.m_motorctlr[nCtlr].m_fMotorCurrent[nMotor];
289  fWatts = fAmps * fVolts;
290 
291  m_fMotorAmps += fAmps;
292  m_fMotorWatts += fWatts;
293  }
294  m_fBatteryVoltage += fVolts;
295  }
296 
297  // average
298  m_fBatteryVoltage /= (double)LaeNumMotorCtlrs;
299  }
300 
301  //
302  // For original 2.0 hardware, the only sources to sense battery voltages were
303  // from the motor controllers. New in v2.1+, there is a direct voltage sense
304  // to the WatchDog processor. This change was needed because the motor
305  // controllers' power enable line can be disabled independent of battery
306  // state.
307  //
308  // However, voltage sense is less accurate. Use only if motor controllers'
309  // power is disablbed.
310  //
311  else if( RtDb.m_product.m_uProdHwVer >= LAE_VERSION(2, 1, 0) )
312  {
314  }
315 }
double m_fBatteryVoltage
sensed battery output voltage (V)
Definition: laeBatt.h:181
LaeDbProduct m_product
product data
Definition: laeDb.h:227
double m_fMotorAmps
sensed current for all motors (A)
Definition: laeBatt.h:183
double m_fBatteryVoltage
sensed battery subsystem voltage (V)
Definition: laeDb.h:201
uint_t m_uProdHwVer
product hardware version number
Definition: laeDb.h:80
double m_fBatteryVoltage
sensed battery voltage (V)
Definition: laeDb.h:136
double m_fMotorWatts
sensed power for all motors (watts)
Definition: laeBatt.h:184
double m_fMotorCurrent[LaeNumMotorsPerCtlr]
motor currents (A)
Definition: laeDb.h:137
LaeDb RtDb
The real-time database.
Definition: laeDb.h:244
LaeDbEnable m_enable
key gpio state data
Definition: laeDb.h:230
LaeDbMotorCtlr m_motorctlr[LaeNumMotorCtlrs]
motor controller and motor data
Definition: laeDb.h:231
LaeDbEnergy m_energy
battery and energy data
Definition: laeDb.h:237
bool m_bMotorCtlr
motor controller [not] enabled
Definition: laeDb.h:121
static const int LaeNumMotorCtlrs
number of motor controllers
Definition: laeMotor.h:115
#define LAE_VERSION(major, minor, revision)
Convert version triplet to integer equivalent.
Definition: laelaps.h:158
static const int LaeNumMotorsPerCtlr
number of motors/controller
Definition: laeMotor.h:130
double LaeBattery::estimateBatteryStateOfCharge ( )
virtual

Estimate batteries State of Charge given the present energy state.

Returns
SoC [0.0% - 100.0%]

Definition at line 326 of file laeBatt.cxx.

References linearInterp(), and lookupSoC().

Referenced by getTotalPower().

327 {
328  double fC;
329  size_t n, i;
330  double fSoC0, fSoC1;
331 
332  // normalize specific current
334 
335  n = arraysize(LiIonCellSoCTbls);
336 
337  // look for C's nearest entries
338  for(i = 0; i < n; ++i)
339  {
340  if( LiIonCellSoCTbls[i].m_fC >= fC )
341  {
342  break;
343  }
344  }
345 
346  // lower boundary case - single interpolation
347  if( i == 0 )
348  {
350  LiIonCellSoCTbls[i].m_sizeTbl);
351  }
352  // upper boundary case - single interpolation
353  else if( i == n )
354  {
356  LiIonCellSoCTbls[i-1].m_sizeTbl);
357  }
358  // double interpolation
359  else
360  {
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,
367  fSoC0, fSoC1);
368  }
369 
370  return m_fBatterySoC;
371 }
double m_fBatteryVoltage
sensed battery output voltage (V)
Definition: laeBatt.h:181
static double linearInterp(double x, double x0, double x1, double y0, double y1)
Linear interpolate.
Definition: laeBatt.cxx:195
static double lookupSoC(double fV, LiIonCellSoCVEntry tbl[], size_t n)
Lookup State of Charge, given the battery voltage.
Definition: laeBatt.cxx:211
double m_fBatterySoC
battery state of charge (0% - 100%)
Definition: laeBatt.h:182
double m_fTotalAmps
total system current draw (A)
Definition: laeBatt.h:187
static LiIonCellCSoCEntry LiIonCellSoCTbls[]
C - SoC-V table of tables.
Definition: laeBatt.cxx:176
const double LaeTuneBattCapAh
Fixed battery capacity (Amp-hours).
Definition: laeTune.h:236
double laelaps::LaeBattery::getBatteryStateOfCharge ( )
inline

Get the most recently estimated battery state of charge.

Returns
State of Charge (0.0% - 100.0%).

Definition at line 106 of file laeBatt.h.

References m_fBatterySoC.

107  {
108  return m_fBatterySoC;
109  }
double m_fBatterySoC
battery state of charge (0% - 100%)
Definition: laeBatt.h:182
double laelaps::LaeBattery::getBatteryVoltage ( )
inline

Get the most recently sensed battery voltage.

The battery voltage is the (weighted) average of all voltage sensors from all batteries.

Returns
The sensed battery average voltage (V).

Definition at line 96 of file laeBatt.h.

References m_fBatteryVoltage.

97  {
98  return m_fBatteryVoltage;
99  }
double m_fBatteryVoltage
sensed battery output voltage (V)
Definition: laeBatt.h:181
bool laelaps::LaeBattery::getChargingState ( )
inline

Get the most recently updated battery charging state.

Returns
The batteries are [not] being charged.

Definition at line 83 of file laeBatt.h.

References m_bIsCharging.

84  {
85  return m_bIsCharging;
86  }
bool m_bIsCharging
the battery is [not] being charged
Definition: laeBatt.h:180
double laelaps::LaeBattery::getMotorCurrent ( )
inline

Get most recently sensed current pulled by all motors.

Parameters
Motorcurrent (amps).

Definition at line 116 of file laeBatt.h.

References m_fMotorAmps.

117  {
118  return m_fMotorAmps;
119  }
double m_fMotorAmps
sensed current for all motors (A)
Definition: laeBatt.h:183
double laelaps::LaeBattery::getMotorPowerElec ( const double  fMotorWatts)
inline

Get most recently calculated power used by all motors.

Returns
Motor power (watts).

Definition at line 126 of file laeBatt.h.

References m_fMotorWatts.

127  {
128  return m_fMotorWatts;
129  }
double m_fMotorWatts
sensed power for all motors (watts)
Definition: laeBatt.h:184
double laelaps::LaeBattery::getTotalCurrent ( )
inline

Get most recently estimated total current pulled by the robot.

Returns
System total current (amps).

Definition at line 136 of file laeBatt.h.

References m_fTotalAmps.

137  {
138  return m_fTotalAmps;
139  }
double m_fTotalAmps
total system current draw (A)
Definition: laeBatt.h:187
double laelaps::LaeBattery::getTotalPower ( )
inline

Get most recently estimated power consumed by robot.

Returns
System total power (watts).

Definition at line 146 of file laeBatt.h.

References calcLogicEnergyState(), calcMotorEnergyState(), estimateBatteryStateOfCharge(), m_fTotalWatts, and update().

147  {
148  return m_fTotalWatts;
149  }
double m_fTotalWatts
total system power used (watts)
Definition: laeBatt.h:188

The documentation for this class was generated from the following files: