matlab simulink
Answer
12/6/18 10:20 AM

Hi to Community,

 

i wanna use MATLAB to simulink live (real-time) data, which transfer from XDK over USB or WiFi, but i didn't simulink real-time before.

Do you have any suggestion that help me to do that ?

 

Best regards

Sepehr

0 (0 Votes)
RE: matlab simulink
Answer
12/6/18 3:45 PM as a reply to Sepehr Habibollahzadeh.
Hello Sepehr,

did you tested the options, I recommended in your last thread regarding the same question bluetooth-pc connection ?

Additionally, there are two other threads regarding Matlab and the XDK available, I recommend taking a look at them too:

Recieve udp data and Serial communication to Matlab (UART or USB)) .

Please let me know if this was helpful and feel free to ask if you have further questions.

Kind regards,
Franjo
+1 (1 Vote)
RE: matlab simulink
Answer
12/11/18 12:54 PM as a reply to Franjo Stjepandic.

Hi Franjo,

 

i read those links, which you give me. i undrestand that for simulinking data, first of all i should use Python-software to set up a server for receiving data from XDK to my PC over WiFi. Second step is that, now i should change this data to .CSV file and then use CSV file in SIMULINK.

 

now my questions, 1. can i use this way too have live simulation?

 2. is that necessary to set up a server with python, or can i simply use Hotspot or Router and recieve data directly in MATLAB? 

 

 

Best regards

Sepehr

0 (0 Votes)
RE: matlab simulink
Answer
12/12/18 4:37 PM as a reply to Sepehr Habibollahzadeh.
Hello Sepehr,

This setup would also work for a live simulation. However, I found an easier approach to solve this.
You can use the integrated Matlab functionality for UDP or USB to get the data from the XDK for a real-time simulation.

For UDP, you can follow the example here , while you only need to change to the port you want to use and insert 127.0.0.1 as remote host. Additionally to this, I recommend taking a look at this thread here , where a similar question was answered.

As alternative to UDP, you could also use USB. In this video here it is explained how to setup the connection on the Matlab side.
For the XDK side, you would to need to implement the USB sending functionality included with the XDK sensors manually. For that, I recommend taking a the corresponding USB and sensors articles in the XDK knowledgebase .

Please tell me if this was helpful, and do not hesitate to ask further questions.

Kind regards,
Franjo
0 (0 Votes)
RE: matlab simulink
Answer
12/17/18 2:29 AM as a reply to Franjo Stjepandic.

Hello Franjo,

thanks for your support.

the video, which you mentioned , is NOT my problem. i actually know how to see live data or streaming data over COM in MATLAB.  i want to plot this live data (for example in Scop) and for this purpose , the data must be numerical and actually we don't have numerical value over COM.

so, maybe we can simulate that data but first of all should change this string data and that's my question, how?!

 

Best regards

Sepehr

 

0 (0 Votes)
RE: matlab simulink
Answer
12/17/18 4:27 PM as a reply to Sepehr Habibollahzadeh.
Hello Sepehr,

For plotting and analyzing live binary data UDP should be your method of choice.
Its supports different data types and can be used inside plain matlab or simulink function blocks.
Matlab also offers toolboxes for UDP communication
TCP/UDP/IP Toolbox 2.0.6 .

Technically its possible to do the same over USB but it will be limited to UINT8 unless you want to spend extra effort to split and combine packets.

Please let me know if this was helpful and feel free to ask if you have further questions.

Kind regards,
Franjo
0 (0 Votes)
RE: matlab simulink
Answer
12/21/18 1:42 PM as a reply to Franjo Stjepandic.

Hi,

which type of data transfer from XDK over UDP?

i mean, ist that Unit8 or... sth??

(I know that’s really simple question, but i couldn’t  find that)

 

Best regards

Sepehr

0 (0 Votes)
RE: matlab simulink
Answer
12/21/18 4:02 PM as a reply to Sepehr Habibollahzadeh.
Hello Sepehr,

Unfortunately, I do not fully understand your question and problem case. Could you go more into detail about it.

Normally, the data type needs to be set inside Matlab to whatever type you send over UDP.
Furthermore, this depends which kind of data on the XDK side is send via the function UDP_Send() .

Please let me know if this was helpful and feel free to ask if you have further questions.

