publish_scene_from_text.cpp
Go to the documentation of this file.
00001 /*********************************************************************
00002  * Software License Agreement (BSD License)
00003  *
00004  *  Copyright (c) 2013, Ioan A. Sucan
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 Ioan A. Sucan 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: Ioan Sucan */
00036 
00037 #include <moveit/planning_scene_monitor/planning_scene_monitor.h>
00038 
00039 int main(int argc, char** argv)
00040 {
00041   ros::init(argc, argv, "publish_planning_scene", ros::init_options::AnonymousName);
00042 
00043   // decide whether to publish the full scene
00044   bool full_scene = false;
00045 
00046   // the index of the argument with the filename
00047   int filename_index = 1;
00048   if (argc > 2)
00049     if (strncmp(argv[1], "--scene", 7) == 0)
00050     {
00051       full_scene = true;
00052       filename_index = 2;
00053     }
00054 
00055   if (argc > 1)
00056   {
00057     ros::AsyncSpinner spinner(1);
00058     spinner.start();
00059 
00060     ros::NodeHandle nh;
00061     ros::Publisher pub_scene;
00062     if (full_scene)
00063       pub_scene = nh.advertise<moveit_msgs::PlanningScene>(
00064           planning_scene_monitor::PlanningSceneMonitor::DEFAULT_PLANNING_SCENE_TOPIC, 1);
00065     else
00066       pub_scene = nh.advertise<moveit_msgs::PlanningSceneWorld>(
00067           planning_scene_monitor::PlanningSceneMonitor::DEFAULT_PLANNING_SCENE_WORLD_TOPIC, 1);
00068 
00069     robot_model_loader::RobotModelLoader::Options opt;
00070     opt.robot_description_ = "robot_description";
00071     opt.load_kinematics_solvers_ = false;
00072     robot_model_loader::RobotModelLoaderPtr rml(new robot_model_loader::RobotModelLoader(opt));
00073     planning_scene::PlanningScene ps(rml->getModel());
00074 
00075     std::ifstream f(argv[filename_index]);
00076     if (f.good() && !f.eof())
00077     {
00078       ROS_INFO("Publishing geometry from '%s' ...", argv[filename_index]);
00079       ps.loadGeometryFromStream(f);
00080       moveit_msgs::PlanningScene ps_msg;
00081       ps.getPlanningSceneMsg(ps_msg);
00082       ps_msg.is_diff = true;
00083 
00084       ros::WallDuration dt(0.5);
00085       unsigned int attempts = 0;
00086       while (pub_scene.getNumSubscribers() < 1 && ++attempts < 100)
00087         dt.sleep();
00088 
00089       if (full_scene)
00090         pub_scene.publish(ps_msg);
00091       else
00092         pub_scene.publish(ps_msg.world);
00093 
00094       sleep(1);
00095     }
00096     else
00097       ROS_WARN("Unable to load '%s'.", argv[filename_index]);
00098   }
00099   else
00100     ROS_WARN("A filename was expected as argument. That file should be a text representation of the geometry in a "
00101              "planning scene.");
00102 
00103   ros::shutdown();
00104   return 0;
00105 }


planning
Author(s): Ioan Sucan , Sachin Chitta
autogenerated on Mon Jul 24 2017 02:21:19