Difference between revisions of "ECE597 Project SensorTag 3D"

From eLinux.org
Jump to: navigation, search
(Some Fun Math!)
m (to Fall 2014)
 
(15 intermediate revisions by 3 users not shown)
Line 1: Line 1:
[[Category:ECE597 |Px]]
+
[[Category:ECE497Fall2014]]
 
{{YoderHead}}
 
{{YoderHead}}
  
 
Team members: [[user:Leihao| Leihao Wei]] [[user:Yashi3456| Yashi Yadav]]
 
Team members: [[user:Leihao| Leihao Wei]] [[user:Yashi3456| Yashi Yadav]]
 
== Grading Template ==
 
I'm using the following template to grade.  Each slot is 10 points.
 
0 = Missing, 5=OK, 10=Wow!
 
 
<pre style="color:red">
 
00 Executive Summary
 
00 Installation Instructions
 
00 User Instructions
 
00 Highlights
 
00 Theory of Operation
 
00 Work Breakdown
 
00 Future Work
 
00 Conclusions
 
00 Demo
 
00 Late
 
Comments: I'm looking forward to seeing this.
 
 
Score:  10/100
 
</pre>
 
 
<span style="color:red">(Inline Comment)</span>
 
  
 
== Executive Summary ==
 
== Executive Summary ==
 
+
SensorTag is a portable low-power module that uses Blueooth Low Energy (BLE, Bluetooth 4.0) and various sensors to communicate data to any BLE receiver. The purpose of this project is to build an application interacting with a beaglebone to track the SensorTag’s rotation in 3D. We started off from the previous work [<ref>http://elinux.org/TI_SensorTag</ref> SensorTag]. We were able to improve the tracking of the sensor tag by running the angles measured through a complementary filter. We were also able to change the firmware on the SensorTag so it is now able to have a faster refreshing rate (10Hz).
SensorTag is a portable low-power module that uses Blueooth Low Energy (BLE, Bluetooth 4.0) and various sensors to communicate data to any BLE receiver. The purpose of this project is to build an application interacting with a beaglebone to track the SensorTag’s rotation in 3D. We'll start off from the previous work [<ref>http://elinux.org/TI_SensorTag</ref> SensorTag]. We expect to see it sending updates at 10Hz by modifying the firmware.
 
  
 
== Packaging ==
 
== Packaging ==
Line 97: Line 74:
  
 
<source lang="bash">
 
<source lang="bash">
root@beaglebone:~/sensorTag3D/MyRealtime# sudo DEBUG=test_gyro node test_gyro.js
+
$root@beaglebone:~/sensorTag3D/MyRealtime# sudo DEBUG=test_gyro node test_gyro.js
 
starting test_gyro
 
starting test_gyro
 
connect
 
connect
Line 120: Line 97:
 
</source>
 
</source>
  
Now, we can see that data are transmitted about the rate of 100 ms on average (10Hz).
+
Now, the firmware is updated to 1.5 version, and we can see that data are transmitted about the rate of 100 ms on average (10Hz).
  
  
Line 146: Line 123:
  
 
== Theory of Operation ==
 
== Theory of Operation ==
 +
 +
Click [https://www.youtube.com/watch?v=D9vi4AAVvj8&feature=youtu.be HERE] to see the youtube demo of our project.
  
 
This is the flow of our program:  
 
This is the flow of our program:  
Line 159: Line 138:
 
*The x-axis is aligned at right angles to both the y and z axes so that the three axes form a right handed coordinate system.
 
*The x-axis is aligned at right angles to both the y and z axes so that the three axes form a right handed coordinate system.
  
Accelerometer sensors measure the difference between any linear acceleration in the accelerometer’s reference frame and the earth's gravitational field vector. Of course, we can convert it to pitch and roll by doing some math<ref>http://www.freescale.com/files/sensors/doc/app_note/AN3461.pdf</ref> or <ref>http://www.analog.com/static/imported-files/application_notes/AN-1057.pdf</ref>. This involves some simple vector algebra to derive tilt angles.Note that, the order is not unique. For me, I choose YXZ, that is, do a pitch (rotate around y) first then followed by a roll (rotate around x). The ATAN2 function automatically returns the angle (in radians) in the correct quadrant based on the signs of the two arguments.
+
Accelerometer sensors measure the difference between any linear acceleration in the accelerometer’s reference frame and the earth's gravitational field vector. Of course, we can convert it to pitch and roll by doing some math<ref>http://www.freescale.com/files/sensors/doc/app_note/AN3461.pdf</ref> or <ref>http://www.analog.com/static/imported-files/application_notes/AN-1057.pdf</ref> <ref>http://developer.nokia.com/community/wiki/How_to_get_pitch_and_roll_from_accelerometer_data_on_Windows_Phone</ref>. This involves some simple vector algebra to derive tilt angles.Note that, the order is not unique. For me, I choose YXZ, that is, do a pitch (rotate around y) first then followed by a roll (rotate around x). The ATAN2 function automatically returns the angle (in radians) in the correct quadrant based on the signs of the two arguments.
 
<center>Pitch= ATAN2(-Ax/Az)</center>
 
<center>Pitch= ATAN2(-Ax/Az)</center>
 
<center>Roll= ATAN2(Ay/sqrt(Ax^2+Az^2))</center>
 
<center>Roll= ATAN2(Ay/sqrt(Ax^2+Az^2))</center>
Line 196: Line 175:
  
 
*Major Tasks:
 
*Major Tasks:
1) Get previous work working: Lei Hao and Yashi
+
1) Get previous work working: Leihao and Yashi
 
