36 #include <std_msgs/UInt16.h> 37 #include <sensor_msgs/LaserScan.h> 38 #include <boost/asio.hpp> 44 : port_(port), baud_rate_(baud_rate), shutting_down_(false), serial_(io, port_)
46 serial_.set_option(boost::asio::serial_port_base::baud_rate(baud_rate_));
49 boost::asio::write(serial_, boost::asio::buffer(
"b", 1));
52 LFCDLaser::~LFCDLaser()
54 boost::asio::write(serial_, boost::asio::buffer(
"e", 1));
61 void LFCDLaser::poll(sensor_msgs::LaserScan::Ptr scan)
64 bool got_scan =
false;
65 boost::array<uint8_t, 42> raw_bytes;
66 uint8_t good_sets = 0;
67 uint32_t motor_speed = 0;
71 while (!shutting_down_ && !got_scan)
74 boost::asio::read(serial_, boost::asio::buffer(&raw_bytes[0], 1));
76 if(raw_bytes[0] == 0xFA)
80 boost::asio::read(serial_,boost::asio::buffer(&raw_bytes[1], 41));
82 if(raw_bytes[1] >= 0xA0 && raw_bytes[1] <= 0xDB)
84 int degree_count_num = 0;
85 index = (raw_bytes[1] - 0xA0) * 6;
88 motor_speed += (raw_bytes[3] << 8) + raw_bytes[2];
89 rpms=(raw_bytes[3]<<8|raw_bytes[2])/10;
92 for(uint16_t j = 4; j < 40; j = j + 6)
94 uint8_t byte0 = raw_bytes[j];
95 uint8_t byte1 = raw_bytes[j+1];
96 uint8_t byte2 = raw_bytes[j+2];
97 uint8_t byte3 = raw_bytes[j+3];
99 uint16_t intensity = (byte1 << 8) + byte0;
100 uint16_t range = (byte3 << 8) + byte2;
102 scan->ranges[359 - index - degree_count_num] = range / 1000.0;
103 scan->intensities[359 - index - degree_count_num] = intensity;
108 scan->time_increment = motor_speed/good_sets/1e8;
115 int main(
int argc,
char **argv)
117 ros::init(argc, argv,
"hlds_laser_segment_publisher");
123 std::string frame_id;
125 std_msgs::UInt16 rpms;
127 priv_nh.
param(
"port", port, std::string(
"/dev/ttyUSB0"));
128 priv_nh.
param(
"baud_rate", baud_rate, 230400);
129 priv_nh.
param(
"frame_id", frame_id, std::string(
"laser"));
131 boost::asio::io_service io;
138 sensor_msgs::LaserScan::Ptr scan(
new sensor_msgs::LaserScan);
140 scan->header.frame_id = frame_id;
141 scan->angle_increment = (2.0*M_PI/360.0);
142 scan->angle_min = 0.0;
143 scan->angle_max = 2.0*M_PI-scan->angle_increment;
144 scan->range_min = 0.12;
145 scan->range_max = 3.5;
146 scan->ranges.resize(360);
147 scan->intensities.resize(360);
153 rpms.data=laser.
rpms;
155 motor_pub.publish(rpms);
161 catch (boost::system::system_error ex)
163 ROS_ERROR(
"An exception was thrown: %s", ex.what());
void publish(const boost::shared_ptr< M > &message) const
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
uint16_t rpms
RPMS derived from the rpm bytes in an LFCD packet.
LFCDLaser(const std::string &port, uint32_t baud_rate, boost::asio::io_service &io)
Constructs a new LFCDLaser attached to the given serial port.
void close()
Close the driver down and prevent the polling loop from advancing.
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)
void poll(sensor_msgs::LaserScan::Ptr scan)
Poll the laser to get a new scan. Blocks until a complete new scan is received or close is called...
int main(int argc, char **argv)