예제 #1
0
    def test_cancel_all_goals(self):
        timer1 = TimerGoal()
        timer2 = TimerGoal()
        timer1.duration = 1.0
        timer2.duration = 1.0

        gh1 = self.client.send_goal(timer1)
        gh2 = self.client.send_goal(timer2)
        time.sleep(0.5)
        self.client.cancel_all_goals()
        time.sleep(0.5)

        self.assertEqual(GoalStatus.PREEMPTED, self.client.get_state(gh1))
        self.assertEqual(GoalStatus.PREEMPTED, self.client.get_state(gh2))
예제 #2
0
 def test_send_goal(self):
     timer = TimerGoal()
     timer.duration = 0.5
     gh1 = self.client.send_goal(timer)
     success = self.client.wait_for_result(
         gh1, timeout=rospy.Duration.from_sec(0.6))
     self.assertEqual(success, True)
예제 #3
0
 def test_feedback_callback(self):
     timer = TimerGoal()
     timer.duration = 1.0
     mock = Mock()
     gh1 = self.client.send_goal(timer, feedback_cb=mock)
     self.client.wait_for_result(gh1, timeout=rospy.Duration.from_sec(1.1))
     mock.assert_called_once_with(gh1, TimerFeedback(current_time=10))
예제 #4
0
 def test_active_callback(self):
     timer = TimerGoal()
     timer.duration = 0.5
     mock = Mock()
     gh1 = self.client.send_goal(timer, active_cb=mock)
     self.client.wait_for_result(gh1, timeout=rospy.Duration.from_sec(1.1))
     mock.assert_called_once_with(gh1)
예제 #5
0
 def test_done_callback(self):
     timer = TimerGoal()
     timer.duration = 0.5
     mock = Mock()
     gh1 = self.client.send_goal(timer, done_cb=mock)
     time.sleep(1.0)
     mock.assert_called_once_with(gh1)
예제 #6
0
 def test_get_action_handle(self):
     timer = TimerGoal()
     timer.duration = 1.0
     gh1 = self.client.send_goal(timer)
     time.sleep(0.5)
     action_handle = self.client.get_action_handle(gh1)
     self.assertEqual(isinstance(action_handle, ActionHandle), True)
예제 #7
0
    def test_send_two_goals_serial(self):
        # First goal
        timer1 = TimerGoal()
        timer1.duration = 0.5
        gh1 = self.client.send_goal(timer1)
        success1 = self.client.wait_for_result(
            gh1, timeout=rospy.Duration.from_sec(0.55))

        # Second goal
        timer2 = TimerGoal()
        timer2.duration = 0.5
        gh2 = self.client.send_goal(timer2)
        success2 = self.client.wait_for_result(
            gh2, timeout=rospy.Duration.from_sec(0.6))

        self.assertEqual(success1, True)
        self.assertEqual(success2, True)
예제 #8
0
    def test_get_result(self):
        timer = TimerGoal()
        timer.duration = 0.5
        gh1 = self.client.send_goal(timer)
        self.client.wait_for_result(gh1, timeout=rospy.Duration.from_sec(0.55))
        result = self.client.get_result(gh1)

        self.assertEqual(isinstance(result, TimerResult), True)
        self.assertEqual(result.success, True)
예제 #9
0
    def test_send_two_goals_parallel(self):
        timer1 = TimerGoal()
        timer2 = TimerGoal()
        timer1.duration = 1.0
        timer2.duration = 1.0

        start = time.time()
        # Send both goals
        gh1 = self.client.send_goal(timer1)
        gh2 = self.client.send_goal(timer2)
        result1 = self.client.wait_for_result(
            gh1, timeout=rospy.Duration.from_sec(1.1))
        result2 = self.client.wait_for_result(
            gh2, timeout=rospy.Duration.from_sec(1.1))
        end = time.time()
        duration = end - start

        self.assertEqual(result1, True)
        self.assertEqual(result2, True)
예제 #10
0
    def test_cancel_goals_at_and_before_time(self):
        before_time1 = TimerGoal()
        before_time2 = TimerGoal()
        before_time1.duration = 5.0
        before_time2.duration = 5.0
        gh1 = self.client.send_goal(before_time1)
        gh2 = self.client.send_goal(before_time2)
        cancel_time = rospy.Time().now()

        after_time_1 = TimerGoal()
        after_time_1.duration = 1.0
        gh3 = self.client.send_goal(after_time_1)
        time.sleep(0.5)
        self.client.cancel_goals_at_and_before_time(cancel_time)

        success = self.client.wait_for_result(
            gh3, timeout=rospy.Duration.from_sec(1.1))

        self.assertEqual(GoalStatus.PREEMPTED, self.client.get_state(gh1))
        self.assertEqual(GoalStatus.PREEMPTED, self.client.get_state(gh2))
        self.assertEqual(GoalStatus.SUCCEEDED, self.client.get_state(gh3))
        self.assertEqual(success, True)
예제 #11
0
    def test_cancel_goal(self):
        timer1 = TimerGoal()
        timer1.duration = 5.0

        gh1 = self.client.send_goal(timer1)
        pending = self.client.get_state(gh1)
        time.sleep(0.5)
        active = self.client.get_state(gh1)
        self.client.cancel_goal(gh1)
        time.sleep(0.5)
        preempted = self.client.get_state(gh1)

        self.assertEqual(GoalStatus.PENDING, pending)
        self.assertEqual(GoalStatus.ACTIVE, active)
        self.assertEqual(GoalStatus.PREEMPTED, preempted)
예제 #12
0
    def test_get_state(self):
        timer = TimerGoal()
        timer.duration = 1.0
        gh1 = self.client.send_goal(timer)
        pending = self.client.get_state(gh1)
        time.sleep(0.5)
        active = self.client.get_state(gh1)
        self.client.wait_for_result(gh1, timeout=rospy.Duration.from_sec(1.1))
        succeeded = self.client.get_state(gh1)

        # gh2 = self.client.send_goal(timer)
        # time.sleep(0.5)
        # self.client.cancel_goal(gh2)
        #preeempted = self.client.get_state(gh2)

        self.assertEqual(pending, GoalStatus.PENDING)
        self.assertEqual(active, GoalStatus.ACTIVE)
        self.assertEqual(succeeded, GoalStatus.SUCCEEDED)
예제 #13
0
 def test_is_tracking_goal(self):
     timer = TimerGoal()
     timer.duration = 0.1
     gh1 = self.client.send_goal(timer)
     tracking = self.client.is_tracking_goal(gh1)
     self.assertEqual(tracking, True)
예제 #14
0
 def test_get_goal_id(self):
     timer = TimerGoal()
     timer.duration = 0.1
     gh1 = self.client.send_goal(timer)
     goal_id = self.client.goal_id(gh1)
     self.assertIsNotNone(goal_id)