Code covered by the BSD License  

Highlights from
SAE Paper Demo: Model-Based Design of Hybrid Electric Vehicles

image thumbnail

SAE Paper Demo: Model-Based Design of Hybrid Electric Vehicles


Simulink Dude (view profile)


07 Nov 2010 (Updated )

Demo files to accompany the paper by the same name

%% Hybrid Electric Vehicle Demo for Simulink Tour R2007b
% This script is intended to be used to learn the demo
bdclose all
clear all

%% The model
% Before discussing HEV concepts, lets run the model and look at a GUI that 
% shows us vehicle speed and milage based on a driver profile.
% <matlab:linkClicked='link1';HEV_script_links; Open the system model>

%% System-level model of the HEV
% The first step in designing an HEV is creating an executable
% specification from the system requirements. The executable specification
% is a high level model of the entire system that is created by the systems
% engineer. This system model typically captures all the system dynamics
% and a basic control strategy so that the model can be simulated. This can
% then be used to communicate the detailed design specifications to the
% various engineering teams so that they can work on the detailed design.
% For example, the high level model may define interfaces between various
% subsystems that represent the motor, transmission and engine. This
% specification is executable in the sense that you can always hit the run
% button simulate it to see what the expected behavior is. This helps
% reduce errors due to misinterpretation of paper based specs or
% engineering drawings. 
% <matlab:linkClicked='link2';HEV_script_links; Lets look at the top level of the model>

% We can see the various components that we discussed laid out in Simulink
% 7 in a similar architecture to the diagram on the slide. These have been
% implemented in Simulink 7 using Simulink and Simscape blocks.
% Simscape enables systems engineers who are not domain experts to model a
% system and capture high level dynamics like average power flow. Rather
% than model equations, simscape enables you to model physical components
% like resistors capacitors and actual physical connections like shafts
% with inertias and electrical wire connections. It is a single multidomain
% environment that enables interconnection connections of electrical,
% driveline, hydraulic and rigid body mechanical systems. This makes it an
% ideal tool for developing a system model that engineers with varied
% specializations can share. Additionally because the models are high
% level, and no co-simulation is needed, simulation performance is high
% enabling rapid design iterations.  

%% Lets look the implementation of the components in detail:
% <matlab:linkClicked='link3';HEV_script_links; The synchronous generator and drive model> is an interesting example of multi-domain modeling. On
% the left side, in blue, you see the electrical components coupled to the
% mechanical components represented in green on the right. The block in
% pale orange represents the coupling model. What is interesting about this
% design is that Simscape library blocks can be combined to create
% electromechanical machines whose characteristics can be customized, all
% within the single Simulink environment. Using this approach we have
% modeled the remaining dynamic components of the system model. 
% In addition to modeling the dynamics, we have modeled the mode logic
% using Stateflow. The mode logic is the supervisory controller that
% switches the components depending on the driver inputs of gas and brake
% pedal. Stateflow works seamlessly with Simulink 7 and Simscape to
% integrate advanced logic-based control in a single model. 
% <matlab:linkClicked='link4';HEV_script_links; Lets look at a specific driver input scenario>
% Looking at the stateflow chart, we can see how Stateflow switches between
% the various modes automatically based on the brake or driver input while
% the vehicle response changes on the GUI. Initially the gas pedal is
% being depressed so we expect to see acceleration, looking at velocity
% graph, we can see thisfollowing this there is a period where the pedal
% is held at a fixed position so the vehicle should still accelerate to a
% pointafter this the driver gradually lifts of the pedal so the vehicle
% starts to coast, note that the velocity levels off and the fuel
% efficiency in mile per gallon starts to increase which makes sense
% because we expect the vehicle to use the least fuel when coasting and the
% most during acceleration. Running the simulation again and focussing on
% stateflow this time, we transition from acceleration to cruising
% and eventually to braking. This corresponds to what the driver wants the
% vehicle to do based on the inputs from the brake and throttle input.

%% Detailed component design
% At this point in a design cycle, the systems engineer can hand of the
% model to the various component specialists for further elaboration and
% detailed design. Lets focus on the machine drive and control components
% to see how Simulink can be used in the model elaboration and software
% implementation steps.
% <matlab:linkClicked='link5';HEV_script_links; Let's open the generator and Drive subysstem>
% This model shows us a more detailed implementation of a synchronous
% machine, which includes detailed power electronics, and detailed
% synchronous machine dynamics, including high-frequency switching. This is
% important to model because the control strategy depends on this high
% frequency switching to control the synchronous machine. This component is
% developed using SimPowerSystems, a specialized tool for hi-fidelity
% modeling of power systems and electromechanical drives. SimPowerSystems
% is a Simulink add-on that can be integrated with Simscape enabling
% gradual model elaboration and comparison of both modeling languages in a
% single model. 
% The model also includes the original high-level Simscape component which
% will be used for validation by direct comaprison of the responses of teh
% two components. This is a quick way to validate that we are meeting the
% executable spec for this component. As you can see the two designs match
% quite closely. An important point is that the control strategies are
% completely different. The control algorithm for the simscape model is a
% simple PI controller. The SimPowerSystems generator uses a cascaded
% vector control component together with PI control to control the
% generator. 
% <matlab:linkClicked='link6';HEV_script_links; Let's look at the architecture of the generator control system>
% Simulink control Design, an add on for Simulink 7 was used to perform the
% control design, directly on the SimPowerSystems model using classical and
% modern linear control techniques. 

