$search
00001 00009 /* 00010 * Copyright (c) 2010-2012, A. Hornung, University of Freiburg 00011 * All rights reserved. 00012 * 00013 * Redistribution and use in source and binary forms, with or without 00014 * modification, are permitted provided that the following conditions are met: 00015 * 00016 * * Redistributions of source code must retain the above copyright 00017 * notice, this list of conditions and the following disclaimer. 00018 * * Redistributions in binary form must reproduce the above copyright 00019 * notice, this list of conditions and the following disclaimer in the 00020 * documentation and/or other materials provided with the distribution. 00021 * * Neither the name of the University of Freiburg nor the names of its 00022 * contributors may be used to endorse or promote products derived from 00023 * this software without specific prior written permission. 00024 * 00025 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00026 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00027 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00028 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 00029 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00030 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 00031 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00032 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00033 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00034 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00035 * POSSIBILITY OF SUCH DAMAGE. 00036 */ 00037 00038 00039 #include <ros/ros.h> 00040 #include <visualization_msgs/MarkerArray.h> 00041 #include <nav_msgs/OccupancyGrid.h> 00042 #include <std_msgs/ColorRGBA.h> 00043 #include <arm_navigation_msgs/CollisionObject.h> 00044 #include <arm_navigation_msgs/CollisionMap.h> 00045 #include <sensor_msgs/PointCloud2.h> 00046 #include <std_srvs/Empty.h> 00047 #include <dynamic_reconfigure/server.h> 00048 #include <octomap_server/OctomapServerConfig.h> 00049 00050 #include <pcl/point_types.h> 00051 #include <pcl/ros/conversions.h> 00052 #include <pcl_ros/transforms.h> 00053 #include <pcl/sample_consensus/method_types.h> 00054 #include <pcl/sample_consensus/model_types.h> 00055 #include <pcl/segmentation/sac_segmentation.h> 00056 #include <pcl/io/pcd_io.h> 00057 #include <pcl/filters/extract_indices.h> 00058 #include <pcl/filters/passthrough.h> 00059 00060 00061 #include <tf/transform_listener.h> 00062 #include <tf/message_filter.h> 00063 #include <message_filters/subscriber.h> 00064 #include <octomap_ros/OctomapBinary.h> 00065 #include <octomap_ros/GetOctomap.h> 00066 #include <octomap_ros/ClearBBXRegion.h> 00067 #include <octomap_ros/OctomapROS.h> 00068 #include <octomap/OcTreeKey.h> 00069 00070 00071 namespace octomap_server { 00072 class OctomapServer{ 00073 00074 public: 00075 typedef pcl::PointCloud<pcl::PointXYZ> PCLPointCloud; 00076 00077 00078 OctomapServer(const std::string& filename= ""); 00079 virtual ~OctomapServer(); 00080 bool serviceCallback(octomap_ros::GetOctomap::Request &req, octomap_ros::GetOctomap::Response &res); 00081 bool clearBBXSrv(octomap_ros::ClearBBXRegionRequest& req, octomap_ros::ClearBBXRegionRequest& resp); 00082 bool resetSrv(std_srvs::Empty::Request& req, std_srvs::Empty::Response& resp); 00083 00084 void insertCloudCallback(const sensor_msgs::PointCloud2::ConstPtr& cloud); 00085 bool openFile(const std::string& filename); 00086 00087 protected: 00088 void reconfigureCallback(octomap_server::OctomapServerConfig& config, uint32_t level); 00089 void publishMap(const ros::Time& rostime = ros::Time::now()) const; 00090 void publishAll(const ros::Time& rostime = ros::Time::now()); 00091 00100 virtual void insertScan(const tf::Point& sensorOrigin, const PCLPointCloud& ground, const PCLPointCloud& nonground); 00101 00103 void filterGroundPlane(const PCLPointCloud& pc, PCLPointCloud& ground, PCLPointCloud& nonground) const; 00104 00110 bool isSpeckleNode(const octomap::OcTreeKey& key) const; 00111 00113 void handlePreNodeTraversal(const ros::Time& rostime); 00114 00116 void handleNode(const octomap::OcTreeROS::OcTreeType::iterator& it) {}; 00117 00119 void handleOccupiedNode(const octomap::OcTreeROS::OcTreeType::iterator& it); 00120 00122 void handleFreeNode(const octomap::OcTreeROS::OcTreeType::iterator& it); 00123 00125 void handlePostNodeTraversal(const ros::Time& rostime); 00126 00127 std_msgs::ColorRGBA heightMapColor(double h) const; 00128 ros::NodeHandle m_nh; 00129 ros::Publisher m_markerPub, m_binaryMapPub, m_pointCloudPub, m_collisionObjectPub, m_mapPub, m_cmapPub; 00130 message_filters::Subscriber<sensor_msgs::PointCloud2>* m_pointCloudSub; 00131 tf::MessageFilter<sensor_msgs::PointCloud2>* m_tfPointCloudSub; 00132 ros::ServiceServer m_octomapService, m_clearBBXService, m_resetService; 00133 tf::TransformListener m_tfListener; 00134 dynamic_reconfigure::Server<OctomapServerConfig> m_reconfigureServer; 00135 00136 octomap::OcTreeROS *m_octoMap; 00137 octomap::KeyRay m_keyRay; // temp storage for ray casting 00138 double m_maxRange; 00139 std::string m_worldFrameId; // the map frame 00140 std::string m_baseFrameId; // base of the robot for ground plane filtering 00141 bool m_useHeightMap; 00142 std_msgs::ColorRGBA m_color; 00143 double m_colorFactor; 00144 00145 bool m_latchedTopics; 00146 00147 double m_res; 00148 unsigned m_treeDepth; 00149 unsigned m_maxTreeDepth; 00150 double m_probHit; 00151 double m_probMiss; 00152 double m_thresMin; 00153 double m_thresMax; 00154 00155 double m_pointcloudMinZ; 00156 double m_pointcloudMaxZ; 00157 double m_occupancyMinZ; 00158 double m_occupancyMaxZ; 00159 double m_minSizeX; 00160 double m_minSizeY; 00161 bool m_filterSpeckles; 00162 00163 bool m_filterGroundPlane; 00164 double m_groundFilterDistance; 00165 double m_groundFilterAngle; 00166 double m_groundFilterPlaneDistance; 00167 00168 // downprojected 2D map: 00169 nav_msgs::OccupancyGrid m_gridmap; 00170 bool m_publish2DMap; 00171 octomap::OcTreeKey m_paddedMinKey; 00172 unsigned m_multires2DScale; 00173 }; 00174 } 00175