def sendMsg(self, snd, cmd, s, arg2="", vol=1.0, prior = 1, **kwargs): """ Internal method that publishes the sound request, either directly as a SoundRequest to the soundplay_node or through the actionlib interface (which blocks until the sound has finished playing). The blocking behavior is nominally the class-wide setting unless it has been explicitly specified in the play call. """ # Use the passed-in argument if it exists, otherwise fall back to the # class-wide setting. blocking = kwargs.get('blocking', self._blocking) msg = SoundRequest() msg.sound = snd # Threshold volume between 0 and 1. msg.volume = max(0, min(1, vol)) msg.command = cmd msg.arg = s msg.arg2 = arg2 msg.priority = prior rospy.logdebug('Sending sound request with volume = {}' ' and blocking = {}'.format(msg.volume, blocking)) # Defensive check for the existence of the correct communicator. if not blocking and not self.pub: rospy.logerr('Publisher for SoundRequest must exist') return if blocking and not self.actionclient: rospy.logerr('Action client for SoundRequest does not exist.') return if not blocking: # Publish message directly and return immediately self.pub.publish(msg) if self.pub.get_num_connections() < 1: rospy.logwarn("Sound command issued, but no node is subscribed" " to the topic. Perhaps you forgot to run" " soundplay_node.py?") else: # Block until result comes back. assert self.actionclient, 'Actionclient must exist' rospy.logdebug('Sending action client sound request [blocking]') self.actionclient.wait_for_server() goal = SoundRequestGoal() goal.sound_request = msg self.actionclient.send_goal(goal) self.actionclient.wait_for_result() rospy.logdebug('sound request response received') return