Kind regards,
Franjo
0 (0 Votes)
RE: matlab simulink
Answer
1/6/19 10:38 PM as a reply to Franjo Stjepandic.

Hi Franjo,

 

unfortunately i could not transfer data over UDP yet. there are 2 ways for transfer data from XDK to MATLAB over UDP. 

1. we can use UDP function, as you can see this in MATLABs' help, and for this function i need  "RemotePort" which i dont know exactly what this is and how find it ?!

2. second way is that use UDP reciever block in simulink, and also i need there RemotePort , which i explanin that i don't know how to find that and is that for XDK or for what?!

 

furthermore, i tried to transfer data from XDK but see always an error, which no returned data. (because of problem in port number that i found, i think.)

i read alot about this but didn't understand more. in addition i should finish this side of my project untill Feb. Atleast i should see data in MATLAB or XDK Workbench over wifi.

 i really appreciate that you help me to find out this problem.

 

Best regards

Sepehr

 

0 (0 Votes)
RE: matlab simulink
Answer
1/7/19 3:03 PM as a reply to Sepehr Habibollahzadeh.
Dear Sepehr,

I will gladly explain for what the RemoteHost and RemotePort stand for.

Matlab is setting up an UDP server with the UDP object. There you only need to pass in the IP address of your own notebook/pc where Matlab is running on. 127.0.0.1 should do exactly that. Please note, 127.0.0.1 is the local host address and configures that your laptop/pc's current IP address in your Wi-Fi network is used.

The RemotePort , in fact, is the server port the XDK should send its data to.
Here the passed remote port 8888 should suit your use case and would only be needed to configured on the XDK.

For the XDK configuration, you simply need to add the IP address of your laptop/pc. Please note, here it must be the correct IP address of your notebook/pc in your network. For receiving that information, you can simply get your ip by using this link here .

Then, the IP address must be inserted in AppController.h with the server port 8888 you choose. Afterwards, you should be able to receive the sensor data from the XDK in your Matlab program.

Please note for this to work, you need to be in the same Wi-Fi network as the XDK is, that the XDK is able to reach the opened UDP server on your laptop/pc.

Additionally, please note that the SendDataOverUdp example you are using does not contain any printf() function calls, which sends the sensor data over USB to the XDK-Workbench console. If you require this, I recommend adding it in the function, where the sensor data is sent via UDP.

In regards to the XDK error you mentioned, is the error the one you linked with the screenshot of Matlab? Or is it an independent one in the console of the XDK-Workbench?

Please let me know if this was helpful and feel free to ask if you have further questions.

Kind regards,
Franjo
0 (0 Votes)
RE: matlab simulink
Answer
1/8/19 1:17 PM as a reply to Franjo Stjepandic.

Dear Franjo,

 

Thanks for your Support!

The screenshot which attached in last message is the error for UDP Block in SIMULINK.

 

Today I try again the UDP function but I can’t send data yet. Now I write down the changes in .h file:

( my Laptop and XDK connect to the same WIFI successfully.)

 

#define DEST_SERVER_IP ………….  “MY LAPTOPS’ IP"   // (try both Local address und IPv4 address

#define DEST_SERVER_PORT …………….. UINT16_C (8888)         //   (as you said)

 

**in addition, I use SendAccelDataOverUdpAndBle example. I think in this examples’ code , send the data to remote port easily. Is that right?

 

In MATLAB side, I wrote :

u=udp('127.0.0.1',8888);   // as you said

u=fopen(u)

A=fread(u)

 

But I saw nothing and also see "Warning: Unsuccessful read:  The specified amount of data was not returned within the Timeout period. 'udp' unable to read any data." , as a warning that you can find in screenshot in this message.

 

Best regards

Sepehr

0 (0 Votes)
RE: matlab simulink
Answer
1/8/19 3:32 PM as a reply to Sepehr Habibollahzadeh.
Dear Sepehr,

Thank you for providing further information.

On the first glance, your Matlab and XDK configuration should be fine.
In regards to the SendAccelDataOverUdpAndBle example, please note that this example will only start to stream data over BLE and UDP if the command "start"  has been sent via BLE to the XDK.
Otherwise, the XDK will preserve in idle mode.

In regards to the send data, how do you ensure that data is received by your laptop/PC?
Did you try as an alternative the use of a simple UDP server, for example in python , to verify the outgoing data?

Additionally, did you verify that your Matlab configuration is correct, by using a third party UDP client?

