base_test.py
Go to the documentation of this file.
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 
00016 def dialog_client(dialog_type, message):
00017         #dialog type: 0=confirm 1=question
00018         rospy.wait_for_service('dialog')
00019         try:
00020                 dialog = rospy.ServiceProxy('dialog', Dialog)
00021                 resp1 = dialog(dialog_type, message)
00022                 return resp1.answer
00023         except rospy.ServiceException, e:
00024                 print "Service call failed: %s" % e
00025 
00026 class HardwareTest(unittest.TestCase):
00027         def __init__(self, *args):
00028 
00029                 super(HardwareTest, self).__init__(*args)
00030                 rospy.init_node('test_hardware_test')
00031                 torso_joint_states = []
00032                 self.message_received = False
00033                 self.sss = simple_script_server()
00034 
00035                 try:
00036                                 # move_
00037                                 if not rospy.has_param('~move_x'):
00038                                         self.fail('Parameter move_x does not exist on ROS Parameter Server')
00039                                 self.move_x = rospy.get_param('~move_x')
00040 
00041                                 if not rospy.has_param('~move_y'):
00042                                         self.fail('Parameter move_ does not exist on ROS Parameter Server')
00043                                 self.move_y = rospy.get_param('~move_y')
00044 
00045                                 if not rospy.has_param('~move_theta'):
00046                                         self.fail('Parameter move_ does not exist on ROS Parameter Server')
00047                                 self.move_theta = rospy.get_param('~move_theta')
00048 
00049                 except KeyError, e:
00050                                 self.fail('Parameters not set properly')
00051 
00052 
00053         def test_base(self):
00054                 self.sss.init("base")
00055                 self.assertTrue(dialog_client(0, 'Ready to move base?' ))
00056                 handle = self.sss.move_base_rel("base", [self.move_x, self.move_y, self.move_theta])
00057                 self.assertEqual(handle.get_state(), 3)
00058                 self.assertTrue(dialog_client(1, 'Did I move?'))
00059                 self.assertTrue(dialog_client(0, 'EM Pressed and Released? \n Ready to move my Base ?' ))
00060                 self.sss.recover("base")
00061                 handle = self.sss.move_base_rel("base", [self.move_x, self.move_y, self.move_theta])
00062 
00063                 
00064 
00065                 
00066 
00067 if __name__ == '__main__':
00068         # Copied from hztest: A dirty hack to work around an apparent race condition at startup
00069         # that causes some hztests to fail. Most evident in the tests of
00070         # rosstage.
00071         time.sleep(0.75)
00072         try:
00073                 rostest.run('rostest', 'test_hardware_test', HardwareTest, sys.argv)
00074         except KeyboardInterrupt, e:
00075                 pass
00076         print "exiting"


cob_hardware_test
Author(s): Florian Weisshardt
autogenerated on Mon Mar 17 2014 10:13:52