This commit is contained in:
@@ -0,0 +1,126 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Belevo\EnelixUtils;
|
||||
|
||||
use InvalidArgumentException;
|
||||
|
||||
final class VGTRegler
|
||||
{
|
||||
public const GERAETEART_PV = 0;
|
||||
public const GERAETEART_BATTERIE = 1;
|
||||
|
||||
public static function begrenzeSetpoint(
|
||||
int $geraeteart,
|
||||
float $wert,
|
||||
float $maximum
|
||||
): float {
|
||||
self::pruefeGeraeteart($geraeteart);
|
||||
if ($maximum < 0.0) {
|
||||
throw new InvalidArgumentException(
|
||||
'MaxPowerSetpoint darf nicht negativ sein.'
|
||||
);
|
||||
}
|
||||
if ($geraeteart === self::GERAETEART_PV) {
|
||||
return min($maximum, max(0.0, $wert));
|
||||
}
|
||||
|
||||
return min($maximum, max(-$maximum, $wert));
|
||||
}
|
||||
|
||||
public static function zielwert(
|
||||
int $geraeteart,
|
||||
string $strategie,
|
||||
float $setpoint,
|
||||
float $maximum,
|
||||
float $ladezustand,
|
||||
float $zielLadezustand,
|
||||
float $ladeleistung,
|
||||
float $entladeleistung,
|
||||
float $minLadezustand,
|
||||
float $maxLadezustand
|
||||
): float {
|
||||
self::pruefeGeraeteart($geraeteart);
|
||||
$strategie = trim($strategie);
|
||||
$setpoint = self::begrenzeSetpoint(
|
||||
$geraeteart,
|
||||
$setpoint,
|
||||
$maximum
|
||||
);
|
||||
|
||||
if ($strategie === 'stop') {
|
||||
return $geraeteart === self::GERAETEART_PV ? $maximum : 0.0;
|
||||
}
|
||||
if ($strategie === 'activate') {
|
||||
$ziel = $geraeteart === self::GERAETEART_PV
|
||||
? $setpoint
|
||||
: -$setpoint;
|
||||
return self::begrenzeNachLadezustand(
|
||||
$geraeteart,
|
||||
$ziel,
|
||||
$ladezustand,
|
||||
$minLadezustand,
|
||||
$maxLadezustand
|
||||
);
|
||||
}
|
||||
if ($geraeteart === self::GERAETEART_PV) {
|
||||
return $maximum;
|
||||
}
|
||||
|
||||
if ($ladezustand >= $zielLadezustand
|
||||
&& $ladezustand <= $zielLadezustand + 1.0
|
||||
) {
|
||||
return 0.0;
|
||||
}
|
||||
$ziel = $ladezustand < $zielLadezustand
|
||||
? abs($ladeleistung)
|
||||
: -abs($entladeleistung);
|
||||
$ziel = self::begrenzeSetpoint($geraeteart, $ziel, $maximum);
|
||||
|
||||
return self::begrenzeNachLadezustand(
|
||||
$geraeteart,
|
||||
$ziel,
|
||||
$ladezustand,
|
||||
$minLadezustand,
|
||||
$maxLadezustand
|
||||
);
|
||||
}
|
||||
|
||||
private static function begrenzeNachLadezustand(
|
||||
int $geraeteart,
|
||||
float $zielW,
|
||||
float $ladezustand,
|
||||
float $minimum,
|
||||
float $maximum
|
||||
): float {
|
||||
if ($geraeteart === self::GERAETEART_PV) {
|
||||
return $zielW;
|
||||
}
|
||||
if ($minimum < 0.0
|
||||
|| $maximum > 100.0
|
||||
|| $minimum > $maximum
|
||||
) {
|
||||
throw new InvalidArgumentException(
|
||||
'MinSoC und MaxSoC sind ungueltig.'
|
||||
);
|
||||
}
|
||||
if (($zielW < 0.0 && $ladezustand <= $minimum)
|
||||
|| ($zielW > 0.0 && $ladezustand >= $maximum)
|
||||
) {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
return $zielW;
|
||||
}
|
||||
|
||||
private static function pruefeGeraeteart(int $geraeteart): void
|
||||
{
|
||||
if (!in_array($geraeteart, [
|
||||
self::GERAETEART_PV,
|
||||
self::GERAETEART_BATTERIE,
|
||||
], true)) {
|
||||
throw new InvalidArgumentException('Geraeteart ist ungueltig.');
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user