21 #include <sys/socket.h> 22 #include <arpa/inet.h> 29 #include <tf/transform_listener.h> 55 ROS_INFO_STREAM(
"Opening UDP socket: port " << UDP_PORT_NUMBER);
67 const double diag_freq = 16*20000.0 / (12*32);
70 ROS_INFO(
"expected frequency: %.3f (Hz)", diag_freq);
80 "lslidar_packet", 100);
86 socket_id = socket(PF_INET, SOCK_DGRAM, 0);
93 memset(&my_addr, 0,
sizeof(my_addr));
94 my_addr.sin_family = AF_INET;
97 my_addr.sin_addr.s_addr = INADDR_ANY;
99 if (bind(
socket_id, (sockaddr *)&my_addr,
sizeof(sockaddr)) == -1) {
104 if (fcntl(
socket_id, F_SETFL, O_NONBLOCK|FASYNC) < 0) {
114 ROS_ERROR(
"Cannot load all required ROS parameters...");
119 ROS_ERROR(
"Cannot create all ROS IO...");
127 ROS_INFO(
"Initialised lslidar n301 without error");
132 lslidar_n301_msgs::LslidarN301PacketPtr& packet) {
136 struct pollfd fds[1];
138 fds[0].events = POLLIN;
139 static const int POLL_TIMEOUT = 2000;
141 sockaddr_in sender_address;
142 socklen_t sender_address_len =
sizeof(sender_address);
165 int retval = poll(fds, 1, POLL_TIMEOUT);
169 ROS_ERROR(
"poll() error: %s", strerror(errno));
177 if ((fds[0].revents & POLLERR)
178 || (fds[0].revents & POLLHUP)
179 || (fds[0].revents & POLLNVAL))
181 ROS_ERROR(
"poll() reports lslidar error");
184 }
while ((fds[0].revents & POLLIN) == 0);
189 (sockaddr*) &sender_address, &sender_address_len);
196 if (errno != EWOULDBLOCK)
222 packet->stamp =
ros::Time((time2 + time1) / 2.0);
230 lslidar_n301_msgs::LslidarN301PacketPtr packet(
231 new lslidar_n301_msgs::LslidarN301Packet());
250 if (rc < 0)
return false;
254 ROS_DEBUG(
"Publishing a full lslidar scan.");
int getPacket(lslidar_n301_msgs::LslidarN301PacketPtr &msg)
void publish(const boost::shared_ptr< M > &message) const
void setHardwareID(const std::string &hwid)
std::string device_ip_string
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
ros::Publisher packet_pub
static uint16_t PACKET_SIZE
diagnostic_updater::Updater diagnostics
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
#define ROS_INFO_STREAM(args)
boost::shared_ptr< diagnostic_updater::TopicDiagnostic > diag_topic
LslidarN301Driver(ros::NodeHandle &n, ros::NodeHandle &pn)