Beispiel #1
0
class TestStatus(unittest.TestCase):

    def setUp(self):
        rospy.init_node('test_status')
        self.robot = Robot('robot_0', 1, 0.5, 1, 1, pi/2)
        self.robot1 = Robot('robot_1', 1, 0.5, 5, 5, pi/2)

        # Execute robots a few times to allow statuses to become existant.
        for i in range(0, 10):
            self.robot.execute()
            self.robot1.execute()
            time.sleep(0.1)

    def test_init(self):
        """Checks if status exists after initialising."""
        self.assertIsNotNone(self.robot.curr_robot_messages)
        self.assertIsNotNone(self.robot.curr_robot_messages[1])
        self.assertIsNotNone(self.robot.curr_robot_messages[1].robot_id)

    def test_robot_id(self):
        """Tests that the robots are publishing the correct id"""
        self.assertEquals(self.robot.curr_robot_messages[1].robot_id, 'robot_1')

    def test_position(self):
        """Tests whether the robots are publishing the correct position"""
        self.assertAlmostEqual(self.robot.curr_robot_messages[1].x, 5.0, places=2)

    def to_string(self):
        return "test movement"
Beispiel #2
0
class TestStatus(unittest.TestCase):
    def setUp(self):
        rospy.init_node('test_status')
        self.robot = Robot('robot_0', 1, 0.5, 1, 1, pi / 2)
        self.robot1 = Robot('robot_1', 1, 0.5, 5, 5, pi / 2)

        # Execute robots a few times to allow statuses to become existant.
        for i in range(0, 10):
            self.robot.execute()
            self.robot1.execute()
            time.sleep(0.1)

    def test_init(self):
        """Checks if status exists after initialising."""
        self.assertIsNotNone(self.robot.curr_robot_messages)
        self.assertIsNotNone(self.robot.curr_robot_messages[1])
        self.assertIsNotNone(self.robot.curr_robot_messages[1].robot_id)

    def test_robot_id(self):
        """Tests that the robots are publishing the correct id"""
        self.assertEquals(self.robot.curr_robot_messages[1].robot_id,
                          'robot_1')

    def test_position(self):
        """Tests whether the robots are publishing the correct position"""
        self.assertAlmostEqual(self.robot.curr_robot_messages[1].x,
                               5.0,
                               places=2)

    def to_string(self):
        return "test movement"
Beispiel #3
0
class TestRobot(unittest.TestCase):
    def setUp(self):
        rospy.init_node('test_robot')
        self.robot = Robot('robot_0', 1, 0.5, 1, 1, pi / 2)
        for i in range(0, 20):
            self.robot.execute()

    def test_init(self):
        """Checks if subscribed information has been received."""
        self.assertIsNot(self.robot.odometry, None)
        self.assertIsNot(self.robot.leftLaser, None)
        self.assertIsNot(self.robot.rightLaser, None)

    def test_forward(self):
        """Checks if forward sets the velocity to its top speed."""
        self.robot.forward()
        self.assertEqual(self.robot.velocity.linear.x, 1)

    def test_stop(self):
        """Checks if stop sets the linear and angular velocity to 0."""
        self.robot.forward()
        self.robot.start_rotate()
        self.robot.stop()

        self.assertEqual(self.robot.velocity.linear.x, 0)
        self.assertEqual(self.robot.velocity.angular.z, 0)

    def test_set_angular_velocity(self):
        """Checks if angular velocity is set to the specified value."""
        self.robot.set_angular_velocity(0.2)
        self.assertEqual(self.robot.velocity.angular.z, 0.2)

    def test_set_linear_velocity(self):
        """Checks if linear velocity is set to the specified value."""
        self.robot.set_linear_velocity(0.7)
        self.assertEqual(self.robot.velocity.linear.x, 0.7)

    def test_start_rotate(self):
        """Checks if angular velocity is set to angular_top_speed
        and rotation_executing is set to true."""
        self.robot.start_rotate()

        self.assertEqual(self.robot.velocity.angular.z, 0.5)
        self.assertTrue(self.robot.rotation_executing)

    def test_start_rotate_opposite(self):
        """Checks if angular velocity is set to angular_top_speed in the
        negative direction and rotation_executing is set to true."""
        self.robot.start_rotate_opposite()

        self.assertEqual(self.robot.velocity.angular.z, -0.5)
        self.assertTrue(self.robot.rotation_executing)

    def test_stop_rotate(self):
        """Checks to see if angular velocity is set to 0 and
        rotation_executing is set to false."""
        self.robot.stop_rotate()

        self.assertEqual(self.robot.velocity.angular.z, 0)
        self.assertFalse(self.robot.rotation_executing)
Beispiel #4
0
class TestRobot(unittest.TestCase):

    def setUp(self):
        rospy.init_node('test_robot')
        self.robot = Robot('robot_0', 1, 0.5, 1, 1, pi / 2)
        for i in range(0, 20):
            self.robot.execute()

    def test_init(self):
        """Checks if subscribed information has been received."""
        self.assertIsNot(self.robot.odometry, None)
        self.assertIsNot(self.robot.leftLaser, None)
        self.assertIsNot(self.robot.rightLaser, None)

    def test_forward(self):
        """Checks if forward sets the velocity to its top speed."""
        self.robot.forward()
        self.assertEqual(self.robot.velocity.linear.x, 1)

    def test_stop(self):
        """Checks if stop sets the linear and angular velocity to 0."""
        self.robot.forward()
        self.robot.start_rotate()
        self.robot.stop()

        self.assertEqual(self.robot.velocity.linear.x, 0)
        self.assertEqual(self.robot.velocity.angular.z, 0)

    def test_set_angular_velocity(self):
        """Checks if angular velocity is set to the specified value."""
        self.robot.set_angular_velocity(0.2)
        self.assertEqual(self.robot.velocity.angular.z, 0.2)

    def test_set_linear_velocity(self):
        """Checks if linear velocity is set to the specified value."""
        self.robot.set_linear_velocity(0.7)
        self.assertEqual(self.robot.velocity.linear.x, 0.7)

    def test_start_rotate(self):
        """Checks if angular velocity is set to angular_top_speed
        and rotation_executing is set to true."""
        self.robot.start_rotate()

        self.assertEqual(self.robot.velocity.angular.z, 0.5)
        self.assertTrue(self.robot.rotation_executing)

    def test_start_rotate_opposite(self):
        """Checks if angular velocity is set to angular_top_speed in the
        negative direction and rotation_executing is set to true."""
        self.robot.start_rotate_opposite()

        self.assertEqual(self.robot.velocity.angular.z, -0.5)
        self.assertTrue(self.robot.rotation_executing)

    def test_stop_rotate(self):
        """Checks to see if angular velocity is set to 0 and
        rotation_executing is set to false."""
        self.robot.stop_rotate()

        self.assertEqual(self.robot.velocity.angular.z, 0)
        self.assertFalse(self.robot.rotation_executing)