why is there difference in matlab execution and generated code execution on different processor?
11 次查看(过去 30 天)
显示 更早的评论
I am trying to execute the generated code of MATLAB example Forward Collision Warning Using Sensor Fusion on different processor. The entry function generates 4 outputs. The example compares one of the output numTracks for MATLAB and generated code execution.
Once i executed the generated C code on the processor, numTracks matched with the matlab simulation but the output 'mostImportantObject' is behaving different from the matlab simulation.
main.c file:
visionObjects, radarObjects, imu, lanes of '01_city_c2s_fcw_10s_sensor.mat' has been extracted into a c file and its extern are available in Data.h
/*
* File: main.c
*
* MATLAB Coder version : 5.1
* C/C++ source code generated on : 16-May-2021 03:44:11
*/
/*************************************************************************/
/* 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 "main.h"
#include "rt_nonfinite.h"
#include "trackingForFCW_kernel.h"
#include "trackingForFCW_kernel_emxAPI.h"
#include "trackingForFCW_kernel_terminate.h"
#include "trackingForFCW_kernel_types.h"
#include "Data.h"
#include <stdio.h>
/* Input Data */
struct0_T *visionObj;
struct2_T *radarObj;
struct4_T *imu_in;
struct5_T *lanes_in;
struct7_T egoLane;
/* Function Declarations */
static void argInit_1x3_real_T(double result[3], float);
static struct7_T argInit_struct7_T(float);
static double argInit_real_T(void);
/*
* Arguments : void
* Return Type : double
*/
static double argInit_real_T(void)
{
return 0.0;
}
/* Function Definitions */
/*
* Arguments : double result[3]
* Return Type : void
*/
static void argInit_1x3_real_T(double result[3], float lanewidth)
{
int idx1;
/* Loop over the array to initialize each element. */
for (idx1 = 0; idx1 < 2; idx1++) {
/* Set the value of the array element.
Change this value to the value that the application requires. */
result[idx1] = argInit_real_T();
}
result[2] = lanewidth/2;
}
/*
* Arguments : void
* Return Type : struct7_T
*/
static struct7_T argInit_struct7_T(float lanewidth)
{
struct7_T result;
/* Set the value of each structure field.
Change this value to the value that the application requires. */
argInit_1x3_real_T(result.left, lanewidth);
result.right[0] = result.left[0];
result.right[1] = result.left[1];
result.right[2] = -result.left[2];
return result;
}
void argInt_MIO(struct10_T *result)
{
static const char cv[5] = { 'g', 'r', 'e', 'e', 'n' };
result -> Warning = 3;
result -> ObjectID.data[0] = 0u;
result -> ObjectID.size[0] = 0;
result -> ObjectID.size[1] = 0;
result -> TrackIndex.size[0] = 0;
result -> TrackIndex.size[1] = 0;
result -> TrackIndex.data[0] = 0.0f;
result -> ThreatColor.size[0] = 1;
result -> ThreatColor.size[1] = 5;
for (int i = 0; i < 5; i++)
{
result -> ThreatColor.data[i] = cv[i];
}
}
/*
* Arguments : int argc
* const char * const argv[]
* Return Type : int
*/
int main(int argc, const char * const argv[])
{
(void)argc;
(void)argv;
double timeStamp = 0;
double timeStep = 0.05;
double lanewidth = 3.6;
double positionSelector_tmp[12] = {1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0};
double velocitySelector_tmp[12] = {0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0};
emxArray_struct8_T *confirmedTracks;
struct10_T mostImportantObject;
argInt_MIO(&mostImportantObject);
double numTracks = 0.0f;
emxInitArray_struct8_T(&confirmedTracks, 1);
/* Invoke the entry-point functions. */
for(int i=0; i<205; i++)
{
timeStamp = timeStamp + timeStep;
visionObj = (struct0_T*)(&visionObjects[i]);
radarObj = (struct2_T*)(&radarObjects[i]);
imu_in = (struct4_T*)(&imu[i]);
lanes_in = (struct5_T*)(&lanes[i]);
egoLane = argInit_struct7_T(lanewidth);
trackingForFCW_kernel(visionObj, radarObj, imu_in, lanes_in, &egoLane, timeStamp,
positionSelector_tmp, velocitySelector_tmp,
confirmedTracks, &numTracks, &mostImportantObject);
/* Print the output */
printf("mostImportantObjects ObjectID %u \n", *(mostImportantObject.ObjectID.data) );
printf("mostImportantObjects Trackindex %lf \n", *(mostImportantObject.TrackIndex.data) );
printf("mostImportantObjects Warning %lf \n", mostImportantObject.Warning);
printf("mostImportantObjects Threatcolor %s \n", mostImportantObject.ThreatColor.data);
printf("Tracks %f \n", numTracks);
printf("\n \n");
}
/* Terminate the application.
You do not need to do this more than one time. */
trackingForFCW_kernel_terminate();
return 0;
}
/*
* File trailer for main.c
*
* [EOF]
*/
0 个评论
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Get Started with MATLAB Coder 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!