$search
00001 /********************************************************************* 00002 * Software License Agreement (BSD License) 00003 * 00004 * Copyright (c) 2009, Willow Garage, Inc. 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 the Willow Garage 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 00036 00037 #include <ros/console.h> 00038 #include <ros/ros.h> 00039 #include <laser_cb_detector/laser_cb_detector.h> 00040 #include <sstream> 00041 00042 using namespace laser_cb_detector; 00043 using namespace std; 00044 00045 00046 #define ROS_INFO_CONFIG(name) \ 00047 {\ 00048 ostringstream ss;\ 00049 ss << "[" << #name << "] -> " << config.name;\ 00050 ROS_INFO(ss.str().c_str());\ 00051 } 00052 00053 00054 00055 laser_cb_detector::ConfigGoal getParamConfig(ros::NodeHandle &n) 00056 { 00057 laser_cb_detector::ConfigGoal config; 00058 00059 ros::NodeHandle pn("~"); 00060 00061 int num_x; 00062 pn.param("num_x", num_x, 3); 00063 config.num_x = (unsigned int) num_x; 00064 00065 int num_y; 00066 pn.param("num_y", num_y, 3); 00067 config.num_y = (unsigned int) num_y; 00068 00069 double spacing_x; 00070 pn.param("spacing_x", spacing_x, 1.0); 00071 config.spacing_x = spacing_x; 00072 00073 double spacing_y; 00074 pn.param("spacing_y", spacing_y, 1.0); 00075 config.spacing_y = spacing_y; 00076 00077 double width_scaling; 00078 pn.param("width_scaling", width_scaling, 1.0); 00079 config.width_scaling = width_scaling; 00080 00081 double height_scaling; 00082 pn.param("height_scaling", height_scaling, 1.0); 00083 config.height_scaling = height_scaling; 00084 00085 double min_intensity; 00086 pn.param("min_intensity", min_intensity, 500.0); 00087 config.min_intensity = min_intensity; 00088 00089 double max_intensity; 00090 pn.param("max_intensity", max_intensity, 5000.0); 00091 config.max_intensity = max_intensity; 00092 00093 int subpixel_window; 00094 pn.param("subpixel_window", subpixel_window, 2); 00095 config.subpixel_window = subpixel_window; 00096 00097 pn.param("subpixel_zero_zone", config.subpixel_zero_zone, -1); 00098 00099 int flip_horizontal; 00100 pn.param("flip_horizontal", flip_horizontal, 0); 00101 if (flip_horizontal) 00102 config.flip_horizontal = 1; 00103 else 00104 config.flip_horizontal = 0; 00105 00106 ROS_INFO_CONFIG(num_x); 00107 ROS_INFO_CONFIG(num_y); 00108 ROS_INFO_CONFIG(spacing_x); 00109 ROS_INFO_CONFIG(spacing_y); 00110 ROS_INFO_CONFIG(width_scaling); 00111 ROS_INFO_CONFIG(height_scaling); 00112 ROS_INFO_CONFIG(min_intensity); 00113 ROS_INFO_CONFIG(max_intensity); 00114 ROS_INFO_CONFIG(subpixel_window); 00115 ROS_INFO_CONFIG(subpixel_zero_zone); 00116 //ROS_INFO_CONFIG(reflect_model); 00117 ROS_INFO("[flip_horizontal]->%u", config.flip_horizontal); 00118 00119 return config; 00120 } 00121 00122 void snapshotCallback(ros::Publisher* pub, ros::Publisher* image_pub, LaserCbDetector* detector, const calibration_msgs::DenseLaserSnapshotConstPtr& msg) 00123 { 00124 bool detect_result; 00125 calibration_msgs::CalibrationPattern result; 00126 detect_result = detector->detect(*msg, result); 00127 00128 if (!detect_result) 00129 ROS_ERROR("Error during checkerboard detection. (This error is worse than simply not seeing a checkerboard"); 00130 else 00131 { 00132 pub->publish(result); 00133 } 00134 00135 sensor_msgs::Image image; 00136 if(detector->getImage(*msg, image)) 00137 { 00138 image.header.stamp = msg->header.stamp; 00139 image_pub->publish(image); 00140 } 00141 else 00142 ROS_ERROR("Error trying to generate ROS image"); 00143 } 00144 00145 int main(int argc, char** argv) 00146 { 00147 ros::init(argc, argv, "laser_cb_detector"); 00148 00149 ros::NodeHandle n; 00150 00151 // Set up the LaserCbDetector 00152 laser_cb_detector::ConfigGoal config = getParamConfig(n); 00153 LaserCbDetector detector; 00154 detector.configure(config); 00155 00156 // Output 00157 ros::Publisher pub = n.advertise<calibration_msgs::CalibrationPattern>("laser_checkerboard", 1); 00158 ros::Publisher image_pub = n.advertise<sensor_msgs::Image>("image", 1); 00159 00160 // Input 00161 boost::function<void (const calibration_msgs::DenseLaserSnapshotConstPtr&)> cb 00162 = boost::bind(&snapshotCallback, &pub, &image_pub, &detector, _1); 00163 00164 ros::Subscriber sub = n.subscribe(std::string("snapshot"), 1, cb); 00165 00166 ros::spin(); 00167 }