主要介绍外部控制器的的通讯

/*
外部控制器的自定义有两种实现方式:.EXE和.DLL
编译成可执行文件(.EXE)的外部控制器与Bladed模拟数据之间通过共享的二进制文件来进行信息交换,二进制文件由多个4字节记录组成。文件中的4字节记录应该写入或者读取4字节(单精度)的整数,实数(浮点数)或者4个字节的字符组。这个想通过python生成exe来实现,毕竟python深度学习机器学习的开源库能够利用到风机上真是让人遐想万分,先mark,以后再做。
以DLL动态链接库形式编译的,所有数组单元以实数传递,软件安装的里面有一个使用c++编写DLL完成外部控制器的demo,代码难度不大,仔细看一下,要点就是要注意指导使用手册里面的数据交换的表点存储的位置和数据格式。

*/

#include <string.h>
#define NINT(a) ((a) >= 0.0 ? (int)((a)+0.5) : (int)((a)-0.5))
float *SwapArray;
float GetSwapValue(int Index)           { return(SwapArray[Index-1]); }
void SetSwapValue(int Index, float Val) { SwapArray[Index-1] = Val; }

extern "C" void __declspec(dllexport) __cdecl DISCON (float *avrSwap,
        int *aviFail, char *accInfile, char *avcOutname, char *avcMsg)
{
    int iStatus;
    static float rPitchDemand;

    SwapArray = avrSwap;    //Store the pointer

    //Make sure there's a C string terminator
    accInfile[NINT(avrSwap[49])] = '\0';
    avcOutname[NINT(avrSwap[50])] = '\0';
    avcMsg[0] = '\0';

    iStatus = NINT (avrSwap[0]);
    //Initialise
    if (iStatus == 0)
    {
        //Initialise pitch demand to current pitch angle
        rPitchDemand = GetSwapValue(4);
        //This is also where you could read in any user-defined data from accInFile
    }

    //Return demanded variables
    //Note: previous values can be used before they updated, to simulate a one-sample delay
    if (NINT(GetSwapValue(10)) == 0)
    {
        SetSwapValue(42, rPitchDemand);
        SetSwapValue(43, rPitchDemand);
        SetSwapValue(44, rPitchDemand);
        SetSwapValue(45, rPitchDemand);
    }
    else
    {
        strcpy(avcMsg,"This simple DLL needs pitch position actuator");
        *aviFail = -1;
    }

    //Main calculation
    if (*aviFail >= 0)
    {
        //Just a 1-degree step change in pitch position demand at 10 seconds
        static int iDone;
        if (iStatus == 0) iDone = 0;
        if (GetSwapValue(2) >= 10.0 && iDone == 0)
        {
            rPitchDemand += 0.017453F;
            iDone = 1;
        }
        //Logging output
        strcpy(avcOutname,"Pitch demand:A;");
        SetSwapValue(NINT(GetSwapValue(63)),rPitchDemand);
        SetSwapValue(65,1.0F);
    }
}

附录:表点excel
这里写图片描述
这里写图片描述
这里写图片描述
这里写图片描述

Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