-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbillybass.html
231 lines (200 loc) · 20 KB
/
billybass.html
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><title>Python: module billybass</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head><body bgcolor="#f0f0f8">
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="heading">
<tr bgcolor="#7799ee">
<td valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"> <br><big><big><strong>billybass</strong></big></big></font></td
><td align=right valign=bottom
><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/opt/AlexaPi/src/billybass.py">/opt/AlexaPi/src/billybass.py</a></font></td></tr></table>
<p></p>
<p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#aa55cc">
<td colspan=3 valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Modules</strong></big></font></td></tr>
<tr><td bgcolor="#aa55cc"><tt> </tt></td><td> </td>
<td width="100%"><table width="100%" summary="list"><tr><td width="25%" valign=top><a href="coloredlogs.html">coloredlogs</a><br>
</td><td width="25%" valign=top><a href="logging.html">logging</a><br>
</td><td width="25%" valign=top><a href="threading.html">threading</a><br>
</td><td width="25%" valign=top><a href="time.html">time</a><br>
</td></tr></table></td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ee77aa">
<td colspan=3 valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Classes</strong></big></font></td></tr>
<tr><td bgcolor="#ee77aa"><tt> </tt></td><td> </td>
<td width="100%"><dl>
<dt><font face="helvetica, arial"><a href="threading.html#Thread">threading.Thread</a>(<a href="builtins.html#object">builtins.object</a>)
</font></dt><dd>
<dl>
<dt><font face="helvetica, arial"><a href="billybass.html#BillyBass">BillyBass</a>
</font></dt></dl>
</dd>
</dl>
<p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ffc8d8">
<td colspan=3 valign=bottom> <br>
<font color="#000000" face="helvetica, arial"><a name="BillyBass">class <strong>BillyBass</strong></a>(<a href="threading.html#Thread">threading.Thread</a>)</font></td></tr>
<tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td>
<td colspan=2><tt>Purpose:<br>
Executes commands that move the motors of the billy bass animatronic.<br>
These commands represent different things the animatronic can do, such as move it's head, tail, or mouth.<br>
Commands are run by passing it through the constructor via its task parameter, which subsequently executes that command if it is valid. <br>
Once the function has executed, the object is destroyed because it inherits threading behaviors<br>
<br>
Behavior:<br>
Inherits multithreading. This allows the fish to respond to the voice commands by moving its motors<br>
while at the same time outputting the audio coming from alexapi. It also allows for it to listen for other voice commands while its executing. <br>
Usage:<br>
It is highly recommended to utilize this class using the with keyword as it will handle resource management without having to explicitly close the threads. This is because this class is a context manager.<br>
ex) with billybass(task="greet"):<br>
--enter code here if necessary--<br> </tt></td></tr>
<tr><td> </td>
<td width="100%"><dl><dt>Method resolution order:</dt>
<dd><a href="billybass.html#BillyBass">BillyBass</a></dd>
<dd><a href="threading.html#Thread">threading.Thread</a></dd>
<dd><a href="builtins.html#object">builtins.object</a></dd>
</dl>
<hr>
Methods defined here:<br>
<dl><dt><a name="BillyBass-__enter__"><strong>__enter__</strong></a>(self)</dt><dd><tt>Magic method that is called when the class is being instantiated <br>
with the 'with' keyword (context manager protocol). This method allows us to define what function to execute based on the task given in the constructor variable.<br>
If the task is illegal or does not exist, we raise an exception.<br>
<br>
Using context managers gives us the security in knowing the thread<br>
that is spawned when this class is instantiated is being released without having to deal with releasing it explicitly in the code that calls it. (__exit__ frees the resource)</tt></dd></dl>
<dl><dt><a name="BillyBass-__exit__"><strong>__exit__</strong></a>(self, exc_type, exc_val, exc_tb)</dt><dd><tt>Called once were exiting from the with statement.</tt></dd></dl>
<dl><dt><a name="BillyBass-__init__"><strong>__init__</strong></a>(self, task)</dt><dd><tt>Constructor calls superclass(threading) to set up its appropriate variables<br>
It also initalizes the adafruit motorkit, which we need in order to manipulate the motors of the animatronic.<br>
:param task: string that represents a command to the alexa service is being executed ( ex) When querying alexa</tt></dd></dl>
<dl><dt><a name="BillyBass-dance"><strong>dance</strong></a>(self)</dt><dd><tt>The fish can dance! Moves it's head and tail with a time buffer<br>
in between so we don't overload the fish with too much current!<br>
BUG: Fish stops dancing after a couple seconds of usage. I have a feeling it has something to do with<br>
thread synchronization as when the dance function is called in main.py<br>
it is continiously called which spawns more threads to execute the same function.<br>
<br>
The fish dances in main.py when we play a playlist</tt></dd></dl>
<dl><dt><a name="BillyBass-greet"><strong>greet</strong></a>(self)</dt><dd><tt>Moves mouth in a specific way when the alexapi service starts.<br>
When its first initalized, the alexapi service notifies it is ready to run by saying "hello"</tt></dd></dl>
<dl><dt><a name="BillyBass-move_head"><strong>move_head</strong></a>(self)</dt><dd><tt>Moves the head of the billybass fish by controlling the motor that moves it's body (negative values move head)</tt></dd></dl>
<dl><dt><a name="BillyBass-move_mouth"><strong>move_mouth</strong></a>(self)</dt><dd><tt>Moves the mouth of the billybass fish by controlling the motor that moves it's mouth</tt></dd></dl>
<dl><dt><a name="BillyBass-move_tail"><strong>move_tail</strong></a>(self)</dt><dd><tt>Moves the tail of the billybass fish by controlling the motor that moves it's body (positive values move tail)</tt></dd></dl>
<dl><dt><a name="BillyBass-release_motor"><strong>release_motor</strong></a>(self, sensitivity)</dt><dd><tt>Releases motor by sleeping for a specified amount of time<br>
:param sensitivity: time in seconds to sleep for</tt></dd></dl>
<dl><dt><a name="BillyBass-reset_motors"><strong>reset_motors</strong></a>(self)</dt><dd><tt>Helper function that resets both of the positions of the <br>
motors to their default values</tt></dd></dl>
<dl><dt><a name="BillyBass-response"><strong>response</strong></a>(self)</dt><dd><tt>Moves mouth of billybass fish when alexa is responding<br>
to a query the user requested.<br>
NOTE: This function is redundant in a sense that it only calls one function and debug logs. However I implemented it this way<br>
because there may be multiple ways the billybass fish can respond to a query (it can move its head and tail as well)<br>
so its nice to know I don't have to mess around with the actual function that moves the motors and instead can mess around with it here.</tt></dd></dl>
<dl><dt><a name="BillyBass-run"><strong>run</strong></a>(self)</dt><dd><tt>When the thread is executed it runs this method<br>
It keeps executing until were told to stop. (self.<strong>done</strong>)<br>
If any errors occur we output to the user and raise the exception</tt></dd></dl>
<dl><dt><a name="BillyBass-run_motor"><strong>run_motor</strong></a>(self, motor, sensitivity, steps)</dt><dd><tt>:param motor: which motor to run this on (mouth or body)<br>
:param sensitivity: delays the time between steps. The higher the value, the longer it will wait (measured in seconds)<br>
:param steps: list of floats that represent a sequence of positions on where to move the motor to [value of motor can only -1 <= x <= 1.</tt></dd></dl>
<dl><dt><a name="BillyBass-stop"><strong>stop</strong></a>(self)</dt><dd><tt>Stops execution of the thread by setting this flag to<br>
true. Once execution of the thread has finished, it will<br>
free its resources</tt></dd></dl>
<dl><dt><a name="BillyBass-trigger"><strong>trigger</strong></a>(self)</dt><dd><tt>Moves head and mouth of the billybass fish. This should be called<br>
when the user triggers alexa for a query so that the fish mimics responsiveness</tt></dd></dl>
<hr>
Static methods defined here:<br>
<dl><dt><a name="BillyBass-set_debug"><strong>set_debug</strong></a>(DEBUG)</dt><dd><tt>Sets the debug level. Used primarily for debugging purposes<br>
:param DEBUG: boolean indicating whether to set log_level to debug or not</tt></dd></dl>
<hr>
Methods inherited from <a href="threading.html#Thread">threading.Thread</a>:<br>
<dl><dt><a name="BillyBass-__repr__"><strong>__repr__</strong></a>(self)</dt><dd><tt>Return repr(self).</tt></dd></dl>
<dl><dt><a name="BillyBass-getName"><strong>getName</strong></a>(self)</dt></dl>
<dl><dt><a name="BillyBass-isAlive"><strong>isAlive</strong></a> = is_alive(self)</dt><dd><tt>Return whether the thread is alive.<br>
<br>
This method returns True just before the <a href="#BillyBass-run">run</a>() method starts until just<br>
after the <a href="#BillyBass-run">run</a>() method terminates. The module function enumerate()<br>
returns a list of all alive threads.</tt></dd></dl>
<dl><dt><a name="BillyBass-isDaemon"><strong>isDaemon</strong></a>(self)</dt></dl>
<dl><dt><a name="BillyBass-is_alive"><strong>is_alive</strong></a>(self)</dt><dd><tt>Return whether the thread is alive.<br>
<br>
This method returns True just before the <a href="#BillyBass-run">run</a>() method starts until just<br>
after the <a href="#BillyBass-run">run</a>() method terminates. The module function enumerate()<br>
returns a list of all alive threads.</tt></dd></dl>
<dl><dt><a name="BillyBass-join"><strong>join</strong></a>(self, timeout=None)</dt><dd><tt>Wait until the thread terminates.<br>
<br>
This blocks the calling thread until the thread whose <a href="#BillyBass-join">join</a>() method is<br>
called terminates -- either normally or through an unhandled exception<br>
or until the optional timeout occurs.<br>
<br>
When the timeout argument is present and not None, it should be a<br>
floating point number specifying a timeout for the operation in seconds<br>
(or fractions thereof). As <a href="#BillyBass-join">join</a>() always returns None, you must call<br>
<a href="#BillyBass-isAlive">isAlive</a>() after <a href="#BillyBass-join">join</a>() to decide whether a timeout happened -- if the<br>
thread is still alive, the <a href="#BillyBass-join">join</a>() call timed out.<br>
<br>
When the timeout argument is not present or None, the operation will<br>
block until the thread terminates.<br>
<br>
A thread can be <a href="#BillyBass-join">join</a>()ed many times.<br>
<br>
<a href="#BillyBass-join">join</a>() raises a RuntimeError if an attempt is made to join the current<br>
thread as that would cause a deadlock. It is also an error to <a href="#BillyBass-join">join</a>() a<br>
thread before it has been started and attempts to do so raises the same<br>
exception.</tt></dd></dl>
<dl><dt><a name="BillyBass-setDaemon"><strong>setDaemon</strong></a>(self, daemonic)</dt></dl>
<dl><dt><a name="BillyBass-setName"><strong>setName</strong></a>(self, name)</dt></dl>
<dl><dt><a name="BillyBass-start"><strong>start</strong></a>(self)</dt><dd><tt>Start the thread's activity.<br>
<br>
It must be called at most once per thread object. It arranges for the<br>
object's <a href="#BillyBass-run">run</a>() method to be invoked in a separate thread of control.<br>
<br>
This method will raise a RuntimeError if called more than once on the<br>
same thread object.</tt></dd></dl>
<hr>
Data descriptors inherited from <a href="threading.html#Thread">threading.Thread</a>:<br>
<dl><dt><strong>__dict__</strong></dt>
<dd><tt>dictionary for instance variables (if defined)</tt></dd>
</dl>
<dl><dt><strong>__weakref__</strong></dt>
<dd><tt>list of weak references to the object (if defined)</tt></dd>
</dl>
<dl><dt><strong>daemon</strong></dt>
<dd><tt>A boolean value indicating whether this thread is a daemon thread.<br>
<br>
This must be set before start() is called, otherwise RuntimeError is<br>
raised. Its initial value is inherited from the creating thread; the<br>
main thread is not a daemon thread and therefore all threads created in<br>
the main thread default to daemon = False.<br>
<br>
The entire Python program exits when no alive non-daemon threads are<br>
left.</tt></dd>
</dl>
<dl><dt><strong>ident</strong></dt>
<dd><tt>Thread identifier of this thread or None if it has not been started.<br>
<br>
This is a nonzero integer. See the thread.get_ident() function. Thread<br>
identifiers may be recycled when a thread exits and another thread is<br>
created. The identifier is available even after the thread has exited.</tt></dd>
</dl>
<dl><dt><strong>name</strong></dt>
<dd><tt>A string used for identification purposes only.<br>
<br>
It has no semantics. Multiple threads may be given the same name. The<br>
initial name is set by the constructor.</tt></dd>
</dl>
</td></tr></table></td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#eeaa77">
<td colspan=3 valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Functions</strong></big></font></td></tr>
<tr><td bgcolor="#eeaa77"><tt> </tt></td><td> </td>
<td width="100%"><dl><dt><a name="-main"><strong>main</strong></a>()</dt></dl>
</td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#55aa55">
<td colspan=3 valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Data</strong></big></font></td></tr>
<tr><td bgcolor="#55aa55"><tt> </tt></td><td> </td>
<td width="100%"><strong>logger</strong> = <logging.Logger object></td></tr></table>
</body></html>