<br>
 
<br>
2) Look into firmware for faster refreshing rate: Lei Hao and Yashi
+
2) Look into firmware for faster refreshing rate: Leihao and Yashi
 
<br>
 
<br>
3) Update javascript file to be compatible with new firmware version: Lei Hao
+
3) Update javascript file to be compatible with new firmware version: Leihao
 
<br>
 
<br>
4) Documentation: Lei Hao and Yashi
+
4) Documentation: Leihao and Yashi
 
<br>
 
<br>
 
  
 
== Future Work ==
 
== Future Work ==

Latest revision as of 04:12, 10 August 2015

thumb‎ Embedded Linux Class by Mark A. Yoder


Team members: Leihao Wei Yashi Yadav

Executive Summary

SensorTag is a portable low-power module that uses Blueooth Low Energy (BLE, Bluetooth 4.0) and various sensors to communicate data to any BLE receiver. The purpose of this project is to build an application interacting with a beaglebone to track the SensorTag’s rotation in 3D. We started off from the previous work [[1] SensorTag]. We were able to improve the tracking of the sensor tag by running the angles measured through a complementary filter. We were also able to change the firmware on the SensorTag so it is now able to have a faster refreshing rate (10Hz).

Packaging

  • Beaglebone Black
  • TI SensorTag [[2]|TI SensorTag]
  • Bluetooth CSR 4.0 dongle
Beagleboneblack
TI SensorTag

Installation Instructions

  • Get the project repository
 git clone https://github.com/Litou1/sensorTag3D
  • Install necessary packages in the current directory.
npm install -g async 
npm install debug 
npm install noble 
npm install sensortag
  • Obtain the test code
git clone  https://github.com/Lahorde/node-sensortag.git

Update the SensorTag Firmware

NOTE: You will need an iOS device for this!

I obtained the following instructions from this website: [[3] | FirmwareInstructions]


