Documentation
¶
Overview ¶
Package ev models the EV on a connector: just enough of a battery to make the energy flow of a transaction look real.
Index ¶
- Constants
- func BuiltinCurveNames() []string
- func ParseEnergy(s string) (float64, error)
- func ParsePercent(s string) (float64, error)
- type Curve
- type EV
- func (e *EV) Charge(offeredW float64, d time.Duration) float64
- func (e *EV) ChargeWithin(connectorW, limitW float64, d time.Duration) float64
- func (e *EV) Full() bool
- func (e *EV) Params() Params
- func (e *EV) Power(offeredW float64) float64
- func (e *EV) PowerWithin(connectorW, limitW float64) float64
- func (e *EV) SoC() float64
- func (e *EV) State() State
- type Overrides
- type Params
- type Point
- type State
Constants ¶
const ( CurveStandard = "standard" CurveDCFast = "dc-fast" )
Names of the built-in curves.
Variables ¶
This section is empty.
Functions ¶
func BuiltinCurveNames ¶
func BuiltinCurveNames() []string
BuiltinCurveNames returns the names of the built-in curves, sorted.
func ParseEnergy ¶
ParseEnergy reads an energy value such as "60kWh" or "500Wh" into Wh.
func ParsePercent ¶
ParsePercent reads a percentage such as "20%" or "20" into a fraction from 0 to 1.
Types ¶
type Curve ¶
type Curve struct {
// Name is the name of a built-in curve, or empty for a custom one.
Name string `json:"name,omitempty"`
Points []Point `json:"points,omitempty"`
}
Curve is a charge curve: how much of its maximum power an EV accepts at each state of charge. Between points the value changes in a straight line. The zero Curve is the standard curve.
func BuiltinCurve ¶
BuiltinCurve returns the built-in curve with the given name.
type EV ¶
type EV struct {
// contains filtered or unexported fields
}
EV is a plugged-in EV.
func (*EV) Charge ¶
Charge advances the EV by d of charging with up to offeredW on offer, and returns the energy taken in Wh. There are no losses: all of it goes into the battery.
func (*EV) ChargeWithin ¶
ChargeWithin is Charge for a connector that can deliver connectorW and offers only limitW of it for now.
func (*EV) Power ¶
Power returns the power in W the EV draws right now when the connector offers up to offeredW.
The charge curve belongs to the EV: it scales the EV's own maximum power, and the connector then caps the result. An EV whose maximum is far above the connector's therefore charges at the connector's full power until late, as a fast-charging car does on a slow charger. An EV with no maximum of its own takes the connector's as its maximum.
func (*EV) PowerWithin ¶
PowerWithin is Power for a connector that can deliver connectorW and offers only limitW of it for now, as under a charging profile. The limit caps the power and leaves the EV's own maximum as it is.
type Overrides ¶
type Overrides struct {
BatteryWh *float64 `json:"batteryWh,omitempty"`
SoC *float64 `json:"soc,omitempty"`
MaxPowerW *float64 `json:"maxPowerW,omitempty"`
TargetSoC *float64 `json:"targetSoc,omitempty"`
Curve *Curve `json:"curve,omitempty"`
}
Overrides are EV parameters that may or may not have been given. They are what an EV preset holds, and what the flags of a plug carry.
type Params ¶
type Params struct {
// BatteryWh is the battery capacity in Wh.
BatteryWh float64
// SoC is the state of charge at plug-in, from 0 to 1.
SoC float64
// MaxPowerW is the most power the EV accepts, in W. Zero means no limit
// of its own, so the connector's maximum applies.
MaxPowerW float64
// TargetSoC is the state of charge at which the EV stops charging, from
// 0 to 1.
TargetSoC float64
// Curve is the charge curve: the share of its maximum power the EV
// accepts at each state of charge. The zero value is the standard curve.
Curve Curve
}
Params are the parameters of an EV.
func Defaults ¶
func Defaults() Params
Defaults returns the built-in EV: 60 kWh, 20% charged, no power limit, charging to 100%.