[Ovmsdev] Charging and Driving Logs

Mark Webb-Johnson mark at webb-johnson.net
Mon Apr 29 21:26:01 HKT 2013


I've just pushed to github the stub for an implementation of this.

The key data structure is:

#define LOG_TYPE_CHARGE         'C'     // A charge log record
#define LOG_TYPE_CHARGING       'c'     // A charging log record
#define LOG_TYPE_DRIVE          'D'     // A drive log record
#define LOG_TYPE_DRIVING        'd'     // A driving log record
#define LOG_TYPE_FREE           'F'     // A free log record

#define LOG_CHARGERESULT_OK     'D'     // Result if charge was ok
#define LOG_CHARGERESULT_STOP   'S'     // Result if charge was stopped
#define LOG_CHARGERESULT_FAIL   'F'     // Result if charge failed

#define LOG_RECORDSTORE         4       // Number of records that can be stored

struct logging_record
  {
  unsigned char type;               // One of LOG_TYPE_*
  unsigned long start_time;         // Time (car_time) log record created
  unsigned int  duration;           // Log record duration
  union
    {
    struct
      {
      unsigned char charge_mode;    // Mode vehicle was charging in
      signed long charge_latitude;  // Raw GPS Latitude
      signed long charge_longitude; // Raw GPS Longitude
      unsigned int charge_voltage;  // Largest line voltage during charge
      unsigned char charge_current; // Largest lien current during charge
      unsigned char charge_result;  // One of LOG_CHARGERESULT_*
      unsigned char start_SOC;
      unsigned int start_idealrange;
      unsigned char end_SOC;
      unsigned int end_idealrange;
      } charge;
    struct
      {
      unsigned char drive_mode;    // Mode vehicle was driven in
      signed long start_latitude;  // Raw GPS Latitude
      signed long start_longitude; // Raw GPS Longitude
      signed long end_latitude;    // Raw GPS Latitude
      signed long end_longitude;   // Raw GPS Longitude
      unsigned long distance;      // Distance driven (or start odometer for 'd')
      unsigned char start_SOC;
      unsigned int start_idealrange;
      unsigned char end_SOC;
      unsigned int end_idealrange;
      } drive;
    } record;
  };

#pragma udata LOGGING
struct logging_record log_recs[LOG_RECORDSTORE];
signed char logging_pos = -1;

The idea is that we create an array data structure containing up to LOG_RECORDSTORE log records. I've got this set to 4 at the moment, and that is the number of charges/drives that can be stored without GPRS connectivity, before drive/charge records are lost. One slot is needed the for 'current' drive/charge, and the others are used for historical data.

Each record (slot) has a type - either a current/historical drive, or a current/historical charge, or free. When the system needs a free slot, it tries to find one marked 'free', otherwise it will dump the oldest one.

We'll have a process that looks for GPRS connectivity, and if it is good and stable it will try to send completed drive and charge records to the server. Once sent, the slot can be freed. I'm going to try to introduce a send/ack style protocol for this, so the server can ack the data record it receives.

The data returned to the server will be whatever is in those records.

Comments / suggestions welcome (particularly from vehicles other that Tesla Roadster, as I need to know if this meets your needs).

Regards, Mark.

P.S. Michael: I added the standard car_* variables for limited charge estimates. I'll update the documentation soon, but in the meantime I hope the change is self-explanatory and you can make use of it in the Twizy code.

On 11 Mar, 2013, at 5:57 AM, Tom Saxton <tom at idleloop.com> wrote:

> Mark,
> 
> This will be a great feature!
> 
> Cathy and I have logged every charge and drive on all three of our EVs since
> 2008. Our goal with logging is to enable us to use historical data to answer
> the question: how much charge do I need to drive from point A to B in these
> conditions? We're also interested in how the performance of each car changes
> through seasons and over the years. I've even written an iPhone app just for
> the manual logging we do.
> 
> The data you propose seems good. I have two suggestions:
> 
> 1. I think it's more important to track charge depletion than kWh used. If
> you're driving hard, either high speed or up elevation, you'll get more
> voltage sag and thus less power per amp-hour than you would with more
> nominal driving. In these cases, kWh out of the pack understates how much of
> the pack's charge you used. So, I'd rather know how much the SOC changed on
> a drive or charge segment, preferably in energy units if available.
> 
>    Tesla Roadster: ideal mi|km
>    Tesla Model S: ideal or rated mi|km
>    LEAF: Gids
> 
> On cars that don't have an energy unit SOC measurement, then SOC % would
> work.
> 
> On drive records, if there's isn't enough room for kWh and change in SOC,
> I'd prefer change in SOC. I even prefer computing miles per ideal mile (or
> miles per charge %) to know Wh per mile.
> 
> On charges, the kWh drawn from the wall is useful data, but I'd also like to
> know how the SOC changed.
> 
> 2. On the charge record, what do you mean by current used? Peak current or
> average current? With tapering near the top of a charge, they can be quite
> different. I'd suggest peak current. You could even get rid of it if you
> need the space for something else. You can determine peak power from the
> available voltage and current (plus knowing the car's limit), and you can
> calculate average power from energy and duration.
> 
>    Tom
> 
> on 3/10/13 7:42 AM, Mark Webb-Johnson wrote:
> 
>> I have wanted to implement charging and driving logs, for some time now. The
>> idea is the car will record 'drives' and 'charges' and report them back as
>> historical records. This will be independent of the vehicle module, so should
>> work for all supported vehicles.
>> 
>> For each drive, we need:
>> 
>> End time [4 bytes]
>> Duration (seconds) [2 bytes]
>> Drive mode [1 byte]
>> Start location [8 bytes]
>> End location [8 bytes]
>> Distance driven [2 bytes]
>> kWh used [2 bytes]
>> 
>> For each charge, we need:
>> 
>> End time [4 bytes]
>> Duration (seconds) [2 bytes]
>> Charge mode [1 byte]
>> Charge location [8 bytes]
>> Current available [1 byte]
>> Current used [1 byte]
>> Voltage [2 bytes]
>> Result (completed, stopped, failed) [1 byte]
>> kWh used [1 byte]
>> 
>> That is 27 bytes per drive, or 21 bytes per charge.
>> 
>> The problem is that GPRS connectivity may not be there at the end of the drive
>> or charge, so we need to store these records. RAM would be good, but we only
>> have 429 bytes left (and I think 256 bytes of that may be stack). EEPROM is
>> also possible, but full of parameters at the moment.
>> 
>> I'm thinking of using the top 4 parameters (#20 through #23) - these appear to
>> be free at the moment, and would give us 128 bytes of permanent storage.
>> Easiest would be 32 bytes for each record.
>> 
>> This would be turned on with a FEATURE_CARBITS (suggestion: 0x80), so it would
>> default off (for privacy).
>> 
>> Comments / suggestions?
>> 
>> Regards, Mark.
>> 
>> _______________________________________________
>> OvmsDev mailing list
>> OvmsDev at lists.teslaclub.hk
>> http://lists.teslaclub.hk/mailman/listinfo/ovmsdev
> 
> 
> _______________________________________________
> OvmsDev mailing list
> OvmsDev at lists.teslaclub.hk
> http://lists.teslaclub.hk/mailman/listinfo/ovmsdev

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openvehicles.com/pipermail/ovmsdev/attachments/20130429/d6ac470f/attachment.htm>


More information about the OvmsDev mailing list