Main Content

Deployed Application of Parameter Estimation

This example shows how to monitor the condition of an electric vehicle battery in the field, with a deployed version of parameter estimation in Simulink® Design Optimization™, together with Simulink Compiler™.

Battery Monitoring

电池在电动汽车是昂贵的再保险place and need to be monitored and maintained carefully, to ensure they function well for their intended lifetime. In this example, an electric car is driven to work and back on a daily commute. At home, the car is plugged in to a smart charger that monitors both the current and the battery voltage. The charger analyzes the battery data to estimate the battery parameters, using a deployed version of parameter estimation in Simulink Design Optimization, together with Simulink Compiler. The charger relays these parameters to the car manufacturer through an Internet of Things (IoT) connection, so that the manufacturer can monitor the battery health over time.

Battery Model

This example estimates parameters of a simple, rechargeable battery model,sdoBattery. The input tosdoBatteryis the battery current, and the model output is the battery terminal voltage which is computed from the battery state of charge.

The battery model is based on the equation:

E = ( 1 - Loss ) V - K Q max 1 - s s

where:

  • E is the battery terminal voltage in Volts.

  • V is the battery constant voltage in Volts.

  • K is the battery polarization resistance in Ohms.

  • Q max is the maximum battery capacity in Ampere-hours. Q 0 is the battery initial state of charge in Ampere-hours.

  • s is the battery charge state, with 1 being fully charged and 0 discharged. The battery state of charge is computed from the integral of the battery current with a positive current indicating discharge and a negative current indicating charging.

  • Loss is the voltage drop when charging, expressed as a fraction of the battery constant voltage.

Use the following command to open the model.

open_system('sdoBattery')

Battery Characteristics

The following battery characteristics are known:

  • Voltage, V = 400V

  • Loss factor, Loss = 0.012

  • Resistance, K = 0.32 Ohms.

Q max is known to be 250 Ampere-hours (100 kWh) when the battery is new. As the battery ages, Q max is expected to decrease, and this is monitored to track the health of the battery. The initial state of charge Q 0 and the new battery capacity Q max need to be estimated.

Steps for Deployed Parameter Estimation

There are two main steps to run parameter estimation in deployed mode:

  1. Make asetupfile, to set up parameter estimation objects for use in deployed mode

  2. Make arunfile, which is a MATLAB function for parameter estimation that can be compiled and run in deployed mode

It is recommended to create thesetupandrunfiles by starting with MATLAB code generated from theParameter Estimator. Copy, split, and modify the generated code to make thesetupandrunfiles as demonstrated in the following section.

Parameter Estimation in Non-Deployed Mode

First generate MATLAB code to estimate Q 0 and Q max in non-deployed mode. Use the following commands to load the pre-configured estimation session:

loadsdoBattery_spesession_forDeploymentspetool(SDOSessionData)

This step loads and plots the experiment with measured voltage and current data and configures theParameter Estimatorto estimate Q 0 and Q max .

Navigate to theEstimatebutton in the toolstrip and from the dropdown list, selectGenerate MATLAB Function(seeGenerate MATLAB Code for Parameter Estimation Problems (GUI)). This step generates a MATLAB function which is added to the MATLAB editor, and a MAT-fileparameterEstimation_sdoBattery_Data.mat. The generated code is available for you in fileparameterEstimationSdoBattery.m. You can use the generated code to estimate parameters in non-deployed mode.

It is recommended to start with this generated code and copy, split and modify the code to create thesetupandrunfiles described in the following sections.

Setup-File for Deployed Parameter Estimation

To estimate parameters in deployed mode, the code for non-deployed parameter estimation can be split into asetupfile to use in non-deployed mode, and arunfile to use in deployed mode. The setup file is available asparameterEstimationSdoBattery_setup.mand the main parts are:

  1. Define parameters

  2. Define experiments

  3. Prepare for deployment and save

Define Parameters

Parameters are defined inparameterEstimationSdoBattery_setup.min the same way as the generated MATLAB code,parameterEstimationSdoBattery.m. Use thesdo.getParameterFromModelcommand to create a parameter object, containing fields for parameter value, minimum and maximum, and a field ("Free") indicating whether the parameter will be tuned during estimation.

In this example, parameter information is also stored in a database in which cars are identified by a code akin to a pseudo vehicle identification number (VIN). The car manufacturer can use this to monitor the health of the battery over time. TheparameterEstimationSdoBattery_setup.mfile uses the VIN database to update battery parameter values. See theparameterEstimationSdoBattery_setup.mfile for more details.

The initial database is loaded from the MATLAB filesdoBatteryVinDatabase.matwhich has the VIN database stored in variablevinDatabase. This is acontainers.Mapobject, and the VIN key4DEFis used to look up parameters for the battery in this example.

