-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
basic throw counter; audio with flite
- Loading branch information
Alon
committed
Feb 26, 2010
1 parent
799d2bc
commit 278f9a9
Showing
4 changed files
with
54 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
""" | ||
signal processing. Determine what is happening to the ball from | ||
a stream of accelerations. The code here is generator based, i.e. event | ||
based. | ||
""" | ||
|
||
def sum_squares_gen(v3_gen, verbose=False): | ||
for x, y, z in v3_gen: | ||
sq = x**2 + y**2 + z**2 | ||
if verbose: | ||
print sq | ||
yield sq | ||
|
||
def throws(accels, initial = 0, throw_max_accel=0.1, land_min_accel=0.5, verbose=False): | ||
""" generator, yields (<throw num>, 1) when thrown, and (<throw num>, 0) | ||
when landed. Throw is detected | ||
""" | ||
i = initial | ||
sq_gen = sum_squares_gen(accels, verbose=verbose) | ||
while True: | ||
for a in sq_gen: | ||
if a < throw_max_accel: | ||
i += 1 | ||
yield i, 1 | ||
break | ||
for a in sq_gen: | ||
if a > land_min_accel: | ||
yield i, 0 | ||
break | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!/usr/bin/python | ||
|
||
import os | ||
from reader import stationary_factory | ||
from sp import throws | ||
|
||
def main(): | ||
stationary = stationary_factory() | ||
for throw_num, thrown in throws(stationary.accelerations()): | ||
print throw_num, thrown | ||
if thrown: | ||
os.system("flite -t %s &" % throw_num) | ||
|
||
if __name__ == '__main__': | ||
main() | ||
|