Пример #1
0
def test_launch_description_add_things():
    """Test adding things to the LaunchDescription class."""
    ld = LaunchDescription()
    assert len(ld.entities) == 0
    ld.add_entity(LaunchDescription())
    assert len(ld.entities) == 1
    ld.add_action(Action())
    assert len(ld.entities) == 2
Пример #2
0
def generate_launch_description():
    talker = Node(package='jvr_basic', executable='talker')
    listener = Node(package='jvr_basic', executable='listener')

    launcher = LaunchDescription()

    launcher.add_entity(talker)
    launcher.add_entity(listener)

    return launcher
def generate_launch_description():
    ld = LaunchDescription()

    arg = DeclareLaunchArgument("bagfile")

    # this is a bad way to get the launch file
    bag_file = sys.argv[-1]
    bag_process = ExecuteProcess(
        cmd=['ros2', 'bag', 'play', launch.substitutions.LaunchConfiguration("bagfile")]
    )

    ekf_node = Node(
        package="robot_projects_ekf_localization",
        executable="ekf_localization",
        output={"both": "screen"},
        parameters=[
            {'filter_type':'ekf'}
        ]
    )

    vis_node = Node(
        package="rviz2",
        executable="rviz2",
        arguments=["-d", os.path.join(get_package_share_directory("robot_projects_ekf_localization"), "config", "ekf_sim_world.rviz")],
        output={"both": "screen"}
    )

    # get params file for eval node
    parameters_file_name = "ekf_evaluate_params.yaml"
    parameters_file_path = str(pathlib.Path(__file__).parents[1]) # get current path and go one level up
    parameters_file_path += '/config/' + parameters_file_name
    print(parameters_file_path)
    eval_node = Node(
        package="robot_projects_ekf_localization",
        executable="ekf_evaluation",
        parameters=[
            parameters_file_path
        ]
    )

    ld.add_action(ekf_node)
    ld.add_action(eval_node)
    ld.add_action(bag_process)
    ld.add_entity(vis_node)
    ld.add_entity(arg)

    return ld
def generate_launch_description():
    """Launch file for gritsbot in Gazebo."""
    # Get input arguments
    input_args = get_args()

    pos_y = '1.45'
    neg_y = '-1.45'
    def_z = '0.91'
    x_val = [
        0.3 * -1, 0.3 * -2, 0.3 * -3, 0.3 * -4, 0.3 * -5, 0.3 * 0.0, 0.3 * 1,
        0.3 * 2, 0.3 * 3, 0.3 * 4, 0.3 * 5
    ]

    # use_sim_time = LaunchConfiguration('use_sim_time', default='true')

    worlds_file_path = os.path.join(
        get_package_share_directory('robotarium_gazebo'), 'worlds',
        'robotarium/robotarium.world')
    rclpy.logging.get_logger('Launch File').info(worlds_file_path)

    sdf_file_path = os.path.join(
        get_package_share_directory('robotarium_gazebo'), 'models',
        'gritsbotx/model.sdf')
    rclpy.logging.get_logger('Launch File').info(sdf_file_path)

    experiment_launch_description = LaunchDescription([
        ExecuteProcess(cmd=[
            'gazebo', '--verbose', worlds_file_path, '-s',
            'libgazebo_ros_factory.so'
        ],
                       output='screen'),
    ])

    for i in range(11):
        experiment_launch_description.add_entity(
            Node(
                package='robotarium_bringup',
                executable='spawn_gritsbotx',
                name='test_spawn',
                output='screen',
                namespace='',
                arguments=[
                    f'robot_{i}',  # Name
                    f'gb_{i}',  # Namespace
                    str(x_val[i]),  # X
                    pos_y,  # Y
                    def_z,  # Z
                    '0',  # Roll
                    '0',  # Pitch
                    '-1.57',  # Yaw
                ]))

    for i in range(11):
        experiment_launch_description.add_entity(
            Node(
                package='robotarium_bringup',
                executable='spawn_gritsbotx',
                name='test_spawn',
                output='screen',
                namespace='',
                arguments=[
                    f'robot_{i + 11}',  # Name
                    f'gb_{i + 11}',  # Namespace
                    str(x_val[i]),  # X
                    neg_y,  # Y
                    def_z,  # Z
                    '0',  # Roll
                    '0',  # Pitch
                    '1.57',  # Yaw
                ]))

    return experiment_launch_description
Пример #5
0
class TestStdoutReadyListener(unittest.TestCase):
    def setUp(self):
        # Set up a launch description for the tests to use
        node_env = os.environ.copy()
        node_env["PYTHONUNBUFFERED"] = "1"

        self.launch_description = LaunchDescription([
            Node(package='apex_rostest',
                 node_executable='terminating_node',
                 env=node_env)
        ])

    def test_wait_for_ready(self):
        data = []

        self.launch_description.add_entity(
            RegisterEventHandler(
                StdoutReadyListener(
                    node_name="terminating_node",
                    ready_txt="Ready",
                    actions=[
                        OpaqueFunction(
                            function=lambda context: data.append('ok'))
                    ])))

        launch_service = LaunchService()
        launch_service.include_launch_description(self.launch_description)
        launch_service.run()

        # If the StdoutReadyListener worked, we should see 'ok' in the data
        self.assertIn('ok', data)

    def test_wait_for_wrong_process(self):
        data = []

        self.launch_description.add_entity(
            RegisterEventHandler(
                StdoutReadyListener(
                    node_name="different_node",
                    ready_txt="Ready",
                    actions=[
                        OpaqueFunction(
                            function=lambda context: data.append('ok'))
                    ])))

        launch_service = LaunchService()
        launch_service.include_launch_description(self.launch_description)
        launch_service.run()

        # We should not get confused by output from another node
        self.assertNotIn('ok', data)

    def test_wait_for_wrong_message(self):
        data = []

        self.launch_description.add_entity(
            RegisterEventHandler(
                StdoutReadyListener(
                    node_name="different_node",
                    ready_txt="not_ready",
                    actions=[
                        OpaqueFunction(
                            function=lambda context: data.append('ok'))
                    ])))

        launch_service = LaunchService()
        launch_service.include_launch_description(self.launch_description)
        launch_service.run()

        # We should not get confused by output that doesn't match the ready_txt
        self.assertNotIn('ok', data)