hlrc / client / python / hlrc_client / RobotEmotion.py @ 909e9261
History | View | Annotate | Download (2.322 KB)
1 |
"""
|
---|---|
2 |
This file is part of hlrc
|
3 |
|
4 |
Copyright(c) sschulz <AT> techfak.uni-bielefeld.de
|
5 |
http://opensource.cit-ec.de/projects/hlrc
|
6 |
|
7 |
This file may be licensed under the terms of the
|
8 |
GNU General Public License Version 3 (the ``GPL''),
|
9 |
or (at your option) any later version.
|
10 |
|
11 |
Software distributed under the License is distributed
|
12 |
on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
|
13 |
express or implied. See the GPL for the specific language
|
14 |
governing rights and limitations.
|
15 |
|
16 |
You should have received a copy of the GPL along with this
|
17 |
program. If not, go to http://www.gnu.org/licenses/gpl.html
|
18 |
or write to the Free Software Foundation, Inc.,
|
19 |
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
20 |
|
21 |
The development of this software was supported by the
|
22 |
Excellence Cluster EXC 277 Cognitive Interaction Technology.
|
23 |
The Excellence Cluster EXC 277 is a grant of the Deutsche
|
24 |
Forschungsgemeinschaft (DFG) in the context of the German
|
25 |
Excellence Initiative.
|
26 |
"""
|
27 |
|
28 |
class RobotEmotion: |
29 |
TYPE_DEFAULT = 0
|
30 |
TYPE_CURRENT = 1
|
31 |
|
32 |
NEUTRAL = 0
|
33 |
HAPPY = 1
|
34 |
SAD = 2
|
35 |
ANGRY = 3
|
36 |
SURPRISED = 4
|
37 |
FEAR = 5
|
38 |
|
39 |
# mappings from values to strings and vice versa
|
40 |
__value_as_str = dict(zip([NEUTRAL, HAPPY, SAD, ANGRY, SURPRISED, FEAR], |
41 |
['neutral', 'happy', 'sad', 'angry', 'surprised', 'fear'])) |
42 |
__str_as_value = dict([(s,v) for v,s in __value_as_str.items()]) |
43 |
|
44 |
def __init__(self, emotion = NEUTRAL, duration = 1.): |
45 |
""" constructor
|
46 |
param emotion: emotion constant
|
47 |
param duration: duration of emotion in seconds
|
48 |
"""
|
49 |
try:
|
50 |
self.value = int(emotion) |
51 |
try:
|
52 |
self.__value_as_str[self.value] |
53 |
except KeyError: |
54 |
raise Exception('invalid emotion id: %d' % self.value) |
55 |
except ValueError: |
56 |
try:
|
57 |
self.value = self.__str_as_value[emotion.lower()] |
58 |
except KeyError: |
59 |
raise Exception('invalid emotion: %s' % emotion) |
60 |
self.time_ms = int(1000*duration) # convert from s to ms |
61 |
|
62 |
def value_as_str(self): |
63 |
try:
|
64 |
return self.__value_as_str[self.value] |
65 |
except KeyError: |
66 |
return "INVALID EMOTION TYPE" |
67 |
|
68 |
def __str__(self): |
69 |
return "RobotEmotion = { value='%s', time_ms=%d }" % (self.value_as_str(), self.time_ms) |