Editing Accelerometers

Warning: You are not logged in. Your IP address will be recorded in this page's edit history.
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision Your text
Line 1: Line 1:
-
#REDIRECT [[N900 accelerometer]]
+
Fremantle offers the possibility to play with accelerometers. There is a plan to offer a proper interface for accelerometers in Maemo, but if you want to try out before there are a couple of ways to do it.
 +
 
 +
See also the [http://talk.maemo.org/showthread.php?p=288990 related thread] in talk.maemo.org.
 +
 
 +
== D-Bus ==
 +
 
 +
Thomas Thurman ([http://twitter.com/marnanel marnanel]) has put together a simple demo of an application using accelerometers using the D-Bus interface. You can find sources and .deb up at http://people.collabora.co.uk/~tthurman/sandcastle/
 +
 
 +
== sysfs ==
 +
 
 +
Another way is to use the sysfs file information.
 +
 
 +
/sys/class/i2c-adapter/i2c-3/3-001d/coord
 +
 
 +
When reading that file you get 3 values X, Y and Z. Values are in mG (milli G). 1000 = 1 G
 +
 
 +
{| class="wikitable"
 +
|-
 +
! Position
 +
! X
 +
! Y
 +
! Z
 +
|-
 +
| Lying on table (back down)
 +
| 0
 +
| 0
 +
| -1000
 +
|-
 +
| Lying on table (face down)
 +
| 0
 +
| 0
 +
| 1000
 +
|-
 +
| Sitting on table (bottom edge down)
 +
| 0
 +
| -1000
 +
| 0
 +
|-
 +
| Sitting on table (right edge down)
 +
| -1000
 +
| 0
 +
| 0
 +
|-
 +
| Sitting on table (left edge down)
 +
| 1000
 +
| 0
 +
| 0
 +
|-
 +
| Bottom right corner down (approx.)
 +
| -500
 +
| -500
 +
| 0
 +
|}
 +
 
 +
These are theoretical values. In real life your mileage will vary.
 +
 
 +
== Using the data ==
 +
 
 +
The ''X'' and ''Y'' values can be used to calculate<ref>Tom Pycke, ''[http://tom.pycke.be/mav/69/accelerometer-to-attitude Accelerometer to pitch and roll]''</ref> the roll (that is, clockwise rotation) using the ''atan2'' function (note the inverted sign of ''y''):
 +
 
 +
  angle_in_radians = '''atan2'''(''x'', -''y'')
 +
 
 +
Similar, ''Y'' and ''Z'' can be used to calculate the pitch.
 +
 
 +
== Python ==
 +
 
 +
Using the sysfs interface:
 +
<pre>
 +
  def get_rotation():
 +
    f = open("/sys/class/i2c-adapter/i2c-3/3-001d/coord", 'r' )
 +
    coords = [int(w) for w in f.readline().split()]
 +
    f.close()
 +
    return coords
 +
</pre>
 +
 
 +
== References ==
 +
 
 +
<small>
 +
<references/>
 +
</small>
 +
 
 +
[[Category:Development]][[Category:Fremantle]]

Learn more about Contributing to the wiki.


Please note that all contributions to maemo.org wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see maemo.org wiki:Copyrights for details). Do not submit copyrighted work without permission!


Cancel | Editing help (opens in new window)