bta_tof_driver.hpp
Go to the documentation of this file.
00001 /******************************************************************************
00002  * Copyright (c) 2016
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_TOF_DRIVER_HPP_
00044 #define _BTA_TOF_DRIVER_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 #include <tf2_ros/static_transform_broadcaster.h>
00059 #include <geometry_msgs/TransformStamped.h>
00060 
00061 #include <ros/console.h>
00062 #include <tf/transform_listener.h>
00063 
00064 // PCL 
00065 #include <pcl_ros/point_cloud.h>
00066 #include <pcl/point_types.h>
00067 #include <pcl/conversions.h>
00068 
00069 // Standard libs
00070 #include <stdio.h>
00071 #include <time.h>
00072 #include <sstream>
00073 #include <string>
00074 
00075 // Dynamic reconfigure
00076 #include <bta_tof_driver/bta_tof_driverConfig.h>
00077 #include <dynamic_reconfigure/server.h>
00078 
00079 //static ros::Publisher int_amp,int_dis,int_rgb;
00080 
00081 namespace bta_tof_driver {
00082 
00083 class BtaRos
00084 {
00085 
00086     typedef bta_tof_driver::bta_tof_driverConfig Config;
00087     typedef dynamic_reconfigure::Server<Config> ReconfigureServer;
00088 
00089 public:
00090 
00100     BtaRos(ros::NodeHandle nh_camera, ros::NodeHandle nh_private, std::string nodeName);
00101 
00107     virtual ~BtaRos();
00108 
00114     int initialize();
00115 
00121     int connectCamera();
00122 
00128     void close();
00129 
00130 
00136     void publishData();
00137 
00138     //void ampCb(const sensor_msgs::ImagePtr& amp);
00139 
00140     //void disCb(const sensor_msgs::ImagePtr& dis);
00141 
00142     static void BTA_CALLCONV infoEventCb(BTA_EventId eventId, int8_t *msg) {
00143         ROS_DEBUG("   Callback: infoEvent (%d) %s\n", eventId, msg);
00144     }
00145 
00146 private:
00147     ros::NodeHandle nh_, nh_private_;
00148     std::string nodeName_;
00149     camera_info_manager::CameraInfoManager cim_tof_/*, *cim_rgb*/;
00150     image_transport::ImageTransport it_;
00151     image_transport::CameraPublisher pub_amp_, pub_dis_/*, pub_rgb*/;
00152     tf2_ros::StaticTransformBroadcaster pub_tf;
00153     geometry_msgs::TransformStamped transformStamped;
00154     ros::Publisher pub_xyz_;
00155     //ros::Subscriber sub_amp_, sub_dis_;
00156     boost::shared_ptr<ReconfigureServer> reconfigure_server_;
00157     bool config_init_;
00158 
00159     boost::mutex connect_mutex_;
00160 
00161     // Variables needed for config
00162     uint8_t udpDataIpAddr_[6], udpControlOutIpAddr_[6],
00163     udpControlInIpAddr_[6], tcpDeviceIpAddr_[6];
00164     std::string uartPortName_, calibFileName_;
00165 
00166     sensor_msgs::PointCloud2Ptr _xyz;
00167 
00168     BTA_Handle handle_;
00169     BTA_Config config_;
00170 
00180     void callback(bta_tof_driver::bta_tof_driverConfig &config, uint32_t level);
00181 
00187     void parseConfig();
00188 
00194     size_t getDataSize(BTA_DataFormat dataFormat);
00195 
00201     std::string getDataType(BTA_DataFormat dataFormat);
00202 
00208     float getUnit2Meters(BTA_Unit unit);
00209 
00210     //Test of using camera callback
00211     /*static void BTA_CALLCONV frameArrived(BTA_Frame *frame) {
00212 
00213         ROS_DEBUG("   Callback: frameArrived FrameCounter %d\n", frame->frameCounter);
00214 
00215         BTA_Status status;
00216         uint16_t *distances;
00217         BTA_DataFormat dataFormat;
00218         BTA_Unit unit;
00219         uint16_t xRes, yRes;
00220 
00221         sensor_msgs::ImagePtr amp (new sensor_msgs::Image);
00222         sensor_msgs::ImagePtr dis (new sensor_msgs::Image);
00223 
00224         status = BTAgetDistances(frame, (void **)&distances, &dataFormat, &unit, &xRes, &yRes);
00225         if (status == BTA_StatusOk) {
00226                 if (dataFormat == BTA_DataFormatUInt16) {
00227                     if (unit == BTA_UnitMillimeter) {
00228                                 dis->header.seq = frame->frameCounter;
00229                                 dis->header.stamp.sec = frame->timeStamp;
00230                                 dis->height = yRes;
00231                                 dis->width = xRes;
00232                                 dis->encoding = sensor_msgs::image_encodings::TYPE_16UC1;
00233                                 dis->step = yRes*sizeof(uint16_t);
00234                                 dis->data.resize(xRes*yRes*sizeof(uint16_t));
00235                                 memcpy ( &dis->data[0], distances, xRes*yRes*sizeof(uint16_t) );
00236                     }
00237                 }
00238         }
00239 
00240         uint16_t *amplitudes;
00241         status = BTAgetAmplitudes(frame, (void **)&amplitudes, &dataFormat, &unit, &xRes, &yRes);
00242         if (status == BTA_StatusOk) {
00243                 if (dataFormat == BTA_DataFormatUInt16) {
00244                     if (unit == BTA_UnitUnitLess) {
00245                         dis->header.seq = frame->frameCounter;
00246                                 amp->header.stamp.sec = frame->timeStamp;
00247                                 amp->height = yRes;
00248                                 amp->width = xRes;
00249                                 amp->encoding = sensor_msgs::image_encodings::TYPE_16UC1;
00250                                 amp->step = yRes*sizeof(uint16_t);
00251                                 amp->data.resize(xRes*yRes*sizeof(uint16_t));
00252                                 memcpy ( &amp->data[0], amplitudes, xRes*yRes*sizeof(uint16_t) );
00253                     }
00254                 }
00255         }
00256 
00257         / *
00258          * Publishing the messages
00259          * /
00260         //int_amp.publish(amp);
00261         //int_dis.publish(dis);
00262 
00263     };*/
00264 
00265 };
00266 }
00267 
00268 #endif //_BTA_TOF_DRIVER_HPP_
00269 


bta_tof_driver
Author(s): Angel Merino , Simon Vogl
autogenerated on Thu Jun 20 2019 19:58:11