bta_ros.hpp
Go to the documentation of this file.
00001 /******************************************************************************
00002  * Copyright (c) 2014
00003  * VoXel Interaction Design GmbH
00004  *
00005  * @author Angel Merino Sastre
00006  *
00007  * Permission is hereby granted, free of charge, to any person obtaining a copy
00008  * of this software and associated documentation files (the "Software"), to deal
00009  * in the Software without restriction, including without limitation the rights
00010  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00011  * copies of the Software, and to permit persons to whom the Software is
00012  * furnished to do so, subject to the following conditions:
00013  *
00014  * The above copyright notice and this permission notice shall be included in
00015  * all copies or substantial portions of the Software.
00016  *
00017  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00018  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00019  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00020  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00021  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00022  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00023  * THE SOFTWARE.
00024  *
00025  ******************************************************************************/
00026 
00043 #ifndef _BTA_ROS_HPP_
00044 #define _BTA_ROS_HPP_
00045 
00046 #include <bta.h>
00047 
00048 // ROS communication
00049 #include <ros/ros.h>
00050 #include <image_transport/image_transport.h>
00051 #include <camera_info_manager/camera_info_manager.h>
00052 #include <sensor_msgs/Image.h>
00053 #include <sensor_msgs/CameraInfo.h>
00054 #include <sensor_msgs/SetCameraInfo.h>
00055 #include <sensor_msgs/image_encodings.h>
00056 #include <sensor_msgs/PointCloud2.h>
00057 #include <sensor_msgs/point_cloud2_iterator.h>
00058 
00059 
00060 #include <ros/console.h>
00061 #include <tf/transform_listener.h>
00062 
00063 // PCL 
00064 #include <pcl_ros/point_cloud.h>
00065 #include <pcl/point_types.h>
00066 #include <pcl/conversions.h>
00067 
00068 // Standard libs
00069 #include <stdio.h>
00070 #include <time.h>
00071 #include <sstream>
00072 #include <string>
00073 
00074 // Dynamic reconfigure
00075 #include <bta_ros/bta_rosConfig.h>
00076 #include <dynamic_reconfigure/server.h>
00077 
00078 //static ros::Publisher int_amp,int_dis,int_rgb;
00079 
00080 namespace bta_ros {
00081 
00082         class BtaRos 
00083         {
00084 
00085                 typedef bta_ros::bta_rosConfig Config;
00086                 typedef dynamic_reconfigure::Server<Config> ReconfigureServer;
00087 
00088                 ros::NodeHandle nh_, nh_private_;
00089                 std::string nodeName_;
00090                 camera_info_manager::CameraInfoManager cim_tof_/*, *cim_rgb*/;
00091                 image_transport::ImageTransport it_;
00092                 image_transport::CameraPublisher pub_amp_, pub_dis_/*, pub_rgb*/;
00093                 ros::Publisher pub_xyz_;
00094                 //ros::Subscriber sub_amp_, sub_dis_;
00095                 boost::shared_ptr<ReconfigureServer> reconfigure_server_;
00096                 bool config_init_;
00097         
00098                 boost::mutex connect_mutex_;
00099         
00100                 // Variables needed for config
00101                 uint8_t udpDataIpAddr_[6], udpControlOutIpAddr_[6],
00102                 udpControlInIpAddr_[6], tcpDeviceIpAddr_[6];
00103                 std::string uartPortName_, calibFileName_;
00104         
00105                 BTA_Handle handle_;
00106                 BTA_Config config_;
00107                 
00117                 void callback(bta_ros::bta_rosConfig &config, uint32_t level);
00118                 
00124                 void parseConfig();
00125                 
00131                 size_t getDataSize(BTA_DataFormat dataFormat);
00132                         
00138                 std::string getDataType(BTA_DataFormat dataFormat);
00139         
00140                 public:
00141 
00151                 BtaRos(ros::NodeHandle nh_camera, ros::NodeHandle nh_private, std::string nodeName);
00152         
00158                 virtual ~BtaRos();
00159 
00165                 int initialize();
00166         
00172                 int connectCamera();
00173 
00179                 void close();
00180 
00181 
00187                 void publishData();
00188         
00189                 //void ampCb(const sensor_msgs::ImagePtr& amp);
00190                 
00191           //void disCb(const sensor_msgs::ImagePtr& dis);
00192 
00193                 static void BTA_CALLCONV infoEventCb(BTA_EventId eventId, int8_t *msg) {
00194                         ROS_DEBUG("   Callback: infoEvent (%d) %s\n", eventId, msg);
00195                 };
00196 
00197                 //Test of using camera callback
00198                 /*static void BTA_CALLCONV frameArrived(BTA_Frame *frame) {
00199 
00200                 ROS_DEBUG("   Callback: frameArrived FrameCounter %d\n", frame->frameCounter);
00201         
00202                 BTA_Status status;
00203                 uint16_t *distances;
00204                 BTA_DataFormat dataFormat;
00205                 BTA_Unit unit;
00206                 uint16_t xRes, yRes;
00207         
00208                 sensor_msgs::ImagePtr amp (new sensor_msgs::Image);
00209                 sensor_msgs::ImagePtr dis (new sensor_msgs::Image);
00210         
00211                 status = BTAgetDistances(frame, (void **)&distances, &dataFormat, &unit, &xRes, &yRes);
00212                 if (status == BTA_StatusOk) {
00213                         if (dataFormat == BTA_DataFormatUInt16) {
00214                             if (unit == BTA_UnitMillimeter) {
00215                                         dis->header.seq = frame->frameCounter;
00216                                         dis->header.stamp.sec = frame->timeStamp;
00217                                         dis->height = yRes;
00218                                         dis->width = xRes;
00219                                         dis->encoding = sensor_msgs::image_encodings::TYPE_16UC1;
00220                                         dis->step = yRes*sizeof(uint16_t);
00221                                         dis->data.resize(xRes*yRes*sizeof(uint16_t));
00222                                         memcpy ( &dis->data[0], distances, xRes*yRes*sizeof(uint16_t) );
00223                             }
00224                         }
00225                 }
00226         
00227                 uint16_t *amplitudes;
00228                 status = BTAgetAmplitudes(frame, (void **)&amplitudes, &dataFormat, &unit, &xRes, &yRes);
00229                 if (status == BTA_StatusOk) {
00230                         if (dataFormat == BTA_DataFormatUInt16) {
00231                             if (unit == BTA_UnitUnitLess) {
00232                                 dis->header.seq = frame->frameCounter;
00233                                         amp->header.stamp.sec = frame->timeStamp;
00234                                         amp->height = yRes;
00235                                         amp->width = xRes;
00236                                         amp->encoding = sensor_msgs::image_encodings::TYPE_16UC1;
00237                                         amp->step = yRes*sizeof(uint16_t);
00238                                         amp->data.resize(xRes*yRes*sizeof(uint16_t));
00239                                         memcpy ( &amp->data[0], amplitudes, xRes*yRes*sizeof(uint16_t) );
00240                             }
00241                         }
00242                 }
00243                   
00244                 / *
00245                  * Publishing the messages
00246                  * /
00247                 //int_amp.publish(amp);
00248                 //int_dis.publish(dis);
00249 
00250         };*/
00251         
00252         };
00253 }
00254 
00255 #endif
00256 


bta_ros
Author(s): Angel Merino , Simon Vogl
autogenerated on Wed Sep 16 2015 10:07:06