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
3 changes: 0 additions & 3 deletions .gitmodules

This file was deleted.

4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ mkdir -p ldlidar_ros2_ws/src

cd ldlidar_ros2_ws/src

git clone https://github.com/ldrobotSensorTeam/ldlidar_ros2.git

git submodule update --init --recursive
git clone https://github.com/maxryan4/ldlidar_ros2.git
```
## step 1: system setup
- Connect the LiDAR to your system motherboard via an onboard serial port or usB-to-serial module (for example, CP2102 module).
Expand Down
1 change: 0 additions & 1 deletion sdk
Submodule sdk deleted from 6148cd
3 changes: 3 additions & 0 deletions sdk/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.json
build/**
sample/windows/build/**
47 changes: 47 additions & 0 deletions sdk/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# sub project
message(STATUS "operation system is ${CMAKE_SYSTEM}")

if(CMAKE_SYSTEM_NAME MATCHES "Linux")
message(STATUS "current platform: Linux ")

set(LDLIDAR_DRIVER_SOURCE_LINUX
${CMAKE_CURRENT_SOURCE_DIR}/src/ldlidar_driver.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/ldlidar_driver_linux.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/ldlidar_dataprocess.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/ldlidar_protocol.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/log_module.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/network_socket_interface_linux.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/serial_interface_linux.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/sl_transform.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/slbf.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/tofbf.cpp
)

add_library(ldlidar_driver STATIC
${LDLIDAR_DRIVER_SOURCE_LINUX}
)

elseif(CMAKE_SYSTEM_NAME MATCHES "Windows")
message(STATUS "current platform: Windows")

set(LDLIDAR_DRIVER_SOURCE_WIN
${CMAKE_CURRENT_SOURCE_DIR}/src/ldlidar_driver.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/ldlidar_driver_win.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/ldlidar_dataprocess.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/ldlidar_protocol.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/log_module.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/serial_interface_win.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/sl_transform.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/slbf.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/tofbf.cpp
)

add_library(ldlidar_driver STATIC
${LDLIDAR_DRIVER_SOURCE_WIN}
)

else()
message(STATUS "other platform: ${CMAKE_SYSTEM_NAME}")
endif (CMAKE_SYSTEM_NAME MATCHES "Linux")


21 changes: 21 additions & 0 deletions sdk/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 SHENZHEN LDROBOT CO., LTD. All rights

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
32 changes: 32 additions & 0 deletions sdk/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# LDLiDAR SDK
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|

---
## Get SDK
- download package file or use git.
```bash
$ cd ~

$ mkdir ldlidar_ws

$ cd ldlidar_ws

