File: motionsensor-two.py

package info (click to toggle)
expeyes 5.3.4%2Brepack-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 43,608 kB
  • sloc: python: 36,039; ansic: 9,754; xml: 1,010; makefile: 784; sh: 581; asm: 202; javascript: 46; php: 1
file content (147 lines) | stat: -rw-r--r-- 4,621 bytes parent folder | download | duplicates (3)
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
'''
expEYES program
Developed as a part of GSoC Project 
this program allows user to use TWO motion sensors (srf-05 modules) and plot graphs in real-time.
'''
import gettext
gettext.bindtextdomain("expeyes")
gettext.textdomain('expeyes')
_ = gettext.gettext

import time, sys, math
from tkinter import *
sys.path=[".."] + sys.path
import expeyes.eyesj as eyes
import expeyes.eyeplot as eyeplot
import expeyes.eyemath as eyemath



WIDTH = 600 # width of drawing canvas
HEIGHT = 400 # height
vs = 0.034000
class Pend:
    tv = [ [], [], [] ] # Lists for Readings
    TIMER = 10	# Time interval between reads
    MINY = 0
    MAXY = 80
    running = False
    MAXTIME = 10

    def xmgrace(self):
        if self.running == True:
            return
        p.grace([self.tv])

    def start(self):
        self.running = True
        self.index = 0
        self.tv = [ [], [], [] ]
        try:
            self.MAXTIME = int(DURATION.get())
            self.MAXY = int(MAXDIST.get())
            g.setWorld(0, self.MINY, self.MAXTIME, self.MAXY,_('Time'),_('cm'))
            Dur.config(state=DISABLED)
            self.msg(_('Starting the Measurements'))
            root.after(self.TIMER, self.update)
        except:
            self.msg(_('Failed to Start'))

    def stop(self):
        self.running = False
        Dur.config(state=NORMAL)
        self.msg(_('User Stopped the measurements'))

    def update(self):
        if self.running == False:
            return
        tt = p.srfechotime(9,0)
        dist = (tt-400) *vs/2
        tt2 = p.srfechotime(8,3)
        dist2 = (tt2-400) *vs/2
        if len(self.tv[0]) == 0:
            self.start_time = time.time()
            elapsed = 0
        else:
            elapsed = time.time() - self.start_time
        self.tv[0].append(elapsed)
        self.tv[1].append(dist)
        self.tv[2].append(dist2)
        if len(self.tv[0]) >= 2:
            g.delete_lines()
            g.line(self.tv[0], self.tv[1])
            g.line(self.tv[0], self.tv[2],1)
        if elapsed > self.MAXTIME:
            self.running = False
            Dur.config(state=NORMAL)
            self.msg(_('Completed the Measurements'))
            return
        root.after(self.TIMER, self.update)

    def save(self):
        try:
            fn = filename.get()
        except:
            fn = 'motion2.dat'
        p.save([self.tv],fn)
        self.msg(_('Data saved to %s')%fn)

    def clear(self):
        if self.running == True:
            return
        self.tv = [ [], [] ]
        g.delete_lines()
        self.msg(_('Cleared Data and Trace'))

    def msg(self,s, col = 'blue'):
        msgwin.config(text=s, fg=col)

p = eyes.open()
p.disable_actions()
root = Tk()
Canvas(root, width = WIDTH, height = 5).pack(side=TOP) # Some space at the top
g = eyeplot.graph(root, width=WIDTH, height=HEIGHT, bip=False) # make plot objects using draw.disp
pen = Pend()
cf = Frame(root, width = WIDTH, height = 10)
cf.pack(side=TOP, fill = BOTH, expand = 1)
b3 = Label(cf, text = _('Digitize for'))
b3.pack(side = LEFT, anchor = SW)
DURATION = StringVar()
Dur =Entry(cf, width=5, bg = 'white', textvariable = DURATION)
DURATION.set('10')
Dur.pack(side = LEFT, anchor = SW)
b3 = Label(cf, text = _('Seconds.'))
b3.pack(side = LEFT, anchor = SW)
b3 = Label(cf, text = _('Max Dist='))
b3.pack(side = LEFT, anchor = SW)
MAXDIST = StringVar()
Dis =Entry(cf, width=5, bg = 'white', textvariable = MAXDIST)
MAXDIST.set('60')
Dis.pack(side = LEFT, anchor = SW)
b3 = Label(cf, text = _('cm'))
b3.pack(side = LEFT, anchor = SW)
cf = Frame(root, width = WIDTH, height = 10)
cf.pack(side=TOP, fill = BOTH, expand = 1)
b1 = Button(cf, text = _('START'), command = pen.start)
b1.pack(side = LEFT, anchor = N)
b1 = Button(cf, text = _('STOP'), command = pen.stop)
b1.pack(side = LEFT, anchor = N)
b4 = Button(cf, text = _('CLEAR'), command = pen.clear)
b4.pack(side = LEFT, anchor = N)
b1 = Button(cf, text = _('Xmgrace'), command = pen.xmgrace)
b1.pack(side = LEFT, anchor = N)
b3 = Button(cf, text = _('SAVE to'), command = pen.save)
b3.pack(side = LEFT, anchor = N)
filename = StringVar()
e1 =Entry(cf, width=15, bg = 'white', textvariable = filename)
filename.set('motion2.dat')
e1.pack(side = LEFT)
b5 = Button(cf, text = _('QUIT'), command = sys.exit)
b5.pack(side = RIGHT, anchor = N)
mf = Frame(root, width = WIDTH, height = 10)
mf.pack(side=TOP)
msgwin = Label(mf,text=_('Message'), fg = 'blue')
msgwin.pack(side=LEFT, anchor = S, fill=BOTH, expand=1)
#eyeplot.pop_image('pics/imagename.png', _('write the name of expt setup image'))
root.title(_('TWO Motion sensors'))
root.mainloop()