专业编程基础技术教程

网站首页 > 基础教程 正文

实例讲解Simulink建立模型的版本管理

ccvgpt 2024-10-19 03:24:53 基础教程 7 ℃

在MBD的软件开发过程中,需要对模型及生成的代码进行版本管理。需要在MATLAB的Simulink的版本管理中撰写版本变更内容及版本号,可以更好的管理模型及功能开发生成的代码。今天主要是以实际的例子介绍Simulink模型的版本管理。


1.新建一个模型

实例讲解Simulink建立模型的版本管理

在MATLAB中新建一个模型,根据实际的开发内容建立模型如图1和图2所示,建立一个低通滤波的子系统模型。

图1 新建Simulink模型

图2 低通滤波模型

图3 低通滤波子系统内部构建


2.查看模型的版本信息

在打开的Simulink模型的空白处,右键选择Model Properties属性,操作如图4所示。

图4 查看模型的版本信息

点击Info,可以查看和修改模型的版本信息,具体如图5所示。

1.Created by:模型创建的作者名称
2.Created on:模型创建的时间
3.Last saved by:模型上一次修改的作者名称
4.Last save on:模型上一次修改的时间
5.Model version:模块的版本号,此时可以修改。

图5 模型版本info

在图5中,取消勾线Read Only,即可修改模型的上述五种信息的内容,具体操作如6所示。例如修改模型的版本为1.0.0,之后点击Apply,即可修改模型的版本属性,修改之后可以勾选Read Only属性,之后点击Apply和Ok。

图6 可编辑版本信息属性

图7 修改模型属性

图8 版本信息设置保存

在修改好信息之后,点击模型时,在模型的预览窗口里面会显示模型的版本信息,具体如图9所示。

图9 模型的版本预览

可以在模型属性的Description中写上版本的变更内容,可以更好的将模型的变更范围确定,方便团队合作和开发后期的问题排查,具体操作如图10所示。

图10 模型的变更内容管理


3.生成代码

修改模型的配置,如图11和图12所示。

图11 模型的求解器配置

图12 模型生成代码配置

使用Embedded Coder生成嵌入式代码,具体操作如图13和图14所示。

图13 生成代码

图14 生成代码

此时生成的代码中的版本号则和在模型中设置的版本号一致,这样模型自动生成的代码和模型的版本号相关联起来,方便版本的变更管理和问题的排查,具体操作和结果如图15和图16所示。

图15 模型生成代码

图16 模型生成的程序文件清单



/*
 * File: model_management.c
 *
 * Code generated for Simulink model 'model_management'.
 *
 * Model version                  : 1.0.0
 * Simulink Coder version         : 9.5 (R2021a) 14-Nov-2020
 * C/C++ source code generated on : Sun Jul  7 15:31:00 2024
 *
 * Target selection: ert.tlc
 * Embedded hardware selection: Intel->x86-64 (Windows64)
 * Code generation objectives: Unspecified
 * Validation result: Not run
 */


#include "model_management.h"
#include "model_management_private.h"


/* Real-time model */
static RT_MODEL_model_management_T model_management_M_;
RT_MODEL_model_management_T *const model_management_M = &model_management_M_;


/* Model step function */
void model_management_step(void)
{
  /* Update absolute time for base rate */
  /* The "clockTick0" counts the number of times the code of this task has
   * been executed. The absolute time is the multiplication of "clockTick0"
   * and "Timing.stepSize0". Size of "clockTick0" ensures timer will not
   * overflow during the application lifespan selected.
   */
  model_management_M->Timing.t[0] =
    ((time_T)(++model_management_M->Timing.clockTick0)) *
    model_management_M->Timing.stepSize0;


  {
    /* Update absolute timer for sample time: [0.001s, 0.0s] */
    /* The "clockTick1" counts the number of times the code of this task has
     * been executed. The resolution of this integer timer is 0.001, which is the step size
     * of the task. Size of "clockTick1" ensures timer will not overflow during the
     * application lifespan selected.
     */
    model_management_M->Timing.clockTick1++;
  }
}


/* Model initialize function */
void model_management_initialize(void)
{
  /* Registration code */
  {
    /* Setup solver object */
    rtsiSetSimTimeStepPtr(&model_management_M->solverInfo,
                          &model_management_M->Timing.simTimeStep);
    rtsiSetTPtr(&model_management_M->solverInfo, &rtmGetTPtr(model_management_M));
    rtsiSetStepSizePtr(&model_management_M->solverInfo,
                       &model_management_M->Timing.stepSize0);
    rtsiSetErrorStatusPtr(&model_management_M->solverInfo, (&rtmGetErrorStatus
      (model_management_M)));
    rtsiSetRTModelPtr(&model_management_M->solverInfo, model_management_M);
  }


  rtsiSetSimTimeStep(&model_management_M->solverInfo, MAJOR_TIME_STEP);
  rtsiSetSolverName(&model_management_M->solverInfo,"FixedStepDiscrete");
  rtmSetTPtr(model_management_M, &model_management_M->Timing.tArray[0]);
  model_management_M->Timing.stepSize0 = 0.001;
}


/* Model terminate function */
void model_management_terminate(void)
{
  /* (no terminate code required) */
}


/*
 * File trailer for generated code.
 *
 * [EOF]
 */

当模型的内容变更时,我们需要及时的修改版本号,并在描述中记录变更的内容,方便进行及时的模型和代码进行同步。

本文内容来源于网络,仅供参考学习,如内容、图片有任何版权问题,请联系处理,24小时内删除。


作 者 | 郭志龙

编 辑 | 郭志龙
校 对 | 郭志龙

Tags:

最近发表
标签列表