-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1150 from tier4/feature/real-time-factor-control
Feature/real time factor control
- Loading branch information
Showing
18 changed files
with
286 additions
and
27 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
rviz_plugins/real_time_factor_control_rviz_plugin/CMakeLists.txt
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,25 @@ | ||
cmake_minimum_required(VERSION 3.14) | ||
|
||
project(real_time_factor_control_rviz_plugin) | ||
|
||
find_package(ament_cmake_auto REQUIRED) | ||
find_package(Qt5 REQUIRED Core Widgets) | ||
|
||
ament_auto_find_build_dependencies() | ||
|
||
set(QT_LIBRARIES Qt5::Widgets) | ||
set(CMAKE_AUTOMOC ON) | ||
set(CMAKE_INCLUDE_CURRENT_DIR ON) | ||
|
||
ament_auto_add_library(${PROJECT_NAME} SHARED src/real_time_factor_slider.cpp) | ||
|
||
target_compile_definitions(${PROJECT_NAME} PUBLIC QT_NO_KEYWORDS) | ||
|
||
target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src) | ||
|
||
target_link_libraries(${PROJECT_NAME} ${QT_LIBRARIES}) | ||
|
||
# Export the plugin to be imported by rviz2 | ||
pluginlib_export_plugin_description_file(rviz_common plugins/plugin_description.xml) | ||
|
||
ament_auto_package() |
28 changes: 28 additions & 0 deletions
28
rviz_plugins/real_time_factor_control_rviz_plugin/package.xml
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,28 @@ | ||
<?xml version="1.0"?> | ||
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?> | ||
<package format="3"> | ||
<name>real_time_factor_control_rviz_plugin</name> | ||
<version>0.1.0</version> | ||
<description>Slider controlling real time factor value.</description> | ||
<maintainer email="[email protected]">Paweł Lech</maintainer> | ||
<license>Apache License 2.0</license> | ||
|
||
<author email="[email protected]">Paweł Lech</author> | ||
|
||
<buildtool_depend>ament_cmake</buildtool_depend> | ||
<buildtool_depend>ament_cmake_auto</buildtool_depend> | ||
|
||
<depend>libqt5-core</depend> | ||
<depend>libqt5-widgets</depend> | ||
<depend>qtbase5-dev</depend> | ||
<depend>rviz_common</depend> | ||
<depend>std_msgs</depend> | ||
|
||
<test_depend>ament_lint_auto</test_depend> | ||
<test_depend>autoware_lint_common</test_depend> | ||
|
||
<export> | ||
<build_type>ament_cmake</build_type> | ||
<rviz plugin="${prefix}/plugins/plugin_description.xml"/> | ||
</export> | ||
</package> |
7 changes: 7 additions & 0 deletions
7
rviz_plugins/real_time_factor_control_rviz_plugin/plugins/plugin_description.xml
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,7 @@ | ||
<library path="real_time_factor_control_rviz_plugin"> | ||
<class name="real_time_factor_control_rviz_plugin/RealTimeFactorSliderPanel" | ||
type="real_time_factor_control_rviz_plugin::RealTimeFactorSliderPanel" | ||
base_class_type="rviz_common::Panel"> | ||
<description> Slider controlling real time factor value. </description> | ||
</class> | ||
</library> |
64 changes: 64 additions & 0 deletions
64
rviz_plugins/real_time_factor_control_rviz_plugin/src/real_time_factor_slider.cpp
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,64 @@ | ||
// | ||
// Copyright 2020 Tier IV, Inc. All rights reserved. | ||
// | ||
// 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 <pluginlib/class_list_macros.hpp> | ||
#include <qt5/QtWidgets/QHBoxLayout> | ||
#include <real_time_factor_slider.hpp> | ||
#include <rviz_common/display_context.hpp> | ||
|
||
namespace real_time_factor_control_rviz_plugin | ||
{ | ||
RealTimeFactorSliderPanel::RealTimeFactorSliderPanel(QWidget * parent) | ||
: rviz_common::Panel(parent), | ||
value_label_(new QLabel("x 1.00")), | ||
slider_(new QSlider(Qt::Horizontal)) | ||
{ | ||
value_label_->setAlignment(Qt::AlignCenter); | ||
|
||
slider_->setMinimum(1); | ||
slider_->setMaximum(200); | ||
slider_->setTickInterval(1); | ||
slider_->setValue(100); | ||
|
||
auto layout = new QHBoxLayout(this); | ||
layout->addWidget(value_label_); | ||
layout->addWidget(slider_); | ||
|
||
setLayout(layout); | ||
} | ||
|
||
auto RealTimeFactorSliderPanel::onChangedRealTimeFactorValue(int percentage) -> void | ||
{ | ||
std_msgs::msg::Float64 real_time_factor; | ||
real_time_factor.data = percentage / 100.0; | ||
real_time_factor_publisher->publish(real_time_factor); | ||
value_label_->setText(QString("x ") + QString::number(real_time_factor.data, 'f', 2)); | ||
} | ||
|
||
auto RealTimeFactorSliderPanel::onInitialize() -> void | ||
{ | ||
real_time_factor_publisher = getDisplayContext() | ||
->getRosNodeAbstraction() | ||
.lock() | ||
->get_raw_node() | ||
->create_publisher<std_msgs::msg::Float64>("/real_time_factor", 1); | ||
|
||
connect(slider_, SIGNAL(valueChanged(int)), SLOT(onChangedRealTimeFactorValue(int))); | ||
} | ||
} // namespace real_time_factor_control_rviz_plugin | ||
|
||
PLUGINLIB_EXPORT_CLASS( | ||
real_time_factor_control_rviz_plugin::RealTimeFactorSliderPanel, rviz_common::Panel) |
56 changes: 56 additions & 0 deletions
56
rviz_plugins/real_time_factor_control_rviz_plugin/src/real_time_factor_slider.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 |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// | ||
// Copyright 2023 Tier IV, Inc. All rights reserved. | ||
// | ||
// 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 REAL_TIME_FACTOR_SLIDER_PANEL_HPP_ | ||
#define REAL_TIME_FACTOR_SLIDER_PANEL_HPP_ | ||
|
||
#include <qt5/QtWidgets/QLabel> | ||
#include <qt5/QtWidgets/QSlider> | ||
#include <std_msgs/msg/float64.hpp> | ||
|
||
#ifndef Q_MOC_RUN | ||
#include <rclcpp/rclcpp.hpp> | ||
#include <rviz_common/panel.hpp> | ||
#endif | ||
|
||
namespace real_time_factor_control_rviz_plugin | ||
{ | ||
class RealTimeFactorSliderPanel : public rviz_common::Panel | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
explicit RealTimeFactorSliderPanel(QWidget * parent = nullptr); | ||
|
||
auto onInitialize() -> void override; | ||
|
||
public Q_SLOTS: | ||
/* | ||
Declaring this function by trailing return type causes Qt AutoMoc | ||
subprocess error. | ||
*/ | ||
void onChangedRealTimeFactorValue(int real_time_factor_value); | ||
|
||
protected: | ||
rclcpp::Publisher<std_msgs::msg::Float64>::SharedPtr real_time_factor_publisher; | ||
|
||
QLabel * const value_label_; | ||
|
||
QSlider * const slider_; | ||
}; | ||
} // namespace real_time_factor_control_rviz_plugin | ||
|
||
#endif // REAL_TIME_FACTOR_SLIDER_PANEL_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
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
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
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
Oops, something went wrong.