Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #ifndef TEDUSAR_BOX_DETECTION__BOX_DETECTION_H_
00039 #define TEDUSAR_BOX_DETECTION__BOX_DETECTION_H_
00040
00041
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_