1) Make the changes to the firmware to get a faster refreshing rage. Here is how to do so (information obtained from [[4] HERE]):

  • a) Download IAR Workbench [[5] HERE](make sure to choose 30 day evaluation copy)
  • b) Download BLE-STACK from [[6] HERE]
  • c) In IAR Workbench Open SensorTag.eww file from following path: "C:\Texas Instruments\BLE-CC254x-1.4.0\Projects\ble\SensorTag\CC2541DB\SensorTag.eww"
  • d) After the gyro data is read, the gyro goes into sleep mode. A gyro wake up routine is called. This makes the gyro capture period limited to the gyro startup time which is 60ms. So, in order to get a faster refreshing rate, one must modify to code in HalGyro.c so the gyro does not go to sleep after data is read (line 296). Also, get rid of SENSOR_PERIOD_RESOLUTION in the gyro service source file
  • (Alternatively, instead of changing the firmware manually, you can get the updated version (with faster refreshing rate) from a github repository. Get the A and B images from [[7] HERE]


    2) Get the SensorTag App from the app from the Apple App Store 3) Connect your iOS device to your computer and open up iTunes.
    4) Under the "Apps" section, go to the bottom of the page to find "File Sharing". The SensorTag App should appear in the "Apps"-list.
    5) Click "Add" on the right hand side and select both firmware files.
    6) Sync iTunes with iOS device.
    7) Open SensorTag App on your iOS device.
    8) Select "Upgrade FW" then "Select FW File" then "Shared Files"
    9) If you already have image A installed, install image B. (If you have B installed, install image A)
    10) Wait till firmware has been updated on your device.

    You have successfully updated your firmware, so now you can have a fast refreshing rate!

    Test the Gyroscope

    Press the side button on your sensorTag so that it enters discovery mode.

    $root@beaglebone:~/sensorTag3D/MyRealtime# sudo DEBUG=test_gyro node test_gyro.js
    starting test_gyro
    connect
    discoverServicesAndCharacteristics
    readDeviceName
    	device name = TI BLE Sensor Tag
    readSystemId
    	system id = 90:59:af:0:0:b:b:b0
    readFirmwareRevision
    	firmware revision = 1.5 (Oct 23 2013)
    enableGyroscope
      test_gyro 	x = 2.7 °/s - y = -0.3 °/s - z = -1.1 °/s +0ms
      test_gyro 	x = 2.9 °/s - y = -0.1 °/s - z = -1.5 °/s +114ms
      test_gyro 	x = 2.6 °/s - y = -0.5 °/s - z = -1.5 °/s +68ms
      test_gyro 	x = 2.6 °/s - y = -0.4 °/s - z = -1.5 °/s +140ms
      test_gyro 	x = 2.7 °/s - y = -0.2 °/s - z = -1.5 °/s +71ms
      test_gyro 	x = 2.7 °/s - y = 0 °/s - z = -1.5 °/s +147ms
      test_gyro 	x = 2.8 °/s - y = -1 °/s - z = -1.5 °/s +62ms
      test_gyro 	x = 2.7 °/s - y = -0.2 °/s - z = -1.3 °/s +76ms
      test_gyro 	x = 2.4 °/s - y = -0.5 °/s - z = -1.3 °/s +134ms
      test_gyro 	x = 2.6 °/s - y = -0.7 °/s - z = -1.5 °/s +70ms
    

    Now, the firmware is updated to 1.5 version, and we can see that data are transmitted about the rate of 100 ms on average (10Hz).


    User Instructions

    To use the program run ./boneServer_sensorTag.js as shown below

    Go to 192.168.7.2.9090 and click on the ball and cube image.

    Wait a few seconds to connect.

    The image should be rendering on the screen as shown below.

    SensorTagRotation.gif


    Theory of Operation

    Click HERE to see the youtube demo of our project.

    This is the flow of our program:

    BallAndCube123.jpg

    Some Fun Math!

    We will use the rectangular coordinate system for a sensorTag, but using Aircraft principal axes [8] (pitch, roll and yaw) to describle rotation. Define coordinate system: Put the sensorTag on the table, IR sensor facing upward.

    • The y-axis is aligned along the body axis of the sensor tag (small end of the tag).
    • The z-axis points upward so that it is aligned with opposite gravity when the smartphone is flat on a table.
    • The x-axis is aligned at right angles to both the y and z axes so that the three axes form a right handed coordinate system.

    Accelerometer sensors measure the difference between any linear acceleration in the accelerometer’s reference frame and the earth's gravitational field vector. Of course, we can convert it to pitch and roll by doing some math[9] or [10] [11]. This involves some simple vector algebra to derive tilt angles.Note that, the order is not unique. For me, I choose YXZ, that is, do a pitch (rotate around y) first then followed by a roll (rotate around x). The ATAN2 function automatically returns the angle (in radians) in the correct quadrant based on the signs of the two arguments.

    Pitch= ATAN2(-Ax/Az)
    Roll= ATAN2(Ay/sqrt(Ax^2+Az^2))

    Note that we can't sense rotation around z since z is aligned with g, so instead we'll use gyroscope to find the rotation around z. Gyroscope measures the angular velocity around each x y and z.

    Integrate Gyroscope and Accelerometer Measurements

    • The problem with accelerometers

    As an accelerometer measures all forces that are working on the object, it will also see a lot more than just the gravity vector. Every small force working on the object will disturb our measurement completely. The accelerometer data is reliable only on the long term, so a "low pass" filter has to be used.

    • The problem with gyroscopes

    It is very easy to obtain an accurate measurement that was not susceptible to external forces. The less good news was that, because of the integration over time, the measurement has the tendency to drift, not returning to zero when the system went back to its original position. The gyroscope data is reliable only on the short term, as it starts to drift on the long term.

    • The complementary filter

    The complementary filter gives us a "best of both worlds" kind of deal. On the short term, we use the data from the gyroscope, because it is very precise and not susceptible to external forces. On the long term, we use the data from the accelerometer, as it does not drift. In it's most simple form, the filter looks as follows:

    angle = a*(angle + gyro*dt) + (1-a)*acc

    , where a between 0 and 1, dt is the gyroscope sampling time. a=T/(T+dt) and T is typically less than one second. I had a sampling rate of about 0.1 seconds and chose a time constant of about .75 seconds, giving a=0.88. More details about choosing "a" and complementary filter can be found in this balance filter [12] and these articles [13] [14].

            for (var i = 0; i < 3; i++) {
                // complementary filter
                filteredAngle[i] = alpha * (filteredAngle[i] + omega[i] * ts / 1000) + (1 - alpha) * accAngle[i];
            }
            // set Euler rotation order
            cube.rotation.order = "YXZ";
           // apply rotation 
            cube.rotation.x = filteredAngle[0];
            cube.rotation.y = filteredAngle[1];
            cube.rotation.z = filteredAngle[2];
            renderer.render(scene, camera);
    

    This will ensure that the measurement won't drift, but that it will be very accurate on the short term.

    Work Breakdown

    • Major Tasks:

    1) Get previous work working: Leihao and Yashi
    2) Look into firmware for faster refreshing rate: Leihao and Yashi
    3) Update javascript file to be compatible with new firmware version: Leihao
    4) Documentation: Leihao and Yashi

    Future Work

    Additional things that can improve project:

    • There are still some glitches in the program. For instance, the image isn't able to do a full 360 degree turn when you do a 360 degree turn on the SensorTag. It is possible due to the fact that accelerometer sensors are insensitive to rotation about the earth's gravitational field vector so that the equations for the roll and pitch angles therefore have mathematical instabilities when rotation axes happen to become aligned with gravity and point upwards or downwards.
    • Try a better filter e.g.. Kalman filter.

    Conclusions

    In conclusion, our project is able to pretty accurately display the SensorTage image and it's movements. We were also able to look into the firmware and update the refreshing rate to be faster than the previous project.




    thumb‎ Embedded Linux Class by Mark A. Yoder

    References: Template:Referencess