-
Notifications
You must be signed in to change notification settings - Fork 457
Add state_interfaces_broadcaster #2006
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
christophfroehlich
merged 24 commits into
ros-controls:master
from
pal-robotics-forks:add/generic_state_broadcaster
Dec 15, 2025
Merged
Changes from 21 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
4931294
Add initial commit of generic state broadcaster
saikishor 6875e65
Add first version of the tests
saikishor 7e8e34a
change to new message types
saikishor d2a4b58
update tests
saikishor 6e2980f
add state broadcaster params file
saikishor bfe9c80
rename the package to interfaces state broadcaster
saikishor a0b0b1c
Add release_notes
saikishor ce8f111
Merge branch 'master' into add/generic_state_broadcaster
saikishor dc9b673
Apply suggestions from code review
saikishor ec48562
Apply suggestions from code review
saikishor fdb6f6b
Apply suggestions from code review
saikishor b143897
Apply suggestions from code review
saikishor 839dec3
pre-commit and minor fixes
saikishor 69a46f8
remove wrong include
saikishor 3e2b8ce
fix compilation
saikishor 00c3fc3
Update interfaces_state_broadcaster/src/interfaces_state_broadcaster.cpp
saikishor 7769bc6
Merge branch 'master' into add/generic_state_broadcaster
saikishor 8b381ec
add pre-commit changes
saikishor a5bbdb1
update the documentation
saikishor 6d07b97
Rename the package to state_interfaces_broadcaster
saikishor 574ecab
add changes to support double data type
saikishor a8eb06a
Update state_interfaces_broadcaster/doc/userdoc.rst
saikishor a27c304
Apply suggestions from code review
christophfroehlich 8b317e1
Update CMakeLists.txt
christophfroehlich File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| cmake_minimum_required(VERSION 3.16) | ||
| project(state_interfaces_broadcaster) | ||
|
|
||
| find_package(ros2_control_cmake REQUIRED) | ||
| set_compiler_options() | ||
| export_windows_symbols() | ||
|
|
||
| set(THIS_PACKAGE_INCLUDE_DEPENDS | ||
| builtin_interfaces | ||
| control_msgs | ||
| controller_interface | ||
| generate_parameter_library | ||
| pluginlib | ||
| rclcpp_lifecycle | ||
| realtime_tools | ||
| ) | ||
|
|
||
| find_package(ament_cmake REQUIRED) | ||
| find_package(backward_ros REQUIRED) | ||
| foreach(Dependency IN ITEMS ${THIS_PACKAGE_INCLUDE_DEPENDS}) | ||
| find_package(${Dependency} REQUIRED) | ||
| endforeach() | ||
|
|
||
| generate_parameter_library(state_interfaces_broadcaster_parameters | ||
| src/state_interfaces_broadcaster_parameters.yaml | ||
| ) | ||
|
|
||
| add_library(state_interfaces_broadcaster SHARED | ||
| src/state_interfaces_broadcaster.cpp | ||
| ) | ||
| target_compile_features(state_interfaces_broadcaster PUBLIC cxx_std_17) | ||
| target_include_directories(state_interfaces_broadcaster PUBLIC | ||
| $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include> | ||
| $<INSTALL_INTERFACE:include/state_interfaces_broadcaster> | ||
| ) | ||
| target_link_libraries(state_interfaces_broadcaster PUBLIC | ||
| state_interfaces_broadcaster_parameters | ||
| controller_interface::controller_interface | ||
| pluginlib::pluginlib | ||
| rclcpp::rclcpp | ||
| rclcpp_lifecycle::rclcpp_lifecycle | ||
| realtime_tools::realtime_tools | ||
| ${control_msgs_TARGETS} | ||
| ${builtin_interfaces_TARGETS}) | ||
christophfroehlich marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| pluginlib_export_plugin_description_file(controller_interface state_interfaces_broadcaster_plugin.xml) | ||
|
|
||
| if(BUILD_TESTING) | ||
| find_package(ament_cmake_gmock REQUIRED) | ||
| find_package(controller_manager REQUIRED) | ||
| find_package(hardware_interface REQUIRED) | ||
| find_package(rclcpp REQUIRED) | ||
| find_package(ros2_control_test_assets REQUIRED) | ||
|
|
||
| ament_add_gmock(test_load_state_interfaces_broadcaster | ||
| test/test_load_state_interfaces_broadcaster.cpp | ||
| ) | ||
| target_link_libraries(test_load_state_interfaces_broadcaster | ||
| state_interfaces_broadcaster | ||
| controller_manager::controller_manager | ||
| hardware_interface::hardware_interface | ||
| rclcpp::rclcpp | ||
| ros2_control_test_assets::ros2_control_test_assets) | ||
| target_compile_definitions( | ||
| test_load_state_interfaces_broadcaster | ||
| PRIVATE PARAMETERS_FILE_PATH="${CMAKE_CURRENT_LIST_DIR}/test/test_state_interfaces_broadcaster_params.yaml") | ||
|
|
||
| ament_add_gmock(test_state_interfaces_broadcaster | ||
| test/test_state_interfaces_broadcaster.cpp | ||
| ) | ||
| target_link_libraries(test_state_interfaces_broadcaster | ||
| state_interfaces_broadcaster | ||
| ros2_control_test_assets::ros2_control_test_assets | ||
| rclcpp::rclcpp | ||
| ${control_msgs_TARGETS}) | ||
| endif() | ||
|
|
||
| install( | ||
| DIRECTORY include/ | ||
| DESTINATION include/state_interfaces_broadcaster | ||
| ) | ||
| install( | ||
| TARGETS | ||
| state_interfaces_broadcaster | ||
| state_interfaces_broadcaster_parameters | ||
| EXPORT export_state_interfaces_broadcaster | ||
| RUNTIME DESTINATION bin | ||
| ARCHIVE DESTINATION lib | ||
| LIBRARY DESTINATION lib | ||
| ) | ||
|
|
||
| ament_export_targets(export_state_interfaces_broadcaster HAS_LIBRARY_TARGET) | ||
| ament_export_dependencies(${THIS_PACKAGE_INCLUDE_DEPENDS}) | ||
| ament_package() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| :github_url: https://github.com/ros-controls/ros2_controllers/blob/{REPOS_FILE_BRANCH}/state_interfaces_broadcaster/doc/userdoc.rst | ||
|
|
||
| .. _state_interfaces_broadcaster_userdoc: | ||
|
|
||
| State Interfaces Broadcaster | ||
| -------------------------------- | ||
| The State Interfaces Broadcaster publishes the state of specified hardware interfaces that support double data type. | ||
saikishor marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| The broadcaster publishes two topics: | ||
|
|
||
| - ``/state_interfaces_broadcaster/names``: Publishes the names of the hardware interfaces being monitored with a message type of ``control_msgs/msg/Keys``. | ||
| - ``/state_interfaces_broadcaster/values``: Publishes the current state values of the specified hardware interfaces with a message type of ``control_msgs/msg/Float64Values``. | ||
|
|
||
| Parameters | ||
| ^^^^^^^^^^^ | ||
| This controller uses the `generate_parameter_library <https://github.com/PickNikRobotics/generate_parameter_library>`_ to handle its parameters. The parameter `definition file located in the src folder <https://github.com/ros-controls/ros2_controllers/blob/{REPOS_FILE_BRANCH}/state_interfaces_broadcaster/src/state_interfaces_broadcaster_parameters.yaml>`_ contains descriptions for all the parameters used by the controller. | ||
|
|
||
| List of parameters | ||
| ========================= | ||
| .. generate_parameter_library_details:: ../src/state_interfaces_broadcaster_parameters.yaml | ||
|
|
||
|
|
||
| An example parameter file | ||
| ========================= | ||
|
|
||
| An example parameter file for this controller can be found in `the test directory <https://github.com/ros-controls/ros2_controllers/blob/{REPOS_FILE_BRANCH}/state_interfaces_broadcaster/test/test_state_interfaces_broadcaster_params.yaml>`_: | ||
|
|
||
| .. literalinclude:: ../test/test_state_interfaces_broadcaster_params.yaml | ||
| :language: yaml | ||
84 changes: 84 additions & 0 deletions
84
...erfaces_broadcaster/include/state_interfaces_broadcaster/state_interfaces_broadcaster.hpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| // Copyright (c) 2025, PAL Robotics | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| #ifndef STATE_INTERFACES_BROADCASTER__STATE_INTERFACES_BROADCASTER_HPP_ | ||
| #define STATE_INTERFACES_BROADCASTER__STATE_INTERFACES_BROADCASTER_HPP_ | ||
|
|
||
| #include <memory> | ||
| #include <string> | ||
| #include <unordered_map> | ||
christophfroehlich marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| #include <vector> | ||
|
|
||
| #include "control_msgs/msg/float64_values.hpp" | ||
| #include "control_msgs/msg/keys.hpp" | ||
| #include "controller_interface/controller_interface.hpp" | ||
| #include "realtime_tools/realtime_publisher.hpp" | ||
|
|
||
| // auto-generated by generate_parameter_library | ||
| #include "state_interfaces_broadcaster/state_interfaces_broadcaster_parameters.hpp" | ||
|
|
||
| namespace state_interfaces_broadcaster | ||
| { | ||
| /** | ||
| * \brief State Interfaces Broadcaster for selected state interfaces in a ros2_control system. | ||
| * | ||
| * StateInterfacesBroadcaster publishes the selected state interfaces from ros2_control as ROS | ||
| * messages. | ||
| * | ||
| * Publishes to: | ||
| * - \b ~/names (control_msgs::msg::Keys): The list of the interface names that are selected | ||
| * to be published by the interfaces state broadcaster. This is published with transient local | ||
| * durability. | ||
| * - \b ~/values (control_msgs::msg::Float64Values): The list of the values corresponding to the | ||
| * interface names that are selected to be published by the interfaces state broadcaster. | ||
| * | ||
| * \note The values are published at the same rate as the controller update rate. | ||
| */ | ||
| class StateInterfacesBroadcaster : public controller_interface::ControllerInterface | ||
| { | ||
| public: | ||
| StateInterfacesBroadcaster(); | ||
|
|
||
| controller_interface::InterfaceConfiguration command_interface_configuration() const override; | ||
|
|
||
| controller_interface::InterfaceConfiguration state_interface_configuration() const override; | ||
|
|
||
| controller_interface::return_type update( | ||
| const rclcpp::Time & time, const rclcpp::Duration & period) override; | ||
|
|
||
| controller_interface::CallbackReturn on_init() override; | ||
|
|
||
| controller_interface::CallbackReturn on_configure( | ||
| const rclcpp_lifecycle::State & previous_state) override; | ||
|
|
||
| controller_interface::CallbackReturn on_activate( | ||
| const rclcpp_lifecycle::State & previous_state) override; | ||
|
|
||
| protected: | ||
| // Optional parameters | ||
| std::shared_ptr<ParamListener> param_listener_; | ||
| Params params_; | ||
|
|
||
| // publishers and messages | ||
| std::shared_ptr<rclcpp::Publisher<control_msgs::msg::Keys>> names_publisher_; | ||
| std::shared_ptr<rclcpp::Publisher<control_msgs::msg::Float64Values>> values_publisher_; | ||
| std::shared_ptr<realtime_tools::RealtimePublisher<control_msgs::msg::Float64Values>> | ||
| realtime_values_publisher_; | ||
| control_msgs::msg::Keys names_msg_; | ||
| control_msgs::msg::Float64Values values_msg_; | ||
| }; | ||
|
|
||
| } // namespace state_interfaces_broadcaster | ||
|
|
||
| #endif // STATE_INTERFACES_BROADCASTER__STATE_INTERFACES_BROADCASTER_HPP_ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| <?xml version="1.0"?> | ||
| <package format="3"> | ||
| <name>state_interfaces_broadcaster</name> | ||
| <version>6.1.0</version> | ||
| <description>Broadcaster to publish the requested hardware interface states</description> | ||
|
|
||
| <maintainer email="bence.magyar.robotics@gmail.com">Bence Magyar</maintainer> | ||
| <maintainer email="denis@stoglrobotics.de">Denis Štogl</maintainer> | ||
| <maintainer email="christoph.froehlich@ait.ac.at">Christoph Froehlich</maintainer> | ||
| <maintainer email="sai.kishor@pal-robotics.com">Sai Kishor Kothakota</maintainer> | ||
|
|
||
| <author email="sai.kishor@pal-robotics.com">Sai Kishor Kothakota</author> | ||
|
|
||
| <license>Apache License 2.0</license> | ||
|
|
||
| <url type="website">https://control.ros.org</url> | ||
| <url type="bugtracker">https://github.com/ros-controls/ros2_controllers/issues</url> | ||
| <url type="repository">https://github.com/ros-controls/ros2_controllers/</url> | ||
|
|
||
| <buildtool_depend>ament_cmake</buildtool_depend> | ||
|
|
||
| <build_depend>ros2_control_cmake</build_depend> | ||
|
|
||
| <depend>backward_ros</depend> | ||
| <depend>builtin_interfaces</depend> | ||
christophfroehlich marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| <depend>control_msgs</depend> | ||
| <depend>controller_interface</depend> | ||
| <depend>generate_parameter_library</depend> | ||
| <depend>pluginlib</depend> | ||
| <depend>rclcpp_lifecycle</depend> | ||
| <depend>rclcpp</depend> | ||
| <depend>realtime_tools</depend> | ||
|
|
||
| <test_depend>ament_cmake_gmock</test_depend> | ||
| <test_depend>controller_manager</test_depend> | ||
| <test_depend>hardware_interface_testing</test_depend> | ||
christophfroehlich marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| <test_depend>hardware_interface</test_depend> | ||
| <test_depend>ros2_control_test_assets</test_depend> | ||
|
|
||
| <export> | ||
| <build_type>ament_cmake</build_type> | ||
| </export> | ||
| </package> | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.