Skip to content

Commit b513c9d

Browse files
committed
Added capability to measure the arduino robot battery
1 parent d49a22c commit b513c9d

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

avr/libraries/LottieLemon/src/utility/LottieLemonMotorBoard.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,3 +307,24 @@ void MotorBoard::reset() {
307307
begin();
308308
stopCurrentActions();
309309
}
310+
311+
float MotorBoard::getBatteryTerminalVolts() {
312+
// Read battery voltage on multiplexer channel 5.
313+
int adcValue = _multiplexer.analogRead(5);
314+
float adcVoltage = (5.0f / 1023.0f) * adcValue;
315+
return 2.0f * adcVoltage; // Compensate for voltage divider.
316+
}
317+
318+
float MotorBoard::getBatteryChargeMilliamps() {
319+
// Read battery charge current on multiplexer channel 6.
320+
int adcValue = _multiplexer.analogRead(6);
321+
float adcVoltage = (5.0f / 1023.0f) * adcValue;
322+
return adcVoltage / 0.00075f; // Compensate sense resistor and gain.
323+
}
324+
325+
float MotorBoard::getBatteryDischargeMilliamps() {
326+
// Read battery discharge current on multiplexer channel 7.
327+
int adcValue = _multiplexer.analogRead(7);
328+
float adcVoltage = (5.0f / 1023.0f) * adcValue;
329+
return adcVoltage / 0.00075f; // Compensate sense resistor and gain.
330+
}

avr/libraries/LottieLemon/src/utility/LottieLemonMotorBoard.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ namespace LottieLemon {
3535

3636
int IRread(uint8_t num);
3737

38+
float getBatteryTerminalVolts();
39+
float getBatteryChargeMilliamps();
40+
float getBatteryDischargeMilliamps();
41+
3842
void setMode(uint8_t mode);
3943
void pauseMode(bool onOff);
4044

0 commit comments

Comments
 (0)