[Ovmsdev] Calculating Leaf Rated Miles

Tom Saxton tom at idleloop.com
Sun May 8 08:39:51 HKT 2016

I think exposing Gids would be fine, but it's not as user friendly as rated miles.

Now that I've looked at it some more, I don't think it matters which model Leaf it is.

The 24 kWh Leaf has an EPA rated range of 84 miles and a nominal full pack has 281 Gids. The 30 kWh Leaf is rated at 107 miles and has a nominal full pack around 363 Gids (that's the value James Pollock, aka Turbo3, the creator of LeafSpy recommended I use to convert Gids to percent for the Plug In America Leaf survey).

Gids *  84 / 281 = Gids * 0.298932
Gids * 107 / 363 = Gids * 0.294765

Split the difference as 0.296849 which can be approximated very closely and rounded with integer math as:

(Gids * 19 + 32) / 64

That's much closer to the target average than the average is to the two model-specific numbers, and won't overflow uint16_t until 3448 Gids. It has a maximum error of 1 rated mile compared to either the 24- or 30-kWh calculation in floating point and rounded through the range from 0 to 370, and an average absolute error just under 0.39 for both.

The early Leafs had a lower rated range, but that was at least partially because of the methodology used by the EPA. Since the early Leafs has an option to charge to 80%, the EPA took the range with an 80% charge and averaged that with the 100% charge range. That's why Nissan took away the 80% charge option. Or so the story goes.

As an owner of one of those early Leafs, I'd be totally happy with a rated miles calculation based on the later model's rated range.


On 5/7/16, 4:09 PM, "Tom Parker" <ovmsdev-bounces at lists.teslaclub.hk on behalf of tom at carrott.org> wrote:

>On 05/04/2016 04:13 AM, Tom Saxton wrote:
>> In C, integer calculations truncates instead of rounding. 99/100 = 0. Adding half of the denominator to the numerator causes the calculation to round up, i.e., (99 + 50) / 100 = 1. That's great for positive values, the case here, but isn't the right thing for negative values. Gary Gidding's original SOC meter didn't round, so that's been the de facto standard in the Leaf world.
>Thanks for the explanation, I've already removed the 140 and it sounds 
>like putting it back will move further from Gary's algorithm so I won't 
>put it back.
>> As for configuration, I think there's real value in having a pack energy number, like rated miles, that isn't configurable so it can be compared between owners. If the parameters change, I think it should be based on model configuration (which I'm hoping can be determined from the CAN bus), and not from owner configuration.
>Would it be better to expose the raw number of gids for comparison, so 
>there's no confusion about what the numbers mean? I've got some 
>rudimentary historical data reporting that sends the current gids. I 
>don't think there is a way to see the historical data other than the 
>HTTP api?
>I've not yet tried to be compatible with the Twizzy historical format, 
>and I don't have anything to visualize the data I am sending (I've 
>mostly used it as a channel for debugging).
>OvmsDev mailing list
>OvmsDev at lists.teslaclub.hk

More information about the OvmsDev mailing list