Hi!
I experienced the same problem and was now able to solve it (at least for my configuration).
Since I'm no Python programmer and the changes are really quick and dirty, I don't feel able to post a ticket. But maybe this helps some people.
Setup: ROS Fuerte on Laptop Lenovo Thinkpad X130e (which was delivered with my TurtleBot) running Ubunto 12.04 (fresh install). My battery information is located in /sys/class/power_supply/BAT1.
I found some information here: mjmwired.net/kernel/Documentation/power/power_supply_class.txt
My system provided power_now, energy_now and voltage_now that I could use to calculate the values. Since all such entries just contain a single value, you don't need to parse anything, just devide it by 1.000.000 because values are supplied in micro-A/W/V. Also remember to change the path to the battery in minimal.launch!
Attached see my changed laptop_battery.py (you can identify modified lines by the commented original lines next to them).
from __future__ import division
import roslib; roslib.load_manifest('turtlebot_node')
from collections import deque
import threading
import copy
import yaml
import math
import rospy
from turtlebot_node.msg import LaptopChargeStatus
from diagnostic_msgs.msg import DiagnosticStatus, DiagnosticArray, KeyValue
def _strip_Ah(raw_val):
if 'mAh' in raw_val:
rv = float(raw_val.rstrip('mAh').strip()) / 1000.0
elif 'Ah' in raw_val:
rv = float(raw_val.rstrip('Ah').strip())
elif 'mWh' in raw_val:
rv = float(raw_val.rstrip('mWh').strip()) / 1000.0
elif 'Wh' in raw_val:
rv = float(raw_val.rstrip('Wh').strip())
else:
raise Exception('Value %s did not have supported units. (mAh,Ah,mWh,Wh)' % raw_val)
return rv
def _strip_V(raw_val):
if 'mV' in raw_val:
rv = float(raw_val.rstrip('mV').strip()) / 1000.0
elif 'V' in raw_val:
rv = float(raw_val.rstrip('V').strip())
else:
raise Exception('Value %s did not have "V" or "mV"' % raw_val)
return rv
def _strip_A(raw_val):
if 'mA' in raw_val:
rv = float(raw_val.rstrip('mA').strip()) / 1000.0
elif 'A' in raw_val:
rv = float(raw_val.rstrip('A').strip())
elif 'mW' in raw_val:
rv = float(raw_val.rstrip('mW').strip()) / 1000.0
elif 'W' in raw_val:
rv = float(raw_val.rstrip('W').strip())
else:
raise Exception('Value %s did not have supported units. (A,mA,W,mW)' % raw_val)
return rv
def slerp(filename):
f = open(filename, 'r')
data = f.read()
f.close()
data = data.replace('\t', ' ')
return data
#/proc/acpi/battery/BAT0/state
def _check_battery_info(_battery_acpi_path):
o = slerp(_battery_acpi_path+'/energy_full_design')
# batt_info = yaml.load(o)
design_capacity = float(o) / 1000000.0
o = slerp(_battery_acpi_path+'/energy_full')
last_full_capacity = float(o) / 1000000.0
# design_capacity = _strip_Ah(batt_info.get('design capacity', '0 mAh'))
# last_full_capacity = _strip_Ah(batt_info.get('last full capacity', '0 mAh'))
return (design_capacity, last_full_capacity)
state_to_val = {'Full': LaptopChargeStatus.CHARGED,
'Charging': LaptopChargeStatus.CHARGING,
'Discharging': LaptopChargeStatus.DISCHARGING }
diag_level_to_msg = { DiagnosticStatus.OK: 'OK',
DiagnosticStatus.WARN: 'Warning',
DiagnosticStatus.ERROR: 'Error' }
def _check_battery_state(_battery_acpi_path):
"""
@return LaptopChargeStatus
"""
o = slerp(_battery_acpi_path+'/status')
# batt_info = yaml.load(o)
rv = LaptopChargeStatus()
# state = batt_info.get('charging state', 'discharging')
state = o
rv.charge_state = state_to_val.get(state, 0)
o = slerp(_battery_acpi_path+'/power_now')
rv.rate = float(o) / 1000000.0
# rv.rate = _strip_A(batt_info.get ...
(more)