Revision 3877047d client/python/hlrc_client/Middleware.py

View differences:

client/python/hlrc_client/Middleware.py
33 33
from RobotAnimation import *
34 34

  
35 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
			
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 55
	def __del__(self):
56
		"""destructor
57
		"""
58
		self.logger.debug("destructor of Middleware called")
59
	
60
	def config_logger(self, level):
56
	    """destructor
57
	    """
58
	    self.logger.debug("destructor of Middleware called")
59

  
60
	    def config_logger(self, level):
61 61
		formatter = logging.Formatter('%(asctime)s %(name)-30s %(levelname)-8s > %(message)s')
62 62
		ch = logging.StreamHandler()
63 63
		#ch.setLevel(level)
64 64
		ch.setFormatter(formatter)
65 65
		self.logger.setLevel(level)
66 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 init_middleware(self):
74
		self.die_virtual(sys._getframe().f_code.co_name)
75
	
76
	def publish_default_emotion(self, emotion, blocking):
77
		self.die_virtual(sys._getframe().f_code.co_name)
78
	
79
	def publish_current_emotion(self, emotion, blocking):
80
		self.die_virtual(sys._getframe().f_code.co_name)
81
	
82
	def publish_gaze_target(self, gaze, blocking):
83
		self.die_virtual(sys._getframe().f_code.co_name)
84
	
85
	def publish_mouth_target(self, mouth, blocking):
86
		self.die_virtual(sys._getframe().f_code.co_name)
87
	
88
	def publish_head_animation(self, animation, blocking):
89
		self.die_virtual(sys._getframe().f_code.co_name)
90
	
91
	def publish_speech(self, text, blocking):
92
		self.die_virtual(sys._getframe().f_code.co_name)
93
	
94
	#######################################################################
95
        #finally some implemented functions
96
        def set_default_emotion(self, emotion, blocking):
97
		"""set the default emotion
98
		:param emotion: RobotEmotion to set 
99
		:param blocking: True if this call should block until execution finished on robot
100
		"""
101
		self.default_emotion = emotion
102
		self.publish_default_emotion(emotion, blocking)
103
		
104
	def set_current_emotion(self, emotion, blocking):
105
		"""set a temporary emotion (duration: see emotion.time_ms)
106
		:param emotion: RobotEmotion to set temporarily
107
		:param blocking: True if this call should block until execution finished on robot
108
		"""
109
		self.current_emotion = emotion
110
		self.publish_current_emotion(emotion, blocking)
111
	
112
	def set_head_animation(self, animation, blocking):
113
		"""trigger a head animation
114
		:param animation: RobotAnimation to set
115
		:param blocking: True if this call should block until execution finished on robot
116
		"""
117
		self.animation = animation
118
		self.publish_head_animation(animation, blocking)
119
	
120
	def set_mouth_target(self, mouth, blocking):
121
		"""set a mouth target
122
		:param mouth: RobotMouth to set
123
		:param blocking: True if this call should block until execution finished on robot
124
		"""
125
		self.mouth_target = mouth
126
		self.publish_mouth_target(mouth, blocking)
127

  
128
	def set_speak(self, text, blocking):
129
		"""trigger a tts speech output
130
		:param text: text to synthesize and speak
131
		:param blocking: True if this call should block until execution finished on robot
132
		"""
133
		self.publish_speech(text, blocking)
134
	
135
	def set_gaze_target(self, gaze, blocking):
136
		"""set a new gaze 
137
		:param gaze: RobotGaze to set
138
		:param blocking: True if this call should block until execution finished on robot
139
		"""
140
		self.gaze_target = gaze
141
		self.publish_gaze_target(gaze, blocking)
142
		
143
	#######################################################################
144
	#some get methods
145
	#def get_current_emotion(self):
146
	#	return self.current_emotion
147
	#
148
	#def get_default_emotion(self):
149
	#	return self.default_emotion
150
	#
67

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

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

  
76
		    def publish_default_emotion(self, emotion, blocking):
77
			self.die_virtual(sys._getframe().f_code.co_name)
78

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

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

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

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

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

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

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

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

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

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

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

  
143
								    #######################################################################
144
								    #some get methods
145
								    #def get_current_emotion(self):
146
									#	return self.current_emotion
147
									#
148
									#def get_default_emotion(self):
149
									    #	return self.default_emotion
150
									    #

Also available in: Unified diff