-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.scm
57 lines (45 loc) · 1.3 KB
/
main.scm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
;;
;; Tiny scheme program to play around with accelerometer data.
;; I captured this data using the Physics Toolbox Suite app.
;; It's a sweet app that gives you access to recording sensors
;; on your phone.
;;
(load (string-append
(if (defined? '*src-dir*) *src-dir* "")
"utils.scm"))
;; Counting the peaks in a given accelerometer stream. This should
;; give us a rough approximation of jumps
(define (count-peaks accum data)
(let ((lower 0)
(upper 10)
(verbose? #t)
(a-now (+ (data 1) (data 2) (data 3)))
(rising? (accum 0))
(num-peaks (accum 1)))
(cond ((and rising? (>= a-now upper))
(if verbose?
(show "peak discovered: " a-now))
(list #f (+ 1 num-peaks)))
((and (not rising?) (<= a-now lower))
(list #t num-peaks))
(else
(list rising? num-peaks)))))
;; Use Physics 101 to calculate distance
;; based on the current acceleration, time
;; and velocity
(define (calculate-distance accum data)
(let* ((t-now (data 0))
(a-now (+
(data 1) ; ax
(data 2) ; ay
(data 3) ; az
))
(t-prev (accum 0))
(v-prev (accum 1))
(d-prev (accum 2))
(t (- t-now t-prev))
(v-now (+ v-prev (* a-now t)))
(d-now (+ d-prev (* v-now t))))
(list t-now v-now d-now)))
(define (count-jumps path)
(cadr (with-data path count-peaks '(#t 0))))