Statistics
| Branch: | Tag: | Revision:

hlrc / client / python / hlrc_client / Middleware.py @ e34ce888

History | View | Annotate | Download (5.982 KB)

1 0c286af0 Simon Schulz
"""
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 836f314c Robert Haschke
from .RobotEmotion import *
31
from .RobotGaze import *
32
from .RobotMouth import *
33
from .RobotAnimation import *
34 0c286af0 Simon Schulz
35
class Middleware:
36 3877047d Simon Schulz
    #######################################################################
37
    def __init__(self, scope, loglevel=logging.WARNING):
38 70c54617 Simon Schulz
        """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 02fc76ae Simon Schulz
    def is_running(self):
74
        self.die_virtual(sys._getframe().f_code.co_name)
75
76 70c54617 Simon Schulz
    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 465c7ad7 Florian Lier
    def publish_lookat_target(self, x, y, z, blocking, frame_id, roll):
89
        self.die_virtual(sys._getframe().f_code.co_name)
90
91 70c54617 Simon Schulz
    def publish_mouth_target(self, mouth, blocking):
92
        self.die_virtual(sys._getframe().f_code.co_name)
93
94
    def publish_head_animation(self, animation, blocking):
95
        self.die_virtual(sys._getframe().f_code.co_name)
96
97
    def publish_speech(self, text, blocking):
98
        self.die_virtual(sys._getframe().f_code.co_name)
99
100
    #######################################################################
101
    #finally some implemented functions
102
    def set_default_emotion(self, emotion, blocking):
103
        """set the default emotion
104
        :param emotion: RobotEmotion to set
105
        :param blocking: True if this call should block until execution finished on robot
106
        """
107
        self.default_emotion = emotion
108
        self.publish_default_emotion(emotion, blocking)
109
110
    def set_current_emotion(self, emotion, blocking):
111
        """set a temporary emotion (duration: see emotion.time_ms)
112
        :param emotion: RobotEmotion to set temporarily
113
        :param blocking: True if this call should block until execution finished on robot
114
        """
115
        self.current_emotion = emotion
116
        self.publish_current_emotion(emotion, blocking)
117
118
    def set_head_animation(self, animation, blocking):
119
        """trigger a head animation
120
        :param animation: RobotAnimation to set
121
        :param blocking: True if this call should block until execution finished on robot
122
        """
123
        self.animation = animation
124
        self.publish_head_animation(animation, blocking)
125
126
    def set_mouth_target(self, mouth, blocking):
127
        """set a mouth target
128
        :param mouth: RobotMouth to set
129
        :param blocking: True if this call should block until execution finished on robot
130
        """
131
        self.mouth_target = mouth
132
        self.publish_mouth_target(mouth, blocking)
133
134
    def set_speak(self, text, blocking):
135
        """trigger a tts speech output
136
        :param text: text to synthesize and speak
137
        :param blocking: True if this call should block until execution finished on robot
138
        """
139
        self.publish_speech(text, blocking)
140
141
    def set_gaze_target(self, gaze, blocking):
142
        """set a new gaze
143
        :param gaze: RobotGaze to set
144
        :param blocking: True if this call should block until execution finished on robot
145
        """
146
        self.gaze_target = gaze
147
        self.publish_gaze_target(gaze, blocking)
148
149 465c7ad7 Florian Lier
    def set_lookat_target(self, x, y, z, blocking=False, frame_id='', roll=0.0):
150
        """set a gaze at a Cartesian position
151
        :param x,y,z: position to look at (in eyes frame or frame_id)
152
        :param roll: side-ways motion of head
153
        :param blocking: True if this call should block until execution finished on robot
154
        """
155
        self.publish_lookat_target(x, y, z, blocking, frame_id, roll)
156
157 70c54617 Simon Schulz
    #######################################################################
158
    #some get methods
159
    #def get_current_emotion(self):
160
    #       return self.current_emotion
161
    #
162
    #def get_default_emotion(self):
163
    #       return self.default_emotion
164
    #