$ git clone https://github.com/ldrobotSensorTeam/ldlidar_sdk.git
```

---
## Introduction to linux application example
- [EN](./sample/linux/README.md)
- [CN](./sample/linux/README_CN.md)

---

## Introduction to windows application example
- [EN](./sample/windows/README.md)
- [CN](./sample/windows/README_CN.md)
122 changes: 122 additions & 0 deletions sdk/include/ldlidar_driver/ldlidar_dataprocess.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
/**
* @file lipkg.h
* @author LDRobot (support@ldrobot.com)
* David Hu (hmd_hubei_cn@163.com)
* @brief LiDAR data protocol processing App
* This code is only applicable to LDROBOT LiDAR LD00 LD03 LD08 LD14
* products sold by Shenzhen LDROBOT Co., LTD
* @version 1.0
* @date 2023-03-12
*
* @copyright Copyright (c) 2017-2023 SHENZHEN LDROBOT CO., LTD. All rights
* reserved.
* Licensed under the MIT License (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License in the file LICENSE
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __LDLIDAR_DATAPROCESS_H__
#define __LDLIDAR_DATAPROCESS_H__

#include <string.h>

#include <chrono>
#include <mutex>
#include <functional>

#include "ldlidar_driver/slbf.h"
#include "ldlidar_driver/sl_transform.h"
#include "ldlidar_driver/tofbf.h"
#include "ldlidar_driver/ldlidar_protocol.h"

namespace ldlidar {

class LdLidarDataProcess {
public:
LdLidarDataProcess();

~LdLidarDataProcess();

void SetProductType(LDType typenumber);

void SetNoiseFilter(bool is_enable);

void RegisterTimestampGetFunctional(std::function<uint64_t(void)> timestamp_handle);

void CommReadCallback(const char *byte, size_t len);

/**
* @brief get lidar scan data
*/
bool GetLaserScanData(Points2D& out);

/**
* @brief get Lidar spin speed (Hz)
*/
double GetSpeed(void);

LidarStatus GetLidarStatus(void);

uint8_t GetLidarErrorCode(void);

bool GetLidarPowerOnCommStatus(void);

void ClearDataProcessStatus(void) {
is_frame_ready_ = false;
is_poweron_comm_normal_ = false;
lidarstatus_ = LidarStatus::NORMAL;
lidarerrorcode_ = LIDAR_NO_ERROR;
last_pkg_timestamp_ = 0;
lidar_scan_data_vec_.clear();
tmp_lidar_scan_data_vec_.clear();
}

private:
int lidar_measure_freq_;
LDType typenumber_;
LidarStatus lidarstatus_;
uint8_t lidarerrorcode_;
bool is_frame_ready_;
bool is_noise_filter_;
uint16_t timestamp_;
double speed_;
std::function<uint64_t(void)> get_timestamp_;
bool is_poweron_comm_normal_;
uint64_t last_pkg_timestamp_;

LdLidarProtocol* protocol_handle_;
Points2D lidar_scan_data_vec_;
Points2D tmp_lidar_scan_data_vec_;
std::mutex mutex_lock1_;
std::mutex mutex_lock2_;

void SetLidarStatus(LidarStatus status);

void SetLidarErrorCode(uint8_t errorcode);

bool AnalysisOne(uint8_t byte); // parse single packet

bool Parse(const uint8_t *data, long len);

bool AssemblePacket(); // combine stantard data into data frames and calibrate

bool IsFrameReady(void); // get Lidar data frame ready flag

void ResetFrameReady(void); // reset frame ready flag

void SetFrameReady(void); // set frame ready flag

void SetLaserScanData(Points2D& src);

Points2D GetLaserScanData(void);
};

} // namespace ldlidar

#endif // __LDLIDAR_DATAPROCESS_H__
/********************* (C) COPYRIGHT SHENZHEN LDROBOT CO., LTD *******END OF
* FILE ********/
104 changes: 104 additions & 0 deletions sdk/include/ldlidar_driver/ldlidar_datatype.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/**
* @file ldlidar_datatype.h
* @author LDRobot (support@ldrobot.com)
* @brief lidar point data structure
* This code is only applicable to LDROBOT products
* sold by Shenzhen LDROBOT Co., LTD
* @version 0.1
* @date 2021-11-09
*
* @copyright Copyright (c) 2017-2023 SHENZHEN LDROBOT CO., LTD. All rights
* reserved.
* Licensed under the MIT License (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License in the file LICENSE
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef _LDLIDAR_POINT_DATA_H_
#define _LDLIDAR_POINT_DATA_H_

#include <stdint.h>

#include <iostream>
#include <vector>
#include <string>

#define LDLiDAR_SDK_VERSION_NUMBER "3.3.1"

#define ANGLE_TO_RADIAN(angle) ((angle)*3141.59 / 180000)

// lidar error code definition
#define LIDAR_NO_ERROR 0x00
#define LIDAR_ERROR_BLOCKING 0x01 /* 雷达堵转 */
#define LIDAR_ERROR_OCCLUSION 0x02 /* 雷达遮挡 */
#define LIDAR_ERROR_BLOCKING_AND_OCCLUSION 0x03 /* 雷达堵转且遮挡 */
// end lidar error code definition

namespace ldlidar {

enum class LDType {
NO_VER,
LD_14,
LD_14P,
LD_06,
LD_19,
STL_06P,
STL_26,
STL_27L,
};

enum class LidarStatus {
NORMAL, /* 雷达正常,可获取点云数据 */
ERROR, /* 表明雷达出现异常错误,可获取雷达反馈的错误码了解具体错误 */
DATA_TIME_OUT, /* 雷达点云数据包发布超时 */
DATA_WAIT, /* 雷达点云数据包发布等待 */
STOP, /* 雷达停止转动、未启动Driver */
};

struct PointData {
// Polar coordinate representation
float angle; // Angle ranges from 0 to 359 degrees
uint16_t distance; // Distance is measured in millimeters
uint8_t intensity; // Intensity is 0 to 255
//! System time when first range was measured in nanoseconds
uint64_t stamp;
// Cartesian coordinate representation
double x;
double y;
PointData(float angle, uint16_t distance, uint8_t intensity, uint64_t stamp = 0, double x = 0, double y = 0) {
this->angle = angle;
this->distance = distance;
this->intensity = intensity;
this->stamp = stamp;
this->x = x;
this->y = y;
}
PointData() {}
};

typedef std::vector<PointData> Points2D;

struct LaserScan {
//! System time when first range was measured in nanoseconds
uint64_t stamp;
//! Array of laser point
Points2D points;

LaserScan &operator=(const LaserScan &data) {
this->stamp = data.stamp;
this->points = data.points;
return *this;
}
};


} // namespace ldlidar

#endif // _LDLIDAR_POINT_DATA_H_

/********************* (C) COPYRIGHT SHENZHEN LDROBOT CO., LTD *******END OF
* FILE ********/
Loading