Read movement and time sensors
Answer
12/7/17 2:36 PM

Hello community,

i need some help to start off with the XDK. 

I want to read the movement data connected with the time data and get them together in another program to display them there. 

So basically i want that the XDK saves the current time to the current movement value and give them out in the console (later live via Wifi or Bluetooth). 

I would appreciate if you guys could tell me if this is possible and give me maybe a quick start.

So that you don´t get me wrong i don´t want you guys to program this for me but i don´t want to waste much time if it´s not even possible.

 

Thank you guys in advance.

 

Regards

0 (0 Votes)
RE: Read movement and time sensors
Answer
12/8/17 9:23 AM as a reply to Christian.

Hello Christan,

First I'd like to welcome you to the XDK community. Your use case sounds very interesting and it should be possible to implement it with the XDK. Furthermore, I think you could sense the movement data with the accelerometer and the gyroscope of the XDK.

For more information about how to program both sensors, I recommend taking a look at the corresponding section in the sensor guide.

Regarding the time stamps, please note that there is no real time clock on the XDK and that they can be implemented in more than one way.

You could, for example, use the function xTaskGetTickCount() to receive the current system ticks after the application boots and calculate the time in milliseconds from them.

An implementation could be as follows:

uint32_t currentTime = xTaskGetTickCount()/portTICK_PERIOD_MS;

An alternative to this would be to receive the current time via NTP by using the UDP protocol.

Nevertheless, since you are a beginner, I strongly recommend going through the first steps and freeRTOS guide to get familiar with XDK programming.

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

Kind regards,
Franjo

+1 (1 Vote)
RE: Read movement and time sensors
Answer
12/11/17 1:14 AM as a reply to Franjo Stjepandic.

Hello Franjo,

thank you very much for your reply.

I will test the things out you mentioned and reply here if there are any problems with it.

Hopefully this works. :-)

Thanks!

0 (0 Votes)
RE: Read movement and time sensors
Answer
12/11/17 5:03 PM as a reply to Christian.

Hello Christian,

I am glad to hear that I could help you.

Please feel free to ask, if you have further questions.

Kind regards,
Franjo

+1 (1 Vote)
RE: Read movement and time sensors
Answer
12/12/17 8:05 PM as a reply to Franjo Stjepandic.

Hello Franjo,

i tested the things you mentioned. I guess it could work this way but in the meantime i want to ask another question regarding my idea.

I saw that the program "SendAccelDataOverUdpAndBle" would be the perfect program to start off with my project. I just need to add the time-factor and the other sensors, which would be easy to implement i think. 

But in fact i have very little experience with the Udp programming. Maybe you could help me here again? I just want to connect the XDK with my Router (which works perfectly) and send the AccelerationData and the other data to my computer over Wifi. The console says "Udp sending successful" but how do i get this data to my pc and show it in a textfile or something like that?

So short form: I want to record, send the data over udp, get it from the protocol in a file or something else and display it on the screen to read it out with another program

I dont know if this is a stupid question but i really didnt do anything with these protocols in the past.

I would really appreciate if you could help me again.

Thanks in advance!!

0 (0 Votes)
RE: Read movement and time sensors
Answer
12/13/17 5:10 PM as a reply to Christian.

Hello Christian,

UDP is, with TCP, one of the two most commonly used protocols for transferring data via the internet. Most application protocols (MQTT, HTTP, etc) use TCP or UDP as their basis.

Since you only want to store data in a file, I would recommend using the python socket library. An example for a simple receiving script for UDP can be found here.

To read and write to csv files with python, take a look at the documentation here.

In general, programming with a certain protocol is usually a question of finding a library in your preferred language. And luckily, there are libraries for everything for most languages. At least for everything that is widely and commonly used, such as most protocols.

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

Kind regards,
Franjo

0 (0 Votes)
RE: Read movement and time sensors
Answer
12/14/17 3:54 PM as a reply to Franjo Stjepandic.

Hello Franjo,

this worked. Thank you for your help!

Do you know how to send an Array over Udp filled with Strings? 

If i send only one String it isn´t a problem. But when i send an Array like: 

static char *stringArray[3];
    stringArray[0] = "a";
    stringArray[1] = "b";
    stringArray[2] = "c";

