Skip to content

Commit 6391d82

Browse files
committed
增加适配R3雷达
1 parent 49b65f3 commit 6391d82

7 files changed

+39
-13
lines changed

CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ project(ydlidar_sdk C CXX)
55
# version
66
set(YDLIDAR_SDK_VERSION_MAJOR 1)
77
set(YDLIDAR_SDK_VERSION_MINOR 2)
8-
set(YDLIDAR_SDK_VERSION_PATCH 5)
8+
set(YDLIDAR_SDK_VERSION_PATCH 6)
99
set(YDLIDAR_SDK_VERSION ${YDLIDAR_SDK_VERSION_MAJOR}.${YDLIDAR_SDK_VERSION_MINOR}.${YDLIDAR_SDK_VERSION_PATCH})
1010

1111
##########################################################

core/common/DriverInterface.h

+1
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,7 @@ namespace ydlidar
512512
YDLIDAR_G5 = 20, /**< G5 LiDAR Model. */
513513
YDLIDAR_G7 = 21, /**< G7 LiDAR Model. */
514514
YDLIDAR_SCL = 22, // SCL雷达
515+
YDLIDAR_R3 = 23, //R3雷达
515516

516517
YDLIDAR_GS2 = 51, // GS2雷达
517518
YDLIDAR_GS1 = 52, // GS1雷达

core/common/ydlidar_datatype.h

