Skip to content
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

Use Rviz as a component #1140

Draft
wants to merge 1 commit into
base: rolling
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions rviz_common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ find_package(Qt5 REQUIRED COMPONENTS Widgets)
find_package(geometry_msgs REQUIRED)
find_package(pluginlib REQUIRED)
find_package(rclcpp REQUIRED)
find_package(rclcpp_components REQUIRED)
find_package(resource_retriever REQUIRED)
find_package(rviz_rendering REQUIRED)
find_package(sensor_msgs REQUIRED)
Expand Down Expand Up @@ -239,6 +240,8 @@ target_link_libraries(rviz_common PUBLIC
pluginlib::pluginlib
Qt5::Widgets
rclcpp::rclcpp
rclcpp_components::component
rclcpp_components::component_manager
rviz_ogre_vendor::OgreMain
rviz_ogre_vendor::OgreOverlay
rviz_rendering::rviz_rendering
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright (c) 2024, Open Source Robotics Foundation.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the Willow Garage, Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/

#ifndef RVIZ_COMMON__ROS_INTEGRATION__ROS_COMPONENT_MANAGER_HPP_
#define RVIZ_COMMON__ROS_INTEGRATION__ROS_COMPONENT_MANAGER_HPP_

#include "rclcpp_components/component_manager.hpp"
#include "rclcpp_components/node_instance_wrapper.hpp"
#include "rviz_common/visibility_control.hpp"

namespace rviz_common
{
namespace ros_integration
{
class RVIZ_COMMON_PUBLIC ComponentManager : public rclcpp_components::ComponentManager{
public:
using rclcpp_components::ComponentManager::ComponentManager;

void
add_node_to_executor(
rclcpp_components::NodeInstanceWrapper & node)
{
auto node_id = unique_id_++;
node_wrappers_[node_id] = node;
if (auto exec = this->executor_.lock()) {
exec->add_node(node.get_node_base_interface(), true);
}
}
};
} // namespace ros_integration
} // namespace rviz_common

#endif // RVIZ_COMMON__ROS_INTEGRATION__ROS_COMPONENT_MANAGER_HPP_
2 changes: 2 additions & 0 deletions rviz_common/include/rviz_common/visualization_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
#include "rviz_common/display_context.hpp"
#include "rviz_common/frame_manager_iface.hpp"
#include "rviz_common/ros_integration/ros_node_abstraction_iface.hpp"
#include "rviz_common/ros_integration/ros_component_manager.hpp"
#include "rviz_common/transformation/transformation_manager.hpp"

class QTimer;
Expand Down Expand Up @@ -399,6 +400,7 @@ private Q_SLOTS:
rclcpp::executors::SingleThreadedExecutor::SharedPtr executor_;
ros_integration::RosNodeAbstractionIface::WeakPtr rviz_ros_node_;
rviz_common::transformation::TransformationManager * transformation_manager_;
std::shared_ptr<ros_integration::ComponentManager> mgr_;
};

} // 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 @@ -40,6 +40,7 @@
<depend>geometry_msgs</depend>
<depend>pluginlib</depend>
<depend>rclcpp</depend>
<depend>rclcpp_components</depend>
<depend>resource_retriever</depend>
<depend>rviz_ogre_vendor</depend>
<depend>rviz_rendering</depend>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ namespace ros_integration
{

RosNodeAbstraction::RosNodeAbstraction(const std::string & node_name)
: raw_node_(rclcpp::Node::make_shared(node_name))
: raw_node_(rclcpp::Node::make_shared(node_name, rclcpp::NodeOptions().use_intra_process_comms(true)))
{}

std::string
Expand Down
11 changes: 10 additions & 1 deletion rviz_common/src/rviz_common/visualization_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@

#include "rclcpp/clock.hpp"
#include "rclcpp/time.hpp"
#include <rclcpp_components/node_instance_wrapper.hpp>
#include "rviz_rendering/material_manager.hpp"
#include "rviz_rendering/render_window.hpp"

Expand Down Expand Up @@ -225,7 +226,15 @@ VisualizationManager::VisualizationManager(

connect(this, SIGNAL(timeJumped()), this, SLOT(resetTime()));

executor_->add_node(rviz_ros_node_.lock()->get_raw_node());
if (!mgr_) {
mgr_ = std::make_shared<ros_integration::ComponentManager>(executor_);
executor_->add_node(mgr_);

auto inst = rclcpp_components::NodeInstanceWrapper(
rviz_ros_node_.lock()->get_raw_node(),
std::bind(&rclcpp::Node::get_node_base_interface, rviz_ros_node_.lock()->get_raw_node()));
mgr_->add_node_to_executor(inst);
}

display_factory_ = new DisplayFactory();

Expand Down