-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Copy, rename and make buildable Signed-off-by: Rufus Wong <[email protected]> * Swap input and output topic Signed-off-by: Rufus Wong <[email protected]> * Reset publisher if output topic changes Signed-off-by: Rufus Wong <[email protected]> * Add tests Signed-off-by: Rufus Wong <[email protected]> * Fix test failures Signed-off-by: Rufus Wong <[email protected]> * Fix header guard Signed-off-by: Rufus Wong <[email protected]> * Make linter happy Signed-off-by: Rufus Wong <[email protected]> * Add README entry Signed-off-by: Rufus Wong <[email protected]> * Remove lazy parameter Signed-off-by: Rufus Wong <[email protected]> * Rename default input topic to ~/input Signed-off-by: Rufus Wong <[email protected]> * Fix typo Signed-off-by: Rufus Wong <[email protected]> * Remove usage of ament_cmake_auto Signed-off-by: Rufus Wong <[email protected]> * Add missing dependency on ament_cmake Signed-off-by: Rufus Wong <[email protected]> * Fix uncrustify warnings Signed-off-by: Rufus Wong <[email protected]> * Add initial_topic_ variable to avoid confusion This addresses comment #106 (comment) Signed-off-by: Rufus Wong <[email protected]> * Fix outtopic spelling This addresses comment #106 (comment) Signed-off-by: Rufus Wong <[email protected]> * Add error message on incorrect number of arguments Addresses #106 (comment) Signed-off-by: Rufus Wong <[email protected]> * Formatting Signed-off-by: Rufus Wong <[email protected]> --------- Signed-off-by: Rufus Wong <[email protected]>
- Loading branch information
Showing
17 changed files
with
604 additions
and
45 deletions.
There are no files selected for viewing
This file contains 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 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 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,65 @@ | ||
// Copyright 2024 Rufus Wong | ||
// | ||
// 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 TOPIC_TOOLS__DEMUX_NODE_HPP_ | ||
#define TOPIC_TOOLS__DEMUX_NODE_HPP_ | ||
|
||
#include <memory> | ||
#include <optional> // NOLINT : https://github.com/ament/ament_lint/pull/324 | ||
#include <string> | ||
#include <utility> | ||
#include <vector> | ||
|
||
#include "rclcpp/rclcpp.hpp" | ||
#include "topic_tools/tool_base_node.hpp" | ||
#include "topic_tools_interfaces/srv/demux_add.hpp" | ||
#include "topic_tools_interfaces/srv/demux_delete.hpp" | ||
#include "topic_tools_interfaces/srv/demux_list.hpp" | ||
#include "topic_tools_interfaces/srv/demux_select.hpp" | ||
|
||
namespace topic_tools | ||
{ | ||
static const char NONE_TOPIC[] = "__none"; | ||
|
||
class DemuxNode final : public ToolBaseNode | ||
{ | ||
public: | ||
TOPIC_TOOLS_PUBLIC | ||
explicit DemuxNode(const rclcpp::NodeOptions & options); | ||
|
||
private: | ||
void process_message(std::shared_ptr<rclcpp::SerializedMessage> msg) override; | ||
void make_subscribe_unsubscribe_decisions() override; | ||
void on_demux_add( | ||
const std::shared_ptr<topic_tools_interfaces::srv::DemuxAdd::Request> request, | ||
std::shared_ptr<topic_tools_interfaces::srv::DemuxAdd::Response> response); | ||
void on_demux_delete( | ||
const std::shared_ptr<topic_tools_interfaces::srv::DemuxDelete::Request> request, | ||
std::shared_ptr<topic_tools_interfaces::srv::DemuxDelete::Response> response); | ||
void on_demux_list( | ||
const std::shared_ptr<topic_tools_interfaces::srv::DemuxList::Request> request, | ||
std::shared_ptr<topic_tools_interfaces::srv::DemuxList::Response> response); | ||
void on_demux_select( | ||
const std::shared_ptr<topic_tools_interfaces::srv::DemuxSelect::Request> request, | ||
std::shared_ptr<topic_tools_interfaces::srv::DemuxSelect::Response> response); | ||
|
||
std::vector<std::string> output_topics_; | ||
rclcpp::Service<topic_tools_interfaces::srv::DemuxAdd>::SharedPtr demux_add_srv_; | ||
rclcpp::Service<topic_tools_interfaces::srv::DemuxDelete>::SharedPtr demux_delete_srv_; | ||
rclcpp::Service<topic_tools_interfaces::srv::DemuxList>::SharedPtr demux_list_srv_; | ||
rclcpp::Service<topic_tools_interfaces::srv::DemuxSelect>::SharedPtr demux_select_srv_; | ||
}; | ||
} // namespace topic_tools | ||
|
||
#endif // TOPIC_TOOLS__DEMUX_NODE_HPP_ |
This file contains 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 |
---|---|---|
|
@@ -11,7 +11,7 @@ | |
<maintainer email="[email protected]">ROS Tooling Working Group</maintainer> | ||
<license>Apache License 2.0</license> | ||
|
||
<buildtool_depend>ament_cmake_auto</buildtool_depend> | ||
<buildtool_depend>ament_cmake</buildtool_depend> | ||
<buildtool_depend>ament_cmake_python</buildtool_depend> | ||
<buildtool_depend>rosidl_default_generators</buildtool_depend> | ||
|
||
|
This file contains 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,45 @@ | ||
// Copyright 2024 Rufus Wong | ||
// | ||
// 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. | ||
|
||
#include <memory> | ||
#include <string> | ||
#include <vector> | ||
|
||
#include "rclcpp/rclcpp.hpp" | ||
#include "topic_tools/demux_node.hpp" | ||
|
||
int main(int argc, char * argv[]) | ||
{ | ||
auto args = rclcpp::init_and_remove_ros_arguments(argc, argv); | ||
auto options = rclcpp::NodeOptions{}; | ||
|
||
if (args.size() < 3) { | ||
RCLCPP_ERROR( | ||
rclcpp::get_logger("demux"), | ||
"Incorect number of arguments. " | ||
"Usage: " | ||
"ros2 run topic_tools demux <intopic> <outtopic1> [outtopic2...]"); | ||
return 1; | ||
} | ||
|
||
options.append_parameter_override("input_topic", args.at(1)); | ||
options.append_parameter_override( | ||
"output_topics", std::vector<std::string>{args.begin() + 2, args.end()}); | ||
|
||
auto node = std::make_shared<topic_tools::DemuxNode>(options); | ||
|
||
rclcpp::spin(node); | ||
rclcpp::shutdown(); | ||
return 0; | ||
} |
Oops, something went wrong.