Skip to content

Commit

Permalink
修改TIA雷达自动重连问题
Browse files Browse the repository at this point in the history
  • Loading branch information
zhanyiaini committed Dec 24, 2024
1 parent cf0e391 commit 1dfd712
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 13 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 9)
set(YDLIDAR_SDK_VERSION_PATCH 10)
set(YDLIDAR_SDK_VERSION ${YDLIDAR_SDK_VERSION_MAJOR}.${YDLIDAR_SDK_VERSION_MINOR}.${YDLIDAR_SDK_VERSION_PATCH})

##########################################################
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ YDLidar SDK consists of YDLidar SDK communication protocol, YDLidar SDK core, YD

### Prerequisites
* Linux
* Windows 7/10, Visual Studio 2015/2017(UTF-8 encoding)
* Windows 7/10, Visual Studio 2015 latest version or higher(UTF-8 encoding)
* C++11 compiler

### Supported Languages
* C / C++
* Python
* Python2 32-bit
* C#

## YDLidar SDK Communication Protocol
Expand Down
2 changes: 1 addition & 1 deletion examples/sdm18_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ int main(int argc, char *argv[])
// }
// }

int baudrate = 921600; //默认串口号
int baudrate = 921600; //默认波特率

bool isSingleChannel = false;

Expand Down
2 changes: 1 addition & 1 deletion python/examples/tea_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
while ret and ydlidar.os_isOk() :
r = laser.doProcessSimple(scan);
if r:
print("Scan received[",scan.stamp,"]:",scan.points.size(),"ranges is [",1.0/scan.config.scan_time,"]Hz");
print("Scan received [", scan.points.size(), "] points");
else :
print("Failed to get Lidar Data.")
time.sleep(0.05);
Expand Down
12 changes: 6 additions & 6 deletions src/ETLidarDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,18 @@
#define NOMINMAX
#endif

#include <core/network/PassiveSocket.h>
#include "ETLidarDriver.h"
#include <stdio.h>
/*Socket Specific headers */
#include <errno.h>
#include <core/serial/common.h>
#include <core/math/angles.h>
#include <math.h>
#include <algorithm>
#include <ydlidar_config.h>
using namespace impl;
#include "ETLidarDriver.h"
#include "core/network/PassiveSocket.h"
#include "core/serial/common.h"
#include "core/math/angles.h"
#include "ydlidar_config.h"

using namespace impl;
using namespace ydlidar;
using namespace ydlidar::core;
using namespace ydlidar::core::network;
Expand Down
23 changes: 21 additions & 2 deletions src/TiaLidarDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,24 @@ result_t TiaLidarDriver::stopScan(uint32_t timeout)
return ret ? RESULT_OK : RESULT_FAIL;
}

result_t TiaLidarDriver::startAutoScan(bool force, uint32_t timeout)
{
UNUSED(force);
UNUSED(timeout);

bool ret = setParam(P_TIA_SCANTYPE, 0);
return ret ? RESULT_OK : RESULT_FAIL;
}

result_t TiaLidarDriver::stopAutoScan(uint32_t timeout)
{
UNUSED(timeout);

//停止扫描
bool ret = setParam(P_TIA_SCANTYPE, -1);
return ret ? RESULT_OK : RESULT_FAIL;
}

bool TiaLidarDriver::dataConnect(const char *ip, int port)
{
UNUSED(ip);
Expand Down Expand Up @@ -463,7 +481,7 @@ result_t TiaLidarDriver::checkAutoConnecting()
}
//重新连接
while (isAutoconnting &&
!IS_OK(connect(m_port.c_str(), m_baudrate)))
!IS_OK(connect(m_port.c_str(), m_port2)))
{
setDriverError(NotOpenError);
delay(300); //延时
Expand All @@ -477,7 +495,8 @@ result_t TiaLidarDriver::checkAutoConnecting()
if (isconnected() &&
isAutoconnting)
{
ans = startScan();
stopAutoScan(); //尝试停止扫描
ans = startAutoScan();
if (IS_OK(ans))
{
if (getDriverError() == DeviceNotFoundError)
Expand Down
7 changes: 7 additions & 0 deletions src/TiaLidarDriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,13 @@ class TiaLidarDriver : public DriverInterface
bool createThread();
//销毁线程
void deleteThread();
//启动扫描
result_t startAutoScan(
bool force = false,
uint32_t timeout = SDK_TIMEOUT);
//停止扫描
result_t stopAutoScan(
uint32_t timeout = SDK_TIMEOUT);

result_t getScanData(node_info* nodes, size_t& count);
//检查自动连接
Expand Down

0 comments on commit 1dfd712

Please sign in to comment.