Statistics
| Branch: | Tag: | Revision:

hlrc / client / python / hlrc_client / Middleware.py @ 5eb9025f

History | View | Annotate | Download (5.445 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
import sys
29
import logging
30
from RobotEmotion import *
31
from RobotGaze import *
32
from RobotMouth import *
33
from RobotAnimation import *
34

    
35
class Middleware:
36
    #######################################################################
37
    def __init__(self, scope, loglevel=logging.WARNING):
38
        """initialise
39
        :param scope: base scope we want to listen on
40
        """
41
        self.base_scope = scope
42

    
43
        self.logger = logging.getLogger(__name__)
44

    
45
        # create nice and actually usable formatter and add it to the handler
46
        self.config_logger(loglevel)
47

    
48
        #initialise defaults
49
        self.default_emotion = RobotEmotion()
50
        self.current_emotion = RobotEmotion()
51
        self.gaze_target = RobotGaze()
52
        self.mouth_target = RobotMouth()
53
        self.robot_animation = RobotAnimation()
54

    
55
    def __del__(self):
56
        """destructor
57
        """
58
        self.logger.debug("destructor of Middleware called")
59

    
60
    def config_logger(self, level):
61
        formatter = logging.Formatter('%(asctime)s %(name)-30s %(levelname)-8s > %(message)s')
62
        ch = logging.StreamHandler()
63
        #ch.setLevel(level)
64
        ch.setFormatter(formatter)
65
        self.logger.setLevel(level)
66
        self.logger.addHandler(ch)
67

    
68
    #######################################################################
69
    #abstract/virtual functions
70
    def die_virtual(self, funcname):
71
        raise NotImplementedError(funcname + "() is virtual, must be overwritten")
72

    
73
    def is_running(self):
74
        self.die_virtual(sys._getframe().f_code.co_name)
75

    
76
    def init_middleware(self):
77
        self.die_virtual(sys._getframe().f_code.co_name)
78

    
79
    def publish_default_emotion(self, emotion, blocking):
80
        self.die_virtual(sys._getframe().f_code.co_name)
81

    
82
    def publish_current_emotion(self, emotion, blocking):
83
        self.die_virtual(sys._getframe().f_code.co_name)
84

    
85
    def publish_gaze_target(self, gaze, blocking):
86
        self.die_virtual(sys._getframe().f_code.co_name)
87

    
88
    def publish_mouth_target(self, mouth, blocking):
89
        self.die_virtual(sys._getframe().f_code.co_name)
90

    
91
    def publish_head_animation(self, animation, blocking):
92
        self.die_virtual(sys._getframe().f_code.co_name)
93

    
94
    def publish_speech(self, text, blocking):
95
        self.die_virtual(sys._getframe().f_code.co_name)
96

    
97
    #######################################################################
98
    #finally some implemented functions
99
    def set_default_emotion(self, emotion, blocking):
100
        """set the default emotion
101
        :param emotion: RobotEmotion to set
102
        :param blocking: True if this call should block until execution finished on robot
103
        """
104
        self.default_emotion = emotion
105
        self.publish_default_emotion(emotion, blocking)
106

    
107
    def set_current_emotion(self, emotion, blocking):
108
        """set a temporary emotion (duration: see emotion.time_ms)
109
        :param emotion: RobotEmotion to set temporarily
110
        :param blocking: True if this call should block until execution finished on robot
111
        """
112
        self.current_emotion = emotion
113
        self.publish_current_emotion(emotion, blocking)
114

    
115
    def set_head_animation(self, animation, blocking):
116
        """trigger a head animation
117
        :param animation: RobotAnimation to set
118
        :param blocking: True if this call should block until execution finished on robot
119
        """
120
        self.animation = animation
121
        self.publish_head_animation(animation, blocking)
122

    
123
    def set_mouth_target(self, mouth, blocking):
124
        """set a mouth target
125
        :param mouth: RobotMouth to set
126
        :param blocking: True if this call should block until execution finished on robot
127
        """
128
        self.mouth_target = mouth
129
        self.publish_mouth_target(mouth, blocking)
130

    
131
    def set_speak(self, text, blocking):
132
        """trigger a tts speech output
133
        :param text: text to synthesize and speak
134
        :param blocking: True if this call should block until execution finished on robot
135
        """
136
        self.publish_speech(text, blocking)
137

    
138
    def set_gaze_target(self, gaze, blocking):
139
        """set a new gaze
140
        :param gaze: RobotGaze to set
141
        :param blocking: True if this call should block until execution finished on robot
142
        """
143
        self.gaze_target = gaze
144
        self.publish_gaze_target(gaze, blocking)
145

    
146
    #######################################################################
147
    #some get methods
148
    #def get_current_emotion(self):
149
    #       return self.current_emotion
150
    #
151
    #def get_default_emotion(self):
152
    #       return self.default_emotion
153
    #