%% Fixed point implementation of controller
% Because all the design teams share a single environment, it is easy to do
% work in parallel and share models at various stages of elaboration. While
% our power systems team was developing their components, our software team
% was working on implementing the various controllers in C-Code using
% Real-Time Workshop Embedded Coder for automatic code generation. Before
% generating code, we had to convert the controller to fixed point
% implementation so that we could minimize our ECU costs. Lets look at the
% new Fixed-Point Tool in Simulink Fixed Point, an add on tool to Simulink
% 7 that is used to simplify the fixed-point conversion 
% <matlab:linkClicked='link7';HEV_script_links; Let's go through the process of converting a piece of the controller to Fixed-Point>
% Through the use of a GUI, various steps of the conversion are simplified
% including data logging, fixed and floating point comparisons, and
% auto-scaling of optimal fixed point settings.
% This model has been modified to convert floating point to fixed point.
% The settings are a first cut at the conversion. Lets evaluate the
% accuracy of our conversion when compared to the golden reference
% floating point model.
% Select the Speed Controller subsystem and then run the mode lwith the
% settings matching teh GUI image below. Thsi will grab a snapshot of the
% results of the current fixed point settings. 
% <<fxpt_gui_initial.jpg>>
% Navigate to the Speed Controller subsystem in the Fixed-Point Tool Now
% change _*Store results as:*_ to reference and _*Data type override:*_ to True
% doubles See below for reference. Run the model from the GUI or Simulink,
% this will save floating point results as a reference, for future
% comparison.
% <<fxpt_gui_gold_ref.jpg>>
% Create plot that compares floating and fixed point by following the two steps below:
% Navigate to the top level model and select the generator under contents(see step1
% below). Select Time Series Difference (A-R) Plot from the View menu(see step
% 2 below), this will generate the plot shown below step 2.
% The top subplot shows the fixed and floating point results, you can see
% that they are very different. The bottom subplot shows the error signal.
% Step 1. 
% <<fxpt_gui_plot_2.jpg>>
% Step 2. 
% <<fxpt_gui_plot.jpg>>
% <<fxpt_gui_plot_3.jpg>>
% Notice how we were able to quickly override the data in the model to
% switch between data types without actually modifying individual block
% settings in the Simulink model.
% <matlab:linkClicked='link8';HEV_script_links; Lets look at the plot showing the floating to fixed point comparison>
% So now that we have established that our conversion is not very accurate, lets use the
% fixed point autoscaling tool to improve our results
% Navigate to the Speed Controller subsystem. Under Autoscaling, set
% _*Autoscale Using:*_ to reference, and then click propose fraction
% lengths button, and then click on Apply accepted fraction lengths button
% <<fxpt_gui_autoscaling.jpg>>
% Now change _*Store results as:*_ to active and Data type override: to
% local settings, then run the model and view the comparison plot. 
% If you zoom in several times on the top plot, you can see the dotted nad
% solid lines are very close, ie the conversion was successful. Note the
% y-axis scle of the error plot.(see below)
% <<fxpt_gui_plot_4.jpg>>
% <matlab:linkClicked='link9';HEV_script_links; Lets look at the plot showing the floating to fixed point comparison>

%% Simulation Performance
% One of the tradeoffs with model fidelity is simulation performance. As
% expected, a system model with detailed SimPowerSystems components
% runs much slower than the high-level system model that uses the Simscape
% blocks. To help address this, Simulink 7 includes new integrated
% capabilities to speed up simulations under a variety of circumstances.
% Simulink Accelerator, which used to be a separate product, is now
% included into Simulink. Moreover, Simulink 7 also includes a Rapid
% Accelerator mode which takes advantage of dual-core capabilities of
% modern processors and speeds up the execution of your Simulink models
% even more than accelerator.
% <matlab:linkClicked='link10';HEV_script_links; Lets look at a bar chart that shows the comparison of Simulink running in normal mode, accelerator mode and rapid accelerator mode>

% Accelerator uses code generation under the hood to give a performance
% boost. Rapid accelerator uses code generation and also runs the Simulink
% model as a separate process on the second core to further speed up
% simulation when this is available.

%% Final Model
% Fast forward to the end of the design cycle, we now have a complete
% system level model with controllers that have been prepared for fixed
% point code generation 
% <matlab:linkClicked='link11';HEV_script_links; Open detailed HEV model>
% Let us briefly look at the components in the model. Note the additional
% detail of the drives models, vehicle models and fixed point
% implementation. We can now simulate this as we did with the original
% model and compare the results. We have simulated this in advance and
% plotted the data from the original system model and overlaid it with the
% detailed model. 
% <matlab:linkClicked='link12';HEV_script_links; Lest take a look at the bar chart>

open speed_mpg_comparison.fig 

% Notice how hi-fidelity system-level model we developed matches the
% results for the original executable specification.
% Now lets go back to PowerPoint presentation and summarize new features
% in Simulink 7 that we highlighted during this demonstration.

clear all; bdclose all; close all; clc

Contact us