2016-06-08 6 views
0

Я построил нейронную сеть в Matlab и создал функцию, которая использует NN. Я использовал код C++, чтобы использовать его на моем Arduino Yun.Matlab Coder и Arduino IDE emxCreateWrapper_real_T

В 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 Data - матрица 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 кодер, где я могу это найти?

Я использую 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); 
} 

ответ

0

я не знаю библиотеку, которую вы используете, но ...

Ошибка вы получаете «не был объявлен в этой области» , поэтому компилятор не знает символ 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: извините за мой плохой английский.

0

спасибо, я нашел файл с именем «_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; 
    } 
} 

можно также использовать эту функцию, если да, то какие входные заданы параметры ??

Но есть и следующая проблема .... в том числе заголовок, который включен в файл заголовка .h с именем «_coder_NeuralNetwork_mex.h», и ему нужен «mex.h», но кодер matlab не создал такой файл.

Содержание _coder_NeuralNetwork_mex.ч:

#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 

Я не знаю, если я должен использовать эти файлы, beacuse они создаются в папке separte из MatLab кодера.

0

я нашел что-то кодировщик генерируемого что может помочь:

// 
// 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 ??? Чтобы получить входные значения (в моем первом сообщении переменный вход [] []), я могу заменить вызов функции «argInit_real_T()» для ввода [idx0] [idx1], если я создаю эту переменную внутри этой функции или как глобальную ?

Смежные вопросы