diff --git a/core/soc/estimator.go b/core/soc/estimator.go index d296b655e..fa5d0591e 100644 --- a/core/soc/estimator.go +++ b/core/soc/estimator.go @@ -111,7 +111,7 @@ func (s *Estimator) Soc(fetchedSoc *float64, chargedEnergy float64) float64 { // recalculate gradient, wh per soc % if socDiff > 10 && energyDiff > 0 { s.energyPerSocStep = energyDiff / socDiff - s.virtualCapacity = s.energyPerSocStep * 100 + s.virtualCapacity = max(s.vehicle.Capacity()*1e3, s.energyPerSocStep*100) s.log.DEBUG.Printf("soc gradient updated: soc: %.1f%%, socDiff: %.1f%%, energyDiff: %.0fWh, energyPerSocStep: %.1fWh, virtualCapacity: %.0fWh", s.vehicleSoc, socDiff, energyDiff, s.energyPerSocStep, s.virtualCapacity) } diff --git a/core/soc/estimator_test.go b/core/soc/estimator_test.go index 84f3052bf..5edd30350 100644 --- a/core/soc/estimator_test.go +++ b/core/soc/estimator_test.go @@ -39,7 +39,7 @@ func TestSocEstimation(t *testing.T) { charger := &chargerStruct{api.NewMockCharger(ctrl), api.NewMockBattery(ctrl)} // 8.5 kWh user battery capacity is converted to initial value of 10 kWh virtual capacity (at 85% efficiency) - vehicle.EXPECT().Capacity().Return(8.5) + vehicle.EXPECT().Capacity().Return(8.5).AnyTimes() ce := NewEstimator(util.NewLogger("foo"), charger, vehicle) @@ -66,6 +66,7 @@ func TestSocEstimation(t *testing.T) { {5001, 50.0, 100.0, 10000}, {0, 20.0, 20.0, 10000}, {1000, 30.0, 30.0, 10000}, + {1000, 50.0, 50.0, 8500}, // cap virtual capacity minimum to physical capacity } for _, tc := range tc {