test_nlj_dummy.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 from __future__ import print_function
00004 
00005 import random
00006 import unittest
00007 
00008 import rospy
00009 import actionlib
00010 from lama_jockeys.msg import NavigateAction
00011 from lama_jockeys.msg import NavigateGoal
00012 from lama_jockeys.msg import LocalizeAction
00013 from lama_jockeys.msg import LocalizeGoal
00014 
00015 
00016 def navigateFeedbackCallback(feedback):
00017     # TODO: Add a test on feedback.current_state and other
00018     # "enum" in devel/share/lama_jockeys/msg/NavigateFeedback.msg
00019     # states = ['', 'TRAVERSING', 'INTERRUPTED']
00020     # rospy.loginfo('Navigation current state: ' +
00021     #               states[feedback.current_state])
00022     # rospy.loginfo('Time elapsed: {:.3f} s'.format(
00023     #     feedback.time_elapsed.to_sec()))
00024     # rospy.loginfo('Completion: {:.2f} %'.format(feedback.completion * 100))
00025     pass
00026 
00027 
00028 class TestNljdummy(unittest.TestCase):
00029     def test_nlj_dummy(self):
00030         navigate = actionlib.SimpleActionClient('navigating_jockey',
00031                                                 NavigateAction)
00032         navigate.wait_for_server()
00033         localize = actionlib.SimpleActionClient('localizing_jockey',
00034                                                 LocalizeAction)
00035         localize.wait_for_server()
00036 
00037         nav_goal = NavigateGoal()
00038         for i in range(2):
00039             loc_goal = LocalizeGoal()
00040             loc_goal.action = loc_goal.GET_VERTEX_DESCRIPTOR
00041             localize.send_goal_and_wait(loc_goal, rospy.Duration(0.1))
00042             loc_result = localize.get_result()
00043             self.assertIsNotNone(loc_result)
00044 
00045             loc_goal.action = loc_goal.GET_EDGES_DESCRIPTORS
00046             localize.send_goal_and_wait(loc_goal, rospy.Duration(0.5))
00047             loc_result = localize.get_result()
00048             self.assertIsNotNone(loc_result)
00049             self.assertIs(len(loc_result.descriptor_links), 4,
00050                           msg='expected 4 descriptor_links, got {}'.format(
00051                               len(loc_result.descriptor_links)))
00052 
00053             nav_goal.action = nav_goal.TRAVERSE
00054             random_descriptor = random.choice(loc_result.descriptor_links)
00055             nav_goal.descriptor_link = random_descriptor
00056             navigate.send_goal(nav_goal,
00057                                feedback_cb=navigateFeedbackCallback)
00058             navigate.wait_for_result(rospy.Duration.from_sec(5.0))
00059             nav_result = navigate.get_result()
00060             self.assertIsNotNone(nav_result)
00061             self.assertEqual(nav_result.final_state, nav_result.DONE,
00062                              msg='expected final_state DONE, got {}'.format(
00063                                  nav_result.final_state))
00064 
00065 if __name__ == '__main__':
00066     rospy.init_node('test_nlj_dummy')
00067 
00068     import rostest
00069     rostest.rosrun('nlj_dummy',
00070                    'test_nlj_dummy',
00071                    TestNljdummy)


nlj_dummy
Author(s): Gaël Ecorchard , Karel Košnar
autogenerated on Thu Jun 6 2019 22:02:12