7
Introduction The development of high-fidelity predictive models of vehicle engines is a major preoccupation of powertrain engineers. By developing “virtual” prototypes of their engine designs, automotive manufacturers can obtain tremendous insight into the behavior of the engine, particularly for controller design and development, to maximize performance while complying with governmental and ecological constraints. Doing this before investing in the prototyping stages has been proven to save significant time and costs during the product development process. In a previous article, “Mean-Value Internal Combustion Engine Model with MapleSim™,” we described the development of a high-fidelity model of an internal combustion engine based on the underlying equations describing the behavior of the different components. The “mean-value” approach essentially ignores the cyclic details of the engine, such as crank rotation, piston motion, gas compression/expansion and ignition, and provides the overall power/ torque/speed output in response to the mass of air/fuel mixture flowing into the engine. This approach is particularly favored by powertrain control developers because the models deal only with the properties of the system the engineers are interested in (in this case, engine torque and speed), and the models are faster to simulate. Now that we have the model, the next step is to deploy this model further down the toolchain. This article will document the process of exporting the engine model to Simulink® for further development and deployment to real-time systems such as dSPACE®. Mean-Value Internal Combustion Engine Model: Simulink ® S-Function Generation from MapleSim

Mean-Value Internal Combustion Engine Model: …...All that remains is defining the parameters for the subsystem. Mean-Value Internal Combustion Engine Model: Simulink® S-Function

  • Upload
    others

  • View
    1

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Mean-Value Internal Combustion Engine Model: …...All that remains is defining the parameters for the subsystem. Mean-Value Internal Combustion Engine Model: Simulink® S-Function

IntroductionThe development of high-fidelity predictive models of vehicle engines is a major preoccupation of powertrain engineers. By developing “virtual” prototypes of their engine designs, automotive manufacturers can obtain tremendous insight into the behavior of the engine, particularly for controller design and development, to maximize performance while complying with governmental and ecological constraints. Doing this before investing in the prototyping stages has been proven to save significant time and costs during the product development process.

In a previous article, “Mean-Value Internal Combustion Engine Model with MapleSim™,” we described the development of a high-fidelity model of an internal combustion engine based on the underlying equations describing the behavior of the different components. The “mean-value” approach essentially ignores the cyclic details of the engine, such as crank rotation, piston motion, gas compression/expansion and ignition, and provides the overall power/torque/speed output in response to the mass of air/fuel mixture flowing into the engine. This approach is particularly favored by powertrain control

developers because the models deal only with the properties of the system the engineers are interested in (in this case, engine torque and speed), and the models are faster to simulate.

Now that we have the model, the next step is to deploy this model further down the toolchain. This article will document the process of exporting the engine model to Simulink® for further development and deployment to real-time systems such as dSPACE®.

Mean-Value Internal Combustion Engine Model: Simulink® S-Function Generation from MapleSim™

Page 2: Mean-Value Internal Combustion Engine Model: …...All that remains is defining the parameters for the subsystem. Mean-Value Internal Combustion Engine Model: Simulink® S-Function

Simulink®, three steps must be performed:

1) Identify which parts of the model will be exported and gather them into a single subsystem in MapleSim;

2) Define which properties will be

inputs to and outputs from the subsystem; and

3) Define the subsystem parameters, identifying those that will be hard-coded and those that the user will be able to edit in Simulink®.

Mean-Value IC Engine Model

Figure 1: Mean-value engine model in MapleSim

Figure 2: Definition of exported subsystem, “CompleteEngine”

1. Create a Subsystem of the Model Components to be ExportedTo define which parts of the model to export, you need to select the required components and create a subsystem component. In this case, the throttle, manifold, engine, and dynamometer (load) subsystems were selected and combined into a subsystem called “CompleteEngine.”

Mean-Value Internal Combustion Engine Model: Simulink® S-Function Generation from MapleSim™

Model Preparation The mean-value engine model, shown in Figure 1, was developed using published equations from several industry-standard texts (see the References section), implemented as custom components in MapleSim, and demonstrates the use of signal-flow (or causal) and topological (or acausal) modeling techniques in combination.

