41 #include <rclcpp/qos.hpp> 
   44 #include <rviz_default_plugins/robot/robot.hpp> 
   45 #include <rviz_default_plugins/robot/robot_link.hpp> 
   47 #include <rviz_common/properties/property.hpp> 
   48 #include <rviz_common/properties/string_property.hpp> 
   49 #include <rviz_common/properties/bool_property.hpp> 
   50 #include <rviz_common/properties/float_property.hpp> 
   51 #include <rviz_common/properties/ros_topic_property.hpp> 
   52 #include <rviz_common/properties/color_property.hpp> 
   53 #include <rviz_common/display_context.hpp> 
   54 #include <rviz_common/frame_manager_iface.hpp> 
   56 #include <OgreSceneManager.h> 
   57 #include <OgreSceneNode.h> 
   69       "Robot Description", 
"robot_description", 
"The name of the ROS parameter where the URDF for the robot is loaded",
 
   70       this, SLOT(changedRobotDescription()), 
this);
 
   73       "Robot State Topic", 
"display_robot_state",
 
   74       rosidl_generator_traits::data_type<moveit_msgs::msg::DisplayRobotState>(),
 
   75       "The topic on which the moveit_msgs::msg::DisplayRobotState messages are received", 
this,
 
   76       SLOT(changedRobotStateTopic()), 
this);
 
   80       new rviz_common::properties::StringProperty(
"Robot Root Link", 
"",
 
   81                                                   "Shows the name of the root link for the robot model", 
this,
 
   82                                                   SLOT(changedRootLinkName()), 
this);
 
   86       "Robot Alpha", 1.0f, 
"Specifies the alpha for the robot links", 
this, SLOT(changedRobotSceneAlpha()), 
this);
 
   91       new rviz_common::properties::ColorProperty(
"Attached Body Color", QColor(150, 50, 150),
 
   92                                                  "The color for the attached bodies", 
this,
 
   93                                                  SLOT(changedAttachedBodyColor()), 
this);
 
   96                                                                      "Specifies whether link highlighting is enabled",
 
   97                                                                      this, SLOT(changedEnableLinkHighlight()), 
this);
 
   99       new rviz_common::properties::BoolProperty(
"Visual Enabled", 
true,
 
  100                                                 "Whether to display the visual representation of the robot.", 
this,
 
  101                                                 SLOT(changedEnableVisualVisible()), 
this);
 
  103       new rviz_common::properties::BoolProperty(
"Collision Enabled", 
false,
 
  104                                                 "Whether to display the collision representation of the robot.", 
this,
 
  105                                                 SLOT(changedEnableCollisionVisible()), 
this);
 
  108       "Show All Links", 
true, 
"Toggle all links visibility on or off.", 
this, SLOT(changedAllLinks()), 
this);
 
  118   Display::onInitialize();
 
  119   auto ros_node_abstraction = context_->getRosNodeAbstraction().lock();
 
  120   if (!ros_node_abstraction)
 
  122     RVIZ_COMMON_LOG_WARNING(
"Unable to lock weak_ptr from DisplayContext in RobotStateDisplay constructor");
 
  126   node_ = ros_node_abstraction->get_raw_node();
 
  127   robot_ = std::make_shared<RobotStateVisualization>(scene_node_, context_, 
"Robot State", 
this);
 
  128   changedEnableVisualVisible();
 
  129   changedEnableCollisionVisible();
 
  130   robot_->setVisible(
false);
 
  142 void RobotStateDisplay::changedAllLinks()
 
  144   Property* links_prop = subProp(
"Links");
 
  147   for (
int i = 0; i < links_prop->numChildren(); ++i)
 
  149     Property* link_prop = links_prop->childAt(i);
 
  150     link_prop->setValue(value);
 
  156   rviz_default_plugins::robot::RobotLink* link = 
robot_->getRobot().getLink(link_name);
 
  159     link->setColor(color.r, color.g, color.b);
 
  166   rviz_default_plugins::robot::RobotLink* link = 
robot_->getRobot().getLink(link_name);
 
  174 void RobotStateDisplay::changedEnableLinkHighlight()
 
  178     for (std::pair<const std::string, std_msgs::msg::ColorRGBA>& highlight : 
highlights_)
 
  185     for (std::pair<const std::string, std_msgs::msg::ColorRGBA>& highlight : 
highlights_)
 
  192 void RobotStateDisplay::changedEnableVisualVisible()
 
  197 void RobotStateDisplay::changedEnableCollisionVisible()
 
  203     const moveit_msgs::msg::DisplayRobotState::_highlight_links_type& highlight_links)
 
  205   if (highlight_links.empty() && 
highlights_.empty())
 
  208   std::map<std::string, std_msgs::msg::ColorRGBA> highlights;
 
  209   for (
const moveit_msgs::msg::ObjectColor& highlight_link : highlight_links)
 
  211     highlights[highlight_link.id] = highlight_link.color;
 
  216     std::map<std::string, std_msgs::msg::ColorRGBA>::iterator ho = 
