exploration_transform_vis.h
Go to the documentation of this file.
00001 //=================================================================================================
00002 // Copyright (c) 2012, Mark Sollweck, Stefan Kohlbrecher, TU Darmstadt
00003 // All rights reserved.
00004 
00005 // Redistribution and use in source and binary forms, with or without
00006 // modification, are permitted provided that the following conditions are met:
00007 //     * Redistributions of source code must retain the above copyright
00008 //       notice, this list of conditions and the following disclaimer.
00009 //     * Redistributions in binary form must reproduce the above copyright
00010 //       notice, this list of conditions and the following disclaimer in the
00011 //       documentation and/or other materials provided with the distribution.
00012 //     * Neither the name of the Simulation, Systems Optimization and Robotics
00013 //       group, TU Darmstadt nor the names of its contributors may be used to
00014 //       endorse or promote products derived from this software without
00015 //       specific prior written permission.
00016 
00017 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
00018 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00019 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00020 // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
00021 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00022 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00023 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00024 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00025 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00026 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00027 //=================================================================================================
00028 
00029 #ifndef EXPLORATION_TRANSFORM_VIS_H___
00030 #define EXPLORATION_TRANSFORM_VIS_H___
00031 
00032 #include <sensor_msgs/PointCloud.h>
00033 #include <ros/ros.h>
00034 #include <costmap_2d/costmap_2d.h>
00035 
00036 
00037 namespace hector_exploration_planner{
00038 
00039   class ExplorationTransformVis
00040   {
00041   public:
00042     ExplorationTransformVis(const std::string& topic_name)
00043     {
00044       ros::NodeHandle pnh("~");
00045       exploration_transform_pointcloud_pub_ = pnh.advertise<sensor_msgs::PointCloud>(topic_name, 2, false);
00046     }
00047 
00048     virtual ~ExplorationTransformVis()
00049     {}
00050 
00051     void publishVisOnDemand(const costmap_2d::Costmap2D& costmap, const unsigned int* exploration_array)
00052     {
00053       if (exploration_transform_pointcloud_pub_.getNumSubscribers() > 0){
00054         unsigned int size_x = costmap.getSizeInCellsX();
00055         unsigned int size_y = costmap.getSizeInCellsY();
00056         unsigned int size = size_x * size_y;
00057 
00058         unsigned int max = 0;
00059 
00060         for (size_t i = 0; i < size; ++i){
00061           if ((exploration_array[i] < INT_MAX) && (exploration_array[i] > max)){
00062             max = exploration_array[i];
00063           }
00064         }
00065 
00066         float max_f = static_cast<float>(max);
00067 
00068         sensor_msgs::PointCloud cloud;
00069         cloud.header.frame_id = "/map";
00070         cloud.header.stamp = ros::Time::now();
00071 
00072         double x_world, y_world;
00073 
00074         geometry_msgs::Point32 point;
00075 
00076         for (size_t x = 0; x < size_x; ++x){
00077           for (size_t y = 0; y < size_y; ++y){
00078 
00079             unsigned int index = costmap.getIndex(x,y);
00080 
00081             if (exploration_array[index] < INT_MAX){
00082 
00083               costmap.mapToWorld(x,y, x_world, y_world);
00084               point.x = x_world;
00085               point.y = y_world;
00086               point.z = static_cast<float>(exploration_array[index])/max_f;
00087 
00088               cloud.points.push_back(point);
00089             }
00090 
00091           }
00092         }
00093         exploration_transform_pointcloud_pub_.publish(cloud);
00094       }
00095     }
00096 
00097   protected:
00098 
00099     ros::Publisher exploration_transform_pointcloud_pub_;
00100   };
00101 
00102 }
00103 
00104 #endif


hector_exploration_planner
Author(s):
autogenerated on Wed May 8 2019 02:32:10