Skip to content

Commit

Permalink
bugfix:start/stop_motor(service) cause lidar to stop scanning
Browse files Browse the repository at this point in the history
  • Loading branch information
WubinXia committed Dec 31, 2019
1 parent 3c770ba commit 4f899e6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
4 changes: 3 additions & 1 deletion sdk/src/rplidar_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@ u_result RPlidarDriverImplCommon::_waitResponseHeader(rplidar_ans_header_t * hea
}



u_result RPlidarDriverImplCommon::getHealth(rplidar_response_device_health_t & healthinfo, _u32 timeout)
{
u_result ans;
Expand Down Expand Up @@ -1550,6 +1549,7 @@ u_result RPlidarDriverImplCommon::getScanModeCount(_u16& modeCount, _u32 timeout

u_result RPlidarDriverImplCommon::startScan(bool force, bool useTypicalScan, _u32 options, RplidarScanMode* outUsedScanMode)
{
if(_isScanning)return RESULT_ALREADY_DONE;
u_result ans;

bool ifSupportLidarConf = false;
Expand Down Expand Up @@ -2158,6 +2158,7 @@ u_result RPlidarDriverImplCommon::setMotorPWM(_u16 pwm)
return RESULT_OK;
}


u_result RPlidarDriverImplCommon::setLidarSpinSpeed(_u16 rpm, _u32 timeout)
{
if (!_isTofLidar) return RESULT_OPERATION_NOT_SUPPORT;
Expand Down Expand Up @@ -2188,6 +2189,7 @@ u_result RPlidarDriverImplCommon::startMotor()
}
else {
setLidarSpinSpeed(600);//set default rpm to tof lidar
return RESULT_OK;
}

}
Expand Down
3 changes: 1 addition & 2 deletions sdk/src/rplidar_driver_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ namespace rp { namespace standalone{ namespace rplidar {
virtual u_result startScan(bool force, bool useTypicalScan, _u32 options = 0, RplidarScanMode* outUsedScanMode = NULL);
virtual u_result startScanExpress(bool force, _u16 scanMode, _u32 options = 0, RplidarScanMode* outUsedScanMode = NULL, _u32 timeout = DEFAULT_TIMEOUT);


virtual u_result getHealth(rplidar_response_device_health_t & health, _u32 timeout = DEFAULT_TIMEOUT);
virtual u_result getDeviceInfo(rplidar_response_device_info_t & info, _u32 timeout = DEFAULT_TIMEOUT);
virtual u_result checkIfTofLidar(bool & isTofLidar, _u32 timeout = DEFAULT_TIMEOUT);
Expand Down Expand Up @@ -135,4 +134,4 @@ namespace rp { namespace standalone{ namespace rplidar {
RPlidarDriverImplCommon();
virtual ~RPlidarDriverImplCommon() {}
};
}}}
}}}
14 changes: 8 additions & 6 deletions src/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ bool checkRPLIDARHealth(RPlidarDriver * drv)
{
u_result op_result;
rplidar_response_device_health_t healthinfo;

op_result = drv->getHealth(healthinfo);
if (IS_OK(op_result)) {
ROS_INFO("RPLidar health status : %d", healthinfo.status);
Expand All @@ -158,7 +157,6 @@ bool stop_motor(std_srvs::Empty::Request &req,
return false;

ROS_DEBUG("Stop motor");
drv->stop();
drv->stopMotor();
return true;
}
Expand All @@ -168,9 +166,14 @@ bool start_motor(std_srvs::Empty::Request &req,
{
if(!drv)
return false;
ROS_DEBUG("Start motor");
drv->startMotor();
drv->startScan(0,1);
if(drv->isConnected())
{
ROS_DEBUG("Start motor");
u_result ans=drv->startMotor();

ans=drv->startScan(0,1);
}
else ROS_INFO("lost connection");
return true;
}

Expand Down Expand Up @@ -369,7 +372,6 @@ int main(int argc, char * argv[]) {
// All the data is invalid, just publish them
float angle_min = DEG2RAD(0.0f);
float angle_max = DEG2RAD(359.0f);

publish_scan(&scan_pub, nodes, count,
start_scan_time, scan_duration, inverted,
angle_min, angle_max, max_distance,
Expand Down

0 comments on commit 4f899e6

Please sign in to comment.