def test_launch_and_terminate_gazebo(self):
     random_seed = 123
     config = {
         'random_seed': random_seed,
         'gazebo': 'true',
         'world_name': 'cube_world',
         'output_path': self.output_dir
     }
     ros_process = RosWrapper(launch_file='load_ros.launch',
                              config=config,
                              visible=False)
     self.assertEqual(ros_process.get_state(), ProcessState.Running)
     time.sleep(5)
     self.assertGreaterEqual(count_grep_name('gzserver'), 1)
     ros_process.terminate()
     self.assertEqual(count_grep_name('gzserver'), 0)
Beispiel #2
0
class TestRos(unittest.TestCase):
    """
    Basic test that validates position, depth, camera sensors are updated
    """
    def setUp(self) -> None:
        self.output_dir = f'{get_data_dir(os.environ["CODEDIR"])}/test_dir/{get_filename_without_extension(__file__)}'
        os.makedirs(self.output_dir, exist_ok=True)
        config = {
            'random_seed': 123,
            'gazebo': 'true',
            'world_name': 'empty',
            'robot_name': 'drone_sim',
            'output_path': self.output_dir
        }
        self.ros_process = RosWrapper(launch_file='load_ros.launch',
                                      config=config,
                                      visible=False)
        subscribe_topics = [
            TopicConfig(
                topic_name=rospy.get_param(f'/robot/{sensor}_sensor/topic'),
                msg_type=rospy.get_param(f'/robot/{sensor}_sensor/type'))
            for sensor in ['camera', 'position', 'depth']
        ]
        self.ros_topic = TestPublisherSubscriber(
            subscribe_topics=subscribe_topics, publish_topics=[])
        self._unpause_client = rospy.ServiceProxy('/gazebo/unpause_physics',
                                                  Emptyservice)

    def test_drone_sim(self):
        self.assertEqual(self.ros_process.get_state(), ProcessState.Running)
        self._unpause_client.wait_for_service()
        self._unpause_client(EmptyRequest())
        time.sleep(2)
        for sensor in [
                'camera', 'position', 'depth'
        ]:  # collision < wrench, only published when turned upside down
            self.assertTrue(
                rospy.get_param(f'/robot/{sensor}_sensor/topic') in
                self.ros_topic.topic_values.keys())

    def tearDown(self) -> None:
        self.ros_process.terminate()
        shutil.rmtree(self.output_dir, ignore_errors=True)
 def test_launch_and_terminate_ros(self):
     ros_process = RosWrapper(launch_file='empty_ros.launch',
                              config={'output_path': self.output_dir})
     self.assertEqual(ros_process.get_state(), ProcessState.Running)
     self.assertTrue(count_grep_name('ros') > 0)
     ros_process.terminate()