本文主要是介绍GH Bladed 软件使用学习笔记(2),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
主要介绍外部控制器的的通讯
/*
外部控制器的自定义有两种实现方式:.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 terminatoraccInfile[NINT(avrSwap[49])] = '\0';avcOutname[NINT(avrSwap[50])] = '\0';avcMsg[0] = '\0';iStatus = NINT (avrSwap[0]);//Initialiseif (iStatus == 0){//Initialise pitch demand to current pitch anglerPitchDemand = 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 delayif (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 calculationif (*aviFail >= 0){//Just a 1-degree step change in pitch position demand at 10 secondsstatic int iDone;if (iStatus == 0) iDone = 0;if (GetSwapValue(2) >= 10.0 && iDone == 0){rPitchDemand += 0.017453F;iDone = 1;}//Logging outputstrcpy(avcOutname,"Pitch demand:A;");SetSwapValue(NINT(GetSwapValue(63)),rPitchDemand);SetSwapValue(65,1.0F);}
}
附录:表点excel
这篇关于GH Bladed 软件使用学习笔记(2)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!