highlights_.begin();
 
  217     std::map<std::string, std_msgs::msg::ColorRGBA>::iterator hn = highlights.begin();
 
  218     while (ho != 
highlights_.end() || hn != highlights.end())
 
  225       else if (hn == highlights.end())
 
  230       else if (hn->first < ho->first)
 
  235       else if (hn->first > ho->first)
 
  240       else if (hn->second != ho->second)
 
  257 void RobotStateDisplay::changedAttachedBodyColor()
 
  262     std_msgs::msg::ColorRGBA color_msg;
 
  263     color_msg.r = color.redF();
 
  264     color_msg.g = color.greenF();
 
  265     color_msg.b = color.blueF();
 
  267     robot_->setDefaultAttachedObjectColor(color_msg);
 
  272 void RobotStateDisplay::changedRobotDescription()
 
  278 void RobotStateDisplay::changedRootLinkName()
 
  282 void RobotStateDisplay::changedRobotSceneAlpha()
 
  288     std_msgs::msg::ColorRGBA color_msg;
 
  289     color_msg.r = color.redF();
 
  290     color_msg.g = color.greenF();
 
  291     color_msg.b = color.blueF();
 
  293     robot_->setDefaultAttachedObjectColor(color_msg);
 
  298 void RobotStateDisplay::changedRobotStateTopic()
 
  300   using namespace std::placeholders;
 
  305   robot_->setVisible(
false);
 
  306   setStatus(rviz_common::properties::StatusProperty::Warn, 
"RobotState", 
"No msg received");
 
  310       [
this](
const moveit_msgs::msg::DisplayRobotState::ConstSharedPtr& state) { 
return newRobotStateCallback(state); });
 
  330     setStatus(rviz_common::properties::StatusProperty::Error, 
"RobotState", e.what());
 
  331     robot_->setVisible(
false);
 
  335   if (
robot_->isVisible() != !state_msg->hide)
 
  337     robot_->setVisible(!state_msg->hide);
 
  339       setStatus(rviz_common::properties::StatusProperty::Ok, 
"RobotState", 
"");
 
  341       setStatus(rviz_common::properties::StatusProperty::Warn, 
"RobotState", 
"Hidden");
 
  359   robot_->setVisible(visible);
 
  365   rviz_default_plugins::robot::RobotLink* link = 
robot->getLink(link_name);
 
  369     link->setColor(color.redF(), color.greenF(), color.blueF());
 
  374   rviz_default_plugins::robot::RobotLink* link = 
robot->getLink(link_name);
 
  388     setStatus(rviz_common::properties::StatusProperty::Error, 
"RobotModel", 
"`Robot Description` field can't be empty");
 
  403       const srdf::ModelSharedPtr& srdf =
 
  413       setStatus(rviz_common::properties::StatusProperty::Ok, 
"RobotModel", 
"Loaded successfully");
 
  415       changedEnableVisualVisible();
 
  416       changedEnableCollisionVisible();
 
  418     catch (std::exception& e)
 
  420       setStatus(rviz_common::properties::StatusProperty::Error, 
"RobotModel",
 
  421                 QString(
"Loading failed: %1").arg(e.what()));
 
  425     setStatus(rviz_common::properties::StatusProperty::Error, 
"RobotModel", 
"Loading failed");
 
  435   Display::load(config);
 
  443   changedRobotStateTopic();
 
  454     robot_->setVisible(
false);
 
  455   Display::onDisable();
 
  460   Display::update(wall_dt, ros_dt);
 
  478   Ogre::Vector3 position;
 
  479   Ogre::Quaternion orientation;
 
  481   context_->getFrameManager()->getTransform(
getRobotModel()->getModelFrame(), rclcpp::Time(0, 0, RCL_ROS_TIME),
 
  482                                             position, orientation);
 
  484   scene_node_->setPosition(position);
 
  485   scene_node_->setOrientation(orientation);
 
  490   Display::fixedFrameChanged();
 
This may be thrown if unrecoverable errors occur.
 
rviz_common::properties::RosTopicProperty * robot_state_topic_property_
 
RobotStateVisualizationPtr robot_
 
void load(const rviz_common::Config &config) override
 
moveit::core::RobotModelConstPtr robot_model_
 
void setHighlight(const std::string &link_name, const std_msgs::msg::ColorRGBA &color)
 
~RobotStateDisplay() override
 
void update(float wall_dt, float ros_dt) override
 
void setRobotHighlights(const moveit_msgs::msg::DisplayRobotState::_highlight_links_type &highlight_links)
 
rviz_common::properties::FloatProperty * robot_alpha_property_
 
rviz_common::properties::ColorProperty * attached_body_color_property_
 
rviz_common::properties::StringProperty * root_link_name_property_
 
rclcpp::Subscription< moveit_msgs::msg::DisplayRobotState >::SharedPtr robot_state_subscriber_
 
void unsetHighlight(const std::string &link_name)
 
rclcpp::Node::SharedPtr node_
 
rviz_common::properties::BoolProperty * enable_visual_visible_
 
void fixedFrameChanged() override
 
void calculateOffsetPosition()
Set the scene node's position, given the target frame and the planning frame.
 
void setVisible(bool visible)
 
void onInitialize() override
 
void unsetLinkColor(const std::string &link_name)
 
void newRobotStateCallback(const moveit_msgs::msg::DisplayRobotState::ConstSharedPtr &state)
 
rviz_common::properties::BoolProperty * enable_link_highlight_
 
rviz_common::properties::BoolProperty * enable_collision_visible_
 
rviz_common::properties::BoolProperty * show_all_links_
 
rviz_common::properties::StringProperty * robot_description_property_
 
rdf_loader::RDFLoaderPtr rdf_loader_
 
void setLinkColor(const std::string &link_name, const QColor &color)
 
std::map< std::string, std_msgs::msg::ColorRGBA > highlights_
 
moveit::core::RobotStatePtr robot_state_
 
const moveit::core::RobotModelConstPtr & getRobotModel() const
 
void onDisable() override
 
bool isEmpty(const moveit_msgs::msg::PlanningScene &msg)
Check if a message includes any information about a planning scene, or whether it is empty.
 
bool robotStateMsgToRobotState(const Transforms &tf, const moveit_msgs::msg::RobotState &robot_state, RobotState &state, bool copy_attached_bodies=true)
Convert a robot state msg (with accompanying extra transforms) to a MoveIt robot state.