¿Cuál es la fórmula correcta para calcular el porcentaje de carga de la batería según el tipo de batería (12v, 24v, 48v, etc.) y el voltaje actual de la batería?
Por ejemplo, si tengo una batería de 12v y la batería tiene 12.06v, me daría un 50% de capacidad restante.
Estoy buscando la fórmula utilizada en este cuadro (tipo de batería de 12v):
EJEMPLO DE ACTUALIZACIÓN DE MI FORMA ACTUAL DE DETERMINAR EL ESTADO DE CARGA:
function battery_percentage($voltage_type, $battery_voltage) {
if($voltage_type == 12) {
if($battery_voltage <= 10.5) {
$battery_percentage = 0;
} elseif($battery_voltage <= 11.31) {
$battery_percentage = 10;
} elseif($battery_voltage <= 11.58) {
$battery_percentage = 20;
} elseif($battery_voltage <= 11.75) {
$battery_percentage = 30;
} elseif($battery_voltage <= 11.9) {
$battery_percentage = 40;
} elseif($battery_voltage <= 12.06) {
$battery_percentage = 50;
} elseif($battery_voltage <= 12.20) {
$battery_percentage = 60;
} elseif($battery_voltage <= 12.32) {
$battery_percentage = 70;
} elseif($battery_voltage <= 12.42) {
$battery_percentage = 80;
} elseif($battery_voltage <= 12.5) {
$battery_percentage = 90;
} elseif($battery_voltage <= 12.6) {
$battery_percentage = 100;
} elseif($battery_voltage >= 12.6) {
$battery_percentage = 100;
}
} elseif($voltage_type == 24) {
if($battery_voltage <= 22) {
$battery_percentage = 0;
} elseif($battery_voltage <= 23.02) {
$battery_percentage = 10;
} elseif($battery_voltage <= 23.32) {
$battery_percentage = 20;
} elseif($battery_voltage <= 23.62) {
$battery_percentage = 30;
} elseif($battery_voltage <= 23.92) {
$battery_percentage = 40;
} elseif($battery_voltage <= 24.20) {
$battery_percentage = 50;
} elseif($battery_voltage <= 24.48) {
$battery_percentage = 60;
} elseif($battery_voltage <= 24.74) {
$battery_percentage = 70;
} elseif($battery_voltage <= 25) {
$battery_percentage = 80;
} elseif($battery_voltage <= 25.24) {
$battery_percentage = 90;
} elseif($battery_voltage <= 25.46) {
$battery_percentage = 100;
} elseif($battery_voltage >= 25.46) {
$battery_percentage = 100;
}
} elseif($voltage_type == 48) {
if($battery_voltage <= 45.5) {
$battery_percentage = 0;
} elseif($battery_voltage <= 46.04) {
$battery_percentage = 10;
} elseif($battery_voltage <= 46.64) {
$battery_percentage = 20;
} elseif($battery_voltage <= 47.24) {
$battery_percentage = 30;
} elseif($battery_voltage <= 47.84) {
$battery_percentage = 40;
} elseif($battery_voltage <= 48.40) {
$battery_percentage = 50;
} elseif($battery_voltage <= 48.96) {
$battery_percentage = 60;
} elseif($battery_voltage <= 49.48) {
$battery_percentage = 70;
} elseif($battery_voltage <= 50) {
$battery_percentage = 80;
} elseif($battery_voltage <= 50.48) {
$battery_percentage = 90;
} elseif($battery_voltage <= 50.92) {
$battery_percentage = 100;
} elseif($battery_voltage >= 50.92) {
$battery_percentage = 100;
}
}