Skip to content

Commit

Permalink
Implement reset time service (#1109)
Browse files Browse the repository at this point in the history
  • Loading branch information
hyunseok-yang authored Dec 26, 2023
1 parent bb2ab95 commit a4f4de9
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 5 deletions.
3 changes: 3 additions & 0 deletions rviz_common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ find_package(resource_retriever REQUIRED)
find_package(rviz_rendering REQUIRED)
find_package(sensor_msgs REQUIRED)
find_package(std_msgs REQUIRED)
find_package(std_srvs REQUIRED)
find_package(tinyxml2_vendor REQUIRED)
find_package(tf2 REQUIRED)
find_package(tf2_ros REQUIRED)
Expand Down Expand Up @@ -243,6 +244,7 @@ target_link_libraries(rviz_common PUBLIC
rviz_rendering::rviz_rendering
${sensor_msgs_TARGETS}
${std_msgs_TARGETS}
${std_srvs_TARGETS}
tf2::tf2
tf2_ros::tf2_ros
yaml-cpp
Expand All @@ -267,6 +269,7 @@ ament_export_dependencies(
rviz_rendering
sensor_msgs
std_msgs
std_srvs
tf2
tf2_ros
yaml_cpp_vendor
Expand Down
12 changes: 12 additions & 0 deletions rviz_common/include/rviz_common/view_controller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#define RVIZ_COMMON__VIEW_CONTROLLER_HPP_

#include <string>
#include <memory>

#include <OgreVector.h>

Expand All @@ -40,6 +41,8 @@
#include <QString> // NOLINT: cpplint is unable to handle the include order here
#include <Qt> // NOLINT: cpplint is unable to handle the include order here
#include <QVariant> // NOLINT: cpplint is unable to handle the include order here
#include <rclcpp/service.hpp>
#include <std_srvs/srv/empty.hpp>

#include "rviz_common/properties/property.hpp"
#include "rviz_common/visibility_control.hpp"
Expand Down Expand Up @@ -211,6 +214,8 @@ class RVIZ_COMMON_PUBLIC ViewController : public properties::Property

virtual FocalPointStatus getFocalPointStatus();

void resetTime();

Q_SIGNALS:
void configChanged();

Expand Down Expand Up @@ -279,6 +284,13 @@ private Q_SLOTS:

// Default cursors for the most common actions
QMap<CursorType, QCursor> standard_cursors_;

rclcpp::Service<std_srvs::srv::Empty>::SharedPtr reset_time_srv_;

void resetService(
const std::shared_ptr<rmw_request_id_t>,
const std::shared_ptr<std_srvs::srv::Empty::Request>,
const std::shared_ptr<std_srvs::srv::Empty::Response>);
};

} // namespace rviz_common
Expand Down
1 change: 1 addition & 0 deletions rviz_common/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
<depend>rviz_rendering</depend>
<depend>sensor_msgs</depend>
<depend>std_msgs</depend>
<depend>std_srvs</depend>
<depend>tf2</depend>
<depend>tf2_ros</depend>
<depend>message_filters</depend>
Expand Down
33 changes: 28 additions & 5 deletions rviz_common/src/rviz_common/view_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,16 @@ void ViewController::initialize(DisplayContext * context)
stereo_enable_->setBool(false);
stereo_enable_->hide();
// }

auto ros_node_abstraction = context_->getRosNodeAbstraction().lock();
if (ros_node_abstraction) {
auto node = ros_node_abstraction->get_raw_node();
reset_time_srv_ = node->create_service<std_srvs::srv::Empty>(
ros_node_abstraction->get_node_name() + "/reset_time",
std::bind(
&ViewController::resetService, this,
std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
}
}

ViewController::~ViewController()
Expand Down Expand Up @@ -235,12 +245,25 @@ void ViewController::handleKeyEvent(QKeyEvent * event, RenderPanel * panel)
}

if (event->key() == Qt::Key_R) {
rviz_common::VisualizationManager * vis_manager =
dynamic_cast<rviz_common::VisualizationManager *>(context_);
resetTime();
}
}

if (vis_manager != nullptr) {
vis_manager->resetTime();
}
void ViewController::resetService(
const std::shared_ptr<rmw_request_id_t>,
const std::shared_ptr<std_srvs::srv::Empty::Request>,
const std::shared_ptr<std_srvs::srv::Empty::Response>)
{
resetTime();
}

void ViewController::resetTime()
{
rviz_common::VisualizationManager * vis_manager =
dynamic_cast<rviz_common::VisualizationManager *>(context_);

if (vis_manager != nullptr) {
vis_manager->resetTime();
}
}

Expand Down

0 comments on commit a4f4de9

Please sign in to comment.