Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion ldlidar_driver/src/log_module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
#include <stdlib.h>
#endif

// Ubuntu 24.04 won't compile without this include:
#include <pthread.h>

//使用vswprintf会出现奔溃的情况如果,传入数据大于 VA_PARAMETER_MAX 就会出现崩溃
#define VA_PARAMETER_MAX (1024 * 2)

Expand Down Expand Up @@ -281,4 +284,4 @@ void LogPrint::LogPrintInf(const char* str) {
#endif
}

/********************* (C) COPYRIGHT SHENZHEN LDROBOT CO., LTD *******END OF FILE ********/
/********************* (C) COPYRIGHT SHENZHEN LDROBOT CO., LTD *******END OF FILE ********/
25 changes: 23 additions & 2 deletions src/demo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ int main(int argc, char **argv) {
int serial_baudrate = 0;
ldlidar::LDType lidartypename = ldlidar::LDType::NO_VER;

// Added to measure average beam count (points per revolution) at start:
int beam_count = 0;
int beam_count_i = 0;

// declare ros2 param
node->declare_parameter<std::string>("product_name", product_name);
node->declare_parameter<std::string>("laser_scan_topic_name", laser_scan_topic_name);
Expand Down Expand Up @@ -137,8 +141,25 @@ int main(int argc, char **argv) {
case ldlidar::LidarStatus::NORMAL: {
double lidar_scan_freq = 0;
lidar_drv->GetLidarScanFreq(lidar_scan_freq);
ToLaserscanMessagePublish(laser_scan_points, lidar_scan_freq, setting, node, lidar_pub_laserscan);
ToSensorPointCloudMessagePublish(laser_scan_points, setting, node, lidar_pub_pointcloud);
int n_points = static_cast<int>(laser_scan_points.size());
int n_samples = 20;
if(beam_count_i++ < n_samples) {
// Measure average beam count (points per revolution) at start:
if(beam_count_i > 1) {
// skip the first sample, it is messed up
beam_count += n_points;
}
//RCLCPP_INFO(node->get_logger(), "beam count: %d", n_points);
if(beam_count_i == n_samples) {
beam_count = beam_count / (n_samples - 1);
RCLCPP_INFO(node->get_logger(), "Average beam count: %d", beam_count);
}
} else if(n_points > beam_count - 5) {
// ensure the size of points vector is constant between LIDAR head revolutions:
laser_scan_points.resize(beam_count, laser_scan_points.back());
ToLaserscanMessagePublish(laser_scan_points, lidar_scan_freq, setting, node, lidar_pub_laserscan);
ToSensorPointCloudMessagePublish(laser_scan_points, setting, node, lidar_pub_pointcloud);
}
break;
}
case ldlidar::LidarStatus::DATA_TIME_OUT: {
Expand Down