33 #include <ConsumerImplHelper/ToFCamera.h> 34 #include <GenTL/PFNC.h> 42 #include <sensor_msgs/Image.h> 43 #include <sensor_msgs/CameraInfo.h> 46 #include <opencv2/opencv.hpp> 50 #include <dynamic_reconfigure/server.h> 51 #include <basler_tof/BaslerToFConfig.h> 78 if (parts.size() != 3)
80 ROS_ERROR(
"Expected 3 parts, got %zu!", parts.size());
85 if (parts[0].dataFormat != PFNC_Coord3D_ABC32f)
87 ROS_ERROR(
"Unexpected data format for the first image part. Coord3D_ABC32f is expected.");
91 if (parts[1].dataFormat != PFNC_Mono16)
93 ROS_ERROR(
"Unexpected data format for the second image part. Mono16 is expected.");
98 const size_t nPixel = parts[0].width * parts[0].height;
100 pcl::PointCloud<pcl::PointXYZI>::Ptr cloud(
new pcl::PointCloud<pcl::PointXYZI>());
103 cloud->width = parts[0].width;
104 cloud->height = parts[0].height;
105 cloud->is_dense =
false;
106 cloud->points.resize(nPixel);
108 CToFCamera::Coord3D *pPoint =
static_cast<CToFCamera::Coord3D*
>(parts[0].pData);
109 uint16_t *pIntensity =
static_cast<uint16_t*
>(parts[1].pData);
111 for (
size_t i = 0; i < nPixel; ++i)
113 pcl::PointXYZI &p = cloud->points[i];
114 if (pPoint->IsValid())
116 p.x = 0.001f * pPoint->x;
117 p.y = 0.001f * pPoint->y;
118 p.z = 0.001f * pPoint->z;
119 p.intensity = *pIntensity;
123 p.x = std::numeric_limits<float>::quiet_NaN();
124 p.y = std::numeric_limits<float>::quiet_NaN();
125 p.z = std::numeric_limits<float>::quiet_NaN();
134 pIntensity =
static_cast<uint16_t*
>(parts[1].pData);
139 intensity_cvimg.
header.stamp = acquisition_time;
140 intensity_cvimg.
image = cv::Mat(parts[1].height, parts[1].width, CV_16UC1);
141 intensity_cvimg.
image.setTo(0);
143 for (
size_t i = 0; i < parts[1].height; i++)
145 for (
size_t j = 0; j < parts[1].width; j++)
147 intensity_cvimg.
image.at<
unsigned short>(i, j) = static_cast<unsigned short>(*pIntensity);
157 sensor_msgs::CameraInfoPtr intensity_info_msg(
new sensor_msgs::CameraInfo(intensity_info_manager_->getCameraInfo()));
158 intensity_info_msg->header.stamp = acquisition_time;
159 intensity_info_msg->header.frame_id =
frame_id_;
160 intensity_ci_pub_.
publish(intensity_info_msg);
163 uint16_t *pConfidence =
static_cast<uint16_t*
>(parts[2].pData);
168 confidence_cvimg.
header.stamp = acquisition_time;
169 confidence_cvimg.
image = cv::Mat(parts[2].height, parts[2].width, CV_16UC1);
170 confidence_cvimg.
image.setTo(0);
172 for (
size_t i = 0; i < parts[2].height; i++)
174 for (
size_t j = 0; j < parts[2].width; j++)
176 confidence_cvimg.
image.at<
unsigned short>(i, j) = static_cast<unsigned short>(*pConfidence);
183 sensor_msgs::CameraInfoPtr confidence_info_msg(
new sensor_msgs::CameraInfo(confidence_info_manager_->getCameraInfo()));
184 confidence_info_msg->header.stamp = acquisition_time;
185 confidence_info_msg->header.frame_id =
frame_id_;
186 confidence_ci_pub_.
publish(confidence_info_msg);
189 pPoint =
static_cast<CToFCamera::Coord3D*
>(parts[0].pData);
194 depth_cvimg.
header.stamp = acquisition_time;
195 depth_cvimg.
image = cv::Mat(parts[0].height, parts[0].width, CV_16UC1);
196 depth_cvimg.
image.setTo(0);
198 for (
size_t i = 0; i < parts[0].height; i++)
200 for (
size_t j = 0; j < parts[0].width; j++)
202 depth_cvimg.
image.at<uint16_t>(i, j) = static_cast<uint16_t>(pPoint->z);
209 sensor_msgs::CameraInfoPtr depth_info_msg(
new sensor_msgs::CameraInfo(depth_info_manager_->getCameraInfo()));
210 depth_info_msg->header.stamp = acquisition_time;
211 depth_info_msg->header.frame_id =
frame_id_;
212 depth_ci_pub_.
publish(depth_info_msg);
219 param = ((param + increment / 2) / increment) * increment;
224 param = (int)((param + increment / 2) / increment) * increment;
236 CFloatPtr(
camera_.GetParameter(
"AcquisitionFrameRate"))->SetValue(new_config.frame_rate);
238 if (new_config.exposure_auto)
240 CEnumerationPtr(
camera_.GetParameter(
"ExposureAuto"))->FromString(
"Continuous");
243 CFloatPtr(
camera_.GetParameter(
"Agility"))->SetValue(new_config.exposure_agility);
244 CIntegerPtr(
camera_.GetParameter(
"Delay"))->SetValue(new_config.exposure_delay);
248 CEnumerationPtr(
camera_.GetParameter(
"ExposureAuto"))->FromString(
"Off");
251 CFloatPtr(
camera_.GetParameter(
"ExposureTime"))->SetValue(new_config.exposure_time);
254 CIntegerPtr(
camera_.GetParameter(
"ConfidenceThreshold"))->SetValue(new_config.confidence_threshold);
255 CBooleanPtr(
camera_.GetParameter(
"FilterSpatial"))->SetValue(new_config.spatial_filter);
256 CBooleanPtr(
camera_.GetParameter(
"FilterTemporal"))->SetValue(new_config.temporal_filter);
257 CIntegerPtr(
camera_.GetParameter(
"FilterStrength"))->SetValue(new_config.temporal_strength);
258 CIntegerPtr(
camera_.GetParameter(
"OutlierTolerance"))->SetValue(new_config.outlier_tolerance);
288 int main(
int argc,
char* argv[])
290 ros::init(argc, argv,
"basler_tof_node");
297 pn.
param(
"frame_id",
frame_id_, std::string(
"camera_optical_frame"));
300 ROS_WARN(
"~device_id is not set! Using first device.");
306 cloud_pub_ = n.
advertise<pcl::PointCloud<pcl::PointXYZI> > (
"points", 10, rsscb, rsscb);
307 intensity_pub_ = n.
advertise<sensor_msgs::Image>(
"intensity/image_raw", 10, rsscb, rsscb);
308 confidence_pub_ = n.
advertise<sensor_msgs::Image>(
"confidence/image_raw", 10, rsscb, rsscb);
309 depth_pub_ = n.
advertise<sensor_msgs::Image>(
"depth/image_raw", 10, rsscb, rsscb);
310 intensity_ci_pub_ = n.
advertise<sensor_msgs::CameraInfo>(
"intensity/camera_info", 10, rsscb, rsscb);
311 confidence_ci_pub_ = n.
advertise<sensor_msgs::CameraInfo>(
"confidence/camera_info", 10, rsscb, rsscb);
312 depth_ci_pub_ = n.
advertise<sensor_msgs::CameraInfo>(
"depth/camera_info", 10, rsscb, rsscb);
314 intensity_info_manager_ = boost::make_shared<camera_info_manager::CameraInfoManager>(intensity_nh);
315 confidence_info_manager_ = boost::make_shared<camera_info_manager::CameraInfoManager>(confidence_nh);
316 depth_info_manager_ = boost::make_shared<camera_info_manager::CameraInfoManager>(depth_nh);
318 int exitCode = EXIT_FAILURE;
322 CToFCamera::InitProducer();
331 CameraList cameraList =
camera_.EnumerateCameras();
333 for (CameraList::const_iterator it = cameraList.begin(); it != cameraList.end(); ++it)
335 ROS_INFO(
"Found camera device with serial: %s", it->strSerialNumber.c_str());
338 ROS_INFO(
"Serial matches device_id, opening camera.");
352 +
"_" +
camera_.GetCameraInfo().strSerialNumber;
353 if (!intensity_info_manager_->setCameraName(camera_name_) ||
354 !confidence_info_manager_->setCameraName(camera_name_) ||
355 !depth_info_manager_->setCameraName(camera_name_))
358 <<
"] name not valid" 359 <<
" for camera_info_manager");
362 std::string camera_info_url;
363 if (pn.
getParam(
"camera_info_url", camera_info_url))
365 if (!intensity_info_manager_->validateURL(camera_info_url) ||
366 !confidence_info_manager_->validateURL(camera_info_url) ||
367 !depth_info_manager_->validateURL(camera_info_url))
369 ROS_WARN(
"camera_info_url invalid: %s", camera_info_url.c_str());
373 intensity_info_manager_->loadCameraInfo(camera_info_url);
374 confidence_info_manager_->loadCameraInfo(camera_info_url);
375 depth_info_manager_->loadCameraInfo(camera_info_url);
381 ROS_INFO_STREAM(
"DeviceVendorName: " << CStringPtr(
camera_.GetParameter(
"DeviceVendorName"))->GetValue());
384 ROS_INFO_STREAM(
"DeviceFirmwareVersion: " << CStringPtr(
camera_.GetParameter(
"DeviceFirmwareVersion"))->GetValue());
385 ROS_INFO_STREAM(
"DeviceDriverVersion: " << CStringPtr(
camera_.GetParameter(
"DeviceDriverVersion"))->GetValue());
386 ROS_INFO_STREAM(
"DeviceSerialNumber: " << CStringPtr(
camera_.GetParameter(
"DeviceSerialNumber"))->GetValue());
388 ROS_INFO_STREAM(
"DeviceCalibVersion: " << CIntegerPtr(
camera_.GetParameter(
"DeviceCalibVersion"))->GetValue());
389 ROS_INFO_STREAM(
"DeviceCalibState: " << CEnumerationPtr(
camera_.GetParameter(
"DeviceCalibState"))->ToString());
390 ROS_INFO_STREAM(
"DeviceCalibOffset: " << CIntegerPtr(
camera_.GetParameter(
"DeviceCalibOffset"))->GetValue());
392 ROS_INFO_STREAM(
"DeviceTemperature: " << CFloatPtr(
camera_.GetParameter(
"DeviceTemperature"))->GetValue() <<
" degrees C");
396 CEnumerationPtr ptrImageComponentSelector =
camera_.GetParameter(
"ImageComponentSelector");
397 CBooleanPtr ptrImageComponentEnable =
camera_.GetParameter(
"ImageComponentEnable");
398 CEnumerationPtr ptrPixelFormat =
camera_.GetParameter(
"PixelFormat");
400 ptrImageComponentSelector->FromString(
"Range");
401 ptrImageComponentEnable->SetValue(
true);
402 ptrPixelFormat->FromString(
"Coord3D_ABC32f");
404 ptrImageComponentSelector->FromString(
"Intensity");
405 ptrImageComponentEnable->SetValue(
true);
406 ptrPixelFormat->FromString(
"Mono16");
408 ptrImageComponentSelector->FromString(
"Confidence");
409 ptrImageComponentEnable->SetValue(
true);
410 ptrPixelFormat->FromString(
"Confidence16");
412 dynamic_reconfigure::Server<basler_tof::BaslerToFConfig> dynamic_reconfigure_server;
413 dynamic_reconfigure::Server<basler_tof::BaslerToFConfig>::CallbackType
f;
415 dynamic_reconfigure_server.setCallback(f);
427 GrabResultPtr ptrGrabResult =
camera_.GrabSingleImage(1000, &parts);
430 if (ptrGrabResult->status == GrabResult::Ok)
442 exitCode = EXIT_SUCCESS;
444 catch (GenICam::GenericException& e)
449 if (CToFCamera::IsProducerInitialized())
450 CToFCamera::TerminateProducer();
boost::function< void(const SingleSubscriberPublisher &)> SubscriberStatusCallback
void publish(const boost::shared_ptr< M > &message) const
boost::shared_ptr< camera_info_manager::CameraInfoManager > depth_info_manager_
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
bool subscriber_connected_
ros::Publisher confidence_pub_
void round_to_increment_double(double ¶m, double increment)
boost::shared_ptr< camera_info_manager::CameraInfoManager > intensity_info_manager_
int main(int argc, char *argv[])
ros::Publisher depth_pub_
ros::Publisher depth_ci_pub_
void round_to_increment_int(int ¶m, int increment)
ros::Publisher intensity_ci_pub_
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
const std::string TYPE_16UC1
ros::Publisher cloud_pub_
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
#define ROS_WARN_STREAM(args)
uint32_t getNumSubscribers() const
#define ROS_INFO_STREAM(args)
bool publish(const BufferParts &parts, ros::Time acquisition_time)
bool getParam(const std::string &key, std::string &s) const
ros::Publisher intensity_pub_
ros::Publisher confidence_ci_pub_
#define ROS_ERROR_STREAM(args)
ROSCPP_DECL void spinOnce()
sensor_msgs::ImagePtr toImageMsg() const
void toPCL(const ros::Time &stamp, pcl::uint64_t &pcl_stamp)
boost::shared_ptr< camera_info_manager::CameraInfoManager > confidence_info_manager_
void update_config(basler_tof::BaslerToFConfig &new_config, uint32_t level)