box_detection_node.h
Go to the documentation of this file.
00001 /*********************************************************************
00002  *
00003  *  Software License Agreement (BSD License)
00004  *
00005  *  Copyright (c) 2014, Alexander Buchegger
00006  *                      Institute for Software Technology,
00007  *                      Graz University of Technology
00008  *  All rights reserved.
00009  *
00010  *  Redistribution and use in source and binary forms, with or without
00011  *  modification, are permitted provided that the following conditions
00012  *  are met:
00013  *
00014  *   * Redistributions of source code must retain the above copyright
00015  *     notice, this list of conditions and the following disclaimer.
00016  *   * Redistributions in binary form must reproduce the above
00017  *     copyright notice, this list of conditions and the following
00018  *     disclaimer in the documentation and/or other materials provided
00019  *     with the distribution.
00020  *   * Neither the name of Graz University of Technology nor the names of
00021  *     its contributors may be used to endorse or promote products derived
00022  *     from this software without specific prior written permission.
00023  *
00024  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00025  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00026  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00027  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00028  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00029  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00030  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00031  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00032  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00033  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00034  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00035  *  POSSIBILITY OF SUCH DAMAGE.
00036  *
00037  *********************************************************************/
00038 #ifndef TEDUSAR_BOX_DETECTION__BOX_DETECTION_H_
00039 #define TEDUSAR_BOX_DETECTION__BOX_DETECTION_H_
00040 
00041 // Prevent unaligned array exception:
00042 #define EIGEN_DONT_VECTORIZE
00043 #define EIGEN_DISABLE_UNALIGNED_ARRAY_ASSERT
00044 
00045 #include <Eigen/Geometry>
00046 #include <pcl/point_cloud.h>
00047 #include <pcl/point_types.h>
00048 #include <pcl/PointIndices.h>
00049 #include <ros/node_handle.h>
00050 #include <ros/subscriber.h>
00051 #include <ros/time.h>
00052 #include <ros/timer.h>
00053 #include <tf/transform_listener.h>
00054 #include <actionlib/server/simple_action_server.h>
00055 #include <sensor_msgs/PointCloud.h>
00056 #include <sensor_msgs/PointCloud2.h>
00057 #include <geometry_msgs/PoseStamped.h>
00058 #include <geometry_msgs/Vector3.h>
00059 #include <moveit_msgs/PlanningScene.h>
00060 #include <tedusar_box_detection_msgs/BoxDetectionAction.h>
00061 
00062 namespace tedusar_box_detection
00063 {
00064 
00065 class BoxDetectionNode
00066 {
00067 public:
00068     BoxDetectionNode();
00069 
00070 private:
00071     typedef pcl::PointXYZ PclPoint;
00072     typedef pcl::PointCloud<PclPoint> PclPointCloud;
00073 
00074     struct Parameters
00075     {
00076         std::string point_cloud_topic_;
00077         std::string target_frame_id_;
00078         bool have_action_server_debug_output_;
00079         bool have_box_detection_debug_output_;
00080 
00081         int box_plane_points_min_;
00082         Eigen::Vector3f box_plane_size_min_;
00083         Eigen::Vector3f box_plane_size_max_;
00084         double detection_timeout_;
00085         double plane_fitting_distance_threshold_;
00086         int plane_fitting_max_iterations_;
00087         double downsampling_leaf_size_;
00088         double clusterization_tolerance_;
00089 
00090         bool have_plane_publisher_;
00091         double plane_publishing_rate_;
00092 
00093         bool have_collision_object_publisher_;
00094         std::string collision_objects_basename_;
00095 
00096         bool have_visualization_marker_publisher_;
00097         std::string visualization_marker_namespace_;
00098     };
00099 
00100     struct Box
00101     {
00102         unsigned int id_;
00103         std::string name_;
00104         geometry_msgs::PoseStamped pose_;
00105         geometry_msgs::Vector3 size_;
00106     };
00107 
00108     void loadParameters();
00109     template <typename T> static void getRequiredParameter(ros::NodeHandle & private_nh, const std::string & key, T & value);
00110     template <typename T> static void getOptionalParameter(ros::NodeHandle & private_nh, const std::string & key, T & value, T default_value);
00111     template <typename T> static bool getParameter(ros::NodeHandle & private_nh, const std::string & key, T & value);
00112 
00113     void boxDetectionActionGoalCallback();
00114     void boxDetectionActionPreemptCallback();
00115     void pointCloudCallback(const sensor_msgs::PointCloud2ConstPtr & msg);
00116     void planePublisherTimerCallback(const ros::TimerEvent &);
00117 
00118     void fitPlane(const PclPointCloud::ConstPtr & cloud, pcl::PointIndices::Ptr & inliers);
00119     void extractPlane(const PclPointCloud::ConstPtr & cloud,
00120                       const pcl::PointIndices::ConstPtr & inliers,
00121                       PclPointCloud & cloud_plane,
00122                       PclPointCloud & cloud_rest);
00123     void downsampleCloud(const PclPointCloud::ConstPtr & cloud, PclPointCloud & cloud_filtered);
00124     void clusterizeCloud(const PclPointCloud::ConstPtr & cloud, std::vector<pcl::PointIndices> & cluster_indices);
00125     bool fitBox(const PclPointCloud::ConstPtr & cloud, Box & box);
00126     void publishClusterCloud(const PclPointCloud::ConstPtr & cloud);
00127     void publishCollisionObject(const Box & box);
00128     void publishVisualizationMarker(const Box & box);
00129     void publishActionFeedback(const Box & box);
00130 
00131     ros::NodeHandle nh_;
00132     Parameters parameters_;
00133     actionlib::SimpleActionServer<tedusar_box_detection_msgs::BoxDetectionAction> box_detection_as_;
00134     tf::TransformListener tf_listener_;
00135     ros::Subscriber point_cloud_subscriber_;
00136     ros::Publisher plane_cloud_publisher_;
00137     ros::Timer plane_publisher_timer_;
00138     ros::Publisher planning_scene_publisher_;
00139     ros::Publisher visualization_marker_publisher_;
00140     ros::Time detection_timeout_time_;
00141     std::vector<Box> boxes_;
00142     sensor_msgs::PointCloud plane_cloud_;
00143     float plane_intensity_;
00144     unsigned int box_counter_;
00145 };
00146 
00147 }
00148 
00149 #endif // TEDUSAR_BOX_DETECTION__BOX_DETECTION_H_


tedusar_box_detection
Author(s):
autogenerated on Wed Aug 26 2015 16:30:42