[gnome-battery-bench] Improve the approximation of power from current
- From: Owen Taylor <otaylor src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-battery-bench] Improve the approximation of power from current
- Date: Tue, 30 Jun 2015 21:18:19 +0000 (UTC)
commit fa6052918a4dfa770062ac55ef1f2311c9d0dc6d
Author: Owen W. Taylor <otaylor fishsoup net>
Date: Tue Jun 30 16:30:10 2015 -0400
Improve the approximation of power from current
P = Integral from Q1 to Q2 of V(Q)dQ
Use:
(V1 + V2)/2 * (Q2 - Q1)
as the trapezoid rule approximation of this instead of:
V2 * Q2 - V1 * Q1
which doesn't have a clear meaning. If V is constant, both are
the same, but for example, if we had a capacitor with V(Q) = Q/C,
then the old expression would over-estimate by a factor of 2,
while the new expression is asymptotically right for small changes.
https://bugzilla.gnome.org/show_bug.cgi?id=747370
src/power-monitor.c | 14 ++++++++++++--
1 files changed, 12 insertions(+), 2 deletions(-)
---
diff --git a/src/power-monitor.c b/src/power-monitor.c
index 8946b16..7a70f3c 100644
--- a/src/power-monitor.c
+++ b/src/power-monitor.c
@@ -455,14 +455,24 @@ gbb_power_statistics_compute (const GbbPowerState *base,
}
} else if (current->charge_now >= 0 && time_elapsed > 0) {
double charge_used = base->charge_now - current->charge_now;
- double energy_used = base->charge_now * base->voltage_now - current->charge_now *
current->voltage_now;
+
if (charge_used > 0) {
statistics->current = 3600 * (charge_used) / time_elapsed;
- statistics->power = 3600 * (energy_used) / time_elapsed;
if (base->charge_full >= 0)
statistics->battery_life = 3600 * base->charge_full / statistics->current;
if (base->charge_full_design >= 0)
statistics->battery_life_design = 3600 * base->charge_full_design / statistics->current;
+
+ /* We can approximate the power used using the current and the voltage; the
+ * more the voltage is constant, the more accurate this will be. We could
+ * improve this by looking at intermediate statistics, but since reporting
+ * capacity in watts is clearly preferred by the relevant standards, too much
+ * complexity to improve this doesn't seem to make sense.
+ */
+ if (current->voltage_now >= 0) {
+ double average_voltage = (base->voltage_now + current->voltage_now) / 2;
+ statistics->power = 3600 * average_voltage * charge_used / time_elapsed;
+ }
}
} else if (current->capacity_now >= 0 && time_elapsed > 0) {
double capacity_used = base->capacity_now - current->capacity_now;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]