collision_objects_demo.cpp
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:   Demo implementation of moveit_visual_tools
00037            To use, add a Rviz Marker Display subscribed to topic /moveit_visual_tools
00038 */
00039 
00040 // ROS
00041 #include <ros/ros.h>
00042 
00043 // For visualizing things in rviz
00044 #include <moveit_visual_tools/moveit_visual_tools.h>
00045 
00046 // MoveIt
00047 #include <moveit/planning_scene_monitor/planning_scene_monitor.h>
00048 
00049 namespace moveit_visual_tools
00050 {
00051 
00052 // Baxter specific
00053 static const std::string EE_PARENT_LINK = "right_wrist";
00054 static const std::string PLANNING_GROUP_NAME = "right_arm_torso_grasping";
00055 static const std::string EE_GROUP = "right_hand";
00056 
00057 class VisualToolsDemo
00058 {
00059 private:
00060 
00061   // A shared node handle
00062   ros::NodeHandle nh_;
00063 
00064   // For visualizing things in rviz
00065   moveit_visual_tools::MoveItVisualToolsPtr visual_tools_;
00066 
00067   // MoveIt Components
00068   planning_scene_monitor::PlanningSceneMonitorPtr planning_scene_monitor_;
00069 
00070 public:
00071 
00075   VisualToolsDemo()
00076   {
00077     visual_tools_.reset(new moveit_visual_tools::MoveItVisualTools("base","/moveit_visual_tools"));
00078     visual_tools_->loadPlanningSceneMonitor();
00079 
00080     // Allow time to publish messages
00081     ros::spinOnce();
00082     ros::Duration(5.0).sleep();
00083 
00084     // Create pose
00085     geometry_msgs::Pose pose1;
00086     geometry_msgs::Pose pose2;
00087 
00088     // Demo all collision shapes ----------
00089     for (std::size_t i = 0; i < 10; ++i)
00090     {
00091       if (!ros::ok())
00092         break;
00093 
00094       ROS_INFO_STREAM_NAMED("visual_tools","Publishing Collision Mesh");
00095       visual_tools_->generateRandomPose(pose1);
00096       static const std::string package = "moveit_visual_tools";
00097       std::string path = "file://" + ros::package::getPath(package);
00098       if( path == "file://" )
00099         ROS_FATAL_STREAM_NAMED("visual_tools", "Unable to get " << package << " package path " );
00100       path.append("/resources/demo_mesh.stl");
00101       visual_tools_->publishCollisionMesh(pose1, "Mesh", path, rviz_visual_tools::RAND);
00102       ros::Duration(1.0).sleep();
00103 
00104       ROS_INFO_STREAM_NAMED("visual_tools","Publishing Collision Block");
00105       visual_tools_->generateRandomPose(pose1);
00106       visual_tools_->publishCollisionBlock(pose1, "Block", 0.1, rviz_visual_tools::RAND);
00107       ros::Duration(1.0).sleep();
00108 
00109       ROS_INFO_STREAM_NAMED("visual_tools","Publishing Collision Rectanglular Cuboid");
00110       visual_tools_->generateRandomPose(pose1);
00111       visual_tools_->generateRandomPose(pose2);
00112       visual_tools_->publishCollisionCuboid(pose1.position, pose2.position, "Rectangle", rviz_visual_tools::RAND);
00113       ros::Duration(1.0).sleep();
00114 
00115       ROS_INFO_STREAM_NAMED("visual_tools","Publishing Collision Floor");
00116       visual_tools_->publishCollisionFloor(0, "Floor", rviz_visual_tools::RAND);
00117       ros::Duration(1.0).sleep();
00118 
00119       ROS_INFO_STREAM_NAMED("visual_tools","Publishing Collision Cylinder");
00120       visual_tools_->generateRandomPose(pose1);
00121       visual_tools_->generateRandomPose(pose2);
00122       visual_tools_->publishCollisionCylinder(pose1.position, pose2.position, "Cylinder", 0.1, rviz_visual_tools::RAND);
00123       ros::Duration(1.0).sleep();
00124 
00125       // TODO: test publishCollisionGraph
00126 
00127       ROS_INFO_STREAM_NAMED("visual_tools","Publishing Collision Wall");
00128       visual_tools_->generateRandomPose(pose1);
00129       visual_tools_->publishCollisionWall(pose1.position.x, pose1.position.y, 0, 1, "Wall", rviz_visual_tools::RAND);
00130       ros::Duration(1.0).sleep();
00131 
00132       ROS_INFO_STREAM_NAMED("visual_tools","Publishing Collision Table");
00133       visual_tools_->generateRandomPose(pose1);
00134       visual_tools_->publishCollisionTable(pose1.position.x, pose1.position.y, 0, 0.5, 0.5, 0.5, "Table", rviz_visual_tools::RAND);
00135       ros::Duration(1.0).sleep();
00136     }
00137   }
00138 
00142   ~VisualToolsDemo()
00143   {
00144   }
00145 
00146 }; // end class
00147 
00148 } // end namespace
00149 
00150 int main(int argc, char** argv)
00151 {
00152   ros::init(argc, argv, "visual_tools_demo");
00153   ROS_INFO_STREAM("Visual Tools Demo");
00154 
00155   // Allow the action server to recieve and send ros messages
00156   ros::AsyncSpinner spinner(1);
00157   spinner.start();
00158 
00159   moveit_visual_tools::VisualToolsDemo demoer;
00160 
00161   ROS_INFO_STREAM("Shutting down.");
00162 
00163   return 0;
00164 }


moveit_visual_tools
Author(s): Dave Coleman
autogenerated on Thu Jun 6 2019 17:34:03