diff --git a/common/tier4_string_viewer_rviz_plugin/CMakeLists.txt b/common/tier4_string_viewer_rviz_plugin/CMakeLists.txt new file mode 100644 index 00000000..410cddc6 --- /dev/null +++ b/common/tier4_string_viewer_rviz_plugin/CMakeLists.txt @@ -0,0 +1,26 @@ +cmake_minimum_required(VERSION 3.14) +project(tier4_string_viewer_rviz_plugin) + +find_package(autoware_cmake REQUIRED) +autoware_package() + +find_package(Qt5 REQUIRED Core Widgets) +set(QT_LIBRARIES Qt5::Widgets) +set(CMAKE_AUTOMOC ON) +set(CMAKE_INCLUDE_CURRENT_DIR ON) +add_definitions(-DQT_NO_KEYWORDS) + +ament_auto_add_library(${PROJECT_NAME} SHARED + src/string_viewer_panel.hpp + src/string_viewer_panel.cpp +) +target_link_libraries(${PROJECT_NAME} + ${QT_LIBRARIES} +) +pluginlib_export_plugin_description_file(rviz_common plugins/plugin_description.xml) + +ament_auto_package( + INSTALL_TO_SHARE + icons + plugins +) diff --git a/common/tier4_string_viewer_rviz_plugin/README.md b/common/tier4_string_viewer_rviz_plugin/README.md new file mode 100644 index 00000000..fba6e508 --- /dev/null +++ b/common/tier4_string_viewer_rviz_plugin/README.md @@ -0,0 +1,15 @@ +# tier4_string_viewer_rviz_plugin + +## Purpose + +This plugin displays the ROS message whose topic type is `tier4_debug_msgs::msg::StringStamped` in rviz. + +## Assumptions / Known limits + +TBD. + +## Usage + +1. Start rviz and select panels/Add new panel. + ![select_panel](./images/select_panels.png) +2. Select tier4_string_viewer_rviz_plugin/StringViewerPanel and press OK. diff --git a/common/tier4_string_viewer_rviz_plugin/icons/classes/AutowareDateTimePanel.png b/common/tier4_string_viewer_rviz_plugin/icons/classes/AutowareDateTimePanel.png new file mode 100644 index 00000000..9431c2d4 Binary files /dev/null and b/common/tier4_string_viewer_rviz_plugin/icons/classes/AutowareDateTimePanel.png differ diff --git a/common/tier4_string_viewer_rviz_plugin/images/select_datetime_plugin.png b/common/tier4_string_viewer_rviz_plugin/images/select_datetime_plugin.png new file mode 100644 index 00000000..6485b973 Binary files /dev/null and b/common/tier4_string_viewer_rviz_plugin/images/select_datetime_plugin.png differ diff --git a/common/tier4_string_viewer_rviz_plugin/images/select_panels.png b/common/tier4_string_viewer_rviz_plugin/images/select_panels.png new file mode 100644 index 00000000..a691602c Binary files /dev/null and b/common/tier4_string_viewer_rviz_plugin/images/select_panels.png differ diff --git a/common/tier4_string_viewer_rviz_plugin/package.xml b/common/tier4_string_viewer_rviz_plugin/package.xml new file mode 100644 index 00000000..2f196167 --- /dev/null +++ b/common/tier4_string_viewer_rviz_plugin/package.xml @@ -0,0 +1,28 @@ + + + + tier4_string_viewer_rviz_plugin + 0.0.0 + The tier4_string_viewer_rviz_plugin package + Satoshi Ota + Apache License 2.0 + + ament_cmake_auto + autoware_cmake + + libqt5-core + libqt5-gui + libqt5-widgets + qtbase5-dev + rclcpp + rviz_common + tier4_debug_msgs + + ament_lint_auto + autoware_lint_common + + + ament_cmake + + + diff --git a/common/tier4_string_viewer_rviz_plugin/plugins/plugin_description.xml b/common/tier4_string_viewer_rviz_plugin/plugins/plugin_description.xml new file mode 100644 index 00000000..7ed9c664 --- /dev/null +++ b/common/tier4_string_viewer_rviz_plugin/plugins/plugin_description.xml @@ -0,0 +1,7 @@ + + + StringViewerPanel + + diff --git a/common/tier4_string_viewer_rviz_plugin/src/string_viewer_panel.cpp b/common/tier4_string_viewer_rviz_plugin/src/string_viewer_panel.cpp new file mode 100644 index 00000000..5e7805d2 --- /dev/null +++ b/common/tier4_string_viewer_rviz_plugin/src/string_viewer_panel.cpp @@ -0,0 +1,86 @@ +// Copyright 2024 TIER IV, Inc. +// +// 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 "string_viewer_panel.hpp" + +#include +#include + +#include + +namespace tier4_string_viewer_rviz_plugin +{ + +StringViewerPanel::StringViewerPanel(QWidget * parent) : rviz_common::Panel(parent) +{ + auto * layout = new QVBoxLayout(this); + + topic_list_ = new QComboBox(); + layout->addWidget(topic_list_); + + contents_ = new QLabel; + layout->addWidget(contents_); + + setLayout(layout); + + connect( + topic_list_, SIGNAL(currentIndexChanged(const QString &)), this, + SLOT(on_topic_name(const QString &))); +} + +void StringViewerPanel::onInitialize() +{ + raw_node_ = this->getDisplayContext()->getRosNodeAbstraction().lock()->get_raw_node(); + + using namespace std::literals::chrono_literals; + timer_ = raw_node_->create_wall_timer(1000ms, [&]() { on_timer(); }); +} + +void StringViewerPanel::on_topic_name(const QString & topic) +{ + contents_->clear(); + sub_string_.reset(); + sub_string_ = raw_node_->create_subscription( + topic.toStdString(), rclcpp::QoS{1}, + std::bind(&StringViewerPanel::on_string, this, std::placeholders::_1)); +} + +void StringViewerPanel::on_string(const StringStamped::ConstSharedPtr msg) +{ + contents_->setText(msg->data.c_str()); + contents_->setWordWrap(true); +} + +void StringViewerPanel::on_timer() +{ + const auto std_message_type = rosidl_generator_traits::name(); + const auto published_topics = raw_node_->get_topic_names_and_types(); + + if (published_topics.size() == topic_num_) return; + + for (const auto & topic : published_topics) { + // Only add topics whose type matches. + for (const auto & type : topic.second) { + if (type == std_message_type) { + topic_list_->addItem(QString::fromStdString(topic.first)); + } + } + } + + topic_num_ = published_topics.size(); +} +} // namespace tier4_string_viewer_rviz_plugin + +#include +PLUGINLIB_EXPORT_CLASS(tier4_string_viewer_rviz_plugin::StringViewerPanel, rviz_common::Panel) diff --git a/common/tier4_string_viewer_rviz_plugin/src/string_viewer_panel.hpp b/common/tier4_string_viewer_rviz_plugin/src/string_viewer_panel.hpp new file mode 100644 index 00000000..380a10fc --- /dev/null +++ b/common/tier4_string_viewer_rviz_plugin/src/string_viewer_panel.hpp @@ -0,0 +1,65 @@ +// Copyright 2024 TIER IV, Inc. +// +// 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 STRING_VIEWER_PANEL_HPP_ +#define STRING_VIEWER_PANEL_HPP_ + +#include +#include +#include +#include +#include +#include + +#include + +namespace tier4_string_viewer_rviz_plugin +{ + +using tier4_debug_msgs::msg::StringStamped; + +class QLineEdit; + +class StringViewerPanel : public rviz_common::Panel +{ + Q_OBJECT + +public: + explicit StringViewerPanel(QWidget * parent = nullptr); + + void onInitialize() override; + +private Q_SLOTS: + void on_topic_name(const QString & topic); + +private: + void on_string(const StringStamped::ConstSharedPtr msg); + + void on_timer(); + + QLabel * contents_; + + QComboBox * topic_list_; + + rclcpp::Node::SharedPtr raw_node_; + + rclcpp::TimerBase::SharedPtr timer_; + + rclcpp::Subscription::SharedPtr sub_string_; + + size_t topic_num_{0L}; +}; +} // namespace tier4_string_viewer_rviz_plugin + +#endif // STRING_VIEWER_PANEL_HPP_