The engine model is composed of three main subsystems: the throttle, the intake manifold, and engine power generation from the fuel combustion. Loading on the engine shaft is provided by a model of a dynamometer, acausally connected to the engine drive shaft. The engine speed is determined by a simple controller that regulates the angle of the throttle valve, which in turn controls the air/fuel mass flow through the throttle, the manifold and into the engine.

To prepare the model for code generation and implementation in

Page 3: Mean-Value Internal Combustion Engine Model: …...All that remains is defining the parameters for the subsystem. Mean-Value Internal Combustion Engine Model: Simulink® S-Function

Figure 3: The CompleteEngine subsystem with input and output ports

Figure 4: The CompleteEngine subsystem from the top level

By rearranging the signal port positions, the subsystem is almost ready for export. All that remains is defining the parameters for the subsystem.

Mean-Value Internal Combustion Engine Model: Simulink® S-Function Generation from MapleSim™

2. Determine the Input and Output SignalsSince the target application (Simulink®) is a signal-flow environment, the connections between the engine subsystem and the rest of the environment need to be signal inputs and outputs. In this particular case, the inputs are the valve angle from the Speed Controller and the road load, and the outputs are engine speed, engine brake power, and fuel mass flow.

Most of these inputs and outputs appear automatically. Wherever a line crosses the boundary between a selected component and an unselected one, an input or output port will appear at the subsystem boundary, depending on the direction of the signal flow. When needed, it is very easy to define additional ports at the subsystem boundary. Inside the subsystem, simply connect the desired port to any position on the boundary (indicated by a dashed box) and the appropriate port appears.

This has been done for the brake power signal coming from the Engine subsystem. In Figure 3, the green dot indicates the position of the port before it is confirmed with a mouse click. It is a good practice to rename the ports to something more meaningful than the automatically generated default names. For this project, the inputs have been renamed to AngleInput and LoadInput, and the outputs to EngineSpeedOutput, FuelFlowOutput, and BrakePowerOutput.

Note that when you hover your mouse pointer over a port on the new subsystem, the port name appears in a tooltip (Figure 4).

Page 4: Mean-Value Internal Combustion Engine Model: …...All that remains is defining the parameters for the subsystem. Mean-Value Internal Combustion Engine Model: Simulink® S-Function

3. Define the System ParametersBefore the export process, all the parameters used by the CompleteEngine subsystem must be defined within the subsystem, so they are properly exported and available from Simulink®. These parameters will be divided into two groups: those whose values can be modified from within Simulink®, and those whose values should be defined as constants in the generated code.

In MapleSim, parameter definitions are scoped. Parameter values defined at one level of the model hierarchy are inherited by all of its subsystems, unless

they are explicitly overridden at a lower level. This means you can define the parameter values at the top level and these will be used throughout the model hierarchy. You can then override a parameter value for use in a particular subsystem, or even set new and different values for the same parameter in different subsystems. Managing these parameters and their different values is done through parameter blocks. In this case, in order to ensure all values needed by the Complete Engine model are properly exported, all parameters need to be explicitly defined at the level of the CompleteEngine subsystem. This is easily

Figure 5: Opening the Parameter Editor and entering the local parameters

achieved by copying the Engine Parameters block at the top level and pasting it into the CompleteEngine subsystem.

The next step is to define which parameters should be modifiable by the user in the block mask within Simulink®. For the purpose of this project, throttle diameter, stroke, bore, number of cylinders, and the fuel internal heat value were made available as user-editable parameters. During the export process, all other parameters are hard-coded as constants.

To make these values user-editable from within Simulink®, they must be declared as local parameters to the CompleteEngine subsystem. This is done using the Parameter Editor, which is opened by clicking the Parameter Editor button. Because these parameters will be receiving their values from elsewhere, the default value is set to the parameter’s own name (see Figure 5 and Figure 6). Before the export process, the effect is that the local parameter, Dt (for example), will take on the value of the global Dt, which is defined at the top level. After the export process, Dt will be given its value based on the Simulink® settings, using the MapleSim global value as the default.

