首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用fmusdk将c文件/函数导出到FMU

如何使用fmusdk将c文件/函数导出到FMU
EN

Stack Overflow用户
提问于 2017-07-07 07:17:50
回答 1查看 1.2K关注 0票数 2

这是我的职责。我正试图将此代码导出到fmu。我正在使用范德克

对于每个周期(时间步骤),

  1. 我的input应该更改为在模拟期间给出的值。
  2. 应该调用myexecute()
  3. 在仿真过程中需要存储inputpout的值,这样才能在仿真后绘制出相应的值。

我尝试了范德克中给出的例子(范德克和值)。我创建了相应的fmus并在Amesim中导入它们。他们工作得很好。但是我想不出如何对我的C文件/函数做同样的事情。

代码语言:javascript
复制
/*
 * Execution function
 */
void  myexecute(double *input, double *pout) 
{
  (*pout) = 2 * (*input);
}

我检查了弹出的Ball.c和values.c,他们只有四种方法

代码语言:javascript
复制
setStartValues(ModelInstance *comp)
calculateValues(ModelInstance *comp)
getReal(ModelInstance *comp, fmi2ValueReference vr)
void eventUpdate(ModelInstance *comp, fmi2EventInfo *eventInfo, int isTimeEvent, int isNewEventIteration) 

有人能帮我完成这个fmi出口吗?总之,我正在寻找上述四个功能的内容。对上述4种方法的解释也是足够的。我可以为函数创建内容。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-07-07 11:32:40

考虑下面给出的C文件,类似于您提到的bouningBall.c或valus.c文件。由于您已经从另一个c文件中引用了函数myexecute,所以用正确的文件替换yourCFile.c和/或yourHFile.h。另外,您的modelDescription.xml应该与这个C文件同步。对于ex),guid值在两个文件中应该是相同的。此外,标量变量的值引用应该是相同的。分析<ScalarVariable name="pin" valueReference="0">#define pin_ 0。同样适用于pout。创建类似于bouncingBall的文件夹结构。创建一个单独的批处理文件,因为我们必须包括其他文件(yourCFile.c和/或yourHFile.h)

代码语言:javascript
复制
// define class name and unique id
#define MODEL_IDENTIFIER modelName
#define MODEL_GUID "{8c4e810f-3df3-4a00-8276-176fa3c90123}"

// define model size
#define NUMBER_OF_REALS 2
#define NUMBER_OF_INTEGERS 0
#define NUMBER_OF_BOOLEANS 0
#define NUMBER_OF_STRINGS 0
#define NUMBER_OF_STATES 1
#define NUMBER_OF_EVENT_INDICATORS 0

// include fmu header files, typedefs and macros
#include "fmuTemplate.h"
#include "yourHFile.h"
#include "yourCFile.c"

// define all model variables and their value references
// conventions used here:
// - if x is a variable, then macro x_ is its variable reference
// - the vr of a variable is its index in array  r, i, b or s
// - if k is the vr of a real state, then k+1 is the vr of its derivative
#define pin_        0
#define pout_       1

// define state vector as vector of value references
#define STATES { pout_ }

// called by fmi2Instantiate
// Set values for all variables that define a start value
// Settings used unless changed by fmi2SetX before fmi2EnterInitializationMode
void setStartValues(ModelInstance *comp) {
    r(pin_) = 2;
    r(pout_) = 4;
}

// called by fmi2GetReal, fmi2GetInteger, fmi2GetBoolean, fmi2GetString, fmi2ExitInitialization
// if setStartValues or environment set new values through fmi2SetXXX.
// Lazy set values for all variable that are computed from other variables.
void calculateValues(ModelInstance *comp) {
    if (comp->state == modelInitializationMode) {
        // set first time event
        comp->eventInfo.nextEventTimeDefined = fmi2True;
    }
}

// called by fmi2GetReal, fmi2GetContinuousStates and fmi2GetDerivatives
fmi2Real getReal(ModelInstance *comp, fmi2ValueReference vr){
    switch (vr) {
        case pin_  : return  r(pin_);
        case pout_ : return     r(pout_);
        default: return 0;
    }
}

// used to set the next time event, if any.
void eventUpdate(ModelInstance *comp, fmi2EventInfo *eventInfo, int isTimeEvent, int isNewEventIteration) {
    myexecute(&r(pin_), &r(pout_));
}

#include "fmuTemplate.c"
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44964787

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档