├── .github └── workflows │ └── colcon-build.yml ├── .gitignore ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── autoware_reference_system ├── CMakeLists.txt ├── README.md ├── autoware_reference_system.dot ├── cmake │ ├── generate_report.cmake │ ├── generate_summary_report.cmake │ ├── generate_traces.cmake │ └── test_requirements.cmake ├── include │ └── autoware_reference_system │ │ ├── autoware_system_builder.hpp │ │ └── system │ │ ├── priority │ │ └── default.hpp │ │ └── timing │ │ ├── benchmark.hpp │ │ └── default.hpp ├── package.xml ├── scripts │ ├── benchmark_all.sh │ ├── benchmark_one.sh │ └── utils.sh ├── src │ └── ros2 │ │ ├── executor │ │ ├── autoware_default_multithreaded.cpp │ │ ├── autoware_default_singlethreaded.cpp │ │ ├── autoware_default_singlethreaded_picas_multi_executors.cpp │ │ ├── autoware_default_singlethreaded_picas_single_executor.cpp │ │ └── autoware_default_staticsinglethreaded.cpp │ │ └── number_cruncher_benchmark.cpp └── test │ ├── callback_duration.py │ ├── constants.py │ ├── dropped_messages.py │ ├── generate_callback_traces.py │ ├── generate_graph.sh │ ├── generate_reports.py │ ├── generate_std_traces.py │ ├── generate_summary_reports.py │ ├── memory_usage.py │ ├── std_latency.py │ ├── test_autoware_reference_system.cpp │ ├── test_platform.py │ ├── test_requirements.py │ ├── trace_utils.py │ └── utils.py ├── content └── img │ └── autoware_reference_system.svg ├── rclcpp ├── .gitignore ├── CHANGELOG.rst ├── CMakeLists.txt ├── Doxyfile ├── QUALITY_DECLARATION.md ├── README.md ├── doc │ ├── api_review_march_2020.md │ └── notes_on_statically_typed_parameters.md ├── include │ └── rclcpp │ │ ├── allocator │ │ ├── allocator_common.hpp │ │ └── allocator_deleter.hpp │ │ ├── any_executable.hpp │ │ ├── any_service_callback.hpp │ │ ├── any_subscription_callback.hpp │ │ ├── callback_group.hpp │ │ ├── cb_sched.hpp │ │ ├── client.hpp │ │ ├── clock.hpp │ │ ├── context.hpp │ │ ├── contexts │ │ └── default_context.hpp │ │ ├── create_client.hpp │ │ ├── create_generic_publisher.hpp │ │ ├── create_generic_subscription.hpp │ │ ├── create_publisher.hpp │ │ ├── create_service.hpp │ │ ├── create_subscription.hpp │ │ ├── create_timer.hpp │ │ ├── detail │ │ ├── README.md │ │ ├── mutex_two_priorities.hpp │ │ ├── qos_parameters.hpp │ │ ├── resolve_enable_topic_statistics.hpp │ │ ├── resolve_intra_process_buffer_type.hpp │ │ ├── resolve_use_intra_process.hpp │ │ ├── rmw_implementation_specific_payload.hpp │ │ ├── rmw_implementation_specific_publisher_payload.hpp │ │ ├── rmw_implementation_specific_subscription_payload.hpp │ │ ├── subscription_callback_type_helper.hpp │ │ └── utilities.hpp │ │ ├── duration.hpp │ │ ├── event.hpp │ │ ├── exceptions.hpp │ │ ├── exceptions │ │ └── exceptions.hpp │ │ ├── executor.hpp │ │ ├── executor_options.hpp │ │ ├── executors.hpp │ │ ├── executors │ │ ├── multi_threaded_executor.hpp │ │ ├── single_threaded_executor.hpp │ │ ├── static_executor_entities_collector.hpp │ │ └── static_single_threaded_executor.hpp │ │ ├── expand_topic_or_service_name.hpp │ │ ├── experimental │ │ ├── README.md │ │ ├── buffers │ │ │ ├── buffer_implementation_base.hpp │ │ │ ├── intra_process_buffer.hpp │ │ │ └── ring_buffer_implementation.hpp │ │ ├── create_intra_process_buffer.hpp │ │ ├── executable_list.hpp │ │ ├── intra_process_manager.hpp │ │ ├── subscription_intra_process.hpp │ │ └── subscription_intra_process_base.hpp │ │ ├── function_traits.hpp │ │ ├── future_return_code.hpp │ │ ├── generic_publisher.hpp │ │ ├── generic_subscription.hpp │ │ ├── graph_listener.hpp │ │ ├── guard_condition.hpp │ │ ├── init_options.hpp │ │ ├── intra_process_buffer_type.hpp │ │ ├── intra_process_setting.hpp │ │ ├── loaned_message.hpp │ │ ├── logger.hpp │ │ ├── macros.hpp │ │ ├── memory_strategies.hpp │ │ ├── memory_strategy.hpp │ │ ├── message_info.hpp │ │ ├── message_memory_strategy.hpp │ │ ├── network_flow_endpoint.hpp │ │ ├── node.hpp │ │ ├── node_impl.hpp │ │ ├── node_interfaces │ │ ├── node_base.hpp │ │ ├── node_base_interface.hpp │ │ ├── node_clock.hpp │ │ ├── node_clock_interface.hpp │ │ ├── node_graph.hpp │ │ ├── node_graph_interface.hpp │ │ ├── node_logging.hpp │ │ ├── node_logging_interface.hpp │ │ ├── node_parameters.hpp │ │ ├── node_parameters_interface.hpp │ │ ├── node_services.hpp │ │ ├── node_services_interface.hpp │ │ ├── node_time_source.hpp │ │ ├── node_time_source_interface.hpp │ │ ├── node_timers.hpp │ │ ├── node_timers_interface.hpp │ │ ├── node_topics.hpp │ │ ├── node_topics_interface.hpp │ │ ├── node_waitables.hpp │ │ └── node_waitables_interface.hpp │ │ ├── node_options.hpp │ │ ├── parameter.hpp │ │ ├── parameter_client.hpp │ │ ├── parameter_event_handler.hpp │ │ ├── parameter_events_filter.hpp │ │ ├── parameter_map.hpp │ │ ├── parameter_service.hpp │ │ ├── parameter_value.hpp │ │ ├── publisher.hpp │ │ ├── publisher_base.hpp │ │ ├── publisher_factory.hpp │ │ ├── publisher_options.hpp │ │ ├── qos.hpp │ │ ├── qos_event.hpp │ │ ├── qos_overriding_options.hpp │ │ ├── rate.hpp │ │ ├── rclcpp.hpp │ │ ├── scope_exit.hpp │ │ ├── serialization.hpp │ │ ├── serialized_message.hpp │ │ ├── service.hpp │ │ ├── strategies │ │ ├── allocator_memory_strategy.hpp │ │ └── message_pool_memory_strategy.hpp │ │ ├── subscription.hpp │ │ ├── subscription_base.hpp │ │ ├── subscription_factory.hpp │ │ ├── subscription_options.hpp │ │ ├── subscription_traits.hpp │ │ ├── subscription_wait_set_mask.hpp │ │ ├── time.hpp │ │ ├── time_source.hpp │ │ ├── timer.hpp │ │ ├── topic_statistics │ │ └── subscription_topic_statistics.hpp │ │ ├── topic_statistics_state.hpp │ │ ├── type_support_decl.hpp │ │ ├── typesupport_helpers.hpp │ │ ├── utilities.hpp │ │ ├── visibility_control.hpp │ │ ├── wait_for_message.hpp │ │ ├── wait_result.hpp │ │ ├── wait_result_kind.hpp │ │ ├── wait_set.hpp │ │ ├── wait_set_policies │ │ ├── detail │ │ │ ├── storage_policy_common.hpp │ │ │ ├── synchronization_policy_common.hpp │ │ │ └── write_preferring_read_write_lock.hpp │ │ ├── dynamic_storage.hpp │ │ ├── sequential_synchronization.hpp │ │ ├── static_storage.hpp │ │ └── thread_safe_synchronization.hpp │ │ ├── wait_set_template.hpp │ │ └── waitable.hpp ├── package.xml ├── resource │ ├── get_interface.hpp.em │ ├── interface_traits.hpp.em │ └── logging.hpp.em └── src │ └── rclcpp │ ├── any_executable.cpp │ ├── callback_group.cpp │ ├── client.cpp │ ├── clock.cpp │ ├── context.cpp │ ├── contexts │ └── default_context.cpp │ ├── detail │ ├── mutex_two_priorities.cpp │ ├── resolve_parameter_overrides.cpp │ ├── resolve_parameter_overrides.hpp │ ├── rmw_implementation_specific_payload.cpp │ ├── rmw_implementation_specific_publisher_payload.cpp │ ├── rmw_implementation_specific_subscription_payload.cpp │ └── utilities.cpp │ ├── duration.cpp │ ├── event.cpp │ ├── exceptions │ └── exceptions.cpp │ ├── executable_list.cpp │ ├── executor.cpp │ ├── executors.cpp │ ├── executors │ ├── multi_threaded_executor.cpp │ ├── single_threaded_executor.cpp │ ├── static_executor_entities_collector.cpp │ └── static_single_threaded_executor.cpp │ ├── expand_topic_or_service_name.cpp │ ├── future_return_code.cpp │ ├── generic_publisher.cpp │ ├── generic_subscription.cpp │ ├── graph_listener.cpp │ ├── guard_condition.cpp │ ├── init_options.cpp │ ├── intra_process_manager.cpp │ ├── logger.cpp │ ├── logging_mutex.cpp │ ├── logging_mutex.hpp │ ├── memory_strategies.cpp │ ├── memory_strategy.cpp │ ├── message_info.cpp │ ├── network_flow_endpoint.cpp │ ├── node.cpp │ ├── node_interfaces │ ├── node_base.cpp │ ├── node_clock.cpp │ ├── node_graph.cpp │ ├── node_logging.cpp │ ├── node_parameters.cpp │ ├── node_services.cpp │ ├── node_time_source.cpp │ ├── node_timers.cpp │ ├── node_topics.cpp │ └── node_waitables.cpp │ ├── node_options.cpp │ ├── parameter.cpp │ ├── parameter_client.cpp │ ├── parameter_event_handler.cpp │ ├── parameter_events_filter.cpp │ ├── parameter_map.cpp │ ├── parameter_service.cpp │ ├── parameter_service_names.hpp │ ├── parameter_value.cpp │ ├── publisher_base.cpp │ ├── qos.cpp │ ├── qos_event.cpp │ ├── qos_overriding_options.cpp │ ├── serialization.cpp │ ├── serialized_message.cpp │ ├── service.cpp │ ├── signal_handler.cpp │ ├── signal_handler.hpp │ ├── subscription_base.cpp │ ├── subscription_intra_process_base.cpp │ ├── time.cpp │ ├── time_source.cpp │ ├── timer.cpp │ ├── type_support.cpp │ ├── typesupport_helpers.cpp │ ├── utilities.cpp │ ├── wait_set_policies │ └── detail │ │ └── write_preferring_read_write_lock.cpp │ └── waitable.cpp ├── reference_interfaces ├── CMakeLists.txt ├── msg │ ├── Message4kb.idl │ └── TransmissionStats.idl └── package.xml └── reference_system ├── CMakeLists.txt ├── README.md ├── include └── reference_system │ ├── msg_types.hpp │ ├── nodes │ ├── rclcpp │ │ ├── command.hpp │ │ ├── cyclic.hpp │ │ ├── fusion.hpp │ │ ├── intersection.hpp │ │ ├── sensor.hpp │ │ └── transform.hpp │ └── settings.hpp │ ├── number_cruncher.hpp │ ├── sample_management.hpp │ └── system │ ├── systems.hpp │ └── type │ └── rclcpp_system.hpp └── package.xml /.github/workflows/colcon-build.yml: -------------------------------------------------------------------------------- 1 | # This is a basic workflow to help you get started with Actions 2 | 3 | name: CI 4 | 5 | # Controls when the workflow will run 6 | on: 7 | # Triggers the workflow on push or pull request events but only for the main branch 8 | push: 9 | branches: [ main ] 10 | pull_request: 11 | branches: [ main ] 12 | 13 | # Allows you to run this workflow manually from the Actions tab 14 | workflow_dispatch: 15 | 16 | # A workflow run is made up of one or more jobs that can run sequentially or in parallel 17 | jobs: 18 | # This workflow contains a single job called "build" 19 | build: 20 | # The type of runner that the job will run on 21 | runs-on: [ubuntu-latest] 22 | strategy: 23 | fail-fast: false 24 | matrix: 25 | ros_distribution: 26 | - foxy 27 | - galactic 28 | - rolling 29 | include: 30 | # Foxy Fitzroy (June 2020 - May 2023) 31 | - ros_distribution: foxy 32 | docker_image: rostooling/setup-ros-docker:ubuntu-focal-ros-foxy-ros-base-latest 33 | # Galactic Geochelone (May 2021 - November 2022) 34 | - ros_distribution: galactic 35 | docker_image: rostooling/setup-ros-docker:ubuntu-focal-ros-galactic-ros-base-latest 36 | # Rolling Ridley (June 2020 - Present) 37 | - ros_distribution: rolling 38 | docker_image: rostooling/setup-ros-docker:ubuntu-focal-ros-rolling-ros-base-latest 39 | container: 40 | image: ${{ matrix.docker_image }} 41 | # Steps represent a sequence of tasks that will be executed as part of the job 42 | steps: 43 | - name: setup workspace 44 | run: mkdir -p ros2_ws/src 45 | - name: checkout 46 | uses: actions/checkout@v2 47 | with: 48 | path: ros2_ws/src 49 | - name: build and test 50 | uses: ros-tooling/action-ros-ci@v0.2 51 | with: 52 | package-name: autoware_reference_system 53 | target-ros2-distro: ${{ matrix.ros_distribution }} 54 | vcs-repo-file-url: "" 55 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | **__pycache__ 2 | .vscode/ 3 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | Any contribution that you make to this repository will 2 | be under the Apache 2 License, as dictated by that 3 | [license](http://www.apache.org/licenses/LICENSE-2.0.html): 4 | 5 | ~~~ 6 | 5. Submission of Contributions. Unless You explicitly state otherwise, 7 | any Contribution intentionally submitted for inclusion in the Work 8 | by You to the Licensor shall be under the terms and conditions of 9 | this License, without any additional terms or conditions. 10 | Notwithstanding the above, nothing herein shall supersede or modify 11 | the terms of any separate license agreement you may have executed 12 | with Licensor regarding such Contributions. 13 | ~~~ 14 | -------------------------------------------------------------------------------- /autoware_reference_system/cmake/generate_report.cmake: -------------------------------------------------------------------------------- 1 | # Copyright 2021 Apex.AI, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # generate report from traces 16 | function(generate_report target trace_type runtime) 17 | if(${trace_type} MATCHES "memory") 18 | set(TRACE_DIR "${ROS_HOME}/${trace_type}/${target}_${rmw_implementation}_${runtime}s.txt") 19 | add_test( 20 | NAME generate_${trace_type}_report_${target}_${rmw_implementation}_${runtime}s 21 | COMMAND bash -c "python3 ${CMAKE_INSTALL_PREFIX}/share/${PROJECT_NAME}/test/generate_reports.py ${TRACE_DIR}" 22 | COMMENT "Generate CPU and Memory Usage report from psrecord data" 23 | ) 24 | set_tests_properties(generate_${trace_type}_report_${target}_${rmw_implementation}_${runtime}s 25 | PROPERTIES TIMEOUT ${DEFAULT_TIMEOUT}) 26 | elseif(${trace_type} MATCHES "std") 27 | add_test( 28 | NAME generate_${trace_type}_report_${target}_${rmw_implementation}_${runtime}s 29 | COMMAND bash -c "python3 ${CMAKE_INSTALL_PREFIX}/share/${PROJECT_NAME}/test/generate_reports.py ${ROS_LOG_DIR}" 30 | COMMENT "Generate Latency and Dropped Message reports from the std print log files" 31 | ) 32 | else() 33 | set(TRACE_DIR "${ROS_HOME}/tracing/${trace_type}_${target}_${rmw_implementation}_${runtime}s") 34 | # future note: this will fail on windows 35 | add_test( 36 | NAME convert_${trace_type}_trace_${target}_${rmw_implementation}_${runtime}s 37 | COMMAND bash -c "ros2 run tracetools_analysis convert ${TRACE_DIR}" 38 | ) 39 | set_tests_properties(convert_${trace_type}_trace_${target}_${rmw_implementation}_${runtime}s 40 | PROPERTIES TIMEOUT ${DEFAULT_TIMEOUT}) 41 | add_test( 42 | NAME process_${trace_type}_trace_${target}_${rmw_implementation}_${runtime}s 43 | COMMAND bash -c "ros2 run tracetools_analysis process ${TRACE_DIR}" 44 | ) 45 | set_tests_properties(process_${trace_type}_trace_${target}_${rmw_implementation}_${runtime}s 46 | PROPERTIES TIMEOUT ${DEFAULT_TIMEOUT}) 47 | add_test( 48 | NAME generate_${trace_type}_report_${target}_${rmw_implementation}_${runtime}s 49 | COMMAND bash -c "python3 ${CMAKE_INSTALL_PREFIX}/share/${PROJECT_NAME}/test/generate_reports.py ${TRACE_DIR}" 50 | COMMENT "Process converted traces to create data model" 51 | ) 52 | set_tests_properties(generate_${trace_type}_report_${target}_${rmw_implementation}_${runtime}s 53 | PROPERTIES TIMEOUT ${DEFAULT_TIMEOUT}) 54 | endif() 55 | endfunction() -------------------------------------------------------------------------------- /autoware_reference_system/cmake/generate_summary_report.cmake: -------------------------------------------------------------------------------- 1 | # Copyright 2021 Apex.AI, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # generate summary report from all trace data 16 | function(generate_summary_report trace_type run_time) 17 | if(${trace_type} MATCHES "memory") 18 | set(TRACE_DIR "${ROS_HOME}/${trace_type}") 19 | elseif(${trace_type} MATCHES "std") 20 | set(TRACE_DIR "${ROS_LOG_DIR}") 21 | else() 22 | set(TRACE_DIR "${ROS_HOME}/tracing") 23 | endif() 24 | 25 | add_test( 26 | NAME generate_summary_report_${trace_type}_${run_time}s 27 | COMMAND bash -c "python3 ${CMAKE_INSTALL_PREFIX}/share/${PROJECT_NAME}/test/generate_summary_reports.py ${TRACE_DIR} ${run_time}" 28 | COMMENT "Generate Summary Report" 29 | ) 30 | set_tests_properties(generate_summary_report_${trace_type}_${run_time}s 31 | PROPERTIES TIMEOUT ${DEFAULT_TIMEOUT}) 32 | endfunction() -------------------------------------------------------------------------------- /autoware_reference_system/cmake/generate_traces.cmake: -------------------------------------------------------------------------------- 1 | # Copyright 2021 Apex.AI, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # run target for n seconds 16 | function(generate_traces target trace_type runtime) 17 | set(TEST_EXECUTABLE ${target}) 18 | set(TEST_EXECUTABLE_NAME ${target}_${rmw_implementation}) 19 | set(TRACE_TYPE ${trace_type}) 20 | set(RUNTIME ${runtime}) 21 | set(RMW_IMPLEMENTATION ${rmw_implementation}) 22 | # ensure timeout is longer than the test runtime 23 | math(EXPR timeout "${runtime} + 5") 24 | if(${trace_type} MATCHES "memory") 25 | set(MEMRECORD_PATH "${CMAKE_INSTALL_PREFIX}/share/${PROJECT_NAME}/scripts/benchmark_one.sh") 26 | set(MEMRECORD_LOG "${ROS_HOME}/${trace_type}") 27 | set(MEMRECORD_LOG_NAME "${target}_${rmw_implementation}_${runtime}s.txt") 28 | set(MEMRECORD_EXE "$(ros2 pkg prefix ${PROJECT_NAME})/lib/${PROJECT_NAME}/${target}") 29 | # run psrecord script instead of ros2_tracing for memory usage plots 30 | add_test( 31 | NAME generate_${trace_type}_trace_${target}_${rmw_implementation}_${runtime}s 32 | COMMAND 33 | bash -c 34 | "chmod u+x ${MEMRECORD_PATH}; 35 | RMW_IMPLEMENTATION=${rmw_implementation} \ 36 | ${MEMRECORD_PATH} \ 37 | ${MEMRECORD_EXE} \ 38 | ${runtime} \ 39 | ${MEMRECORD_LOG} \ 40 | ${MEMRECORD_LOG_NAME}" 41 | ) 42 | set_tests_properties(generate_${trace_type}_trace_${target}_${rmw_implementation}_${runtime}s 43 | PROPERTIES TIMEOUT ${DEFAULT_TIMEOUT}) 44 | else() 45 | # callback and std trace types run ros_tests 46 | # replaces all @var@ and ${var} within input file 47 | configure_file( 48 | test/generate_${trace_type}_traces.py 49 | generate_${trace_type}_traces_${target}_${rmw_implementation}_${runtime}s.py 50 | @ONLY 51 | ) 52 | add_ros_test( 53 | ${CMAKE_CURRENT_BINARY_DIR}/generate_${trace_type}_traces_${target}_${rmw_implementation}_${runtime}s.py 54 | TIMEOUT ${timeout} # seconds 55 | ) 56 | endif() 57 | if(TARGET ${target}) 58 | ament_target_dependencies(${target} 59 | "rclcpp" "reference_interfaces" "reference_system") 60 | endif() 61 | endfunction() -------------------------------------------------------------------------------- /autoware_reference_system/cmake/test_requirements.cmake: -------------------------------------------------------------------------------- 1 | # Copyright 2021 Apex.AI, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # make sure executable matches system requirements 16 | function(test_requirements target) 17 | set(TEST_EXECUTABLE ${CMAKE_CURRENT_BINARY_DIR}/${target}) 18 | set(TEST_EXECUTABLE_NAME test_requirements_${target}) 19 | # replaces all @var@ and ${var} within input file 20 | configure_file( 21 | test/test_requirements.py 22 | test_requirements_${target}.py 23 | @ONLY 24 | ) 25 | add_ros_test( 26 | ${CMAKE_CURRENT_BINARY_DIR}/test_requirements_${target}.py 27 | TIMEOUT ${DEFAULT_TIMEOUT} # seconds 28 | ) 29 | if(TARGET ${target}) 30 | ament_target_dependencies(${target} 31 | "rclcpp" "reference_interfaces" "reference_system") 32 | endif() 33 | endfunction() -------------------------------------------------------------------------------- /autoware_reference_system/package.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | autoware_reference_system 5 | 0.1.1 6 | Autoware Reference System for the ROScon workshop 7 | Evan Flynn 8 | Apache License 2.0 9 | 10 | Christian Eltzschig 11 | 12 | ament_cmake 13 | ament_cmake_auto 14 | 15 | reference_system 16 | 17 | rclcpp 18 | reference_interfaces 19 | rcl_interfaces 20 | 21 | ament_cmake_pytest 22 | ament_cmake_gtest 23 | ament_lint_auto 24 | ament_lint_common 25 | ros_testing 26 | launch 27 | launch_ros 28 | tracetools_analysis 29 | tracetools_launch 30 | tracetools_trace 31 | python3-bokeh-pip 32 | python3-selenium 33 | 34 | 35 | ament_cmake 36 | 37 | 38 | -------------------------------------------------------------------------------- /autoware_reference_system/scripts/benchmark_all.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # arg1: duration to run test in seconds 3 | source $(dirname "$0")/utils.sh 4 | 5 | check_psrecord 6 | 7 | for FILE in $(find build/autoware_reference_system/ -maxdepth 1 -type f -executable); do 8 | generate_memory_data $FILE $1 9 | done 10 | -------------------------------------------------------------------------------- /autoware_reference_system/scripts/benchmark_one.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # arg1: duration to run test in seconds 3 | # arg2: name of target to test 4 | # arg3: path to store log data (directory only) 5 | # arg4: log filename (including filetype extension, e.g. .txt) 6 | source $(dirname "$0")/utils.sh 7 | 8 | check_psrecord 9 | 10 | generate_memory_data $1 $2 $3 $4 11 | -------------------------------------------------------------------------------- /autoware_reference_system/scripts/utils.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | function check_psrecord { 4 | if ! [ -x "$(command -v psrecord)" ]; then 5 | echo psrecord is not installed, please install it with pip install -U psrecord 6 | exit 1 7 | fi 8 | } 9 | 10 | function generate_memory_data { 11 | [ ! -d ${3} ] && mkdir -p ${3}/ 12 | full_log_name="${3}" 13 | [ ! "${full_log_name: -1}" == "/" ] && full_log_name+="/" 14 | full_log_name+="${4}" 15 | plot_name="${3}" 16 | plot_name="${4:-4}" 17 | plot_name+=".png" 18 | echo "Benchmarking: $1" 19 | echo "Duration: $2" 20 | echo "writing logs to: ${full_log_name}" 21 | psrecord $1 --include-children --log ${full_log_name} --plot ${plot_name} --duration $2 22 | killall $1 23 | } -------------------------------------------------------------------------------- /autoware_reference_system/src/ros2/executor/autoware_default_multithreaded.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Apex.AI, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "rclcpp/rclcpp.hpp" 16 | 17 | #include "reference_system/system/systems.hpp" 18 | 19 | #include "autoware_reference_system/autoware_system_builder.hpp" 20 | #include "autoware_reference_system/system/timing/benchmark.hpp" 21 | #include "autoware_reference_system/system/timing/default.hpp" 22 | 23 | int main(int argc, char * argv[]) 24 | { 25 | rclcpp::init(argc, argv); 26 | 27 | using TimeConfig = nodes::timing::Default; 28 | // uncomment for benchmarking 29 | // using TimeConfig = nodes::timing::BenchmarkCPUUsage; 30 | // set_benchmark_mode(true); 31 | 32 | auto nodes = create_autoware_nodes(); 33 | 34 | rclcpp::executors::MultiThreadedExecutor executor; 35 | for (auto & node : nodes) { 36 | executor.add_node(node); 37 | } 38 | executor.spin(); 39 | 40 | nodes.clear(); 41 | rclcpp::shutdown(); 42 | 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /autoware_reference_system/src/ros2/executor/autoware_default_singlethreaded.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Apex.AI, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "rclcpp/rclcpp.hpp" 16 | 17 | #include "reference_system/system/systems.hpp" 18 | 19 | #include "autoware_reference_system/autoware_system_builder.hpp" 20 | #include "autoware_reference_system/system/timing/benchmark.hpp" 21 | #include "autoware_reference_system/system/timing/default.hpp" 22 | 23 | int main(int argc, char * argv[]) 24 | { 25 | rclcpp::init(argc, argv); 26 | 27 | using TimeConfig = nodes::timing::Default; 28 | // uncomment for benchmarking 29 | // using TimeConfig = nodes::timing::BenchmarkCPUUsage; 30 | // set_benchmark_mode(true); 31 | 32 | auto nodes = create_autoware_nodes(); 33 | 34 | rclcpp::executors::SingleThreadedExecutor executor; 35 | for (auto & node : nodes) { 36 | executor.add_node(node); 37 | } 38 | executor.spin(); 39 | 40 | nodes.clear(); 41 | rclcpp::shutdown(); 42 | 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /autoware_reference_system/src/ros2/executor/autoware_default_singlethreaded_picas_single_executor.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Apex.AI, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "rclcpp/rclcpp.hpp" 16 | 17 | #include "reference_system/system/systems.hpp" 18 | 19 | #include "autoware_reference_system/autoware_system_builder.hpp" 20 | #include "autoware_reference_system/system/timing/benchmark.hpp" 21 | #include "autoware_reference_system/system/timing/default.hpp" 22 | 23 | int main(int argc, char * argv[]) 24 | { 25 | rclcpp::init(argc, argv); 26 | 27 | using TimeConfig = nodes::timing::Default; 28 | // uncomment for benchmarking 29 | //using TimeConfig = nodes::timing::BenchmarkCPUUsage; 30 | // set_benchmark_mode(true); 31 | 32 | auto nodes = create_autoware_nodes(); 33 | 34 | rclcpp::executors::SingleThreadedExecutor executor; 35 | 36 | executor.enable_callback_priority(); 37 | RCLCPP_INFO(rclcpp::get_logger("rclcpp"), "PiCAS priority-based callback scheduling: %s", executor.callback_priority_enabled ? "Enabled" : "Disabled"); 38 | 39 | executor.set_executor_priority_cpu(90, 0); 40 | RCLCPP_INFO(rclcpp::get_logger("rclcpp"), "PiCAS executor 1's rt-priority %d and CPU %d", executor.executor_priority, executor.executor_cpu); 41 | 42 | for (auto & node : nodes) { 43 | executor.add_node(node); 44 | } 45 | executor.spin_rt(); 46 | 47 | nodes.clear(); 48 | rclcpp::shutdown(); 49 | 50 | return 0; 51 | } 52 | 53 | -------------------------------------------------------------------------------- /autoware_reference_system/src/ros2/executor/autoware_default_staticsinglethreaded.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Apex.AI, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "rclcpp/rclcpp.hpp" 16 | 17 | #include "reference_system/system/systems.hpp" 18 | 19 | #include "autoware_reference_system/autoware_system_builder.hpp" 20 | #include "autoware_reference_system/system/timing/benchmark.hpp" 21 | #include "autoware_reference_system/system/timing/default.hpp" 22 | 23 | int main(int argc, char * argv[]) 24 | { 25 | rclcpp::init(argc, argv); 26 | 27 | using TimeConfig = nodes::timing::Default; 28 | // uncomment for benchmarking 29 | // using TimeConfig = nodes::timing::BenchmarkCPUUsage; 30 | // set_benchmark_mode(true); 31 | 32 | auto nodes = create_autoware_nodes(); 33 | 34 | rclcpp::executors::StaticSingleThreadedExecutor executor; 35 | for (auto & node : nodes) { 36 | executor.add_node(node); 37 | } 38 | executor.spin(); 39 | 40 | nodes.clear(); 41 | rclcpp::shutdown(); 42 | 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /autoware_reference_system/src/ros2/number_cruncher_benchmark.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Apex.AI, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | #include "reference_system/number_cruncher.hpp" 16 | 17 | #include 18 | #include 19 | 20 | long double get_crunch_time_in_ms(const uint64_t maximum_number) 21 | { 22 | auto start = std::chrono::system_clock::now(); 23 | number_cruncher(maximum_number); 24 | auto stop = std::chrono::system_clock::now(); 25 | return static_cast( 26 | std::chrono::nanoseconds(stop - start).count() / 1000000.0); 27 | } 28 | int main() 29 | { 30 | long double crunch_time = 0.0; 31 | std::cout << "maximum_number run time" << std::endl; 32 | for (uint64_t i = 64; crunch_time < 1000.0; i *= 2) { 33 | crunch_time = get_crunch_time_in_ms(i); 34 | std::cout << std::setfill(' ') << std::setw(12) << i << " " << 35 | crunch_time << "ms" << std::endl; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /autoware_reference_system/test/constants.py: -------------------------------------------------------------------------------- 1 | # Copyright 2021 Apex.AI, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | TRACE_CALLBACK = 'tracing' 16 | TRACE_MEMORY = 'memory' 17 | TRACE_STD = 'log' 18 | TRACE_UNSUPPORTED = 'unsupported' 19 | # TODO(flynneva): support path as just the `tracing` directory and loop over 20 | # all subdirectories that have tracing data in them 21 | TRACE_DIRECTORY = 'tracing' 22 | 23 | SIZE_SUMMARY = 800 24 | SIZE_SUBPLOT = 500 25 | -------------------------------------------------------------------------------- /autoware_reference_system/test/generate_graph.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if ! [ -x "$(command -v psrecord)" ] 4 | then 5 | echo Please install psrecord and make it available via the PATH variable. 6 | echo \# pip install psrecord 7 | echo \# export PATH=\${PATH}:\${HOME}/.local/bin/ 8 | exit -1 9 | fi 10 | 11 | psrecord "ros2 run reference_system_autoware $1" --log $2 --plot $3 --duration $4 -------------------------------------------------------------------------------- /autoware_reference_system/test/generate_std_traces.py: -------------------------------------------------------------------------------- 1 | # Copyright 2021 Apex.AI, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | import time 15 | import unittest 16 | 17 | from launch import LaunchDescription 18 | from launch.actions import SetEnvironmentVariable 19 | from launch_ros.actions import Node 20 | 21 | import launch_testing 22 | import launch_testing.actions 23 | 24 | # Generate traces for specified executables and RMWs 25 | 26 | # this file has @variables@ that are meant to be automatically replaced 27 | # by values using the `configure_file` CMake function during the build 28 | RUNTIME = int('@RUNTIME@') 29 | 30 | 31 | def generate_test_description(): 32 | # replaced with cmake `configure_file` function 33 | rmw_impl = '@RMW_IMPLEMENTATION@' 34 | test_exe = '@TEST_EXECUTABLE@' 35 | test_exe_name = '@TEST_EXECUTABLE_NAME@' 36 | trace_type = '@TRACE_TYPE@' 37 | 38 | launch_description = LaunchDescription() 39 | 40 | # see https://github.com/ros2/launch/issues/417 41 | # have to use `SetEnvironmentVariable` to set env vars in launch description 42 | envvar_rcutils_action = SetEnvironmentVariable( 43 | 'RCUTILS_CONSOLE_OUTPUT_FORMAT', '[{severity}] [{name}]: {message}') 44 | envvar_rmw_action = SetEnvironmentVariable( 45 | 'RMW_IMPLEMENTATION', rmw_impl) 46 | envvar_rclassert_rmw_action = SetEnvironmentVariable( 47 | 'RCL_ASSERT_RMW_ID_MATCHES', rmw_impl) 48 | 49 | node_under_test = Node( 50 | package='autoware_reference_system', 51 | executable=test_exe, 52 | output='screen' 53 | ) 54 | 55 | launch_description.add_action(envvar_rcutils_action) 56 | launch_description.add_action(envvar_rclassert_rmw_action) 57 | launch_description.add_action(envvar_rmw_action) 58 | launch_description.add_action(node_under_test) 59 | launch_description.add_action( 60 | launch_testing.actions.ReadyToTest() 61 | ) 62 | return launch_description, locals() 63 | 64 | 65 | class TestGenerateTracesAutowareReferenceSystem(unittest.TestCase): 66 | 67 | def test_generate_traces(self): 68 | global RUNTIME 69 | start_time = time.time() 70 | end_time = start_time + RUNTIME 71 | 72 | while time.time() < end_time: 73 | print('generating traces...') 74 | time.sleep(0.25) # seconds 75 | 76 | self.assertTrue(True) 77 | -------------------------------------------------------------------------------- /autoware_reference_system/test/test_autoware_reference_system.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Apex.AI, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "gtest/gtest.h" 16 | 17 | TEST(TestReferenceSystemAutoware, DummyTest) { 18 | EXPECT_EQ(1, 1); 19 | } 20 | -------------------------------------------------------------------------------- /autoware_reference_system/test/test_platform.py: -------------------------------------------------------------------------------- 1 | # Copyright 2021 Apex.AI, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | import multiprocessing 16 | import platform 17 | 18 | # this file has @variables@ that are meant to be automatically replaced 19 | # by values using the `configure_file` CMake function during the build 20 | 21 | platforms = {} 22 | 23 | # TODO(flynneva): move this to its own file for portability 24 | # can add more supported platforms here 25 | platforms['rpi4-linux-rt'] = { 26 | 'common-name': 'raspberrypi4', 27 | 'machine': 'aarch64', 28 | 'processor': 'aarch64', 29 | 'system': 'Linux', 30 | 'flavor': 'ubuntu', 31 | 'cores': 4, 32 | 'realtime': True 33 | } 34 | 35 | 36 | def test_platform(): 37 | # get current system information 38 | system, node, release, version, machine, processor = platform.uname() 39 | platform_supported = False 40 | for pform in platforms: 41 | if(platforms[pform]['system'] == system): 42 | if(platforms[pform]['processor'] == processor): 43 | platform_supported = True 44 | assert multiprocessing.cpu_count() == platforms[pform]['cores'] 45 | if(platforms[pform]['realtime']): 46 | assert version.find('PREEMPT_RT') != -1 47 | if platform_supported: 48 | print('platform supported') 49 | assert True 50 | else: 51 | print('platform unsupported') 52 | assert False 53 | -------------------------------------------------------------------------------- /autoware_reference_system/test/trace_utils.py: -------------------------------------------------------------------------------- 1 | # Copyright 2021 Apex.AI, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | from tracetools_analysis.loading import load_file 15 | from tracetools_analysis.processor.ros2 import Ros2Handler 16 | from tracetools_analysis.utils.ros2 import Ros2DataModelUtil 17 | 18 | 19 | def initDataModel(path): 20 | events = load_file(path) 21 | handler = Ros2Handler.process(events) 22 | # handler.data.print_data() 23 | 24 | return Ros2DataModelUtil(handler.data) 25 | -------------------------------------------------------------------------------- /autoware_reference_system/test/utils.py: -------------------------------------------------------------------------------- 1 | # Copyright 2021 Apex.AI, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | import os 16 | import sys 17 | 18 | from constants import TRACE_CALLBACK, TRACE_MEMORY, TRACE_STD, TRACE_UNSUPPORTED 19 | 20 | 21 | def checkPath(path: str): 22 | # make sure directory exists 23 | if not os.path.isdir(path): 24 | # make sure given path isnt a file 25 | if not os.path.isfile(path): 26 | print('Given path does not exist: ' + path) 27 | sys.exit() 28 | # make sure path ends in a `/` 29 | if (path[-1] != '/'): 30 | if not (path.find('.txt') >= 0): 31 | path += '/' 32 | return path 33 | 34 | 35 | def getTraceType(path): 36 | # check if given path is a callback trace 37 | if path.find(TRACE_CALLBACK) >= 0: 38 | return TRACE_CALLBACK 39 | elif path.find(TRACE_MEMORY) >= 0: 40 | return TRACE_MEMORY 41 | elif path.find(TRACE_STD) >= 0: 42 | return TRACE_STD 43 | else: 44 | return TRACE_UNSUPPORTED 45 | 46 | 47 | def getPWD(path): 48 | return os.path.basename(os.path.normpath(path)) 49 | 50 | 51 | def getDirPath(path): 52 | # given path is a filename, remove filename but keep rest of path 53 | return os.path.dirname(path) + '/' 54 | 55 | 56 | def getFileName(path): 57 | return os.path.splitext(os.path.basename(path))[0] 58 | -------------------------------------------------------------------------------- /rclcpp/.gitignore: -------------------------------------------------------------------------------- 1 | doc_output 2 | -------------------------------------------------------------------------------- /rclcpp/Doxyfile: -------------------------------------------------------------------------------- 1 | # All settings not listed here will use the Doxygen default values. 2 | 3 | PROJECT_NAME = "rclcpp" 4 | PROJECT_NUMBER = master 5 | PROJECT_BRIEF = "C++ ROS Client Library API" 6 | 7 | # Use these lines to include the generated logging.hpp (update install path if needed) 8 | #INPUT = ../../../../install_isolated/rclcpp/include 9 | #STRIP_FROM_PATH = /Users/william/ros2_ws/install_isolated/rclcpp/include 10 | # Otherwise just generate for the local (non-generated header files) 11 | INPUT = ./include 12 | 13 | RECURSIVE = YES 14 | OUTPUT_DIRECTORY = doc_output 15 | 16 | EXTRACT_ALL = YES 17 | SORT_MEMBER_DOCS = NO 18 | 19 | GENERATE_LATEX = NO 20 | 21 | ENABLE_PREPROCESSING = YES 22 | MACRO_EXPANSION = YES 23 | EXPAND_ONLY_PREDEF = YES 24 | PREDEFINED = RCLCPP_PUBLIC= 25 | 26 | # Tag files that do not exist will produce a warning and cross-project linking will not work. 27 | TAGFILES += "../../../../doxygen_tag_files/cppreference-doxygen-web.tag.xml=http://en.cppreference.com/w/" 28 | # Consider changing "latest" to the version you want to reference (e.g. beta1 or 1.0.0) 29 | TAGFILES += "../../../../doxygen_tag_files/rcl.tag=http://docs.ros2.org/latest/api/rcl/" 30 | TAGFILES += "../../../../doxygen_tag_files/rmw.tag=http://docs.ros2.org/latest/api/rmw/" 31 | TAGFILES += "../../../../doxygen_tag_files/rcutils.tag=http://docs.ros2.org/latest/api/rcutils/" 32 | # Uncomment to generate tag files for cross-project linking. 33 | #GENERATE_TAGFILE = "../../../../doxygen_tag_files/rclcpp.tag" 34 | -------------------------------------------------------------------------------- /rclcpp/README.md: -------------------------------------------------------------------------------- 1 | # `rclcpp` 2 | 3 | The ROS client library in C++. 4 | 5 | Visit the [rclcpp API documentation](http://docs.ros2.org/latest/api/rclcpp/) for a complete list of its main components and features. 6 | 7 | ## Quality Declaration 8 | 9 | This package claims to be in the **Quality Level 1** category, see the [Quality Declaration](QUALITY_DECLARATION.md) for more details. 10 | -------------------------------------------------------------------------------- /rclcpp/include/rclcpp/any_executable.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2015 Open Source Robotics Foundation, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef RCLCPP__ANY_EXECUTABLE_HPP_ 16 | #define RCLCPP__ANY_EXECUTABLE_HPP_ 17 | 18 | #include 19 | 20 | #include "rclcpp/callback_group.hpp" 21 | #include "rclcpp/client.hpp" 22 | #include "rclcpp/macros.hpp" 23 | #include "rclcpp/node_interfaces/node_base_interface.hpp" 24 | #include "rclcpp/service.hpp" 25 | #include "rclcpp/subscription.hpp" 26 | #include "rclcpp/timer.hpp" 27 | #include "rclcpp/visibility_control.hpp" 28 | #include "rclcpp/waitable.hpp" 29 | 30 | namespace rclcpp 31 | { 32 | 33 | struct AnyExecutable 34 | { 35 | RCLCPP_PUBLIC 36 | AnyExecutable(); 37 | 38 | RCLCPP_PUBLIC 39 | virtual ~AnyExecutable(); 40 | 41 | // Only one of the following pointers will be set. 42 | rclcpp::SubscriptionBase::SharedPtr subscription; 43 | rclcpp::TimerBase::SharedPtr timer; 44 | rclcpp::ServiceBase::SharedPtr service; 45 | rclcpp::ClientBase::SharedPtr client; 46 | rclcpp::Waitable::SharedPtr waitable; 47 | // These are used to keep the scope on the containing items 48 | rclcpp::CallbackGroup::SharedPtr callback_group; 49 | rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_base; 50 | std::shared_ptr data; 51 | }; 52 | 53 | } // namespace rclcpp 54 | 55 | #endif // RCLCPP__ANY_EXECUTABLE_HPP_ 56 | -------------------------------------------------------------------------------- /rclcpp/include/rclcpp/cb_sched.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RCLCPP__CB_SCHED_HPP_ 2 | #define RCLCPP__CB_SCHED_HPP_ 3 | 4 | //#define PICAS_DEBUG // comment this out for non-debug mode 5 | 6 | #ifdef PICAS_DEBUG 7 | #include 8 | #include 9 | #include 10 | 11 | static inline void print_stacktrace() // from https://panthema.net/ 12 | { 13 | RCLCPP_INFO(rclcpp::get_logger("stack"), "trace start"); 14 | 15 | // storage array for stack trace address data 16 | void* addrlist[20]; 17 | 18 | // retrieve current stack addresses 19 | int addrlen = backtrace(addrlist, sizeof(addrlist) / sizeof(void*)); 20 | 21 | if (addrlen == 0) { 22 | RCLCPP_INFO(rclcpp::get_logger("stack"), ""); 23 | return; 24 | } 25 | 26 | // resolve addresses into strings containing "filename(function+address)", 27 | // this array must be free()-ed 28 | char** symbollist = backtrace_symbols(addrlist, addrlen); 29 | 30 | // allocate string which will be filled with the demangled function name 31 | size_t funcnamesize = 256; 32 | char* funcname = (char*)malloc(funcnamesize); 33 | 34 | // iterate over the returned symbol lines. skip the first, it is the 35 | // address of this function. 36 | for (int i = 1; i < addrlen; i++) 37 | { 38 | char *begin_name = 0, *begin_offset = 0, *end_offset = 0; 39 | 40 | // find parentheses and +address offset surrounding the mangled name: 41 | // ./module(function+0x15c) [0x8048a6d] 42 | for (char *p = symbollist[i]; *p; ++p) 43 | { 44 | if (*p == '(') 45 | begin_name = p; 46 | else if (*p == '+') 47 | begin_offset = p; 48 | else if (*p == ')' && begin_offset) { 49 | end_offset = p; 50 | break; 51 | } 52 | } 53 | 54 | if (begin_name && begin_offset && end_offset 55 | && begin_name < begin_offset) 56 | { 57 | *begin_name++ = '\0'; 58 | *begin_offset++ = '\0'; 59 | *end_offset = '\0'; 60 | 61 | // mangled name is now in [begin_name, begin_offset) and caller 62 | // offset in [begin_offset, end_offset). now apply 63 | // __cxa_demangle(): 64 | 65 | int status; 66 | char* ret = abi::__cxa_demangle(begin_name, funcname, &funcnamesize, &status); 67 | if (status == 0) { 68 | funcname = ret; // use possibly realloc()-ed string 69 | RCLCPP_INFO(rclcpp::get_logger("stack"), " %s : %s+%s", symbollist[i], funcname, begin_offset); 70 | } 71 | else { 72 | // demangling failed. Output function name as a C function with 73 | // no arguments. 74 | RCLCPP_INFO(rclcpp::get_logger("stack"), " %s : %s()+%s", symbollist[i], begin_name, begin_offset); 75 | } 76 | } 77 | else 78 | { 79 | // couldn't parse the line? print the whole line. 80 | RCLCPP_INFO(rclcpp::get_logger("stack"), " %s", symbollist[i]); 81 | } 82 | } 83 | free(funcname); 84 | free(symbollist); 85 | } 86 | 87 | #endif 88 | 89 | #endif 90 | -------------------------------------------------------------------------------- /rclcpp/include/rclcpp/contexts/default_context.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2014 Open Source Robotics Foundation, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef RCLCPP__CONTEXTS__DEFAULT_CONTEXT_HPP_ 16 | #define RCLCPP__CONTEXTS__DEFAULT_CONTEXT_HPP_ 17 | 18 | #include "rclcpp/context.hpp" 19 | #include "rclcpp/visibility_control.hpp" 20 | 21 | namespace rclcpp 22 | { 23 | namespace contexts 24 | { 25 | 26 | class DefaultContext : public rclcpp::Context 27 | { 28 | public: 29 | RCLCPP_SMART_PTR_DEFINITIONS(DefaultContext) 30 | 31 | RCLCPP_PUBLIC 32 | DefaultContext(); 33 | }; 34 | 35 | RCLCPP_PUBLIC 36 | DefaultContext::SharedPtr 37 | get_global_default_context(); 38 | 39 | } // namespace contexts 40 | } // namespace rclcpp 41 | 42 | #endif // RCLCPP__CONTEXTS__DEFAULT_CONTEXT_HPP_ 43 | -------------------------------------------------------------------------------- /rclcpp/include/rclcpp/create_client.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2019 Open Source Robotics Foundation, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef RCLCPP__CREATE_CLIENT_HPP_ 16 | #define RCLCPP__CREATE_CLIENT_HPP_ 17 | 18 | #include 19 | #include 20 | 21 | #include "rclcpp/node_interfaces/node_base_interface.hpp" 22 | #include "rclcpp/node_interfaces/node_services_interface.hpp" 23 | #include "rmw/rmw.h" 24 | 25 | namespace rclcpp 26 | { 27 | 28 | /// Create a service client with a given type. 29 | /// \internal 30 | template 31 | typename rclcpp::Client::SharedPtr 32 | create_client( 33 | std::shared_ptr node_base, 34 | std::shared_ptr node_graph, 35 | std::shared_ptr node_services, 36 | const std::string & service_name, 37 | const rmw_qos_profile_t & qos_profile, 38 | rclcpp::CallbackGroup::SharedPtr group) 39 | { 40 | rcl_client_options_t options = rcl_client_get_default_options(); 41 | options.qos = qos_profile; 42 | 43 | auto cli = rclcpp::Client::make_shared( 44 | node_base.get(), 45 | node_graph, 46 | service_name, 47 | options); 48 | 49 | auto cli_base_ptr = std::dynamic_pointer_cast(cli); 50 | node_services->add_client(cli_base_ptr, group); 51 | return cli; 52 | } 53 | 54 | } // namespace rclcpp 55 | 56 | #endif // RCLCPP__CREATE_CLIENT_HPP_ 57 | -------------------------------------------------------------------------------- /rclcpp/include/rclcpp/create_generic_publisher.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2020, Apex.AI Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef RCLCPP__CREATE_GENERIC_PUBLISHER_HPP_ 16 | #define RCLCPP__CREATE_GENERIC_PUBLISHER_HPP_ 17 | 18 | #include 19 | #include 20 | #include 21 | 22 | #include "rclcpp/generic_publisher.hpp" 23 | #include "rclcpp/node_interfaces/node_topics_interface.hpp" 24 | #include "rclcpp/publisher_options.hpp" 25 | #include "rclcpp/qos.hpp" 26 | #include "rclcpp/typesupport_helpers.hpp" 27 | 28 | namespace rclcpp 29 | { 30 | 31 | /// Create and return a GenericPublisher. 32 | /** 33 | * The returned pointer will never be empty, but this function can throw various exceptions, for 34 | * instance when the message's package can not be found on the AMENT_PREFIX_PATH. 35 | * 36 | * \param topics_interface NodeTopicsInterface pointer used in parts of the setup 37 | * \param topic_name Topic name 38 | * \param topic_type Topic type 39 | * \param qos %QoS settings 40 | * \param options %Publisher options. 41 | * Not all publisher options are currently respected, the only relevant options for this 42 | * publisher are `event_callbacks`, `use_default_callbacks`, and `%callback_group`. 43 | */ 44 | template> 45 | std::shared_ptr create_generic_publisher( 46 | rclcpp::node_interfaces::NodeTopicsInterface::SharedPtr topics_interface, 47 | const std::string & topic_name, 48 | const std::string & topic_type, 49 | const rclcpp::QoS & qos, 50 | const rclcpp::PublisherOptionsWithAllocator & options = ( 51 | rclcpp::PublisherOptionsWithAllocator() 52 | ) 53 | ) 54 | { 55 | auto ts_lib = rclcpp::get_typesupport_library(topic_type, "rosidl_typesupport_cpp"); 56 | auto pub = std::make_shared( 57 | topics_interface->get_node_base_interface(), 58 | std::move(ts_lib), 59 | topic_name, 60 | topic_type, 61 | qos, 62 | options); 63 | topics_interface->add_publisher(pub, options.callback_group); 64 | return pub; 65 | } 66 | 67 | } // namespace rclcpp 68 | 69 | #endif // RCLCPP__CREATE_GENERIC_PUBLISHER_HPP_ 70 | -------------------------------------------------------------------------------- /rclcpp/include/rclcpp/create_service.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Open Source Robotics Foundation, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef RCLCPP__CREATE_SERVICE_HPP_ 16 | #define RCLCPP__CREATE_SERVICE_HPP_ 17 | 18 | #include 19 | #include 20 | #include 21 | 22 | #include "rclcpp/node_interfaces/node_base_interface.hpp" 23 | #include "rclcpp/node_interfaces/node_services_interface.hpp" 24 | #include "rclcpp/visibility_control.hpp" 25 | #include "rmw/rmw.h" 26 | 27 | namespace rclcpp 28 | { 29 | 30 | /// Create a service with a given type. 31 | /// \internal 32 | template 33 | typename rclcpp::Service::SharedPtr 34 | create_service( 35 | std::shared_ptr node_base, 36 | std::shared_ptr node_services, 37 | const std::string & service_name, 38 | CallbackT && callback, 39 | const rmw_qos_profile_t & qos_profile, 40 | rclcpp::CallbackGroup::SharedPtr group) 41 | { 42 | rclcpp::AnyServiceCallback any_service_callback; 43 | any_service_callback.set(std::forward(callback)); 44 | 45 | rcl_service_options_t service_options = rcl_service_get_default_options(); 46 | service_options.qos = qos_profile; 47 | 48 | auto serv = Service::make_shared( 49 | node_base->get_shared_rcl_node_handle(), 50 | service_name, any_service_callback, service_options); 51 | auto serv_base_ptr = std::dynamic_pointer_cast(serv); 52 | node_services->add_service(serv_base_ptr, group); 53 | return serv; 54 | } 55 | 56 | } // namespace rclcpp 57 | 58 | #endif // RCLCPP__CREATE_SERVICE_HPP_ 59 | -------------------------------------------------------------------------------- /rclcpp/include/rclcpp/detail/README.md: -------------------------------------------------------------------------------- 1 | Notice that headers in this folder should only provide symbols in the rclcpp::detail namespace. 2 | 3 | Also that these headers are not considered part of the public API and are subject to change without notice. 4 | -------------------------------------------------------------------------------- /rclcpp/include/rclcpp/detail/mutex_two_priorities.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Open Source Robotics Foundation, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef RCLCPP__DETAIL__MUTEX_TWO_PRIORITIES_HPP_ 16 | #define RCLCPP__DETAIL__MUTEX_TWO_PRIORITIES_HPP_ 17 | 18 | #include 19 | #include 20 | 21 | namespace rclcpp 22 | { 23 | namespace detail 24 | { 25 | /// \internal A mutex that has two locking mechanism, one with higher priority than the other. 26 | /** 27 | * After the current mutex owner release the lock, a thread that used the high 28 | * priority mechanism will have priority over threads that used the low priority mechanism. 29 | */ 30 | class MutexTwoPriorities 31 | { 32 | public: 33 | class HighPriorityLockable 34 | { 35 | public: 36 | explicit HighPriorityLockable(MutexTwoPriorities & parent); 37 | 38 | void lock(); 39 | 40 | void unlock(); 41 | 42 | private: 43 | MutexTwoPriorities & parent_; 44 | }; 45 | 46 | class LowPriorityLockable 47 | { 48 | public: 49 | explicit LowPriorityLockable(MutexTwoPriorities & parent); 50 | 51 | void lock(); 52 | 53 | void unlock(); 54 | 55 | private: 56 | MutexTwoPriorities & parent_; 57 | }; 58 | 59 | HighPriorityLockable 60 | get_high_priority_lockable(); 61 | 62 | LowPriorityLockable 63 | get_low_priority_lockable(); 64 | 65 | private: 66 | std::condition_variable hp_cv_; 67 | std::condition_variable lp_cv_; 68 | std::mutex cv_mutex_; 69 | size_t hp_waiting_count_{0u}; 70 | bool data_taken_{false}; 71 | }; 72 | 73 | } // namespace detail 74 | } // namespace rclcpp 75 | 76 | #endif // RCLCPP__DETAIL__MUTEX_TWO_PRIORITIES_HPP_ 77 | -------------------------------------------------------------------------------- /rclcpp/include/rclcpp/detail/resolve_enable_topic_statistics.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef RCLCPP__DETAIL__RESOLVE_ENABLE_TOPIC_STATISTICS_HPP_ 16 | #define RCLCPP__DETAIL__RESOLVE_ENABLE_TOPIC_STATISTICS_HPP_ 17 | 18 | #include 19 | 20 | #include "rclcpp/topic_statistics_state.hpp" 21 | 22 | namespace rclcpp 23 | { 24 | namespace detail 25 | { 26 | 27 | /// Return whether or not topic statistics is enabled, resolving "NodeDefault" if needed. 28 | template 29 | bool 30 | resolve_enable_topic_statistics(const OptionsT & options, const NodeBaseT & node_base) 31 | { 32 | bool topic_stats_enabled; 33 | switch (options.topic_stats_options.state) { 34 | case TopicStatisticsState::Enable: 35 | topic_stats_enabled = true; 36 | break; 37 | case TopicStatisticsState::Disable: 38 | topic_stats_enabled = false; 39 | break; 40 | case TopicStatisticsState::NodeDefault: 41 | topic_stats_enabled = node_base.get_enable_topic_statistics_default(); 42 | break; 43 | default: 44 | throw std::runtime_error("Unrecognized EnableTopicStatistics value"); 45 | } 46 | 47 | return topic_stats_enabled; 48 | } 49 | 50 | } // namespace detail 51 | } // namespace rclcpp 52 | 53 | #endif // RCLCPP__DETAIL__RESOLVE_ENABLE_TOPIC_STATISTICS_HPP_ 54 | -------------------------------------------------------------------------------- /rclcpp/include/rclcpp/detail/resolve_intra_process_buffer_type.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2019 Open Source Robotics Foundation, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef RCLCPP__DETAIL__RESOLVE_INTRA_PROCESS_BUFFER_TYPE_HPP_ 16 | #define RCLCPP__DETAIL__RESOLVE_INTRA_PROCESS_BUFFER_TYPE_HPP_ 17 | 18 | #include 19 | 20 | #include "rclcpp/any_subscription_callback.hpp" 21 | #include "rclcpp/intra_process_buffer_type.hpp" 22 | 23 | namespace rclcpp 24 | { 25 | 26 | namespace detail 27 | { 28 | 29 | /// Return the buffer type, resolving the "CallbackDefault" type to an actual type if needed. 30 | template 31 | rclcpp::IntraProcessBufferType 32 | resolve_intra_process_buffer_type( 33 | const rclcpp::IntraProcessBufferType buffer_type, 34 | const rclcpp::AnySubscriptionCallback & any_subscription_callback) 35 | { 36 | rclcpp::IntraProcessBufferType resolved_buffer_type = buffer_type; 37 | 38 | // If the user has not specified a type for the intra-process buffer, use the callback's type. 39 | if (resolved_buffer_type == IntraProcessBufferType::CallbackDefault) { 40 | if (any_subscription_callback.use_take_shared_method()) { 41 | resolved_buffer_type = IntraProcessBufferType::SharedPtr; 42 | } else { 43 | resolved_buffer_type = IntraProcessBufferType::UniquePtr; 44 | } 45 | } 46 | 47 | return resolved_buffer_type; 48 | } 49 | 50 | } // namespace detail 51 | 52 | } // namespace rclcpp 53 | 54 | #endif // RCLCPP__DETAIL__RESOLVE_INTRA_PROCESS_BUFFER_TYPE_HPP_ 55 | -------------------------------------------------------------------------------- /rclcpp/include/rclcpp/detail/resolve_use_intra_process.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2019 Open Source Robotics Foundation, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef RCLCPP__DETAIL__RESOLVE_USE_INTRA_PROCESS_HPP_ 16 | #define RCLCPP__DETAIL__RESOLVE_USE_INTRA_PROCESS_HPP_ 17 | 18 | #include 19 | 20 | #include "rclcpp/intra_process_setting.hpp" 21 | 22 | namespace rclcpp 23 | { 24 | 25 | namespace detail 26 | { 27 | 28 | /// Return whether or not intra process is enabled, resolving "NodeDefault" if needed. 29 | template 30 | bool 31 | resolve_use_intra_process(const OptionsT & options, const NodeBaseT & node_base) 32 | { 33 | bool use_intra_process; 34 | switch (options.use_intra_process_comm) { 35 | case IntraProcessSetting::Enable: 36 | use_intra_process = true; 37 | break; 38 | case IntraProcessSetting::Disable: 39 | use_intra_process = false; 40 | break; 41 | case IntraProcessSetting::NodeDefault: 42 | use_intra_process = node_base.get_use_intra_process_default(); 43 | break; 44 | default: 45 | throw std::runtime_error("Unrecognized IntraProcessSetting value"); 46 | break; 47 | } 48 | 49 | return use_intra_process; 50 | } 51 | 52 | } // namespace detail 53 | 54 | } // namespace rclcpp 55 | 56 | #endif // RCLCPP__DETAIL__RESOLVE_USE_INTRA_PROCESS_HPP_ 57 | -------------------------------------------------------------------------------- /rclcpp/include/rclcpp/detail/rmw_implementation_specific_payload.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2019 Open Source Robotics Foundation, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef RCLCPP__DETAIL__RMW_IMPLEMENTATION_SPECIFIC_PAYLOAD_HPP_ 16 | #define RCLCPP__DETAIL__RMW_IMPLEMENTATION_SPECIFIC_PAYLOAD_HPP_ 17 | 18 | #include "rclcpp/visibility_control.hpp" 19 | 20 | namespace rclcpp 21 | { 22 | namespace detail 23 | { 24 | 25 | /// Mechanism for passing rmw implementation specific settings through the ROS interfaces. 26 | class RCLCPP_PUBLIC RMWImplementationSpecificPayload 27 | { 28 | public: 29 | virtual 30 | ~RMWImplementationSpecificPayload() = default; 31 | 32 | /// Return false if this class has not been customized, otherwise true. 33 | /** 34 | * It does this based on the value of the rmw implementation identifier that 35 | * this class reports, and so it is important for a specialization of this 36 | * class to override the get_rmw_implementation_identifier() method to return 37 | * something other than nullptr. 38 | */ 39 | bool 40 | has_been_customized() const; 41 | 42 | /// Derrived classes should override this and return the identifier of its rmw implementation. 43 | virtual 44 | const char * 45 | get_implementation_identifier() const; 46 | }; 47 | 48 | } // namespace detail 49 | } // namespace rclcpp 50 | 51 | #endif // RCLCPP__DETAIL__RMW_IMPLEMENTATION_SPECIFIC_PAYLOAD_HPP_ 52 | -------------------------------------------------------------------------------- /rclcpp/include/rclcpp/detail/rmw_implementation_specific_publisher_payload.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2019 Open Source Robotics Foundation, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef RCLCPP__DETAIL__RMW_IMPLEMENTATION_SPECIFIC_PUBLISHER_PAYLOAD_HPP_ 16 | #define RCLCPP__DETAIL__RMW_IMPLEMENTATION_SPECIFIC_PUBLISHER_PAYLOAD_HPP_ 17 | 18 | #include "rcl/publisher.h" 19 | 20 | #include "rclcpp/detail/rmw_implementation_specific_payload.hpp" 21 | #include "rclcpp/visibility_control.hpp" 22 | 23 | namespace rclcpp 24 | { 25 | namespace detail 26 | { 27 | 28 | class RCLCPP_PUBLIC RMWImplementationSpecificPublisherPayload 29 | : public RMWImplementationSpecificPayload 30 | { 31 | public: 32 | ~RMWImplementationSpecificPublisherPayload() override = default; 33 | 34 | /// Opportunity for a derived class to inject information into the rcl options. 35 | /** 36 | * This is called after the rcl_publisher_options_t has been prepared by 37 | * rclcpp, but before rcl_publisher_init() is called. 38 | * 39 | * The passed option is the rmw_publisher_options field of the 40 | * rcl_publisher_options_t that will be passed to rcl_publisher_init(). 41 | * 42 | * By default the options are unmodified. 43 | */ 44 | virtual 45 | void 46 | modify_rmw_publisher_options(rmw_publisher_options_t & rmw_publisher_options) const; 47 | }; 48 | 49 | } // namespace detail 50 | } // namespace rclcpp 51 | 52 | #endif // RCLCPP__DETAIL__RMW_IMPLEMENTATION_SPECIFIC_PUBLISHER_PAYLOAD_HPP_ 53 | -------------------------------------------------------------------------------- /rclcpp/include/rclcpp/detail/rmw_implementation_specific_subscription_payload.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2019 Open Source Robotics Foundation, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef RCLCPP__DETAIL__RMW_IMPLEMENTATION_SPECIFIC_SUBSCRIPTION_PAYLOAD_HPP_ 16 | #define RCLCPP__DETAIL__RMW_IMPLEMENTATION_SPECIFIC_SUBSCRIPTION_PAYLOAD_HPP_ 17 | 18 | #include "rcl/subscription.h" 19 | 20 | #include "rclcpp/detail/rmw_implementation_specific_payload.hpp" 21 | #include "rclcpp/visibility_control.hpp" 22 | 23 | namespace rclcpp 24 | { 25 | namespace detail 26 | { 27 | 28 | /// Subscription payload that may be rmw implementation specific. 29 | class RCLCPP_PUBLIC RMWImplementationSpecificSubscriptionPayload 30 | : public RMWImplementationSpecificPayload 31 | { 32 | public: 33 | ~RMWImplementationSpecificSubscriptionPayload() override = default; 34 | 35 | /// Opportunity for a derived class to inject information into the rcl options. 36 | /** 37 | * This is called after the rcl_subscription_options_t has been prepared by 38 | * rclcpp, but before rcl_subscription_init() is called. 39 | * 40 | * The passed option is the rmw_subscription_options field of the 41 | * rcl_subscription_options_t that will be passed to rcl_subscription_init(). 42 | * 43 | * By default the options are unmodified. 44 | */ 45 | virtual 46 | void 47 | modify_rmw_subscription_options(rmw_subscription_options_t & rmw_subscription_options) const; 48 | }; 49 | 50 | } // namespace detail 51 | } // namespace rclcpp 52 | 53 | #endif // RCLCPP__DETAIL__RMW_IMPLEMENTATION_SPECIFIC_SUBSCRIPTION_PAYLOAD_HPP_ 54 | -------------------------------------------------------------------------------- /rclcpp/include/rclcpp/detail/utilities.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2019 Open Source Robotics Foundation, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef RCLCPP__DETAIL__UTILITIES_HPP_ 16 | #define RCLCPP__DETAIL__UTILITIES_HPP_ 17 | 18 | #include "rclcpp/detail/utilities.hpp" 19 | 20 | #include 21 | #include 22 | 23 | #include "rcl/allocator.h" 24 | #include "rcl/arguments.h" 25 | 26 | namespace rclcpp 27 | { 28 | namespace detail 29 | { 30 | 31 | std::vector 32 | get_unparsed_ros_arguments( 33 | int argc, char const * const argv[], 34 | rcl_arguments_t * arguments, 35 | rcl_allocator_t allocator); 36 | 37 | } // namespace detail 38 | } // namespace rclcpp 39 | 40 | #endif // RCLCPP__DETAIL__UTILITIES_HPP_ 41 | -------------------------------------------------------------------------------- /rclcpp/include/rclcpp/event.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Open Source Robotics Foundation, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef RCLCPP__EVENT_HPP_ 16 | #define RCLCPP__EVENT_HPP_ 17 | 18 | #include 19 | #include 20 | 21 | #include "rclcpp/macros.hpp" 22 | #include "rclcpp/visibility_control.hpp" 23 | 24 | namespace rclcpp 25 | { 26 | 27 | class Event 28 | { 29 | public: 30 | RCLCPP_SMART_PTR_DEFINITIONS_NOT_COPYABLE(Event) 31 | 32 | /// Default construct 33 | /** 34 | * Set the default value to false 35 | */ 36 | RCLCPP_PUBLIC 37 | Event(); 38 | 39 | /// Set the Event state value to true 40 | /** 41 | * \return The state value before the call. 42 | */ 43 | RCLCPP_PUBLIC 44 | bool 45 | set(); 46 | 47 | /// Get the state value of the Event 48 | /** 49 | * \return the Event state value 50 | */ 51 | RCLCPP_PUBLIC 52 | bool 53 | check(); 54 | 55 | /// Get the state value of the Event and set to false 56 | /** 57 | * \return the Event state value 58 | */ 59 | RCLCPP_PUBLIC 60 | bool 61 | check_and_clear(); 62 | 63 | private: 64 | RCLCPP_DISABLE_COPY(Event) 65 | 66 | std::atomic_bool state_; 67 | }; 68 | 69 | } // namespace rclcpp 70 | 71 | #endif // RCLCPP__EVENT_HPP_ 72 | -------------------------------------------------------------------------------- /rclcpp/include/rclcpp/exceptions.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Open Source Robotics Foundation, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef RCLCPP__EXCEPTIONS_HPP_ 16 | #define RCLCPP__EXCEPTIONS_HPP_ 17 | 18 | #include "rclcpp/exceptions/exceptions.hpp" 19 | 20 | #endif // RCLCPP__EXCEPTIONS_HPP_ 21 | -------------------------------------------------------------------------------- /rclcpp/include/rclcpp/executor_options.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2014-2020 Open Source Robotics Foundation, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef RCLCPP__EXECUTOR_OPTIONS_HPP_ 16 | #define RCLCPP__EXECUTOR_OPTIONS_HPP_ 17 | 18 | #include "rclcpp/context.hpp" 19 | #include "rclcpp/contexts/default_context.hpp" 20 | #include "rclcpp/memory_strategies.hpp" 21 | #include "rclcpp/memory_strategy.hpp" 22 | #include "rclcpp/visibility_control.hpp" 23 | 24 | namespace rclcpp 25 | { 26 | 27 | /// Options to be passed to the executor constructor. 28 | struct ExecutorOptions 29 | { 30 | ExecutorOptions() 31 | : memory_strategy(rclcpp::memory_strategies::create_default_strategy()), 32 | context(rclcpp::contexts::get_global_default_context()), 33 | max_conditions(0) 34 | {} 35 | 36 | rclcpp::memory_strategy::MemoryStrategy::SharedPtr memory_strategy; 37 | rclcpp::Context::SharedPtr context; 38 | size_t max_conditions; 39 | }; 40 | 41 | } // namespace rclcpp 42 | 43 | #endif // RCLCPP__EXECUTOR_OPTIONS_HPP_ 44 | -------------------------------------------------------------------------------- /rclcpp/include/rclcpp/executors/single_threaded_executor.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2014 Open Source Robotics Foundation, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef RCLCPP__EXECUTORS__SINGLE_THREADED_EXECUTOR_HPP_ 16 | #define RCLCPP__EXECUTORS__SINGLE_THREADED_EXECUTOR_HPP_ 17 | 18 | #include 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | #include "rclcpp/executor.hpp" 26 | #include "rclcpp/macros.hpp" 27 | #include "rclcpp/memory_strategies.hpp" 28 | #include "rclcpp/node.hpp" 29 | #include "rclcpp/utilities.hpp" 30 | #include "rclcpp/rate.hpp" 31 | #include "rclcpp/visibility_control.hpp" 32 | 33 | namespace rclcpp 34 | { 35 | namespace executors 36 | { 37 | 38 | /// Single-threaded executor implementation. 39 | /** 40 | * This is the default executor created by rclcpp::spin. 41 | */ 42 | class SingleThreadedExecutor : public rclcpp::Executor 43 | { 44 | public: 45 | RCLCPP_SMART_PTR_DEFINITIONS(SingleThreadedExecutor) 46 | 47 | /// Default constructor. See the default constructor for Executor. 48 | RCLCPP_PUBLIC 49 | explicit SingleThreadedExecutor( 50 | const rclcpp::ExecutorOptions & options = rclcpp::ExecutorOptions()); 51 | 52 | /// Default destructor. 53 | RCLCPP_PUBLIC 54 | virtual ~SingleThreadedExecutor(); 55 | 56 | /// Single-threaded implementation of spin. 57 | /** 58 | * This function will block until work comes in, execute it, and then repeat 59 | * the process until canceled. 60 | * It may be interrupt by a call to rclcpp::Executor::cancel() or by ctrl-c 61 | * if the associated context is configured to shutdown on SIGINT. 62 | * \throws std::runtime_error when spin() called while already spinning 63 | */ 64 | RCLCPP_PUBLIC 65 | void 66 | spin() override; 67 | 68 | #ifdef PICAS 69 | RCLCPP_PUBLIC 70 | void 71 | spin_rt(); 72 | 73 | RCLCPP_PUBLIC 74 | void 75 | spin_cpu(int c); 76 | 77 | RCLCPP_PUBLIC 78 | void 79 | spin_deadline(int p, int T, int budget); 80 | #endif 81 | 82 | private: 83 | RCLCPP_DISABLE_COPY(SingleThreadedExecutor) 84 | }; 85 | 86 | } // namespace executors 87 | } // namespace rclcpp 88 | 89 | #endif // RCLCPP__EXECUTORS__SINGLE_THREADED_EXECUTOR_HPP_ 90 | -------------------------------------------------------------------------------- /rclcpp/include/rclcpp/expand_topic_or_service_name.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Open Source Robotics Foundation, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef RCLCPP__EXPAND_TOPIC_OR_SERVICE_NAME_HPP_ 16 | #define RCLCPP__EXPAND_TOPIC_OR_SERVICE_NAME_HPP_ 17 | 18 | #include 19 | 20 | #include "rclcpp/visibility_control.hpp" 21 | 22 | namespace rclcpp 23 | { 24 | 25 | /// Expand a topic or service name and throw if it is not valid. 26 | /** 27 | * This function can be used to "just" validate a topic or service name too, 28 | * since expanding the topic name is required to fully validate a name. 29 | * 30 | * If the name is invalid, then InvalidTopicNameError is thrown or 31 | * InvalidServiceNameError if is_service is true. 32 | * 33 | * This function can take any form of a topic or service name, i.e. it does not 34 | * have to be a fully qualified name. 35 | * The node name and namespace are used to expand it if necessary while 36 | * validating it. 37 | * 38 | * Expansion is done with rcl_expand_topic_name. 39 | * The validation is doen with rcl_validate_topic_name and 40 | * rmw_validate_full_topic_name, so details about failures can be found in the 41 | * documentation for those functions. 42 | * 43 | * \param name the topic or service name to be validated 44 | * \param node_name the name of the node associated with the name 45 | * \param namespace_ the namespace of the node associated with the name 46 | * \param is_service if true InvalidServiceNameError is thrown instead 47 | * \returns expanded (and validated) topic name 48 | * \throws InvalidTopicNameError if name is invalid and is_service is false 49 | * \throws InvalidServiceNameError if name is invalid and is_service is true 50 | * \throws std::bad_alloc if memory cannot be allocated 51 | * \throws RCLError if an unexpect error occurs 52 | * \throws std::runtime_error if the topic name is unexpectedly valid or, 53 | * if the rcl name is invalid or if the rcl namespace is invalid 54 | */ 55 | RCLCPP_PUBLIC 56 | std::string 57 | expand_topic_or_service_name( 58 | const std::string & name, 59 | const std::string & node_name, 60 | const std::string & namespace_, 61 | bool is_service = false); 62 | 63 | } // namespace rclcpp 64 | 65 | #endif // RCLCPP__EXPAND_TOPIC_OR_SERVICE_NAME_HPP_ 66 | -------------------------------------------------------------------------------- /rclcpp/include/rclcpp/experimental/README.md: -------------------------------------------------------------------------------- 1 | Notice that headers in this folder should only provide symbols in the rclcpp::experimental namespace. 2 | 3 | Also notice that these headers are not considered part of the public API as they have not yet been stabilized. 4 | And therefore they are subject to change without notice. 5 | -------------------------------------------------------------------------------- /rclcpp/include/rclcpp/experimental/buffers/buffer_implementation_base.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2019 Open Source Robotics Foundation, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef RCLCPP__EXPERIMENTAL__BUFFERS__BUFFER_IMPLEMENTATION_BASE_HPP_ 16 | #define RCLCPP__EXPERIMENTAL__BUFFERS__BUFFER_IMPLEMENTATION_BASE_HPP_ 17 | 18 | namespace rclcpp 19 | { 20 | namespace experimental 21 | { 22 | namespace buffers 23 | { 24 | 25 | template 26 | class BufferImplementationBase 27 | { 28 | public: 29 | virtual ~BufferImplementationBase() {} 30 | 31 | virtual BufferT dequeue() = 0; 32 | virtual void enqueue(BufferT request) = 0; 33 | 34 | virtual void clear() = 0; 35 | virtual bool has_data() const = 0; 36 | }; 37 | 38 | } // namespace buffers 39 | } // namespace experimental 40 | } // namespace rclcpp 41 | 42 | #endif // RCLCPP__EXPERIMENTAL__BUFFERS__BUFFER_IMPLEMENTATION_BASE_HPP_ 43 | -------------------------------------------------------------------------------- /rclcpp/include/rclcpp/experimental/subscription_intra_process_base.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2019 Open Source Robotics Foundation, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef RCLCPP__EXPERIMENTAL__SUBSCRIPTION_INTRA_PROCESS_BASE_HPP_ 16 | #define RCLCPP__EXPERIMENTAL__SUBSCRIPTION_INTRA_PROCESS_BASE_HPP_ 17 | 18 | #include 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #include "rcl/error_handling.h" 27 | 28 | #include "rclcpp/type_support_decl.hpp" 29 | #include "rclcpp/waitable.hpp" 30 | 31 | namespace rclcpp 32 | { 33 | namespace experimental 34 | { 35 | 36 | class SubscriptionIntraProcessBase : public rclcpp::Waitable 37 | { 38 | public: 39 | RCLCPP_SMART_PTR_ALIASES_ONLY(SubscriptionIntraProcessBase) 40 | 41 | RCLCPP_PUBLIC 42 | SubscriptionIntraProcessBase(const std::string & topic_name, rmw_qos_profile_t qos_profile) 43 | : topic_name_(topic_name), qos_profile_(qos_profile) 44 | {} 45 | 46 | virtual ~SubscriptionIntraProcessBase() = default; 47 | 48 | RCLCPP_PUBLIC 49 | size_t 50 | get_number_of_ready_guard_conditions() {return 1;} 51 | 52 | RCLCPP_PUBLIC 53 | bool 54 | add_to_wait_set(rcl_wait_set_t * wait_set); 55 | 56 | virtual bool 57 | is_ready(rcl_wait_set_t * wait_set) = 0; 58 | 59 | virtual 60 | std::shared_ptr 61 | take_data() = 0; 62 | 63 | virtual void 64 | execute(std::shared_ptr & data) = 0; 65 | 66 | virtual bool 67 | use_take_shared_method() const = 0; 68 | 69 | RCLCPP_PUBLIC 70 | const char * 71 | get_topic_name() const; 72 | 73 | RCLCPP_PUBLIC 74 | rmw_qos_profile_t 75 | get_actual_qos() const; 76 | 77 | protected: 78 | std::recursive_mutex reentrant_mutex_; 79 | rcl_guard_condition_t gc_; 80 | 81 | private: 82 | virtual void 83 | trigger_guard_condition() = 0; 84 | 85 | std::string topic_name_; 86 | rmw_qos_profile_t qos_profile_; 87 | }; 88 | 89 | } // namespace experimental 90 | } // namespace rclcpp 91 | 92 | #endif // RCLCPP__EXPERIMENTAL__SUBSCRIPTION_INTRA_PROCESS_BASE_HPP_ 93 | -------------------------------------------------------------------------------- /rclcpp/include/rclcpp/future_return_code.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2014 Open Source Robotics Foundation, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef RCLCPP__FUTURE_RETURN_CODE_HPP_ 16 | #define RCLCPP__FUTURE_RETURN_CODE_HPP_ 17 | 18 | #include 19 | #include 20 | 21 | #include "rclcpp/visibility_control.hpp" 22 | 23 | namespace rclcpp 24 | { 25 | 26 | /// Return codes to be used with spin_until_future_complete. 27 | /** 28 | * SUCCESS: The future is complete and can be accessed with "get" without blocking. 29 | * This does not indicate that the operation succeeded; "get" may still throw an exception. 30 | * INTERRUPTED: The future is not complete, spinning was interrupted by Ctrl-C or another error. 31 | * TIMEOUT: Spinning timed out. 32 | */ 33 | enum class FutureReturnCode {SUCCESS, INTERRUPTED, TIMEOUT}; 34 | 35 | /// Stream operator for FutureReturnCode. 36 | RCLCPP_PUBLIC 37 | std::ostream & 38 | operator<<(std::ostream & os, const FutureReturnCode & future_return_code); 39 | 40 | /// String conversion function for FutureReturnCode. 41 | RCLCPP_PUBLIC 42 | std::string 43 | to_string(const FutureReturnCode & future_return_code); 44 | 45 | } // namespace rclcpp 46 | 47 | #endif // RCLCPP__FUTURE_RETURN_CODE_HPP_ 48 | -------------------------------------------------------------------------------- /rclcpp/include/rclcpp/intra_process_buffer_type.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2019 Open Source Robotics Foundation, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef RCLCPP__INTRA_PROCESS_BUFFER_TYPE_HPP_ 16 | #define RCLCPP__INTRA_PROCESS_BUFFER_TYPE_HPP_ 17 | 18 | namespace rclcpp 19 | { 20 | 21 | /// Used as argument in create_publisher and create_subscriber 22 | /// when intra-process communication is enabled 23 | enum class IntraProcessBufferType 24 | { 25 | /// Set the data type used in the intra-process buffer as std::shared_ptr 26 | SharedPtr, 27 | /// Set the data type used in the intra-process buffer as std::unique_ptr 28 | UniquePtr, 29 | /// Set the data type used in the intra-process buffer as the same used in the callback 30 | CallbackDefault 31 | }; 32 | 33 | } // namespace rclcpp 34 | 35 | #endif // RCLCPP__INTRA_PROCESS_BUFFER_TYPE_HPP_ 36 | -------------------------------------------------------------------------------- /rclcpp/include/rclcpp/intra_process_setting.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2019 Open Source Robotics Foundation, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef RCLCPP__INTRA_PROCESS_SETTING_HPP_ 16 | #define RCLCPP__INTRA_PROCESS_SETTING_HPP_ 17 | 18 | namespace rclcpp 19 | { 20 | 21 | /// Used as argument in create_publisher and create_subscriber. 22 | enum class IntraProcessSetting 23 | { 24 | /// Explicitly enable intraprocess comm at publisher/subscription level. 25 | Enable, 26 | /// Explicitly disable intraprocess comm at publisher/subscription level. 27 | Disable, 28 | /// Take intraprocess configuration from the node. 29 | NodeDefault 30 | }; 31 | 32 | } // namespace rclcpp 33 | 34 | #endif // RCLCPP__INTRA_PROCESS_SETTING_HPP_ 35 | -------------------------------------------------------------------------------- /rclcpp/include/rclcpp/memory_strategies.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2015 Open Source Robotics Foundation, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef RCLCPP__MEMORY_STRATEGIES_HPP_ 16 | #define RCLCPP__MEMORY_STRATEGIES_HPP_ 17 | 18 | #include "rclcpp/memory_strategy.hpp" 19 | #include "rclcpp/visibility_control.hpp" 20 | 21 | namespace rclcpp 22 | { 23 | namespace memory_strategies 24 | { 25 | 26 | /// Create a MemoryStrategy sharedPtr 27 | /** 28 | * \return a MemoryStrategy sharedPtr 29 | */ 30 | RCLCPP_PUBLIC 31 | memory_strategy::MemoryStrategy::SharedPtr 32 | create_default_strategy(); 33 | 34 | } // namespace memory_strategies 35 | } // namespace rclcpp 36 | 37 | #endif // RCLCPP__MEMORY_STRATEGIES_HPP_ 38 | -------------------------------------------------------------------------------- /rclcpp/include/rclcpp/message_info.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Open Source Robotics Foundation, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef RCLCPP__MESSAGE_INFO_HPP_ 16 | #define RCLCPP__MESSAGE_INFO_HPP_ 17 | 18 | #include "rmw/types.h" 19 | 20 | #include "rclcpp/visibility_control.hpp" 21 | 22 | namespace rclcpp 23 | { 24 | 25 | /// Additional meta data about messages taken from subscriptions. 26 | class RCLCPP_PUBLIC MessageInfo 27 | { 28 | public: 29 | /// Default empty constructor. 30 | MessageInfo() = default; 31 | 32 | /// Conversion constructor, which is intentionally not marked as explicit. 33 | /** 34 | * \param[in] rmw_message_info message info to initialize the class 35 | */ 36 | // cppcheck-suppress noExplicitConstructor 37 | MessageInfo(const rmw_message_info_t & rmw_message_info); // NOLINT(runtime/explicit) 38 | 39 | virtual ~MessageInfo(); 40 | 41 | /// Return the message info as the underlying rmw message info type. 42 | const rmw_message_info_t & 43 | get_rmw_message_info() const; 44 | 45 | /// Return the message info as the underlying rmw message info type. 46 | rmw_message_info_t & 47 | get_rmw_message_info(); 48 | 49 | private: 50 | rmw_message_info_t rmw_message_info_; 51 | }; 52 | 53 | } // namespace rclcpp 54 | 55 | #endif // RCLCPP__MESSAGE_INFO_HPP_ 56 | -------------------------------------------------------------------------------- /rclcpp/include/rclcpp/node_interfaces/node_clock.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Open Source Robotics Foundation, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef RCLCPP__NODE_INTERFACES__NODE_CLOCK_HPP_ 16 | #define RCLCPP__NODE_INTERFACES__NODE_CLOCK_HPP_ 17 | 18 | #include "rclcpp/clock.hpp" 19 | #include "rclcpp/macros.hpp" 20 | #include "rclcpp/node_interfaces/node_base_interface.hpp" 21 | #include "rclcpp/node_interfaces/node_clock_interface.hpp" 22 | #include "rclcpp/node_interfaces/node_graph_interface.hpp" 23 | #include "rclcpp/node_interfaces/node_logging_interface.hpp" 24 | #include "rclcpp/node_interfaces/node_services_interface.hpp" 25 | #include "rclcpp/node_interfaces/node_topics_interface.hpp" 26 | #include "rclcpp/visibility_control.hpp" 27 | 28 | namespace rclcpp 29 | { 30 | namespace node_interfaces 31 | { 32 | 33 | /// Implementation of the NodeClock part of the Node API. 34 | class NodeClock : public NodeClockInterface 35 | { 36 | public: 37 | RCLCPP_SMART_PTR_ALIASES_ONLY(NodeClock) 38 | 39 | RCLCPP_PUBLIC 40 | explicit NodeClock( 41 | rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_base, 42 | rclcpp::node_interfaces::NodeTopicsInterface::SharedPtr node_topics, 43 | rclcpp::node_interfaces::NodeGraphInterface::SharedPtr node_graph, 44 | rclcpp::node_interfaces::NodeServicesInterface::SharedPtr node_services, 45 | rclcpp::node_interfaces::NodeLoggingInterface::SharedPtr node_logging); 46 | 47 | RCLCPP_PUBLIC 48 | virtual 49 | ~NodeClock(); 50 | 51 | /// Get a clock which will be kept up to date by the node. 52 | RCLCPP_PUBLIC 53 | rclcpp::Clock::SharedPtr 54 | get_clock() override; 55 | 56 | /// Get a clock which will be kept up to date by the node. 57 | RCLCPP_PUBLIC 58 | rclcpp::Clock::ConstSharedPtr 59 | get_clock() const override; 60 | 61 | private: 62 | RCLCPP_DISABLE_COPY(NodeClock) 63 | 64 | rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_base_; 65 | rclcpp::node_interfaces::NodeTopicsInterface::SharedPtr node_topics_; 66 | rclcpp::node_interfaces::NodeGraphInterface::SharedPtr node_graph_; 67 | rclcpp::node_interfaces::NodeServicesInterface::SharedPtr node_services_; 68 | rclcpp::node_interfaces::NodeLoggingInterface::SharedPtr node_logging_; 69 | 70 | rclcpp::Clock::SharedPtr ros_clock_; 71 | }; 72 | 73 | } // namespace node_interfaces 74 | } // namespace rclcpp 75 | 76 | #endif // RCLCPP__NODE_INTERFACES__NODE_CLOCK_HPP_ 77 | -------------------------------------------------------------------------------- /rclcpp/include/rclcpp/node_interfaces/node_clock_interface.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Open Source Robotics Foundation, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef RCLCPP__NODE_INTERFACES__NODE_CLOCK_INTERFACE_HPP_ 16 | #define RCLCPP__NODE_INTERFACES__NODE_CLOCK_INTERFACE_HPP_ 17 | 18 | #include "rclcpp/clock.hpp" 19 | #include "rclcpp/macros.hpp" 20 | #include "rclcpp/visibility_control.hpp" 21 | 22 | namespace rclcpp 23 | { 24 | namespace node_interfaces 25 | { 26 | 27 | /// Pure virtual interface class for the NodeClock part of the Node API. 28 | class NodeClockInterface 29 | { 30 | public: 31 | RCLCPP_SMART_PTR_ALIASES_ONLY(NodeClockInterface) 32 | 33 | RCLCPP_PUBLIC 34 | virtual 35 | ~NodeClockInterface() = default; 36 | 37 | /// Get a ROS clock which will be kept up to date by the node. 38 | RCLCPP_PUBLIC 39 | virtual 40 | rclcpp::Clock::SharedPtr 41 | get_clock() = 0; 42 | 43 | /// Get a const ROS clock which will be kept up to date by the node. 44 | RCLCPP_PUBLIC 45 | virtual 46 | rclcpp::Clock::ConstSharedPtr 47 | get_clock() const = 0; 48 | }; 49 | 50 | } // namespace node_interfaces 51 | } // namespace rclcpp 52 | 53 | #endif // RCLCPP__NODE_INTERFACES__NODE_CLOCK_INTERFACE_HPP_ 54 | -------------------------------------------------------------------------------- /rclcpp/include/rclcpp/node_interfaces/node_logging.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Open Source Robotics Foundation, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef RCLCPP__NODE_INTERFACES__NODE_LOGGING_HPP_ 16 | #define RCLCPP__NODE_INTERFACES__NODE_LOGGING_HPP_ 17 | 18 | #include 19 | 20 | #include "rclcpp/logger.hpp" 21 | #include "rclcpp/macros.hpp" 22 | #include "rclcpp/node_interfaces/node_base_interface.hpp" 23 | #include "rclcpp/node_interfaces/node_logging_interface.hpp" 24 | #include "rclcpp/visibility_control.hpp" 25 | 26 | namespace rclcpp 27 | { 28 | namespace node_interfaces 29 | { 30 | 31 | /// Implementation of the NodeLogging part of the Node API. 32 | class NodeLogging : public NodeLoggingInterface 33 | { 34 | public: 35 | RCLCPP_SMART_PTR_ALIASES_ONLY(NodeLoggingInterface) 36 | 37 | RCLCPP_PUBLIC 38 | explicit NodeLogging(rclcpp::node_interfaces::NodeBaseInterface * node_base); 39 | 40 | RCLCPP_PUBLIC 41 | virtual 42 | ~NodeLogging(); 43 | 44 | RCLCPP_PUBLIC 45 | rclcpp::Logger 46 | get_logger() const override; 47 | 48 | RCLCPP_PUBLIC 49 | const char * 50 | get_logger_name() const override; 51 | 52 | private: 53 | RCLCPP_DISABLE_COPY(NodeLogging) 54 | 55 | /// Handle to the NodeBaseInterface given in the constructor. 56 | rclcpp::node_interfaces::NodeBaseInterface * node_base_; 57 | 58 | rclcpp::Logger logger_; 59 | }; 60 | 61 | } // namespace node_interfaces 62 | } // namespace rclcpp 63 | 64 | #endif // RCLCPP__NODE_INTERFACES__NODE_LOGGING_HPP_ 65 | -------------------------------------------------------------------------------- /rclcpp/include/rclcpp/node_interfaces/node_logging_interface.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Open Source Robotics Foundation, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef RCLCPP__NODE_INTERFACES__NODE_LOGGING_INTERFACE_HPP_ 16 | #define RCLCPP__NODE_INTERFACES__NODE_LOGGING_INTERFACE_HPP_ 17 | 18 | #include 19 | 20 | #include "rclcpp/logger.hpp" 21 | #include "rclcpp/macros.hpp" 22 | #include "rclcpp/visibility_control.hpp" 23 | 24 | namespace rclcpp 25 | { 26 | namespace node_interfaces 27 | { 28 | 29 | /// Pure virtual interface class for the NodeLogging part of the Node API. 30 | class NodeLoggingInterface 31 | { 32 | public: 33 | RCLCPP_SMART_PTR_ALIASES_ONLY(NodeLoggingInterface) 34 | 35 | RCLCPP_PUBLIC 36 | virtual 37 | ~NodeLoggingInterface() = default; 38 | 39 | /// Return the logger of the node. 40 | /** \return The logger of the node. */ 41 | RCLCPP_PUBLIC 42 | virtual 43 | rclcpp::Logger 44 | get_logger() const = 0; 45 | 46 | /// Return the logger name associated with the node. 47 | /** \return The logger name associated with the node. */ 48 | RCLCPP_PUBLIC 49 | virtual 50 | const char * 51 | get_logger_name() const = 0; 52 | }; 53 | 54 | } // namespace node_interfaces 55 | } // namespace rclcpp 56 | 57 | #endif // RCLCPP__NODE_INTERFACES__NODE_LOGGING_INTERFACE_HPP_ 58 | -------------------------------------------------------------------------------- /rclcpp/include/rclcpp/node_interfaces/node_services.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Open Source Robotics Foundation, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef RCLCPP__NODE_INTERFACES__NODE_SERVICES_HPP_ 16 | #define RCLCPP__NODE_INTERFACES__NODE_SERVICES_HPP_ 17 | 18 | #include 19 | 20 | #include "rclcpp/callback_group.hpp" 21 | #include "rclcpp/client.hpp" 22 | #include "rclcpp/macros.hpp" 23 | #include "rclcpp/node_interfaces/node_base_interface.hpp" 24 | #include "rclcpp/node_interfaces/node_services_interface.hpp" 25 | #include "rclcpp/service.hpp" 26 | #include "rclcpp/visibility_control.hpp" 27 | 28 | namespace rclcpp 29 | { 30 | namespace node_interfaces 31 | { 32 | 33 | /// Implementation of the NodeServices part of the Node API. 34 | class NodeServices : public NodeServicesInterface 35 | { 36 | public: 37 | RCLCPP_SMART_PTR_ALIASES_ONLY(NodeServices) 38 | 39 | RCLCPP_PUBLIC 40 | explicit NodeServices(rclcpp::node_interfaces::NodeBaseInterface * node_base); 41 | 42 | RCLCPP_PUBLIC 43 | virtual 44 | ~NodeServices(); 45 | 46 | RCLCPP_PUBLIC 47 | void 48 | add_client( 49 | rclcpp::ClientBase::SharedPtr client_base_ptr, 50 | rclcpp::CallbackGroup::SharedPtr group) override; 51 | 52 | RCLCPP_PUBLIC 53 | void 54 | add_service( 55 | rclcpp::ServiceBase::SharedPtr service_base_ptr, 56 | rclcpp::CallbackGroup::SharedPtr group) override; 57 | 58 | RCLCPP_PUBLIC 59 | std::string 60 | resolve_service_name(const std::string & name, bool only_expand = false) const override; 61 | 62 | private: 63 | RCLCPP_DISABLE_COPY(NodeServices) 64 | 65 | rclcpp::node_interfaces::NodeBaseInterface * node_base_; 66 | }; 67 | 68 | } // namespace node_interfaces 69 | } // namespace rclcpp 70 | 71 | #endif // RCLCPP__NODE_INTERFACES__NODE_SERVICES_HPP_ 72 | -------------------------------------------------------------------------------- /rclcpp/include/rclcpp/node_interfaces/node_services_interface.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Open Source Robotics Foundation, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef RCLCPP__NODE_INTERFACES__NODE_SERVICES_INTERFACE_HPP_ 16 | #define RCLCPP__NODE_INTERFACES__NODE_SERVICES_INTERFACE_HPP_ 17 | 18 | #include 19 | 20 | #include "rclcpp/callback_group.hpp" 21 | #include "rclcpp/client.hpp" 22 | #include "rclcpp/macros.hpp" 23 | #include "rclcpp/service.hpp" 24 | #include "rclcpp/visibility_control.hpp" 25 | 26 | namespace rclcpp 27 | { 28 | namespace node_interfaces 29 | { 30 | 31 | /// Pure virtual interface class for the NodeServices part of the Node API. 32 | class NodeServicesInterface 33 | { 34 | public: 35 | RCLCPP_SMART_PTR_ALIASES_ONLY(NodeServicesInterface) 36 | 37 | RCLCPP_PUBLIC 38 | virtual 39 | ~NodeServicesInterface() = default; 40 | 41 | RCLCPP_PUBLIC 42 | virtual 43 | void 44 | add_client( 45 | rclcpp::ClientBase::SharedPtr client_base_ptr, 46 | rclcpp::CallbackGroup::SharedPtr group) = 0; 47 | 48 | RCLCPP_PUBLIC 49 | virtual 50 | void 51 | add_service( 52 | rclcpp::ServiceBase::SharedPtr service_base_ptr, 53 | rclcpp::CallbackGroup::SharedPtr group) = 0; 54 | 55 | /// Get the remapped and expanded service name given a input name. 56 | RCLCPP_PUBLIC 57 | virtual 58 | std::string 59 | resolve_service_name(const std::string & name, bool only_expand = false) const = 0; 60 | }; 61 | 62 | } // namespace node_interfaces 63 | } // namespace rclcpp 64 | 65 | #endif // RCLCPP__NODE_INTERFACES__NODE_SERVICES_INTERFACE_HPP_ 66 | -------------------------------------------------------------------------------- /rclcpp/include/rclcpp/node_interfaces/node_time_source_interface.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Open Source Robotics Foundation, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef RCLCPP__NODE_INTERFACES__NODE_TIME_SOURCE_INTERFACE_HPP_ 16 | #define RCLCPP__NODE_INTERFACES__NODE_TIME_SOURCE_INTERFACE_HPP_ 17 | 18 | #include "rclcpp/macros.hpp" 19 | #include "rclcpp/visibility_control.hpp" 20 | 21 | namespace rclcpp 22 | { 23 | namespace node_interfaces 24 | { 25 | 26 | /// Pure virtual interface class for the NodeTimeSource part of the Node API. 27 | class NodeTimeSourceInterface 28 | { 29 | public: 30 | RCLCPP_SMART_PTR_ALIASES_ONLY(NodeTimeSourceInterface) 31 | 32 | RCLCPP_PUBLIC 33 | virtual 34 | ~NodeTimeSourceInterface() = default; 35 | }; 36 | 37 | } // namespace node_interfaces 38 | } // namespace rclcpp 39 | 40 | #endif // RCLCPP__NODE_INTERFACES__NODE_TIME_SOURCE_INTERFACE_HPP_ 41 | -------------------------------------------------------------------------------- /rclcpp/include/rclcpp/node_interfaces/node_timers.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Open Source Robotics Foundation, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef RCLCPP__NODE_INTERFACES__NODE_TIMERS_HPP_ 16 | #define RCLCPP__NODE_INTERFACES__NODE_TIMERS_HPP_ 17 | 18 | #include "rclcpp/callback_group.hpp" 19 | #include "rclcpp/macros.hpp" 20 | #include "rclcpp/node_interfaces/node_base_interface.hpp" 21 | #include "rclcpp/node_interfaces/node_timers_interface.hpp" 22 | #include "rclcpp/timer.hpp" 23 | #include "rclcpp/visibility_control.hpp" 24 | 25 | namespace rclcpp 26 | { 27 | namespace node_interfaces 28 | { 29 | 30 | /// Implementation of the NodeTimers part of the Node API. 31 | class NodeTimers : public NodeTimersInterface 32 | { 33 | public: 34 | RCLCPP_SMART_PTR_ALIASES_ONLY(NodeTimers) 35 | 36 | RCLCPP_PUBLIC 37 | explicit NodeTimers(rclcpp::node_interfaces::NodeBaseInterface * node_base); 38 | 39 | RCLCPP_PUBLIC 40 | virtual 41 | ~NodeTimers(); 42 | 43 | /// Add a timer to the node. 44 | RCLCPP_PUBLIC 45 | void 46 | add_timer( 47 | rclcpp::TimerBase::SharedPtr timer, 48 | rclcpp::CallbackGroup::SharedPtr callback_group) override; 49 | 50 | private: 51 | RCLCPP_DISABLE_COPY(NodeTimers) 52 | 53 | rclcpp::node_interfaces::NodeBaseInterface * node_base_; 54 | }; 55 | 56 | } // namespace node_interfaces 57 | } // namespace rclcpp 58 | 59 | #endif // RCLCPP__NODE_INTERFACES__NODE_TIMERS_HPP_ 60 | -------------------------------------------------------------------------------- /rclcpp/include/rclcpp/node_interfaces/node_timers_interface.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Open Source Robotics Foundation, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef RCLCPP__NODE_INTERFACES__NODE_TIMERS_INTERFACE_HPP_ 16 | #define RCLCPP__NODE_INTERFACES__NODE_TIMERS_INTERFACE_HPP_ 17 | 18 | #include "rclcpp/callback_group.hpp" 19 | #include "rclcpp/macros.hpp" 20 | #include "rclcpp/timer.hpp" 21 | #include "rclcpp/visibility_control.hpp" 22 | 23 | namespace rclcpp 24 | { 25 | namespace node_interfaces 26 | { 27 | 28 | /// Pure virtual interface class for the NodeTimers part of the Node API. 29 | class NodeTimersInterface 30 | { 31 | public: 32 | RCLCPP_SMART_PTR_ALIASES_ONLY(NodeTimersInterface) 33 | 34 | RCLCPP_PUBLIC 35 | virtual 36 | ~NodeTimersInterface() = default; 37 | 38 | /// Add a timer to the node. 39 | RCLCPP_PUBLIC 40 | virtual 41 | void 42 | add_timer( 43 | rclcpp::TimerBase::SharedPtr timer, 44 | rclcpp::CallbackGroup::SharedPtr callback_group) = 0; 45 | }; 46 | 47 | } // namespace node_interfaces 48 | } // namespace rclcpp 49 | 50 | #endif // RCLCPP__NODE_INTERFACES__NODE_TIMERS_INTERFACE_HPP_ 51 | -------------------------------------------------------------------------------- /rclcpp/include/rclcpp/node_interfaces/node_waitables.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Open Source Robotics Foundation, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef RCLCPP__NODE_INTERFACES__NODE_WAITABLES_HPP_ 16 | #define RCLCPP__NODE_INTERFACES__NODE_WAITABLES_HPP_ 17 | 18 | #include "rclcpp/callback_group.hpp" 19 | #include "rclcpp/macros.hpp" 20 | #include "rclcpp/node_interfaces/node_base_interface.hpp" 21 | #include "rclcpp/node_interfaces/node_waitables_interface.hpp" 22 | #include "rclcpp/waitable.hpp" 23 | #include "rclcpp/visibility_control.hpp" 24 | 25 | namespace rclcpp 26 | { 27 | namespace node_interfaces 28 | { 29 | 30 | /// Implementation of the NodeWaitables part of the Node API. 31 | class NodeWaitables : public NodeWaitablesInterface 32 | { 33 | public: 34 | RCLCPP_SMART_PTR_ALIASES_ONLY(NodeWaitables) 35 | 36 | RCLCPP_PUBLIC 37 | explicit NodeWaitables(rclcpp::node_interfaces::NodeBaseInterface * node_base); 38 | 39 | RCLCPP_PUBLIC 40 | virtual 41 | ~NodeWaitables(); 42 | 43 | RCLCPP_PUBLIC 44 | void 45 | add_waitable( 46 | rclcpp::Waitable::SharedPtr waitable_base_ptr, 47 | rclcpp::CallbackGroup::SharedPtr group) override; 48 | 49 | RCLCPP_PUBLIC 50 | void 51 | remove_waitable( 52 | rclcpp::Waitable::SharedPtr waitable_ptr, 53 | rclcpp::CallbackGroup::SharedPtr group) noexcept override; 54 | 55 | private: 56 | RCLCPP_DISABLE_COPY(NodeWaitables) 57 | 58 | rclcpp::node_interfaces::NodeBaseInterface * node_base_; 59 | }; 60 | 61 | } // namespace node_interfaces 62 | } // namespace rclcpp 63 | 64 | #endif // RCLCPP__NODE_INTERFACES__NODE_WAITABLES_HPP_ 65 | -------------------------------------------------------------------------------- /rclcpp/include/rclcpp/node_interfaces/node_waitables_interface.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Open Source Robotics Foundation, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef RCLCPP__NODE_INTERFACES__NODE_WAITABLES_INTERFACE_HPP_ 16 | #define RCLCPP__NODE_INTERFACES__NODE_WAITABLES_INTERFACE_HPP_ 17 | 18 | #include "rclcpp/callback_group.hpp" 19 | #include "rclcpp/macros.hpp" 20 | #include "rclcpp/visibility_control.hpp" 21 | #include "rclcpp/waitable.hpp" 22 | 23 | namespace rclcpp 24 | { 25 | namespace node_interfaces 26 | { 27 | 28 | /// Pure virtual interface class for the NodeWaitables part of the Node API. 29 | class NodeWaitablesInterface 30 | { 31 | public: 32 | RCLCPP_SMART_PTR_ALIASES_ONLY(NodeWaitablesInterface) 33 | 34 | RCLCPP_PUBLIC 35 | virtual 36 | ~NodeWaitablesInterface() = default; 37 | 38 | RCLCPP_PUBLIC 39 | virtual 40 | void 41 | add_waitable( 42 | rclcpp::Waitable::SharedPtr waitable_ptr, 43 | rclcpp::CallbackGroup::SharedPtr group) = 0; 44 | 45 | /// \note this function should not throw because it may be called in destructors 46 | RCLCPP_PUBLIC 47 | virtual 48 | void 49 | remove_waitable( 50 | rclcpp::Waitable::SharedPtr waitable_ptr, 51 | rclcpp::CallbackGroup::SharedPtr group) noexcept = 0; 52 | }; 53 | 54 | } // namespace node_interfaces 55 | } // namespace rclcpp 56 | 57 | #endif // RCLCPP__NODE_INTERFACES__NODE_WAITABLES_INTERFACE_HPP_ 58 | -------------------------------------------------------------------------------- /rclcpp/include/rclcpp/parameter_map.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Open Source Robotics Foundation, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef RCLCPP__PARAMETER_MAP_HPP_ 16 | #define RCLCPP__PARAMETER_MAP_HPP_ 17 | 18 | #include 19 | #include 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | #include "rclcpp/exceptions.hpp" 26 | #include "rclcpp/parameter.hpp" 27 | #include "rclcpp/parameter_value.hpp" 28 | #include "rclcpp/visibility_control.hpp" 29 | 30 | namespace rclcpp 31 | { 32 | 33 | /// A map of fully qualified node names to a list of parameters 34 | using ParameterMap = std::unordered_map>; 35 | 36 | /// Convert parameters from rcl_yaml_param_parser into C++ class instances. 37 | /// \param[in] c_params C structures containing parameters for multiple nodes. 38 | /// \returns a map where the keys are fully qualified node names and values a list of parameters. 39 | /// \throws InvalidParametersException if the `rcl_params_t` is inconsistent or invalid. 40 | RCLCPP_PUBLIC 41 | ParameterMap 42 | parameter_map_from(const rcl_params_t * const c_params); 43 | 44 | /// Convert parameter value from rcl_yaml_param_parser into a C++ class instance. 45 | /// \param[in] c_value C structure containing a value of a parameter. 46 | /// \returns an instance of a parameter value 47 | /// \throws InvalidParameterValueException if the `rcl_variant_t` is inconsistent or invalid. 48 | RCLCPP_PUBLIC 49 | ParameterValue 50 | parameter_value_from(const rcl_variant_t * const c_value); 51 | 52 | /// Get the ParameterMap from a yaml file. 53 | /// \param[in] yaml_filename full name of the yaml file. 54 | /// \returns an instance of a parameter map 55 | /// \throws from rcl error of rcl_parse_yaml_file() 56 | RCLCPP_PUBLIC 57 | ParameterMap 58 | parameter_map_from_yaml_file(const std::string & yaml_filename); 59 | 60 | } // namespace rclcpp 61 | 62 | #endif // RCLCPP__PARAMETER_MAP_HPP_ 63 | -------------------------------------------------------------------------------- /rclcpp/include/rclcpp/parameter_service.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2015 Open Source Robotics Foundation, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef RCLCPP__PARAMETER_SERVICE_HPP_ 16 | #define RCLCPP__PARAMETER_SERVICE_HPP_ 17 | 18 | #include 19 | #include 20 | 21 | #include "rcl_interfaces/srv/describe_parameters.hpp" 22 | #include "rcl_interfaces/srv/get_parameter_types.hpp" 23 | #include "rcl_interfaces/srv/get_parameters.hpp" 24 | #include "rcl_interfaces/srv/list_parameters.hpp" 25 | #include "rcl_interfaces/srv/set_parameters.hpp" 26 | #include "rcl_interfaces/srv/set_parameters_atomically.hpp" 27 | #include "rclcpp/executors.hpp" 28 | #include "rclcpp/macros.hpp" 29 | #include "rclcpp/node.hpp" 30 | #include "rclcpp/parameter.hpp" 31 | #include "rclcpp/visibility_control.hpp" 32 | #include "rmw/rmw.h" 33 | 34 | namespace rclcpp 35 | { 36 | 37 | class ParameterService 38 | { 39 | public: 40 | RCLCPP_SMART_PTR_DEFINITIONS(ParameterService) 41 | 42 | RCLCPP_PUBLIC 43 | explicit ParameterService( 44 | const std::shared_ptr node_base, 45 | const std::shared_ptr node_services, 46 | rclcpp::node_interfaces::NodeParametersInterface * node_params, 47 | const rmw_qos_profile_t & qos_profile = rmw_qos_profile_parameters); 48 | 49 | private: 50 | rclcpp::Service::SharedPtr get_parameters_service_; 51 | rclcpp::Service::SharedPtr 52 | get_parameter_types_service_; 53 | rclcpp::Service::SharedPtr set_parameters_service_; 54 | rclcpp::Service::SharedPtr 55 | set_parameters_atomically_service_; 56 | rclcpp::Service::SharedPtr 57 | describe_parameters_service_; 58 | rclcpp::Service::SharedPtr list_parameters_service_; 59 | }; 60 | 61 | } // namespace rclcpp 62 | 63 | #endif // RCLCPP__PARAMETER_SERVICE_HPP_ 64 | -------------------------------------------------------------------------------- /rclcpp/include/rclcpp/scope_exit.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2015 Open Source Robotics Foundation, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Based on: http://the-witness.net/news/2012/11/scopeexit-in-c11/ 16 | // But I changed the lambda to include by reference rather than value, see: 17 | // http://the-witness.net/news/2012/11/scopeexit-in-c11/comment-page-1/#comment-86873 18 | 19 | #ifndef RCLCPP__SCOPE_EXIT_HPP_ 20 | #define RCLCPP__SCOPE_EXIT_HPP_ 21 | 22 | #include 23 | 24 | #include "rclcpp/macros.hpp" 25 | 26 | namespace rclcpp 27 | { 28 | 29 | template 30 | struct ScopeExit 31 | { 32 | explicit ScopeExit(Callable callable) 33 | : callable_(callable) {} 34 | ~ScopeExit() {callable_();} 35 | 36 | private: 37 | Callable callable_; 38 | }; 39 | 40 | template 41 | ScopeExit 42 | make_scope_exit(Callable callable) 43 | { 44 | return ScopeExit(callable); 45 | } 46 | 47 | } // namespace rclcpp 48 | 49 | #define RCLCPP_SCOPE_EXIT(code) \ 50 | auto RCLCPP_STRING_JOIN(scope_exit_, __LINE__) = rclcpp::make_scope_exit([&]() {code;}) 51 | 52 | #endif // RCLCPP__SCOPE_EXIT_HPP_ 53 | -------------------------------------------------------------------------------- /rclcpp/include/rclcpp/subscription_wait_set_mask.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Open Source Robotics Foundation, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef RCLCPP__SUBSCRIPTION_WAIT_SET_MASK_HPP_ 16 | #define RCLCPP__SUBSCRIPTION_WAIT_SET_MASK_HPP_ 17 | 18 | #include "rclcpp/visibility_control.hpp" 19 | 20 | namespace rclcpp 21 | { 22 | 23 | /// Options used to determine what parts of a subscription get added to or removed from a wait set. 24 | class RCLCPP_PUBLIC SubscriptionWaitSetMask 25 | { 26 | public: 27 | /// If true, include the actual subscription. 28 | bool include_subscription = true; 29 | /// If true, include any events attached to the subscription. 30 | bool include_events = true; 31 | /// If true, include the waitable used to handle intra process communication. 32 | bool include_intra_process_waitable = true; 33 | }; 34 | 35 | } // namespace rclcpp 36 | 37 | #endif // RCLCPP__SUBSCRIPTION_WAIT_SET_MASK_HPP_ 38 | -------------------------------------------------------------------------------- /rclcpp/include/rclcpp/topic_statistics_state.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2019 Open Source Robotics Foundation, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef RCLCPP__TOPIC_STATISTICS_STATE_HPP_ 16 | #define RCLCPP__TOPIC_STATISTICS_STATE_HPP_ 17 | 18 | namespace rclcpp 19 | { 20 | 21 | /// Represent the state of topic statistics collector. 22 | /// Used as argument in create_subscriber. 23 | enum class TopicStatisticsState 24 | { 25 | /// Explicitly enable topic statistics at subscription level. 26 | Enable, 27 | /// Explicitly disable topic statistics at subscription level. 28 | Disable, 29 | /// Take topic statistics state from the node. 30 | NodeDefault 31 | }; 32 | 33 | } // namespace rclcpp 34 | 35 | #endif // RCLCPP__TOPIC_STATISTICS_STATE_HPP_ 36 | -------------------------------------------------------------------------------- /rclcpp/include/rclcpp/type_support_decl.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2014 Open Source Robotics Foundation, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef RCLCPP__TYPE_SUPPORT_DECL_HPP_ 16 | #define RCLCPP__TYPE_SUPPORT_DECL_HPP_ 17 | 18 | #include "rosidl_runtime_cpp/message_type_support_decl.hpp" 19 | #include "rosidl_runtime_cpp/service_type_support_decl.hpp" 20 | 21 | #include "rosidl_typesupport_cpp/message_type_support.hpp" 22 | #include "rosidl_typesupport_cpp/service_type_support.hpp" 23 | 24 | #include "rclcpp/visibility_control.hpp" 25 | 26 | namespace rclcpp 27 | { 28 | namespace type_support 29 | { 30 | 31 | RCLCPP_PUBLIC 32 | const rosidl_message_type_support_t * 33 | get_intra_process_message_msg_type_support(); 34 | 35 | RCLCPP_PUBLIC 36 | const rosidl_message_type_support_t * 37 | get_parameter_event_msg_type_support(); 38 | 39 | RCLCPP_PUBLIC 40 | const rosidl_message_type_support_t * 41 | get_set_parameters_result_msg_type_support(); 42 | 43 | RCLCPP_PUBLIC 44 | const rosidl_message_type_support_t * 45 | get_parameter_descriptor_msg_type_support(); 46 | 47 | RCLCPP_PUBLIC 48 | const rosidl_message_type_support_t * 49 | get_list_parameters_result_msg_type_support(); 50 | 51 | RCLCPP_PUBLIC 52 | const rosidl_service_type_support_t * 53 | get_get_parameters_srv_type_support(); 54 | 55 | RCLCPP_PUBLIC 56 | const rosidl_service_type_support_t * 57 | get_get_parameter_types_srv_type_support(); 58 | 59 | RCLCPP_PUBLIC 60 | const rosidl_service_type_support_t * 61 | get_set_parameters_srv_type_support(); 62 | 63 | RCLCPP_PUBLIC 64 | const rosidl_service_type_support_t * 65 | get_list_parameters_srv_type_support(); 66 | 67 | RCLCPP_PUBLIC 68 | const rosidl_service_type_support_t * 69 | get_describe_parameters_srv_type_support(); 70 | 71 | RCLCPP_PUBLIC 72 | const rosidl_service_type_support_t * 73 | get_set_parameters_atomically_srv_type_support(); 74 | 75 | } // namespace type_support 76 | } // namespace rclcpp 77 | 78 | #endif // RCLCPP__TYPE_SUPPORT_DECL_HPP_ 79 | -------------------------------------------------------------------------------- /rclcpp/include/rclcpp/typesupport_helpers.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2018, Bosch Software Innovations GmbH. 2 | // Copyright 2021, Apex.AI Inc. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | #ifndef RCLCPP__TYPESUPPORT_HELPERS_HPP_ 17 | #define RCLCPP__TYPESUPPORT_HELPERS_HPP_ 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | #include "rcpputils/shared_library.hpp" 24 | #include "rosidl_runtime_cpp/message_type_support_decl.hpp" 25 | 26 | #include "rclcpp/visibility_control.hpp" 27 | 28 | namespace rclcpp 29 | { 30 | /// Load the type support library for the given type. 31 | /** 32 | * \param[in] type The topic type, e.g. "std_msgs/msg/String" 33 | * \param[in] typesupport_identifier Type support identifier, typically "rosidl_typesupport_cpp" 34 | * \return A shared library 35 | */ 36 | RCLCPP_PUBLIC 37 | std::shared_ptr 38 | get_typesupport_library(const std::string & type, const std::string & typesupport_identifier); 39 | 40 | /// Extract the type support handle from the library. 41 | /** 42 | * The library needs to match the topic type. The shared library must stay loaded for the lifetime of the result. 43 | * \param[in] type The topic type, e.g. "std_msgs/msg/String" 44 | * \param[in] typesupport_identifier Type support identifier, typically "rosidl_typesupport_cpp" 45 | * \param[in] library The shared type support library 46 | * \return A type support handle 47 | */ 48 | RCLCPP_PUBLIC 49 | const rosidl_message_type_support_t * 50 | get_typesupport_handle( 51 | const std::string & type, 52 | const std::string & typesupport_identifier, 53 | rcpputils::SharedLibrary & library); 54 | 55 | } // namespace rclcpp 56 | 57 | #endif // RCLCPP__TYPESUPPORT_HELPERS_HPP_ 58 | -------------------------------------------------------------------------------- /rclcpp/include/rclcpp/visibility_control.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2015 Open Source Robotics Foundation, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | /* This header must be included by all rclcpp headers which declare symbols 16 | * which are defined in the rclcpp library. When not building the rclcpp 17 | * library, i.e. when using the headers in other package's code, the contents 18 | * of this header change the visibility of certain symbols which the rclcpp 19 | * library cannot have, but the consuming code must have inorder to link. 20 | */ 21 | 22 | #ifndef RCLCPP__VISIBILITY_CONTROL_HPP_ 23 | #define RCLCPP__VISIBILITY_CONTROL_HPP_ 24 | 25 | // This logic was borrowed (then namespaced) from the examples on the gcc wiki: 26 | // https://gcc.gnu.org/wiki/Visibility 27 | 28 | #if defined _WIN32 || defined __CYGWIN__ 29 | #ifdef __GNUC__ 30 | #define RCLCPP_EXPORT __attribute__ ((dllexport)) 31 | #define RCLCPP_IMPORT __attribute__ ((dllimport)) 32 | #else 33 | #define RCLCPP_EXPORT __declspec(dllexport) 34 | #define RCLCPP_IMPORT __declspec(dllimport) 35 | #endif 36 | #ifdef RCLCPP_BUILDING_LIBRARY 37 | #define RCLCPP_PUBLIC RCLCPP_EXPORT 38 | #else 39 | #define RCLCPP_PUBLIC RCLCPP_IMPORT 40 | #endif 41 | #define RCLCPP_PUBLIC_TYPE RCLCPP_PUBLIC 42 | #define RCLCPP_LOCAL 43 | #else 44 | #define RCLCPP_EXPORT __attribute__ ((visibility("default"))) 45 | #define RCLCPP_IMPORT 46 | #if __GNUC__ >= 4 47 | #define RCLCPP_PUBLIC __attribute__ ((visibility("default"))) 48 | #define RCLCPP_LOCAL __attribute__ ((visibility("hidden"))) 49 | #else 50 | #define RCLCPP_PUBLIC 51 | #define RCLCPP_LOCAL 52 | #endif 53 | #define RCLCPP_PUBLIC_TYPE 54 | #endif 55 | 56 | #endif // RCLCPP__VISIBILITY_CONTROL_HPP_ 57 | -------------------------------------------------------------------------------- /rclcpp/include/rclcpp/wait_result_kind.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Open Source Robotics Foundation, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef RCLCPP__WAIT_RESULT_KIND_HPP_ 16 | #define RCLCPP__WAIT_RESULT_KIND_HPP_ 17 | 18 | #include "rclcpp/visibility_control.hpp" 19 | 20 | namespace rclcpp 21 | { 22 | 23 | /// Represents the various kinds of results from waiting on a wait set. 24 | enum RCLCPP_PUBLIC WaitResultKind 25 | { 26 | Ready, // 19 | #include 20 | 21 | namespace rclcpp 22 | { 23 | namespace wait_set_policies 24 | { 25 | namespace detail 26 | { 27 | 28 | /// Common structure for synchronization policies. 29 | class SynchronizationPolicyCommon 30 | { 31 | protected: 32 | SynchronizationPolicyCommon() = default; 33 | ~SynchronizationPolicyCommon() = default; 34 | 35 | std::function 36 | create_loop_predicate( 37 | std::chrono::nanoseconds time_to_wait_ns, 38 | std::chrono::steady_clock::time_point start) 39 | { 40 | if (time_to_wait_ns >= std::chrono::nanoseconds(0)) { 41 | // If time_to_wait_ns is >= 0 schedule against a deadline. 42 | auto deadline = start + time_to_wait_ns; 43 | return [deadline]() -> bool {return std::chrono::steady_clock::now() < deadline;}; 44 | } else { 45 | // In the case of time_to_wait_ns < 0, just always return true to loop forever. 46 | return []() -> bool {return true;}; 47 | } 48 | } 49 | 50 | std::chrono::nanoseconds 51 | calculate_time_left_to_wait( 52 | std::chrono::nanoseconds original_time_to_wait_ns, 53 | std::chrono::steady_clock::time_point start) 54 | { 55 | std::chrono::nanoseconds time_left_to_wait; 56 | if (original_time_to_wait_ns < std::chrono::nanoseconds(0)) { 57 | time_left_to_wait = original_time_to_wait_ns; 58 | } else { 59 | time_left_to_wait = original_time_to_wait_ns - (std::chrono::steady_clock::now() - start); 60 | if (time_left_to_wait < std::chrono::nanoseconds(0)) { 61 | time_left_to_wait = std::chrono::nanoseconds(0); 62 | } 63 | } 64 | return time_left_to_wait; 65 | } 66 | }; 67 | 68 | } // namespace detail 69 | } // namespace wait_set_policies 70 | } // namespace rclcpp 71 | 72 | #endif // RCLCPP__WAIT_SET_POLICIES__DETAIL__SYNCHRONIZATION_POLICY_COMMON_HPP_ 73 | -------------------------------------------------------------------------------- /rclcpp/package.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | rclcpp 5 | 9.2.0 6 | The ROS client library in C++. 7 | Ivan Paunovic 8 | Mabel Zhang 9 | William Woodall 10 | Apache License 2.0 11 | Dirk Thomas 12 | 13 | ament_cmake_ros 14 | 15 | ament_index_cpp 16 | builtin_interfaces 17 | rcl_interfaces 18 | rosgraph_msgs 19 | rosidl_runtime_cpp 20 | rosidl_typesupport_c 21 | rosidl_typesupport_cpp 22 | ament_index_cpp 23 | builtin_interfaces 24 | rcl_interfaces 25 | rosgraph_msgs 26 | rosidl_runtime_cpp 27 | rosidl_typesupport_c 28 | rosidl_typesupport_cpp 29 | 30 | libstatistics_collector 31 | rcl 32 | rcl_yaml_param_parser 33 | rcpputils 34 | rcutils 35 | rmw 36 | statistics_msgs 37 | tracetools 38 | 39 | ament_cmake_gmock 40 | ament_cmake_gtest 41 | ament_lint_auto 42 | ament_lint_common 43 | mimick_vendor 44 | performance_test_fixture 45 | rmw 46 | rmw_implementation_cmake 47 | rosidl_default_generators 48 | test_msgs 49 | 50 | 51 | ament_cmake 52 | 53 | 54 | -------------------------------------------------------------------------------- /rclcpp/resource/interface_traits.hpp.em: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Open Source Robotics Foundation, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | @{ 15 | uppercase_interface_name = interface_name.upper() 16 | interface_typename = ''.join([part.capitalize() for part in interface_name.split('_')]) 17 | }@ 18 | 19 | #ifndef RCLCPP__NODE_INTERFACES__@(uppercase_interface_name)_TRAITS_HPP_ 20 | #define RCLCPP__NODE_INTERFACES__@(uppercase_interface_name)_TRAITS_HPP_ 21 | 22 | #include 23 | #include 24 | 25 | #include "rclcpp/node_interfaces/@(interface_name).hpp" 26 | 27 | namespace rclcpp 28 | { 29 | namespace node_interfaces 30 | { 31 | 32 | template 33 | struct has_@(interface_name) : std::false_type 34 | {}; 35 | 36 | template 37 | struct has_@(interface_name)< 38 | T, typename std::enable_if< 39 | std::is_same< 40 | std::shared_ptr, 41 | decltype(std::declval().get_@(interface_name)())>::value>::type> : std::true_type 42 | {}; 43 | 44 | } // namespace node_interfaces 45 | } // namespace rclcpp 46 | 47 | #endif // RCLCPP__NODE_INTERFACES__@(uppercase_interface_name)_TRAITS_HPP_ 48 | -------------------------------------------------------------------------------- /rclcpp/src/rclcpp/any_executable.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2015 Open Source Robotics Foundation, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "rclcpp/any_executable.hpp" 16 | 17 | using rclcpp::AnyExecutable; 18 | 19 | AnyExecutable::AnyExecutable() 20 | : subscription(nullptr), 21 | timer(nullptr), 22 | service(nullptr), 23 | client(nullptr), 24 | callback_group(nullptr), 25 | node_base(nullptr) 26 | {} 27 | 28 | AnyExecutable::~AnyExecutable() 29 | { 30 | // Make sure that discarded (taken but not executed) AnyExecutable's have 31 | // their callback groups reset. This can happen when an executor is canceled 32 | // between taking an AnyExecutable and executing it. 33 | if (callback_group) { 34 | callback_group->can_be_taken_from().store(true); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /rclcpp/src/rclcpp/contexts/default_context.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2015 Open Source Robotics Foundation, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "rclcpp/contexts/default_context.hpp" 16 | 17 | using rclcpp::contexts::DefaultContext; 18 | 19 | DefaultContext::DefaultContext() 20 | {} 21 | 22 | DefaultContext::SharedPtr 23 | rclcpp::contexts::get_global_default_context() 24 | { 25 | static DefaultContext::SharedPtr default_context = DefaultContext::make_shared(); 26 | return default_context; 27 | } 28 | -------------------------------------------------------------------------------- /rclcpp/src/rclcpp/detail/mutex_two_priorities.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Open Source Robotics Foundation, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "rclcpp/detail/mutex_two_priorities.hpp" 16 | 17 | #include 18 | 19 | namespace rclcpp 20 | { 21 | namespace detail 22 | { 23 | 24 | using LowPriorityLockable = MutexTwoPriorities::LowPriorityLockable; 25 | using HighPriorityLockable = MutexTwoPriorities::HighPriorityLockable; 26 | 27 | HighPriorityLockable::HighPriorityLockable(MutexTwoPriorities & parent) 28 | : parent_(parent) 29 | {} 30 | 31 | void 32 | HighPriorityLockable::lock() 33 | { 34 | std::unique_lock guard{parent_.cv_mutex_}; 35 | if (parent_.data_taken_) { 36 | ++parent_.hp_waiting_count_; 37 | while (parent_.data_taken_) { 38 | parent_.hp_cv_.wait(guard); 39 | } 40 | --parent_.hp_waiting_count_; 41 | } 42 | parent_.data_taken_ = true; 43 | } 44 | 45 | void 46 | HighPriorityLockable::unlock() 47 | { 48 | bool notify_lp{false}; 49 | { 50 | std::lock_guard guard{parent_.cv_mutex_}; 51 | parent_.data_taken_ = false; 52 | notify_lp = 0u == parent_.hp_waiting_count_; 53 | } 54 | if (notify_lp) { 55 | parent_.lp_cv_.notify_one(); 56 | } else { 57 | parent_.hp_cv_.notify_one(); 58 | } 59 | } 60 | 61 | LowPriorityLockable::LowPriorityLockable(MutexTwoPriorities & parent) 62 | : parent_(parent) 63 | {} 64 | 65 | void 66 | LowPriorityLockable::lock() 67 | { 68 | std::unique_lock guard{parent_.cv_mutex_}; 69 | while (parent_.data_taken_ || parent_.hp_waiting_count_) { 70 | parent_.lp_cv_.wait(guard); 71 | } 72 | parent_.data_taken_ = true; 73 | } 74 | 75 | void 76 | LowPriorityLockable::unlock() 77 | { 78 | bool notify_lp{false}; 79 | { 80 | std::lock_guard guard{parent_.cv_mutex_}; 81 | parent_.data_taken_ = false; 82 | notify_lp = 0u == parent_.hp_waiting_count_; 83 | } 84 | if (notify_lp) { 85 | parent_.lp_cv_.notify_one(); 86 | } else { 87 | parent_.hp_cv_.notify_one(); 88 | } 89 | } 90 | 91 | HighPriorityLockable 92 | MutexTwoPriorities::get_high_priority_lockable() 93 | { 94 | return HighPriorityLockable{*this}; 95 | } 96 | 97 | LowPriorityLockable 98 | MutexTwoPriorities::get_low_priority_lockable() 99 | { 100 | return LowPriorityLockable{*this}; 101 | } 102 | 103 | } // namespace detail 104 | } // namespace rclcpp 105 | -------------------------------------------------------------------------------- /rclcpp/src/rclcpp/detail/resolve_parameter_overrides.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Open Source Robotics Foundation, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef RCLCPP__DETAIL__RESOLVE_PARAMETER_OVERRIDES_HPP_ 16 | #define RCLCPP__DETAIL__RESOLVE_PARAMETER_OVERRIDES_HPP_ 17 | 18 | #include 19 | #include 20 | #include 21 | 22 | #include "rcl/arguments.h" 23 | 24 | #include "rclcpp/parameter.hpp" 25 | #include "rclcpp/parameter_value.hpp" 26 | #include "rclcpp/visibility_control.hpp" 27 | 28 | namespace rclcpp 29 | { 30 | namespace detail 31 | { 32 | /// \internal Get the parameter overrides from the arguments. 33 | RCLCPP_LOCAL 34 | std::map 35 | resolve_parameter_overrides( 36 | const std::string & node_name, 37 | const std::vector & parameter_overrides, 38 | const rcl_arguments_t * local_args, 39 | const rcl_arguments_t * global_args); 40 | 41 | } // namespace detail 42 | } // namespace rclcpp 43 | 44 | #endif // RCLCPP__DETAIL__RESOLVE_PARAMETER_OVERRIDES_HPP_ 45 | -------------------------------------------------------------------------------- /rclcpp/src/rclcpp/detail/rmw_implementation_specific_payload.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2019 Open Source Robotics Foundation, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | 17 | namespace rclcpp 18 | { 19 | namespace detail 20 | { 21 | 22 | bool 23 | RMWImplementationSpecificPayload::has_been_customized() const 24 | { 25 | return nullptr != this->get_implementation_identifier(); 26 | } 27 | 28 | const char * 29 | RMWImplementationSpecificPayload::get_implementation_identifier() const 30 | { 31 | return nullptr; 32 | } 33 | 34 | } // namespace detail 35 | } // namespace rclcpp 36 | -------------------------------------------------------------------------------- /rclcpp/src/rclcpp/detail/rmw_implementation_specific_publisher_payload.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2019 Open Source Robotics Foundation, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | 17 | #include "rcl/publisher.h" 18 | 19 | namespace rclcpp 20 | { 21 | namespace detail 22 | { 23 | 24 | void 25 | RMWImplementationSpecificPublisherPayload::modify_rmw_publisher_options( 26 | rmw_publisher_options_t & rmw_publisher_options) const 27 | { 28 | // By default, do not mutate the rmw publisher options. 29 | (void)rmw_publisher_options; 30 | } 31 | 32 | } // namespace detail 33 | } // namespace rclcpp 34 | -------------------------------------------------------------------------------- /rclcpp/src/rclcpp/detail/rmw_implementation_specific_subscription_payload.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2019 Open Source Robotics Foundation, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | 17 | #include "rcl/subscription.h" 18 | 19 | namespace rclcpp 20 | { 21 | namespace detail 22 | { 23 | 24 | void 25 | RMWImplementationSpecificSubscriptionPayload::modify_rmw_subscription_options( 26 | rmw_subscription_options_t & rmw_subscription_options) const 27 | { 28 | // By default, do not mutate the rmw subscription options. 29 | (void)rmw_subscription_options; 30 | } 31 | 32 | } // namespace detail 33 | } // namespace rclcpp 34 | -------------------------------------------------------------------------------- /rclcpp/src/rclcpp/detail/utilities.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2019 Open Source Robotics Foundation, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "rclcpp/detail/utilities.hpp" 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | #include "rclcpp/exceptions.hpp" 23 | 24 | #include "rcl/allocator.h" 25 | #include "rcl/arguments.h" 26 | 27 | namespace rclcpp 28 | { 29 | namespace detail 30 | { 31 | 32 | std::vector 33 | get_unparsed_ros_arguments( 34 | int argc, char const * const argv[], 35 | rcl_arguments_t * arguments, 36 | rcl_allocator_t allocator) 37 | { 38 | (void)argc; 39 | std::vector unparsed_ros_arguments; 40 | int unparsed_ros_args_count = rcl_arguments_get_count_unparsed_ros(arguments); 41 | if (unparsed_ros_args_count > 0) { 42 | int * unparsed_ros_args_indices = nullptr; 43 | rcl_ret_t ret = 44 | rcl_arguments_get_unparsed_ros(arguments, allocator, &unparsed_ros_args_indices); 45 | if (RCL_RET_OK != ret) { 46 | rclcpp::exceptions::throw_from_rcl_error(ret, "failed to get unparsed ROS arguments"); 47 | } 48 | try { 49 | for (int i = 0; i < unparsed_ros_args_count; ++i) { 50 | assert(unparsed_ros_args_indices[i] >= 0); 51 | assert(unparsed_ros_args_indices[i] < argc); 52 | unparsed_ros_arguments.push_back(argv[unparsed_ros_args_indices[i]]); 53 | } 54 | allocator.deallocate(unparsed_ros_args_indices, allocator.state); 55 | } catch (...) { 56 | allocator.deallocate(unparsed_ros_args_indices, allocator.state); 57 | throw; 58 | } 59 | } 60 | return unparsed_ros_arguments; 61 | } 62 | 63 | } // namespace detail 64 | } // namespace rclcpp 65 | -------------------------------------------------------------------------------- /rclcpp/src/rclcpp/event.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Open Source Robotics Foundation, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "rclcpp/event.hpp" 16 | 17 | namespace rclcpp 18 | { 19 | 20 | Event::Event() 21 | : state_(false) {} 22 | 23 | bool 24 | Event::set() 25 | { 26 | return state_.exchange(true); 27 | } 28 | 29 | bool 30 | Event::check() 31 | { 32 | return state_.load(); 33 | } 34 | 35 | bool 36 | Event::check_and_clear() 37 | { 38 | return state_.exchange(false); 39 | } 40 | 41 | } // namespace rclcpp 42 | -------------------------------------------------------------------------------- /rclcpp/src/rclcpp/executable_list.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2019 Nobleo Technology 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | 17 | #include "rclcpp/experimental/executable_list.hpp" 18 | 19 | using rclcpp::experimental::ExecutableList; 20 | 21 | ExecutableList::ExecutableList() 22 | : number_of_subscriptions(0), 23 | number_of_timers(0), 24 | number_of_services(0), 25 | number_of_clients(0), 26 | number_of_waitables(0) 27 | {} 28 | 29 | ExecutableList::~ExecutableList() 30 | {} 31 | 32 | void 33 | ExecutableList::clear() 34 | { 35 | this->timer.clear(); 36 | this->number_of_timers = 0; 37 | 38 | this->subscription.clear(); 39 | this->number_of_subscriptions = 0; 40 | 41 | this->service.clear(); 42 | this->number_of_services = 0; 43 | 44 | this->client.clear(); 45 | this->number_of_clients = 0; 46 | 47 | this->waitable.clear(); 48 | this->number_of_waitables = 0; 49 | } 50 | 51 | void 52 | ExecutableList::add_subscription(rclcpp::SubscriptionBase::SharedPtr subscription) 53 | { 54 | this->subscription.push_back(std::move(subscription)); 55 | this->number_of_subscriptions++; 56 | } 57 | 58 | void 59 | ExecutableList::add_timer(rclcpp::TimerBase::SharedPtr timer) 60 | { 61 | this->timer.push_back(std::move(timer)); 62 | this->number_of_timers++; 63 | } 64 | 65 | void 66 | ExecutableList::add_service(rclcpp::ServiceBase::SharedPtr service) 67 | { 68 | this->service.push_back(std::move(service)); 69 | this->number_of_services++; 70 | } 71 | 72 | void 73 | ExecutableList::add_client(rclcpp::ClientBase::SharedPtr client) 74 | { 75 | this->client.push_back(std::move(client)); 76 | this->number_of_clients++; 77 | } 78 | 79 | void 80 | ExecutableList::add_waitable(rclcpp::Waitable::SharedPtr waitable) 81 | { 82 | this->waitable.push_back(std::move(waitable)); 83 | this->number_of_waitables++; 84 | } 85 | -------------------------------------------------------------------------------- /rclcpp/src/rclcpp/executors.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2015 Open Source Robotics Foundation, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "rclcpp/executors.hpp" 16 | 17 | void 18 | rclcpp::spin_some(rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_ptr) 19 | { 20 | rclcpp::executors::SingleThreadedExecutor exec; 21 | exec.spin_node_some(node_ptr); 22 | } 23 | 24 | void 25 | rclcpp::spin_some(rclcpp::Node::SharedPtr node_ptr) 26 | { 27 | rclcpp::spin_some(node_ptr->get_node_base_interface()); 28 | } 29 | 30 | void 31 | rclcpp::spin(rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_ptr) 32 | { 33 | rclcpp::executors::SingleThreadedExecutor exec; 34 | exec.add_node(node_ptr); 35 | exec.spin(); 36 | exec.remove_node(node_ptr); 37 | } 38 | 39 | void 40 | rclcpp::spin(rclcpp::Node::SharedPtr node_ptr) 41 | { 42 | rclcpp::spin(node_ptr->get_node_base_interface()); 43 | } 44 | -------------------------------------------------------------------------------- /rclcpp/src/rclcpp/future_return_code.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2015 Open Source Robotics Foundation, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | #include 17 | #include 18 | 19 | #include "rclcpp/future_return_code.hpp" 20 | 21 | namespace rclcpp 22 | { 23 | 24 | std::ostream & 25 | operator<<(std::ostream & os, const rclcpp::FutureReturnCode & future_return_code) 26 | { 27 | return os << to_string(future_return_code); 28 | } 29 | 30 | std::string 31 | to_string(const rclcpp::FutureReturnCode & future_return_code) 32 | { 33 | using enum_type = std::underlying_type::type; 34 | std::string prefix = "Unknown enum value ("; 35 | std::string ret_as_string = std::to_string(static_cast(future_return_code)); 36 | switch (future_return_code) { 37 | case FutureReturnCode::SUCCESS: 38 | prefix = "SUCCESS ("; 39 | break; 40 | case FutureReturnCode::INTERRUPTED: 41 | prefix = "INTERRUPTED ("; 42 | break; 43 | case FutureReturnCode::TIMEOUT: 44 | prefix = "TIMEOUT ("; 45 | break; 46 | } 47 | return prefix + ret_as_string + ")"; 48 | } 49 | 50 | } // namespace rclcpp 51 | -------------------------------------------------------------------------------- /rclcpp/src/rclcpp/generic_publisher.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2018, Bosch Software Innovations GmbH. 2 | // Copyright 2021, Apex.AI Inc. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | #include "rclcpp/generic_publisher.hpp" 17 | 18 | #include 19 | #include 20 | 21 | namespace rclcpp 22 | { 23 | 24 | void GenericPublisher::publish(const rclcpp::SerializedMessage & message) 25 | { 26 | auto return_code = rcl_publish_serialized_message( 27 | get_publisher_handle().get(), &message.get_rcl_serialized_message(), NULL); 28 | 29 | if (return_code != RCL_RET_OK) { 30 | rclcpp::exceptions::throw_from_rcl_error(return_code, "failed to publish serialized message"); 31 | } 32 | } 33 | 34 | } // namespace rclcpp 35 | -------------------------------------------------------------------------------- /rclcpp/src/rclcpp/generic_subscription.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2018, Bosch Software Innovations GmbH. 2 | // Copyright 2021, Apex.AI Inc. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | #include "rclcpp/generic_subscription.hpp" 17 | 18 | #include 19 | #include 20 | 21 | #include "rcl/subscription.h" 22 | 23 | #include "rclcpp/exceptions.hpp" 24 | 25 | namespace rclcpp 26 | { 27 | 28 | std::shared_ptr GenericSubscription::create_message() 29 | { 30 | return create_serialized_message(); 31 | } 32 | 33 | std::shared_ptr GenericSubscription::create_serialized_message() 34 | { 35 | return std::make_shared(0); 36 | } 37 | 38 | void GenericSubscription::handle_message( 39 | std::shared_ptr & message, const rclcpp::MessageInfo & message_info) 40 | { 41 | (void) message_info; 42 | auto typed_message = std::static_pointer_cast(message); 43 | callback_(typed_message); 44 | } 45 | 46 | void GenericSubscription::handle_loaned_message( 47 | void * message, const rclcpp::MessageInfo & message_info) 48 | { 49 | (void) message; 50 | (void) message_info; 51 | throw rclcpp::exceptions::UnimplementedError( 52 | "handle_loaned_message is not implemented for GenericSubscription"); 53 | } 54 | 55 | void GenericSubscription::return_message(std::shared_ptr & message) 56 | { 57 | auto typed_message = std::static_pointer_cast(message); 58 | return_serialized_message(typed_message); 59 | } 60 | 61 | void GenericSubscription::return_serialized_message( 62 | std::shared_ptr & message) 63 | { 64 | message.reset(); 65 | } 66 | 67 | } // namespace rclcpp 68 | -------------------------------------------------------------------------------- /rclcpp/src/rclcpp/guard_condition.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Open Source Robotics Foundation, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "rclcpp/guard_condition.hpp" 16 | 17 | #include "rclcpp/exceptions.hpp" 18 | #include "rclcpp/logging.hpp" 19 | 20 | namespace rclcpp 21 | { 22 | 23 | GuardCondition::GuardCondition(rclcpp::Context::SharedPtr context) 24 | : context_(context), rcl_guard_condition_{rcl_get_zero_initialized_guard_condition()} 25 | { 26 | if (!context_) { 27 | throw std::invalid_argument("context argument unexpectedly nullptr"); 28 | } 29 | rcl_guard_condition_options_t guard_condition_options = rcl_guard_condition_get_default_options(); 30 | rcl_ret_t ret = rcl_guard_condition_init( 31 | &this->rcl_guard_condition_, 32 | context_->get_rcl_context().get(), 33 | guard_condition_options); 34 | if (RCL_RET_OK != ret) { 35 | rclcpp::exceptions::throw_from_rcl_error(ret); 36 | } 37 | } 38 | 39 | GuardCondition::~GuardCondition() 40 | { 41 | rcl_ret_t ret = rcl_guard_condition_fini(&this->rcl_guard_condition_); 42 | if (RCL_RET_OK != ret) { 43 | try { 44 | rclcpp::exceptions::throw_from_rcl_error(ret); 45 | } catch (const std::exception & exception) { 46 | RCLCPP_ERROR( 47 | rclcpp::get_logger("rclcpp"), 48 | "Error in destruction of rcl guard condition: %s", exception.what()); 49 | } 50 | } 51 | } 52 | 53 | rclcpp::Context::SharedPtr 54 | GuardCondition::get_context() const 55 | { 56 | return context_; 57 | } 58 | 59 | const rcl_guard_condition_t & 60 | GuardCondition::get_rcl_guard_condition() const 61 | { 62 | return rcl_guard_condition_; 63 | } 64 | 65 | void 66 | GuardCondition::trigger() 67 | { 68 | rcl_ret_t ret = rcl_trigger_guard_condition(&rcl_guard_condition_); 69 | if (RCL_RET_OK != ret) { 70 | rclcpp::exceptions::throw_from_rcl_error(ret); 71 | } 72 | } 73 | 74 | bool 75 | GuardCondition::exchange_in_use_by_wait_set_state(bool in_use_state) 76 | { 77 | return in_use_by_wait_set_.exchange(in_use_state); 78 | } 79 | 80 | } // namespace rclcpp 81 | -------------------------------------------------------------------------------- /rclcpp/src/rclcpp/logger.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Open Source Robotics Foundation, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | 17 | #include "rcl_logging_interface/rcl_logging_interface.h" 18 | 19 | #include "rclcpp/exceptions.hpp" 20 | #include "rclcpp/logger.hpp" 21 | #include "rclcpp/logging.hpp" 22 | 23 | namespace rclcpp 24 | { 25 | 26 | Logger 27 | get_logger(const std::string & name) 28 | { 29 | #if RCLCPP_LOGGING_ENABLED 30 | return rclcpp::Logger(name); 31 | #else 32 | (void)name; 33 | return rclcpp::Logger(); 34 | #endif 35 | } 36 | 37 | Logger 38 | get_node_logger(const rcl_node_t * node) 39 | { 40 | const char * logger_name = rcl_node_get_logger_name(node); 41 | if (nullptr == logger_name) { 42 | auto logger = rclcpp::get_logger("rclcpp"); 43 | RCLCPP_ERROR( 44 | logger, "failed to get logger name from node at address %p", 45 | static_cast(const_cast(node))); 46 | return logger; 47 | } 48 | return rclcpp::get_logger(logger_name); 49 | } 50 | 51 | rcpputils::fs::path 52 | get_logging_directory() 53 | { 54 | char * log_dir = NULL; 55 | auto allocator = rcutils_get_default_allocator(); 56 | rcl_logging_ret_t ret = rcl_logging_get_logging_directory(allocator, &log_dir); 57 | if (RCL_LOGGING_RET_OK != ret) { 58 | rclcpp::exceptions::throw_from_rcl_error(ret); 59 | } 60 | std::string path{log_dir}; 61 | allocator.deallocate(log_dir, allocator.state); 62 | return path; 63 | } 64 | 65 | void 66 | Logger::set_level(Level level) 67 | { 68 | rcutils_ret_t rcutils_ret = rcutils_logging_set_logger_level( 69 | get_name(), 70 | static_cast(level)); 71 | if (rcutils_ret != RCUTILS_RET_OK) { 72 | if (rcutils_ret == RCUTILS_RET_INVALID_ARGUMENT) { 73 | exceptions::throw_from_rcl_error( 74 | RCL_RET_INVALID_ARGUMENT, "Invalid parameter", 75 | rcutils_get_error_state(), rcutils_reset_error); 76 | } 77 | exceptions::throw_from_rcl_error( 78 | RCL_RET_ERROR, "Couldn't set logger level", 79 | rcutils_get_error_state(), rcutils_reset_error); 80 | } 81 | } 82 | 83 | } // namespace rclcpp 84 | -------------------------------------------------------------------------------- /rclcpp/src/rclcpp/logging_mutex.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Open Source Robotics Foundation, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | #include 17 | 18 | #include "rcutils/macros.h" 19 | 20 | #include "./logging_mutex.hpp" 21 | 22 | std::shared_ptr 23 | get_global_logging_mutex() 24 | { 25 | static auto mutex = std::make_shared(); 26 | if (RCUTILS_UNLIKELY(!mutex)) { 27 | throw std::runtime_error("rclcpp global logging mutex is a nullptr"); 28 | } 29 | return mutex; 30 | } 31 | -------------------------------------------------------------------------------- /rclcpp/src/rclcpp/logging_mutex.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Open Source Robotics Foundation, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef RCLCPP__LOGGING_MUTEX_HPP_ 16 | #define RCLCPP__LOGGING_MUTEX_HPP_ 17 | 18 | #include 19 | #include 20 | 21 | #include "rclcpp/visibility_control.hpp" 22 | 23 | /// Global logging mutex 24 | /** 25 | * This mutex is locked in the following situations: 26 | * - In initialization/destruction of contexts. 27 | * - In initialization/destruction of nodes. 28 | * - In the rcl logging output handler installed by rclcpp, 29 | * i.e.: in all calls to the logger macros, including RCUTILS_* ones. 30 | */ 31 | // Implementation detail: 32 | // A shared pointer to the mutex is used, so that objects that need to use 33 | // it at destruction time can hold it alive. 34 | // In that way, a destruction ordering problem between static objects is avoided. 35 | RCLCPP_LOCAL 36 | std::shared_ptr 37 | get_global_logging_mutex(); 38 | 39 | #endif // RCLCPP__LOGGING_MUTEX_HPP_ 40 | -------------------------------------------------------------------------------- /rclcpp/src/rclcpp/memory_strategies.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2015 Open Source Robotics Foundation, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "rclcpp/memory_strategies.hpp" 16 | 17 | #include 18 | 19 | #include "rclcpp/strategies/allocator_memory_strategy.hpp" 20 | 21 | using rclcpp::memory_strategies::allocator_memory_strategy::AllocatorMemoryStrategy; 22 | 23 | rclcpp::memory_strategy::MemoryStrategy::SharedPtr 24 | rclcpp::memory_strategies::create_default_strategy() 25 | { 26 | return std::make_shared>(); 27 | } 28 | -------------------------------------------------------------------------------- /rclcpp/src/rclcpp/message_info.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Open Source Robotics Foundation, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "rclcpp/message_info.hpp" 16 | 17 | namespace rclcpp 18 | { 19 | 20 | MessageInfo::MessageInfo(const rmw_message_info_t & rmw_message_info) 21 | : rmw_message_info_(rmw_message_info) 22 | {} 23 | 24 | MessageInfo::~MessageInfo() 25 | {} 26 | 27 | const rmw_message_info_t & 28 | MessageInfo::get_rmw_message_info() const 29 | { 30 | return rmw_message_info_; 31 | } 32 | 33 | rmw_message_info_t & 34 | MessageInfo::get_rmw_message_info() 35 | { 36 | return rmw_message_info_; 37 | } 38 | 39 | } // namespace rclcpp 40 | -------------------------------------------------------------------------------- /rclcpp/src/rclcpp/network_flow_endpoint.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Ericsson AB 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | 17 | #include "rclcpp/network_flow_endpoint.hpp" 18 | 19 | namespace rclcpp 20 | { 21 | 22 | const std::string & 23 | NetworkFlowEndpoint::transport_protocol() const 24 | { 25 | return transport_protocol_; 26 | } 27 | 28 | const std::string & 29 | NetworkFlowEndpoint::internet_protocol() const 30 | { 31 | return internet_protocol_; 32 | } 33 | 34 | uint16_t NetworkFlowEndpoint::transport_port() const 35 | { 36 | return transport_port_; 37 | } 38 | 39 | uint32_t NetworkFlowEndpoint::flow_label() const 40 | { 41 | return flow_label_; 42 | } 43 | 44 | uint8_t NetworkFlowEndpoint::dscp() const 45 | { 46 | return dscp_; 47 | } 48 | 49 | const std::string & 50 | NetworkFlowEndpoint::internet_address() const 51 | { 52 | return internet_address_; 53 | } 54 | 55 | bool operator==(const NetworkFlowEndpoint & left, const NetworkFlowEndpoint & right) 56 | { 57 | return left.transport_protocol_ == right.transport_protocol_ && 58 | left.internet_protocol_ == right.internet_protocol_ && 59 | left.transport_port_ == right.transport_port_ && 60 | left.flow_label_ == right.flow_label_ && 61 | left.dscp_ == right.dscp_ && 62 | left.internet_address_ == right.internet_address_; 63 | } 64 | 65 | bool operator!=(const NetworkFlowEndpoint & left, const NetworkFlowEndpoint & right) 66 | { 67 | return !(left == right); 68 | } 69 | 70 | std::ostream & operator<<(std::ostream & os, const NetworkFlowEndpoint & network_flow_endpoint) 71 | { 72 | // Stream out in JSON-like format 73 | os << "{" << 74 | "\"transportProtocol\": \"" << network_flow_endpoint.transport_protocol_ << "\", " << 75 | "\"internetProtocol\": \"" << network_flow_endpoint.internet_protocol_ << "\", " << 76 | "\"transportPort\": \"" << network_flow_endpoint.transport_port_ << "\", " << 77 | "\"flowLabel\": \"" << std::to_string(network_flow_endpoint.flow_label_) << "\", " << 78 | "\"dscp\": \"" << std::to_string(network_flow_endpoint.dscp_) << "\", " << 79 | "\"internetAddress\": \"" << network_flow_endpoint.internet_address_ << "\"" << 80 | "}"; 81 | return os; 82 | } 83 | 84 | } // namespace rclcpp 85 | -------------------------------------------------------------------------------- /rclcpp/src/rclcpp/node_interfaces/node_clock.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Open Source Robotics Foundation, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "rclcpp/node_interfaces/node_clock.hpp" 16 | 17 | #include 18 | #include 19 | 20 | using rclcpp::node_interfaces::NodeClock; 21 | 22 | NodeClock::NodeClock( 23 | rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_base, 24 | rclcpp::node_interfaces::NodeTopicsInterface::SharedPtr node_topics, 25 | rclcpp::node_interfaces::NodeGraphInterface::SharedPtr node_graph, 26 | rclcpp::node_interfaces::NodeServicesInterface::SharedPtr node_services, 27 | rclcpp::node_interfaces::NodeLoggingInterface::SharedPtr node_logging) 28 | : node_base_(node_base), 29 | node_topics_(node_topics), 30 | node_graph_(node_graph), 31 | node_services_(node_services), 32 | node_logging_(node_logging), 33 | ros_clock_(std::make_shared(RCL_ROS_TIME)) 34 | {} 35 | 36 | NodeClock::~NodeClock() 37 | {} 38 | 39 | rclcpp::Clock::SharedPtr 40 | NodeClock::get_clock() 41 | { 42 | return ros_clock_; 43 | } 44 | 45 | rclcpp::Clock::ConstSharedPtr 46 | NodeClock::get_clock() const 47 | { 48 | return ros_clock_; 49 | } 50 | -------------------------------------------------------------------------------- /rclcpp/src/rclcpp/node_interfaces/node_logging.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Open Source Robotics Foundation, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "rclcpp/node_interfaces/node_logging.hpp" 16 | 17 | using rclcpp::node_interfaces::NodeLogging; 18 | 19 | NodeLogging::NodeLogging(rclcpp::node_interfaces::NodeBaseInterface * node_base) 20 | : node_base_(node_base) 21 | { 22 | logger_ = rclcpp::get_logger(this->get_logger_name()); 23 | } 24 | 25 | NodeLogging::~NodeLogging() 26 | { 27 | } 28 | 29 | rclcpp::Logger 30 | NodeLogging::get_logger() const 31 | { 32 | return logger_; 33 | } 34 | 35 | const char * 36 | NodeLogging::get_logger_name() const 37 | { 38 | return rcl_node_get_logger_name(node_base_->get_rcl_node_handle()); 39 | } 40 | -------------------------------------------------------------------------------- /rclcpp/src/rclcpp/node_interfaces/node_time_source.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Open Source Robotics Foundation, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "rclcpp/node_interfaces/node_time_source.hpp" 16 | 17 | #include 18 | #include 19 | 20 | using rclcpp::node_interfaces::NodeTimeSource; 21 | 22 | NodeTimeSource::NodeTimeSource( 23 | rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_base, 24 | rclcpp::node_interfaces::NodeTopicsInterface::SharedPtr node_topics, 25 | rclcpp::node_interfaces::NodeGraphInterface::SharedPtr node_graph, 26 | rclcpp::node_interfaces::NodeServicesInterface::SharedPtr node_services, 27 | rclcpp::node_interfaces::NodeLoggingInterface::SharedPtr node_logging, 28 | rclcpp::node_interfaces::NodeClockInterface::SharedPtr node_clock, 29 | rclcpp::node_interfaces::NodeParametersInterface::SharedPtr node_parameters, 30 | const rclcpp::QoS & qos, 31 | bool use_clock_thread) 32 | : node_base_(node_base), 33 | node_topics_(node_topics), 34 | node_graph_(node_graph), 35 | node_services_(node_services), 36 | node_logging_(node_logging), 37 | node_clock_(node_clock), 38 | node_parameters_(node_parameters), 39 | time_source_(qos, use_clock_thread) 40 | { 41 | time_source_.attachNode( 42 | node_base_, 43 | node_topics_, 44 | node_graph_, 45 | node_services_, 46 | node_logging_, 47 | node_clock_, 48 | node_parameters_); 49 | time_source_.attachClock(node_clock_->get_clock()); 50 | } 51 | 52 | NodeTimeSource::~NodeTimeSource() 53 | {} 54 | -------------------------------------------------------------------------------- /rclcpp/src/rclcpp/node_interfaces/node_timers.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Open Source Robotics Foundation, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "rclcpp/node_interfaces/node_timers.hpp" 16 | 17 | #include 18 | 19 | #include "tracetools/tracetools.h" 20 | 21 | using rclcpp::node_interfaces::NodeTimers; 22 | 23 | NodeTimers::NodeTimers(rclcpp::node_interfaces::NodeBaseInterface * node_base) 24 | : node_base_(node_base) 25 | {} 26 | 27 | NodeTimers::~NodeTimers() 28 | {} 29 | 30 | void 31 | NodeTimers::add_timer( 32 | rclcpp::TimerBase::SharedPtr timer, 33 | rclcpp::CallbackGroup::SharedPtr callback_group) 34 | { 35 | if (callback_group) { 36 | if (!node_base_->callback_group_in_node(callback_group)) { 37 | // TODO(jacquelinekay): use custom exception 38 | throw std::runtime_error("Cannot create timer, group not in node."); 39 | } 40 | callback_group->add_timer(timer); 41 | } else { 42 | node_base_->get_default_callback_group()->add_timer(timer); 43 | } 44 | if (rcl_trigger_guard_condition(node_base_->get_notify_guard_condition()) != RCL_RET_OK) { 45 | throw std::runtime_error( 46 | std::string("Failed to notify wait set on timer creation: ") + 47 | rmw_get_error_string().str); 48 | } 49 | TRACEPOINT( 50 | rclcpp_timer_link_node, 51 | static_cast(timer->get_timer_handle().get()), 52 | static_cast(node_base_->get_rcl_node_handle())); 53 | } 54 | -------------------------------------------------------------------------------- /rclcpp/src/rclcpp/node_interfaces/node_waitables.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Open Source Robotics Foundation, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "rclcpp/node_interfaces/node_waitables.hpp" 16 | 17 | #include 18 | 19 | using rclcpp::node_interfaces::NodeWaitables; 20 | 21 | NodeWaitables::NodeWaitables(rclcpp::node_interfaces::NodeBaseInterface * node_base) 22 | : node_base_(node_base) 23 | {} 24 | 25 | NodeWaitables::~NodeWaitables() 26 | {} 27 | 28 | void 29 | NodeWaitables::add_waitable( 30 | rclcpp::Waitable::SharedPtr waitable_ptr, 31 | rclcpp::CallbackGroup::SharedPtr group) 32 | { 33 | if (group) { 34 | if (!node_base_->callback_group_in_node(group)) { 35 | // TODO(jacobperron): use custom exception 36 | throw std::runtime_error("Cannot create waitable, group not in node."); 37 | } 38 | group->add_waitable(waitable_ptr); 39 | } else { 40 | node_base_->get_default_callback_group()->add_waitable(waitable_ptr); 41 | } 42 | 43 | // Notify the executor that a new waitable was created using the parent Node. 44 | { 45 | auto notify_guard_condition_lock = node_base_->acquire_notify_guard_condition_lock(); 46 | if (rcl_trigger_guard_condition(node_base_->get_notify_guard_condition()) != RCL_RET_OK) { 47 | throw std::runtime_error( 48 | std::string("Failed to notify wait set on waitable creation: ") + 49 | rmw_get_error_string().str 50 | ); 51 | } 52 | } 53 | } 54 | 55 | void 56 | NodeWaitables::remove_waitable( 57 | rclcpp::Waitable::SharedPtr waitable_ptr, 58 | rclcpp::CallbackGroup::SharedPtr group) noexcept 59 | { 60 | if (group) { 61 | if (!node_base_->callback_group_in_node(group)) { 62 | return; 63 | } 64 | group->remove_waitable(waitable_ptr); 65 | } else { 66 | node_base_->get_default_callback_group()->remove_waitable(waitable_ptr); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /rclcpp/src/rclcpp/parameter_events_filter.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Open Source Robotics Foundation, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "rclcpp/parameter_events_filter.hpp" 16 | 17 | #include 18 | #include 19 | #include 20 | 21 | using rclcpp::ParameterEventsFilter; 22 | using EventType = rclcpp::ParameterEventsFilter::EventType; 23 | using EventPair = rclcpp::ParameterEventsFilter::EventPair; 24 | 25 | ParameterEventsFilter::ParameterEventsFilter( 26 | std::shared_ptr event, 27 | const std::vector & names, 28 | const std::vector & types) 29 | : event_(event) 30 | { 31 | if (std::find(types.begin(), types.end(), EventType::NEW) != types.end()) { 32 | for (auto & new_parameter : event->new_parameters) { 33 | if (std::find(names.begin(), names.end(), new_parameter.name) != names.end()) { 34 | result_.push_back( 35 | EventPair(EventType::NEW, &new_parameter)); 36 | } 37 | } 38 | } 39 | if (std::find(types.begin(), types.end(), EventType::CHANGED) != types.end()) { 40 | for (auto & changed_parameter : event->changed_parameters) { 41 | if (std::find(names.begin(), names.end(), changed_parameter.name) != names.end()) { 42 | result_.push_back( 43 | EventPair(EventType::CHANGED, &changed_parameter)); 44 | } 45 | } 46 | } 47 | if (std::find(types.begin(), types.end(), EventType::DELETED) != types.end()) { 48 | for (auto & deleted_parameter : event->deleted_parameters) { 49 | if (std::find(names.begin(), names.end(), deleted_parameter.name) != names.end()) { 50 | result_.push_back( 51 | EventPair(EventType::DELETED, &deleted_parameter)); 52 | } 53 | } 54 | } 55 | } 56 | 57 | const std::vector & 58 | ParameterEventsFilter::get_events() const 59 | { 60 | return result_; 61 | } 62 | -------------------------------------------------------------------------------- /rclcpp/src/rclcpp/parameter_service_names.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Open Source Robotics Foundation, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef RCLCPP__PARAMETER_SERVICE_NAMES_HPP_ 16 | #define RCLCPP__PARAMETER_SERVICE_NAMES_HPP_ 17 | 18 | namespace rclcpp 19 | { 20 | namespace parameter_service_names 21 | { 22 | 23 | static constexpr const char * get_parameters = "get_parameters"; 24 | static constexpr const char * get_parameter_types = "get_parameter_types"; 25 | static constexpr const char * set_parameters = "set_parameters"; 26 | static constexpr const char * set_parameters_atomically = "set_parameters_atomically"; 27 | static constexpr const char * describe_parameters = "describe_parameters"; 28 | static constexpr const char * list_parameters = "list_parameters"; 29 | 30 | } // namespace parameter_service_names 31 | } // namespace rclcpp 32 | 33 | #endif // RCLCPP__PARAMETER_SERVICE_NAMES_HPP_ 34 | -------------------------------------------------------------------------------- /rclcpp/src/rclcpp/qos_event.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2019 Open Source Robotics Foundation, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | 17 | #include "rclcpp/qos_event.hpp" 18 | 19 | namespace rclcpp 20 | { 21 | 22 | UnsupportedEventTypeException::UnsupportedEventTypeException( 23 | rcl_ret_t ret, 24 | const rcl_error_state_t * error_state, 25 | const std::string & prefix) 26 | : UnsupportedEventTypeException(exceptions::RCLErrorBase(ret, error_state), prefix) 27 | {} 28 | 29 | UnsupportedEventTypeException::UnsupportedEventTypeException( 30 | const exceptions::RCLErrorBase & base_exc, 31 | const std::string & prefix) 32 | : exceptions::RCLErrorBase(base_exc), 33 | std::runtime_error(prefix + (prefix.empty() ? "" : ": ") + base_exc.formatted_message) 34 | {} 35 | 36 | QOSEventHandlerBase::~QOSEventHandlerBase() 37 | { 38 | if (rcl_event_fini(&event_handle_) != RCL_RET_OK) { 39 | RCUTILS_LOG_ERROR_NAMED( 40 | "rclcpp", 41 | "Error in destruction of rcl event handle: %s", rcl_get_error_string().str); 42 | rcl_reset_error(); 43 | } 44 | } 45 | 46 | /// Get the number of ready events. 47 | size_t 48 | QOSEventHandlerBase::get_number_of_ready_events() 49 | { 50 | return 1; 51 | } 52 | 53 | /// Add the Waitable to a wait set. 54 | bool 55 | QOSEventHandlerBase::add_to_wait_set(rcl_wait_set_t * wait_set) 56 | { 57 | rcl_ret_t ret = rcl_wait_set_add_event(wait_set, &event_handle_, &wait_set_event_index_); 58 | if (RCL_RET_OK != ret) { 59 | exceptions::throw_from_rcl_error(ret, "Couldn't add event to wait set"); 60 | } 61 | return true; 62 | } 63 | 64 | /// Check if the Waitable is ready. 65 | bool 66 | QOSEventHandlerBase::is_ready(rcl_wait_set_t * wait_set) 67 | { 68 | return wait_set->events[wait_set_event_index_] == &event_handle_; 69 | } 70 | 71 | } // namespace rclcpp 72 | -------------------------------------------------------------------------------- /rclcpp/src/rclcpp/qos_overriding_options.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Open Source Robotics Foundation, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "rclcpp/qos_overriding_options.hpp" 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | #include "rmw/qos_policy_kind.h" 25 | #include "rmw/qos_string_conversions.h" 26 | 27 | namespace rclcpp 28 | { 29 | 30 | const char * 31 | qos_policy_kind_to_cstr(const QosPolicyKind & qpk) 32 | { 33 | const char * ret = rmw_qos_policy_kind_to_str(static_cast(qpk)); 34 | if (!ret) { 35 | throw std::invalid_argument{"unknown QoS policy kind"}; 36 | } 37 | return ret; 38 | } 39 | 40 | std::ostream & 41 | operator<<(std::ostream & oss, const QosPolicyKind & qpk) 42 | { 43 | return oss << qos_policy_kind_to_cstr(qpk); 44 | } 45 | 46 | static std::initializer_list kDefaultPolicies = 47 | {QosPolicyKind::History, QosPolicyKind::Depth, QosPolicyKind::Reliability}; 48 | 49 | QosOverridingOptions::QosOverridingOptions( 50 | std::initializer_list policy_kinds, 51 | QosCallback validation_callback, 52 | std::string id) 53 | : id_{std::move(id)}, 54 | policy_kinds_{policy_kinds}, 55 | validation_callback_{std::move(validation_callback)} 56 | {} 57 | 58 | QosOverridingOptions 59 | QosOverridingOptions::with_default_policies( 60 | QosCallback validation_callback, 61 | std::string id) 62 | { 63 | return QosOverridingOptions{kDefaultPolicies, validation_callback, id}; 64 | } 65 | 66 | const std::string & 67 | QosOverridingOptions::get_id() const 68 | { 69 | return id_; 70 | } 71 | 72 | const std::vector & 73 | QosOverridingOptions::get_policy_kinds() const 74 | { 75 | return policy_kinds_; 76 | } 77 | 78 | const QosCallback & 79 | QosOverridingOptions::get_validation_callback() const 80 | { 81 | return validation_callback_; 82 | } 83 | 84 | } // namespace rclcpp 85 | -------------------------------------------------------------------------------- /rclcpp/src/rclcpp/serialization.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Open Source Robotics Foundation, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "rclcpp/serialization.hpp" 16 | 17 | #include 18 | #include 19 | 20 | #include "rclcpp/exceptions.hpp" 21 | #include "rclcpp/serialized_message.hpp" 22 | 23 | #include "rcpputils/asserts.hpp" 24 | 25 | #include "rmw/rmw.h" 26 | 27 | namespace rclcpp 28 | { 29 | 30 | SerializationBase::SerializationBase(const rosidl_message_type_support_t * type_support) 31 | : type_support_(type_support) 32 | { 33 | rcpputils::check_true(nullptr != type_support, "Typesupport is nullpointer."); 34 | } 35 | 36 | void SerializationBase::serialize_message( 37 | const void * ros_message, SerializedMessage * serialized_message) const 38 | { 39 | rcpputils::check_true(nullptr != type_support_, "Typesupport is nullpointer."); 40 | rcpputils::check_true(nullptr != ros_message, "ROS message is nullpointer."); 41 | rcpputils::check_true(nullptr != serialized_message, "Serialized message is nullpointer."); 42 | 43 | const auto ret = rmw_serialize( 44 | ros_message, 45 | type_support_, 46 | &serialized_message->get_rcl_serialized_message()); 47 | if (ret != RMW_RET_OK) { 48 | rclcpp::exceptions::throw_from_rcl_error(ret, "Failed to serialize ROS message."); 49 | } 50 | } 51 | 52 | void SerializationBase::deserialize_message( 53 | const SerializedMessage * serialized_message, void * ros_message) const 54 | { 55 | rcpputils::check_true(nullptr != type_support_, "Typesupport is nullpointer."); 56 | rcpputils::check_true(nullptr != serialized_message, "Serialized message is nullpointer."); 57 | rcpputils::check_true( 58 | 0u != serialized_message->capacity(), 59 | "Wrongly initialized. Serialized message has a capacity of zero."); 60 | rcpputils::check_true( 61 | 0u != serialized_message->size(), 62 | "Wrongly initialized. Serialized message has a size of zero."); 63 | rcpputils::check_true(nullptr != ros_message, "ROS message is a nullpointer."); 64 | 65 | const auto ret = rmw_deserialize( 66 | &serialized_message->get_rcl_serialized_message(), type_support_, ros_message); 67 | if (ret != RMW_RET_OK) { 68 | rclcpp::exceptions::throw_from_rcl_error(ret, "Failed to deserialize ROS message."); 69 | } 70 | } 71 | 72 | } // namespace rclcpp 73 | -------------------------------------------------------------------------------- /rclcpp/src/rclcpp/service.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2015 Open Source Robotics Foundation, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "rclcpp/service.hpp" 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | #include "rclcpp/any_service_callback.hpp" 24 | #include "rclcpp/macros.hpp" 25 | #include "rmw/error_handling.h" 26 | #include "rmw/rmw.h" 27 | 28 | using rclcpp::ServiceBase; 29 | 30 | ServiceBase::ServiceBase(std::shared_ptr node_handle) 31 | : node_handle_(node_handle) 32 | {} 33 | 34 | ServiceBase::~ServiceBase() 35 | {} 36 | 37 | bool 38 | ServiceBase::take_type_erased_request(void * request_out, rmw_request_id_t & request_id_out) 39 | { 40 | rcl_ret_t ret = rcl_take_request( 41 | this->get_service_handle().get(), 42 | &request_id_out, 43 | request_out); 44 | if (RCL_RET_SERVICE_TAKE_FAILED == ret) { 45 | return false; 46 | } else if (RCL_RET_OK != ret) { 47 | rclcpp::exceptions::throw_from_rcl_error(ret); 48 | } 49 | return true; 50 | } 51 | 52 | const char * 53 | ServiceBase::get_service_name() 54 | { 55 | return rcl_service_get_service_name(this->get_service_handle().get()); 56 | } 57 | 58 | std::shared_ptr 59 | ServiceBase::get_service_handle() 60 | { 61 | return service_handle_; 62 | } 63 | 64 | std::shared_ptr 65 | ServiceBase::get_service_handle() const 66 | { 67 | return service_handle_; 68 | } 69 | 70 | rcl_node_t * 71 | ServiceBase::get_rcl_node_handle() 72 | { 73 | return node_handle_.get(); 74 | } 75 | 76 | const rcl_node_t * 77 | ServiceBase::get_rcl_node_handle() const 78 | { 79 | return node_handle_.get(); 80 | } 81 | 82 | bool 83 | ServiceBase::exchange_in_use_by_wait_set_state(bool in_use_state) 84 | { 85 | return in_use_by_wait_set_.exchange(in_use_state); 86 | } 87 | -------------------------------------------------------------------------------- /rclcpp/src/rclcpp/subscription_intra_process_base.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2019 Open Source Robotics Foundation, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "rclcpp/experimental/subscription_intra_process_base.hpp" 16 | 17 | using rclcpp::experimental::SubscriptionIntraProcessBase; 18 | 19 | bool 20 | SubscriptionIntraProcessBase::add_to_wait_set(rcl_wait_set_t * wait_set) 21 | { 22 | std::lock_guard lock(reentrant_mutex_); 23 | 24 | rcl_ret_t ret = rcl_wait_set_add_guard_condition(wait_set, &gc_, NULL); 25 | return RCL_RET_OK == ret; 26 | } 27 | 28 | const char * 29 | SubscriptionIntraProcessBase::get_topic_name() const 30 | { 31 | return topic_name_.c_str(); 32 | } 33 | 34 | rmw_qos_profile_t 35 | SubscriptionIntraProcessBase::get_actual_qos() const 36 | { 37 | return qos_profile_; 38 | } 39 | -------------------------------------------------------------------------------- /rclcpp/src/rclcpp/waitable.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Open Source Robotics Foundation, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "rclcpp/waitable.hpp" 16 | 17 | using rclcpp::Waitable; 18 | 19 | size_t 20 | Waitable::get_number_of_ready_subscriptions() 21 | { 22 | return 0u; 23 | } 24 | 25 | size_t 26 | Waitable::get_number_of_ready_timers() 27 | { 28 | return 0u; 29 | } 30 | 31 | size_t 32 | Waitable::get_number_of_ready_clients() 33 | { 34 | return 0u; 35 | } 36 | 37 | size_t 38 | Waitable::get_number_of_ready_events() 39 | { 40 | return 0u; 41 | } 42 | 43 | size_t 44 | Waitable::get_number_of_ready_services() 45 | { 46 | return 0u; 47 | } 48 | 49 | size_t 50 | Waitable::get_number_of_ready_guard_conditions() 51 | { 52 | return 0u; 53 | } 54 | 55 | bool 56 | Waitable::exchange_in_use_by_wait_set_state(bool in_use_state) 57 | { 58 | return in_use_by_wait_set_.exchange(in_use_state); 59 | } 60 | -------------------------------------------------------------------------------- /reference_interfaces/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | project(reference_interfaces) 3 | 4 | # Default to C++17 5 | if(NOT CMAKE_CXX_STANDARD) 6 | set(CMAKE_CXX_STANDARD 17) 7 | endif() 8 | 9 | if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") 10 | add_compile_options(-Wall -Wextra -Wpedantic) 11 | endif() 12 | 13 | find_package(ament_cmake_auto REQUIRED) 14 | ament_auto_find_build_dependencies() 15 | 16 | # add additional messages here 17 | set(msg_files 18 | "msg/TransmissionStats.idl" 19 | "msg/Message4kb.idl" 20 | ) 21 | 22 | # add additional message dependencies here 23 | #set(msg_dependencies 24 | # "std_msgs" 25 | #) 26 | 27 | rosidl_generate_interfaces(${PROJECT_NAME} 28 | ${msg_files} 29 | DEPENDENCIES 30 | ${msg_dependencies} 31 | ADD_LINTER_TESTS 32 | ) 33 | 34 | ament_auto_package() 35 | 36 | # fix rosidl_generator_py bug #143 37 | # https://github.com/ros2/rosidl_python/issues/143 38 | set(GENERATED_FILE "${CMAKE_CURRENT_BINARY_DIR}/rosidl_generator_py/${PROJECT_NAME}/msg/_transmission_stats.py") 39 | 40 | message(STATUS "checking generated file: ${GENERATED_FILE}") 41 | add_custom_command( 42 | TARGET ${PROJECT_NAME}__python 43 | POST_BUILD 44 | COMMAND sed -i "s/all(val >= 0 and val) < 256/all(ord(val) >= 0 and ord(val) < 256/" ${GENERATED_FILE} 45 | COMMENT "Check generated IDL files for extra parenthesis..." 46 | VERBATIM) 47 | -------------------------------------------------------------------------------- /reference_interfaces/msg/Message4kb.idl: -------------------------------------------------------------------------------- 1 | #include "reference_interfaces/msg/TransmissionStats.idl" 2 | 3 | module reference_interfaces { 4 | module msg { 5 | module Message4kb_Constants { 6 | const uint64 STATS_CAPACITY = 63; 7 | }; 8 | struct Message4kb { 9 | uint64 size; // 8 10 | reference_interfaces::msg::TransmissionStats stats[63]; // + 4032 = 63 * 64 11 | int64 data[7]; // + 56 = 7 * 8 12 | //----------------- 13 | // 4096 14 | }; 15 | }; 16 | }; 17 | -------------------------------------------------------------------------------- /reference_interfaces/msg/TransmissionStats.idl: -------------------------------------------------------------------------------- 1 | module reference_interfaces { 2 | module msg { 3 | module TransmissionStats_Constants { 4 | const uint64 NODE_NAME_LENGTH = 48; 5 | }; 6 | struct TransmissionStats { // 64 bytes 7 | uint64 timestamp; 8 | uint32 sequence_number; 9 | uint32 dropped_samples; 10 | char node_name[48]; 11 | }; 12 | }; 13 | }; 14 | -------------------------------------------------------------------------------- /reference_interfaces/package.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | reference_interfaces 5 | 0.1.1 6 | Reference system for the ROScon workshop 7 | Christian Eltzschig 8 | Apache License 2.0 9 | 10 | ament_cmake_auto 11 | rosidl_default_generators 12 | 13 | rosidl_default_runtime 14 | 15 | 16 | rosidl_interface_packages 17 | 18 | 19 | ament_cmake 20 | 21 | 22 | -------------------------------------------------------------------------------- /reference_system/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | project(reference_system 3 | VERSION 0.0.1 4 | ) 5 | 6 | if(NOT CMAKE_CXX_STANDARD) 7 | set(CMAKE_CXX_STANDARD 17) 8 | endif() 9 | 10 | if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") 11 | add_compile_options(-Wall -Wextra -Wpedantic) 12 | endif() 13 | 14 | find_package(ament_cmake_auto REQUIRED) 15 | ament_auto_find_build_dependencies() 16 | 17 | # Add header-only library 18 | add_library(${PROJECT_NAME} INTERFACE) 19 | 20 | target_include_directories(${PROJECT_NAME} INTERFACE 21 | $ 22 | $ 23 | ) 24 | 25 | if(${BUILD_TESTING}) 26 | find_package(ament_lint_auto REQUIRED) 27 | ament_lint_auto_find_test_dependencies() 28 | endif() 29 | 30 | # Install 31 | install(TARGETS ${PROJECT_NAME} 32 | EXPORT "export_${PROJECT_NAME}" 33 | ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} 34 | LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} 35 | RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} 36 | INCLUDES DESTINATION include 37 | ) 38 | 39 | ament_export_targets("export_${PROJECT_NAME}") 40 | ament_auto_package() 41 | 42 | -------------------------------------------------------------------------------- /reference_system/README.md: -------------------------------------------------------------------------------- 1 | # reference_system 2 | 3 | This package holds the core node definitions that can be used to build various reference systems that can end up being quite complex. 4 | 5 | These _reference systems_ can then be used to benchmark, test and evaluate various changes to the core middleware being used (e.g. executors, QoS settings, DDSs', etc.). 6 | 7 | See [autoware_reference_system](../autoware_reference_system/) as an example as to how one could use these nodes to build a simulated real-world system for benchmarking and testing purposes. -------------------------------------------------------------------------------- /reference_system/include/reference_system/msg_types.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Apex.AI, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #ifndef REFERENCE_SYSTEM__MSG_TYPES_HPP_ 15 | #define REFERENCE_SYSTEM__MSG_TYPES_HPP_ 16 | 17 | #include "reference_interfaces/msg/message4kb.hpp" 18 | 19 | using message_t = reference_interfaces::msg::Message4kb; 20 | 21 | #endif // REFERENCE_SYSTEM__MSG_TYPES_HPP_ 22 | -------------------------------------------------------------------------------- /reference_system/include/reference_system/nodes/rclcpp/command.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Apex.AI, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #ifndef REFERENCE_SYSTEM__NODES__RCLCPP__COMMAND_HPP_ 15 | #define REFERENCE_SYSTEM__NODES__RCLCPP__COMMAND_HPP_ 16 | 17 | #include 18 | #include 19 | 20 | #include "rclcpp/rclcpp.hpp" 21 | #include "reference_system/nodes/settings.hpp" 22 | #include "reference_system/sample_management.hpp" 23 | #include "reference_system/msg_types.hpp" 24 | 25 | namespace nodes 26 | { 27 | namespace rclcpp_system 28 | { 29 | 30 | class Command : public rclcpp::Node 31 | { 32 | public: 33 | explicit Command(const CommandSettings & settings) 34 | : Node(settings.node_name) 35 | { 36 | subscription_ = this->create_subscription( 37 | settings.input_topic, 10, 38 | [this](const message_t::SharedPtr msg) {input_callback(msg);}); 39 | #ifdef PICAS 40 | subscription_->callback_priority = settings.callback_priority; 41 | #endif 42 | } 43 | 44 | private: 45 | void input_callback(const message_t::SharedPtr input_message) 46 | { 47 | uint32_t missed_samples = get_missed_samples_and_update_seq_nr(input_message, sequence_number_); 48 | print_sample_path(this->get_name(), missed_samples, input_message); 49 | } 50 | 51 | private: 52 | rclcpp::Subscription::SharedPtr subscription_; 53 | uint32_t sequence_number_ = 0; 54 | }; 55 | } // namespace rclcpp_system 56 | } // namespace nodes 57 | #endif // REFERENCE_SYSTEM__NODES__RCLCPP__COMMAND_HPP_ 58 | -------------------------------------------------------------------------------- /reference_system/include/reference_system/nodes/rclcpp/sensor.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Apex.AI, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #ifndef REFERENCE_SYSTEM__NODES__RCLCPP__SENSOR_HPP_ 15 | #define REFERENCE_SYSTEM__NODES__RCLCPP__SENSOR_HPP_ 16 | #include 17 | #include 18 | #include 19 | 20 | #include "rclcpp/rclcpp.hpp" 21 | #include "reference_system/nodes/settings.hpp" 22 | #include "reference_system/sample_management.hpp" 23 | #include "reference_system/msg_types.hpp" 24 | 25 | namespace nodes 26 | { 27 | namespace rclcpp_system 28 | { 29 | 30 | class Sensor : public rclcpp::Node 31 | { 32 | public: 33 | explicit Sensor(const SensorSettings & settings) 34 | : Node(settings.node_name) 35 | { 36 | publisher_ = this->create_publisher(settings.topic_name, 1); 37 | timer_ = this->create_wall_timer( 38 | settings.cycle_time, 39 | [this] {timer_callback();}); 40 | #ifdef PICAS 41 | timer_->callback_priority = settings.callback_priority; 42 | #endif 43 | } 44 | 45 | private: 46 | void timer_callback() 47 | { 48 | uint64_t timestamp = now_as_int(); 49 | auto message = publisher_->borrow_loaned_message(); 50 | message.get().size = 0; 51 | 52 | set_sample(this->get_name(), sequence_number_++, 0, timestamp, message.get()); 53 | 54 | publisher_->publish(std::move(message)); 55 | } 56 | 57 | private: 58 | rclcpp::Publisher::SharedPtr publisher_; 59 | rclcpp::TimerBase::SharedPtr timer_; 60 | uint32_t sequence_number_ = 0; 61 | }; 62 | } // namespace rclcpp_system 63 | } // namespace nodes 64 | #endif // REFERENCE_SYSTEM__NODES__RCLCPP__SENSOR_HPP_ 65 | -------------------------------------------------------------------------------- /reference_system/include/reference_system/nodes/rclcpp/transform.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Apex.AI, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #ifndef REFERENCE_SYSTEM__NODES__RCLCPP__TRANSFORM_HPP_ 15 | #define REFERENCE_SYSTEM__NODES__RCLCPP__TRANSFORM_HPP_ 16 | #include 17 | #include 18 | #include 19 | 20 | #include "rclcpp/rclcpp.hpp" 21 | #include "reference_system/nodes/settings.hpp" 22 | #include "reference_system/number_cruncher.hpp" 23 | #include "reference_system/sample_management.hpp" 24 | #include "reference_system/msg_types.hpp" 25 | 26 | namespace nodes 27 | { 28 | namespace rclcpp_system 29 | { 30 | 31 | class Transform : public rclcpp::Node 32 | { 33 | public: 34 | explicit Transform(const TransformSettings & settings) 35 | : Node(settings.node_name), 36 | number_crunch_limit_(settings.number_crunch_limit) 37 | { 38 | subscription_ = this->create_subscription( 39 | settings.input_topic, 1, 40 | [this](const message_t::SharedPtr msg) {input_callback(msg);}); 41 | publisher_ = this->create_publisher(settings.output_topic, 1); 42 | #ifdef PICAS 43 | subscription_->callback_priority = settings.callback_priority; 44 | #endif 45 | } 46 | 47 | private: 48 | void input_callback(const message_t::SharedPtr input_message) 49 | { 50 | uint64_t timestamp = now_as_int(); 51 | auto number_cruncher_result = number_cruncher(number_crunch_limit_); 52 | 53 | auto output_message = publisher_->borrow_loaned_message(); 54 | output_message.get().size = 0; 55 | merge_history_into_sample(output_message.get(), input_message); 56 | 57 | uint32_t missed_samples = get_missed_samples_and_update_seq_nr( 58 | input_message, 59 | input_sequence_number_); 60 | 61 | set_sample( 62 | this->get_name(), sequence_number_++, missed_samples, timestamp, 63 | output_message.get()); 64 | 65 | // use result so that it is not optimizied away by some clever compiler 66 | output_message.get().data[0] = number_cruncher_result; 67 | publisher_->publish(std::move(output_message)); 68 | } 69 | 70 | private: 71 | rclcpp::Publisher::SharedPtr publisher_; 72 | rclcpp::Subscription::SharedPtr subscription_; 73 | uint64_t number_crunch_limit_; 74 | uint32_t sequence_number_ = 0; 75 | uint32_t input_sequence_number_ = 0; 76 | }; 77 | } // namespace rclcpp_system 78 | } // namespace nodes 79 | #endif // REFERENCE_SYSTEM__NODES__RCLCPP__TRANSFORM_HPP_ 80 | -------------------------------------------------------------------------------- /reference_system/include/reference_system/nodes/settings.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Apex.AI, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #ifndef REFERENCE_SYSTEM__NODES__SETTINGS_HPP_ 15 | #define REFERENCE_SYSTEM__NODES__SETTINGS_HPP_ 16 | 17 | #include 18 | #include 19 | #include 20 | 21 | namespace nodes 22 | { 23 | 24 | struct CommandSettings 25 | { 26 | std::string node_name; 27 | std::string input_topic; 28 | #ifdef PICAS 29 | int callback_priority; 30 | #endif 31 | }; 32 | 33 | struct FusionSettings 34 | { 35 | std::string node_name; 36 | std::string input_0; 37 | std::string input_1; 38 | std::string output_topic; 39 | uint64_t number_crunch_limit; 40 | #ifdef PICAS 41 | int callback_priority_1; 42 | int callback_priority_2; 43 | #endif 44 | }; 45 | 46 | struct TransformSettings 47 | { 48 | std::string node_name; 49 | std::string input_topic; 50 | std::string output_topic; 51 | uint64_t number_crunch_limit; 52 | #ifdef PICAS 53 | int callback_priority; 54 | #endif 55 | }; 56 | 57 | struct IntersectionSettings 58 | { 59 | struct Connection 60 | { 61 | std::string input_topic; 62 | std::string output_topic; 63 | uint64_t number_crunch_limit; 64 | #ifdef PICAS 65 | int callback_priority; 66 | #endif 67 | }; 68 | 69 | std::string node_name; 70 | std::vector connections; 71 | }; 72 | 73 | struct CyclicSettings 74 | { 75 | std::string node_name; 76 | std::vector inputs; 77 | std::string output_topic; 78 | uint64_t number_crunch_limit; 79 | std::chrono::nanoseconds cycle_time; 80 | #ifdef PICAS 81 | int callback_priority_1; 82 | int callback_priority_2; 83 | int callback_priority_3; 84 | int callback_priority_4; 85 | int callback_priority_5; 86 | int callback_priority_6; 87 | int callback_priority_7; 88 | #endif 89 | }; 90 | 91 | struct SensorSettings 92 | { 93 | std::string node_name; 94 | std::string topic_name; 95 | std::chrono::nanoseconds cycle_time; 96 | #ifdef PICAS 97 | int callback_priority; 98 | #endif 99 | }; 100 | } // namespace nodes 101 | #endif // REFERENCE_SYSTEM__NODES__SETTINGS_HPP_ 102 | -------------------------------------------------------------------------------- /reference_system/include/reference_system/number_cruncher.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Apex.AI, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #ifndef REFERENCE_SYSTEM__NUMBER_CRUNCHER_HPP_ 15 | #define REFERENCE_SYSTEM__NUMBER_CRUNCHER_HPP_ 16 | 17 | #include 18 | #include 19 | #include 20 | 21 | uint64_t number_cruncher(const uint64_t maximum_number) 22 | { 23 | uint64_t number_of_primes = 0; 24 | for (uint64_t i = 3; i < maximum_number; ++i) { 25 | uint64_t rootOfI = static_cast(std::sqrt(i)); 26 | bool is_prime = true; 27 | for (uint64_t n = 2; n < rootOfI; ++n) { 28 | if (i % n == 0) { 29 | is_prime = false; 30 | break; 31 | } 32 | } 33 | 34 | if (is_prime) { 35 | ++number_of_primes; 36 | } 37 | } 38 | return number_of_primes; 39 | } 40 | 41 | #endif // REFERENCE_SYSTEM__NUMBER_CRUNCHER_HPP_ 42 | -------------------------------------------------------------------------------- /reference_system/include/reference_system/system/systems.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Apex.AI, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #ifndef REFERENCE_SYSTEM__SYSTEM__SYSTEMS_HPP_ 15 | #define REFERENCE_SYSTEM__SYSTEM__SYSTEMS_HPP_ 16 | 17 | // Add available systems here 18 | #include "reference_system/system/type/rclcpp_system.hpp" 19 | 20 | #endif // REFERENCE_SYSTEM__SYSTEM__SYSTEMS_HPP_ 21 | -------------------------------------------------------------------------------- /reference_system/include/reference_system/system/type/rclcpp_system.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Apex.AI, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #ifndef REFERENCE_SYSTEM__SYSTEM__TYPE__RCLCPP_SYSTEM_HPP_ 15 | #define REFERENCE_SYSTEM__SYSTEM__TYPE__RCLCPP_SYSTEM_HPP_ 16 | #include "reference_system/nodes/rclcpp/command.hpp" 17 | #include "reference_system/nodes/rclcpp/fusion.hpp" 18 | #include "reference_system/nodes/rclcpp/transform.hpp" 19 | #include "reference_system/nodes/rclcpp/cyclic.hpp" 20 | #include "reference_system/nodes/rclcpp/sensor.hpp" 21 | #include "reference_system/nodes/rclcpp/intersection.hpp" 22 | 23 | struct RclcppSystem 24 | { 25 | using NodeBaseType = rclcpp::Node; 26 | 27 | using Command = nodes::rclcpp_system::Command; 28 | using Cyclic = nodes::rclcpp_system::Cyclic; 29 | using Fusion = nodes::rclcpp_system::Fusion; 30 | using Intersection = nodes::rclcpp_system::Intersection; 31 | using Sensor = nodes::rclcpp_system::Sensor; 32 | using Transform = nodes::rclcpp_system::Transform; 33 | }; 34 | 35 | #endif // REFERENCE_SYSTEM__SYSTEM__TYPE__RCLCPP_SYSTEM_HPP_ 36 | -------------------------------------------------------------------------------- /reference_system/package.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | reference_system 5 | 0.1.1 6 | Reference system for the ROScon workshop 7 | Evan Flynn 8 | Apache License 2.0 9 | 10 | Christian Eltzschig 11 | 12 | ament_cmake 13 | ament_cmake_auto 14 | 15 | rclcpp 16 | reference_interfaces 17 | rcl_interfaces 18 | 19 | ament_lint_auto 20 | ament_lint_common 21 | ros_testing 22 | 23 | 24 | ament_cmake 25 | 26 | 27 | --------------------------------------------------------------------------------