【问题标题】:Matlab Coder and Arduino IDE emxCreateWrapper_real_TMatlab 编码器和 Arduino IDE emxCreateWrapper_real_T
【发布时间】:2016-06-08 10:46:13
【问题描述】:

我在 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 矩阵。

Here我发现有人使用 emxCreateWrapper_real_T 函数,但如果我在 Arduino IDE 中使用此函数,我只会收到错误:

'emxCreateWrapper_real_T' was not declared in this scope

   input = emxCreateWrapper_real_T(input_d,5,6);

我在从 matlab coder 创建的任何文件中都找不到这样的函数,我在哪里可以找到?

我正在使用 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);
}

【问题讨论】:

    标签: c++ arduino matlab-coder


    【解决方案1】:

    我不知道您正在使用的库,但是...

    您得到的错误是“未在此范围内声明”,因此编译器在您使用它时不知道符号emxCreateWrapper_real_T

    您应该包含定义emxCreateWrapper_real_T() 的文件的标题;或者用正确的命名空间调用它......我不知道。

    我发现 an example 在包含文件的地方使用

    #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”中定义的。

    我的建议是:尝试同时包含它们。

    如果这不起作用,请尝试向我们展示完整的代码;包括包含的文件。

    p.s:对不起我的英语不好。

    【讨论】:

      【解决方案2】:

      谢谢,我找到了一个名为“_coder_NeuralNetwork_api.c”的文件和一个头文件。在头文件中声明了 struct 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 编码器的 separte 文件夹中创建的。

      【讨论】:

        【解决方案3】:

        我发现了一些编码器生成的可能有帮助的东西:

        //
        // 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]
        //
        

        但我不确定如何使用函数“static emxArray_real_T *argInit_d7351x5_real_T()”,它说将大小更改为应用程序所需的值,但我必须更改什么?例如我想使用 10x5 数组,是否必须将 iv0[] 中的第一个值更改为 10? 要获取输入值(在我的第一篇文章中,变量 input[][])我可以将“argInit_real_T()”的函数调用替换为 input[idx0][idx1],如果我在该函数中创建该变量或作为全局变量?

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2022-12-18
          • 2012-03-17
          • 2022-07-16
          • 2021-08-06
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多