moveit2
The MoveIt Motion Planning Framework for ROS 2.
Loading...
Searching...
No Matches
trajectory_visualization.hpp
Go to the documentation of this file.
1/*********************************************************************
2 * Software License Agreement (BSD License)
3 *
4 * Copyright (c) 2008, Willow Garage, Inc.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
17 * * Neither the name of Willow Garage nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 *********************************************************************/
34
35/* Author: Dave Coleman */
36
37#pragma once
38
39#include <rclcpp/version.h>
40
42#include <rviz_common/display.hpp>
43#include <rviz_common/panel_dock_widget.hpp>
44#include <rviz_common/properties/int_property.hpp>
45#include <rviz_common/properties/ros_topic_property.hpp>
46#include <mutex>
47#include <rclcpp/logger.hpp>
48
49#ifndef Q_MOC_RUN
52#include <rclcpp/rclcpp.hpp>
56#include <moveit_msgs/msg/display_trajectory.hpp>
57#endif
58
59namespace rviz
60{
61class Robot;
62class Shape;
63class Property;
64class IntProperty;
65class StringProperty;
66class BoolProperty;
67class FloatProperty;
68class RosTopicProperty;
69class EditableEnumProperty;
70class ColorProperty;
71class MovableText;
72} // namespace rviz
73
74namespace moveit_rviz_plugin
75{
76MOVEIT_CLASS_FORWARD(TrajectoryVisualization); // Defines TrajectoryVisualizationPtr, ConstPtr, WeakPtr... etc
77
78class TrajectoryVisualization : public QObject
79{
80 Q_OBJECT
81
82public:
89 TrajectoryVisualization(rviz_common::properties::Property* widget, rviz_common::Display* display);
90
91 ~TrajectoryVisualization() override;
92
93 virtual void update(std::chrono::nanoseconds wall_dt, std::chrono::nanoseconds sim_dt);
94// For Rolling, L-turtle, and newer
95#if RCLCPP_VERSION_GTE(30, 0, 0)
96 [[deprecated("Use update(std::chrono::nanoseconds, std::chrono::nanoseconds) instead")]] virtual void
97 update(double wall_dt, double ros_dt);
98// For Kilted and older
99#else
100 virtual void update(double wall_dt, double ros_dt);
101#endif
102 virtual void reset();
103
104 void onInitialize(const rclcpp::Node::SharedPtr& node, Ogre::SceneNode* scene_node,
105 rviz_common::DisplayContext* context);
106 void clearRobotModel();
107 void onRobotModelLoaded(const moveit::core::RobotModelConstPtr& robot_model);
108 void onEnable();
109 void onDisable();
110 void setName(const QString& name);
111
112 void dropTrajectory();
113
114public Q_SLOTS:
116 void setDefaultAttachedObjectColor(const QColor& color);
117
118private Q_SLOTS:
119
123 void changedDisplayPathVisualEnabled();
124 void changedDisplayPathCollisionEnabled();
125 void changedRobotPathAlpha();
126 void changedLoopDisplay();
127 void changedShowTrail();
128 void changedTrailStepSize();
129 void changedTrajectoryTopic();
130 void changedStateDisplayTime();
131 void changedRobotColor();
132 void enabledRobotColor();
133 void trajectorySliderPanelVisibilityChange(bool enable);
134
135protected:
139 void incomingDisplayTrajectory(const moveit_msgs::msg::DisplayTrajectory::ConstSharedPtr& msg);
140
146 double getStateDisplayTime();
148
149 // Handles actually drawing the robot along motion plans
150 RobotStateVisualizationPtr display_path_robot_;
151 std_msgs::msg::ColorRGBA default_attached_object_color_;
152
153 // Handle colouring of robot
154 void setRobotColor(rviz_default_plugins::robot::Robot* robot, const QColor& color);
155 void unsetRobotColor(rviz_default_plugins::robot::Robot* robot);
156
157 robot_trajectory::RobotTrajectoryPtr displaying_trajectory_message_;
158 robot_trajectory::RobotTrajectoryPtr trajectory_message_to_display_;
159 std::vector<RobotStateVisualizationUniquePtr> trajectory_trail_;
160 rclcpp::Subscription<moveit_msgs::msg::DisplayTrajectory>::SharedPtr trajectory_topic_sub_;
166
167 moveit::core::RobotModelConstPtr robot_model_;
168 moveit::core::RobotStatePtr robot_state_;
169
170 // Pointers from parent display that we save
171 rviz_common::Display* display_; // the parent display that this class populates
172 rviz_common::properties::Property* widget_;
173 Ogre::SceneNode* scene_node_;
174 rviz_common::DisplayContext* context_;
175 rclcpp::Node::SharedPtr node_;
177 rviz_common::PanelDockWidget* trajectory_slider_dock_panel_;
178 rclcpp::Logger logger_;
179
180 // Properties
181 rviz_common::properties::BoolProperty* display_path_visual_enabled_property_;
182 rviz_common::properties::BoolProperty* display_path_collision_enabled_property_;
183 rviz_common::properties::EditableEnumProperty* state_display_time_property_;
184 rviz_common::properties::RosTopicProperty* trajectory_topic_property_;
185 rviz_common::properties::FloatProperty* robot_path_alpha_property_;
186 rviz_common::properties::BoolProperty* loop_display_property_;
187 rviz_common::properties::BoolProperty* use_sim_time_property_;
188 rviz_common::properties::BoolProperty* trail_display_property_;
189 rviz_common::properties::BoolProperty* interrupt_display_property_;
190 rviz_common::properties::ColorProperty* robot_color_property_;
191 rviz_common::properties::BoolProperty* enable_robot_color_property_;
192 rviz_common::properties::IntProperty* trail_step_size_property_;
193};
194
195} // namespace moveit_rviz_plugin
#define MOVEIT_CLASS_FORWARD(C)
rviz_common::properties::BoolProperty * enable_robot_color_property_
void incomingDisplayTrajectory(const moveit_msgs::msg::DisplayTrajectory::ConstSharedPtr &msg)
ROS callback for an incoming path message.
rviz_common::properties::BoolProperty * display_path_visual_enabled_property_
rviz_common::properties::BoolProperty * interrupt_display_property_
robot_trajectory::RobotTrajectoryPtr trajectory_message_to_display_
robot_trajectory::RobotTrajectoryPtr displaying_trajectory_message_
rviz_common::PanelDockWidget * trajectory_slider_dock_panel_
void onInitialize(const rclcpp::Node::SharedPtr &node, Ogre::SceneNode *scene_node, rviz_common::DisplayContext *context)
rviz_common::properties::BoolProperty * trail_display_property_
virtual void update(std::chrono::nanoseconds wall_dt, std::chrono::nanoseconds sim_dt)
rviz_common::properties::BoolProperty * display_path_collision_enabled_property_
rviz_common::properties::RosTopicProperty * trajectory_topic_property_
rviz_common::properties::BoolProperty * use_sim_time_property_
rviz_common::properties::BoolProperty * loop_display_property_
rviz_common::properties::ColorProperty * robot_color_property_
void setRobotColor(rviz_default_plugins::robot::Robot *robot, const QColor &color)
rviz_common::properties::EditableEnumProperty * state_display_time_property_
rviz_common::properties::IntProperty * trail_step_size_property_
std::vector< RobotStateVisualizationUniquePtr > trajectory_trail_
void unsetRobotColor(rviz_default_plugins::robot::Robot *robot)
void onRobotModelLoaded(const moveit::core::RobotModelConstPtr &robot_model)
rviz_common::properties::FloatProperty * robot_path_alpha_property_
rclcpp::Subscription< moveit_msgs::msg::DisplayTrajectory >::SharedPtr trajectory_topic_sub_
double getStateDisplayTime()
get time to show each single robot state