+1
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ typedef struct {
113113
float sampleRate = .0;
114114
// Array of lidar points
115115
std::vector<LaserPoint> points;
116+
int size = 0; //实际点数(固定分辨率时点数与实际点数不符)
116117
// Configuration of scan
117118
LaserConfig config;
118119
int moduleNum = 0;

core/common/ydlidar_help.h

+16-1
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,12 @@ inline std::string lidarModelToString(int model)
135135
case DriverInterface::YDLIDAR_G7:
136136
name = "G7";
137137
break;
138+
case DriverInterface::YDLIDAR_SCL:
139+
name = "SCL";
140+
break;
141+
case DriverInterface::YDLIDAR_R3:
142+
name = "R3";
143+
break;
138144
case DriverInterface::YDLIDAR_GS1:
139145
name = "GS1";
140146
break;
@@ -336,12 +342,21 @@ inline bool hasSampleRate(int model)
336342

337343
return ret;
338344
}
345+
346+
inline bool isR3Lidar(int model)
347+
{
348+
if (model == DriverInterface::YDLIDAR_R3)
349+
{
350+
return true;
351+
}
352+
return false;
353+
}
354+
339355
/*!
340356
* @brief Is there a zero offset angle
341357
* @param model lidar model
342358
* @return true if there are zero offset angle, otherwise false.
343359
*/
344-
345360
inline bool hasZeroAngle(int model) {
346361
bool ret = false;
347362

examples/tri_test.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -270,9 +270,9 @@ int main(int argc, char *argv[])
270270
laser.enableSunNoise(false);
271271

272272
//设置是否获取底板设备信息(默认仅尝试获取模组设备信息)
273-
laser.setBottomPriority(false);
273+
laser.setBottomPriority(true);
274274
//启用调试
275-
laser.setEnableDebug(true);
275+
laser.setEnableDebug(false);
276276

277277
uint32_t t = getms(); //时间
278278
int c = 0; //计数
@@ -334,9 +334,9 @@ int main(int argc, char *argv[])
334334
// for (size_t i = 0; i < scan.points.size(); ++i)
335335
// {
336336
// const LaserPoint &p = scan.points.at(i);
337-
// printf("%d d %f a %f\n", i, p.range, p.angle * 180.0 / M_PI);
337+
// printf("%d a:%.02f d:%.01f\n", i, p.angle * 180.0 / M_PI, p.range * 1000.0);
338338
// }
339-
fflush(stdout);
339+
// fflush(stdout);
340340
}
341341
else
342342
{

src/CYdLidar.cpp

+9-3
Original file line numberDiff line numberDiff line change
@@ -679,8 +679,8 @@ bool CYdLidar::doProcessSimple(LaserScan &outscan)
679679
{
680680
const node_info& node = global_nodes[i];
681681

682-
// printf("%lu a %.01f r %u\n",
683-
// i, float(node.angle) / 64.0f, node.dist);
682+
// printf("%lu a:%.01f d:%u\n",
683+
// i, float(node.angle) / 128.0f, node.dist);
684684

685685
if (isNetTOFLidar(m_LidarType))
686686
{
@@ -700,6 +700,10 @@ bool CYdLidar::doProcessSimple(LaserScan &outscan)
700700
{
701701
range = static_cast<float>(global_nodes[i].dist / 2000.f);
702702
}
703+
else if (isR3Lidar(lidar_model))
704+
{
705+
range = static_cast<float>(global_nodes[i].dist / 40000.f);
706+
}
703707
else
704708
{
705709
if (isTOFLidar(m_LidarType) ||
@@ -787,6 +791,8 @@ bool CYdLidar::doProcessSimple(LaserScan &outscan)
787791
}
788792
} //end for (int i = 0; i < count; i++)
789793

794+
outscan.size = outscan.points.size(); //保留原点云数
795+
790796
if (m_FixedResolution)
791797
{
792798
outscan.points.resize(all_node_count);
@@ -1408,10 +1414,10 @@ bool CYdLidar::getDeviceInfo()
14081414

14091415
frequencyOffset = 0.4;
14101416
lidar_model = di.model;
1417+
printf("Current Lidar Model Code %d\n", lidar_model);
14111418
bool intensity = hasIntensity(di.model);
14121419
defalutSampleRate = getDefaultSampleRate(di.model);
14131420
// printf("getDefaultSampleRate %d\n", defalutSampleRate.size());
1414-
14151421
intensity = m_Intensity;
14161422
std::string serial_number;
14171423
lidarPtr->setIntensities(intensity);

src/YDlidarDriver.cpp

+7-4
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,9 @@ result_t YDlidarDriver::waitDevicePackage(uint32_t timeout)
749749

750750
device_info di;
751751
getData(reinterpret_cast<uint8_t *>(&di), DEVICEINFOSIZE);
752-
model = di.model;
752+
//没有启用底板时才使用模组的雷达型号码
753+
if (!m_Bottom)
754+
model = di.model;
753755
m_HasDeviceInfo |= EPT_Module;
754756
m_ModuleDevInfo = di;
755757
printfDeviceInfo(di, EPT_Module);
@@ -1270,7 +1272,7 @@ void YDlidarDriver::parseNodeFromeBuffer(node_info *node)
12701272
package.nodes[nodeIndex].dist & 0xfffc;
12711273
(*node).is = package.nodes[nodeIndex].dist & 0x0003;
12721274

1273-
// printf("%d i %u\n", nodeIndex, (*node).qual);
1275+
// printf("%d d:%u\n", nodeIndex, (*node).dist);
12741276
// fflush(stdout);
12751277
}
12761278
else
@@ -1309,7 +1311,8 @@ void YDlidarDriver::parseNodeFromeBuffer(node_info *node)
13091311
// printf("SCL correct angle [%d]\n", correctAngle);
13101312
}
13111313
else if (isTriangleLidar(m_LidarType) &&
1312-
!isTminiLidar(model)) //去掉Tmini雷达的角度二级解析
1314+
!isTminiLidar(model) && //去掉Tmini雷达的角度二级解析
1315+
!isR3Lidar(model)) //去掉R3雷达的角度二级解析
13131316
{
13141317
correctAngle = (int32_t)(((atan(((21.8 * (155.3 - ((*node).dist / 4.0))) / 155.3) / ((*node).dist / 4.0))) * 180.0 / 3.1415) * 64.0);
13151318
}
@@ -1666,7 +1669,7 @@ result_t YDlidarDriver::getDeviceInfo(device_info &info, uint32_t timeout)
16661669
//获取启动时抛出的设备信息或每帧数据中的设备信息
16671670
if (m_HasDeviceInfo & EPT_Module)
16681671
{
1669-
info = m_BaseDevInfo;
1672+
info = m_ModuleDevInfo;
16701673
return RESULT_OK;
16711674
}
16721675
else

0 commit comments

Comments
 (0)