28 #include <boost/shared_ptr.hpp> 29 #include <boost/range/algorithm.hpp> 31 #include <sensor_msgs/LaserScan.h> 44 using boost::range::reverse;
45 using sensor_msgs::LaserScan;
50 const double EPS = 1e-3;
53 int main(
int argc,
char* argv[])
59 string host, frame_id, local_ip;
60 double start_angle, end_angle, expected_frequency, frequency_tolerance, timestamp_min_acceptable,
61 timestamp_max_acceptable, frequency, reconnect_timeout;
62 bool publish_intensities;
64 ros::param::param<std::string>(
"~host", host,
"192.168.1.1");
65 ros::param::param<std::string>(
"~local_ip", local_ip,
"0.0.0.0");
66 ros::param::param<std::string>(
"~frame_id", frame_id,
"laser");
69 ros::param::param<double>(
"~frequency", frequency, 12.856);
70 ros::param::param<double>(
"~expected_frequency", expected_frequency, frequency);
71 ros::param::param<double>(
"~frequency_tolerance", frequency_tolerance, 0.1);
72 ros::param::param<double>(
"~timestamp_min_acceptable", timestamp_min_acceptable, -1);
73 ros::param::param<double>(
"~timestamp_max_acceptable", timestamp_max_acceptable, -1);
74 ros::param::param<double>(
"~reconnect_timeout", reconnect_timeout, 2.0);
75 ros::param::param<bool>(
"~publish_intensities", publish_intensities,
false);
76 ros::param::param<bool>(
"~invert_scan", invert_scan,
false);
84 ROS_FATAL(
"Frequency exceeds the limit of 25hz.");
87 else if (frequency <= 0)
89 ROS_FATAL(
"Frequency should be positive");
93 if (fabs(frequency - expected_frequency) >
EPS)
95 ROS_WARN(
"Frequency parameter is not equal to expected frequency parameter.");
105 laserscan_pub, updater,
FrequencyStatusParam(&expected_frequency, &expected_frequency, frequency_tolerance),
110 boost::asio::io_service io_service;
113 OS32C os32c(socket, io_socket);
119 catch (std::runtime_error ex)
121 ROS_ERROR(
"Exception caught opening session: %s. Reconnecting in %.2f seconds ...", ex.what(), reconnect_timeout);
130 os32c.selectBeams(start_angle, end_angle);
132 catch (std::invalid_argument ex)
134 ROS_ERROR(
"Invalid arguments in sensor configuration: %s. Reconnecting in %.2f seconds ...", ex.what(),
140 sensor_msgs::LaserScan laserscan_msg;
141 os32c.fillLaserScanStaticConfig(&laserscan_msg);
142 laserscan_msg.header.frame_id = frame_id;
161 if (!publish_intensities)
163 laserscan_msg.intensities.clear();
168 laserscan_msg.header.seq++;
169 diagnosed_publisher.
publish(laserscan_msg);
174 catch (std::runtime_error ex)
178 catch (std::logic_error ex)
183 if (!laserscan_msg.header.stamp.isZero() &&
184 (
ros::Time::now() - laserscan_msg.header.stamp).toSec() > reconnect_timeout)
186 ROS_ERROR(
"No scan received for %.2f seconds, reconnecting ...", reconnect_timeout);
187 laserscan_msg.header.stamp =
ros::Time();
199 os32c.closeActiveConnection();
int main(int argc, char *argv[])
static const double ANGLE_MAX
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)
#define ROS_ERROR_STREAM_DELAYED_THROTTLE(rate, args)
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
REGISTER_ROSCONSOLE_BRIDGE
static const double ANGLE_MIN
static void convertToLaserScan(const RangeAndReflectanceMeasurement &rr, sensor_msgs::LaserScan *ls)
#define ROS_ERROR_STREAM(args)
ROSCPP_DECL void spinOnce()
vector< EIP_UINT > range_data