Beginners problems
Answer
3/9/18 7:50 AM

Dear community,

unfortunately I have no experience in C. This is why I am excited about the new XDK-Live language. Is there a documentaion on the new language? Because I can't find any.

My aim is to mount the XDK to a hydraulic guillotine shear and to log the accelerometer data. After that I would like to do a FFT analysis like Johannes Scholz allready have done before here.

But first things firtst: How could I achieve that the XDK logs the accelerometer data to a shared folder on the harddrive or on a network-drive? As I understand, the docs explain only how to stream sensor data over USB and let them show up inside the console, but not how to get the XDK to store the data to a file automatically. How could I achieve that with the new XDK-Live language?

Hope you can help me.

0 (0 Votes)
RE: Beginners problems
Answer
3/9/18 10:12 AM as a reply to Aleksandr Gorovoj.
Hello Aleksandr,

first, I would like to welcome you to the XDK Community.

Regarding XDK-Live, the only official documentation is available within the XDK-Workbench. For this, in the top menu bar select Help > Help Contents . There, you will find XDK LIVE as an article in the contents.

This will open a HTML based documentation for XDK Live. Keep in mind that this feature / language is currently still in development, and is therefore not complete yet.

As for how to store data using the XDK, the XDK Device does not have direct control over what happens on your hard drives. In general, applications are built as such that the XDK Device streams data (over WiFi, USB, UART or any other available transport medium), and the device that the XDK is connected to reads the data stream, and handles it.

The last part, i.e. handling the data, is an entirely different application. You can think of the XDK Device as a smart provider. It can only send (and receive) data, but not manipulate the outside world (unless that data is used to trigger events on other devices).

On the other hand, the XDK has an SD Card slot. If an appropriate microSD Card is inserted, the XDK can store data on the SD Card. There is a guide for this in the XDK Learning Section , but this does require some knowledge with C-Programming. For beginners, I would thus recommend to going through the basic guides first.

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

Kind regards,
Alexander
+1 (1 Vote)
RE: Beginners problems
Answer
3/9/18 11:53 AM as a reply to Alexander Sawtschuk.

Dear Alexander,

thanks a lot for the fast reply. Now I see the docs inside the XDK Workbench.

Initially I'm trying to get the accelerometer data printed to the console. For this I'm using the following code:

package main;

import platforms.xdk110;

every accelerometer.any_motion {

   print("shock detected\n");

}

But after flashing nothing happens if I slightly clap the XDK.

If I use every 100 milliseconds instead of accelerometer.any_motion, it works fine. So my error in thought is in accelerometer.any_motion.

Any idea what I'm doing wrong?

0 (0 Votes)
RE: Beginners problems
Answer
3/9/18 3:40 PM as a reply to Aleksandr Gorovoj.
Hello Aleksandr,

glad to hear that you were able to find an entry to XDK Live, but at the same time I must unfortunately say that the accelerometer implementation seems to not work as one would expect.

The accelerometer itself is working just fine - the magnitude can be read using accelerometer.magnitude.read() for example. The issue lies with the events (for example any_data ).

An alternative to what you are trying to do could be done as follows:

 
package main;
import platforms.xdk110;

native unchecked fn abs(n : uint32) : uint32
   header "math.h";

var previous_value : uint32 = 0;
var current_value : uint32 = 0;
var diff : uint32 = 0;
var threshold : uint32 = 8000;

every 10 millisecond {
    current_value = accelerometer.magnitude.read();
    diff = abs(current_value - previous_value);
    if(diff > threshold) {
        println(`diff: ${diff}`);
    }
    previous_value = current_value;
}


As mentioned before, XDK Live is still in development. The issues with the accelerometer events will be forwarded to the responsible developer, though I am sure that they are already known.

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

Kind regards,
Alexander
+1 (1 Vote)
RE: Beginners problems
Answer
3/11/18 9:35 PM as a reply to Alexander Sawtschuk.
Hi Alexander,

it looks like You have not selected/configured the thresholds of the any-motion interrupt before using it.

Regards,

Francisco
+1 (1 Vote)
RE: Beginners problems
Answer
3/12/18 10:22 AM as a reply to Francisco Llobet Blandino.

