def test_music(self):
        goal = MusicGoal()  # create a instance for action goal
        goal.freqs = [100, 200, 300, 400, 0]  #set the frequency
        goal.durations = [1, 2, 3, 2, 1]  #set the duration

        self.client.wait_for_server()  #wait for server
        self.client.send_goal(goal, feedback_cb=self.feedback_cb)
        #send goal, 2nd item is callback function to catch the feedback
        self.client.wait_for_result()

        self.assertTrue(self.client.get_result(), "Invalid result")
        self.assertEqual(
            goal.freqs, self.device_values, "Invalid feedback:" +
            ",".join([str(e) for e in self.device_values]))

        ##preemotion##
        self.device_values = []  #empty device values
        self.client.send_goal(goal, feedback_cb=self.feedback_cb)
        #send the goal to preempt

        self.client.wait_for_result(rospy.Duration.from_sec(0.5))

        self.assertFalse(self.client.get_result(),
                         "stop is requested but return true")
        self.assertFalse(goal.freqs == self.device_values, "not stopped")
    def test_music(self):
        ### skip this test because a problem of this test code ###
        return
        goal = MusicGoal()
        goal.freqs = [100, 200, 300, 0]
        goal.durations = [2, 2, 2, 2]

        self.client.wait_for_server()
        self.client.send_goal(goal, feedback_cb=self.feedback_cb)
        self.client.wait_for_result()

        self.assertTrue(self.client.get_result(), "invalid result")
        self.assertEqual(
            goal.freqs, self.device_values, "invalid feedback:" +
            ",".join([str(e) for e in self.device_values]))

        ###preemption###
        self.device_values = []
        self.client.send_goal(goal, feedback_cb=self.feedback_cb)
        self.client.wait_for_result(rospy.Duration.from_sec(0.5))

        self.assertFalse(self.client.get_result(),
                         "stop is requested but return true")
        self.assertFalse(goal.freqs == self.device_values, "not stopped")

        def feedback_cb(self, feedback):
            with open("/dev/rtbuzzer0", "r") as f:
                data = f.readline()
                self.device_values.append(int(data.rstrip()))
    def test_music(self):
        goal = MusicGoal()
        goal.freqs = [100, 200, 300, 0]
        goal.durations = [2, 2, 2, 2]

        # normal test
        self.device_values = []
        self.client.wait_for_server()  # wait server wake up
        self.client.send_goal(goal, feedback_cb=self.feedback_cb)
        self.client.wait_for_result()  # wait server execute result

        self.assertTrue(self.client.get_result(), "invalid result")
        # self.assertEqual(goal.freqs, self.device_values, "invalid feedback:" + ",".join([str(e) for e in self.device_values]))

        #preempt test
        self.device_values = []
        # self.client.wait_for_server() # dont need to wait server wake up
        self.client.send_goal(goal, feedback_cb=self.feedback_cb)
        self.client.wait_for_result(
            rospy.Duration.from_sec(0.5))  # wait server execute result

        self.assertFalse(self.client.get_result(),
                         "preemption is requested but result is not correct")
        self.assertFalse(
            goal.freqs == self.device_values,
            "preemption is requested but request freq execute all")
示例#4
0
	def test_music(self):
		goal = MusicGoal()
		goal.freqs = [100, 200, 300, 0]
		goal.durations = [2,2,2,2]

		self.client.wait_for_server()
		self.client.send_goal(goal,feedback_cb=self.feedback_cb)
		self.client.wait_for_result()

		self.assertTrue(self.client.get_result(),"invalid feedback:"
			+ ",".join([str(e) for e in self.device_values]))

		self.device_values = []
		self.client.send_goal(goal,feedback_cb=self.feedback_cb)
		self.client.wait_for_result(rospy.Duration.from_sec(0.5))

		self.assertFalse(self.client.get_result(),"stop is requested but return true")
		self.assertFalse(goal.freqs == self.device_values,"not stopped")
示例#5
0
    def test_music(self):
        goal = MusicGoal()
        goal.freqs = [100, 200, 300, 0]
        goal.durations = [2,2,2,2]

        self.client.wait_for_server()
        self.client.send_goal(goal,feedback_cb=self.feedback_cb)
        self.client.wait_for_result()

        self.assertTrue(self.client.get_result(),"Wrong Result")
        self.assertEqual(goal.freqs,self.device_values,"Wrong feedback:"
                             + ",".join([str(e) for e in self.device_values]))

        ###preemption###
        self.device_values = []
        self.client.send_goal(goal, feedback_cb=self.feedback_cb)
        self.client.wait_for_result(rospy.Duration.from_sec(0.5))

        self.assertFalse(self.client.get_result(), "stopping operation is required but return TRUE")
        self.assertFalse(goal.freqs == self.device_values, "did not stop")