TI Sensor Tag - Gyroscope

Discuss mobile apps for Texas Instruments products.
klemens2014
Posts: 12
Joined: 16:22, 17 Sep 2014

Re: TI Sensor Tag - Gyroscope

Postby klemens2014 » 17:57, 25 Sep 2014

I have written now an adapted version of the demo. It can be downloaded from here:
http://www.heartsome.de/android/tisensorapp-release.apk

I changed the follwoing:
a) Sensor service can be started and terminated with Connect to service
b) Sensor values can be stored in a csv file "Start saving values"
c) Sensors to be read can be activated with check boxes, red indicates not active, green active
d) frequency can be set for accelerometer, magnetometer and gyroscope (10-255)
e) gyroscope axis can be set (1-7)
f) Output displayed can be defined with Raw (raw data values), Conv (converted to physical measures), CSV string and Time can be displayed
g) Store only does not display values, but only writes to file (if activated)
h) Get Baro Calibration Data reads the sensors baro Calibration data for conversion

CSV output looks like this:

Code: Select all

SavedLine;SensorCode;Called;Date;TimeMs;DTimeMS;DiffTimeMS;data1;data2;data3;data4;data5;data6;data7;data8;data9;data10;data11;data12;data13;data14
12;H;13;25.9.2014 18:35:14;1411662914562;35306;134;4;105;-21;103;44.7354736328125;25.23338134765624
13;A;14;25.9.2014 18:35:14;1411662914953;35697;391;0;1;16;0;0.0625;-1;0;0.613125;-9.81
15;T;16;25.9.2014 18:35:15;1411662915037;35781;66;-100;-2;-128;12;25;21.05870147231468
16;B;17;25.9.2014 18:35:15;1411662915382;36126;345;4;-3;104;-121;104;958.7684029600323;-764;28.041163444519043;-19431.013358501717;17729286.903381348
17;M;18;25.9.2014 18:35:15;1411662915435;36179;53;112;-7;17;-5;87;-15;51.26953125;38.543701171875;-114.532470703125
18;H;19;25.9.2014 18:35:15;1411662915616;36360;181;4;105;-22;103;44.7354736328125;25.23338134765624


Now the drawbacks/problems:

a) I have the impression that the frequency rates is not really working well, if one looks at the csv file only 3 or 4 sensor measures are made per second. Maybe due to my bad implementation?
b) The conversion for barometer is not really looking good, values are sometimes not correkt compared with other tools. This could be due to the conversion functions which I based on TIs algorithms. Maybe I misunderstood something and made wrong assumptions, mixing up signed and unsigned bytes? But here TI info is not really helpfull as there is a difference between C and Java code shown there. Any ideas corrections are welcome.
c) The accelerometer values are based on a range from -8 - 8g and not -2 - 2g as TI wrote. At least this is my impression.

I can provide the source code no problem. If you want either in GitHub or where needed.

Klemens

klemens2014
Posts: 12
Joined: 16:22, 17 Sep 2014

Re: TI Sensor Tag - Gyroscope

Postby klemens2014 » 07:10, 29 Sep 2014

Just another though on this problem of speed:

How complicated would it be to change or add more code to the evo (Android) Java Cordova code so that it supports starting a service in the back ground for reading all the sensor values in Java and have an interface function for JavaScript part to read this values on demand. This could enabale storing the data in some structure in Java which I assume would be much faster than doing this in JavaScript and accessing a bulk of the sensor values every time through a JavaScript handlers. I have never written a Cordova plugin, therefore my question about the complexity of this.

I would do this but would like your feedback on this. I have to add that I would do it for Android (Java), not for iOS with its Objecktive C language.

klemens2014
Posts: 12
Joined: 16:22, 17 Sep 2014

Re: TI Sensor Tag - Gyroscope

Postby klemens2014 » 16:43, 30 Sep 2014


kmcallenberg
Posts: 2
Joined: 21:30, 02 Oct 2014

Re: TI Sensor Tag - Gyroscope

Postby kmcallenberg » 21:36, 02 Oct 2014

Hi Klemens, could you please post the source code somewhere? It would be excellent to see how you've saved the CSV. Thanks!

kmcallenberg
Posts: 2
Joined: 21:30, 02 Oct 2014

Re: TI Sensor Tag - Gyroscope

Postby kmcallenberg » 21:50, 02 Oct 2014

Sorry, nevermind! I just realized your code is all available inside the .apk file when opened as an archive.

User avatar
micke
Posts: 256
Joined: 20:49, 18 Nov 2013

Re: TI Sensor Tag - Gyroscope

Postby micke » 16:14, 05 Oct 2014

Dear Klemens,

Thanks for sharing truly great work!

Some input regarding your findings:

a) I have the impression that the frequency rates is not really working well, if one looks at the csv file only 3 or 4 sensor measures are made per second. Maybe due to my bad implementation?


A person I met said the SensorTag can be slow when having many sensors enabled, but this is not my experience however. The basic demo program (TISensorTag) seems to have a decent update frequency with all sensors enabled, but I have not done any measurements. Do you know if data storage plugin has any performance hits? If you turn off logging to CSV, does performance increase?

b) The conversion for barometer is not really looking good, values are sometimes not correkt compared with other tools. This could be due to the conversion functions which I based on TIs algorithms. Maybe I misunderstood something and made wrong assumptions, mixing up signed and unsigned bytes? But here TI info is not really helpfull as there is a difference between C and Java code shown there. Any ideas corrections are welcome.