Dear Alexander,

dear Francisco,

thank you for your replies!

 

I'm now trying to send accelerometer data over USB and doing it by the tutorial provided in the USB Guide. For this I've pasted the code from the document to XdkApplicationTemplate.c as follows:

/* module includes ********************************************************** */

/* system header files */
#include <stdio.h>
/* additional interface header files */
#include "FreeRTOS.h"
#include "timers.h"

/* own header files */
#include "XdkApplicationTemplate.h"
#include "BCDS_CmdProcessor.h"
#include "BCDS_Assert.h"
#include "XdkSensorHandle.h"

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

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

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

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

/* local functions ********************************************************** */
#define SWAP_32_MACRO(x) \
	(uint32_t)((x & 0xff) << 24 | \
			(x & 0xff00) << 8 |          \
			(x & 0xff0000) >> 8 |.       \
			(x & 0xff000000) >> 24);

#define SWAP_32_MEMCPY_MACRO(bufAddress,data) \
	{uint32_t _tmp = SWAP_32_MACRO(data);\
	memcpy(bufAddress, &_tmp, sizeof(_tmp));}
/* global functions ********************************************************* */

/**
 * @brief This is a template function where the user can write his custom application.
 *
 */
void appInitSystem(void * CmdProcessorHandle, uint32_t param2)
{
    if (CmdProcessorHandle == NULL)
    {
        printf("Command processor handle is null \n\r");
        assert(false);
    }
    BCDS_UNUSED(param2);
    /* Delay because USB to workbench connection need to be established */
    /* Note: This delay is only for demonstration purposes */
    const TickType_t xDelay = 3000 / portTICK_PERIOD_MS; vTaskDelay( xDelay );
    /* Initialize accelerometer */ Accelerometer_init(xdkAccelerometers_BMA280_Handle); Accelerometer_XyzData_T accelData = {INT32_C(0), INT32_C(0), INT32_C(0)}; Accelerometer_readXyzGValue(xdkAccelerometers_BMA280_Handle, &accelData);
    /* USB send buffer */
    uint32_t length = 12; uint8_t sensorData[length];
    /* Copy sensor data to send buffer */
    SWAP_32_MEMCPY_MACRO(&sensorData[3],accelData.xAxisData);
    SWAP_32_MEMCPY_MACRO(&sensorData[7],accelData.yAxisData);
    SWAP_32_MEMCPY_MACRO(&sensorData[11],accelData.zAxisData);
    USB_transmitData(sensorData,length);
}
/**@} */

But unfortunately I get an error as you can see attached.

 

Any idea whats going wrong?

0 (0 Votes)
RE: Beginners problems
Answer
3/12/18 3:12 PM as a reply to Aleksandr Gorovoj.
Hello Aleksandr and Francisco,

First off, Aleksandr, you have a . in your macro on line 75 in your code. This is causing the issue, because it obviously does not belong there.

As for Francisco, thank you for pointing this out, but I have not been able to make it work even after setting the any_motion_threshold. As such, could you do me a favor and post a working example here?

I have tried it using the following code:
 
package main;
import platforms.xdk110;

setup accelerometer {
    any_motion_threshold = 0;
}

every accelerometer.any_motion {
    println("Motion Detected");
}
I would expect that this would print the defined string on every motion, since the threshold is 0. But even when setting it to higher than zero, nothing is printed.

In fact, since the any_motion_threshold is set to be 20 by default, I think it should have worked even when not setting up the variable.

Thank you in advance.

Kind regards,
Alexander
0 (0 Votes)
RE: Beginners problems
Answer
3/12/18 4:02 PM as a reply to Alexander Sawtschuk.

Hey Alexander,

the dot actually comes from the tutorial (as you can see in first attachment). If I erase the . other errors come in (as you can see in attachment nr.2).

0 (0 Votes)
RE: Beginners problems
Answer
3/12/18 4:39 PM as a reply to Aleksandr Gorovoj.
Hello Aleksandr,

the errors do not seem to correspond to what is actually written in the code. I think you did not save the file before you attempted to build again. If this is not the case, could you please post the entire code?

