DTL_ROS.cpp
Go to the documentation of this file.
00001 /*
00002  * Software License Agreement (BSD License)
00003  *
00004  * Copyright (c) 2015, IAV Automotive Engineering
00005  * All rights reserved.
00006  *
00007  * Redistribution and use in source and binary forms, with or without 
00008  * modification, are permitted provided that the following conditions are met:
00009  *
00010  * 1. Redistributions of source code must retain the above copyright notice, 
00011  *    this list of conditions and the following disclaimer.
00012  *
00013  * 2. Redistributions in binary form must reproduce the above copyright notice, 
00014  *    this list of conditions and the following disclaimer in the documentation 
00015  *    and/or other materials provided with the distribution.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
00018  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
00019  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 
00020  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 
00021  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
00022  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 
00023  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 
00024  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
00025  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 
00026  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 
00027  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00028  *
00029  */
00030 /*
00031  *  IAV Team
00032  *  http://www.iav.com
00033  *
00034  */
00035 
00036 
00037 #include "../include/DTL_ROS.h"
00038 
00039 using namespace iav_depthimage_to_laserscan;
00040 
00041 DTL_ROS::DTL_ROS(ros::NodeHandle& n, CParam& Param_1, CParam& Param_2, LSParam& laser_param): it_(n){
00042   boost::mutex::scoped_lock lock(connect_mutex_);
00043 
00044   // Initialize the parameters
00045   Param1 = Param_1;
00046   Param2 = Param_2;
00047   lsparam = laser_param;
00048   sensor_msgs::LaserScanPtr scan_msg(new sensor_msgs::LaserScan());
00049   scan_msg_united = scan_msg;
00050           
00051   // Calculate and fill the ranges for the scan_msg_united
00052   uint32_t ranges_size = lsparam.laser_rays - 1;
00053   scan_msg_united->ranges.assign(ranges_size, std::numeric_limits<float>::quiet_NaN());
00054 
00055   scan_msg_united->angle_min = lsparam.laser_min_angle;
00056   scan_msg_united->angle_max = lsparam.laser_max_angle;
00057   scan_msg_united->angle_increment = (scan_msg_united->angle_max - scan_msg_united->angle_min) / (scan_msg_united->ranges.size() - 1);;
00058   scan_msg_united->time_increment = 0.0;
00059   scan_msg_united->scan_time = 0;
00060   scan_msg_united->range_min = lsparam.laser_min_range;
00061   scan_msg_united->range_max = lsparam.laser_max_range;
00062 
00063   pub_ = n.advertise<sensor_msgs::LaserScan>("Laser_Scan", 10);
00064 
00065   image_transport::TransportHints hints("raw", ros::TransportHints(), n);
00066   sub_ = it_.subscribeCamera("image", 10, &DTL_ROS::image_callback, this, hints); //Subscribe to a synchronized image & camera info topic pair.
00067   sub_2 = it_.subscribeCamera("image2", 10, &DTL_ROS::image_callback_2, this, hints); //Subscribe to a synchronized image & camera info topic pair.
00068   
00069 }
00070 
00071 DTL_ROS::~DTL_ROS() {
00072   sub_.shutdown();
00073   sub_2.shutdown();
00074 }
00075 
00076 /*
00077 * Callbacks for image_transport
00078 *
00079 * Synchronized callback for depth image and camera info (parameters of the camera). Publishes laserscan at the end.
00080 *
00081 * @param depth_msg Image provided by image_transport.
00082 * @param info_msg CameraInfo provided by image_transport.
00083 */
00084 
00085 void DTL_ROS::image_callback(const sensor_msgs::ImageConstPtr& depth_msg, const sensor_msgs::CameraInfoConstPtr& info_msg) {
00086   // Called the function to convert the depth_msg in laser_msg
00087   sensor_msgs::LaserScanPtr scan_msg = itl.convert_msg(depth_msg, Param1, lsparam); 
00088  
00089   scan_msg_united->header = depth_msg->header; // Associates the general laser_msg header with depth_msg header of the first camera
00090   scan_msg_united->header.frame_id = lsparam.laser_output_frame_id; // Add the real frame of the laser 
00091   
00092   int index; // Index for the correct depth points
00093 
00094   // Fill the ranges for the scan_msg_united with the laser of the first camera
00095   for(int i=0; i < Param1.cam_image_width; i++) { 
00096      index = Param1.cam_index[i];
00097      scan_msg_united->ranges[index] = scan_msg->ranges[index];
00098   }
00099 
00100   // Set current time and publish over TransformBroadcaster
00101   ros::Time time = ros::Time::now();
00102   Param1.m_tf->header.stamp = time;
00103   m_TB.sendTransform(*Param1.m_tf);
00104 
00105   // Publishes the general laser scan (with informations from the laser(s))
00106   pub_.publish(scan_msg_united); 
00107 }
00108 
00109 void DTL_ROS::image_callback_2(const sensor_msgs::ImageConstPtr& depth_msg2, const sensor_msgs::CameraInfoConstPtr& info_msg2) {
00110   // Called the function to convert the depth_msg in laser_msg
00111   sensor_msgs::LaserScanPtr scan_msg_2 = itl.convert_msg(depth_msg2, Param2, lsparam); 
00112   
00113   int index; // index for the correct depth points
00114 
00115   // Fill the ranges for the scan_msg_united with the laser of the second camera
00116   for(int i=0; i < Param2.cam_image_width; i++) { 
00117      index = Param2.cam_index[i];
00118      scan_msg_united->ranges[index] = scan_msg_2->ranges[index];
00119   }
00120 
00121   // Set current time and publish over TransformBroadcaster
00122   ros::Time time = ros::Time::now();
00123   Param2.m_tf->header.stamp = time;
00124   m_TB.sendTransform(*Param2.m_tf);
00125 
00126 }


iav_depthimage_to_laserscan
Author(s): Jan Obermueller
autogenerated on Thu Jun 6 2019 20:28:38