Finally, a little cleanup. The parameters which have just been declared to be local are now declared twice at the level of the CompleteEngine subsystem – once in the parameter block and once in the local parameter list. While parameters can be defined with different values at different places in the model hierarchy, they cannot appear more than once at the same level. Therefore, these names must be removed from the parameter block.

Figure 6: User-defined local parameters for the CompleteEngine subsystem

Mean-Value Internal Combustion Engine Model: Simulink® S-Function Generation from MapleSim™

Page 5: Mean-Value Internal Combustion Engine Model: …...All that remains is defining the parameters for the subsystem. Mean-Value Internal Combustion Engine Model: Simulink® S-Function

S-Function Generation for Simulink®

Once the model subsystem has been prepared as described in the previous section, it is ready for code generation using the MapleSim Connector. When you install the connector, a template for Simulink® block generation is placed in the MapleSim Document Folder template list. See Figure 7.

When this template is opened, the system model appears embedded in the document (see Figure 8).

Using the template, the model equations and parameters are extracted and the model is stored in an internal data structure. The “Model Summary” section displays the input and output signals. These are identified using the port names defined in step 2. (See Figure 9.)

You can specify the block name, which will be used as the name of the model code file and the name of the model in Simulink®. The default is the name of the top-level subsystem name (in this case, CompleteEngine1).

The “Simulink Block Generation” section provides several options for how the model parameters will appear in the S-Function block mask (the Simulink® equivalent of the Parameter Inspector in MapleSim) as well as options for the code generation and projection solver.

Under the “Setting Parameters” subsection, you can choose which parameters will remain as hard-coded constants (under “Substituted Parameters”) and which will appear in the parameter mask so that the user can change them (under “Block Parameters”). For this project, all five parameters have been moved to the “Block Parameters” list. The default value for each parameter can be seen by clicking on the parameter name (see Figure 10).

The “Advanced Code Generation Settings” provides various fine-tuning options for code optimization and the DAE constraint projection solver (mdlProjection) in Simulink®. For most applications, they can be left in their default state. (See Figure 11.)

Mean-Value Internal Combustion Engine Model: Simulink® S-Function Generation from MapleSim™

Figure 8: The CompleteEngine subsystem in the Simulink® Block Template

Figure 7: Simulink® Block Generation Template in the Document Folder

Figure 9: System equation extraction and identified inputs/outputs

Figure 10: Setting the block mask parameters

Figure 11: Advanced code generation settings

Page 6: Mean-Value Internal Combustion Engine Model: …...All that remains is defining the parameters for the subsystem. Mean-Value Internal Combustion Engine Model: Simulink® S-Function

Mean-Value Internal Combustion Engine Model: Simulink® S-Function Generation from MapleSim™

The “Generate Simulink Block” section is the final step in the model code-generation process. You can either set the path where the block code will be saved or use the default path. You can choose to place the S-Function block directly into a Simulink® model diagram or save it in the Simulink® Block Library for easy use in multiple models. In this case, all of the options were left as their default values (see Figure 12) and the block was saved directly in a Simulink® model by clicking the “Generate to Simulink” button.

MapleSim generates the C code for the model and the mdl Block script for Simulink® to create a library block. If you have Simulink® installed on your computer, MapleSim launches it and displays the CompleteEngine model in the user library (see Figure 13).

When you view the block properties, all the information about the block inputs, outputs, and parameters is provided. There are also entry fields for initial conditions and parameters, which are pre-populated with the default values passed from MapleSim.

The block is now ready to be used in Simulink®. A test example was created to replicate the closed-loop model in MapleSim (see Figure 14). The resulting engine response closely follows the response in MapleSim.

Because the S-Function is based on ANSI C code generated from MapleSim (see Figure 15), the model code is compatible with Real-Time Workshop® and can be executed on a real-time target platform. In a future project, the model will be tested on a dSPACE system. The Simulink® model is also available from the Maplesoft Application Center (www.maplesoft.com/engine_model/) if you wish to try it yourself.

