目录
不指定硬件树莓派
使用的模型
信号对象和信号指定
由于输入没指定维度时,生成代码报错,无法自动确定数据维度,后指定了维度。
模型参数配置:
尝试仅仅生成代码,不指定硬件为树莓派,此时勾选并发执行,将会报错:This model is configured for concurrent execution and has modeling constraints. To generate code, the 'Generate an example main program' option must be selected and the 'Target operating system' must be set to 'NativeThreadsExample' from the 'Templates' section of the 'Code Generation' pane of the Configuration Parameters dialog.该模型被配置为用于并发执行,并且具有建模约束。若要生成代码,必须选择“生成示例主程序”选项,并且必须从“配置参数”对话框的“代码生成”窗格的“模板”部分将“目标操作系统”设置为“NativeThreadsExample”。
此先设置为不并发。
现在先只试试中间算法部分,不涉及树莓派硬件IO,可以不勾选Package code and artifacts,勾选可以生成一个压缩包,包含所有内容,就有树莓派上的一些头文件、dll。
指定了一下step函数名字。
生成文件
生成的代码文件位于模型同级目录下“模型名_ert_rtw”文件夹内,这六个文件的作用分别是:
- ert_main.c:该文件是一个样例文件,向用户展示主程序如何调用模型代码,在代码集成时可以参考该文件;
- 模型名.c:该文件包含模型的全部实现方法,包含变量的声明和定义,Step函数、初始化函数、终止函数等的定义和实现,即“模型的本身”;
- 模型名.h:该文件包含模型所依赖的数据结构、数据类型的定义和声明,以及模型变量、模型算法函数的外部声明;
- 模型名_private.h:包含模型本地的宏和数据类型定义,有定义才会生成相关内容;
- 模型名_types.h:该文件包含模块参数(Parameters)和模型数据(Model Data)的数据结构的向前声明,在一些可重用函数中可能会被使用;
- rtwtypes.h:定义了基本的数据类型和宏,大部分的生成代码可能会依赖该文件;
- 模型名_data.c:上图中没有生成,但在某些情况下会生成该文件,其中包含模型中的模块参数(Parameters)、常数模块和I/O的数据结构的定义和声明。
CAN2PSC_types.h文件:
/*
* File: CAN2PSC_types.h
*
* Code generated for Simulink model 'CAN2PSC'.
*
* Model version : 1.3
* Simulink Coder version : 9.4 (R2020b) 29-Jul-2020
* C/C++ source code generated on : Mon Jun 12 16:10:53 2023
*
* Target selection: ert.tlc
* Embedded hardware selection: ARM Compatible->ARM Cortex
* Code generation objectives: Unspecified
* Validation result: Not run
*/
#ifndef RTW_HEADER_CAN2PSC_types_h_
#define RTW_HEADER_CAN2PSC_types_h_
/* Model Code Variants */
/* Forward declaration for rtModel */
typedef struct tag_RTM_CAN2PSC_T RT_MODEL_CAN2PSC_T;
#endif /* RTW_HEADER_CAN2PSC_types_h_ */
/*
* File trailer for generated code.
*
* [EOF]
*/
CAN2PSC_private.h文件:
/*
* File: CAN2PSC_private.h
*
* Code generated for Simulink model 'CAN2PSC'.
*
* Model version : 1.3
* Simulink Coder version : 9.4 (R2020b) 29-Jul-2020
* C/C++ source code generated on : Mon Jun 12 16:10:53 2023
*
* Target selection: ert.tlc
* Embedded hardware selection: ARM Compatible->ARM Cortex
* Code generation objectives: Unspecified
* Validation result: Not run
*/
#ifndef RTW_HEADER_CAN2PSC_private_h_
#define RTW_HEADER_CAN2PSC_private_h_
#include "rtwtypes.h"
#include "CAN2PSC.h"
extern void CAN2PSC_MATLABFunction1(const uint8_T rtu_UDP[26], real_T rtu_Num,
real_T rtu_TCANid, uint8_T rty_TCAN_Data[8], DW_MATLABFunction1_CAN2PSC_T
*localDW);
#endif /* RTW_HEADER_CAN2PSC_private_h_ */
/*
* File trailer for generated code.
*
* [EOF]
*/
CAN2PSC.h文件:
/*
* File: CAN2PSC.h
*
* Code generated for Simulink model 'CAN2PSC'.
*
* Model version : 1.3
* Simulink Coder version : 9.4 (R2020b) 29-Jul-2020
* C/C++ source code generated on : Mon Jun 12 16:10:53 2023
*
* Target selection: ert.tlc
* Embedded hardware selection: ARM Compatible->ARM Cortex
* Code generation objectives: Unspecified
* Validation result: Not run
*/
#ifndef RTW_HEADER_CAN2PSC_h_
#define RTW_HEADER_CAN2PSC_h_
#include <string.h>
#ifndef CAN2PSC_COMMON_INCLUDES_
#define CAN2PSC_COMMON_INCLUDES_
#include <math.h>
#include <string.h>
#include "rtwtypes.h"
#include "can_message.h"
#endif /* CAN2PSC_COMMON_INCLUDES_ */
#include "CAN2PSC_types.h"
/* Macros for accessing real-time model data structure */
/*用于访问实时模型数据结构的宏*/
#ifndef rtmGetErrorStatus
#define rtmGetErrorStatus(rtm) ((rtm)->errorStatus)
#endif
#ifndef rtmSetErrorStatus
#define rtmSetErrorStatus(rtm, val) ((rtm)->errorStatus = (val))
#endif
/* user code (top of export header file) */
/*用户代码(导出头文件顶部)*/
#include "can_message.h"
/* Block states (default storage) for system '<S1>/MATLAB Function1' */
/*系统'<S1>/MATLAB Function1'的块状态(默认存储)*/
typedef struct {
uint8_T TCAN_Last[8]; /* '<S1>/MATLAB Function1' */
} DW_MATLABFunction1_CAN2PSC_T;
/* Block signals (default storage) */
/*块信号(默认存储)*/
typedef struct {
CAN_DATATYPE CANPack3; /* '<S1>/CAN Pack3' */
CAN_DATATYPE CANPack1; /* '<S1>/CAN Pack1' */
real_T CANUnpack4_o1; /* '<S1>/CAN Unpack4' */
real_T CANUnpack4_o2; /* '<S1>/CAN Unpack4' */
real_T CANUnpack4_o3; /* '<S1>/CAN Unpack4' */
real_T CANUnpack4_o4; /* '<S1>/CAN Unpack4' */
real_T CANUnpack4_o5; /* '<S1>/CAN Unpack4' */
real_T CANUnpack4_o6; /* '<S1>/CAN Unpack4' */
real_T CANUnpack4_o7; /* '<S1>/CAN Unpack4' */
real_T CANUnpack4_o8; /* '<S1>/CAN Unpack4' */
real_T CANUnpack4_o9; /* '<S1>/CAN Unpack4' */
real_T CANUnpack4_o10; /* '<S1>/CAN Unpack4' */
real_T CANUnpack4_o11; /* '<S1>/CAN Unpack4' */
real_T CANUnpack4_o12; /* '<S1>/CAN Unpack4' */
real_T CANUnpack4_o13; /* '<S1>/CAN Unpack4' */
real_T CANUnpack4_o14; /* '<S1>/CAN Unpack4' */
real_T CANUnpack4_o15; /* '<S1>/CAN Unpack4' */
real_T CANUnpack4_o24; /* '<S1>/CAN Unpack4' */
real_T CANUnpack4_o25; /* '<S1>/CAN Unpack4' */
real_T CANUnpack4_o26; /* '<S1>/CAN Unpack4' */
real_T CANUnpack4_o27; /* '<S1>/CAN Unpack4' */
real_T CANUnpack1_o3; /* '<S1>/CAN Unpack1' */
real_T CANUnpack1_o4; /* '<S1>/CAN Unpack1' */
real_T CANUnpack1_o6; /* '<S1>/CAN Unpack1' */
real_T CANUnpack1_o7; /* '<S1>/CAN Unpack1' */
uint8_T TCAN_Data[8]; /* '<S1>/MATLAB Function8' */
uint8_T TCAN_Data_n[8]; /* '<S1>/MATLAB Function1' */
} B_CAN2PSC_T;
/* Block states (default storage) for system '<Root>' */
/*系统'<Root>'的块状态(默认存储)*/
typedef struct {
int_T CANUnpack4_ModeSignalID; /* '<S1>/CAN Unpack4' */
int_T CANUnpack4_StatusPortID; /* '<S1>/CAN Unpack4' */
int_T CANUnpack1_ModeSignalID; /* '<S1>/CAN Unpack1' */
int_T CANUnpack1_StatusPortID; /* '<S1>/CAN Unpack1' */
DW_MATLABFunction1_CAN2PSC_T sf_MATLABFunction8;/* '<S1>/MATLAB Function8' */
DW_MATLABFunction1_CAN2PSC_T sf_MATLABFunction1;/* '<S1>/MATLAB Function1' */
} DW_CAN2PSC_T;
/* Real-time Model Data Structure */
/*实时模型数据结构*/
struct tag_RTM_CAN2PSC_T {
const char_T *errorStatus;
};
/* Block signals (default storage) */
extern B_CAN2PSC_T CAN2PSC_B;
/* Block states (default storage) */
extern DW_CAN2PSC_T CAN2PSC_DW;
/* Model entry point functions */
/*模型入口点函数*/
extern void CAN2PSC_initialize(void);
extern void CAN2PSCFunc(void);
extern void CAN2PSC_terminate(void);
/* Real-time Model object */
/*实时模型对象*/
extern RT_MODEL_CAN2PSC_T *const CAN2PSC_M;
/* Exported data declaration */
/*导出的数据声明*/
/* Declaration for custom storage class: Global */
/*自定义存储类的声明:全局*/
extern real_T PDC1_Status_DistanceFL_Lvl;/* '<S1>/CAN Unpack4' */
extern real_T PDC1_Status_DistanceFML_Lvl;/* '<S1>/CAN Unpack4' */
extern real_T PDC1_Status_DistanceFMR_Lvl;/* '<S1>/CAN Unpack4' */
extern real_T PDC1_Status_DistanceFR_Lvl;/* '<S1>/CAN Unpack4' */
extern real_T PDC1_Status_DistanceRL_Lvl;/* '<S1>/CAN Unpack4' */
extern real_T PDC1_Status_DistanceRML_Lvl;/* '<S1>/CAN Unpack4' */
extern real_T PDC1_Status_DistanceRMR_Lvl;/* '<S1>/CAN Unpack4' */
extern real_T PDC1_Status_DistanceRR_Lvl;/* '<S1>/CAN Unpack4' */
extern real_T PSC2_Status_FlankDistanceFL_Lvl;/* '<S1>/CAN Unpack1' */
extern real_T PSC2_Status_FlankDistanceFR_Lvl;/* '<S1>/CAN Unpack1' */
extern real_T PSC2_Status_FlankDistanceRL_Lvl;/* '<S1>/CAN Unpack1' */
extern real_T PSC2_Status_FlankDistanceRR_Lvl;/* '<S1>/CAN Unpack1' */
extern uint8_T PSC_UDP_Data[26]; /* '<Root>/In1' */
/*-
* The generated code includes comments that allow you to trace directly
* back to the appropriate location in the model. The basic format
* is <system>/block_name, where system is the system number (uniquely
* assigned by Simulink) and block_name is the name of the block.
*
* Use the MATLAB hilite_system command to trace the generated code back
* to the model. For example,
*
* hilite_system('<S3>') - opens system 3
* hilite_system('<S3>/Kp') - opens and selects block Kp which resides in S3
*
* Here is the system hierarchy for this model
*
* '<Root>' : 'CAN2PSC'
* '<S1>' : 'CAN2PSC/CAN2_PSC'
* '<S2>' : 'CAN2PSC/CAN2_PSC/MATLAB Function1'
* '<S3>' : 'CAN2PSC/CAN2_PSC/MATLAB Function8'
*/
/*-
*生成的代码包括注释,这些注释允许您直接追溯到模型中的适当位置。基本格式为<system>/block_name,其中system是系统编号(由Simulink唯一分配),block_name是块的名称。
*
*使用MATLAB hilite_system命令将生成的代码追溯到模型。例如
*
*hilite_system('<S3>')-打开系统3
*hilite_system('<S3>/Kp')-打开并选择驻留在S3中的块Kp
*
*以下是此模型的系统层次结构
*
*'<Root>':'CAN2PSC'
*“<S1>”:“CAN2PSC/CAN2_PSC”
*“<S2>”:“CAN2P