moveit2
The MoveIt Motion Planning Framework for ROS 2.
Loading...
Searching...
No Matches
interactive_marker_display.hpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2008, Willow Garage, Inc.
3 * Copyright (c) 2019, Open Source Robotics Foundation, Inc.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
8 *
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * * Neither the name of the copyright holder nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
29 */
30
31// TODO(JafarAbdi): Remove this file once the lag issue is fixed upstream https://github.com/ros2/rviz/issues/548
32// This file is copied from https://github.com/ros2/rviz, the only difference is the addition of the private members
33// pnode_, private_executor_, and private_executor_thread_ to fix the lag in the motion planning display interactive
34// marker cause by Rviz having only a single thread executor
35
36#pragma once
37
38#include <chrono>
39#include <map>
40#include <memory>
41#include <string>
42#include <thread>
43#include <vector>
44
45#include <rclcpp/executors/single_threaded_executor.hpp>
46#include <rclcpp/node.hpp>
47#include <rclcpp/version.h>
48
49#include <visualization_msgs/msg/interactive_marker.hpp>
50#include <visualization_msgs/msg/interactive_marker_update.hpp>
51#include <visualization_msgs/msg/interactive_marker_init.hpp>
52
53#ifndef Q_MOC_RUN
54#include <interactive_markers/interactive_marker_client.hpp>
55#endif
56
57#include <rviz_common/display.hpp>
58
59#include <rviz_default_plugins/displays/interactive_markers/interactive_marker.hpp>
60
61namespace rviz_common
62{
63class BoolProperty;
64class Object;
65} // namespace rviz_common
66
68{
69class InteractiveMarkerNamespaceProperty;
70
71namespace displays
72{
73class MarkerBase;
74
76class InteractiveMarkerDisplay : public rviz_common::Display
77{
78 Q_OBJECT
79
80public:
83 {
84 private_executor_->cancel();
85 if (private_executor_thread_.joinable())
86 private_executor_thread_.join();
87 private_executor_.reset();
88 }
89
90 // Overrides from Display.
91 // rviz_common 16.0.1 (Rolling) removed the deprecated (float, float) overload
92 // in favor of (std::chrono::nanoseconds, std::chrono::nanoseconds); see
93 // ros2/rviz#1533. Remove this branch when Kilted goes EOL.
94 // For Rolling, L-turtle, and newer
95#if RCLCPP_VERSION_GTE(30, 0, 0)
96 void update(std::chrono::nanoseconds wall_dt, std::chrono::nanoseconds ros_dt) override;
97 // For Kilted and older
98#else
99 void update(float wall_dt, float ros_dt) override;
100#endif
101
102 void reset() override;
103
104protected:
105 // Overrides from Display
106 void fixedFrameChanged() override;
107
108 void onInitialize() override;
109
110 void onEnable() override;
111
112 void onDisable() override;
113
114protected Q_SLOTS:
115 void namespaceChanged();
117 void updateShowAxes();
120 void publishFeedback(visualization_msgs::msg::InteractiveMarkerFeedback& feedback);
121 void onStatusUpdate(rviz_common::properties::StatusProperty::Level level, const std::string& name,
122 const std::string& text);
123
124private:
126 void subscribe();
127
129 void unsubscribe();
130
132 void initializeCallback(const visualization_msgs::srv::GetInteractiveMarkers::Response::SharedPtr& /*msg*/);
133
135 void updateCallback(const visualization_msgs::msg::InteractiveMarkerUpdate::ConstSharedPtr& msg);
136
138 void resetCallback();
139
141 void statusCallback(interactive_markers::InteractiveMarkerClient::Status /*status*/, const std::string& message);
142
143 void updateMarkers(const std::vector<visualization_msgs::msg::InteractiveMarker>& markers);
144
145 void updatePoses(const std::vector<visualization_msgs::msg::InteractiveMarkerPose>& marker_poses);
146
148 void eraseAllMarkers();
149
151
154 void eraseMarkers(const std::vector<std::string>& names);
155
156 std::map<std::string, InteractiveMarker::SharedPtr> interactive_markers_map_;
157
158 // Properties
159 InteractiveMarkerNamespaceProperty* interactive_marker_namespace_property_;
160 rviz_common::properties::BoolProperty* show_descriptions_property_;
161 rviz_common::properties::BoolProperty* show_axes_property_;
162 rviz_common::properties::BoolProperty* show_visual_aids_property_;
163 rviz_common::properties::BoolProperty* enable_transparency_property_;
164
165 std::unique_ptr<interactive_markers::InteractiveMarkerClient> interactive_marker_client_;
166
167 std::shared_ptr<rclcpp::Node> pnode_;
168 std::shared_ptr<rclcpp::executors::SingleThreadedExecutor> private_executor_;
169 std::thread private_executor_thread_;
170}; // class InteractiveMarkerDisplay
171
172} // namespace displays
173} // namespace rviz_default_plugins
void publishFeedback(visualization_msgs::msg::InteractiveMarkerFeedback &feedback)
void onStatusUpdate(rviz_common::properties::StatusProperty::Level level, const std::string &name, const std::string &text)