Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LdLidar SDK fixes #2

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
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
36 changes: 30 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,35 @@
# LDLiDAR SDK
# LDLiDAR SDK - Fixed

## Fixes by MrKussen including:

- Deleted non-working code
- Added missing functions
- Fixing includes
- Added one missing header guard instead of pragma once, to make the code uniform.
- Added platform-dependant defines to decrease confusion and making sure that only code for the right platform will be compiled and run.
- The linux code was mostly fine, most changes were either in the windows code or the logging module

## How to use (mostly for beginners):

You can use this SDK by just adding the cpp files and the headers to your projects.

When you compile, there might be errors if you have UNICODE or _UNICODE defined, so avoid defining those if you can, or you will have to change between wide and thin characters in the source code.

Make sure that you compile the .cpp files here as well as your program files.

(For example, compilation with g++ can be done by placing your program files in /src/ and running g++ ./src/*.cpp -I./include/)

---

## Supported products

This SDK is only applicable to the LiDAR products sold by Shenzhen LDROBOT Co., LTD.
| product models | range types |
| ---- | ---- |
| LDROBOT LiDAR LD06 | 2D DTOF |
| LDROBOT LiDAR LD19 | 2D DTOF |
| LDROBOT LiDAR LD14 | 2D Triangle|
| LDROBOT LiDAR LD14P | 2D Triangle|
| ---- | ---- |
| LDROBOT LiDAR LD06 | 2D DTOF |
| LDROBOT LiDAR LD19 | 2D DTOF |
| LDROBOT LiDAR LD14 | 2D Triangle |
| LDROBOT LiDAR LD14P | 2D Triangle |

---
## Get SDK
Expand Down
2 changes: 2 additions & 0 deletions include/ldlidar_driver/ldlidar_driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

namespace ldlidar {

uint64_t GetSystemTimeStamp(void);

class LDLidarDriver {
public:
LDLidarDriver();
Expand Down
3 changes: 3 additions & 0 deletions include/ldlidar_driver/ldlidar_driver_linux.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#ifndef __LDLIDAR_DRIVER_SDK_LINUX_INTERFACE_H__
#define __LDLIDAR_DRIVER_SDK_LINUX_INTERFACE_H__

#ifdef __linux__

#include "ldlidar_driver/ldlidar_driver.h"
#include "ldlidar_driver/ldlidar_dataprocess.h"
#include "ldlidar_driver/serial_interface_linux.h"
Expand Down Expand Up @@ -158,6 +160,7 @@ class LDLidarDriverLinuxInterface : public LDLidarDriver {

} // namespace ldlidar

#endif //__linux__
#endif // __LDLIDAR_DRIVER_NODE_H__
/********************* (C) COPYRIGHT SHENZHEN LDROBOT CO., LTD *******END OF
* FILE ********/
5 changes: 4 additions & 1 deletion include/ldlidar_driver/ldlidar_driver_win.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#ifndef __LDLIDAR_DRIVER_SDK_WIN_INTERFACE_H__
#define __LDLIDAR_DRIVER_SDK_WIN_INTERFACE_H__

#ifdef WIN32

#include "ldlidar_driver/ldlidar_driver.h"
#include "ldlidar_driver/ldlidar_dataprocess.h"
#include "ldlidar_driver/log_module.h"
Expand Down Expand Up @@ -72,7 +74,7 @@ class LDLidarDriverWinInterface : public LDLidarDriver {
bool WaitLidarComm(int64_t timeout = 1000) override;

/**
* @brief get lidar laser scan point cloud data
* @brief get lidar laser scan point cloud data | NOTE THAT THIS DOES NOT RETURN X AND Y, ONLY ANGLE AND DISTANCE
* @param [output]
* *@param dst: type is ldlidar::Point2D, value is laser scan point cloud data
* @param [in]
Expand Down Expand Up @@ -147,6 +149,7 @@ class LDLidarDriverWinInterface : public LDLidarDriver {

} // namespace ldlidar

#endif //WIN32
#endif // __LDLIDAR_DRIVER_NODE_H__
/********************* (C) COPYRIGHT SHENZHEN LDROBOT CO., LTD *******END OF
* FILE ********/
4 changes: 2 additions & 2 deletions include/ldlidar_driver/log_module.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ class LogModule {

ILogRealization* p_realization_;
public:
static LogModule* GetInstance( __in const char* filename, __in const char* funcname,__in int lineno, LogLevel level, ILogRealization* plog = NULL);
// static LogModule* GetInstance( __in const char* filename, __in const char* funcname,__in int lineno, LogLevel level, ILogRealization* plog = NULL);
static LogModule* GetInstance(LogLevel level, ILogRealization* plog = NULL);
static LogModule* GetInstancePrintOriginData(LogLevel level, ILogRealization* plog = NULL);

Expand Down Expand Up @@ -200,7 +200,7 @@ class LogModule {
};

#ifdef ENABLE_LOG_DIS_OUTPUT
#define LOG(level,format,...) LogModule::GetInstance(__FILE__, __FUNCTION__, __LINE__,level)->LogPrintInf(format,__VA_ARGS__);
#define LOG(level,format,...) LogModule::GetInstance(level)->LogPrintInf(format,__VA_ARGS__);
#define LOG_DEBUG(format,...) LOG(LogModule::DEBUG_LEVEL,format,__VA_ARGS__)
#define LOG_INFO(format,...) LOG(LogModule::INFO_LEVEL,format,__VA_ARGS__)
#define LOG_WARN(format,...) LOG(LogModule::WARNING_LEVEL,format,__VA_ARGS__)
Expand Down
4 changes: 4 additions & 0 deletions include/ldlidar_driver/network_socket_interface_linux.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#ifndef __SOCKET_INTERFACE_LINUX_H__
#define __SOCKET_INTERFACE_LINUX_H__

#ifdef __linux__

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Expand Down Expand Up @@ -120,6 +122,8 @@ class TCPSocketInterfaceLinux {
};

} // namespace ldlidar

#endif // __linux__
#endif // __SOCKET_INTERFACE_LINUX_H__
/********************* (C) COPYRIGHT SHENZHEN LDROBOT CO., LTD *******END OF
* FILE ********/
5 changes: 4 additions & 1 deletion include/ldlidar_driver/serial_interface_linux.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#ifndef __LINUX_SERIAL_PORT_H__
#define __LINUX_SERIAL_PORT_H__

#ifdef __linux__

#include <inttypes.h>
#include <errno.h>
#include <fcntl.h>
Expand Down Expand Up @@ -75,7 +77,8 @@ class SerialInterfaceLinux {

} // namespace ldlidar

#endif //__LINUX_SERIAL_PORT_H__
#endif //__linux__
#endif //__LINUX_SERIAL_PORT_H__

/********************* (C) COPYRIGHT SHENZHEN LDROBOT CO., LTD *******END OF
* FILE ********/
15 changes: 11 additions & 4 deletions include/ldlidar_driver/serial_interface_win.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,18 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __WINDOWS_SERIAL_PORT_H__
#define __WINDOWS_SERIAL_PORT_H__

#ifdef WIN32

#pragma once
#include <Windows.h>

#include <atomic>
#include <string>
#include <thread>
#include <vector>
#include <functional>

struct PortInfo {
std::string name;
Expand Down Expand Up @@ -77,6 +81,10 @@ struct PortParams {
};

class SerialInterfaceWin {
private:
std::function<void(std::string)> commErrorHandle;
std::function<void(const char *, size_t length)> readCallback;

public:
SerialInterfaceWin();
~SerialInterfaceWin();
Expand Down Expand Up @@ -115,10 +123,9 @@ class SerialInterfaceWin {
OVERLAPPED mOverlappedRecv;
std::atomic<bool> mRxThreadRunFlag;

std::function<void(std::string)> commErrorHandle;
std::function<void(const char *, size_t length)> readCallback;

PortParams portParams;
};

#endif //WIN32
#endif //__WINDOWS_SERIAL_PORT_H__
/********************* (C) COPYRIGHT LD Robot *******END OF FILE ********/
7 changes: 7 additions & 0 deletions src/ldlidar_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@

namespace ldlidar {

uint64_t GetSystemTimeStamp(void) {
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 ((uint64_t)tmp.count());
}

bool LDLidarDriver::is_ok_ = false;

LDLidarDriver::LDLidarDriver() :
Expand Down
6 changes: 6 additions & 0 deletions src/ldlidar_driver_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifdef __linux__

#include "ldlidar_driver/ldlidar_driver_linux.h"

namespace ldlidar {
Expand All @@ -28,6 +31,7 @@ LDLidarDriverLinuxInterface::LDLidarDriverLinuxInterface() : comm_pkg_(new LdLi
comm_udp_network_(new UDPSocketInterfaceLinux()){

last_pubdata_times_ = std::chrono::steady_clock::now();
RegisterGetTimestampFunctional(std::bind(GetSystemTimeStamp));
}

LDLidarDriverLinuxInterface::~LDLidarDriverLinuxInterface() {
Expand Down Expand Up @@ -337,5 +341,7 @@ bool LDLidarDriverLinuxInterface::Stop(void) {
}

} // namespace ldlidar

#endif //__linux__
/********************* (C) COPYRIGHT SHENZHEN LDROBOT CO., LTD *******END OF
* FILE ********/
6 changes: 6 additions & 0 deletions src/ldlidar_driver_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifdef WIN32

#include "ldlidar_driver/ldlidar_driver_win.h"

namespace ldlidar {
Expand All @@ -27,6 +30,7 @@ LDLidarDriverWinInterface::LDLidarDriverWinInterface() :
comm_port_handle_(new SerialInterfaceWin()) {

last_pubdata_times_ = std::chrono::steady_clock::now();
RegisterGetTimestampFunctional(std::bind(GetSystemTimeStamp));
}

LDLidarDriverWinInterface::~LDLidarDriverWinInterface() {
Expand Down Expand Up @@ -226,5 +230,7 @@ bool LDLidarDriverWinInterface::Stop(void) {
}

} // namespace ldlidar

#endif //WIN32
/********************* (C) COPYRIGHT SHENZHEN LDROBOT CO., LTD *******END OF
* FILE ********/
17 changes: 0 additions & 17 deletions src/log_module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,6 @@

LogModule* LogModule::s_plog_module_ = NULL;


LogModule* LogModule::GetInstance(__in const char* filename, __in const char* funcname, __in int lineno,LogLevel level,ILogRealization* plog) {
if (s_plog_module_ == NULL) {
s_plog_module_ = new LogModule();
}
s_plog_module_->logInfo_.str_filename = filename;
s_plog_module_->logInfo_.str_funcname = funcname;
s_plog_module_->logInfo_.n_linenumber = lineno;
s_plog_module_->logInfo_.loglevel = level;

if (plog != NULL) {
s_plog_module_->p_realization_->free();
s_plog_module_->p_realization_ = plog;
}
return s_plog_module_;
}

LogModule* LogModule::GetInstance(LogLevel level, ILogRealization* plog) {
if (s_plog_module_ == NULL) {
s_plog_module_ = new LogModule();
Expand Down
4 changes: 4 additions & 0 deletions src/network_socket_interface_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@
* limitations under the License.
*/

#ifdef __linux__

#include "ldlidar_driver/network_socket_interface_linux.h"
#include "ldlidar_driver/log_module.h"


#define MAX_RECV_BUF_LEN 4096

namespace ldlidar {
Expand Down Expand Up @@ -454,5 +457,6 @@ void TCPSocketInterfaceLinux::RecvThreadProc(void *param) {
}

} // namespace ldlidar
#endif //__linux__
/********************* (C) COPYRIGHT SHENZHEN LDROBOT CO., LTD *******END OF
* FILE ********/
3 changes: 2 additions & 1 deletion src/serial_interface_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "ldlidar_driver/serial_interface_linux.h"
#include "ldlidar_driver/log_module.h"

#ifdef __linux__

#define MAX_ACK_BUF_LEN 4096

Expand Down Expand Up @@ -179,6 +180,6 @@ void SerialInterfaceLinux::RxThreadProc(void *param) {
}

} // namespace ldlidar

#endif //__linux__
/********************* (C) COPYRIGHT SHENZHEN LDROBOT CO., LTD *******END OF
* FILE ********/
4 changes: 4 additions & 0 deletions src/serial_interface_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
* limitations under the License.
*/

#ifdef WIN32

#include "ldlidar_driver/serial_interface_win.h"
#include "ldlidar_driver/log_module.h"

Expand Down Expand Up @@ -323,4 +325,6 @@ void SerialInterfaceWin::rxThreadProc(SerialInterfaceWin *pClass) {

delete[] rxBuf;
}

#endif //WIN32
/********************* (C) COPYRIGHT LD Robot *******END OF FILE ********/