Regarding the dot in the guide code, this should not be there, and will be removed from the guide's code as soon as possible.

Kind regards,
Alex
0 (0 Votes)
RE: Beginners problems
Answer
3/12/18 8:50 PM as a reply to Alexander Sawtschuk.

I see that the XDK live code generator for the BMA280 module is defective (as shown in the code snipped). It generated the slope (anymotion) interrupt but disabled all axis in the BMA280. Please file a bug report with the BCDS/PAX team to solve this.

Retcode_T SensorAccelerometer_Enable(void)
{
	/* Enable Active Sensor Events */
	/* Activating any_motion */
	bma2x2_set_intr_enable(BMA2x2_SLOPE_X_INTR, INTR_DISABLE);
	bma2x2_set_intr_enable(BMA2x2_SLOPE_Y_INTR, INTR_DISABLE);
	bma2x2_set_intr_enable(BMA2x2_SLOPE_Z_INTR, INTR_DISABLE);
	
	
	
	return NO_EXCEPTION;
}
0 (0 Votes)
RE: Beginners problems
Answer
3/12/18 10:53 PM as a reply to Francisco Llobet Blandino.

I found another bug in the generated code. The ISR does not use the CmdProcessor_EnqueueFromIsr() to enqueue the event resolving function. Once I edited the file, manually, I could get the anymotion interrupt working (the setting I originally programmed (20LSB) is very little and easy to trigger)

static void BMA280_IsrCallback(uint32_t channel, uint32_t edge)
{
    BCDS_UNUSED(channel);
    BCDS_UNUSED(edge);

    /* Enqueue Event Resolver */
    CmdProcessor_EnqueueFromIsr(&XdkLive_EventQueue, BMA280_Event, NULL, 0);
}

 

0 (0 Votes)
RE: Beginners problems
Answer
3/13/18 1:03 PM as a reply to Francisco Llobet Blandino.

Hey Alex,

I did save the file, but the error remains.

UPDATE: I've forgotten to include the "BCDS_USB.h". After doing that, the error disappeared.

/*----------------------------------------------------------------------------*/
/**
* @ingroup APPS_LIST
*
* @defgroup XDK_APPLICATION_TEMPLATE XDK Application Template
* @{
*
* @brief XDK Application Template
*
* @details Empty XDK Application Template without any functionality. Should be used as a template to start new projects.
*
* @file
**/
/* module includes ********************************************************** */

/* system header files */
#include <stdio.h>
/* additional interface header files */
#include "FreeRTOS.h"
#include "timers.h"

/* own header files */
#include "XdkApplicationTemplate.h"
#include "BCDS_CmdProcessor.h"
#include "BCDS_Assert.h"
#include "XdkSensorHandle.h"
#include "BCDS_USB.h"

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

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

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

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

/* local functions ********************************************************** */
#define SWAP_32_MACRO(x) \
	(uint32_t)((x & 0xff) << 24 | \
			(x & 0xff00) << 8 |          \
			(x & 0xff0000) >> 8 |       \
			(x & 0xff000000) >> 24);

#define SWAP_32_MEMCPY_MACRO(bufAddress,data) \
	{uint32_t _tmp = SWAP_32_MACRO(data);\
	memcpy(bufAddress, &_tmp, sizeof(_tmp));}
/* global functions ********************************************************* */

/**
 * @brief This is a template function where the user can write his custom application.
 *
 */
void appInitSystem(void * CmdProcessorHandle, uint32_t param2)
{
   USB_init(&USBinit);
    if (CmdProcessorHandle == NULL)
    {
        printf("Command processor handle is null \n\r");
        assert(false);
    }
    BCDS_UNUSED(param2);

    /* Delay because USB to workbench connection need to be established */
    /* Note: This delay is only for demonstration purposes */
    const TickType_t xDelay = 3000 / portTICK_PERIOD_MS;
    vTaskDelay( xDelay );

    /* Initialize accelerometer */
    Accelerometer_init(xdkAccelerometers_BMA280_Handle);
    Accelerometer_XyzData_T accelData = {INT32_C(0), INT32_C(0), INT32_C(0)};
    Accelerometer_readXyzGValue(xdkAccelerometers_BMA280_Handle, &accelData);
    /* USB send buffer */
    uint32_t length = 12;
    uint8_t sensorData[length];

    /* Copy sensor data to send buffer */
    SWAP_32_MEMCPY_MACRO(&sensorData[3],accelData.xAxisData);
    SWAP_32_MEMCPY_MACRO(&sensorData[7],accelData.yAxisData);
    SWAP_32_MEMCPY_MACRO(&sensorData[11],accelData.zAxisData);
    USB_transmitData(sensorData,length);
}
/**@} */
/** ************************************************************************* */

 

