Skip to content

Commit

Permalink
[update]版本号3.0.0,ldrobotsensor SDK3.0 framework import success.
Browse files Browse the repository at this point in the history
  • Loading branch information
ldrobotsensor committed Sep 28, 2022
1 parent 0a70181 commit 97d18e6
Show file tree
Hide file tree
Showing 19 changed files with 845 additions and 439 deletions.
64 changes: 47 additions & 17 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
cmake_minimum_required(VERSION 2.8.3)
project(ldlidar_sl)

set(VAL 1)
if(${VAL} EQUAL 1)
set(CMAKE_BUILD_TYPE "Release")
if(${CMAKE_BUILD_TYPE} MATCHES "Release")
#set(CMAKE_BUILD_TYPE "Release")
set(CMAKE_CXX_FLAGS_RELEASE "$ENV{CXXFLAGS} -std=c++11 -Wall")
#set(CMAKE_CXX_FLAGS_RELEASE "$ENV{CXXFLAGS} -std=c++11 -O3 -Wall")
message(STATUS "Mode: Release")
message(STATUS "optional:-std=c++11")
message(STATUS "optional:-std=c++11 -Wall")
else()
set(CMAKE_BUILD_TYPE "Debug")
#set(CMAKE_BUILD_TYPE "Debug")
set(CMAKE_CXX_FLAGS_DEBUG "$ENV{CXXFLAGS} -std=c++11 -Wall -Wextra -Wpedantic -g2 -ggdb")
#set(CMAKE_CXX_FLAGS_DEBUG "$ENV{CXXFLAGS} -std=c++11 -O2 -Wall -Wextra -Wpedantic -g2 -ggdb")
message(STATUS "Mode: Debug")
message(STATUS "optional:-std=c++11")
message(STATUS "optional:-std=c++11 -Wall -Wextra -Wpedantic -g2 -ggdb")
endif()

###########
Expand All @@ -23,22 +22,53 @@ endif()
## Specify additional locations of header files
## Your package locations should be listed before other locations
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/ldlidar_driver/include
${CMAKE_CURRENT_SOURCE_DIR}/ldlidar_driver/include/core/
${CMAKE_CURRENT_SOURCE_DIR}/ldlidar_driver/include/dataprocess/
${CMAKE_CURRENT_SOURCE_DIR}/ldlidar_driver/include/filter/
${CMAKE_CURRENT_SOURCE_DIR}/ldlidar_driver/include/logger/
${CMAKE_CURRENT_SOURCE_DIR}/ldlidar_driver/include/serialcom/
)

