Skip to content

Commit

Permalink
修改雷达对象释放的时机以免多次释放导致异常
Browse files Browse the repository at this point in the history
  • Loading branch information
zhanyiaini committed Mar 5, 2024
1 parent b73fe49 commit 4e77c79
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 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 0)
set(YDLIDAR_SDK_VERSION_PATCH 1)
set(YDLIDAR_SDK_VERSION ${YDLIDAR_SDK_VERSION_MAJOR}.${YDLIDAR_SDK_VERSION_MINOR}.${YDLIDAR_SDK_VERSION_PATCH})

##########################################################
Expand Down
6 changes: 3 additions & 3 deletions examples/tmini_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 %s\n", id, it->first.c_str(), it->second.c_str());
printf("[%d] %s %s\n", id, it->first.c_str(), it->second.c_str());
id++;
}

Expand Down Expand Up @@ -163,7 +163,7 @@ int main(int argc, char *argv[]) {

std::string input_frequency;

float frequency = 10.0;
float frequency = 6.0;

// while (ydlidar::os_isOk() && !isSingleChannel) {
// printf("Please enter the lidar scan frequency[5-12]:");
Expand Down Expand Up @@ -211,7 +211,7 @@ int main(int argc, char *argv[]) {

//////////////////////bool property/////////////////
/// fixed angle resolution
bool b_optvalue = true;
bool b_optvalue = false;
laser.setlidaropt(LidarPropFixedResolution, &b_optvalue, sizeof(bool));
b_optvalue = false;
/// rotate 180
Expand Down
10 changes: 8 additions & 2 deletions src/CYdLidar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -848,8 +848,6 @@ void CYdLidar::disconnecting()
if (lidarPtr)
{
lidarPtr->disconnect();
delete lidarPtr;
lidarPtr = nullptr;
}

scanning = false;
Expand Down Expand Up @@ -1735,6 +1733,14 @@ bool CYdLidar::checkCalibrationAngle(const std::string &serialNumber)
-------------------------------------------------------------*/
bool CYdLidar::checkCOMMs()
{
//如果雷达类型有变化则需要先删除旧对象
if (lidarPtr &&
lidarPtr->getLidarType() != m_LidarType)
{
delete lidarPtr;
lidarPtr = nullptr;
}
//如果未创建对象
if (!lidarPtr)
{
printf("[YDLIDAR] SDK initializing\n");
Expand Down
8 changes: 5 additions & 3 deletions src/YDlidarDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2037,9 +2037,11 @@ result_t YDlidarDriver::stopMotor() {
/************************************************************************/
/* get the current scan frequency of lidar */
/************************************************************************/
result_t YDlidarDriver::getScanFrequency(scan_frequency &frequency,
uint32_t timeout) {
result_t ans;
result_t YDlidarDriver::getScanFrequency(
scan_frequency &frequency,
uint32_t timeout)
{
result_t ans;

if (!m_isConnected) {
return RESULT_FAIL;
Expand Down

0 comments on commit 4e77c79

Please sign in to comment.