예제 #1
0
    def __init__(self):
        self._mutex = threading.Lock()

        self._last_info_update  = 0
        self._last_state_update = 0
        self._msg = LaptopChargeStatus()
        
        self._power_pub = rospy.Publisher('laptop_charge', LaptopChargeStatus, latch=True)
        self._diag_pub  = rospy.Publisher('/diagnostics', DiagnosticArray)
        
        # Battery info
        self._batt_design_capacity = 0
        self._batt_last_full_capacity = 0
        self._last_info_update = 0

        self._batt_info_rate = 1 / 60.0
        self._batt_info_thread = threading.Thread(target=self._check_batt_info)
        self._batt_info_thread.daemon = True
        self._batt_info_thread.start()

        # Battery state
        self._batt_state_rate = 1 / 5.0
        self._batt_state_thread = threading.Thread(target=self._check_batt_state)
        self._batt_state_thread.daemon = True
        self._batt_state_thread.start()
예제 #2
0
def _check_battery_state():
    """
    @return LaptopChargeStatus
    """
    if os.access('/proc/acpi/battery/BAT0', os.F_OK):
        o = slerp('/proc/acpi/battery/BAT0/state')
    elif os.access('/proc/acpi/battery/BAT1', os.F_OK):
        o = slerp('/proc/acpi/battery/BAT1/state')
    else:
        raise Exception('/proc/acpi/battery/BAT* directory is not exist.')

    batt_info = yaml.load(o)
    rv = LaptopChargeStatus()

    state = batt_info.get('charging state', 'discharging')
    rv.charge_state = state_to_val.get(state, 0)
    rv.rate     = _strip_A(batt_info.get('present rate',        '-1 mA'))
    if rv.charge_state == LaptopChargeStatus.DISCHARGING:
        rv.rate = math.copysign(rv.rate, -1) # Need to set discharging rate to negative
    
    rv.charge   = _strip_Ah(batt_info.get('remaining capacity', '-1 mAh'))
    rv.voltage  = _strip_V(batt_info.get('present voltage',     '-1 mV'))
    rv.present  = batt_info.get('present', False)

    rv.header.stamp = rospy.get_rostime()

    return rv
예제 #3
0
def _check_battery_state():
    """
    @return LaptopChargeStatus
    """
    o = slerp(BATTERY_PROC_FILE + "/state")

    batt_info = yaml.load(o)

    rv = LaptopChargeStatus()

    state = batt_info.get('charging state', 'discharging')
    rv.charge_state = state_to_val.get(state, 0)
    rv.rate     = _strip_A(batt_info.get('present rate',        '-1 mA'))
    if rv.charge_state == LaptopChargeStatus.DISCHARGING:
        rv.rate = math.copysign(rv.rate, -1) # Need to set discharging rate to negative
    
    rv.charge   = _strip_Ah(batt_info.get('remaining capacity', '-1 mAh'))
    rv.voltage  = _strip_V(batt_info.get('present voltage',     '-1 mV'))
    rv.present  = batt_info.get('present', False)

    rv.header.stamp = rospy.get_rostime()

    return rv
예제 #4
0
def _check_battery_state():
    """
    @return LaptopChargeStatus
    """
    o = slerp('/proc/acpi/battery/BAT0/state')

    batt_info = yaml.load(o)

    rv = LaptopChargeStatus()

    state = batt_info.get('charging state', 'discharging')
    rv.charge_state = state_to_val.get(state, 0)
    rv.rate     = _strip_A(batt_info.get('present rate',        '-1 mA'))
    rv.charge   = _strip_Ah(batt_info.get('remaining capacity', '-1 mAh'))
    rv.voltage  = _strip_V(batt_info.get('present voltage',     '-1 mV'))
    rv.present  = batt_info.get('present', False)

    rv.header.stamp = rospy.get_rostime()

    return rv