fix protocol detection for undiscoverable devices (#1159)

This commit is contained in:
Borong Yuan
2023-11-16 11:50:07 +08:00
committed by GitHub
parent 4812ce4eaf
commit 757d3eb90b

View File

@@ -200,9 +200,9 @@ bool CameraDepthAI::init(const std::string & calibrationFolder, const std::strin
#ifdef RTABMAP_DEPTHAI #ifdef RTABMAP_DEPTHAI
std::vector<dai::DeviceInfo> devices = dai::Device::getAllAvailableDevices(); std::vector<dai::DeviceInfo> devices = dai::Device::getAllAvailableDevices();
if(devices.empty()) if(devices.empty() && mxidOrName_.empty())
{ {
UERROR("No DepthAI device found"); UERROR("No DepthAI device found or specified");
return false; return false;
} }
@@ -215,24 +215,11 @@ bool CameraDepthAI::init(const std::string & calibrationFolder, const std::strin
bool deviceFound = false; bool deviceFound = false;
dai::DeviceInfo deviceToUse(mxidOrName_); dai::DeviceInfo deviceToUse(mxidOrName_);
if(mxidOrName_.empty()) if(mxidOrName_.empty())
{
std::tie(deviceFound, deviceToUse) = dai::Device::getFirstAvailableDevice(); std::tie(deviceFound, deviceToUse) = dai::Device::getFirstAvailableDevice();
}
else if(!deviceToUse.mxid.empty()) else if(!deviceToUse.mxid.empty())
{
std::tie(deviceFound, deviceToUse) = dai::Device::getDeviceByMxId(deviceToUse.mxid); std::tie(deviceFound, deviceToUse) = dai::Device::getDeviceByMxId(deviceToUse.mxid);
}
else else
{ deviceFound = true;
for(auto& device : devices)
{
if(deviceToUse.name == device.name)
{
deviceFound = true;
deviceToUse = device;
}
}
}
if(!deviceFound) if(!deviceFound)
{ {
@@ -335,7 +322,7 @@ bool CameraDepthAI::init(const std::string & calibrationFolder, const std::strin
monoRight->out.link(stereo->right); monoRight->out.link(stereo->right);
// Using VideoEncoder on PoE devices, Subpixel is not supported // Using VideoEncoder on PoE devices, Subpixel is not supported
if(deviceToUse.protocol == X_LINK_TCP_IP) if(deviceToUse.protocol == X_LINK_TCP_IP || mxidOrName_.find(".") != std::string::npos)
{ {
auto leftEnc = p.create<dai::node::VideoEncoder>(); auto leftEnc = p.create<dai::node::VideoEncoder>();
auto depthOrRightEnc = p.create<dai::node::VideoEncoder>(); auto depthOrRightEnc = p.create<dai::node::VideoEncoder>();
@@ -509,8 +496,8 @@ bool CameraDepthAI::init(const std::string & calibrationFolder, const std::strin
else else
{ {
UScopeMutex lock(imuMutex_); UScopeMutex lock(imuMutex_);
accBuffer_.emplace_hint(accBuffer_.end(), std::make_pair(accStamp, cv::Vec3f(acceleroValues.x, acceleroValues.y, acceleroValues.z))); accBuffer_.emplace_hint(accBuffer_.end(), accStamp, cv::Vec3f(acceleroValues.x, acceleroValues.y, acceleroValues.z));
gyroBuffer_.emplace_hint(gyroBuffer_.end(), std::make_pair(gyroStamp, cv::Vec3f(gyroValues.x, gyroValues.y, gyroValues.z))); gyroBuffer_.emplace_hint(gyroBuffer_.end(), gyroStamp, cv::Vec3f(gyroValues.x, gyroValues.y, gyroValues.z));
} }
} }
}); });
@@ -568,7 +555,7 @@ SensorData CameraDepthAI::captureImage(CameraInfo * info)
rectifRightOrDepth = rightOrDepthQueue_->get<dai::ImgFrame>(); rectifRightOrDepth = rightOrDepthQueue_->get<dai::ImgFrame>();
double stamp = std::chrono::duration<double>(rectifL->getTimestampDevice(dai::CameraExposureOffset::MIDDLE).time_since_epoch()).count(); double stamp = std::chrono::duration<double>(rectifL->getTimestampDevice(dai::CameraExposureOffset::MIDDLE).time_since_epoch()).count();
if(device_->getDeviceInfo().protocol == X_LINK_TCP_IP) if(device_->getDeviceInfo().protocol == X_LINK_TCP_IP || mxidOrName_.find(".") != std::string::npos)
{ {
left = cv::imdecode(rectifL->getData(), cv::IMREAD_GRAYSCALE); left = cv::imdecode(rectifL->getData(), cv::IMREAD_GRAYSCALE);
depthOrRight = cv::imdecode(rectifRightOrDepth->getData(), cv::IMREAD_GRAYSCALE); depthOrRight = cv::imdecode(rectifRightOrDepth->getData(), cv::IMREAD_GRAYSCALE);