34 #include <sl/Camera.hpp>
42 static cv::Mat slMat2cvMat(sl::Mat& input) {
43 #if ZED_SDK_MAJOR_VERSION < 3
46 switch (input.getDataType()) {
47 case sl::MAT_TYPE_32F_C1: cv_type = CV_32FC1;
break;
48 case sl::MAT_TYPE_32F_C2: cv_type = CV_32FC2;
break;
49 case sl::MAT_TYPE_32F_C3: cv_type = CV_32FC3;
break;
50 case sl::MAT_TYPE_32F_C4: cv_type = CV_32FC4;
break;
51 case sl::MAT_TYPE_8U_C1: cv_type = CV_8UC1;
break;
52 case sl::MAT_TYPE_8U_C2: cv_type = CV_8UC2;
break;
53 case sl::MAT_TYPE_8U_C3: cv_type = CV_8UC3;
break;
54 case sl::MAT_TYPE_8U_C4: cv_type = CV_8UC4;
break;
59 return cv::Mat(input.getHeight(), input.getWidth(), cv_type, input.getPtr<sl::uchar1>(sl::MEM_CPU));
63 switch (input.getDataType()) {
64 case sl::MAT_TYPE::F32_C1: cv_type = CV_32FC1;
break;
65 case sl::MAT_TYPE::F32_C2: cv_type = CV_32FC2;
break;
66 case sl::MAT_TYPE::F32_C3: cv_type = CV_32FC3;
break;
67 case sl::MAT_TYPE::F32_C4: cv_type = CV_32FC4;
break;
68 case sl::MAT_TYPE::U8_C1: cv_type = CV_8UC1;
break;
69 case sl::MAT_TYPE::U8_C2: cv_type = CV_8UC2;
break;
70 case sl::MAT_TYPE::U8_C3: cv_type = CV_8UC3;
break;
71 case sl::MAT_TYPE::U8_C4: cv_type = CV_8UC4;
break;
76 return cv::Mat(input.getHeight(), input.getWidth(), cv_type, input.getPtr<sl::uchar1>(sl::MEM::CPU));
80 Transform zedPoseToTransform(
const sl::Pose & pose)
83 pose.pose_data.m[0], pose.pose_data.m[1], pose.pose_data.m[2], pose.pose_data.m[3],
84 pose.pose_data.m[4], pose.pose_data.m[5], pose.pose_data.m[6], pose.pose_data.m[7],
85 pose.pose_data.m[8], pose.pose_data.m[9], pose.pose_data.m[10], pose.pose_data.m[11]);
88 #if ZED_SDK_MAJOR_VERSION < 3
89 IMU zedIMUtoIMU(
const sl::IMUData & imuData,
const Transform & imuLocalTransform)
91 sl::Orientation
orientation = imuData.pose_data.getOrientation();
94 Transform opticalTransform(0, 0, 1, 0, -1, 0, 0, 0, 0, -1, 0, 0);
96 orientationT = opticalTransform * orientationT;
98 static double deg2rad = 0.017453293;
99 Eigen::Vector4d accT = Eigen::Vector4d(imuData.linear_acceleration.v[0], imuData.linear_acceleration.v[1], imuData.linear_acceleration.v[2], 1);
100 Eigen::Vector4d gyrT = Eigen::Vector4d(imuData.angular_velocity.v[0]*deg2rad, imuData.angular_velocity.v[1]*deg2rad, imuData.angular_velocity.v[2]*deg2rad, 1);
102 cv::Mat orientationCov = (cv::Mat_<double>(3,3)<<
103 imuData.pose_covariance[21], imuData.pose_covariance[22], imuData.pose_covariance[23],
104 imuData.pose_covariance[27], imuData.pose_covariance[28], imuData.pose_covariance[29],
105 imuData.pose_covariance[33], imuData.pose_covariance[34], imuData.pose_covariance[35]);
106 cv::Mat angCov = (cv::Mat_<double>(3,3)<<
107 imuData.angular_velocity_convariance.r[0], imuData.angular_velocity_convariance.r[1], imuData.angular_velocity_convariance.r[2],
108 imuData.angular_velocity_convariance.r[3], imuData.angular_velocity_convariance.r[4], imuData.angular_velocity_convariance.r[5],
109 imuData.angular_velocity_convariance.r[6], imuData.angular_velocity_convariance.r[7], imuData.angular_velocity_convariance.r[8]);
110 cv::Mat accCov = (cv::Mat_<double>(3,3)<<
111 imuData.linear_acceleration_convariance.r[0], imuData.linear_acceleration_convariance.r[1], imuData.linear_acceleration_convariance.r[2],
112 imuData.linear_acceleration_convariance.r[3], imuData.linear_acceleration_convariance.r[4], imuData.linear_acceleration_convariance.r[5],
113 imuData.linear_acceleration_convariance.r[6], imuData.linear_acceleration_convariance.r[7], imuData.linear_acceleration_convariance.r[8]);
120 cv::Vec3d(gyrT[0], gyrT[1], gyrT[2]),
122 cv::Vec3d(accT[0], accT[1], accT[2]),
127 IMU zedIMUtoIMU(
const sl::SensorsData & sensorData,
const Transform & imuLocalTransform)
129 sl::Orientation
orientation = sensorData.imu.pose.getOrientation();
132 Transform opticalTransform(0, 0, 1, 0, -1, 0, 0, 0, 0, -1, 0, 0);
134 orientationT = opticalTransform * orientationT;
136 static double deg2rad = 0.017453293;
137 Eigen::Vector4d accT = Eigen::Vector4d(sensorData.imu.linear_acceleration.v[0], sensorData.imu.linear_acceleration.v[1], sensorData.imu.linear_acceleration.v[2], 1);
138 Eigen::Vector4d gyrT = Eigen::Vector4d(sensorData.imu.angular_velocity.v[0]*deg2rad, sensorData.imu.angular_velocity.v[1]*deg2rad, sensorData.imu.angular_velocity.v[2]*deg2rad, 1);
140 cv::Mat orientationCov = (cv::Mat_<double>(3,3)<<
141 sensorData.imu.pose_covariance.r[0], sensorData.imu.pose_covariance.r[1], sensorData.imu.pose_covariance.r[2],
142 sensorData.imu.pose_covariance.r[3], sensorData.imu.pose_covariance.r[4], sensorData.imu.pose_covariance.r[5],
143 sensorData.imu.pose_covariance.r[6], sensorData.imu.pose_covariance.r[7], sensorData.imu.pose_covariance.r[8]);
144 cv::Mat angCov = (cv::Mat_<double>(3,3)<<
145 sensorData.imu.angular_velocity_covariance.r[0], sensorData.imu.angular_velocity_covariance.r[1], sensorData.imu.angular_velocity_covariance.r[2],
146 sensorData.imu.angular_velocity_covariance.r[3], sensorData.imu.angular_velocity_covariance.r[4], sensorData.imu.angular_velocity_covariance.r[5],
147 sensorData.imu.angular_velocity_covariance.r[6], sensorData.imu.angular_velocity_covariance.r[7], sensorData.imu.angular_velocity_covariance.r[8]);
148 cv::Mat accCov = (cv::Mat_<double>(3,3)<<
149 sensorData.imu.linear_acceleration_covariance.r[0], sensorData.imu.linear_acceleration_covariance.r[1], sensorData.imu.linear_acceleration_covariance.r[2],
150 sensorData.imu.linear_acceleration_covariance.r[3], sensorData.imu.linear_acceleration_covariance.r[4], sensorData.imu.linear_acceleration_covariance.r[5],
151 sensorData.imu.linear_acceleration_covariance.r[6], sensorData.imu.linear_acceleration_covariance.r[7], sensorData.imu.linear_acceleration_covariance.r[8]);
158 cv::Vec3d(gyrT[0], gyrT[1], gyrT[2]),
160 cv::Vec3d(accT[0], accT[1], accT[2]),
166 class ZedIMUThread:
public UThread
169 ZedIMUThread(
float rate, sl::Camera * zed, CameraStereoZed * camera,
const Transform & imuLocalTransform,
bool accurate)
172 UASSERT(zed != 0 && camera != 0);
176 accurate_ = accurate;
177 imuLocalTransform_ = imuLocalTransform;
180 virtual void mainLoopBegin()
182 frameRateTimer_.start();
184 virtual void mainLoop()
186 double delay = 1000.0/double(rate_);
187 int sleepTime = delay - 1000.0f*frameRateTimer_.getElapsedTime();
198 while(frameRateTimer_.getElapsedTime() < delay-0.000001)
208 frameRateTimer_.start();
210 #if ZED_SDK_MAJOR_VERSION < 3
212 bool res = zed_->getIMUData(imudata, sl::TIME_REFERENCE_IMAGE);
213 if(res == sl::SUCCESS && imudata.valid)
215 this->postInterIMU(zedIMUtoIMU(imudata, imuLocalTransform_),
UTimer::now());
218 sl::SensorsData sensordata;
219 sl::ERROR_CODE
res = zed_->getSensorsData(sensordata, sl::TIME_REFERENCE::CURRENT);
220 if(res == sl::ERROR_CODE::SUCCESS && sensordata.imu.is_available)
222 camera_->postInterIMUPublic(zedIMUtoIMU(sensordata, imuLocalTransform_),
double(sensordata.imu.timestamp.getNanoseconds())/10e8);
228 CameraStereoZed * camera_;
230 Transform imuLocalTransform_;
248 return ZED_SDK_MAJOR_VERSION;
261 bool computeOdometry,
264 bool selfCalibration,
266 int texturenessConfidenceThr) :
267 Camera(imageRate, localTransform)
272 usbDevice_(deviceId),
274 resolution_(resolution),
276 selfCalibration_(selfCalibration),
277 sensingMode_(sensingMode),
278 confidenceThr_(confidenceThr),
279 texturenessConfidenceThr_(texturenessConfidenceThr),
280 computeOdometry_(computeOdometry),
282 force3DoF_(odomForce3DoF),
283 imuPublishingThread_(0)
288 #if ZED_SDK_MAJOR_VERSION < 4
289 if(resolution_ == 1 || resolution_ == 2)
297 if(resolution_ == 4 || resolution_ == -1)
301 else if(resolution_ == 5 || resolution_ == 6)
306 if(resolution_ == -1)
308 resolution_ =
int(sl::RESOLUTION::AUTO);
312 #if ZED_SDK_MAJOR_VERSION < 3
313 UASSERT(resolution_ >= sl::RESOLUTION_HD2K && resolution_ <sl::RESOLUTION_LAST);
314 UASSERT(quality_ >= sl::DEPTH_MODE_NONE && quality_ <sl::DEPTH_MODE_LAST);
315 UASSERT(sensingMode_ >= sl::SENSING_MODE_STANDARD && sensingMode_ <sl::SENSING_MODE_LAST);
316 UASSERT(confidenceThr_ >= 0 && confidenceThr_ <=100);
318 sl::RESOLUTION
res =
static_cast<sl::RESOLUTION
>(resolution_);
319 sl::DEPTH_MODE qual =
static_cast<sl::DEPTH_MODE
>(quality_);
321 UASSERT(
res >= sl::RESOLUTION::HD2K &&
res < sl::RESOLUTION::LAST);
322 UASSERT(qual >= sl::DEPTH_MODE::NONE && qual < sl::DEPTH_MODE::LAST);
323 #if ZED_SDK_MAJOR_VERSION < 4
324 sl::SENSING_MODE sens =
static_cast<sl::SENSING_MODE
>(sensingMode_);
325 UASSERT(sens >= sl::SENSING_MODE::STANDARD && sens < sl::SENSING_MODE::LAST);
327 UASSERT(sensingMode_ >= 0 && sensingMode_ < 2);
329 UASSERT(confidenceThr_ >= 0 && confidenceThr_ <=100);
330 UASSERT(texturenessConfidenceThr_ >= 0 && texturenessConfidenceThr_ <=100);
336 const std::string & filePath,
340 bool computeOdometry,
343 bool selfCalibration,
345 int texturenessConfidenceThr) :
346 Camera(imageRate, localTransform)
352 svoFilePath_(filePath),
353 #
if ZED_SDK_MAJOR_VERSION < 3
354 resolution_(
sl::RESOLUTION_HD720),
355 #elif ZED_SDK_MAJOR_VERSION < 4
356 resolution_(
sl::RESOLUTION::HD720),
358 resolution_(
int(
sl::RESOLUTION::AUTO)),
361 selfCalibration_(selfCalibration),
362 sensingMode_(sensingMode),
363 confidenceThr_(confidenceThr),
364 texturenessConfidenceThr_(texturenessConfidenceThr),
365 computeOdometry_(computeOdometry),
367 force3DoF_(odomForce3DoF),
368 imuPublishingThread_(0)
373 #if ZED_SDK_MAJOR_VERSION < 3
374 UASSERT(resolution_ >= sl::RESOLUTION_HD2K && resolution_ <sl::RESOLUTION_LAST);
375 UASSERT(quality_ >= sl::DEPTH_MODE_NONE && quality_ <sl::DEPTH_MODE_LAST);
376 UASSERT(sensingMode_ >= sl::SENSING_MODE_STANDARD && sensingMode_ <sl::SENSING_MODE_LAST);
377 UASSERT(confidenceThr_ >= 0 && confidenceThr_ <=100);
379 sl::RESOLUTION
res =
static_cast<sl::RESOLUTION
>(resolution_);
380 sl::DEPTH_MODE qual =
static_cast<sl::DEPTH_MODE
>(quality_);
382 UASSERT(
res >= sl::RESOLUTION::HD2K &&
res < sl::RESOLUTION::LAST);
383 UASSERT(qual >= sl::DEPTH_MODE::NONE && qual < sl::DEPTH_MODE::LAST);
384 #if ZED_SDK_MAJOR_VERSION < 4
385 sl::SENSING_MODE sens =
static_cast<sl::SENSING_MODE
>(sensingMode_);
386 UASSERT(sens >= sl::SENSING_MODE::STANDARD && sens < sl::SENSING_MODE::LAST);
388 UASSERT(sensingMode_ >= 0 && sensingMode_ < 2);
390 UASSERT(confidenceThr_ >= 0 && confidenceThr_ <=100);
391 UASSERT(texturenessConfidenceThr_ >= 0 && texturenessConfidenceThr_ <=100);
399 if(imuPublishingThread_)
401 imuPublishingThread_->join(
true);
403 delete imuPublishingThread_;
412 if(imuPublishingThread_)
414 imuPublishingThread_->join(
true);
415 delete imuPublishingThread_;
416 imuPublishingThread_=0;
426 sl::InitParameters param;
427 param.camera_resolution=
static_cast<sl::RESOLUTION
>(resolution_);
429 param.depth_mode=(sl::DEPTH_MODE)quality_;
430 #if ZED_SDK_MAJOR_VERSION < 3
431 param.camera_linux_id=usbDevice_;
432 param.coordinate_units=sl::UNIT_METER;
433 param.coordinate_system=(sl::COORDINATE_SYSTEM)sl::COORDINATE_SYSTEM_IMAGE ;
435 param.coordinate_units=sl::UNIT::METER;
436 param.coordinate_system=sl::COORDINATE_SYSTEM::IMAGE ;
438 param.sdk_verbose=
true;
440 param.depth_minimum_distance=-1;
441 param.camera_disable_self_calib=!selfCalibration_;
443 sl::ERROR_CODE r = sl::ERROR_CODE::SUCCESS;
446 UINFO(
"svo file = %s", svoFilePath_.c_str());
447 zed_ =
new sl::Camera();
448 #if ZED_SDK_MAJOR_VERSION < 3
449 param.svo_input_filename=svoFilePath_.c_str();
451 param.input.setFromSVOFile(svoFilePath_.c_str());
453 r = zed_->open(param);
457 #if ZED_SDK_MAJOR_VERSION >= 3
458 param.input.setFromCameraID(usbDevice_);
460 UINFO(
"Resolution=%d imagerate=%f device=%d", resolution_,
getImageRate(), usbDevice_);
461 zed_ =
new sl::Camera();
462 r = zed_->open(param);
465 if(r!=sl::ERROR_CODE::SUCCESS)
467 UERROR(
"Camera initialization failed: \"%s\"", toString(r).
c_str());
473 #if ZED_SDK_MAJOR_VERSION < 3
474 UINFO(
"Init ZED: Mode=%d Unit=%d CoordinateSystem=%d Verbose=false device=-1 minDist=-1 self-calibration=%s vflip=false",
475 quality_, sl::UNIT_METER, sl::COORDINATE_SYSTEM_IMAGE , selfCalibration_?
"true":
"false");
477 if(quality_!=sl::DEPTH_MODE_NONE)
479 zed_->setConfidenceThreshold(confidenceThr_);
482 UINFO(
"Init ZED: Mode=%d Unit=%d CoordinateSystem=%d Verbose=false device=-1 minDist=-1 self-calibration=%s vflip=false",
483 quality_, sl::UNIT::METER, sl::COORDINATE_SYSTEM::IMAGE , selfCalibration_?
"true":
"false");
491 if (computeOdometry_)
493 #if ZED_SDK_MAJOR_VERSION < 3
494 sl::TrackingParameters tparam;
495 tparam.enable_spatial_memory=
false;
496 r = zed_->enableTracking(tparam);
498 sl::PositionalTrackingParameters tparam;
499 tparam.enable_area_memory=
false;
500 r = zed_->enablePositionalTracking(tparam);
502 if(r!=sl::ERROR_CODE::SUCCESS)
504 UERROR(
"Camera tracking initialization failed: \"%s\"", toString(r).
c_str());
508 sl::CameraInformation infos = zed_->getCameraInformation();
509 #if ZED_SDK_MAJOR_VERSION < 4
510 sl::CalibrationParameters *stereoParams = &(infos.calibration_parameters );
512 sl::CalibrationParameters *stereoParams = &(infos.camera_configuration.calibration_parameters );
514 sl::Resolution
res = stereoParams->left_cam.image_size;
516 #if ZED_SDK_MAJOR_VERSION < 4
518 stereoParams->left_cam.fx,
519 stereoParams->left_cam.fy,
520 stereoParams->left_cam.cx,
521 stereoParams->left_cam.cy,
523 this->getLocalTransform(),
524 cv::Size(
res.width,
res.height));
527 stereoParams->left_cam.fx,
528 stereoParams->left_cam.fy,
529 stereoParams->left_cam.cx,
530 stereoParams->left_cam.cy,
531 stereoParams->getCameraBaseline(),
532 this->getLocalTransform(),
533 cv::Size(
res.width,
res.height));
536 #if ZED_SDK_MAJOR_VERSION < 4
537 UINFO(
"Calibration: fx=%f, fy=%f, cx=%f, cy=%f, baseline=%f, width=%d, height=%d, transform=%s",
538 stereoParams->left_cam.fx,
539 stereoParams->left_cam.fy,
540 stereoParams->left_cam.cx,
541 stereoParams->left_cam.cy,
545 this->getLocalTransform().prettyPrint().c_str());
547 UINFO(
"Calibration: fx=%f, fy=%f, cx=%f, cy=%f, baseline=%f, width=%d, height=%d, transform=%s",
548 stereoParams->left_cam.fx,
549 stereoParams->left_cam.fy,
550 stereoParams->left_cam.cx,
551 stereoParams->left_cam.cy,
552 stereoParams->getCameraBaseline(),
555 this->getLocalTransform().prettyPrint().c_str());
558 #if ZED_SDK_MAJOR_VERSION < 3
559 if(infos.camera_model == sl::MODEL_ZED_M)
561 if(infos.camera_model != sl::MODEL::ZED)
564 #if ZED_SDK_MAJOR_VERSION < 4
567 imuLocalTransform_ = this->
getLocalTransform() * zedPoseToTransform(infos.sensors_configuration.camera_imu_transform).
inverse();
570 #if ZED_SDK_MAJOR_VERSION < 4
571 UINFO(
"IMU local transform: %s (imu2cam=%s))",
572 imuLocalTransform_.prettyPrint().c_str(),
573 zedPoseToTransform(infos.camera_imu_transform).prettyPrint().c_str());
575 UINFO(
"IMU local transform: %s (imu2cam=%s))",
576 imuLocalTransform_.prettyPrint().c_str(),
577 zedPoseToTransform(infos.sensors_configuration.camera_imu_transform).prettyPrint().c_str());
581 imuPublishingThread_ =
new ZedIMUThread(200, zed_,
this, imuLocalTransform_,
true);
582 imuPublishingThread_->start();
588 UERROR(
"CameraStereoZED: RTAB-Map is not built with ZED sdk support!");
596 return stereoModel_.isValidForProjection();
607 return uFormat(
"%x", zed_->getCameraInformation ().serial_number);
616 return computeOdometry_;
626 if (computeOdometry_ && zed_)
630 #if ZED_SDK_MAJOR_VERSION < 3
635 sl::TRACKING_STATE tracking_state = zed_->getPosition(
p);
636 if (tracking_state == sl::TRACKING_STATE_OK)
638 if(zed_->grab()!=sl::ERROR_CODE::SUCCESS)
642 sl::POSITIONAL_TRACKING_STATE tracking_state = zed_->getPosition(
p);
643 if (tracking_state == sl::POSITIONAL_TRACKING_STATE::OK)
646 int trackingConfidence =
p.pose_confidence;
648 if (trackingConfidence>0)
650 pose = zedPoseToTransform(
p);
664 covariance = cv::Mat::eye(6, 6, CV_64FC1) * 9999.0f;
670 covariance = cv::Mat::eye(6, 6, CV_64FC1) * 1.0f /
float(trackingConfidence);
671 UDEBUG(
"Run %s (var=%f)", pose.
prettyPrint().c_str(), 1.0f /
float(trackingConfidence));
677 covariance = cv::Mat::eye(6, 6, CV_64FC1) * 9999.0f;
679 UWARN(
"ZED lost! (trackingConfidence=%d)", trackingConfidence);
684 covariance = cv::Mat::eye(6, 6, CV_64FC1) * 9999.0f;
686 UWARN(
"ZED lost! (trackingConfidence=%d)", trackingConfidence);
691 UWARN(
"Tracking not ok: state=\"%s\"", toString(tracking_state).
c_str());
702 #if ZED_SDK_MAJOR_VERSION < 3
703 sl::RuntimeParameters rparam((sl::SENSING_MODE)sensingMode_, quality_ > 0, quality_ > 0, sl::REFERENCE_FRAME_CAMERA);
704 #elif ZED_SDK_MAJOR_VERSION < 4
705 sl::RuntimeParameters rparam((sl::SENSING_MODE)sensingMode_, quality_ > 0, confidenceThr_, texturenessConfidenceThr_, sl::REFERENCE_FRAME::CAMERA);
707 sl::RuntimeParameters rparam(quality_ > 0, sensingMode_ == 1, confidenceThr_, texturenessConfidenceThr_, sl::REFERENCE_FRAME::CAMERA);
713 #if ZED_SDK_MAJOR_VERSION < 3
714 bool res = zed_->grab(rparam);
719 res = zed_->grab(rparam);
726 sl::Timestamp timestamp;
727 bool imuReceived =
true;
730 res = zed_->grab(rparam);
731 timestamp = zed_->getTimestamp(sl::TIME_REFERENCE::IMAGE);
734 if(imuPublishingThread_ == 0 && !imuLocalTransform_.isNull())
736 sl::SensorsData imudatatmp;
737 res = zed_->getSensorsData(imudatatmp, sl::TIME_REFERENCE::IMAGE);
738 imuReceived =
res == sl::ERROR_CODE::SUCCESS && imudatatmp.imu.is_available && imudatatmp.imu.timestamp.getNanoseconds() != 0;
743 if(
res==sl::ERROR_CODE::SUCCESS)
748 #if ZED_SDK_MAJOR_VERSION < 3
749 zed_->retrieveImage(tmp,sl::VIEW_LEFT);
751 zed_->retrieveImage(tmp,sl::VIEW::LEFT);
753 cv::Mat rgbaLeft = slMat2cvMat(tmp);
756 cv::cvtColor(rgbaLeft, left, cv::COLOR_BGRA2BGR);
763 #if ZED_SDK_MAJOR_VERSION < 3
764 zed_->retrieveMeasure(tmp,sl::MEASURE_DEPTH);
766 zed_->retrieveMeasure(tmp,sl::MEASURE::DEPTH);
768 slMat2cvMat(tmp).copyTo(depth);
769 #if ZED_SDK_MAJOR_VERSION < 3
772 data =
SensorData(left, depth, stereoModel_.left(),
this->getNextSeqID(),
double(timestamp.getNanoseconds())/10e8);
778 #if ZED_SDK_MAJOR_VERSION < 3
779 sl::Mat tmp;zed_->retrieveImage(tmp,sl::VIEW_RIGHT );
781 sl::Mat tmp;zed_->retrieveImage(tmp,sl::VIEW::RIGHT );
783 cv::Mat rgbaRight = slMat2cvMat(tmp);
785 cv::cvtColor(rgbaRight, right, cv::COLOR_BGRA2GRAY);
786 #if ZED_SDK_MAJOR_VERSION < 3
789 data =
SensorData(left, right, stereoModel_, this->
getNextSeqID(),
double(timestamp.getNanoseconds())/10e8);
793 if(imuPublishingThread_ == 0)
795 #if ZED_SDK_MAJOR_VERSION < 3
797 res = zed_->getIMUData(imudata, sl::TIME_REFERENCE_IMAGE);
798 if(
res == sl::SUCCESS && imudata.valid)
800 sl::SensorsData imudata;
801 res = zed_->getSensorsData(imudata, sl::TIME_REFERENCE::IMAGE);
802 if(
res == sl::ERROR_CODE::SUCCESS && imudata.imu.is_available)
806 data.setIMU(zedIMUtoIMU(imudata, imuLocalTransform_));
810 if (computeOdometry_ &&
info)
813 #if ZED_SDK_MAJOR_VERSION < 3
814 sl::TRACKING_STATE tracking_state = zed_->getPosition(pose);
815 if (tracking_state == sl::TRACKING_STATE_OK)
817 sl::POSITIONAL_TRACKING_STATE tracking_state = zed_->getPosition(pose);
818 if (tracking_state == sl::POSITIONAL_TRACKING_STATE::OK)
821 int trackingConfidence = pose.pose_confidence;
823 info->odomPose = zedPoseToTransform(pose);
824 if (!
info->odomPose.isNull())
826 #if ZED_SDK_MAJOR_VERSION >=3
827 if(pose.timestamp != timestamp)
829 UWARN(
"Pose retrieve doesn't have same stamp (%ld) than grabbed image (%ld)", pose.timestamp, timestamp);
840 info->odomPose =
info->odomPose.to3DoF();
844 info->odomCovariance = cv::Mat::eye(6, 6, CV_64FC1) * 9999.0f;
846 UDEBUG(
"Init %s (var=%f)",
info->odomPose.prettyPrint().c_str(), 9999.0f);
848 else if(trackingConfidence==0)
850 info->odomCovariance = cv::Mat::eye(6, 6, CV_64FC1) * 9999.0f;
852 UWARN(
"ZED lost! (trackingConfidence=%d)", trackingConfidence);
856 info->odomCovariance = cv::Mat::eye(6, 6, CV_64FC1) * 1.0f /
float(trackingConfidence);
857 UDEBUG(
"Run %s (var=%f)",
info->odomPose.prettyPrint().c_str(), 1.0f /
float(trackingConfidence));
862 info->odomCovariance = cv::Mat::eye(6, 6, CV_64FC1) * 9999.0f;
864 UWARN(
"ZED lost! (trackingConfidence=%d)", trackingConfidence);
869 UWARN(
"Tracking not ok: state=\"%s\"", toString(tracking_state).
c_str());
875 UERROR(
"CameraStereoZed: Failed to grab images after 2 seconds!");
879 UWARN(
"CameraStereoZed: end of stream is reached!");
883 UERROR(
"CameraStereoZED: RTAB-Map is not built with ZED sdk support!");