speak-test-action.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 from __future__ import print_function
4 
5 import unittest
6 
7 import rospy
8 from sound_play.msg import SoundRequest, SoundRequestAction, SoundRequestResult
9 
10 import actionlib
11 
12 PKG = 'pr2eus'
13 NAME = 'test_speack_action'
14 
15 class TestSpeakAction(unittest.TestCase):
16  _result = SoundRequestResult()
17 
18  speak_msg = []
19  speak_msg_jp = []
20 
21  def cb(self, msg):
22  rospy.logwarn("received speak_msg")
23  self.speak_msg.append(msg.sound_request)
24  self._as_en.set_succeeded(self._result)
25 
26  def cb_jp(self, msg):
27  rospy.logwarn("received speak_msg_jp")
28  self.speak_msg_jp.append(msg.sound_request)
29  self._as_jp.set_succeeded(self._result)
30 
31  def setUp(self):
32  rospy.init_node(NAME)
33  self._as_en = actionlib.SimpleActionServer('/robotsound', SoundRequestAction, execute_cb=self.cb, auto_start=False)
34  self._as_jp = actionlib.SimpleActionServer('/robotsound_jp', SoundRequestAction, execute_cb=self.cb_jp, auto_start=False)
35  self._as_en.start()
36  self._as_jp.start()
37 
38  def test_speak(self):
39  rospy.sleep(10)
40  rospy.logwarn("test speak")
41  rospy.logwarn(self.speak_msg)
42  rospy.logwarn(self.speak_msg_jp)
43  while self.speak_msg == []:
44  rospy.logwarn("waiting for speak_msg")
45  rospy.sleep(1)
46  rospy.logwarn("check speak_msg")
47  rospy.logwarn(self.speak_msg)
48  while self.speak_msg_jp == []:
49  rospy.logwarn("waiting for speak_msg_jp")
50  rospy.sleep(1)
51  rospy.logwarn("check speak_msg_jp")
52  rospy.logwarn(self.speak_msg_jp)
53  rospy.logwarn("test speak_msg + speak_msg_jp")
54  for msg in self.speak_msg + self.speak_msg_jp:
55  rospy.logwarn(msg)
56  self.assertTrue(msg.command == SoundRequest.PLAY_ONCE)
57  if hasattr(SoundRequest, 'volume'): # volume is added from 0.3.0 https://github.com/ros-drivers/audio_common/commit/da9623414f381642e52f59701c09928c72a54be7#diff-fe2d85580f1ccfed4e23a608df44a7f7
58  self.assertTrue(msg.volume > 0)
59  self.assertTrue((msg.sound == SoundRequest.SAY and len(msg.arg) > 0) or
60  (msg.sound == SoundRequest.PLAY_FILE and len(msg.arg) > 0) or
61  (msg.sound > 0))
62 
63 if __name__ == '__main__':
64  import rostest
65  rostest.rosrun(PKG, NAME, TestSpeakAction)


pr2eus
Author(s): Kei Okada
autogenerated on Fri Mar 5 2021 04:00:40