Please let me know if this was helpful and feel free to ask if you have further questions.

Kind regards,
Franjo
0 (0 Votes)
RE: matlab simulink
Answer
1/8/19 10:42 PM as a reply to Franjo Stjepandic.

Dear Franjo,

so, i should use SendDataOverUdp. you suggest me to use SendDataOverUdp example, as previous you said. but when i add printf() function in XDK workbench in this example,where you said me in last message , i have alot of errors and try to solve this but that's not fix. would you please say, where should i exactly add this function in this example?? 

 **in addition, i try it again with SendDataOverUdp example, and in .c file in this example wrote  * -Sends the data to the remote server , you can find that in image. and UDP sending successfuly.  which data send over UDP? (i wanna send accl. data.) 

 

when SendAccelDataOverUdpAndBle example is not good choise,then i can not receive data.

 

i didn't try python, but i should install python first and work with that, is it necessary??

 

finally, how should i verify my MATLAB configuration by using a third party UDP client?  (i don't see special setting for that.)

 

Best regards

Sepehr

0 (0 Votes)
RE: matlab simulink
Answer
1/9/19 4:53 PM as a reply to Sepehr Habibollahzadeh.
Dear Sepehr,

Let's go through this one step at a time,
The screenshot you posted of AppControllerFire() is the place you can edit the UDP packet send out.

About the error handling, I simply would ask you to post said errors in a screenshot along with your code, then it would be much easier to analyze them and their possible cause in detail.

You already showed me a console showing the XDK, sending out UDP packets, so let us verify if your XDK sends out the data correctly by using a UDP tool.
The example UDP application simply sends out the AppControllerTxBuffer which is an integer incrementing with each packet.
Now if you want to send your data over it, you need to write your data into the buffer. This can be done with the function memset() or memcpy() .

I mentioned Python as an option for testing the UDP, you could if you do not have to install python necessarily.
A simple tool like UDP test tool or netcat will be sufficient too.

The next step is testing your Matlab setup, by for example sending a test packet to it with one of the formerly mentioned tools.

Please let me know if this was helpful and feel free to ask if you have further questions.

Kind regards,
Franjo
0 (0 Votes)
RE: matlab simulink
Answer
1/10/19 10:35 AM as a reply to Franjo Stjepandic.

Hi Franjo,

 

MATLAB works perfectly.

 

i use a old code which wrote for XDK but now i have a warning in XDK-workbench. (you can see this warning also in image.)
Invalid project path: Include path not found (C:\XDK-Workbench\XDK\SDK\xdk110\Platform\ServalPAL_WiFi\include).

previously, this code works correctly.

 

i reinstall several times (and delete .metadata file) and also install an old version of XDK but this warning not fixed. How should i fix this warning? because, i think for this reason the XDK can't connect to wifi with this code- .

 

 

 

i also paste this example here for more information:

.c file:

 

/* module includes ********************************************************** */
#include "XDKAppInfo.h"
#undef BCDS_MODULE_ID  /* Module ID define before including Basics package*/
#define BCDS_MODULE_ID XDK_APP_MODULE_ID_DATA_OVER_UDP

/* own header files */
#include "GetAccelerationDataViaWiFi.h"
#include "XdkSensorHandle.h"

/* system header files */
#include <stdio.h>

/* additional interface header files */
#include "simplelink.h"
#include "BCDS_Basics.h"
#include "BCDS_Assert.h"
#include "BCDS_CmdProcessor.h"
#include "BCDS_WlanConnect.h"
#include "BCDS_NetworkConfig.h"
#include "Serval_Types.h"
#include "Serval_Ip.h"

/* constant definitions ***************************************************** */

/* local variables ********************************************************** */

static CmdProcessor_T *AppCmdProcessor; /**< Application Command Processor Instance */

/**
 * This buffer holds the data to be sent to server via UDP
 * */
static uint16_t bsdBuffer_mau[BUFFER_SIZE] = { (uint16_t) ZERO };
/**
 * Timer handle for periodically sending data over wifi
 */
xTimerHandle wifiSendTimerHandle = NULL;

/* global variables ********************************************************* */

/* inline functions ********************************************************* */

/* local functions ********************************************************** */

/**
 * @brief Opening a UDP client side socket and sending data on a server port
 *
 * This function opens a UDP socket and tries to connect to a Server SERVER_IP
 * waiting on port SERVER_PORT.
 * Then the function will send periodic UDP packets to the server.
 * 
 * @param[in]   *param1     generic pointer to any context data structure which will be passed to the function.
 *
 * @param[in]   port        destination port number
 *
 *
 */

static void wifiUdpSend(void * param1, uint32_t port)
{
    Retcode_T advancedApiRetValue = (Retcode_T) RETCODE_FAILURE;
    BCDS_UNUSED(param1);
    SlSockAddrIn_t Addr;
    uint16_t AddrSize = (uint16_t) ZERO;
    int16_t SockID = (int16_t) ZERO;
    int16_t Status = (int16_t) ZERO;

    Accelerometer_XyzData_T getaccelData = { INT32_C(0), INT32_C(0), INT32_C(0) };

    /*Reading accel Data (X,Y,Z) */
    advancedApiRetValue = Accelerometer_readXyzGValue(xdkAccelerometers_BMA280_Handle, &getaccelData);
    //printf("AccelData: %ld , %ld , %ld \r\n",(long)getaccelData.xAxisData, (long)getaccelData.yAxisData, (long)getaccelData.zAxisData);

    if (RETCODE_OK == advancedApiRetValue)
    {
        //copy accemerometer data into databuffer
        bsdBuffer_mau[0] = getaccelData.xAxisData;
        bsdBuffer_mau[1] = getaccelData.yAxisData;
        bsdBuffer_mau[2] = getaccelData.zAxisData;

    }
    else
    {
        printf("Reading of accel data failed and is filled with dummy value \n");
    }

    Addr.sin_family = SL_AF_INET;
    Addr.sin_port = sl_Htons((uint16_t) port);
    Addr.sin_addr.s_addr = sl_Htonl(SERVER_IP);
    AddrSize = sizeof(SlSockAddrIn_t);

    SockID = sl_Socket(SL_AF_INET, SL_SOCK_DGRAM, (uint32_t) ZERO); /**<The return value is a positive number if successful; other wise negative*/
    if (SockID < (int16_t) ZERO)
    {
        printf("Error in socket opening\n");
        /* error case*/
        return;
    }

    Status = sl_SendTo(SockID, bsdBuffer_mau, BUFFER_SIZE * sizeof(uint16_t), (uint32_t) ZERO, (SlSockAddr_t *) &Addr, AddrSize);/**<The return value is a number of characters sent;negative if not successful*/
    /*Check if 0 transmitted bytes sent or error condition*/
    if (Status <= (int16_t) ZERO)
    {
        Status = sl_Close(SockID);
        if (Status < 0)
        {
            printf("Error is closing socket after failing to send the Udp data \r\n");
            return;
        }
        printf("Error in sending data \r\n");
        return;
    }
    Status = sl_Close(SockID);
    if (Status < 0)
    {
        printf("Error in closing socket after sending successfully sending the udp data \r\n");
        return;
    }
    //printf("UDP sending successful, Acceleration Values [milliG]:  %i %i %i \r\n",bsdBuffer_mau[0],bsdBuffer_mau[1],bsdBuffer_mau[2]);
    return;
}

/**
 * @brief        This is a application timer callback function used to enqueue SendAccelDataoverWifi function
 *               to the command processor.
 *
 * @param[in]    pvParameters unused parameter.
 */
static void EnqueueDatatoWifi(void *pvParameters)
{
    BCDS_UNUSED(pvParameters);

    Retcode_T retVal = CmdProcessor_enqueue(AppCmdProcessor, wifiUdpSend, NULL, SERVER_PORT);
    if (RETCODE_OK != retVal)
    {
        printf("Failed to Enqueue SendAccelDataoverWifi to Application Command Processor \r\n");
    }
}

/**
 *  @brief       Function to print the XDK Device IP Address on the USB.
 *
 */
/**static void PrintDeviceIP(void)
{
    NetworkConfig_IpSettings_T myIpSettings;
    Ip_Address_T* IpaddressHex = Ip_getMyIpAddr();
    int32_t Result = INT32_C(-1);
    char ipAddress[PAL_IP_ADDRESS_SIZE] = { 0 };

    memset(&myIpSettings, (uint32_t) ZERO, sizeof(myIpSettings));

    Retcode_T ReturnValue = NetworkConfig_GetIpSettings(&myIpSettings);
    if (ReturnValue == RETCODE_OK)
    {
        *IpaddressHex = Basics_htonl(myIpSettings.ipV4);
        Result = Ip_convertAddrToString(IpaddressHex, ipAddress);
        if (Result < INT32_C(0))
        {
            printf("Couldn't convert the IP address to string format \r\n ");
        }
        printf(" Ip address of the device %s \r\n ", ipAddress);
    }
    else
    {
        printf("Error in getting IP settings\n\r");
    }
}

/**
 * @brief Callback function called on WIFI event
 *
 * @param [in]  Event : event to be send by WIFI during connection/disconnection.
 *
 *
 */
static void WlanEventCallback(WlanConnect_Status_T Event)
{
    switch (Event)
    {
    case WLAN_CONNECTED:
        /* start accelerometer data transmission timer */
        if (pdTRUE != xTimerStart(wifiSendTimerHandle, (WIFI_TX_FREQ/portTICK_RATE_MS)))
        {
            /* Assertion Reason : Failed to start software timer. Check command queue size of software timer service*/
            assert(false);
        }
        printf("XDK Device Connected over WIFI \r\n");
        PrintDeviceIP();
        printf("Start sending SensorData... \r\n");

        break;
    case WLAN_DISCONNECTED:
        /* stop Ble timer accelerometer data transmission timer */
        if (pdTRUE != xTimerStop(wifiSendTimerHandle, UINT8_C(0)))
        {
            /* Assertion Reason: Failed to start software timer. Check command queue size of software timer service. */
            assert(false);
        }
        printf("XDK Device disconnected form WIFI n/w \r\n");
        break;
    case WLAN_CONNECTION_ERROR:
        printf("XDK Device WIFI Connection error \r\n");
        break;
    case WLAN_CONNECTION_PWD_ERROR:
        printf("XDK Device WIFI connection error due to wrong password \r\n");
        break;
    case WLAN_DISCONNECT_ERROR:
        printf("XDK Device WIFI Disconnect error \r\n");
        break;
    default:
        printf("XDK Device unknown WIFI event \r\n");
        break;
    }
}

/**
 * @brief        This function used to connect to wifi n/w with provided SSID & Password
 *
 * @retval       RETCODE_OK is API success or an error.
 */
static Retcode_T wifiConnect(void)
{
    WlanConnect_SSID_T connectSSID;
    WlanConnect_PassPhrase_T connectPassPhrase;
    Retcode_T ReturnValue = (Retcode_T) RETCODE_FAILURE;

    ReturnValue = WlanConnect_Init();

    if (RETCODE_OK != ReturnValue)
    {
        printf("Error occurred initializing WLAN \r\n ");
        return ReturnValue;
    }
    printf("Connecting to %s \r\n ", WLAN_CONNECT_WPA_SSID);

    connectSSID = (WlanConnect_SSID_T) WLAN_CONNECT_WPA_SSID;
    connectPassPhrase = (WlanConnect_PassPhrase_T) WLAN_CONNECT_WPA_PASS;
    ReturnValue = NetworkConfig_SetIpDhcp(NULL);
    if (RETCODE_OK != ReturnValue)
    {
        printf("Error in setting IP to DHCP\n\r");
        return ReturnValue;
    }
    ReturnValue = WlanConnect_WPA(connectSSID, connectPassPhrase, WlanEventCallback);
    if (RETCODE_OK != ReturnValue)
    {
        printf("Error occurred while connecting Wlan %s \r\n ", WLAN_CONNECT_WPA_SSID);
    }
    return ReturnValue;
}

/**
 *  @brief
 *      Function to initialize the wifi network send application. Create timer task
 *      to start WiFi Connect and get IP function after one second. After that another timer
 *      to send data periodically.
 */
static void init(void)
{
    Retcode_T retval = RETCODE_OK;
    Retcode_T retval_2 = RETCODE_OK;
    Retcode_T retval_3 = RETCODE_OK;

    static_assert((portTICK_RATE_MS != 0), "Tick rate MS is zero");

    /* create timer task to get and transmit accel data for every one second automatically*/
    wifiSendTimerHandle = xTimerCreate((char * const ) "wifiSend", pdMS_TO_TICKS(UDPTXDELAY), TIMER_AUTORELOAD_ON, NULL, EnqueueDatatoWifi);

    if (NULL != wifiSendTimerHandle)
    {
        //initialize wifi
        retval = wifiConnect();

        //initialize accelerometer
        retval_2 = Accelerometer_init(xdkAccelerometers_BMA280_Handle);

        //set accelerometer range to +-16g
        retval_3 = Accelerometer_setRange(xdkAccelerometers_BMA280_Handle,ACCELEROMETER_BMA280_RANGE_16G);

    }
    if ((RETCODE_OK != retval) || (RETCODE_OK != retval_2) || (RETCODE_OK != retval_3) || (NULL == wifiSendTimerHandle))
    {
        printf("Failed to initialize because of Wifi/Command Processor/Timer Create/Range fail \r\n");
        assert(false);
    }
    else {

        printf("Initialized Sensor correctly \r\n");
    }


}

/* global functions ********************************************************* */
void appInitSystem(void * CmdProcessorHandle, uint32_t param2)
{
    if (CmdProcessorHandle == NULL)
    {
        printf("Command processor handle is null \n\r");
        assert(false);
    }
    AppCmdProcessor = (CmdProcessor_T *) CmdProcessorHandle;
    BCDS_UNUSED(param2);
    /*Call the WNS module init API */
    init();
}
/**@} */
/** ************************************************************************* */
 

-------------------------------------------------------------------------------------------------

.h file:

 

#ifndef GETACCELERATIONDATAVIAWIFI_H_
#define GETACCELERATIONDATAVIAWIFI_H_

/* local interface declaration ********************************************** */
#include "BCDS_Basics.h"

/* local type and macro definitions */
typedef enum returnTypes_e
{
    STATUS_NOT_OK,
    STATUS_OK,
    SOCKET_ERROR,
    SEND_ERROR
} returnTypes_t;

#define ZERO    UINT8_C(0)                                      /**< Macro to define value zero*/
#define TIMER_AUTORELOAD_ON             UINT32_C(1)             /**< Auto reload of timer is enabled*/
#define TIMER_AUTORELOAD_OFF            UINT32_C(0)             /**< Auto reload of timer is disabled*/
#define WIFI_TX_FREQ                    UINT32_C(1000)          /**< Macro to represent One second time unit*/

/***************************************************************************************************************************
      Network and other important configurations
***************************************************************************************************************************/
#define WLAN_CONNECT_WPA_SSID                "VAGUE"       /**< Macros to define WPA/WPA2 network alias */
#define WLAN_CONNECT_WPA_PASS                "kheylidire"      /**< Macros to define WPA/WPA2 network password */
#define SERVER_IP                    UINT32_C(0xc0a88901)      /**< Remote ip address (Notebook ip address) in hex */
#define SERVER_PORT                UINT16_C(6666)            /**< Port number on which server will listen */
#define UDPTXDELAY                 UINT32_C(20)              /**< UDP packet transmit frequency in msec */
#define BUFFER_SIZE                UINT8_C(3)                /**< Number of values to send in one UDP packet */

/* local function prototype declarations */
/**
 * @brief This is a template function where the user can write his custom application.
 *
 * @param[in] CmdProcessorHandle Handle of the main commandprocessor
 *
 * @param[in] param2  Currently not used will be used in future
 *
 */
void appInitSystem(void * CmdProcessorHandle, uint32_t param2);

#endif /* XDK110_SENDDATAOVERUDP_H_ */

/** ************************************************************************* */
 

 

 

 

Best regards

Sepehr

0 (0 Votes)
RE: matlab simulink
Answer
1/10/19 4:04 PM as a reply to Sepehr Habibollahzadeh.
Hello Sepehr,

Unfortunately, I was not able to conduct tests with your posted code, since the definition of the function PrintDeviceIP() is missing in the provided code snippet. Could you please provide the missing function implementation?

Regarding the warning you are receiving, please check the path of you file.
To do this, please follow these steps:
 
  1. Right click on you project and choose Properties.
  2. Click on C/C++ General.
  3. Click on Paths and Symbols.
  4. Click under Includes on GNU C
  5. Check in the Include directories for: ${BCDS_BASE_DIR}/xdk110/Platform/ServalPAL/include
If this is not a part of the directories, you can either add it manually or create a new XdkApplicationTemplate and copy your code into that new project.
As a sidenote, I would like to recommend you to use the latest XDK-Workbench for your projects since a lot of content has been changed. The most important change is the change of the control flow, which makes it easier to use and find error.

Please tell me if this was helpful, and do not hesitate to ask further questions.

Kind regards,
Franjo
0 (0 Votes)
RE: matlab simulink
Answer
1/16/19 12:06 AM as a reply to Franjo Stjepandic.

Hi Franjo,

i correct my code and can see the vibration . 

now, i want to set the range of data which transfer from XDK.

i find a code which use this :

retval_3 = Accelerometer_setRange(xdkAccelerometers_BMA280_Handle,ACCELEROMETER_BMA280_RANGE_16G);

 

and also use this library :   #include "XDK_SensorHandle.h"

 

i use those element (xdkAccelerometers_BMA280_Handle,ACCELEROMETER_BMA280_RANGE_16G) in my code, and resolve some errors but also i have a error just about "xdkAccelerometers_BMA280_Handle" .

and i couldn't solve that.

error is: 
Symbol 'xdkAccelerometers_BMA280_Handle' could not be resolved    AppController.c    /SendDataOverUdp/source

 

do you have any idea about this problem? or is there other way for setting the range of data??

 

Best

Sepehr

0 (0 Votes)
RE: matlab simulink
Answer
1/16/19 4:48 PM as a reply to Sepehr Habibollahzadeh.
Hello Sepehr,

Did you verify that your includes contain
#include "XdkSensorHandle.h"
which should contain the pointer as an extern you are trying to use.

As a guide for the sensors, you can visit the knowledgebase

Also I notice above your init of the sensor there are lines for writing the data into the buffer.
You should place sensorsetups inside AppControllerSetup . The range should be able to be set the way you did once you have a valid pointer.

Please tell me if this was helpful, and do not hesitate to ask further questions.

Kind regards,
Franjo
0 (0 Votes)
RE: matlab simulink
Answer
1/17/19 1:06 AM as a reply to Franjo Stjepandic.

Hi Franjo,

 

1. i use completely code which is in knowledgebase but i don't see changes in range of data when i tested for example: ACCELEROMETER_BMI280_RANGE_16G   and     ACCELEROMETER_BMI280_RANGE_4G.

 

would you please explain what this code changes?? i wanna change the range of data.

 

2.In addition, i also trying to see the data in command window in matlab with these code: 

u=udp(‚127.0.0.1‘, 8888)

fopen(u)

fread(u)

but don‘t receive data and error is that no data in this time exist!

i‘m sure that my matlab work correctly, because i can send data over udpand receive that correctly And also i can receive with simulink.

Best

Sepehr

0 (0 Votes)
RE: matlab simulink
Answer
1/17/19 3:15 PM as a reply to Sepehr Habibollahzadeh.
Hello Sepehr,
Could you please get more into detail about the changes in range that you do not see. What changes do you expect and what do you receive in the recorded data?

Please note the range setting between 4 or 16g has only an influence on the resolution of the BMA280. That means, if you use the same impuls to test it, you will still receive the same magnitude, but the same resolution between two values will be higher or lower in case of the used resolution. This is caused because the BMA280 uses 14 bit for storing the measured sensor data.

Depending on that, I summerized the different resolutions for the different range settings:
 
  1. BMA280_RANGE_2G: (measurement range +/-2g = 4g) (4g/16384)= 0.244mg
  2. BMA280_RANGE_4G: (measurement range +/-4g = 8g) (8g/16384)= 0.488mg
  3. BMA280_RANGE_8G: (measurement range +/-8g = 16g) (16g/16384)= 0.976mg
  4. BMA280_RANGE_16G: (measurement range +/-16g = 32g) (32g/16384)= 1.953mg

Depending on the measurement applications you want to have you need to differ between the different resolutions. Since not every use case requires a range up to 16g, when the incoming measurements are only maximal 2g. For that, I summarized three examples below:
 
  1. Motion: Slow changes in position or velocity.
  2. Vibration: Oscillating motion oriented of the position of equilibrium.
  3. Shock: Sudden change in acceleration.
As such, different settings for the resolution should be made depending on the requirements of your use case.

Regarding your second question, could please check if you used the right port? In a previously provided code snippet you used the server port 6666, while in you matlab snippet port number 8888 . These ports need to match to establish a data exchange. Otherwise, you will not get any data at all.

Please tell me if this was helpful, and do not hesitate to ask further questions.

Kind regards,
Franjo
0 (0 Votes)