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>(planning_scene_monitor::PlanningSceneMonitor::DEFAULT_PLANNING_SCENE_TOPIC, 1);
00064     else
00065       pub_scene = nh.advertise<moveit_msgs::PlanningSceneWorld>(planning_scene_monitor::PlanningSceneMonitor::DEFAULT_PLANNING_SCENE_WORLD_TOPIC, 1);
00066     
00067     robot_model_loader::RobotModelLoader::Options opt;
00068     opt.robot_description_ = "robot_description";
00069     opt.load_kinematics_solvers_ = false;
00070     robot_model_loader::RobotModelLoaderPtr rml(new robot_model_loader::RobotModelLoader(opt));
00071     planning_scene::PlanningScene ps(rml->getModel());
00072     
00073     std::ifstream f(argv[filename_index]);
00074     if (f.good() && !f.eof())
00075     {
00076       ROS_INFO("Publishing geometry from '%s' ...", argv[filename_index]);
00077       ps.loadGeometryFromStream(f);
00078       moveit_msgs::PlanningScene ps_msg;
00079       ps.getPlanningSceneMsg(ps_msg);
00080       ps_msg.is_diff = true;
00081       
00082       ros::WallDuration dt(0.5);
00083       unsigned int attempts = 0;
00084       while (pub_scene.getNumSubscribers() < 1 && ++attempts < 100)
00085         dt.sleep();
00086       
00087       if (full_scene)
00088         pub_scene.publish(ps_msg);
00089       else
00090         pub_scene.publish(ps_msg.world);
00091 
00092       sleep(1);
00093     }
00094     else
00095       ROS_WARN("Unable to load '%s'.", argv[filename_index]);
00096   }
00097   else
00098     ROS_WARN("A filename was expected as argument. That file should be a text representation of the geometry in a planning scene.");
00099   
00100   ros::shutdown();
00101   return 0;
00102 }


planning
Author(s): Ioan Sucan , Sachin Chitta
autogenerated on Wed Aug 26 2015 12:43:30