I get in my receiving console only something like this:

´é ¸é ¼é

I guess my receiver cant convert the incoming data into a String.

It would be very hard to send every single dataset in one "sendTo"  command. I would get maybe 20 incoming Udp packages per second. So an Array would be nice.

 

Thanks in Advance!

0 (0 Votes)
RE: Read movement and time sensors
Answer
12/15/17 2:06 PM as a reply to Christian.

Hello Christian,

there are two issues with the code you posted.

The first issue that you declared the array as follows:

static char *stringArray[3];

In C, when you declare an array, it is already implicitly a pointer to the first element of the array, i.e. a pointer to the first position. But if you also use the asterisk (*), you declare a pointer on the pointer. So your datatype is actually the pointer to a pointer to data, instead of a pointer to data. Just remove the asterisk, and this will be fixed.

The compiler should actually be printing warnings, saying that you're using the wrong type, if you were trying to assign elements of type char as the pointers. But in actualitiy, you are assigning strings, not char arrays. A char is, in actuality, just a number of the size of one byte. See the following code snippet and comments:

char *my_string = "a" // resolves to a pointer to the array {'a', '\0'}
char my_character = 'a' // resolves to the decimal value 97

Changing the double quotes to single quotes will fix this issue.

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

Kind regards,
Franjo

0 (0 Votes)
RE: Read movement and time sensors
Answer
12/18/17 3:24 PM as a reply to Franjo Stjepandic.

Hello Franjo,

you helped me with your reply but i don´t get all of this.

I also already read through these chapters in a C book but maybe I get it with you a bit clearer:

I store the Acceldata in a variable like it is in the example (AcceldataoverUdp):

bsdBuffer_mau[0] = getaccelData.xAxisData;

Then i need to convert this for whatever reason into a String to get it in my Udp Server (Java-coded).

The Server will not receive an integer.

sprintf(testString, "%ld \n",bsdBuffer_mau[0]);

Then i have the String "teststring" until this point it works perfectly. For example the xAxisData is 34 then my testString ist "34".

But if I do now this (with the corrections you mentioned implemented):

char stringArray[3];
    stringArray[0] = testString;
    stringArray[1] = 'b';
    stringArray[2] = 'c';

I do not get in my receiving console "34bc" if i send this over:

Status = sl_SendTo(SockID, stringArray, BUFFER_SIZE * sizeof(int32_t), (uint32_t) ZERO, (SlSockAddr_t *) &Addr, AddrSize);

with the warning: assignment makes integer from pointer without a cast

So i know what this warning means but even with the help of some stackoverflow posts i cant get it to work.

I get in my receiving console this with this code:

Lbc    "
Lbc    
Lbc   %
and so on 

 

So my question:

I know that this output is because of the sprintf command i used to get the integer to a String. But why does everything work when i send only the "testString" over which is the variable in my sprintf command but not if i send the testString in an Array over.

If i do this:

bsdBuffer_mau[0] = getaccelData.xAxisData;
sprintf(testString, "%ld \n",bsdBuffer_mau[0]);
Status = sl_SendTo(SockID, testString, BUFFER_SIZE * sizeof(int32_t), (uint32_t) ZERO, (SlSockAddr_t *) &Addr, AddrSize);

I get in my receving console the actual xAxisData like 30 , 31 and so on.

Can you help me again to resolve this issue?

I think this will be the last problem because all things i want to program after that will be on the serverside in Java. I only need to get the data over there :-)

 

Thank you very much!

0 (0 Votes)
RE: Read movement and time sensors
Answer
12/18/17 5:32 PM as a reply to Christian.

Hello Christian,

I am always glad to help.

Regarding your new issue, there are multiple issues again, and I think you have one basic misunderstanding on how strings work in C.

In essence, there are no strings in C. There are only arrays of elements of type char, which we call strings.

Of course, since strings are so common, there is special syntax in place for them, which allows to define a string using double quotes. See the following code for clarification:

char first_stringArray[3] = "abc"
char second_stringArray[3] = {'a', 'b', 'c', '\0'}

