moveit_visual_tools.h
Go to the documentation of this file.
00001 /*********************************************************************
00002  * Software License Agreement (BSD License)
00003  *
00004  *  Copyright (c) 2015, University of Colorado, Boulder
00005  *  All rights reserved.
00006  *
00007  *  Redistribution and use in source and binary forms, with or without
00008  *  modification, are permitted provided that the following conditions
00009  *  are met:
00010  *
00011  *   * Redistributions of source code must retain the above copyright
00012  *     notice, this list of conditions and the following disclaimer.
00013  *   * Redistributions in binary form must reproduce the above
00014  *     copyright notice, this list of conditions and the following
00015  *     disclaimer in the documentation and/or other materials provided
00016  *     with the distribution.
00017  *   * Neither the name of the Univ of CO, Boulder nor the names of its
00018  *     contributors may be used to endorse or promote products derived
00019  *     from this software without specific prior written permission.
00020  *
00021  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00024  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00025  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00026  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00027  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00028  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00031  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032  *  POSSIBILITY OF SUCH DAMAGE.
00033  *********************************************************************/
00034 
00035 /* \author  Dave Coleman
00036  * \desc    Helper functions for displaying and debugging MoveIt! data in Rviz via published markers
00037  *          and MoveIt! collision objects. Very useful for debugging complex software
00038  */
00039 
00040 #ifndef MOVEIT_VISUAL_TOOLS_MOVEIT_VISUAL_TOOLS_H
00041 #define MOVEIT_VISUAL_TOOLS_MOVEIT_VISUAL_TOOLS_H
00042 
00043 // Rviz Visualization Tool
00044 #include <rviz_visual_tools/rviz_visual_tools.h>
00045 
00046 // MoveIt
00047 #include <moveit/planning_scene_monitor/planning_scene_monitor.h>
00048 // #include <moveit/macros/deprecation.h>
00049 #include <rviz_visual_tools/deprecation.h>
00050 
00051 // MoveIt Messages
00052 #include <moveit_msgs/Grasp.h>
00053 #include <moveit_msgs/DisplayRobotState.h>
00054 #include <moveit_msgs/WorkspaceParameters.h>
00055 
00056 // ROS Messages
00057 #include <trajectory_msgs/JointTrajectory.h>
00058 
00059 // C++
00060 #include <map>
00061 #include <string>
00062 #include <vector>
00063 
00064 namespace moveit_visual_tools
00065 {
00066 // Default constants
00067 static const std::string ROBOT_DESCRIPTION = "robot_description";  // this is the default used in ROS
00068 static const std::string DISPLAY_PLANNED_PATH_TOPIC =
00069     "/move_group/display_planned_path";  // this is the default when adding the Rviz plugin
00070 static const std::string DISPLAY_ROBOT_STATE_TOPIC =
00071     "display_robot_state";                                         // this is the default when adding the Rviz plugin
00072 static const std::string PLANNING_SCENE_TOPIC = "planning_scene";  // this is the default when adding the Rviz plugin
00073 
00074 class MoveItVisualTools : public rviz_visual_tools::RvizVisualTools
00075 {
00076 public:
00084   MoveItVisualTools(const std::string &base_frame, const std::string &marker_topic,
00085                     planning_scene_monitor::PlanningSceneMonitorPtr planning_scene_monitor);
00086 
00093   MoveItVisualTools(const std::string &base_frame,
00094                     const std::string &marker_topic = rviz_visual_tools::RVIZ_MARKER_TOPIC,
00095                     robot_model::RobotModelConstPtr robot_model = robot_model::RobotModelConstPtr());
00096 
00101   void setRobotStateTopic(const std::string &robot_state_topic)
00102   {
00103     robot_state_topic_ = robot_state_topic;
00104   }
00105 
00110   void setPlanningSceneTopic(const std::string &planning_scene_topic)
00111   {
00112     planning_scene_topic_ = planning_scene_topic;
00113   }
00114 
00119   bool loadPlanningSceneMonitor();
00120 
00127   bool processCollisionObjectMsg(const moveit_msgs::CollisionObject &msg,
00128                                  const rviz_visual_tools::colors &color = rviz_visual_tools::GREEN);
00129 
00135   bool processAttachedCollisionObjectMsg(const moveit_msgs::AttachedCollisionObject &msg);
00136 
00141   bool triggerPlanningSceneUpdate();
00142 
00147   bool loadSharedRobotState();
00148 
00153   moveit::core::RobotStatePtr &getSharedRobotState();
00154 
00159   moveit::core::RobotStatePtr &getRootRobotState()
00160   {
00161     return root_robot_state_;
00162   }
00163 
00168   moveit::core::RobotModelConstPtr getRobotModel();
00169 
00175   RVIZ_VISUAL_TOOLS_DEPRECATED
00176   bool loadEEMarker(const std::string &ee_group_name)
00177   {
00178     return loadEEMarker(robot_model_->getJointModelGroup(ee_group_name));
00179   }
00185   bool loadEEMarker(const robot_model::JointModelGroup *ee_jmg);
00186 
00190   void loadTrajectoryPub(const std::string &display_planned_path_topic = DISPLAY_PLANNED_PATH_TOPIC, bool blocking = true);
00191   void loadRobotStatePub(const std::string &robot_state_topic = "", bool blocking = true);
00192 
00197   void setPlanningSceneMonitor(planning_scene_monitor::PlanningSceneMonitorPtr planning_scene_monitor)
00198   {
00199     planning_scene_monitor_ = planning_scene_monitor;
00200   }
00201 
00206   void setManualSceneUpdating(bool enable_manual = true)
00207   {
00208     mannual_trigger_update_ = enable_manual;
00209   }
00210 
00218   bool publishEEMarkers(const Eigen::Affine3d &pose, const robot_model::JointModelGroup *ee_jmg,
00219                         const rviz_visual_tools::colors &color = rviz_visual_tools::CLEAR,
00220                         const std::string &ns = "end_effector")
00221   {
00222     return publishEEMarkers(convertPose(pose), ee_jmg, color, ns);
00223   }
00224   bool publishEEMarkers(const geometry_msgs::Pose &pose, const robot_model::JointModelGroup *ee_jmg,
00225                         const rviz_visual_tools::colors &color = rviz_visual_tools::CLEAR,
00226                         const std::string &ns = "end_effector");
00227 
00234   bool publishGrasps(const std::vector<moveit_msgs::Grasp> &possible_grasps, const robot_model::JointModelGroup *ee_jmg,
00235                      double animate_speed = 0.1);
00236 
00243   bool publishAnimatedGrasps(const std::vector<moveit_msgs::Grasp> &possible_grasps,
00244                              const robot_model::JointModelGroup *ee_jmg, double animate_speed = 0.01);
00245 
00253   bool publishAnimatedGrasp(const moveit_msgs::Grasp &grasp, const robot_model::JointModelGroup *ee_jmg,
00254                             double animate_speed);
00255 
00263   bool publishIKSolutions(const std::vector<trajectory_msgs::JointTrajectoryPoint> &ik_solutions,
00264                           const robot_model::JointModelGroup *arm_jmg, double display_time = 0.4);
00265 
00272   bool removeAllCollisionObjects();
00273 
00279   bool cleanupCO(const std::string &name);
00280 
00286   bool cleanupACO(const std::string &name);
00287 
00294   bool attachCO(const std::string &name, const std::string &ee_parent_link);
00295 
00303   bool publishCollisionFloor(double z = 0.0, const std::string &plane_name = "Floor",
00304                              const rviz_visual_tools::colors &color = rviz_visual_tools::GREEN);
00305 
00314   bool publishCollisionBlock(const geometry_msgs::Pose &block_pose, const std::string &block_name, double block_size,
00315                              const rviz_visual_tools::colors &color = rviz_visual_tools::GREEN);
00316 
00325   RVIZ_VISUAL_TOOLS_DEPRECATED
00326   bool publishCollisionRectangle(const Eigen::Vector3d &point1, const Eigen::Vector3d &point2, const std::string &name,
00327                                  const rviz_visual_tools::colors &color)
00328   {
00329     return publishCollisionCuboid(convertPoint(point1), convertPoint(point2), name, color);
00330   }
00331   RVIZ_VISUAL_TOOLS_DEPRECATED
00332   bool publishCollisionRectangle(const geometry_msgs::Point &point1, const geometry_msgs::Point &point2,
00333                                  const std::string &name, const rviz_visual_tools::colors &color)
00334   {
00335     return publishCollisionCuboid(convertPoint(point1), convertPoint(point2), name, color);
00336   }
00337   bool publishCollisionCuboid(const Eigen::Vector3d &point1, const Eigen::Vector3d &point2, const std::string &name,
00338                               const rviz_visual_tools::colors &color = rviz_visual_tools::GREEN);
00339   bool publishCollisionCuboid(const geometry_msgs::Point &point1, const geometry_msgs::Point &point2,
00340                               const std::string &name,
00341                               const rviz_visual_tools::colors &color = rviz_visual_tools::GREEN);
00342 
00352   bool publishCollisionCylinder(const geometry_msgs::Point &a, const geometry_msgs::Point &b,
00353                                 const std::string &object_name, double radius,
00354                                 const rviz_visual_tools::colors &color = rviz_visual_tools::GREEN);
00355   bool publishCollisionCylinder(const Eigen::Vector3d &a, const Eigen::Vector3d &b, const std::string &object_name,
00356                                 double radius, const rviz_visual_tools::colors &color = rviz_visual_tools::GREEN);
00357 
00367   bool publishCollisionCylinder(const Eigen::Affine3d &object_pose, const std::string &object_name, double radius,
00368                                 double height, const rviz_visual_tools::colors &color = rviz_visual_tools::GREEN);
00369   bool publishCollisionCylinder(const geometry_msgs::Pose &object_pose, const std::string &object_name, double radius,
00370                                 double height, const rviz_visual_tools::colors &color = rviz_visual_tools::GREEN);
00371 
00380   bool publishCollisionMesh(const geometry_msgs::Pose &object_pose, const std::string &object_name,
00381                             const std::string &mesh_path,
00382                             const rviz_visual_tools::colors &color = rviz_visual_tools::GREEN);
00383   bool publishCollisionMesh(const Eigen::Affine3d &object_pose, const std::string &object_name,
00384                             const std::string &mesh_path,
00385                             const rviz_visual_tools::colors &color = rviz_visual_tools::GREEN);
00386   bool publishCollisionMesh(const Eigen::Affine3d &object_pose, const std::string &object_name,
00387                             const shape_msgs::Mesh &mesh_msg,
00388                             const rviz_visual_tools::colors &color = rviz_visual_tools::GREEN);
00389   bool publishCollisionMesh(const geometry_msgs::Pose &object_pose, const std::string &object_name,
00390                             const shape_msgs::Mesh &mesh_msg,
00391                             const rviz_visual_tools::colors &color = rviz_visual_tools::GREEN);
00392 
00400   bool publishCollisionGraph(const graph_msgs::GeometryGraph &graph, const std::string &object_name, double radius,
00401                              const rviz_visual_tools::colors &color = rviz_visual_tools::GREEN);
00402 
00406   void getCollisionWallMsg(double x, double y, double angle, double width, double height, const std::string name,
00407                            moveit_msgs::CollisionObject &collision_obj);
00408 
00420   RVIZ_VISUAL_TOOLS_DEPRECATED
00421   bool publishCollisionWall(double x, double y, double angle, double width, const std::string name,
00422                             const rviz_visual_tools::colors &color = rviz_visual_tools::GREEN);
00423 
00424   bool publishCollisionWall(double x, double y, double angle = 0.0, double width = 2.0, double height = 1.5,
00425                             const std::string name = "wall",
00426                             const rviz_visual_tools::colors &color = rviz_visual_tools::GREEN);
00427 
00440   bool publishCollisionTable(double x, double y, double angle, double width, double height, double depth,
00441                              const std::string name, const rviz_visual_tools::colors &color = rviz_visual_tools::GREEN);
00442 
00449   bool loadCollisionSceneFromFile(const std::string &path);
00450   bool loadCollisionSceneFromFile(const std::string &path, const Eigen::Affine3d &offset);
00451 
00456   RVIZ_VISUAL_TOOLS_DEPRECATED
00457   bool publishCollisionTests();
00458 
00464   bool publishWorkspaceParameters(const moveit_msgs::WorkspaceParameters &params);
00465 
00473   bool publishContactPoints(const moveit::core::RobotState &robot_state,
00474                             const planning_scene::PlanningScene *planning_scene,
00475                             const rviz_visual_tools::colors &color = rviz_visual_tools::RED);
00476 
00488   bool publishTrajectoryPoint(const trajectory_msgs::JointTrajectoryPoint &trajectory_pt,
00489                               const std::string &planning_group, double display_time = 0.1);
00490 
00499   bool publishTrajectoryPath(const std::vector<moveit::core::RobotStatePtr> &trajectory,
00500                              const moveit::core::JointModelGroup *jmg, double speed = 0.01, bool blocking = false);
00501   bool publishTrajectoryPath(const robot_trajectory::RobotTrajectoryPtr &trajectory, bool blocking = false);
00502   bool publishTrajectoryPath(const robot_trajectory::RobotTrajectory &trajectory, bool blocking = false);
00503   bool publishTrajectoryPath(const moveit_msgs::RobotTrajectory &trajectory_msg,
00504                              const moveit::core::RobotStateConstPtr robot_state, bool blocking = false);
00505 
00517   RVIZ_VISUAL_TOOLS_DEPRECATED
00518   bool publishTrajectoryLine(const moveit_msgs::RobotTrajectory &trajectory_msg,
00519                              const moveit::core::LinkModel *ee_parent_link, const robot_model::JointModelGroup *arm_jmg,
00520                              const rviz_visual_tools::colors &color, bool clear_all_markers)
00521   {
00522     // Group together messages
00523     enableInternalBatchPublishing(true);
00524 
00525     if (clear_all_markers)
00526       publishMarker(reset_marker_);
00527 
00528     return publishTrajectoryLine(trajectory_msg, ee_parent_link, arm_jmg, color);
00529   }
00530 
00531   RVIZ_VISUAL_TOOLS_DEPRECATED
00532   bool publishTrajectoryLine(const robot_trajectory::RobotTrajectoryPtr robot_trajectory,
00533                              const moveit::core::LinkModel *ee_parent_link, const rviz_visual_tools::colors &color,
00534                              bool clear_all_markers)
00535   {
00536     // Group together messages
00537     enableInternalBatchPublishing(true);
00538 
00539     if (clear_all_markers)
00540       publishMarker(reset_marker_);
00541 
00542     return publishTrajectoryLine(robot_trajectory, ee_parent_link, color);
00543   }
00544 
00545   RVIZ_VISUAL_TOOLS_DEPRECATED
00546   bool publishTrajectoryLine(const robot_trajectory::RobotTrajectory &robot_trajectory,
00547                              const moveit::core::LinkModel *ee_parent_link, const rviz_visual_tools::colors &color,
00548                              bool clear_all_markers)
00549   {
00550     // Group together messages
00551     enableInternalBatchPublishing(true);
00552 
00553     if (clear_all_markers)
00554       publishMarker(reset_marker_);
00555 
00556     return publishTrajectoryLine(robot_trajectory, ee_parent_link, color);
00557   }
00558 
00567   bool publishTrajectoryLine(const moveit_msgs::RobotTrajectory &trajectory_msg,
00568                              const moveit::core::LinkModel *ee_parent_link, const robot_model::JointModelGroup *arm_jmg,
00569                              const rviz_visual_tools::colors &color);
00570   bool publishTrajectoryLine(const robot_trajectory::RobotTrajectoryPtr robot_trajectory,
00571                              const moveit::core::LinkModel *ee_parent_link, const rviz_visual_tools::colors &color);
00572   bool publishTrajectoryLine(const robot_trajectory::RobotTrajectory &robot_trajectory,
00573                              const moveit::core::LinkModel *ee_parent_link, const rviz_visual_tools::colors &color);
00574 
00581   bool publishTrajectoryPoints(const std::vector<moveit::core::RobotStatePtr> &robot_state_trajectory,
00582                                const moveit::core::LinkModel *ee_parent_link,
00583                                const rviz_visual_tools::colors &color = rviz_visual_tools::YELLOW);
00584 
00586   void enableRobotStateRootOffet(const Eigen::Affine3d &offset);
00587 
00589   void disableRobotStateRootOffet();
00590 
00598   bool publishRobotState(const trajectory_msgs::JointTrajectoryPoint &trajectory_pt,
00599                          const robot_model::JointModelGroup *jmg,
00600                          const rviz_visual_tools::colors &color = rviz_visual_tools::DEFAULT);
00601 
00608   bool publishRobotState(const moveit::core::RobotState &robot_state,
00609                          const rviz_visual_tools::colors &color = rviz_visual_tools::DEFAULT);
00610   bool publishRobotState(const moveit::core::RobotStatePtr &robot_state,
00611                          const rviz_visual_tools::colors &color = rviz_visual_tools::DEFAULT);
00612 
00617   bool hideRobot();
00618 
00620   bool applyVirtualJointTransform(moveit::core::RobotState &robot_state, const Eigen::Affine3d &offset);
00621 
00626   void showJointLimits(moveit::core::RobotStatePtr robot_state);
00627 
00628 private:
00633   planning_scene_monitor::PlanningSceneMonitorPtr getPlanningSceneMonitor();
00634 
00639   bool checkForVirtualJoint(const moveit::core::RobotState &robot_state);
00640 
00641 protected:
00642   // ROS publishers
00643   ros::Publisher pub_display_path_;  // for MoveIt trajectories
00644   ros::Publisher pub_robot_state_;   // publish a RobotState message
00645 
00646   // Pointer to a Planning Scene Monitor
00647   planning_scene_monitor::PlanningSceneMonitorPtr planning_scene_monitor_;
00648   robot_model_loader::RobotModelLoaderPtr rm_loader_;  // so that we can specify our own options
00649 
00650   // End Effector Markers
00651   std::map<const robot_model::JointModelGroup *, visualization_msgs::MarkerArray> ee_markers_map_;
00652   std::map<const robot_model::JointModelGroup *, EigenSTL::vector_Affine3d> ee_poses_map_;
00653 
00654   // Cached robot state marker - cache the colored links.
00655   // Note: Only allows colors provided in rviz_visual_tools to prevent too many robot state messages from being loaded
00656   // and ensuring efficiency
00657   std::map<rviz_visual_tools::colors, moveit_msgs::DisplayRobotState> display_robot_msgs_;
00658 
00659   // Pointer to the robot model
00660   moveit::core::RobotModelConstPtr robot_model_;
00661 
00662   // Note: call loadSharedRobotState() before using this
00663   moveit::core::RobotStatePtr shared_robot_state_;
00664 
00665   // Note: call loadSharedRobotState() before using this. Use only for hiding the robot
00666   moveit::core::RobotStatePtr hidden_robot_state_;
00667 
00668   // A robot state whose virtual_joint remains at identity so that getGlobalLinkTransform() isn't tainted
00669   // Note: call loadSharedRobotState() before using this
00670   moveit::core::RobotStatePtr root_robot_state_;
00671 
00672   // Optional offset that can be applied to all outgoing/published robot states
00673   bool robot_state_root_offset_enabled_;
00674   Eigen::Affine3d robot_state_root_offset_;
00675 
00676   // Prevent the planning scene from always auto-pushing, but rather do it manually
00677   bool mannual_trigger_update_;
00678 
00679   // ROS topic names to use when starting publishers
00680   std::string robot_state_topic_;
00681   std::string planning_scene_topic_;
00682 };  // class
00683 
00684 typedef boost::shared_ptr<MoveItVisualTools> MoveItVisualToolsPtr;
00685 typedef boost::shared_ptr<const MoveItVisualTools> MoveItVisualToolsConstPtr;
00686 
00687 }  // namespace moveit_visual_tools
00688 
00689 #endif  // MOVEIT_VISUAL_TOOLS_MOVEIT_VISUAL_TOOLS_H


moveit_visual_tools
Author(s): Dave Coleman
autogenerated on Fri Jun 17 2016 04:11:05