laser_cb_detector_node.cpp
Go to the documentation of this file.
1 /*********************************************************************
2 * Software License Agreement (BSD License)
3 *
4 * Copyright (c) 2009, Willow Garage, Inc.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
17 * * Neither the name of the Willow Garage nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 *********************************************************************/
34 
36 
37 #include <ros/console.h>
38 #include <ros/ros.h>
40 #include <sstream>
42 
43 using namespace laser_cb_detector;
44 using namespace std;
45 
46 
47 #define ROS_INFO_CONFIG(name) \
48 {\
49  ostringstream ss;\
50  ss << "[" << #name << "] -> " << config.name;\
51  ROS_INFO("%s", ss.str().c_str());\
52 }
53 
54 laser_cb_detector::ConfigGoal getParamConfig(ros::NodeHandle &n)
55 {
56  laser_cb_detector::ConfigGoal config;
57 
58  ros::NodeHandle pn("~");
59 
60  int num_x;
61  pn.param("num_x", num_x, 3);
62  config.num_x = (unsigned int) num_x;
63 
64  int num_y;
65  pn.param("num_y", num_y, 3);
66  config.num_y = (unsigned int) num_y;
67 
68  double spacing_x;
69  pn.param("spacing_x", spacing_x, 1.0);
70  config.spacing_x = spacing_x;
71 
72  double spacing_y;
73  pn.param("spacing_y", spacing_y, 1.0);
74  config.spacing_y = spacing_y;
75 
76  double width_scaling;
77  pn.param("width_scaling", width_scaling, 1.0);
78  config.width_scaling = width_scaling;
79 
80  double height_scaling;
81  pn.param("height_scaling", height_scaling, 1.0);
82  config.height_scaling = height_scaling;
83 
84  double min_intensity;
85  pn.param("min_intensity", min_intensity, 500.0);
86  config.min_intensity = min_intensity;
87 
88  double max_intensity;
89  pn.param("max_intensity", max_intensity, 5000.0);
90  config.max_intensity = max_intensity;
91 
92  int subpixel_window;
93  pn.param("subpixel_window", subpixel_window, 2);
94  config.subpixel_window = subpixel_window;
95 
96  pn.param("subpixel_zero_zone", config.subpixel_zero_zone, -1);
97 
98  int flip_horizontal;
99  pn.param("flip_horizontal", flip_horizontal, 0);
100  if (flip_horizontal)
101  config.flip_horizontal = 1;
102  else
103  config.flip_horizontal = 0;
104 
105  ROS_INFO_CONFIG(num_x);
106  ROS_INFO_CONFIG(num_y);
107  ROS_INFO_CONFIG(spacing_x);
108  ROS_INFO_CONFIG(spacing_y);
109  ROS_INFO_CONFIG(width_scaling);
110  ROS_INFO_CONFIG(height_scaling);
111  ROS_INFO_CONFIG(min_intensity);
112  ROS_INFO_CONFIG(max_intensity);
113  ROS_INFO_CONFIG(subpixel_window);
114  ROS_INFO_CONFIG(subpixel_zero_zone);
115  //ROS_INFO_CONFIG(reflect_model);
116  ROS_INFO("[flip_horizontal]->%u", config.flip_horizontal);
117 
118  return config;
119 }
120 
122  public:
123  LaserCbDetectorAction() : as_("cb_detector_config", false) {
124  // Set up the LaserCbDetector
125  laser_cb_detector::ConfigGoal config = getParamConfig(nh_);
126  detector_.configure(config);
127 
128  // Set up the action server for config
129  as_.registerGoalCallback( boost::bind(&LaserCbDetectorAction::goalCallback, this) );
130  as_.registerPreemptCallback( boost::bind(&LaserCbDetectorAction::preemptCallback, this) );
131 
132  // set up feature publisher
133  pub_ = nh_.advertise<calibration_msgs::CalibrationPattern>("laser_checkerboard", 1);
134  // set up image publisher
135  image_pub_ = nh_.advertise<sensor_msgs::Image>("image", 1);
136 
137  // subscribe to laser snapshotter
138  sub_ = nh_.subscribe("snapshot", 1, &LaserCbDetectorAction::snapshotCallback, this );
139 
140  // start the action server
141  as_.start();
142  }
143 
144  void goalCallback() {
145  boost::mutex::scoped_lock lock(run_mutex_);
146 
147  if(as_.isActive()) {
148  as_.setPreempted();
149  }
150 
151  laser_cb_detector::ConfigGoalConstPtr goal = as_.acceptNewGoal();
152 
153  bool success = detector_.configure(*goal);
154 
155  if( !success ) {
156  as_.setAborted();
157  }
158  }
159 
161  boost::mutex::scoped_lock lock(run_mutex_);
162  // nothing special to do on preempt
163  as_.setPreempted();
164  }
165 
166  void snapshotCallback(const calibration_msgs::DenseLaserSnapshotConstPtr& msg)
167  {
168  boost::mutex::scoped_lock lock(run_mutex_);
169 
170  bool detect_result;
171  calibration_msgs::CalibrationPattern result;
172  detect_result = detector_.detect(*msg, result);
173 
174  if (!detect_result)
175  ROS_ERROR("Error during checkerboard detection. (This error is worse than simply not seeing a checkerboard");
176  else
177  {
178  result.header.stamp = msg->header.stamp;
179  pub_.publish(result);
180  }
181 
182  sensor_msgs::Image image;
183  if(detector_.getImage(*msg, image))
184  {
185  image.header.stamp = msg->header.stamp;
186  image_pub_.publish(image);
187  }
188  else
189  ROS_ERROR("Error trying to generate ROS image");
190  }
191 
192  private:
193  boost::mutex run_mutex_;
200 };
201 
202 
203 int main(int argc, char** argv)
204 {
205  ros::init(argc, argv, "laser_cb_detector");
206  LaserCbDetectorAction detector_action;
207  ros::spin();
208  return 0;
209 }
LaserCbDetectorAction::as_
actionlib::SimpleActionServer< laser_cb_detector::ConfigAction > as_
Definition: laser_cb_detector_node.cpp:199
ros::Publisher
LaserCbDetectorAction::detector_
LaserCbDetector detector_
Definition: laser_cb_detector_node.cpp:198
ros::init
ROSCPP_DECL void init(const M_string &remappings, const std::string &name, uint32_t options=0)
ros.h
laser_cb_detector.h
simple_action_server.h
getParamConfig
laser_cb_detector::ConfigGoal getParamConfig(ros::NodeHandle &n)
Definition: laser_cb_detector_node.cpp:54
laser_cb_detector
Definition: cv_laser_bridge.h:43
LaserCbDetectorAction::nh_
ros::NodeHandle nh_
Definition: laser_cb_detector_node.cpp:194
LaserCbDetectorAction
Definition: laser_cb_detector_node.cpp:121
console.h
LaserCbDetectorAction::LaserCbDetectorAction
LaserCbDetectorAction()
Definition: laser_cb_detector_node.cpp:123
main
int main(int argc, char **argv)
Definition: laser_cb_detector_node.cpp:203
LaserCbDetectorAction::sub_
ros::Subscriber sub_
Definition: laser_cb_detector_node.cpp:197
std
actionlib::SimpleActionServer< laser_cb_detector::ConfigAction >
LaserCbDetectorAction::run_mutex_
boost::mutex run_mutex_
Definition: laser_cb_detector_node.cpp:193
LaserCbDetectorAction::snapshotCallback
void snapshotCallback(const calibration_msgs::DenseLaserSnapshotConstPtr &msg)
Definition: laser_cb_detector_node.cpp:166
ROS_ERROR
#define ROS_ERROR(...)
ros::NodeHandle::param
T param(const std::string &param_name, const T &default_val) const
LaserCbDetectorAction::goalCallback
void goalCallback()
Definition: laser_cb_detector_node.cpp:144
ROS_INFO_CONFIG
#define ROS_INFO_CONFIG(name)
Definition: laser_cb_detector_node.cpp:47
ros::spin
ROSCPP_DECL void spin()
LaserCbDetectorAction::image_pub_
ros::Publisher image_pub_
Definition: laser_cb_detector_node.cpp:196
ROS_INFO
#define ROS_INFO(...)
LaserCbDetectorAction::pub_
ros::Publisher pub_
Definition: laser_cb_detector_node.cpp:195
LaserCbDetectorAction::preemptCallback
void preemptCallback()
Definition: laser_cb_detector_node.cpp:160
laser_cb_detector::LaserCbDetector
Definition: laser_cb_detector.h:83
ros::NodeHandle
ros::Subscriber


laser_cb_detector
Author(s): Vijay Pradeep
autogenerated on Tue Mar 1 2022 23:58:55