The first line is producing essentially the same data in memory as the second line. "abc" resolves to an array with length 4 and the content {'a', 'b', 'c', '\0'} (remember that strings in C end with the null-terminating character '\0').

Also, keep in mind that the variables first_stringArray and second_stringArray are just pointers, which usually have a length of 32bit.

As such stringArray[0] = testString; will produce unexpected results, since stringArray[0] is actually of type char, whereas you assign a pointer to that variable.

This is why sending testString will work just fine, since that variable had been handled properly.

Generally, I would recommend to implementing sending as follows:

char my_buffer[64]; // this can have more space than we actually need!
sprintf(my_buffer, "%d\n\%d\n%d\n", 64, 32, 12);
Status = sl_SendTo(SockID, my_buffer, strlen(my_buffer), (uint32_t) ZERO, (SlSockAddr_t *) &Addr, AddrSize);

Note that I use the function strlen() to determine the amount of bytes that are going to be sent. strlen counts the number of characters in an array until a '\0' is reached - which is always the last character of a string.

Please tell me if this was helpful and feel free to ask further questions.

Kind regards,
Franjo

+1 (1 Vote)
RE: Read movement and time sensors
Answer
12/18/17 10:50 PM as a reply to Franjo Stjepandic.

Hello Franjo,

i really appreciate your constantly help through my C-adventure here :-)

The various sensor data is now displayed correctly in my receiver. I can work with this.

But no one knows when the next problem is around the corner.

Thank you very much again!!

Best wishes, merry christmas and a happy new year aswell.

0 (0 Votes)
RE: Read movement and time sensors
Answer
12/19/17 4:50 PM as a reply to Christian.

Hello Christian,

I am always glad to help, you're welcome.

I wish you the best, a merry christmas and a happy new year, too.

Please feel free to ask if you have further questions.

Kind regards,
Franjo

0 (0 Votes)
RE: Read movement and time sensors
Answer
12/20/17 3:46 PM as a reply to Franjo Stjepandic.

Hello Franjo,

as I said the next problems will be around the corner.

After everything works now i want to concentrate on the orientation data which can be displayed in the 3 ways the guide mentioned. 

Can you tell me if this is possible and maybe how it would work:

So basically i want to know the position in xyz of my XDK and not really the Acceldata (i know this refers to one another).

I want to set a default position for the orientation of the XDK (0,0,0). And then use the orientation values in one of these three possibilities (quaternion, euler degree, euler radiant) to locate the XDK in a xyz coordination system (the rotation would be useless). I never heard something about quaternions so i dont know if this is the right feature for my needs.

To do this only with the Acceldata looks apparently very difficult :-/

Because even if I send the Acceldata every second it shows me only the actual acceldata in this point and time. Its difficult to interprete this data to a exact position.

 

I would appreciate if you can help me again.

Thanks in advance!

0 (0 Votes)
RE: Read movement and time sensors
Answer
12/20/17 4:50 PM as a reply to Christian.

Hello Christian,

depending on your exact use case, getting the position of the XDK in 3d space just from accelerometer and orientation data may be difficult. It specifically requires knowledge and algorithms on determining distance travelled in 3D space, with only accelerometer and orientation data as the basis.

You could send data of the orientation sensor (which is a combination of gyroscope and magnetometer) and data of the accelerometer, to your server and let the server calculate movement and position based on those values.

I would recommend reading through the API of the orientation sensor, which can be found at SDK > xdk110 > Platform > SensorToolbox > include > BCDS_Orientation.h (this file is automatically included, when XdkSensorHandle.h is included).

Generally, you will also have to keep gravity in mind, especially if the XDK is allowed to rotate freely in 3D space. There is always a total of 1G in the direction of earth,

Regarding the interpretation of the accelerometer data, yes, that is correct. G refers to 9,81m/(s^2), which makes your assumptions correct. With 1000mG being read, an acceleration of 9,81m/(s^2) is referred to. Half of that (500mG) refers to 4,405 m/(s^2).

As a sidenote, it would be helpful if you created a new thread for a new topic, since this is far exceeding the original issue. Other users facing similar issues will benefit from this, since the issue would be easier to find.

Please tell me if this was helpful and feel free to ask further questions.

Kind regards,
Franjo

0 (0 Votes)