Now I become a building error:

 

12:04:35 **** Incremental Build of configuration XDK Default for project XdkApplicationTemplate ****
mingw32-make debug 
C:\XDK-Workbench\XDK\make\mingw32-make.exe -C C:\XDK-Workbench\XDK\SDK/xdk110/Common -f application.mk debug
new_bootloader
mingw32-make[1]: Entering directory 'C:/XDK-Workbench/XDK/SDK/xdk110/Common'
C:\XDK-Workbench\XDK\make\mingw32-make.exe -C ./../Platform/SensorUtils debug BCDS_COMMON_MAKEFILE=C:/XDK-Workbench/XDK/SDK/xdk110/Common/common.mk
mingw32-make[2]: Entering directory 'C:/XDK-Workbench/XDK/SDK/xdk110/Platform/SensorUtils'
      0 [main] us 0 init_cheap: VirtualAlloc pointer is null, Win32 error 487
AllocationBase 0xEE0000, BaseAddress 0xEE0000, RegionSize 0x1FD000, State 0x2000
C:\XDK-Workbench\XDK\msys\sh.exe: *** Couldn't reserve space for cygwin's heap, Win32 error 0
C:/XDK-Workbench/XDK/SDK/xdk110/Common/common_settings.mk:215: recipe for target 'sourceFile.list' failed
mingw32-make[2]: *** [sourceFile.list] Error 1
mingw32-make[2]: Leaving directory 'C:/XDK-Workbench/XDK/SDK/xdk110/Platform/SensorUtils'
Libraries.mk:49: recipe for target '../Platform/SensorUtils/debug/libSensorUtils_efm32_debug.a' failed
mingw32-make[1]: *** [../Platform/SensorUtils/debug/libSensorUtils_efm32_debug.a] Error 2
mingw32-make[1]: Leaving directory 'C:/XDK-Workbench/XDK/SDK/xdk110/Common'
Makefile:32: recipe for target 'debug' failed
mingw32-make: *** [debug] Error 2

12:04:35 Build Finished (took 671ms)

What I have to say about this kind of error is that it comes even if I try to build a project of freshly opened examples provided inside the welcome screen of workbench.

 

So I deleted all of my projects (even from disk) and opened the SendVirtualDataOverUSB example from the welcome screen. After right click on the project and then "Build" the error unfortunately persists.

Attached you can see the common_settings.mk and Makefile which may couse the error.

 

Should I reinstall the workbench?

 

ANOTHER UPDATE:

It seemed to be something wrong with other projects. Going to working directory and deleting all projects manually helped to solve this issue.

0 (0 Votes)
RE: Beginners problems
Answer
3/13/18 6:21 PM as a reply to Aleksandr Gorovoj.
Hello Aleksandr,

I am glad that you were able to solve your issue. Perhaps it would be useful to you to get some details on the solutions.

First of all, regarding the missing header-file, in your previous post, there was a warning stating implicit declaration of function 'USB_transmitData' . This indicates that the function was not found anywhere in the namespace (i.e., it was not declared anywhere).

If you ever see an error like that again, you should check your includes again.

As for the other error: I do not exactly know why this occurs. As removing everything from your workspace helped solve this, I assume that the workspace was simply corrupted.

Additionally, deleting everything from the Project Explorer did not help initially, because the projects are not removed from the hard drive. If you try to open a new example from the Welcome-Screen and the Workbench finds a project with the same name in the workspace (even if it is not listed in the Project explorer), the Workbench will simply take the already existing project.

I hope this helps clear things up.

Kind regards,
Alex
0 (0 Votes)