38 #include "sensor_msgs/LaserScan.h" 45 uint32_t n_range_values, uint32_t *intensity_values,
46 uint32_t n_intensity_values,
double scale,
ros::Time start,
47 double scan_time,
bool inverted,
float angle_min,
48 float angle_max, std::string frame_id)
50 static int scan_count = 0;
51 sensor_msgs::LaserScan scan_msg;
52 scan_msg.header.frame_id = frame_id;
55 scan_msg.angle_min = angle_max;
56 scan_msg.angle_max = angle_min;
58 scan_msg.angle_min = angle_min;
59 scan_msg.angle_max = angle_max;
61 scan_msg.angle_increment = (scan_msg.angle_max - scan_msg.angle_min) / (
double)(n_range_values-1);
62 scan_msg.scan_time = scan_time;
63 scan_msg.time_increment = scan_time / (2*M_PI) * scan_msg.angle_increment;
64 scan_msg.range_min = 0;
66 scan_msg.range_max = 81;
68 else if (scale == 0.001) {
69 scan_msg.range_max = 8.1;
71 scan_msg.ranges.resize(n_range_values);
72 scan_msg.header.stamp = start;
73 for (
size_t i = 0; i < n_range_values; i++) {
75 switch (range_values[i])
79 scan_msg.ranges[i] = numeric_limits<float>::quiet_NaN();
82 scan_msg.ranges[i] = numeric_limits<float>::quiet_NaN();
85 scan_msg.ranges[i] = numeric_limits<float>::quiet_NaN();
88 scan_msg.ranges[i] = numeric_limits<float>::quiet_NaN();
91 scan_msg.ranges[i] = numeric_limits<float>::quiet_NaN();
94 scan_msg.ranges[i] = numeric_limits<float>::infinity();
136 scan_msg.ranges[i] = (float)range_values[i] * (
float)scale;
139 scan_msg.intensities.resize(n_intensity_values);
140 for (
size_t i = 0; i < n_intensity_values; i++) {
141 scan_msg.intensities[i] = (float)intensity_values[i];
150 if (units.compare(
"mm") == 0)
152 else if (units.compare(
"cm") == 0)
159 int main(
int argc,
char **argv)
170 std::string measuring_units;
171 std::string frame_id;
172 double scan_time = 0;
173 double angle_increment = 0;
174 float angle_min = 0.0;
175 float angle_max = 0.0;
179 nh_ns.
param<
double>(
"desired_frequency", desired_freq, 75.0);
181 nh_ns.
param<
double>(
"min_frequency", min_freq, desired_freq);
183 nh_ns.
param<
double>(
"max_frequency", max_freq, desired_freq);
184 double freq_tolerance;
185 nh_ns.
param<
double>(
"frequency_tolerance", freq_tolerance, 0.3);
187 nh_ns.
param<
int>(
"window_size", window_size, 30);
189 nh_ns.
param<
double>(
"min_acceptable_delay", min_delay, 0.0);
191 nh_ns.
param<
double>(
"max_acceptable_delay", max_delay, 0.2);
192 std::string hardware_id;
193 nh_ns.
param<std::string>(
"hardware_id", hardware_id,
"SICK LMS");
194 double time_offset_sec;
195 nh_ns.
param<
double>(
"time_offset", time_offset_sec, 0.0);
205 nh_ns.
param(
"port", port,
string(
"/dev/lms200"));
206 nh_ns.
param(
"baud", baud, 38400);
207 nh_ns.
param(
"connect_delay", delay, 0);
208 nh_ns.
param(
"inverted", inverted,
false);
209 nh_ns.
param(
"angle", angle, 0);
210 nh_ns.
param(
"resolution", resolution, 0.0);
211 nh_ns.
param(
"units", measuring_units,
string());
212 nh_ns.
param<std::string>(
"frame_id", frame_id,
"laser");
218 ROS_ERROR(
"The use_rep_117 parameter has not been specified and is now ignored. This parameter was removed in Hydromedusa. Please see: http://ros.org/wiki/rep_117/migration");
224 ROS_ERROR(
"Baud rate must be in {9600, 19200, 38400, 500000}");
229 uint32_t n_range_values = 0;
230 uint32_t n_intensity_values = 0;
234 uint32_t partial_scan_index;
238 uint32_t on_delay = 0;
252 if ((angle && actual_angle != angle) || (resolution && actual_resolution != resolution)) {
253 ROS_INFO(
"Setting variant to (%i, %f)", angle, resolution);
257 ROS_INFO(
"Variant setup not requested or identical to actual (%i, %f)", actual_angle,
259 angle = actual_angle;
260 resolution = actual_resolution;
265 if (angle != actual_angle) {
266 ROS_WARN(
"Unable to set scan angle. Using %i instead of %i.", actual_angle, angle);
267 angle = actual_angle;
269 if (resolution != actual_resolution) {
270 ROS_WARN(
"Unable to set resolution. Using %e instead of %e.", actual_resolution, resolution);
271 resolution = actual_resolution;
278 ROS_INFO(
"Setting measuring units to '%s'", measuring_units.c_str());
282 ROS_INFO(
"Measuring units setup not requested or identical to actual ('%s')",
288 ROS_WARN(
"Unable to set measuring units. Using '%s' instead of '%s'.",
309 scan_time = 1.0 / 75;
316 scan_time = 4.0 / 75;
320 scan_time = 2.0 / 75;
324 scan_time = 1.0 / 75;
331 ROS_WARN(
"You are using an angle smaller than 180 degrees and a " 332 "scan resolution less than 1 degree per scan. Thus, " 333 "you are in inteleaved mode and the returns will not " 334 "arrive sequentially how you read them. So, the " 335 "time_increment field will be misleading. If you need to " 336 "know when the measurement was made at a time resolution " 337 "better than the scan_time, use the whole 180 degree " 348 angle_offset = (180.0-angle)/2;
352 ROS_ERROR(
"Initialize failed! are you using the correct device path?");
362 sick_lms.
GetSickScan(range_values, intensity_values,
363 n_range_values, n_intensity_values);
367 else if (angle != 180) {
371 sick_lms.
GetSickScan(range_values, n_range_values);
372 angle_min = (-90.0 + angle_offset) * M_PI / 180.0;
373 angle_max = (90.0 - angle_offset) * M_PI / 180.0;
382 double partialScanOffset = 0.25 * partial_scan_index;
383 angle_min = (-90.0 + angle_offset + partialScanOffset) * M_PI / 180.0;
384 angle_max = (90.0 - angle_offset - fmod(1.0 - partialScanOffset, 1.0))
394 publish_scan(&scan_pub, range_values, n_range_values, intensity_values,
395 n_intensity_values, scale, start, scan_time, inverted,
396 angle_min, angle_max, frame_id);
void setHardwareID(const std::string &hwid)
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
virtual void publish(const boost::shared_ptr< T > &message)
int main(int argc, char **argv)
void publish_scan(diagnostic_updater::DiagnosedPublisher< sensor_msgs::LaserScan > *pub, uint32_t *range_values, uint32_t n_range_values, uint32_t *intensity_values, uint32_t n_intensity_values, double scale, ros::Time start, double scan_time, bool inverted, float angle_min, float angle_max, std::string frame_id)
bool searchParam(const std::string &key, std::string &result) const
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
SickLMS2xx::sick_lms_2xx_measuring_units_t StringToLmsMeasuringUnits(string units)
ROSCPP_DECL void spinOnce()