示例#1
0
 def sendEmotion(self, emotion):
     msg = EmotionState()
     args = emotion['name'].split(',', 2)
     logger.info(args)
     msg.magnitude = 1
     msg.duration.secs = 1
     if len(args) >= 1:
         msg.name = str(args[0])
     if len(args) >= 2:
         msg.magnitude = float(args[1])
     if len(args) >= 3:
         msg.duration.secs = float(args[2])
     logger.info("Send emotion {}".format(msg))
     self.emotion_topic.publish(msg)
示例#2
0
	def show_emotion(self, expression, intensity, duration, trigger):

		# Try to avoid showing more than one expression at once
		now = time.time()
		since = self.blackboard["show_expression_since"]
		durat = self.blackboard["current_emotion_duration"]
		if since is not None and (now - since < 0.7 * durat) :
			return

		# Update the blackboard
		self.blackboard["current_emotion"] = expression
		self.blackboard["current_emotion_intensity"] = intensity
		self.blackboard["current_emotion_duration"] = duration

		# Create the message
		exp = EmotionState()
		exp.name = self.blackboard["current_emotion"]
		exp.magnitude = self.blackboard["current_emotion_intensity"]
		intsecs = int(duration)
		exp.duration.secs = intsecs
		exp.duration.nsecs = 1000000000 * (duration - intsecs)
		# emotion_pub goes to blender and tts;
		if (self.do_pub_emotions) :
			self.emotion_pub.publish(exp)
			self.write_log(exp.name, time.time(), trigger)

		print "----- Show expression: " + expression + " (" + str(intensity)[:5] + ") for " + str(duration)[:4] + " seconds"
		self.blackboard["show_expression_since"] = time.time()
	def sad(self):
		# Create the message
		exp = EmotionState()
		exp.name = 'sad'
		exp.magnitude = 1.0
		exp.duration.secs = 5
		exp.duration.nsecs = 250*1000000
		self.emotion_pub.publish(exp)
		print "Just published: ", exp.name
	def expression(self, name, intensity, duration):
		# Create the message
		exp = EmotionState()
		exp.name = name
		exp.magnitude = intensity
		exp.duration.secs = int(duration)
		exp.duration.nsecs = 1000000000 * (duration - int(duration))
		self.emotion_pub.publish(exp)
		print "Publish expression: ", exp.name
示例#5
0
 def expression(self, name, intensity, duration):
     if 'noop' == name or (not self.control_mode & self.C_EXPRESSION):
         return
     # Create the message
     exp = EmotionState()
     exp.name = name
     exp.magnitude = intensity
     exp.duration.secs = int(duration)
     exp.duration.nsecs = 1000000000 * (duration - int(duration))
     self.expression_pub.publish(exp)
     print "Publish facial expression:", exp.name
	def expression(self, name, intensity, duration):
		if 'noop' == name or (not self.control_mode & self.C_EXPRESSION):
			return
		# Create the message
		exp = EmotionState()
		exp.name = name
		exp.magnitude = intensity
		exp.duration.secs = int(duration)
		exp.duration.nsecs = 1000000000 * (duration - int(duration))
		self.emotion_pub.publish(exp)
		print "Publish expression:", exp.name
 def expression(self, name, intensity, duration):
     if 'noop' == name:
         return
     # Create the message
     exp = EmotionState()
     exp.name = name
     exp.magnitude = intensity
     exp.duration.secs = int(duration)
     exp.duration.nsecs = 1000000000 * (duration - int(duration))
     self.emotion_pub.publish(exp)
     print "Publish expression:", exp.name
示例#8
0
    def update_head_position(self, event):
        rospy.logdebug(' '.join([
            '%s: %.3f' % (EMOTIONS[n], STATES[n])
            for n in xrange(len(EMOTIONS))
        ]))

        for i, emo in enumerate(EMOTIONS):
            expression = EmotionState()
            expression.name = EXPRESSIONS[i]
            expression.magnitude = STATES[i]
            if expression.magnitude > 0.005:
                self.expressions_pub.publish(expression)
示例#9
0
    def update_robot_emotions_cb(self, event):
        with self.states_lock:
            rospy.logdebug(' '.join([
                '%s: %.3f' % (Mirroring.PERSON_EMOTIONS[n], self.states[n])
                for n in xrange(len(Mirroring.PERSON_EMOTIONS))
            ]))

            for i, emo in enumerate(Mirroring.PERSON_EMOTIONS):
                expression = EmotionState()
                expression.name = Mirroring.ROBOT_EMOTIONS[i]
                expression.magnitude = self.states[i]
                if expression.magnitude > 0.005:
                    self.emotion_pub.publish(expression)
示例#10
0
	def show_emotion(self, expression, intensity, duration):

		# Update the blackboard
		self.blackboard["current_emotion"] = expression
		self.blackboard["current_emotion_intensity"] = intensity
		self.blackboard["current_emotion_duration"] = duration

		# Create the message
		exp = EmotionState()
		exp.name = self.blackboard["current_emotion"]
		exp.magnitude = self.blackboard["current_emotion_intensity"]
		intsecs = int(duration)
		exp.duration.secs = intsecs
		exp.duration.nsecs = 1000000000 * (duration - intsecs)
		self.emotion_pub.publish(exp)

		print "----- Show expression: " + expression + " (" + str(intensity)[:5] + ") for " + str(duration)[:4] + " seconds"
		self.blackboard["show_expression_since"] = time.time()
示例#11
0
    def emote(self, name, magnitude, duration, blend):
        """ Set the robot's emotional state

        :param str name: the id of the emotion
        :param float magnitude: the magnitude of the emotion from 0.0 to 1.0
        :param float duration: the time in seconds that the emotion lasts for
        :param bool blend: blend the emotion with other emotions that also have blend=True. If an emotion is sent with
                           blend=False, then it will overwrite all previously sent and active blendable emotions.
        :return: None
        """
        msg = EmotionState()
        msg.name = name
        msg.magnitude = magnitude
        msg.duration.secs = int(duration)
        msg.duration.nsecs = 1000000000 * (duration - int(duration))

        if blend:
            self.emotion_value_pub.publish(msg)
        else:
            self.emotion_state_pub.publish(msg)
        rospy.logdebug("published emote(name={}, magnitude={}, duration={})".format(name, magnitude, duration))
示例#12
0
	def chatbot_affect_perceive_callback(self, emo):

		rospy.loginfo('chatbot perceived emo class ='+emo.data)
		# for now pass through to blender using random positive or non_positive class
		# in future we want more cognitive / behavior
		# pick random emotions may not do anything depending on random number so add force optional arg
		force=True

		if emo.data == 'happy':
			chosen_emo=self.pick_random_expression("positive_emotions",force)
		else:
			chosen_emo=self.pick_random_expression("frustrated_emotions",force)
		# publish this message to cause chatbot to emit response if it's waiting
		#

		exp = EmotionState()
		#  getting from blackboard seems to be inconsistent with expected state
		exp.name = self.blackboard["current_emotion"]
		exp.magnitude = 0.5
		# use zero for duration, tts can compute if needed
		exp.duration.secs = 3.0
		exp.duration.nsecs = 0
		self.affect_pub.publish(exp)
		rospy.loginfo('picked and expressed '+chosen_emo.name)
def emotion(emo, magnitude=1, duration=1):
    msg = EmotionState()
    msg.name = emo
    msg.magnitude = magnitude
    msg.duration = rospy.Duration.from_sec(duration)
    emotions_pub.publish(msg)