|
|
(16 intermediate revisions not shown) |
Line 1: |
Line 1: |
- | 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.
| + | #REDIRECT [[N900 accelerometer]] |
- | | + | |
- | 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
| + | |
- | | + | |
- | * On the table face up values are 0, 0, -1000 (face down would read 0, 0, 1000)
| + | |
- | * On the table on botton side (landscape): 0, -1000, 0
| + | |
- | * On the table on right side (portrait): -1000, 0, 0
| + | |
- | * In any other position any mix of those 3 values.
| + | |
- | | + | |
- | 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:
| + | |
- | | + | |
- | angle_in_radians = '''atan2'''(''x'', ''y'')
| + | |
- | | + | |
- | Similar, ''Y'' and ''Z'' can be used to calculate the pitch.
| + | |
- | | + | |
- | == Python ==
| + | |
- | | + | |
- | Simple example
| + | |
- | {{{
| + | |
- | | + | |
- | def get_rotation():
| + | |
- | try:
| + | |
- | f = open("/sys/class/i2c-adapter/i2c-3/3-001d/coord", 'r' )
| + | |
- | input=f.readline( )
| + | |
- | f.close()
| + | |
- | coords = input.split(' ')
| + | |
- | x=0
| + | |
- | y=0
| + | |
- | z=0
| + | |
- | try:
| + | |
- | x=int(coords[0])
| + | |
- | x=int(coords[1])
| + | |
- | z=int(coords[2])
| + | |
- | except:
| + | |
- | return (0,0,0)
| + | |
- | return (x,y,z)
| + | |
- | except:
| + | |
- | return (0,0,0)
| + | |
- | | + | |
- | }}}
| + | |
- | | + | |
- | The above is probably far from optimal, so please fix if you know how to read the data faster.
| + | |
- | | + | |
- | x, y and z values are in 1 G conditions between -900 and 900. Nominal state for each vector is 0. The values can be multiplied by the amount of Gs you may experience.
| + | |
- | | + | |
- | == References ==
| + | |
- | | + | |
- | <small>
| + | |
- | <references/>
| + | |
- | </small>
| + | |
- | | + | |
- | [[Category:Development]][[Category:Fremantle]]
| + | |