file(GLOB LDLIDAR_DRIVER_SRC ${CMAKE_CURRENT_SOURCE_DIR}/ldlidar_driver/src/*.cpp)
file(GLOB LDLIDAR_DRI_CORE ${CMAKE_CURRENT_SOURCE_DIR}/ldlidar_driver/src/core/*.cpp)
file(GLOB LDLIDAR_DRI_DATARPC ${CMAKE_CURRENT_SOURCE_DIR}/ldlidar_driver/src/dataprocess/*.cpp)
file(GLOB LDLIDAR_DRI_FILTER ${CMAKE_CURRENT_SOURCE_DIR}/ldlidar_driver/src/filter/*.cpp)
file(GLOB LDLIDAR_DRI_LOGGER ${CMAKE_CURRENT_SOURCE_DIR}/ldlidar_driver/src/logger/*.cpp)
file(GLOB LDLIDAR_DRI_SERIAL ${CMAKE_CURRENT_SOURCE_DIR}/ldlidar_driver/src/serialcom/*.cpp)

add_executable(${PROJECT_NAME} ${CMAKE_CURRENT_SOURCE_DIR}/src/linux_demo/demo.cpp ${LDLIDAR_DRIVER_SRC})
target_link_libraries(${PROJECT_NAME} pthread)
add_executable(${PROJECT_NAME}_node ${CMAKE_CURRENT_SOURCE_DIR}/src/linux_demo/demo.cpp)

add_library(ldlidar_driver_static STATIC
${LDLIDAR_DRI_CORE}
${LDLIDAR_DRI_DATARPC}
${LDLIDAR_DRI_FILTER}
${LDLIDAR_DRI_LOGGER}
${LDLIDAR_DRI_SERIAL}
)

add_library(ldlidar_driver_shared SHARED
${LDLIDAR_DRI_CORE}
${LDLIDAR_DRI_DATARPC}
${LDLIDAR_DRI_FILTER}
${LDLIDAR_DRI_LOGGER}
${LDLIDAR_DRI_SERIAL}
)

# rename library name
set_target_properties (ldlidar_driver_static PROPERTIES OUTPUT_NAME "ldlidar_driver")
set_target_properties (ldlidar_driver_shared PROPERTIES OUTPUT_NAME "ldlidar_driver")

## Declare a C++ library
# add_library(${PROJECT_NAME}
# src/${PROJECT_NAME}/ldlidar.cpp
# )
# binary file link to library
target_link_libraries(${PROJECT_NAME}_node ldlidar_driver_static pthread)

#############
## Testing ##
#############
###########
## Install ##
###########

INSTALL(TARGETS ldlidar_driver_static ldlidar_driver_shared
ARCHIVE DESTINATION lib/ldlidar_driver
LIBRARY DESTINATION share/ldlidar_driver
)

INSTALL(DIRECTORY ${PROJECT_SOURCE_DIR}/ldlidar_driver/include
DESTINATION include/ldlidar_driver
)
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ $ ./auto_build.sh

## 3. 运行
``` bash
$ ./build/ldlidar_sl <serial_number>
# 例如 ./build/ldlidar_sl /dev/ttyS0
$ ./build/ldlidar_sl_node <serial_number>
# 例如 ./build/ldlidar_sl_node /dev/ttyS0
```

# Instructions
Expand Down Expand Up @@ -80,6 +80,6 @@ $ ./auto_build.sh

## step 3: run
``` bash
$ ./build/ldlidar_sl <serial_number>
# 例如 ./build/ldlidar_sl /dev/ttyS0
$ ./build/ldlidar_sl_node <serial_number>
# example ./build/ldlidar_sl_node /dev/ttyS0
```
38 changes: 33 additions & 5 deletions auto_build.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,45 @@
#!/bin/bash
#Author: David Hu
#Date: 2022-05
#Date: 2022-09

# Exit on error
set -e
set -x

BUILD_MODE_DEBUG=1
BUILD_MODE_RELEASE=0
OP_YES=1

echo "Start cmake build"
read -p "Please select build mode [Debug(1)/Release(0)]:" BUILD_MODE
read -p "Is install lib and include files on the workspace, please input [yes(1)/no[0]]:" IS_INSTALL

if [ ! -e "./build" ];then
mkdir build
echo "create ./build/"
fi

echo "start cmake build"
cd ./build
cmake ..
make

if [ ${BUILD_MODE} == ${BUILD_MODE_DEBUG} ];then
cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=../install ..
elif [ ${BUILD_MODE} == ${BUILD_MODE_RELEASE} ];then
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../install ..
else
echo "build mode input error"
exit 0
fi

make

if [ ${IS_INSTALL} == ${OP_YES} ]
then
if [ ! -e "../install" ]
then
mkdir ../install
echo "create ../install/"
fi
make install
echo "build and install finished."
else
echo "build finished."
fi
14 changes: 14 additions & 0 deletions clean_build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash
#Author: David Hu
#Date: 2022-09
if [ -e "./build" ];then
rm -rf build/
echo "del ./build/"
fi

if [ -e "./install" ];then
rm -rf install/
echo "del ./install/"
fi

echo "del is ok....."
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@
#ifndef __LIPKG_H
#define __LIPKG_H

#include <sys/time.h>
#include <string.h>

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

#include "slbf.h"
#include "pointdata.h"
#include "transform.h"
#include "cmd_interface_linux.h"

namespace ldlidar {

Expand Down Expand Up @@ -57,51 +57,74 @@ typedef struct __attribute__((packed)) {
class LiPkg {
public:
LiPkg();

~LiPkg();

std::string GetSdkPackVersionNum(void);
void SetProductType(LDType typenumber);
/**
* @brief set lidar scan dir
* @param is_to_right_hand
* value is true, counterclockwise
* value is false, clockwise
*/
void SetLaserScanDir(bool is_to_right_hand);

void SetNoiseFilter(bool is_enable);

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

void CommReadCallBack(const char *byte, size_t len);
bool GetLaserScanData(Points2D& out); // get a frame lidar data
double GetSpeed(void); //get Lidar spin speed (Hz)

/**
* @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);

private:
const int kPointFrequence = 2300;
std::string sdk_pack_version_;
LDType ld_typenumber_;
LidarStatus ld_lidarstatus_;
bool to_right_hand_;
LDType typenumber_;
LidarStatus lidarstatus_;
uint8_t lidarerrorcode_;
bool is_frame_ready_;
bool is_noise_filter_;
uint16_t timestamp_; // time stamp of the packet
uint16_t timestamp_;
double speed_;
long error_times_;
LiDARFrameTypeDef pkg;
std::function<uint64_t(void)> get_timestamp_;
bool is_poweron_comm_normal_;
uint8_t poweron_datapkg_count_;

LiDARFrameTypeDef datapkg_;
Points2D lidar_frame_data_;
Points2D frame_tmp_;
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 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);
long GetErrorTimes(void); // the number of errors in parser process of lidar data frame
uint64_t GetTime(void); // systime ns

void AnalysisLidarIsBlocking(uint16_t lidar_speed_val);

void AnalysisLidarIsOcclusion(Points2D& lidar_data);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,18 @@
#include <algorithm>
#include <vector>

#include "pointdata.h"
#include "ldlidar_datatype.h"

namespace ldlidar {

class SlTransform {
private:
private:
bool to_right_hand_ = true;
double offset_x_;
double offset_y_;
LDType version_;

public:
public:
SlTransform(LDType version, bool to_right_hand = false);
Points2D Transform(const Points2D &data);
~SlTransform();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@

#include <algorithm>

#include "pointdata.h"
#include "ldlidar_datatype.h"

namespace ldlidar {

class Slbf {
private:
private:
const int kConfidenceHigh = 200;
const int kConfidenceMiddle = 150;
const int kConfidenceLow = 92;
Expand All @@ -45,7 +45,7 @@ class Slbf {
Slbf(const Slbf &) = delete;
Slbf &operator=(const Slbf &) = delete;

public:
public:
Slbf(int speed, bool strict_policy = true);
Points2D NearFilter(const Points2D &tmp) const;
void EnableStrictPolicy(bool enable);
Expand Down
49 changes: 0 additions & 49 deletions ldlidar_driver/include/ldlidar_node.h

This file was deleted.

Loading

0 comments on commit 97d18e6

Please sign in to comment.