Figure 12: Simulink® Block options and generation

Figure 13: CompleteEngine block in the Simulink® user library

Figure 14: Engine test model in Simulink®

Page 7: Mean-Value Internal Combustion Engine Model: …...All that remains is defining the parameters for the subsystem. Mean-Value Internal Combustion Engine Model: Simulink® S-Function

Further WorkThe engine model described in this article was phase one of an ongoing project to produce a realistic, parameterized mean-value model for a range of internal combustion engines. Based on feedback from industrial experts, there is a growing list of enhancements that will be made to the model as the project progresses. These include variation of air/fuel ratio (currently assumed constant), effects of ignition and variable valve timing (VVT), as well as the addition of components such as turbo-chargers and catalytic converters.

The next phase of the engine model will include transmission and drivetrain models so that the model can be used with published driving cycles; this will allow the model to be fully validated against other engine models and real engine test data. In addition, we will create a real-time implementation on a dSPACE system and other systems.

ConclusionThis project demonstrates the process of preparing a mean-value engine model and then converting it to an S-Function for implementation in Simulink®. The project illustrates the ease and speed with which this process can be carried out: the preparation and S-Function generation took less than an hour by an engineer with moderate knowledge of MapleSim and Simulink®.

MapleSim provides a very easy-to-use environment for developing models and deploying it to Simulink® The result is a model development process that takes a fraction of the time and cost it would take using Simulink® alone.

AcknowledgementsThis project is based on the work of Mohammadreza Saeedi, at the University of Waterloo, supervised by Dr. Roydon Fraser and Dr. John McPhee. Maplesoft also owes a debt of gratitude to Joseph Lomonaco at Harley-Davidson for invaluable industrial guidance during the development of this model.

References

Maplesoft: Mean-value Internal Combustion Engine Model with MapleSim, www.maplesoft.com/engine_model

Cook, J. A., Powell, B., K., Discrete Simplified External Linearization and Analytical Comparison of IC Engine Families, Proceedings of the American Control Conference, 1987.

Crossley, P. R., Cook, J. A., A Nonlinear Engine Model for Drive Train System Development, Proceedings of IEEE International Conference, Control’91, 2:921–925, Confer-ence publication 332, Edinburgh, UK, 1991.

Dobner, D. J., A Mathematical Engine Model for Development of Dynamic Engine Control, SAE 800054.

Dawson, J. A., An Experimental and Computational Study of Internal Combustion Engine Modeling for Controls Oriented Research, Ph. D. dissertation, Ohio State University, 1998.

Gillespie, T. D., Fundamentals of Vehicle Dynamics, SAE International, 1992.

Guzzella, L., Onder, C. H., Introduction to Modeling and Control of Internal Combustion Engine Systems, Springer, 2004.

Hendricks, E., Chevalier, A., Jensen, M., Sorenson, S. C., Modeling of the Intake Manifold Filling Dynamics, SAE 960037

Hendricks, E., Sorenson, S. C., Mean Value Modeling of Spark Ignition Engines, SAE 900616

Hendricks, E., Vesterholm, T., The Analysis of Mean Value SI Engine Models, SAE 920682.

Heywood, J. B., Internal Combustion Engine Fundamentals, McGraw Hill, 1988.

Moskwa, J. J., Automotive Engine Modeling for Real-Time Control Using MATLAB®/Simulink®, SAE 950417.

Moskwa, J. J., Automotive Engine Modeling for Real-Time Control, Ph.D. dissertation, Massachusetts Institute of Technology, 1988.

Yuen, W.W., Servati, H., A Mathematical Engine Model Including the Effect of Engine Emissions, SAE 840036.

www.maplesoft.com | [email protected] Toll-free: (US & Canada) 1-800-267-6583 | Direct:1-519-747-2373

© Maplesoft, a division of Waterloo Maple Inc., 2010. Maplesoft, Maple, and MapleSim are trademarks of Waterloo Maple Inc. MATLAB, Real-Time Workshop, and Simulink are registered trademarks of The MathWorks, Inc.

Figure 15: C-code fragment from MapleSim