-
Notifications
You must be signed in to change notification settings - Fork 451
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 19 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| cmake_minimum_required(VERSION 3.16) | ||
| project(interfaces_state_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(interfaces_state_broadcaster_parameters | ||
| src/interfaces_state_broadcaster_parameters.yaml | ||
| ) | ||
|
|
||
| add_library(interfaces_state_broadcaster SHARED | ||
| src/interfaces_state_broadcaster.cpp | ||
| ) | ||
| target_compile_features(interfaces_state_broadcaster PUBLIC cxx_std_17) | ||
| target_include_directories(interfaces_state_broadcaster PUBLIC | ||
| $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include> | ||
| $<INSTALL_INTERFACE:include/interfaces_state_broadcaster> | ||
| ) | ||
| target_link_libraries(interfaces_state_broadcaster PUBLIC | ||
| interfaces_state_broadcaster_parameters | ||
| controller_interface::controller_interface | ||
| pluginlib::pluginlib | ||
| rclcpp::rclcpp | ||
| rclcpp_lifecycle::rclcpp_lifecycle | ||
| realtime_tools::realtime_tools | ||
| ${control_msgs_TARGETS} | ||
| ${builtin_interfaces_TARGETS}) | ||
| pluginlib_export_plugin_description_file(controller_interface interfaces_state_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_interfaces_state_broadcaster | ||
| test/test_load_interfaces_state_broadcaster.cpp | ||
| ) | ||
| target_link_libraries(test_load_interfaces_state_broadcaster | ||
| interfaces_state_broadcaster | ||
| controller_manager::controller_manager | ||
| hardware_interface::hardware_interface | ||
| rclcpp::rclcpp | ||
| ros2_control_test_assets::ros2_control_test_assets) | ||
| target_compile_definitions( | ||
| test_load_interfaces_state_broadcaster | ||
| PRIVATE PARAMETERS_FILE_PATH="${CMAKE_CURRENT_LIST_DIR}/test/test_interfaces_state_broadcaster_params.yaml") | ||
|
|
||
| ament_add_gmock(test_interfaces_state_broadcaster | ||
| test/test_interfaces_state_broadcaster.cpp | ||
| ) | ||
| target_link_libraries(test_interfaces_state_broadcaster | ||
| interfaces_state_broadcaster | ||
| ros2_control_test_assets::ros2_control_test_assets | ||
| rclcpp::rclcpp | ||
| ${control_msgs_TARGETS}) | ||
| endif() | ||
|
|
||
| install( | ||
| DIRECTORY include/ | ||
| DESTINATION include/interfaces_state_broadcaster | ||
| ) | ||
| install( | ||
| TARGETS | ||
| interfaces_state_broadcaster | ||
| interfaces_state_broadcaster_parameters | ||
| EXPORT export_interfaces_state_broadcaster | ||
| RUNTIME DESTINATION bin | ||
| ARCHIVE DESTINATION lib | ||
| LIBRARY DESTINATION lib | ||
| ) | ||
|
|
||
| ament_export_targets(export_interfaces_state_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}/interfaces_state_broadcaster/doc/userdoc.rst | ||
|
|
||
| .. _interfaces_state_broadcaster_userdoc: | ||
|
|
||
| Interfaces State Broadcaster | ||
| -------------------------------- | ||
| The Interfaces State Broadcaster publishes the state of specified hardware interfaces that support double data type. | ||
| The broadcaster publishes two topics: | ||
|
|
||
| - ``/interfaces_state_broadcaster/names``: Publishes the names of the hardware interfaces being monitored with a message type of ``control_msgs/msg/Keys``. | ||
| - ``/interfaces_state_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}/interfaces_state_broadcaster/src/interfaces_state_broadcaster_parameters.yaml>`_ contains descriptions for all the parameters used by the controller. | ||
|
|
||
| List of parameters | ||
| ========================= | ||
| .. generate_parameter_library_details:: ../src/interfaces_state_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}/interfaces_state_broadcaster/test/test_interfaces_state_broadcaster_params.yaml>`_: | ||
|
|
||
| .. literalinclude:: ../test/test_interfaces_state_broadcaster_params.yaml | ||
| :language: yaml | ||
84 changes: 84 additions & 0 deletions
84
...s_state_broadcaster/include/interfaces_state_broadcaster/interfaces_state_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 INTERFACES_STATE_BROADCASTER__INTERFACES_STATE_BROADCASTER_HPP_ | ||
| #define INTERFACES_STATE_BROADCASTER__INTERFACES_STATE_BROADCASTER_HPP_ | ||
|
|
||
| #include <memory> | ||
| #include <string> | ||
| #include <unordered_map> | ||
| #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 "interfaces_state_broadcaster/interfaces_state_broadcaster_parameters.hpp" | ||
|
|
||
| namespace interfaces_state_broadcaster | ||
| { | ||
| /** | ||
| * \brief Interfaces State Broadcaster for selected state interfaces in a ros2_control system. | ||
| * | ||
| * InterfacesStateBroadcaster 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 InterfacesStateBroadcaster : public controller_interface::ControllerInterface | ||
| { | ||
| public: | ||
| InterfacesStateBroadcaster(); | ||
|
|
||
| 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 interfaces_state_broadcaster | ||
|
|
||
| #endif // INTERFACES_STATE_BROADCASTER__INTERFACES_STATE_BROADCASTER_HPP_ |
7 changes: 7 additions & 0 deletions
7
interfaces_state_broadcaster/interfaces_state_broadcaster_plugin.xml
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,7 @@ | ||
| <library path="interfaces_state_broadcaster"> | ||
| <class name="interfaces_state_broadcaster/InterfacesStateBroadcaster" type="interfaces_state_broadcaster::InterfacesStateBroadcaster" base_class_type="controller_interface::ControllerInterface"> | ||
| <description> | ||
| The interfaces state broadcaster publishes the values of the requested interfaces from ros2_control system. | ||
| </description> | ||
| </class> | ||
| </library> |
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>interfaces_state_broadcaster</name> | ||
| <version>5.8.0</version> | ||
| <description>Broadcaster to publish desired hardware interface states that are castable to double</description> | ||
|
|
||
| <maintainer email="[email protected]">Bence Magyar</maintainer> | ||
| <maintainer email="[email protected]">Denis Štogl</maintainer> | ||
| <maintainer email="[email protected]">Christoph Froehlich</maintainer> | ||
| <maintainer email="[email protected]">Sai Kishor Kothakota</maintainer> | ||
|
|
||
| <author email="[email protected]">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> | ||
| <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> | ||
| <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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not 100% true. "is_castable_to_double" is true for all datatypes we currently support, but the get_optional only works for double and bool with additional warning.
We should either limit it to double-only, or support all castable datatypes for real ;)
This is what I started here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would change the logic internally to the code to reflect that