Matlab Coder and Arduino IDE emxCreateWrapper_real_T
Matlab Coder and Arduino IDE emxCreateWrapper_real_T
我在Matlab中构建了一个神经网络,并创建了一个使用NN的函数。我从该函数生成C++代码,以便在我的Arduino Yun上使用它。
在Arduino IDE中,我首先编写了 #include"NeuralNetwork.h",编译没有问题,但我不确定如何从matlab编码器调用生成的函数。函数标头为
void NeuralNetwork(const emxArray_real_T *Data, double activity_data[], int
activity_size[2], double *percent)
emxArray_real_T什么类型的数据?在 Matlab 数据中是一个 inf x 5 矩阵。
在这里,我找到了一些使用emxCreateWrapper_real_T函数的功能,但是如果我在Arduino IDE中使用此功能,则只会收到错误:
'emxCreateWrapper_real_T' was not declared in this scope
input = emxCreateWrapper_real_T(input_d,5,6);
我在从 matlab 编码器创建的任何文件中都找不到这样的功能,我在哪里可以找到它?
我正在使用 Matlab R2016a。
我在Arduino中的循环函数是:
void loop() {
//input data are samples from a 3D Accelerometer
double input [6][5] = { {30.38,0.584,0.106,0.253,1}, //walking
{30.4,0.772,0.059,0.461,1}, //walkinh
{1.98,0.026,0.13,1.031,2}, //sitting
{2.0,0.01,0.102,1.03,2}, //sitting
{5.0,-1.135,0.035,0.099,3}, //standing
{5.02,-1.14,0.039,0.09,3}}; //standing
//emxArray_real_T *input;
double activity[6]; //output from NN
double percent = 0; //amound of recognized data
int act_size[2]; //???
print_inp(input); //just prints the input array to the serial interface
// input = emxCreateWrapper_real_T(input,5,6);
NeuralNetwork(input,activity,act_size,&percent);
delay(50000);
}
你正在使用的库,但是...
您得到的错误是"未在此范围内声明",因此编译器不知道您使用它时emxCreateWrapper_real_T
符号。
你应该包括定义emxCreateWrapper_real_T()
的文件的头;或者使用正确的命名空间调用它...我不太清楚。
我找到了一个使用示例,其中包含的文件
#include "stdafx.h"
#include <iostream>
#include "arcl3d.h"
#include "arcl3d_initialize.h"
#include "arcl3d_terminate.h"
#include "arcl3d_emxAPI.h"
#include "arcl3d_emxutil.h"
所以我想emxCreateWrapper_real_T()
是在"arcl3d_emxAPI.h"或"arcl3d_emxutil.h"中定义的。
我的建议是:尝试将它们都包括在内。
如果这不起作用,请尝试向我们展示完整的代码;包括包含的文件。
PS:对不起,我的英语不好。
谢谢,我找到了一个名为"_coder_NeuralNetwork_api.c"的文件和一个头文件。在头文件中声明了结构emxArray_real_T,但在 .c 文件中没有emxCreateWrapper_real_T函数,但我发现:
static void emxInit_real_T(const emlrtStack *sp, emxArray_real_T **pEmxArray,
int32_T numDimensions, boolean_T doPush)
{
emxArray_real_T *emxArray;
int32_T i;
*pEmxArray = (emxArray_real_T *)emlrtMallocMex(sizeof(emxArray_real_T));
if (doPush) {
emlrtPushHeapReferenceStackR2012b(sp, (void *)pEmxArray, (void (*)(void *))
emxFree_real_T);
}
emxArray = *pEmxArray;
emxArray->data = (real_T *)NULL;
emxArray->numDimensions = numDimensions;
emxArray->size = (int32_T *)emlrtMallocMex((uint32_T)(sizeof(int32_T)
* numDimensions));
emxArray->allocatedSize = 0;
emxArray->canFreeData = true;
for (i = 0; i < numDimensions; i++) {
emxArray->size[i] = 0;
}
}
我也可以使用该功能,如果是,输入参数是什么?
但还有下一个问题。包含头文件的另一个名为"_coder_NeuralNetwork_mex.h"的.h包含在内,并且需要一个"mex.h",但 matlab 编码器没有创建这样的文件。
_coder_NeuralNetwork_mex.h的内容是:
#ifndef _CODER_NEURALNETWORK_MEX_H
#define _CODER_NEURALNETWORK_MEX_H
/* Include Files */
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include "tmwtypes.h"
#include "mex.h"
#include "emlrt.h"
#include "_coder_NeuralNetwork_api.h"
/* Function Declarations */
extern void mexFunction(int32_T nlhs, mxArray *plhs[], int32_T nrhs, const
mxArray *prhs[]);
extern emlrtCTX mexFunctionCreateRootTLS(void);
#endif
我不知道我是否必须使用这些文件,因为它们是在 matlab 编码器的分离文件夹中创建的。
我发现了编码人员生成的东西,可能会有所帮助:
//
// Academic License - for use in teaching, academic research, and meeting
// course requirements at degree granting institutions only. Not for
// government, commercial, or other organizational use.
// File: main.cpp
//
// MATLAB Coder version : 3.1
// C/C++ source code generated on : 07-Jun-2016 19:17:39
//
//***********************************************************************
// This automatically generated example C main file shows how to call
// entry-point functions that MATLAB Coder generated. You must customize
// this file for your application. Do not modify this file directly.
// Instead, make a copy of this file, modify it, and integrate it into
// your development environment.
//
// This file initializes entry-point function arguments to a default
// size and value before calling the entry-point functions. It does
// not store or use any values returned from the entry-point functions.
// If necessary, it does pre-allocate memory for returned values.
// You can use this file as a starting point for a main function that
// you can deploy in your application.
//
// After you copy the file, and before you deploy it, you must make the
// following changes:
// * For variable-size function arguments, change the example sizes to
// the sizes that your application requires.
// * Change the example values of function arguments to the values that
// your application requires.
// * If the entry-point functions return values, store these values or
// otherwise use them as required by your application.
//
//***********************************************************************
// Include Files
#include "rt_nonfinite.h"
#include "NeuralNetwork.h"
#include "main.h"
#include "NeuralNetwork_terminate.h"
#include "NeuralNetwork_emxAPI.h"
#include "NeuralNetwork_initialize.h"
// Function Declarations
static emxArray_real_T *argInit_d7351x5_real_T();
static double argInit_real_T();
static void main_NeuralNetwork();
// Function Definitions
//
// Arguments : void
// Return Type : emxArray_real_T *
//
static emxArray_real_T *argInit_d7351x5_real_T()
{
emxArray_real_T *result;
static int iv0[2] = { 2, 5 };
int idx0;
int idx1;
// Set the size of the array.
// Change this size to the value that the application requires.
result = emxCreateND_real_T(2, *(int (*)[2])&iv0[0]);
// Loop over the array to initialize each element.
for (idx0 = 0; idx0 < result->size[0UL]; idx0++) {
for (idx1 = 0; idx1 < 5; idx1++) {
// Set the value of the array element.
// Change this value to the value that the application requires.
result->data[idx0 + result->size[0] * idx1] = argInit_real_T();
}
}
return result;
}
//
// Arguments : void
// Return Type : double
//
static double argInit_real_T()
{
return 0.0;
}
//
// Arguments : void
// Return Type : void
//
static void main_NeuralNetwork()
{
emxArray_real_T *Data;
double activity_data[7351];
int activity_size[2];
double percent;
// Initialize function 'NeuralNetwork' input arguments.
// Initialize function input argument 'Data'.
Data = argInit_d7351x5_real_T();
// Call the entry-point 'NeuralNetwork'.
NeuralNetwork(Data, activity_data, activity_size, &percent);
emxDestroyArray_real_T(Data);
}
//
// Arguments : int argc
// const char * const argv[]
// Return Type : int
//
int main(int, const char * const [])
{
// Initialize the application.
// You do not need to do this more than one time.
NeuralNetwork_initialize();
// Invoke the entry-point functions.
// You can call entry-point functions multiple times.
main_NeuralNetwork();
// Terminate the application.
// You do not need to do this more than one time.
NeuralNetwork_terminate();
return 0;
}
//
// File trailer for main.cpp
//
// [EOF]
//
但是我不确定如何使用函数"静态emxArray_real_T *argInit_d7351x5_real_T()",它说将大小更改为应用程序所需的值,但我必须更改什么?例如,我想使用 10x5 数组,我是否必须将 iv0[] 中的第一个值更改为 10???要获取输入值(在我的第一篇文章中,变量input[][]),如果我在该函数中创建该变量或作为全局变量,我可以将"argInit_real_T()"的函数调用替换为input[idx0][idx1]吗?
- 点运算符 (.) 是"real"运算符吗?
- 常量参数"real"常量吗?
- C ++引用函数参数似乎包含原始对象的副本,而不是充当"real reference"
- QML/real和C++/float之间的Qt类型错误
- 在日食中获取无法执行 g++.real 错误
- 了解"Real world modelling"程序
- 使用 BER 编码和解码 ASN.1 REAL
- LLVM Callinst 函数如何获取 (real)Name
- <double> 复杂C++ - 不能使用 imag()、complex()、real()
- 实现QProcess的最佳方法是什么,在"real time"中读取stdout和stderr?
- 如何查找"real"错误?
- 关于渲染系统架构布局的建议-Real time/HLSL/DirectX9/ c++
- SQLite文本转换为整数或REAL在c++做太多