visual_tools.h
Go to the documentation of this file.
00001 /*********************************************************************
00002  * Software License Agreement (BSD License)
00003  *
00004  *  Copyright (c) 2013, 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  *          See README.md for developers notes.
00040  *
00041  */
00042 
00043 #ifndef MOVEIT_VISUAL_TOOLS__VISUAL_TOOLS_H_
00044 #define MOVEIT_VISUAL_TOOLS__VISUAL_TOOLS_H_
00045 
00046 // Rviz
00047 #include <visualization_msgs/Marker.h>
00048 #include <visualization_msgs/MarkerArray.h>
00049 
00050 // MoveIt
00051 #include <moveit/planning_scene_monitor/planning_scene_monitor.h>
00052 #include <moveit_msgs/Grasp.h>
00053 #include <moveit_msgs/DisplayRobotState.h>
00054 #include <moveit/macros/deprecation.h>
00055 
00056 // Boost
00057 #include <boost/shared_ptr.hpp>
00058 
00059 // Messages
00060 #include <std_msgs/ColorRGBA.h>
00061 #include <graph_msgs/GeometryGraph.h>
00062 #include <geometry_msgs/PoseArray.h>
00063 #include <geometry_msgs/Polygon.h>
00064 #include <trajectory_msgs/JointTrajectory.h>
00065 
00066 namespace moveit_visual_tools
00067 {
00068 
00069 // Default constants
00070 static const std::string ROBOT_DESCRIPTION = "robot_description";
00071 static const std::string COLLISION_TOPIC = "/collision_object";
00072 static const std::string ATTACHED_COLLISION_TOPIC = "/attached_collision_object";
00073 static const std::string RVIZ_MARKER_TOPIC = "/end_effector_marker";
00074 static const std::string PLANNING_SCENE_TOPIC = "/move_group/monitored_planning_scene";
00075 static const std::string DISPLAY_PLANNED_PATH_TOPIC = "/move_group/display_planned_path";
00076 static const std::string DISPLAY_ROBOT_STATE_TOPIC = "/move_group/robot_state";
00077 
00078 // Note: when adding new colors to rviz_colors, also add them to getRandColor() function
00079 enum rviz_colors { RED, 
00080                    GREEN, 
00081                    BLUE, 
00082                    GREY, 
00083                    WHITE, 
00084                    ORANGE, 
00085                    BLACK, 
00086                    YELLOW, 
00087                    PURPLE, 
00088                    TRANSLUCENT, 
00089                    TRANSLUCENT2,
00090                    RAND };
00091 
00092 enum rviz_scales { XXSMALL,
00093                    XSMALL,
00094                    SMALL,
00095                    REGULAR,
00096                    LARGE, xLARGE, xxLARGE, xxxLARGE,
00097                    XLARGE,
00098                    XXLARGE };
00099 
00100 class VisualTools
00101 {
00102 protected:
00103 
00104   // A shared node handle
00105   ros::NodeHandle nh_;
00106 
00107   // ROS publishers
00108   ros::Publisher pub_rviz_marker_; // for rviz visualization markers
00109   ros::Publisher pub_collision_obj_; // for MoveIt collision objects
00110   ros::Publisher pub_attach_collision_obj_; // for MoveIt attached objects
00111   ros::Publisher pub_display_path_; // for MoveIt trajectories
00112   ros::Publisher pub_planning_scene_diff_; // for adding and removing collision objects
00113   ros::Publisher pub_robot_state_; // publish a RobotState message
00114 
00115   // Pointer to a Planning Scene Monitor
00116   planning_scene_monitor::PlanningSceneMonitorPtr planning_scene_monitor_;
00117   robot_model_loader::RobotModelLoaderPtr rm_loader_; // so that we can specify our own options
00118 
00119   // Strings
00120   std::string marker_topic_; // topic to publish to rviz
00121   std::string base_frame_; // name of base link of robot
00122 
00123   // TODO rename this
00124   double floor_to_base_height_; // allows an offset between base link and floor where objects are built
00125 
00126   // Duration to have Rviz markers persist, 0 for infinity
00127   ros::Duration marker_lifetime_;
00128 
00129   // End Effector Markers
00130   visualization_msgs::MarkerArray ee_marker_array_;
00131   tf::Pose tf_root_to_link_;
00132   geometry_msgs::Pose grasp_pose_to_eef_pose_; // Convert generic grasp pose to this end effector's frame of reference
00133   std::vector<geometry_msgs::Pose> marker_poses_;
00134 
00135   // Library settings
00136   bool muted_; // Whether to actually publish to rviz or not
00137   double alpha_; // opacity of all markers
00138   double global_scale_; // allow all markers to be increased by a constanct factor
00139 
00140   // Cached Rviz markers
00141   visualization_msgs::Marker arrow_marker_;
00142   visualization_msgs::Marker sphere_marker_;
00143   visualization_msgs::Marker block_marker_;
00144   visualization_msgs::Marker cylinder_marker_;
00145   visualization_msgs::Marker text_marker_;
00146   visualization_msgs::Marker rectangle_marker_;
00147   visualization_msgs::Marker line_marker_;
00148   visualization_msgs::Marker path_marker_;
00149   visualization_msgs::Marker spheres_marker_;
00150   visualization_msgs::Marker reset_marker_;
00151 
00152   // MoveIt cached markers
00153   moveit_msgs::DisplayRobotState display_robot_msg_;
00154 
00155   // MoveIt cached objects
00156   robot_state::RobotStatePtr shared_robot_state_; // Note: call loadSharedRobotState() before using this
00157   robot_state::RobotModelConstPtr robot_model_;
00158 
00159 private:
00163   void initialize();
00164 
00165 public:
00166 
00174   VisualTools(const std::string& base_frame,
00175               const std::string& marker_topic,
00176               planning_scene_monitor::PlanningSceneMonitorPtr planning_scene_monitor);
00177 
00184   VisualTools(const std::string& base_frame,
00185               const std::string& marker_topic = RVIZ_MARKER_TOPIC,
00186               robot_model::RobotModelConstPtr robot_model = robot_model::RobotModelConstPtr());
00187 
00191   ~VisualTools() {};
00192 
00196   void deleteAllMarkers();
00197 
00202   void resetMarkerCounts();
00203 
00208   bool loadRvizMarkers();
00209 
00214   bool loadPlanningSceneMonitor();
00215 
00221   bool processCollisionObjectMsg(moveit_msgs::CollisionObject msg);
00222 
00227   bool loadSharedRobotState();
00228 
00233   bool loadRobotMarkers();
00234 
00241   bool loadEEMarker(const std::string& ee_group_name, const std::string& planning_group);
00242 
00246   void loadMarkerPub();
00247   void loadCollisionPub();
00248   void loadAttachedPub();
00249   void loadPlanningPub();
00250   void loadTrajectoryPub();
00251   void loadRobotStatePub(const std::string &marker_topic = DISPLAY_ROBOT_STATE_TOPIC);
00252 
00256   bool isMuted()
00257   {
00258     return muted_;
00259   }
00260 
00265   void setMuted(bool muted)
00266   {
00267     muted_ = muted;
00268   }
00269 
00274   void setFloorToBaseHeight(double floor_to_base_height);
00275 
00280   void setGraspPoseToEEFPose(geometry_msgs::Pose grasp_pose_to_eef_pose);
00281 
00286   void setAlpha(double alpha)
00287   {
00288     alpha_ = alpha;
00289   }
00290 
00295   void setPlanningSceneMonitor(planning_scene_monitor::PlanningSceneMonitorPtr planning_scene_monitor)
00296   {
00297     planning_scene_monitor_ = planning_scene_monitor;
00298   }
00299 
00304   void setLifetime(double lifetime);
00305 
00310   const rviz_colors getRandColor();
00311 
00317   std_msgs::ColorRGBA getColor(const rviz_colors &color);
00318 
00326   geometry_msgs::Vector3 getScale(const rviz_scales &scale, bool arrow_scale = false, double marker_scale = 1.0);
00327 
00334   Eigen::Affine3d getVectorBetweenPoints(Eigen::Vector3d a, Eigen::Vector3d b);
00335 
00342   Eigen::Vector3d getCenterPoint(Eigen::Vector3d a, Eigen::Vector3d b);
00343 
00348   const std::string getBaseFrame()
00349   {
00350     return base_frame_;
00351   }
00352   MOVEIT_DEPRECATED const std::string getBaseLink()
00353   {
00354     return base_frame_;
00355   }
00356 
00362   void setBaseFrame(const std::string& base_frame)
00363   {
00364     base_frame_ = base_frame;
00365     loadRvizMarkers();
00366   }
00367 
00371   double getGlobalScale()
00372   {
00373     return global_scale_;
00374   }
00375 
00379   void setGlobalScale(double global_scale)
00380   {
00381     global_scale_ = global_scale;
00382   }
00383 
00389   bool publishEEMarkers(const geometry_msgs::Pose &pose, const rviz_colors &color = WHITE, const std::string &ns="end_effector");
00390 
00398   bool publishSphere(const Eigen::Affine3d &pose, const rviz_colors color = BLUE, const rviz_scales scale = REGULAR, const std::string& ns = "Sphere");
00399   bool publishSphere(const Eigen::Vector3d &point, const rviz_colors color = BLUE, const rviz_scales scale = REGULAR, const std::string& ns = "Sphere");
00400   bool publishSphere(const geometry_msgs::Point &point, const rviz_colors color = BLUE, const rviz_scales scale = REGULAR, const std::string& ns = "Sphere");
00401   bool publishSphere(const geometry_msgs::Pose &pose, const rviz_colors color = BLUE, const rviz_scales scale = REGULAR, const std::string& ns = "Sphere");
00402   bool publishSphere(const geometry_msgs::Pose &pose, const rviz_colors color, const double scale, const std::string& ns = "Sphere");
00403   bool publishSphere(const geometry_msgs::Pose &pose, const rviz_colors color, const geometry_msgs::Vector3 scale, const std::string& ns = "Sphere");
00404 
00412   bool publishArrow(const Eigen::Affine3d &pose, const rviz_colors color = BLUE, const rviz_scales scale = REGULAR);
00413   bool publishArrow(const geometry_msgs::Pose &pose, const rviz_colors color = BLUE, const rviz_scales scale = REGULAR);
00414 
00422   bool publishRectangle(const geometry_msgs::Point &point1, const geometry_msgs::Point &point2, const rviz_colors color = BLUE);
00423 
00432   bool publishLine(const geometry_msgs::Point &point1, const geometry_msgs::Point &point2,
00433                    const rviz_colors color = BLUE, const rviz_scales scale = REGULAR);
00434 
00443   bool publishPath(const std::vector<geometry_msgs::Point> &path, const rviz_colors color = RED, const rviz_scales scale = REGULAR,
00444                    const std::string& ns = "Path");
00445 
00454   bool publishPolygon(const geometry_msgs::Polygon &polygon, const rviz_colors color = RED, const rviz_scales scale = REGULAR,
00455                       const std::string& ns = "Polygon");
00456 
00464   bool publishBlock(const geometry_msgs::Pose &pose, const rviz_colors color = BLUE, const double &block_size = 0.1);
00465 
00474   bool publishCylinder(const geometry_msgs::Pose &pose, const rviz_colors color = BLUE, double height = 0.1, double radius = 0.1);
00475 
00483   bool publishGraph(const graph_msgs::GeometryGraph &graph, const rviz_colors color, double radius);
00484 
00485 
00494   bool publishSpheres(const std::vector<geometry_msgs::Point> &points, const rviz_colors color = BLUE, const rviz_scales scale = REGULAR,
00495                       const std::string& ns = "Spheres");
00496 
00505   bool publishText(const geometry_msgs::Pose &pose, const std::string &text,
00506                    const rviz_colors &color = WHITE, const rviz_scales scale = REGULAR);
00507 
00508   bool publishText(const geometry_msgs::Pose &pose, const std::string &text,
00509                    const rviz_colors &color, const geometry_msgs::Vector3 scale, bool static_id = true);
00510 
00516   bool publishMarker(const visualization_msgs::Marker &marker);
00517 
00523   bool publishGrasps(const std::vector<moveit_msgs::Grasp>& possible_grasps,
00524                      const std::string &ee_parent_link);
00525 
00532   bool publishAnimatedGrasps(const std::vector<moveit_msgs::Grasp>& possible_grasps,
00533                              const std::string &ee_parent_link, double animate_speed = 0.01);
00534 
00542   bool publishAnimatedGrasp(const moveit_msgs::Grasp &grasp, const std::string &ee_parent_link, double animate_speed);
00543 
00550   bool publishIKSolutions(const std::vector<trajectory_msgs::JointTrajectoryPoint> &ik_solutions,
00551                           const std::string& planning_group, double display_time = 0.4);
00552 
00558   MOVEIT_DEPRECATED bool removeAllCollisionObjects()
00559   {
00560     publishRemoveAllCollisionObjects();
00561   }
00562   bool publishRemoveAllCollisionObjects();
00563 
00570   bool removeAllCollisionObjectsPS();
00571 
00577   bool cleanupCO(std::string name);
00578 
00584   bool cleanupACO(const std::string& name);
00585 
00592   bool attachCO(const std::string& name, const std::string& ee_parent_link);
00593 
00600   bool publishCollisionFloor(double z, std::string plane_name);
00601 
00609   bool publishCollisionBlock(geometry_msgs::Pose block_pose, std::string block_name, double block_size);
00610 
00619   bool publishCollisionCylinder(geometry_msgs::Point a, geometry_msgs::Point b, std::string object_name, double radius);
00620   bool publishCollisionCylinder(Eigen::Vector3d a, Eigen::Vector3d b, std::string object_name, double radius);
00621 
00630   bool publishCollisionCylinder(Eigen::Affine3d object_pose, std::string object_name, double radius, double height);
00631   bool publishCollisionCylinder(geometry_msgs::Pose object_pose, std::string object_name, double radius, double height);
00632 
00639   bool publishCollisionGraph(const graph_msgs::GeometryGraph &graph, const std::string &object_name, double radius);
00640 
00644   void getCollisionWallMsg(double x, double y, double angle, double width, const std::string name,
00645                            moveit_msgs::CollisionObject &collision_obj);
00646 
00656   bool publishCollisionWall(double x, double y, double angle, double width, const std::string name);
00657 
00669   bool publishCollisionTable(double x, double y, double angle, double width, double height,
00670                              double depth, const std::string name);
00671 
00678   bool loadCollisionSceneFromFile(const std::string &path);
00679 
00691   bool publishTrajectoryPoint(const trajectory_msgs::JointTrajectoryPoint& trajectory_pt, const std::string &group_name,
00692                               double display_time = 0.1);
00693 
00700   bool publishTrajectoryPath(const robot_trajectory::RobotTrajectory& trajectory, bool blocking = false);
00701   bool publishTrajectoryPath(const moveit_msgs::RobotTrajectory& trajectory_msg, bool blocking = false);
00702 
00708   bool publishRobotState(const robot_state::RobotState &robot_state);
00709   bool publishRobotState(const robot_state::RobotStatePtr &robot_state);
00710 
00716   bool publishRobotState(const trajectory_msgs::JointTrajectoryPoint& trajectory_pt, const std::string &group_name);
00717 
00722   bool hideRobot();
00723 
00728   bool publishTest();
00729 
00736   static geometry_msgs::Pose convertPose(const Eigen::Affine3d &pose);
00737 
00744   static Eigen::Affine3d convertPose(const geometry_msgs::Pose &pose);
00745 
00752   static Eigen::Affine3d convertPoint32ToPose(const geometry_msgs::Point32 &point);
00753 
00760   static geometry_msgs::Pose convertPointToPose(const geometry_msgs::Point &point);
00761 
00768   static geometry_msgs::Point convertPoseToPoint(const Eigen::Affine3d &pose);
00769 
00776   static Eigen::Vector3d convertPoint(const geometry_msgs::Point &point);
00777 
00784   static Eigen::Vector3d convertPoint32(const geometry_msgs::Point32 &point);
00785 
00792   static geometry_msgs::Point32 convertPoint32(const Eigen::Vector3d &point);
00793 
00798   void generateRandomPose(geometry_msgs::Pose& pose);
00799 
00803   static double dRand(double dMin, double dMax);
00804   static float fRand(float dMin, float dMax);
00805   static int iRand(int dMin, int dMax);
00806 
00810   void print();
00811 
00812 private:
00813 
00818   planning_scene_monitor::PlanningSceneMonitorPtr getPlanningSceneMonitor();
00819 
00820 
00821 }; // class
00822 
00823 typedef boost::shared_ptr<VisualTools> VisualToolsPtr;
00824 typedef boost::shared_ptr<const VisualTools> VisualToolsConstPtr;
00825 
00826 } // namespace
00827 
00828 #endif


moveit_visual_tools
Author(s): Dave Coleman
autogenerated on Wed Aug 26 2015 14:54:49