Sensor applications that access sensor data from the Sensor service can process this data with code that you generate with the MATLAB Coder application.
When you use a MATLAB function to process sensor data, you need to:
To generate source code for a MATLAB function that you can use to build into your QNX project do the following:
function [ out ] = edgeImage( I ) %EDGEIMAGE Uses a canny edge detector on the input image out = edge(I, 'canny', 0.05); end
The MATLAB Coder app guides you through the the following steps that you need to complete in order to generate your C code:
You can either enter the types in directly, or use a MATLAB script that calls your function to automatically define the input and/or output types.
Entry | Option |
---|---|
Build type: | Source Code |
Output file name | file_name (Select the name of the file for the source C code.) |
Language | C |
Hardware Board | None |
Device (vendor and type) | Using the dropdown menus, select your target device's vendor and type. If they're not available, choose what's most appropriate for your device. |
Toolchain | Automatically locate an installed toolchain (It's not necessary to specify a toolchain because your generated source C code will be built using the QNX toolchain in your QNX project.) |
For more information on code generation using MATLAB Coder, see Generate Code from Application Containing Image Processing Functions or your MATLAB Coder documentation.
An example of the source code is provided which you can look at without a MATLAB license. The source code is located as part of Sensor code example package (adas-sensor-examples-vesrion.zip). After you extract the sensor source code package, its located under directory_of_extracted_zip/adas-sensor-examples-version/ source_package_adas_sensor/apps/matlab/matlab_codegen_example. To build and use it, you do require a license to the MATLAB product from Mathworks. To use the generated C code in your sensor application on your QNX target, do the following:
... #include <edgeImage.h> #include <edgeImage_initialize.h> #include <edgeImage_terminate.h> ...
... unsigned char * cmPixData; /* grey bytes of pixel data, column major */ unsigned char * cmEdgeData; /* grey edge pixel data, column major */ ... edgeImage_initialize(); ... /* Receive sensor data*/ ... edgeImage(cmPixData, cmEdgeData); ... edgeImage_terminate();