36 #include <sensor_msgs/CameraInfo.h> 38 #include "hldstof/tof.h" 39 #include <std_srvs/Empty.h> 40 #include <std_srvs/SetBool.h> 41 #include "hls_lfom_tof_driver/FarSignalCutoff.h" 42 #include "hls_lfom_tof_driver/LowSignalCutoff.h" 43 #include "hls_lfom_tof_driver/DistanceMode.h" 58 bool set_far_signal_cutoff(hls_lfom_tof_driver::FarSignalCutoff::Request &req, hls_lfom_tof_driver::FarSignalCutoff::Response &res)
65 bool set_low_signal_cutoff(hls_lfom_tof_driver::LowSignalCutoff::Request &req, hls_lfom_tof_driver::LowSignalCutoff::Response &res)
78 res.message =
"Set Edge Signal Cutoff Enable";
84 res.message =
"Set Edge Signal Cutoff Disable";
88 bool set_distance_mode(hls_lfom_tof_driver::DistanceMode::Request &req, hls_lfom_tof_driver::DistanceMode::Response &res)
95 int main(
int argc,
char* argv[])
101 sensor_msgs::PointCloud2 cloud;
102 sensor_msgs::CameraInfoPtr msgCameraInfo;
103 sensor_msgs::ImagePtr msgDepth;
104 sensor_msgs::ImagePtr msgDepthRaw;
105 sensor_msgs::ImagePtr msgIr;
106 std::string file_name;
107 std::string cloud_topic;
120 Result ret = Result::OK;
123 const TofInfo* ptofinfo =
nullptr;
129 nh.
getParam(
"ini_path", tm.inifilepath);
130 if ((ret = tm.Open()) != Result::OK) {
131 ROS_ERROR_STREAM(
"HLDS 3D TOF initialization file \"" << tm.inifilepath <<
"tof.ini\" invalid.");
136 numoftof = tm.GetTofList(&ptofinfo);
150 if (tof.Open(ptofinfo[0]) != Result::OK){
155 if (tof.GetVersion(&vfpga, &vosv, &vroot) == Result::OK) {
156 ROS_INFO_STREAM(
"HLDS 3D TOF version" <<
":" << vfpga.c_str() <<
":" << vosv.c_str() <<
":" << vroot.c_str() );
159 if (tof.tofinfo.tofver == TofVersion::TOFv1) {
161 }
else if(tof.tofinfo.tofver == TofVersion::TOFv2) {
168 if (tm.Close() != Result::OK){
174 bool edge_signal_cutoff;
175 int location_x, location_y, location_z;
176 int angle_x, angle_y, angle_z;
177 int low_signal_cutoff, ir_gain;
179 double far_signal_cutoff;
181 std::string camera_pixel, distance_mode, frame_rate, camera_mode;
183 nh.
param(
"frame_id", frame_id, std::string(
"base_link"));
184 nh.
param(
"cloud_topic", cloud_topic, std::string(
"cloud"));
186 nh.
param(
"camera_mode", camera_mode, std::string(
"Depth_Ir"));
187 nh.
param(
"sensor_location_x", location_x, 0);
188 nh.
param(
"sensor_location_y", location_y, 0);
189 nh.
param(
"sensor_location_z", location_z, 0);
190 nh.
param(
"sensor_angle_x", angle_x, 0);
191 nh.
param(
"sensor_angle_y", angle_y, 0);
192 nh.
param(
"sensor_angle_z", angle_z, 0);
194 nh.
param(
"edge_signal_cutoff", edge_signal_cutoff,
true);
195 nh.
param(
"low_signal_cutoff", low_signal_cutoff, 20);
196 nh.
param(
"far_signal_cutoff", far_signal_cutoff, 0.0);
198 nh.
param(
"camera_pixel", camera_pixel, std::string(
"320x240"));
199 nh.
param(
"ir_gain", ir_gain, 8);
200 nh.
param(
"distance_mode", distance_mode, std::string(
"dm_1_0x"));
201 nh.
param(
"frame_rate", frame_rate, std::string(
"fr30fps"));
204 if(camera_mode ==
"Depth_Ir") {
205 if (tof.SetCameraMode(CameraMode::Depth_Ir) != Result::OK){
206 ROS_INFO_STREAM(
"HLDS 3D TOF ID " << tof.tofinfo.tofid <<
" Set Camera Mode Error");
210 else if(camera_mode ==
"CameraModeDepth") {
211 if (tof.SetCameraMode(CameraMode::CameraModeDepth) != Result::OK){
212 ROS_INFO_STREAM(
"HLDS 3D TOF ID " << tof.tofinfo.tofid <<
" Set Camera Mode Error");
216 else if(camera_mode ==
"CameraModeIr") {
217 if (tof.SetCameraMode(CameraMode::CameraModeIr) != Result::OK){
218 ROS_INFO_STREAM(
"HLDS 3D TOF ID " << tof.tofinfo.tofid <<
" Set Camera Mode Error");
224 if(camera_pixel ==
"640x480") {
225 if (tof.SetCameraPixel(CameraPixel::w640h480) != Result::OK){
227 ROS_INFO_STREAM(
"HLDS 3D TOF ID " << tof.tofinfo.tofid <<
" Set Camera Pixel Error");
231 else if(camera_pixel ==
"320x240") {
232 if (tof.SetCameraPixel(CameraPixel::w320h240) != Result::OK){
234 ROS_INFO_STREAM(
"HLDS 3D TOF ID " << tof.tofinfo.tofid <<
" Set Camera Pixel Error");
238 else if(camera_pixel ==
"160x120") {
239 if (tof.SetCameraPixel(CameraPixel::w160h120) != Result::OK){
240 ROS_INFO_STREAM(
"HLDS 3D TOF ID " << tof.tofinfo.tofid <<
" Set Camera Pixel Error");
244 else if(camera_pixel ==
"80x60") {
245 if (tof.SetCameraPixel(CameraPixel::w80h60) != Result::OK){
246 ROS_INFO_STREAM(
"HLDS 3D TOF ID " << tof.tofinfo.tofid <<
" Set Camera Pixel Error");
250 else if(camera_pixel ==
"64x48") {
251 if (tof.SetCameraPixel(CameraPixel::w64h48) != Result::OK){
252 ROS_INFO_STREAM(
"HLDS 3D TOF ID " << tof.tofinfo.tofid <<
" Set Camera Pixel Error");
256 else if(camera_pixel ==
"40x30") {
257 if (tof.SetCameraPixel(CameraPixel::w40h30) != Result::OK){
258 ROS_INFO_STREAM(
"HLDS 3D TOF ID " << tof.tofinfo.tofid <<
" Set Camera Pixel Error");
262 else if(camera_pixel ==
"32x24") {
263 if (tof.SetCameraPixel(CameraPixel::w32h24) != Result::OK){
264 ROS_INFO_STREAM(
"HLDS 3D TOF ID " << tof.tofinfo.tofid <<
" Set Camera Pixel Error");
270 if(distance_mode ==
"dm_2_0x") {
271 if (tof.SetDistanceMode(DistanceMode::dm_2_0x) != Result::OK){
272 ROS_INFO_STREAM(
"HLDS 3D TOF ID " << tof.tofinfo.tofid <<
" Set distance mode Error");
276 else if(distance_mode ==
"dm_1_5x") {
277 if (tof.SetDistanceMode(DistanceMode::dm_1_5x) != Result::OK){
278 ROS_INFO_STREAM(
"HLDS 3D TOF ID " << tof.tofinfo.tofid <<
" Set distance mode Error");
282 else if(distance_mode ==
"dm_1_0x") {
283 if (tof.SetDistanceMode(DistanceMode::dm_1_0x) != Result::OK){
284 ROS_INFO_STREAM(
"HLDS 3D TOF ID " << tof.tofinfo.tofid <<
" Set distance mode Error");
288 else if(distance_mode ==
"dm_0_5x") {
289 if (tof.SetDistanceMode(DistanceMode::dm_0_5x) != Result::OK){
290 ROS_INFO_STREAM(
"HLDS 3D TOF ID " << tof.tofinfo.tofid <<
" Set distance mode Error");
296 if(frame_rate ==
"fr30fps") {
297 if (tof.SetFrameRate(FrameRate::fr30fps) != Result::OK){
298 ROS_INFO_STREAM(
"HLDS 3D TOF ID " << tof.tofinfo.tofid <<
" Set frame rate Error");
302 else if(frame_rate ==
"fr16fps") {
303 if (tof.SetFrameRate(FrameRate::fr16fps) != Result::OK){
304 ROS_INFO_STREAM(
"HLDS 3D TOF ID " << tof.tofinfo.tofid <<
" Set frame rate Error");
308 else if(frame_rate ==
"fr8fps") {
309 if (tof.SetFrameRate(FrameRate::fr8fps) != Result::OK){
310 ROS_INFO_STREAM(
"HLDS 3D TOF ID " << tof.tofinfo.tofid <<
" Set frame rate Error");
314 else if(frame_rate ==
"fr4fps") {
315 if (tof.SetFrameRate(FrameRate::fr4fps) != Result::OK){
316 ROS_INFO_STREAM(
"HLDS 3D TOF ID " << tof.tofinfo.tofid <<
" Set frame rate Error");
320 else if(frame_rate ==
"fr2fps") {
321 if (tof.SetFrameRate(FrameRate::fr2fps) != Result::OK){
322 ROS_INFO_STREAM(
"HLDS 3D TOF ID " << tof.tofinfo.tofid <<
" Set frame rate Error");
326 else if(frame_rate ==
"fr1fps") {
327 if (tof.SetFrameRate(FrameRate::fr1fps) != Result::OK){
328 ROS_INFO_STREAM(
"HLDS 3D TOF ID " << tof.tofinfo.tofid <<
" Set frame rate Error");
334 if (tof.SetIrGain(ir_gain) != Result::OK){
335 ROS_INFO_STREAM(
"HLDS 3D TOF ID " << tof.tofinfo.tofid <<
" Set Ir gain Error");
340 if (tof.SetLowSignalCutoff(low_signal_cutoff) != Result::OK){
341 ROS_INFO_STREAM(
"HLDS 3D TOF ID " << tof.tofinfo.tofid <<
" Low Signal Cutoff Error");
346 if (tof.SetFarSignalCutoff(far_signal_cutoff) != Result::OK){
347 ROS_INFO_STREAM(
"HLDS 3D TOF ID " << tof.tofinfo.tofid <<
" Far Signal Cutoff Error");
352 if(edge_signal_cutoff ==
true){
353 if (tof.SetEdgeSignalCutoff(EdgeSignalCutoff::Enable) != Result::OK){
354 ROS_INFO_STREAM(
"HLDS 3D TOF ID " << tof.tofinfo.tofid <<
" Edge Signal Cutoff Error");
358 else if(edge_signal_cutoff ==
false){
359 if (tof.SetEdgeSignalCutoff(EdgeSignalCutoff::Disable) != Result::OK){
360 ROS_INFO_STREAM(
"HLDS 3D TOF ID " << tof.tofinfo.tofid <<
" Edge Signal Cutoff Error");
366 if (tof.SetAttribute(location_x, location_y, location_z, angle_x, angle_y, angle_z) != Result::OK){
367 ROS_INFO_STREAM(
"HLDS 3D TOF ID " << tof.tofinfo.tofid <<
" Set Camera Position Error");
372 if (tof.Run() != Result::OK){
373 ROS_INFO_STREAM(
"HLDS 3D TOF ID " << tof.tofinfo.tofid <<
" Run Error");
378 frame.CreateColorTable(0, 65530);
381 camerainfoPublisher = nh.
advertise<sensor_msgs::CameraInfo> (
"/camera_info", 1);
382 if(camera_mode !=
"CameraModeIr") {
383 cloudPublisher = nh.
advertise<pcl::PointCloud<pcl::PointXYZ> > (cloud_topic, 1);
385 if((camera_mode ==
"Depth_Ir")||(camera_mode ==
"CameraModeIr")) {
386 irPublisher = nh.
advertise<sensor_msgs::Image> (
"/image_ir", 1);
388 if(camera_mode !=
"CameraModeIr") {
389 depthPublisher = nh.
advertise<sensor_msgs::Image> (
"/image_depth", 1);
390 depthrawPublisher = nh.
advertise<sensor_msgs::Image> (
"/image_depth_raw", 1);
418 if(tof.SetEdgeSignalCutoff(EdgeSignalCutoff::Disable) == Result::OK)
419 ROS_INFO(
"Edge Signal Cutoff disabled");
425 if(tof.SetEdgeSignalCutoff(EdgeSignalCutoff::Enable) == Result::OK)
426 ROS_INFO(
"Edge Signal Cutoff enabled");
433 if(tof.SetDistanceMode(DistanceMode::dm_2_0x) == Result::OK)
434 ROS_INFO(
"Distance Mode : dm_2_0x");
437 if(tof.SetDistanceMode(DistanceMode::dm_1_5x) == Result::OK)
438 ROS_INFO(
"Distance Mode : dm_1_5x");
441 if(tof.SetDistanceMode(DistanceMode::dm_1_0x) == Result::OK)
442 ROS_INFO(
"Distance Mode : dm_1_0x");
445 if(tof.SetDistanceMode(DistanceMode::dm_0_5x) == Result::OK)
446 ROS_INFO(
"Distance Mode : dm_0_5x");
454 tof.GetFrameStatus(&frameno, ×tamp);
455 if (frameno != frame.framenumber) {
460 if(camera_mode ==
"Depth_Ir") {
461 ret = tof.ReadFrame(&frame, &frameir);
463 else if(camera_mode ==
"CameraModeDepth") {
464 ret = tof.ReadFrame(&frame);
466 else if(camera_mode ==
"CameraModeIr") {
467 ret = tof.ReadFrame(&frameir);
469 if (ret != Result::OK) {
473 if(camera_mode !=
"CameraModeIr") {
475 frame3d.Convert(&frame);
478 frame3d.Rotate(angle_x, angle_y, angle_z);
484 msgCameraInfo = sensor_msgs::CameraInfoPtr(
new sensor_msgs::CameraInfo);
485 msgCameraInfo->header.frame_id = frame_id;
486 msgCameraInfo->header.stamp = t;
487 msgCameraInfo->height = frame.height;
488 msgCameraInfo->width = frame.width;
489 msgCameraInfo->K[0] = frame.height;
490 msgCameraInfo->K[1] = 0;
491 msgCameraInfo->K[2] = (frame.width/2)-0.5;
492 msgCameraInfo->K[3] = 0;
493 msgCameraInfo->K[4] = frame.height;
494 msgCameraInfo->K[5] = (frame.width*(3./8.))-0.5;
495 msgCameraInfo->K[6] = 0;
496 msgCameraInfo->K[7] = 0;
497 msgCameraInfo->K[8] = 1;
498 msgCameraInfo->R[0] = 1;
499 msgCameraInfo->R[1] = 0;
500 msgCameraInfo->R[2] = 0;
501 msgCameraInfo->R[3] = 0;
502 msgCameraInfo->R[4] = 1;
503 msgCameraInfo->R[5] = 0;
504 msgCameraInfo->R[6] = 0;
505 msgCameraInfo->R[7] = 0;
506 msgCameraInfo->R[8] = 1;
507 msgCameraInfo->P[0] = frame.height;
508 msgCameraInfo->P[1] = 0;
509 msgCameraInfo->P[2] = (frame.width/2)-0.5;
510 msgCameraInfo->P[3] = 0;
511 msgCameraInfo->P[4] = 0;
512 msgCameraInfo->P[5] = frame.height;
513 msgCameraInfo->P[6] = (frame.width*(3./8.))-0.5;
514 msgCameraInfo->P[7] = 0;
515 msgCameraInfo->P[8] = 0;
516 msgCameraInfo->P[9] = 0;
517 msgCameraInfo->P[10] = 1;
518 msgCameraInfo->P[11] = 0;
519 msgCameraInfo->distortion_model =
"plumb_bob";
520 msgCameraInfo->D.resize(5);
521 msgCameraInfo->D[0] = 0;
522 msgCameraInfo->D[1] = 0;
523 msgCameraInfo->D[2] = 0;
524 msgCameraInfo->D[3] = 0;
525 msgCameraInfo->D[4] = 0;
529 msgIr = sensor_msgs::ImagePtr(
new sensor_msgs::Image);
530 msgIr->header.stamp = t;
531 msgIr->header.frame_id = frame_id;
532 msgIr->height = frameir.height;
533 msgIr->width = frameir.width;
534 msgIr->is_bigendian =
false;
536 msgIr->data.resize(frameir.pixel);
537 msgIr->step = frameir.width;
540 msgDepth = sensor_msgs::ImagePtr(
new sensor_msgs::Image);
541 msgDepth->header.stamp = t;
542 msgDepth->header.frame_id = frame_id;
543 msgDepth->height = frame.height;
544 msgDepth->width = frame.width;
545 msgDepth->is_bigendian =
false;
547 msgDepth->data.resize(frame.pixel*3);
548 msgDepth->step = frame.width*3;
551 msgDepthRaw = sensor_msgs::ImagePtr(
new sensor_msgs::Image);
552 msgDepthRaw->header.stamp = t;
553 msgDepthRaw->header.frame_id = frame_id;
554 msgDepthRaw->height = frame.height;
555 msgDepthRaw->width = frame.width;
556 msgDepthRaw->is_bigendian =
false;
558 msgDepthRaw->step = (uint32_t)(
sizeof(
float) * frame.width);
559 msgDepthRaw->data.resize(
sizeof(
float)*frame.pixel);
562 pcl::PointCloud<pcl::PointXYZ>::Ptr ptCloud(
new pcl::PointCloud<pcl::PointXYZ>());
564 ptCloud->header.frame_id = frame_id;
565 ptCloud->width = frame3d.width;
566 ptCloud->height = frame3d.height;
567 ptCloud->is_dense =
false;
568 ptCloud->points.resize(
sizeof(uint16_t)*frame3d.pixel);
570 float *itD = (
float *)&msgDepthRaw->data[0];
572 if(camera_mode !=
"CameraModeIr"){
573 pixel_count = frame.pixel;
575 pixel_count = frameir.pixel;
577 for (
int i = 0; i < pixel_count; i++, ++itD) {
578 pcl::PointXYZ &point = ptCloud->points[i];
580 temp_depth = (float)(frame.CalculateLength(frame.databuf[i]));
581 if(frame3d.frame3d[i].z == 0) frame3d.frame3d[i].z = std::numeric_limits<float>::quiet_NaN();
583 point.x = frame3d.frame3d[i].x/1000.0;
584 point.y = frame3d.frame3d[i].y/1000.0;
585 point.z = frame3d.frame3d[i].z/1000.0;
588 msgIr->data[i] = frameir.databuf[i]/256.0;
591 msgDepth->data[3*i] = frame.ColorTable[2][frame.databuf[i]];
592 msgDepth->data[3*i+1] = frame.ColorTable[1][frame.databuf[i]];
593 msgDepth->data[3*i+2] = frame.ColorTable[0][frame.databuf[i]];
596 *itD = (float)point.z;
600 camerainfoPublisher.
publish(msgCameraInfo);
601 if(camera_mode !=
"CameraModeIr") {
602 cloudPublisher.
publish(*ptCloud);
603 depthPublisher.
publish(msgDepth);
604 depthrawPublisher.
publish(msgDepthRaw);
606 if((camera_mode ==
"Depth_Ir")||(camera_mode ==
"CameraModeIr")) {
614 if (tof.Stop() != Result::OK || tof.Close() != Result::OK) {
615 ROS_INFO_STREAM(
"HLDS 3D TOF ID " << tof.tofinfo.tofid <<
" Stop Error");
bool set_low_signal_cutoff(hls_lfom_tof_driver::LowSignalCutoff::Request &req, hls_lfom_tof_driver::LowSignalCutoff::Response &res)
void publish(const boost::shared_ptr< M > &message) const
int main(int argc, char *argv[])
bool set_edge_signal_cutoff(std_srvs::SetBool::Request &req, std_srvs::SetBool::Response &res)
std::string resolveName(const std::string &name, bool remap=true) const
bool bEdgeSignalCutoff_enable
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
ServiceServer advertiseService(const std::string &service, bool(T::*srv_func)(MReq &, MRes &), T *obj)
bool set_distance_mode(hls_lfom_tof_driver::DistanceMode::Request &req, hls_lfom_tof_driver::DistanceMode::Response &res)
int bLowSignalCutoff_value
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
const std::string TYPE_32FC1
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
#define ROS_INFO_STREAM(args)
string bDistanceMode_value
bool getParam(const std::string &key, std::string &s) const
double bFarSignalCutoff_value
bool set_far_signal_cutoff(hls_lfom_tof_driver::FarSignalCutoff::Request &req, hls_lfom_tof_driver::FarSignalCutoff::Response &res)
#define ROS_ERROR_STREAM(args)
bool bEdgeSignalCutoff_disable
ROSCPP_DECL void spinOnce()
void toPCL(const ros::Time &stamp, pcl::uint64_t &pcl_stamp)