Skip to content

Commit

Permalink
增加适配SDM18单点雷达
Browse files Browse the repository at this point in the history
  • Loading branch information
zhanyiaini committed Mar 25, 2024
1 parent ab43cd7 commit 847f645
Show file tree
Hide file tree
Showing 19 changed files with 1,520 additions and 56 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ project(ydlidar_sdk C CXX)
# version
set(YDLIDAR_SDK_VERSION_MAJOR 1)
set(YDLIDAR_SDK_VERSION_MINOR 2)
set(YDLIDAR_SDK_VERSION_PATCH 2)
set(YDLIDAR_SDK_VERSION_PATCH 3)
set(YDLIDAR_SDK_VERSION ${YDLIDAR_SDK_VERSION_MAJOR}.${YDLIDAR_SDK_VERSION_MINOR}.${YDLIDAR_SDK_VERSION_PATCH})

##########################################################
Expand Down
11 changes: 7 additions & 4 deletions core/common/DriverInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@
#include <core/base/v8stdint.h>
#include <core/base/thread.h>
#include <core/base/locker.h>
#include <core/base/datatype.h>
#include <map>
#include "ydlidar_protocol.h"
#include "ydlidar_def.h"
#include <core/base/datatype.h>


namespace ydlidar
{
namespace core
{
using namespace base;

namespace common
{

Expand Down Expand Up @@ -57,7 +59,7 @@ namespace ydlidar
* @par Constructor
*
*/
DriverInterface() : serial_port(""),
DriverInterface() : m_port(""),
m_baudrate(8000),
m_intensities(false),
m_intensityBit(10),
Expand Down Expand Up @@ -528,7 +530,8 @@ namespace ydlidar
YDLIDAR_TminiPro = 150, /**< Tmini Pro LiDAR Model. */
YDLIDAR_TminiPlus = 151, /**< Tmini Plus LiDAR Model. */

YDLIDAR_SDM15 = 160, // SDM15单点雷达
YDLIDAR_SDM15 = 160, //SDM15单点雷达
YDLIDAR_SDM18, //DTS单点雷达

YDLIDAR_T15 = 200, /**< T15 LiDAR Model. */

Expand Down Expand Up @@ -570,7 +573,7 @@ namespace ydlidar
Locker _error_lock;

/// LiDAR com port or IP Address
std::string serial_port;
std::string m_port;
/// baudrate or IP port
uint32_t m_baudrate;
/// LiDAR intensity
Expand Down
3 changes: 2 additions & 1 deletion core/common/ydlidar_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ typedef enum {
TYPE_TOF_NET = 2,/**< T15 LiDAR.*/
TYPE_GS = 3, //GS系列雷达(目前只有GS2)
TYPE_SCL = 4, //SCL雷达
TYPE_SDM = 5, //SDM单点雷达
TYPE_SDM = 5, //SDM15单点雷达
TYPE_DTS = 6, //SDM18单点雷达
TYPE_Tail,
} LidarTypeID;

Expand Down
7 changes: 7 additions & 0 deletions core/common/ydlidar_help.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ inline std::string lidarModelToString(int model)
break;
case DriverInterface::YDLIDAR_SDM15:
return "SDM15";
case DriverInterface::YDLIDAR_SDM18:
return "SDM18";
default:
name = "unkown(YD-" + std::to_string(model) + ")";
break;
Expand Down Expand Up @@ -591,6 +593,11 @@ inline bool isSDMLidar(int type)
return (type == TYPE_SDM);
}

inline bool isDTSLidar(int type)
{
return (type == TYPE_DTS);
}

/**
* @brief Whether it is Old Version protocol TOF LiDAR
* @param model lidar model
Expand Down
3 changes: 2 additions & 1 deletion core/common/ydlidar_protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@
//GS
#define Angle_Px 1.22
#define Angle_Py 5.315
#define Angle_PAngle 22.5
#define Angle_PAngle 22.5 //GS2
#define Angle_PAngle2 19.0 //GS5
#define GS_PACKHEADSIZE 8
#define GS_MAXPOINTSIZE 160 //GS数据包中最大点云数

Expand Down
234 changes: 234 additions & 0 deletions examples/dts_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,234 @@
/*********************************************************************
* Software License Agreement (BSD License)
*
* Copyright (c) 2018, EAIBOT, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of the Willow Garage nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*********************************************************************/
#include "CYdLidar.h"
#include <iostream>
#include <string>
#include <algorithm>
#include <cctype>
using namespace std;
using namespace ydlidar;

#if defined(_MSC_VER)
#pragma comment(lib, "ydlidar_sdk.lib")
#endif

/**
* @brief sdm test
* @param argc
* @param argv
* @return
* @par Flow chart
* Step1: instance CYdLidar.\n
* Step2: set paramters.\n
* Step3: initialize SDK and LiDAR.(::CYdLidar::initialize)\n
* Step4: Start the device scanning routine which runs on a separate thread and enable motor.(::CYdLidar::turnOn)\n
* Step5: Get the LiDAR Scan Data.(::CYdLidar::doProcessSimple)\n
* Step6: Stop the device scanning thread and disable motor.(::CYdLidar::turnOff)\n
* Step7: Uninitialize the SDK and Disconnect the LiDAR.(::CYdLidar::disconnecting)\n
*/

int main(int argc, char *argv[])
{
printf("__ ______ _ ___ ____ _ ____ \n");
printf("\\ \\ / / _ \\| | |_ _| _ \\ / \\ | _ \\ \n");
printf(" \\ V /| | | | | | || | | |/ _ \\ | |_) | \n");
printf(" | | | |_| | |___ | || |_| / ___ \\| _ < \n");
printf(" |_| |____/|_____|___|____/_/ \\_\\_| \\_\\ \n");
printf("\n");
fflush(stdout);

//初始化
ydlidar::os_init();
//初始化串口号
std::string port = "/dev/ttyCH341USB0";
// std::map<std::string, std::string> ports = ydlidar::lidarPortList();
// std::map<std::string, std::string>::iterator it;
// if (ports.size() == 1)
// {
// port = ports.begin()->second;
// }
// else
// {
// int id = 0;
// for (it = ports.begin(); it != ports.end(); it++)
// {
// printf("[%d] %s %s\n",
// id, it->first.c_str(), it->second.c_str());
// id++;
// }

// if (ports.empty())
// {
// printf("Not Lidar was detected. Please enter the lidar serial port:");
// std::cin >> port;
// }
// else
// {
// while (ydlidar::os_isOk())
// {
// printf("Please select the lidar port:");
// std::string number;
// std::cin >> number;

// if ((size_t)atoi(number.c_str()) >= ports.size())
// {
// continue;
// }

// it = ports.begin();
// id = atoi(number.c_str());

// while (id)
// {
// id--;
// it++;
// }

// port = it->second;
// break;
// }
// }
// }

int baudrate = 921600; //默认串口号

bool isSingleChannel = false;

CYdLidar laser;
//////////////////////string property/////////////////
/// lidar port
laser.setlidaropt(LidarPropSerialPort, port.c_str(), port.size());
/// ignore array
std::string ignore_array;
ignore_array.clear();
laser.setlidaropt(LidarPropIgnoreArray, ignore_array.c_str(),
ignore_array.size());
//////////////////////int property/////////////////
/// lidar baudrate
laser.setlidaropt(LidarPropSerialBaudrate, &baudrate, sizeof(int));
/// sdm lidar
int optval = TYPE_DTS;
laser.setlidaropt(LidarPropLidarType, &optval, sizeof(int));
/// device type
optval = YDLIDAR_TYPE_SERIAL;
laser.setlidaropt(LidarPropDeviceType, &optval, sizeof(int));
/// sample rate
optval = 4;
laser.setlidaropt(LidarPropSampleRate, &optval, sizeof(int));
/// abnormal count
optval = 3;
laser.setlidaropt(LidarPropAbnormalCheckCount, &optval, sizeof(int));
/// Intenstiy bit count
optval = 8;
laser.setlidaropt(LidarPropIntenstiyBit, &optval, sizeof(int));

//////////////////////bool property/////////////////
/// fixed angle resolution
bool b_optvalue = false;
laser.setlidaropt(LidarPropFixedResolution, &b_optvalue, sizeof(bool));
/// rotate 180
laser.setlidaropt(LidarPropReversion, &b_optvalue, sizeof(bool));
/// Counterclockwise
laser.setlidaropt(LidarPropInverted, &b_optvalue, sizeof(bool));
b_optvalue = true;
laser.setlidaropt(LidarPropAutoReconnect, &b_optvalue, sizeof(bool));
/// one-way communication
laser.setlidaropt(LidarPropSingleChannel, &isSingleChannel, sizeof(bool));
/// intensity
b_optvalue = true;
laser.setlidaropt(LidarPropIntenstiy, &b_optvalue, sizeof(bool));
/// Motor DTR
b_optvalue = true;
laser.setlidaropt(LidarPropSupportMotorDtrCtrl, &b_optvalue, sizeof(bool));
/// HeartBeat
b_optvalue = false;
laser.setlidaropt(LidarPropSupportHeartBeat, &b_optvalue, sizeof(bool));

//////////////////////float property/////////////////
/// unit: °
float f_optvalue = 180.0f;
laser.setlidaropt(LidarPropMaxAngle, &f_optvalue, sizeof(float));
f_optvalue = -180.0f;
laser.setlidaropt(LidarPropMinAngle, &f_optvalue, sizeof(float));
/// unit: m
f_optvalue = 20.f;
laser.setlidaropt(LidarPropMaxRange, &f_optvalue, sizeof(float));
f_optvalue = 0.025f;
laser.setlidaropt(LidarPropMinRange, &f_optvalue, sizeof(float));
/// unit: Hz
float frequency = 10.0;
laser.setlidaropt(LidarPropScanFrequency, &frequency, sizeof(float));

// laser.setEnableDebug(true); //打印串口原始数据

// 雷达初始化
bool ret = laser.initialize();
if (!ret)
{
fprintf(stderr, "[YDLIDAR] Fail to initialize %s\n", laser.DescribeError());
return -1;
}
// 启动扫描
ret = laser.turnOn();
if (!ret)
{
fprintf(stderr, "[YDLIDAR] Fail to turn on %s\n", laser.DescribeError());
return -1;
}

LaserScan scan;
while (ret && ydlidar::os_isOk())
{
if (laser.doProcessSimple(scan))
{
for (size_t i = 0; i < scan.points.size(); ++i)
{
const LaserPoint &p = scan.points.at(i);
printf("r %.01f p %.01f\n",
p.range * 1000.0f, p.intensity);
}
fflush(stdout);
}
else
{
fprintf(stderr, "[YDLIDAR] Failed to get lidar data\n");
fflush(stderr);
}
}

laser.turnOff();
laser.disconnecting();

return 0;
}
10 changes: 5 additions & 5 deletions examples/gs_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,11 +275,11 @@ int main(int argc, char *argv[])
// printf("module[%d] time[%lld]\n", scan.moduleNum, t - ts[scan.moduleNum]);
// ts[scan.moduleNum] = t;

// for (size_t i = 0; i < scan.points.size(); ++i)
// {
// const LaserPoint &p = scan.points.at(i);
// printf("%lu a %.01f r %.01f\n", i, p.angle * 180.0f / M_PI, p.range * 1000.0f);
// }
for (size_t i = 0; i < scan.points.size(); ++i)
{
const LaserPoint &p = scan.points.at(i);
printf("%d a %.01f r %.01f\n", int(i), p.angle * 180.0f / M_PI, p.range * 1000.0f);
}
// fflush(stdout);
}
else
Expand Down
12 changes: 6 additions & 6 deletions examples/tmini_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,12 +273,12 @@ int main(int argc, char *argv[]) {
(unsigned int)scan.points.size(),
scan.scanFreq,
1.0 / scan.config.scan_time);
// for (size_t i = 0; i < scan.points.size(); ++i)
// {
// const LaserPoint &p = scan.points.at(i);
// printf("%d a %.01f r %.04f i %.0f\n",
// i, p.angle * 180.0 / M_PI, p.range, p.intensity);
// }
for (size_t i = 0; i < scan.points.size(); ++i)
{
const LaserPoint &p = scan.points.at(i);
printf("%d a %.01f r %.04f i %.0f\n",
i, p.angle * 180.0 / M_PI, p.range, p.intensity);
}
fflush(stdout);
}
else
Expand Down
2 changes: 1 addition & 1 deletion examples/tof_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ int main(int argc, char *argv[]) {
int id = 0;//

for (it = ports.begin(); it != ports.end(); it++) {
printf("%d. %s\n", id, it->first.c_str());
printf("[%d] %s %s\n", id, it->first.c_str(), it->second.c_str());
id++;
}

Expand Down
3 changes: 3 additions & 0 deletions src/CYdLidar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "ETLidarDriver.h"
#include "GSLidarDriver.h"
#include "SDMLidarDriver.h"
#include "DTSLidarDriver.h"

using namespace std;
using namespace impl;
Expand Down Expand Up @@ -1752,6 +1753,8 @@ bool CYdLidar::checkCOMMs()
lidarPtr = new ydlidar::GSLidarDriver(m_DeviceType);
else if (isSDMLidar(m_LidarType)) //SDM
lidarPtr = new ydlidar::SDMLidarDriver();
else if (isDTSLidar(m_LidarType)) //SDM
lidarPtr = new ydlidar::DTSLidarDriver();
else //通用雷达
lidarPtr = new ydlidar::YDlidarDriver(m_DeviceType);

Expand Down
Loading

0 comments on commit 847f645

Please sign in to comment.