-
Notifications
You must be signed in to change notification settings - Fork 0
/
sequences.py
130 lines (100 loc) · 2.92 KB
/
sequences.py
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
import RPi.GPIO as GPIO
import time
import os
import random
from pin_control import *
MOTOR_STATE_FILE = "random_dataset4.txt"
def write_motor_states():
with open(MOTOR_STATE_FILE, "a") as motors:
motors.write(str(datetime.now()) + '\t')
print()
for i in motor_states:
print(motor_states[i] + '\t', end = '')
motors.write(motor_states[i] + '\t')
print()
motors.write('\n')
def HELPER_random_choose_motors():
num_ops = random.randint(1,15)
for _ in range(num_ops):
random_motor = random.randint(0,15)
if motor_states[random_motor] == 'closed':
motorOpen(random_motor)
motor_states[random_motor] = 'open'
print(motor_names[random_motor] + ' opened')
elif motor_states[random_motor] == 'open':
motorClose(random_motor)
motor_states[random_motor] = 'closed'
print(motor_names[random_motor] + ' closed')
def SEQUENCE_random():
closeAll()
while True:
HELPER_random_choose_motors()
write_motor_states()
print()
for i in range(0,300):
print('Next action in: ' + str(i)+'/300', flush=True)
time.sleep(1)
def demo():
closeAll()
while True:
HELPER_random_choose_motors()
write_motor_states()
print()
for i in range(0, 30):
print('Next action in: ' + str(i)+'/30', flush = True)
time.sleep(1)
#def SEQUENCE_NormalDay():
#TODO write method simulating a normal day:
# - since 2 bedroom home imagine a couple with one child
# family wakes up - sun down for one hour
# parent1: bathroom -> shower/change -> join breakfast -> leave(bedroom1->bathroom->kitchen->bathroom->front door)
# parent2: make breakfast -> bathroom -> shower/change -> leave(bedroom1->livingroom->kitchen->bathroom->front door)
# child: shower -> change -> join breakfast -> leave(bedroom2->bathroom->bedroom2->kitchen->front door)
# inital thoughts
# this would actually be best done with threads xd
# 'future work' ~~ (i don't know how to do threading in python)
# yeah so i wrote a bit then decided i'm not gonna do that and i'm going to just listen to Safa's recomendation and just do a couple short sequences
# but i'll start with the morning scenario i described above
def SEQUENCE_avgMorning():
# this sequence will be recording data every second and last for about an hour
# -- will provide ~the same number of data points as our random dataset for a full day's recording
motorOpen(4)
motorOpen(1)
time.sleep(2)
motorClose(4)
motorClose(1)
motorOpen(2)
time.sleep(2)
motorClose(2)
# parent 1 showering, parent 2 making breakfast
time.sleep(300)
motorOpen(3)
time.sleep(2)
motorClose(3)
motorOpen(2)
time.sleep(2)
motorClose(2)
motorOpen(0)
time.sleep(2)
motorClose(0)
time.sleep(300)
motorOpen(0)
time.sleep(2)
motorClose(0)
motorOpen(3)
time.sleep(2)
motorClose(3)
motorOpen(3)
time.sleep(2)
motorClose(3)
time.sleep(300)
motorOpen(4)
time.sleep(2)
motorClose(4)
time.sleep(120)
motorOpen(1)
time.sleep(2)
motorClose(1)
motorOpen(5)
time.sleep(2)
motorClose(5)