import math


def sensor_state_parse(data):
    """ Formats all the sensorimotor data into an appropriate 
    dictionary with appropriate types
    """
    return {
    "bump_right": True if data.bumper % 2 else False,
    "bump_center": True if data.bumper % 4 > 1 else False,
    "bump_left": True if data.bumper >= 4 else False,
    "wheeldrop_right": bool(data.WHEEL_DROP_RIGHT),
    "wheeldrop_left": bool(data.WHEEL_DROP_LEFT),
    "cliff_right": bool(data.CLIFF_RIGHT),
    "cliff_center": bool(data.CLIFF_CENTRE),
    "cliff_left": bool(data.CLIFF_LEFT),
    "ticks_left": data.left_encoder,   # number of wheel ticks since 
    "ticks_right": data.right_encoder, # kobuki turned on; max 65535
    # button number
    "button": int(math.log(data.buttons, 2)) if data.buttons else 0, 
    "current_left_mA": data.current[0] * 10,
    "current_right_mA": data.current[1] * 10,
    "overcurrent_left": True if data.over_current % 2 else False,
    "overcurrent_right": True if data.over_current > 2 else False,
    "battery_voltage": data.battery * 0.1,
    "bottom_dist_left": data.bottom[2],  # cliff PSD sensor (0 - 4095, 
    "bottom_dist_right": data.bottom[0], # distance measure is non-linear)
    "bottom_dist_center": data.bottom[1],
    }