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 <vector>
43
44#include <rclcpp/version.h>
45
46#include <visualization_msgs/msg/interactive_marker.hpp>
47#include <visualization_msgs/msg/interactive_marker_update.hpp>
48#include <visualization_msgs/msg/interactive_marker_init.hpp>
49
50#ifndef Q_MOC_RUN
51#include <interactive_markers/interactive_marker_client.hpp>
52#endif
53
54#include <rviz_common/display.hpp>
55
56#include <rviz_default_plugins/displays/interactive_markers/interactive_marker.hpp>
57
58namespace rviz_common
59{
60class BoolProperty;
61class Object;
62} // namespace rviz_common
63
65{
66class InteractiveMarkerNamespaceProperty;
67
68namespace displays
69{
70class MarkerBase;
71
73class InteractiveMarkerDisplay : public rviz_common::Display
74{
75 Q_OBJECT
76
77public:
80 {
81 private_executor_->cancel();
82 if (private_executor_thread_.joinable())
83 private_executor_thread_.join();
84 private_executor_.reset();
85 }
86
87 // Overrides from Display.
88 // rviz_common 16.0.1 (Rolling) removed the deprecated (float, float) overload
89 // in favor of (std::chrono::nanoseconds, std::chrono::nanoseconds); see
90 // ros2/rviz#1533. Remove this branch when Kilted goes EOL.
91 // For Rolling, L-turtle, and newer
92#if RCLCPP_VERSION_GTE(30, 0, 0)
93 void update(std::chrono::nanoseconds wall_dt, std::chrono::nanoseconds ros_dt) override;
94 // For Kilted and older
95#else
96 void update(float wall_dt, float ros_dt) override;
97#endif
98
99 void reset() override;
100
101protected:
102 // Overrides from Display
103 void fixedFrameChanged() override;
104
105 void onInitialize() override;
106
107 void onEnable() override;
108
109 void onDisable() override;
110
111protected Q_SLOTS:
112 void namespaceChanged();
114 void updateShowAxes();
117 void publishFeedback(visualization_msgs::msg::InteractiveMarkerFeedback& feedback);
118 void onStatusUpdate(rviz_common::properties::StatusProperty::Level level, const std::string& name,
119 const std::string& text);
120
121private:
123 void subscribe();
124
126 void unsubscribe();
127
129 void initializeCallback(const visualization_msgs::srv::GetInteractiveMarkers::Response::SharedPtr& /*msg*/);
130
132 void updateCallback(const visualization_msgs::msg::InteractiveMarkerUpdate::ConstSharedPtr& msg);
133
135 void resetCallback();
136
138 void statusCallback(interactive_markers::InteractiveMarkerClient::Status /*status*/, const std::string& message);
139
140 void updateMarkers(const std::vector<visualization_msgs::msg::InteractiveMarker>& markers);
141
142 void updatePoses(const std::vector<visualization_msgs::msg::InteractiveMarkerPose>& marker_poses);
143
145 void eraseAllMarkers();
146
148
151 void eraseMarkers(const std::vector<std::string>& names);
152
153 std::map<std::string, InteractiveMarker::SharedPtr> interactive_markers_map_;
154
155 // Properties
156 InteractiveMarkerNamespaceProperty* interactive_marker_namespace_property_;
157 rviz_common::properties::BoolProperty* show_descriptions_property_;
158 rviz_common::properties::BoolProperty* show_axes_property_;
159 rviz_common::properties::BoolProperty* show_visual_aids_property_;
160 rviz_common::properties::BoolProperty* enable_transparency_property_;
161
162 std::unique_ptr<interactive_markers::InteractiveMarkerClient> interactive_marker_client_;
163
164 std::shared_ptr<rclcpp::Node> pnode_;
165 std::shared_ptr<rclcpp::executors::SingleThreadedExecutor> private_executor_;
166 std::thread private_executor_thread_;
167}; // class InteractiveMarkerDisplay
168
169} // namespace displays
170} // 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)