Guy on 金宝appSimulink

金宝app仿真软件和基于模型的设计

Internal Combustion Engine Ignition Controller Example - Part 2

我以前的文章, I introduced an example I recently published on MATLAB Central:四缸发动机点火控制仿真

描述植物模型如何实现后,现在是时候来描述控制器是如何实现的,以及整个系统的模拟。

大局

让我们先从回顾整个系统我们正在处理:

SchedulerOverview

在此系统中,以下情况:

  • 发动机曲轴是配备了一个齿轮。在这种情况下,牙齿是等距的每10度,与一个丢失的牙齿。
  • When the crankshaft rotates, the years pass in front of a sensor that triggers the an interrupt, executing code on the ECU.
  • The code computes The position and speed of The engine and determines The when The next cylinder should fire.
  • 代码设置了一个硬件定时器,在适当的时间适当的火花塞。

这个项目的目标是设计一个算法执行的嵌入式控制单元(ECU)操作系统(OS)调度器。该算法计算引擎的位置和速度,并确定下一个缸应该火。一旦确定,算法调用计时器ECU操作系统提供的服务会照顾的点火发生在正确的时间。

基于模型的设计理念后,我们(当然!)想模拟整个系统来帮助设计和验证控制算法,将部署在ECU。

Important Model Architecture Decision: Importing Code versus Exporting Code

在描述控制器及其实现之前,我想介绍一个重要的设计选择我为这个例子。

In most of my posts On this blog, involving code generation, the end of the story is: Click the Build button to generate code, and the final executable is automatically compiled and executed On the target. This is how金宝appSimulink Real - Time和我们的支持包等金宝app目标覆盆子πThe oriPhone / iPad工作。在这些情况下,如果最终遗留应用程序需要C / c++代码包含代码importedIn 金宝appSimulink, typically using aTLC包装. See my blogs about a微博覆盆子πThe orThe Custom driver for LEGO MINDSTORMFor examples.

This is one way of doing things...We call it theThe Import Workflow

现在,是时候去阅读文档页面Choose an External Code Integration WorkflowTo learn about the other way of doing things...the出口流程

这是一个示意图比较这两个并排的工作流:

The Export of the Import Vs

为什么我选择这个项目出口的工作流程?

The use case addressed by The Export Workflow is The where you have an existing large C/C + + software project composed of hand - written and legacy components. In to The case, if you want to develop a new com金宝appponent In Simulink, you can Export The generated code and include it In The existing software project.

这样,模型导出的代码都可以称为遗留代码,并调用遗留代码。金宝app在下一节中,我们将会看到:

  • How the final application deployed on the embedded controller looks
  • How the simulation of the - system looks
  • 如何模拟遗留调度程序执行代码从仿真软件出口吗金宝app
  • How to setup part of a model to generate code compatible with the Export of Workflow
  • How to emulate the services provided by the ECU being utilized by the code exported f金宝approm Simulink

The Final Application Deployed on The Embedded Controller

Here is a picture describing how the final deployed application looks. Note that, to make the difference between handwritten legacy code and 金宝appSimulink - generated code more obvious, I took the screenshots of the legacy code using a company's editor, theArduino IDE

The Controller the overview

在这张图片中,我们有:

  1. The ECU scheduler registers The code exported from 金宝appSimulink (trigCrank)执行基于机械轴的运动。
  2. 代码从仿真软件出口(金宝apptrigCrank) determines the when the next spark ignition should happen.
  3. The code exported from 金宝appSimulink calls a service provided by The ECU OS (setIgnitionSchedule) that will use a hardware timer to produce the spark ignition at the right time.

模拟整个系统

这是顶级的一个屏幕快照模型的模拟整个系统。我使用相同的编号在上面的图像展示哪个子系统相当于已部署的应用程序的一部分。这意味着Stateflow图表标记“1”和子系统标有“3”是模仿遗留功能提供的ECU。

控制器仿真概述

Emulating a Legacy Scheduler using Stateflow

在已部署的应用程序,操作系统调度程序调用函数。在仿真金宝app软件中,这意味着我们需要生成函数调用信号。对于周期性的事件,它很简单:我们可以使用函数调用生成器块。

生成函数调用信号当曲柄角通过特定的角度,我用一块模型的例子sfcndemo_angle_events.slx, which is part of thes函数的例子I. simple had to connect it to the crankshaft and camshaft and specify the teeth pattern in the block dialog.

异步功能。

使用零交点检测这一块将准确地生成函数调用事件每一次牙齿。然后我可以把这些事件与一个周期函数调用使用函数调用生成器生成块触发调度图:

Stateflow调度器

然后Stateflow图表输出函数调用信号,将执行我们想出口的控制算法代码。

Setting Up Part of a Model to Generate Code Compatible with the Export of Workflow

现在是时候讨论我们想出口的控制算法生成的代码!

符合出口的工作流程,我们将算法在一个单独的模型,并引用它在我们的系统仿真使用模型块。

让它一个The Export - Function Model,控制算法必须放置在函数调用子系统所引发的根级尺寸块标记输出函数调用信号。

为这个模型生成代码时,与“正常”模式,不会产生阶跃函数。相反,一个函数每根级将生成函数调用轮廓尺寸。

Export the Function Model and code

模拟ECU所提供的服务

The Last piece of the puzzle...The control algorithm needs to utilize functionalities provided by the ECU. In other words, it needs to call external functions provides - and we want to simulate those.

为此,导出功能模型中,我使用了The Function CallerBlock to be executed when it is time to schedule the when the next cylinder needs to the fire.

这个函数调用块生成的代码和仿真上的表现也不同:

  • The code generated for The Function Caller blocks will call and link against functions provides The available on The ECU.
  • The When referenced in our system simulation model, the Function Caller block will call a金宝app仿真软件的功能Located in the top simulation model.

    函数调用者

    对于这个特定的应用程序,操作系统服务,需要模拟硬件定时器会火的火花塞后所需的时间。为此,我决定使用SimEvents

    模型函数金宝app生成一个SimEvents消息或实体。这个实体通过两个实体服务器块。第一个服务,直到该火花塞。第二个服务,直到它是火花塞放电时间。每次实体出口两个服务器之一,他们称之为仿真软件的功能金宝apptrigCyl生成点火信号发送到引擎。

    SimEvents

    和循环现在关门了!

    仿真结果

    模拟模型时,您将看到如何发动机转速的发展我们启动和关闭引擎,当我们进行传播。

    结果1

    如果你放大点火命令,您将看到当每个汽缸曲轴的旋转。

    结果2

    Now it 's your turn

    在评论中让我们知道你认为这个模型的体系结构和如果有其他功能你想看到这样的例子。

|

评论

要发表评论,请点击here登录到您的MathWorks帐户或创建一个新帐户。