$search
00001 #!/usr/bin/env python 00002 import roslib 00003 roslib.load_manifest('cob_hardware_test') 00004 00005 import sys 00006 import unittest 00007 import rospy 00008 import rostest 00009 import time 00010 from cob_hardware_test.srv import * 00011 from std_msgs.msg import String 00012 from simple_script_server import * 00013 from pr2_controllers_msgs.msg import * 00014 00015 def dialog_client(dialog_type, message): 00016 #dialog type: 0=confirm 1=question 00017 rospy.wait_for_service('dialog') 00018 try: 00019 dialog = rospy.ServiceProxy('dialog', Dialog) 00020 resp1 = dialog(dialog_type, message) 00021 return resp1.answer 00022 except rospy.ServiceException, e: 00023 print "Service call failed: %s" % e 00024 00025 class HardwareTest(unittest.TestCase): 00026 def __init__(self, *args): 00027 00028 super(HardwareTest, self).__init__(*args) 00029 rospy.init_node('test_hardware_test') 00030 torso_joint_states = [] 00031 self.message_received = False 00032 self.sss = simple_script_server() 00033 00034 def test_set_light(self): 00035 self.assertTrue(dialog_client(0, 'Watch out for the Light' )) 00036 self.change_light("red") 00037 rospy.sleep(3.0) 00038 self.change_light("green") 00039 rospy.sleep(3.0) 00040 self.change_light("blue") 00041 rospy.sleep(3.0) 00042 self.change_light("black") 00043 self.assertTrue(dialog_client(1, 'Did I light up in red, green and blue?')) 00044 00045 def change_light(self,color): 00046 handle_light = self.sss.set_light(color) 00047 self.assertEqual(handle_light.get_state(), 3) # state 3 equals errorcode 0 therefore the following will never be executed 00048 if handle_light.get_error_code() != 0: 00049 error_msg = 'Could not set lights' 00050 self.fail(error_msg + "; errorCode: " + str(handle_light.get_error_code())) 00051 00052 00053 if __name__ == '__main__': 00054 # Copied from hztest: A dirty hack to work around an apparent race condition at startup 00055 # that causes some hztests to fail. Most evident in the tests of 00056 # rosstage. 00057 time.sleep(0.75) 00058 try: 00059 rostest.run('rostest', 'test_hardware_test', HardwareTest, sys.argv) 00060 except KeyboardInterrupt, e: 00061 pass 00062 print "exiting"