Run

vinDatabase("4DEF")

to display the following table:

Define Experiments

Experiments are defined inparameterEstimationSdoBattery_setup.min the same way as the generated MATLAB code,parameterEstimationSdoBattery.m. Experiments have measured data and information about specific ports or signals in the model that are associated with the data.

Prepare for Deployment and Save

At the end of theparameterEstimationSdoBattery_setup.mfile, define a simulator which can run the model and compare model output to measured data. Use theprepareToDeploycommand to configure the experiments and simulator so they can be used in deployed mode. Save these prepared objects to a MAT-file.

When running these steps on another model and preparing for deployment, you may be prompted to save the model to continue after running thesetupfunction. Save the model to preserve logging settings that need to be in place for deployed mode.

TherunfileparameterEstimationSdoBattery_run.muses the objects saved insdoBatteryObjectsToDeploy.matfor parameter estimation in deployed mode.

Run-File for Deployed Parameter Estimation

Therunfile is available asparameterEstimationSdoBattery_run.mand the main parts are:

  1. Load preconfigured deployment objects

  2. Update experiments and parameters

  3. Run optimization

  4. Update Parameter Database

Load Preconfigured Deployment Objects

TheparameterEstimationSdoBattery_run.mneeds a pragma so that the Simulink Compiler includes the model in the compiled code as follows:

Load the preconfigured objects that were saved at the end ofparameterEstimationSdoBattery_setup.mfile as follows:

Update Experiments and Parameters

TheparameterEstimationSdoBattery_run.mfile takes two input arguments:

  • dataFilename - a data file name for experiment data

  • vin - a vehicle identification number for parameter values

Read the data from the comma-separated-values (CSV) text file specified bydataFilename. Use theupdateIODatacommand to update the deployed experiments with new input and output data (current and voltage data for this model). Since the data is from a CSV file, you do not need thegetDatafunction that is present in the generated MATLAB code,parameterEstimationSdoBattery.m.

使用VIN作为键来查找这个汽车的电池parameters in the parameter database. Use the current value from the database to update the initial parameter values prior to running the new estimation. See theparameterEstimationSdoBattery_run.mfile for more details.

Run Optimization

The next several steps inparameterEstimationSdoBattery_run.mare very similar to the code inparameterEstimationSdoBattery.m(for non-deployed estimation). Define a handle to the estimation objective function, specify optimization options, and use thesdo.optimizefunction. This step runs the model and compares model output to experiment data. Parameters are tuned to achieve a close match between the model and data.

The objective function is defined in the subfunctionsdoBattery_optFcnwhich is also like the objective function inparameterEstimationSdoBattery.m. However, the name of the signal logging variable needs to be specified since it cannot be queried from the model in deployed mode.

To determine the name of the variable ('logsout' in this case), query the model from MATLAB in non-deployed mode:

get_param('sdoBattery','SignalLoggingName')

Alternatively, in Simulink use theModelingtab in the toolstrip and clickModel Settings. In the configuration dialog, selectData Import/Exportand find the variable name in theSignalloggingbox.

Update Parameter Database

After callingsdo.optimizein the main function ofparameterEstimationSdoBattery_run.m, update the VIN database. For each parameter that is estimated, copy theCurrentValueto thePreviousValueand then use the new parameter estimate to update theCurrentValue. SeeparameterEstimationSdoBattery_run.mfor more details.

Running Parameter Estimation in Deployed Mode

Use themcccommand to compile theparameterEstimationSdoBattery_run.mfunction from either the MATLAB command window or the DOS or UNIX command prompt. You need to have MATLAB Runtime installed to complete the following steps. For more information, seeInstall and Configure MATLAB Runtime(MATLAB Compiler).

Run parameter estimation in deployed mode.

In MATLAB, run

vinDatabase("4DEF")

to display the following result:

Tracking Battery Parameters over Time

The table below shows estimates of battery parameters Q 0 and Q max over time. The filesdoBattery_Data1.csvcontains data for the battery when it was new,sdoBattery_Data2.csvcontains data for the battery when it was 1 year old andsdoBattery_Data3.csvcontains data for the battery when it was 2 years old.

Observe that there is degradation in battery capacity over time. There is a high rate of degradation in the first year after which the rate of degradation reduces. When the battery was new, the round-trip commute left the battery state of charge at 61% while after 2 years, the commute left the battery state of charge at 47%. If the state of charge falls below 40%, this condition reduces the number of times the battery can be recharged. By tracking battery parameters over time, the manufacturer can monitor the battery health, and determine if the car needs a new battery.

See Also

||||