I am no expert in juggling between signed/unsigned in JavaScript but here is the code I used for the gyroscope data (work-in-progress on a space game demo using the gyroscope as a game controller):

Code: Select all

function gyroscopeHandler(data)
{
    // y and x are not used.
    //var y = bytesToGyro(data[0], data[1]) * -1
    //var x = bytesToGyro(data[2], data[3])
    var z = bytesToGyro(data[4], data[5])

    ship1.sprite.body.velocity.x = z * -0.4
}

function bytesToGyro(byte1, byte2)
{
    // Commented out conversion to degrees/second.
    return bytesToInt16(byte1, byte2) // * (500.0 / 65536.0)
}

function bytesToInt16(byte1, byte2)
{
    var val = byte1 | (byte2 << 8)
    return val

    // Conversion that does not work.
    //if (val & 0x8000) { return (0xffff - val + 1) * -1 }
    //else { return val }
}


c) The accelerometer values are based on a range from -8 - 8g and not -2 - 2g as TI wrote. At least this is my impression.


Yes I also noted this! Perhaps this changed in the new SensorTag firmware? (I am using version 1.5)

Here is a snippet I used to test (hope the calculation is correct):

Code: Select all

function accelerometerHandler(data)
{
    var x = data[0] / 16
    var y = data[1] / 16
    var z = data[2] / 16
    var g = Math.sqrt((x*x)+(y*y)+(z*z))
    displayValue(
        'AccelerometerData',
        'x = ' + x + '<br/>y = ' + y + '<br/>z = ' + z + '<br/>g = ' + g)
}


Sorry for slow response on my behalf!

Mikael :)

User avatar
micke
Posts: 256
Joined: 20:49, 18 Nov 2013

Re: TI Sensor Tag - Gyroscope

Postby micke » 16:33, 05 Oct 2014

Hi again Klemens,

How complicated would it be to change or add more code to the evo (Android) Java Cordova code so that it supports starting a service in the back ground for reading all the sensor values in Java and have an interface function for JavaScript part to read this values on demand. This could enabale storing the data in some structure in Java which I assume would be much faster than doing this in JavaScript and accessing a bulk of the sensor values every time through a JavaScript handlers. I have never written a Cordova plugin, therefore my question about the complexity of this.


I think you will find that writing a Cordova plugin is not that hard. You can use the cordova-ble plugin as a template. When developing and testing, it is by far easiest/quickest to modify the generated platform code in platforms/android in your cordova project.

It could be best approach to write a dedicated SensorTag plugin. Communication between Java and JavaScript has some performance impact (but it is still quite fast I think, depends on the application requirements of course, see this blogpost I wrote last year that has some metrics for Android: http://divineprogrammer.blogspot.se/2013/07/android-webkit-performance.html).

Don't think a background service would boost performance, however I don't know for sure (would have to actually do tests to tell).

The steps to develop a Cordova plugin is roughly (sorry for any errors in the procedure):

  • Copy the cordova-ble plugin code to a new folder
  • Rename files as needed and update the plugin.xml file to match
  • Make a Cordova application project (for testing the plugin)
  • Add the plugin using: cordova plugin add ...
  • Add Android as platform: cordova platform add android
  • Build for Android: cordova build android
  • Develop and test in the generated Android project in platforms/android
  • Copy back files to the plugin directory
  • Remove and add the updates plugin in the Cordova project
  • Build and test

Regards, Mikael

User avatar
micke
Posts: 256
Joined: 20:49, 18 Nov 2013

Re: TI Sensor Tag - Gyroscope

Postby micke » 16:38, 05 Oct 2014

klemens2014 wrote:More details about the App here:
http://www.heartsome.de/de/android/andr ... ensor.html


Looks like a great app! Thanks for sharing!!

Mikael :)

klemens2014
Posts: 12
Joined: 16:22, 17 Sep 2014

Re: TI Sensor Tag - Gyroscope

Postby klemens2014 » 18:57, 06 Oct 2014

Hi,

I made small update to the app, adding a test button. I was interested if there is a difference in numbers of measures per second depending if data are written to a file or to the display. The test mode disables all writtings, just counts the number of sensor measures (sensor handlers called). The result is an average value of about 5 measures per second, this is independently how many sensors are activated.

Update on this: I made this measures with a sensor I received today. I upgraded the firmware from 1.4 to 1.5 and after update the measure rate went up to about 10 measures per second (also when writting sensor values to file).

So the question is: Is it up to the sensor speed as such or up to the communication overhead?

I tried a check with the app Sensor Tag and there I had the impression that more measures are done per second - looking at the number of values displayed, but that is just a subjective view.

Klemens

klemens2014
Posts: 12
Joined: 16:22, 17 Sep 2014

Re: TI Sensor Tag - Gyroscope

Postby klemens2014 » 13:01, 07 Oct 2014

I have created a iPhone version too. It can be downloaded from here:
http://www.heartsome.de/de/android/down ... ag.app.zip "WKTISensorTag.app.zip" as a zip file. Installation at your own risk. Measures per seconds are the same as with the Android version - about 10 per second.

Info at: http://www.heartsome.de/de/android/andr ... ensor.html


Return to “Texas Instruments”

Who is online

Users browsing this forum: No registered users and 2 guests