Skip to content

Commit

Permalink
[update]版本号v3.0.3,更新SDK层(ldlidar_driver)。
Browse files Browse the repository at this point in the history
1. 修复32位系统下日志打印时间戳uint64_t数据格式不对问题
2. 更改获取激光雷达扫描频率接口命名
  • Loading branch information
ldrobotsensor committed Oct 26, 2022
1 parent d275bf4 commit 964afad
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 16 deletions.
2 changes: 1 addition & 1 deletion ldlidar_driver/include/core/ldlidar_driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class LDLidarDriver {
* @retval value is true, get lidar laser scan frequence is success;
* value is false, get lidar laser scan ferquence is fail.
*/
bool GetLidarSpinFreq(double& spin_hz);
bool GetLidarScanFreq(double& spin_hz);

/**
* @brief register get timestamp handle functional.
Expand Down
4 changes: 2 additions & 2 deletions ldlidar_driver/include/logger/log_module.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,12 @@ class LogModule {

std::string GetCurrentTime();

inline int64_t GetCurrentLocalTimeStamp() {
inline uint64_t GetCurrentLocalTimeStamp() {
//// 获取系统时间戳
std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> tp =
std::chrono::time_point_cast<std::chrono::nanoseconds>(std::chrono::system_clock::now());
auto tmp = std::chrono::duration_cast<std::chrono::nanoseconds>(tp.time_since_epoch());
return tmp.count();
return (uint64_t)tmp.count();
}

std::string GetFormatValue(std::string str_value);
Expand Down
4 changes: 2 additions & 2 deletions ldlidar_driver/src/core/ldlidar_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace ldlidar {
bool LDLidarDriver::is_ok_ = false;

LDLidarDriver::LDLidarDriver()
: sdk_version_number_("v3.0.2"),
: sdk_version_number_("v3.0.3"),
is_start_flag_(false),
register_get_timestamp_handle_(nullptr),
comm_pkg_(new LiPkg()),
Expand Down Expand Up @@ -286,7 +286,7 @@ LidarStatus LDLidarDriver::GetLaserScanData(LaserScan& dst, int64_t timeout) {
}
}

bool LDLidarDriver::GetLidarSpinFreq(double& spin_hz) {
bool LDLidarDriver::GetLidarScanFreq(double& spin_hz) {
if (!is_start_flag_) {
return false;
}
Expand Down
24 changes: 20 additions & 4 deletions ldlidar_driver/src/logger/log_module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,16 @@ void LogModule::LogPrintInf(const char* format,...) {
case DEBUG_LEVEL: {
//时间戳 uint is seconds
char s_stamp[100] = {0};
int64_t timestamp = GetCurrentLocalTimeStamp();
snprintf(s_stamp, 100, "[%ld.%ld]", (timestamp/1000000000), (timestamp%1000000000));
uint64_t timestamp = GetCurrentLocalTimeStamp();
#ifdef __LP64__
snprintf(s_stamp, 100, "[%lu.%lu]", (timestamp/1000000000), (timestamp%1000000000));
#else
#ifdef _WIN64
snprintf(s_stamp, 100, "[%lu.%lu]", (timestamp/1000000000), (timestamp%1000000000));
#else
snprintf(s_stamp, 100, "[%llu.%llu]", (timestamp/1000000000), (timestamp%1000000000));
#endif
#endif
str_temp.append(s_stamp);
}
break;
Expand Down Expand Up @@ -132,8 +140,16 @@ void LogModule::LogPrintNoLocationInf(const char* format,...) {

//时间戳 uint is seconds
char s_stamp[100] = {0};
int64_t timestamp = GetCurrentLocalTimeStamp();
snprintf(s_stamp, 100, "[%ld.%ld]", (timestamp/1000000000), (timestamp%1000000000));
uint64_t timestamp = GetCurrentLocalTimeStamp();
#ifdef __LP64__
snprintf(s_stamp, 100, "[%lu.%lu]", (timestamp/1000000000), (timestamp%1000000000));
#else
#ifdef _WIN64
snprintf(s_stamp, 100, "[%lu.%lu]", (timestamp/1000000000), (timestamp%1000000000));
#else
snprintf(s_stamp, 100, "[%llu.%llu]", (timestamp/1000000000), (timestamp%1000000000));
#endif
#endif
str_temp.append(s_stamp);

va_list ptr;
Expand Down
11 changes: 4 additions & 7 deletions src/publish_node/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ int main(int argc, char **argv) {
ldlidarnode->EnableFilterAlgorithnmProcess(true);

if (ldlidarnode->Start(type_name, port_name, serial_port_baudrate, ldlidar::COMM_SERIAL_MODE)) {
ROS_INFO("ldldiar node start is success");
ROS_INFO("ldlidar node start is success");
} else {
ROS_ERROR("ldlidar node start is fail");
exit(EXIT_FAILURE);
Expand All @@ -94,18 +94,15 @@ int main(int argc, char **argv) {

ros::Rate r(10); //10hz
ldlidar::Points2D laser_scan_points;
double lidar_spin_freq;
double lidar_scan_freq;
ROS_INFO("Publish topic message:ldlidar scan data .");

while (ros::ok()) {

switch (ldlidarnode->GetLaserScanData(laser_scan_points, 1500)){
case ldlidar::LidarStatus::NORMAL:
ldlidarnode->GetLidarSpinFreq(lidar_spin_freq);
ToLaserscanMessagePublish(laser_scan_points, lidar_spin_freq, setting, lidar_pub);
break;
case ldlidar::LidarStatus::ERROR:
ROS_ERROR("ldlidar driver error.");
ldlidarnode->GetLidarScanFreq(lidar_scan_freq);
ToLaserscanMessagePublish(laser_scan_points, lidar_scan_freq, setting, lidar_pub);
break;
case ldlidar::LidarStatus::DATA_TIME_OUT:
ROS_ERROR("get ldlidar data is time out, please check your lidar device.");
Expand Down

0 comments on commit 964afad

Please sign in to comment.