37#include <boost/algorithm/string.hpp>
38#include <boost/algorithm/string/replace.hpp>
44#include <rviz_default_plugins/robot/robot.hpp>
47#include <rviz_common/display_context.hpp>
48#include <rviz_common/properties/bool_property.hpp>
49#include <rviz_common/properties/color_property.hpp>
50#include <rviz_common/properties/editable_enum_property.hpp>
51#include <rviz_common/properties/float_property.hpp>
52#include <rviz_common/properties/int_property.hpp>
53#include <rviz_common/properties/property.hpp>
54#include <rviz_common/properties/ros_topic_property.hpp>
55#include <rviz_common/properties/string_property.hpp>
56#include <rviz_default_plugins/robot/robot_link.hpp>
57#include <rviz_common/window_manager_interface.hpp>
61using namespace std::placeholders;
67 rviz_common::Display* display)
68 : animating_path_(false)
69 , drop_displaying_trajectory_(false)
73 , trajectory_slider_panel_(nullptr)
74 , trajectory_slider_dock_panel_(nullptr)
75 , logger_(
moveit::getLogger(
"moveit.ros.trajectory_visualization"))
78 "Trajectory Topic",
"/display_planned_path",
79 rosidl_generator_traits::data_type<moveit_msgs::msg::DisplayTrajectory>(),
80 "The topic on which the moveit_msgs::msg::DisplayTrajectory messages are received", widget,
81 SLOT(changedTrajectoryTopic()),
this);
84 new rviz_common::properties::BoolProperty(
"Show Robot Visual",
true,
85 "Indicates whether the geometry of the robot as defined for "
86 "visualisation purposes should be displayed",
87 widget, SLOT(changedDisplayPathVisualEnabled()),
this);
90 new rviz_common::properties::BoolProperty(
"Show Robot Collision",
false,
91 "Indicates whether the geometry of the robot as defined "
92 "for collision detection purposes should be displayed",
93 widget, SLOT(changedDisplayPathCollisionEnabled()),
this);
96 "Robot Alpha", 0.5f,
"Specifies the alpha for the robot links", widget, SLOT(changedRobotPathAlpha()),
this);
101 new rviz_common::properties::EditableEnumProperty(
"State Display Time",
"3x",
102 "Replay speed of trajectory. Either as factor of its time"
103 "parameterization or as constant time (s) per waypoint.",
104 widget, SLOT(changedStateDisplayTime()),
this);
113 "Use Sim Time",
false,
"Indicates whether simulation time or wall-time is used for state display timing.", widget,
117 "Indicates whether the last received path "
118 "is to be animated in a loop",
119 widget, SLOT(changedLoopDisplay()),
this);
121 trail_display_property_ =
new rviz_common::properties::BoolProperty(
"Show Trail",
false,
"Show a path trail", widget,
122 SLOT(changedShowTrail()),
this);
125 "Specifies the step size of the samples "
126 "shown in the trajectory trail.",
127 widget, SLOT(changedTrailStepSize()),
this);
131 "Interrupt Display",
false,
132 "Immediately show newly planned trajectory, interrupting the currently displayed one.", widget);
135 "Robot Color", QColor(150, 50, 150),
"The color of the animated robot", widget, SLOT(changedRobotColor()),
this);
138 "Color Enabled",
false,
"Specifies whether robot coloring is enabled", widget, SLOT(enabledRobotColor()),
this);
153 rviz_common::DisplayContext* context)
160 auto ros_node_abstraction =
context_->getRosNodeAbstraction().lock();
161 if (!ros_node_abstraction)
163 RVIZ_COMMON_LOG_WARNING(
"Unable to lock weak_ptr from DisplayContext in TrajectoryVisualization constructor");
174 rviz_common::WindowManagerInterface* window_context =
context_->getWindowManager();
182 SLOT(trajectorySliderPanelVisibilityChange(
bool)));
204 RCLCPP_ERROR_STREAM(
logger_,
"No robot model found");
218 changedTrajectoryTopic();
238void TrajectoryVisualization::changedLoopDisplay()
245void TrajectoryVisualization::changedShowTrail()
260 static_cast<int>(std::ceil((t->getWayPointCount() + stepsize - 1) /
static_cast<float>(stepsize))));
263 int waypoint_i = std::min(i * stepsize, t->getWayPointCount() - 1);
265 std::make_unique<RobotStateVisualization>(
scene_node_,
context_,
"Trail Robot " + std::to_string(i),
nullptr);
278void TrajectoryVisualization::changedTrailStepSize()
284void TrajectoryVisualization::changedRobotPathAlpha()
291void TrajectoryVisualization::changedTrajectoryTopic()
298 [
this](
const moveit_msgs::msg::DisplayTrajectory::ConstSharedPtr& msg) {
304void TrajectoryVisualization::changedDisplayPathVisualEnabled()
315void TrajectoryVisualization::changedStateDisplayTime()
319void TrajectoryVisualization::changedDisplayPathCollisionEnabled()
332 changedRobotPathAlpha();
344 changedTrajectoryTopic();
351 r->setVisible(
false);
369 constexpr char default_time_string[] =
"3x";
370 constexpr double default_time_value = -3.0;
377 if (tm.back() ==
'x')
381 else if (tm.back() ==
's')
388 return default_time_value;
391 tm.resize(tm.size() - 1);
392 boost::trim_right(tm);
397 value = std::stof(tm);
399 catch (
const std::invalid_argument& ex)
402 return default_time_value;
408 return default_time_value;
496 const double rt_factor = -tm;
553 RCLCPP_ERROR_STREAM(
logger_,
"No robot state or robot model loaded");
557 if (!msg->model_id.empty() && msg->model_id !=
robot_model_->getName())
559 RCLCPP_WARN(
logger_,
"Received a trajectory to display for model '%s' but model '%s' was expected",
560 msg->model_id.c_str(),
robot_model_->getName().c_str());
565 auto t = std::make_shared<robot_trajectory::RobotTrajectory>(
robot_model_,
"");
568 for (std::size_t i = 0; i < msg->trajectory.size(); ++i)
572 t->setRobotTrajectoryMsg(*
robot_state_, msg->trajectory_start, msg->trajectory[i]);
581 display_->setStatus(rviz_common::properties::StatusProperty::Ok,
"Trajectory",
"");
585 display_->setStatus(rviz_common::properties::StatusProperty::Error,
"Trajectory", e.what());
598void TrajectoryVisualization::changedRobotColor()
604void TrajectoryVisualization::enabledRobotColor()
618 for (
auto& link : robot->getLinks())
619 link.second->unsetColor();
640 for (
auto& link : robot->getLinks())
641 robot->getLink(link.first)->setColor(color.redF(), color.greenF(), color.blueF());
644void TrajectoryVisualization::trajectorySliderPanelVisibilityChange(
bool enable)
This may be thrown if unrecoverable errors occur.
void onInitialize() override
void setSliderPosition(int position)
int getSliderPosition() const
void pauseButton(bool check)
void update(int way_point_count)
rviz_common::properties::BoolProperty * enable_robot_color_property_
void clearTrajectoryTrail()
void incomingDisplayTrajectory(const moveit_msgs::msg::DisplayTrajectory::ConstSharedPtr &msg)
ROS callback for an incoming path message.
Ogre::SceneNode * scene_node_
rviz_common::DisplayContext * context_
rviz_common::properties::BoolProperty * display_path_visual_enabled_property_
void setName(const QString &name)
rviz_common::properties::BoolProperty * interrupt_display_property_
robot_trajectory::RobotTrajectoryPtr trajectory_message_to_display_
robot_trajectory::RobotTrajectoryPtr displaying_trajectory_message_
std::mutex update_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(double wall_dt, double sim_dt)
TrajectoryPanel * trajectory_slider_panel_
rviz_common::properties::BoolProperty * display_path_collision_enabled_property_
moveit::core::RobotStatePtr robot_state_
rviz_common::properties::RosTopicProperty * trajectory_topic_property_
moveit::core::RobotModelConstPtr robot_model_
rviz_common::properties::BoolProperty * use_sim_time_property_
TrajectoryVisualization(rviz_common::properties::Property *widget, rviz_common::Display *display)
Playback a trajectory from a planned path.
std_msgs::msg::ColorRGBA default_attached_object_color_
rviz_common::properties::Property * widget_
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)
double current_state_time_
rclcpp::Node::SharedPtr node_
rviz_common::properties::EditableEnumProperty * state_display_time_property_
void setDefaultAttachedObjectColor(const QColor &color)
rviz_common::properties::IntProperty * trail_step_size_property_
void interruptCurrentDisplay()
rviz_common::Display * display_
std::vector< RobotStateVisualizationUniquePtr > trajectory_trail_
void unsetRobotColor(rviz_default_plugins::robot::Robot *robot)
~TrajectoryVisualization() override
void onRobotModelLoaded(const moveit::core::RobotModelConstPtr &robot_model)
RobotStateVisualizationPtr display_path_robot_
rviz_common::properties::FloatProperty * robot_path_alpha_property_
bool drop_displaying_trajectory_
rclcpp::Subscription< moveit_msgs::msg::DisplayTrajectory >::SharedPtr trajectory_topic_sub_
double getStateDisplayTime()
get time to show each single robot state
Maintain a sequence of waypoints and the time durations between these waypoints.
RobotTrajectory & setRobotTrajectoryMsg(const moveit::core::RobotState &reference_state, const trajectory_msgs::msg::JointTrajectory &trajectory)
Copy the content of the trajectory message into this class. The trajectory message itself is not requ...
RobotTrajectory & append(const RobotTrajectory &source, double dt, size_t start_index=0, size_t end_index=std::numeric_limits< std::size_t >::max())
Add a specified part of a trajectory to the end of the current trajectory. The default (when start_in...
Main namespace for MoveIt.