30 #include <opencv2/opencv.hpp> 35 #include <sensor_msgs/Image.h> 38 #include <ifm3d/camera.h> 40 #include <ifm3d/image.h> 41 #include <ifm3d/Config.h> 42 #include <ifm3d/Dump.h> 43 #include <ifm3d/Extrinsics.h> 44 #include <ifm3d/SoftOff.h> 45 #include <ifm3d/SoftOn.h> 46 #include <ifm3d/SyncClocks.h> 47 #include <ifm3d/Trigger.h> 54 std::string nn = this->
getName();
68 std::string frame_id_base;
70 if ((nn.size() > 0) && (nn.at(0) ==
'/'))
72 frame_id_base = nn.substr(1);
80 this->
np_.
param(
"xmlrpc_port", xmlrpc_port, (
int) ifm3d::DEFAULT_XMLRPC_PORT);
82 this->
np_.
param(
"schema_mask", schema_mask, (
int) ifm3d::DEFAULT_SCHEMA_MASK);
87 this->
np_.
param(
"soft_on_timeout_tolerance_secs",
89 this->
np_.
param(
"soft_off_timeout_millis",
91 this->
np_.
param(
"soft_off_timeout_tolerance_secs",
95 this->
np_.
param(
"frame_id_base", frame_id_base, frame_id_base);
97 this->
xmlrpc_port_ =
static_cast<std::uint16_t
>(xmlrpc_port);
98 this->
schema_mask_ =
static_cast<std::uint16_t
>(schema_mask);
100 this->
frame_id_ = frame_id_base +
"_link";
107 this->
np_.
advertise<pcl::PointCloud<ifm3d::PointT> >(
"cloud", 1);
111 this->
conf_pub_ = this->
it_->advertise(
"confidence", 1);
117 this->
np_.
advertise<sensor_msgs::Image>(
"unit_vectors", 1,
true);
120 this->
np_.
advertise<ifm3d::Extrinsics>(
"extrinsics", 1);
128 std::placeholders::_1,
129 std::placeholders::_2));
134 std::placeholders::_1,
135 std::placeholders::_2));
139 ifm3d::Trigger::Response>
141 std::placeholders::_1,
142 std::placeholders::_2));
146 ifm3d::SoftOff::Response>
148 std::placeholders::_1,
149 std::placeholders::_2));
153 ifm3d::SoftOn::Response>
155 std::placeholders::_1,
156 std::placeholders::_2));
160 ifm3d::SyncClocks::Response>
162 std::placeholders::_1,
163 std::placeholders::_2));
177 ifm3d::Dump::Response& res)
179 std::lock_guard<std::mutex> lock(this->
mutex_);
184 res.config = this->
cam_->ToJSONStr();
186 catch (
const ifm3d::error_t& ex)
188 res.status = ex.code();
191 catch (
const std::exception& std_ex)
211 ifm3d::Config::Response& res)
213 std::lock_guard<std::mutex> lock(this->
mutex_);
219 this->
cam_->FromJSONStr(req.json);
221 catch (
const ifm3d::error_t& ex)
223 res.status = ex.code();
226 catch (
const std::exception& std_ex)
229 res.msg = std_ex.what();
234 res.msg =
"Unknown error in `Config'";
247 ifm3d::Trigger::Response& res)
249 std::lock_guard<std::mutex> lock(this->
mutex_);
254 this->
fg_->SWTrigger();
256 catch (
const ifm3d::error_t& ex)
258 res.status = ex.code();
266 ifm3d::SyncClocks::Response& res)
268 std::lock_guard<std::mutex> lock(this->
mutex_);
275 this->
cam_->SetCurrentTime(-1);
277 catch (
const ifm3d::error_t& ex)
279 res.status = ex.code();
290 ifm3d::SoftOff::Response& res)
292 std::lock_guard<std::mutex> lock(this->
mutex_);
296 int active_application = 0;
300 active_application = this->
cam_->ActiveApplication();
301 if (active_application > 0)
306 {{{
"Index", std::to_string(active_application)},
309 static_cast<int>(ifm3d::Camera::trigger_mode::SW))}}}
313 this->
cam_->FromJSON(dict);
321 catch (
const ifm3d::error_t& ex)
323 res.status = ex.code();
333 ifm3d::SoftOn::Response& res)
335 std::lock_guard<std::mutex> lock(this->
mutex_);
339 int active_application = 0;
343 active_application = this->
cam_->ActiveApplication();
344 if (active_application > 0)
349 {{{
"Index", std::to_string(active_application)},
352 static_cast<int>(ifm3d::Camera::trigger_mode::FREE_RUN))}}}
356 this->
cam_->FromJSON(dict);
364 catch (
const ifm3d::error_t& ex)
366 res.status = ex.code();
377 std::lock_guard<std::mutex> lock(this->
mutex_);
394 this->
fg_ = std::make_shared<ifm3d::FrameGrabber>(this->
cam_, mask);
397 this->
im_ = std::make_shared<ifm3d::ImageBuffer>();
401 catch (
const ifm3d::error_t& ex)
416 std::lock_guard<std::mutex> lock(this->
mutex_);
423 catch (
const ifm3d::error_t& ex)
435 std::unique_lock<std::mutex> lock(this->
mutex_, std::defer_lock);
448 this->
cam_->SetCurrentTime(-1);
450 catch (
const ifm3d::error_t& ex)
471 pcl::PointCloud<ifm3d::PointT>::Ptr
472 cloud(
new pcl::PointCloud<ifm3d::PointT>());
474 cv::Mat confidence_img;
475 cv::Mat distance_img;
476 cv::Mat amplitude_img;
478 cv::Mat raw_amplitude_img;
479 cv::Mat good_bad_pixels_img;
481 std::vector<float> extrinsics(6);
487 bool got_uvec =
false;
522 std_msgs::Header head = std_msgs::Header();
525 std::chrono::duration_cast<std::chrono::duration<
double, std::ratio<1>>>
526 (this->
im_->TimeStamp().time_since_epoch()).count());
530 ROS_WARN_ONCE(
"Camera's time is not up to date, therefore header's " 531 "timestamps will be the reception time and not capture time. " 532 "Please update the camera's time if you need the capture time.");
536 std_msgs::Header optical_head = std_msgs::Header();
537 optical_head.stamp = head.stamp;
545 sensor_msgs::ImagePtr uvec_msg =
548 this->
im_->UnitVectors()).toImageMsg();
552 ROS_INFO(
"Got unit vectors, restarting framegrabber with mask: %d",
557 ROS_WARN(
"Could not re-initialize pixel stream!");
573 pcl::copyPointCloud(*(this->
im_->Cloud().get()), *cloud);
574 xyz_img = this->
im_->XYZImage();
575 confidence_img = this->
im_->ConfidenceImage();
576 distance_img = this->
im_->DistanceImage();
577 amplitude_img = this->
im_->AmplitudeImage();
578 raw_amplitude_img = this->
im_->RawAmplitudeImage();
579 extrinsics = this->
im_->Extrinsics();
588 sensor_msgs::ImagePtr confidence_msg =
594 if ((this->
schema_mask_ & ifm3d::IMG_CART) == ifm3d::IMG_CART)
599 sensor_msgs::ImagePtr xyz_image_msg =
601 xyz_img.type() == CV_32FC3 ?
602 enc::TYPE_32FC3 : enc::TYPE_16SC3,
603 xyz_img).toImageMsg();
607 if ((this->
schema_mask_ & ifm3d::IMG_RDIS) == ifm3d::IMG_RDIS)
609 sensor_msgs::ImagePtr distance_msg =
611 distance_img.type() == CV_32FC1 ?
612 enc::TYPE_32FC1 : enc::TYPE_16UC1,
613 distance_img).toImageMsg();
617 if ((this->
schema_mask_ & ifm3d::IMG_AMP) == ifm3d::IMG_AMP)
619 sensor_msgs::ImagePtr amplitude_msg =
621 amplitude_img.type() == CV_32FC1 ?
622 enc::TYPE_32FC1 : enc::TYPE_16UC1,
623 amplitude_img).toImageMsg();
627 if ((this->
schema_mask_ & ifm3d::IMG_RAMP) == ifm3d::IMG_RAMP)
629 sensor_msgs::ImagePtr raw_amplitude_msg =
631 raw_amplitude_img.type() == CV_32FC1 ?
632 enc::TYPE_32FC1 : enc::TYPE_16UC1,
633 raw_amplitude_img).toImageMsg();
645 good_bad_pixels_img = cv::Mat::ones(confidence_img.rows,
648 cv::bitwise_and(confidence_img, good_bad_pixels_img,
649 good_bad_pixels_img);
650 sensor_msgs::ImagePtr good_bad_msg =
659 ifm3d::Extrinsics extrinsics_msg;
660 extrinsics_msg.header = optical_head;
663 extrinsics_msg.tx = extrinsics.at(0);
664 extrinsics_msg.ty = extrinsics.at(1);
665 extrinsics_msg.tz = extrinsics.at(2);
666 extrinsics_msg.rot_x = extrinsics.at(3);
667 extrinsics_msg.rot_y = extrinsics.at(4);
668 extrinsics_msg.rot_z = extrinsics.at(5);
670 catch (
const std::out_of_range& ex)
672 ROS_WARN(
"out-of-range error fetching extrinsics");
float frame_latency_thresh_
#define NODELET_INFO_STREAM(...)
bool Config(ifm3d::Config::Request &req, ifm3d::Config::Response &res)
double soft_off_timeout_tolerance_secs_
void publish(const boost::shared_ptr< M > &message) const
ros::Publisher cloud_pub_
ros::ServiceServer soft_off_srv_
image_transport::Publisher conf_pub_
std::uint16_t schema_mask_
ifm3d::ImageBuffer::Ptr im_
ros::ServiceServer dump_srv_
PLUGINLIB_EXPORT_CLASS(BAGReader, nodelet::Nodelet)
const std::string & getName() const
#define NODELET_WARN_STREAM(...)
image_transport::Publisher good_bad_pub_
ServiceServer advertiseService(const std::string &service, bool(T::*srv_func)(MReq &, MRes &), T *obj)
image_transport::Publisher raw_amplitude_pub_
int soft_on_timeout_millis_
ros::ServiceServer sync_clocks_srv_
image_transport::Publisher amplitude_pub_
ros::NodeHandle & getMTPrivateNodeHandle() const
ifm3d::FrameGrabber::Ptr fg_
bool InitStructures(std::uint16_t mask)
ros::Publisher extrinsics_pub_
double soft_on_timeout_tolerance_secs_
image_transport::Publisher xyz_image_pub_
void publish(const sensor_msgs::Image &message) const
image_transport::Publisher distance_pub_
#define ROS_WARN_ONCE(...)
ros::ServiceServer trigger_srv_
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
bool Trigger(ifm3d::Trigger::Request &req, ifm3d::Trigger::Response &res)
ros::Timer publoop_timer_
Timer createTimer(Rate r, Handler h, Obj o, bool oneshot=false, bool autostart=true) const
ros::ServiceServer soft_on_srv_
bool Dump(ifm3d::Dump::Request &req, ifm3d::Dump::Response &res)
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
int soft_off_timeout_millis_
bool SoftOff(ifm3d::SoftOff::Request &req, ifm3d::SoftOff::Response &res)
std::uint16_t xmlrpc_port_
virtual void onInit() override
double timeout_tolerance_secs_
bool SoftOn(ifm3d::SoftOn::Request &req, ifm3d::SoftOn::Response &res)
bool SyncClocks(ifm3d::SyncClocks::Request &req, ifm3d::SyncClocks::Response &res)
std::string optical_frame_id_
ros::ServiceServer config_srv_
bool assume_sw_triggered_
std::unique_ptr< image_transport::ImageTransport > it_
sensor_msgs::ImagePtr toImageMsg() const
void toPCL(const ros::Time &stamp, pcl::uint64_t &pcl_stamp)