00001
00002 import roslib; roslib.load_manifest('cob_component_test')
00003 import sys
00004 import time
00005 import unittest
00006 import rospy
00007 import rostest
00008 import actionlib
00009 import time
00010
00011 from simple_script_server import *
00012 from geometry_msgs.msg import *
00013 from actionlib_msgs.msg import *
00014 from move_base_msgs import *
00015 from tf.transformations import *
00016
00017 NAME = 'cobbase_unit'
00018 class UnitTest(unittest.TestCase):
00019 def __init__(self, *args):
00020 super(UnitTest, self).__init__(*args)
00021 rospy.init_node(NAME)
00022 self.sss=simple_script_server()
00023
00024
00025 def test_unit(self):
00026
00027 try:
00028
00029 test_duration = float(rospy.get_param('~test_duration'))
00030
00031 x = float(rospy.get_param('~x_value'))
00032
00033 y = float(rospy.get_param('~y_value'))
00034
00035 theta = float(rospy.get_param('~theta_value'))
00036 except KeyError, e:
00037 self.fail('cobunit not initialized properly')
00038 print """
00039 X: %s
00040 Y: %s
00041 Theta: %s
00042 Test duration:%s"""%(x, y, theta, test_duration)
00043 self._test_base(x, y, theta, test_duration)
00044
00045 def _test_base(self, x, y, theta, test_duration):
00046 self.assert_(test_duration > 0.0, "bad parameter (test_duration)")
00047 rospy.sleep(5.0)
00048 self.sss.init("arm")
00049 self.sss.move("arm","folded")
00050
00051 client = actionlib.SimpleActionClient('/move_base',MoveBaseAction)
00052 client_goal = MoveBaseGoal()
00053 pose = PoseStamped()
00054 pose.header.stamp = rospy.Time.now()
00055 pose.header.frame_id = "/map"
00056 pose.pose.position.x = x
00057 pose.pose.position.y = y
00058 pose.pose.position.z = 0.0
00059 q = quaternion_from_euler(0, 0, theta)
00060 pose.pose.orientation.x = q[0]
00061 pose.pose.orientation.y = q[1]
00062 pose.pose.orientation.z = q[2]
00063 pose.pose.orientation.w = q[3]
00064 client_goal.target_pose = pose
00065 client.wait_for_server()
00066 client.send_goal(client_goal)
00067 while client.get_state() != 3:
00068 rospy.sleep(1.0)
00069 if client.get_state() == 0:
00070 client.send_goal(client_goal)
00071
00072 if __name__ == '__main__':
00073 try:
00074 rostest.run('rostest', NAME, UnitTest, sys.argv)
00075 except KeyboardInterrupt, e:
00076 pass
00077 print "exiting"
00078