fx8_driver_nodelet.h
Go to the documentation of this file.
00001 /*****************************************************************************
00002  *
00003  *  Copyright (C) 2013, NIPPON CONTROL SYSTEM Corporation
00004  *  All rights reserved.
00005  *  
00006  *  Redistribution and use in source and binary forms, with or without
00007  *  modification, are permitted provided that the following conditions
00008  *  are met:
00009  *  
00010  *    * Redistributions of source code must retain the above copyright
00011  *      notice, this list of conditions and the following disclaimer.
00012  *   
00013  *    * Redistributions in binary form must reproduce the above
00014  *      copyright notice, this list of conditions and the following
00015  *      disclaimer in the documentation and/or other materials provided
00016  *      with the distribution.
00017  *   
00018  *    * Neither the name of the NIPPON CONTROL SYSTEM Corporation nor
00019  *      the names of its contributors may be used to endorse or promote
00020  *      products derived from this software without specific prior
00021  *      written permission.
00022  *  
00023  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00024  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00025  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00026  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00027  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00028  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00029  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00030  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00031  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00032  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00033  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00034  *  POSSIBILITY OF SUCH DAMAGE.
00035  *
00036  *****************************************************************************/
00037 
00038 #ifndef _FX8_DRIVER_H_
00039 #define _FX8_DRIVER_H_
00040 
00041 #include <ros/ros.h>
00042 #include <nodelet/nodelet.h>
00043 #include <dynamic_reconfigure/server.h>
00044 #include <diagnostic_updater/diagnostic_updater.h>
00045 #include <diagnostic_updater/publisher.h>
00046 
00047 #include <boost/thread.hpp>
00048 
00049 #include <fx8.h>
00050 #include <infinisoleil/FX8Config.h>
00051 
00053 namespace infinisoleil
00054 {
00059 class FX8DriverNodelet : public nodelet::Nodelet
00060 {
00061   typedef fx8_handle FX8Handle; 
00062   typedef fx8_measure_mode FX8MeasureMode; 
00063   typedef fx8_bool FX8Bool; 
00064   typedef fx8_sensor_info FX8SensorInfo; 
00065   typedef fx8_xy_data_element FX8XyDataElement; 
00066   typedef fx8_xy_data_surface FX8XyDataSurface; 
00067   typedef fx8_xy_data FX8XyData; 
00068   typedef dynamic_reconfigure::Server<infinisoleil::FX8Config> ReconfigureServer; 
00069   typedef std::vector<unsigned char> ScanDataPackets; 
00070   typedef std::pair<ros::Time, std::vector<unsigned char> > ReceivedErrorCodePackets; 
00071   typedef std::pair<ros::Time, std::string> ErrorInfo; 
00072   typedef diagnostic_updater::HeaderlessTopicDiagnostic TopicDiagnostic; 
00073   typedef boost::shared_ptr<TopicDiagnostic> TopicDiagnosticPtr; 
00074 
00079   struct FX8Scan
00080   {
00081     FX8XyData xy_data;    
00082     ScanDataPackets scan_data; 
00083     std::string range_frame_id; 
00084     std::string ir_frame_id; 
00085     std::string point_cloud_frame_id; 
00086   };
00087 
00092   struct FX8Info
00093   {
00094     FX8SensorInfo sensor_info; 
00095     int connect_timeout; 
00096     int send_timeout; 
00097     int receive_timeout; 
00098   };
00099 
00100   typedef FX8Info Config; 
00101   typedef FX8Scan Scan; 
00102 
00103 public:
00105   FX8DriverNodelet();
00106   
00108   virtual ~FX8DriverNodelet();
00109 
00110 private:
00112   virtual void onInit();
00113 
00115   void initializeNodelet();
00116 
00118   void shutdownNodelet();
00119 
00124   void initializeReconfigureServer(ros::NodeHandle param_nh);
00125 
00127   void shutdownReconfigureServer();
00128 
00130   void setupDiagnostics();
00131 
00133   void driverThreadFunc();
00134 
00139   bool initializeDevice();
00140 
00142   void shutdownDevice();
00143 
00151   bool setDeviceMeasureMode(const FX8Handle device, const FX8MeasureMode measure_mode,
00152   FX8SensorInfo* sensor_info, FX8XyData* xy_data);
00153 
00161   bool getDeviceSensorInfo(const FX8Handle device, FX8SensorInfo* sensor_info, FX8XyData* xy_data);
00162 
00164   void outputDeviceParameters();
00165 
00170   bool startScan();
00171 
00173   void spin();
00174 
00180   void publishScanData(const unsigned char* scan_data, size_t size);
00181 
00183   sensor_msgs::ImagePtr createRangeImageMessage();
00184 
00186   sensor_msgs::ImagePtr createIRImageMessage();
00187 
00189   sensor_msgs::PointCloud2Ptr createPointCloudMessage();
00190  
00198   void setMessageData(
00199     sensor_msgs::ImagePtr range_msg, sensor_msgs::ImagePtr ir_msg, sensor_msgs::PointCloud2Ptr point_cloud_msg,
00200     unsigned char surface_number);
00201 
00209   inline void extractRangeAndIntensityFromScanData(int index, const unsigned char* scan_data,
00210     unsigned short* range, unsigned short* intensity);
00211 
00216   void fillDiagnosticStatusByErrorInfo(diagnostic_updater::DiagnosticStatusWrapper &status);
00217 
00222   void fillDiagnosticStatusByReceivedErrorCode(diagnostic_updater::DiagnosticStatusWrapper &status);
00223 
00229   void addDiagnostics(const unsigned char* error_data, size_t size);
00230 
00236   void reconfigureFX8Callback(FX8Config config, uint32_t level);
00237 
00239   inline void updateTime();
00240 
00247   static void receiveScanDataCallback(const unsigned char* scan_data, size_t size, void* user_data);
00248 
00255   static void receiveErrorCodeCallback(const unsigned char* error_data, size_t size, void* user_data);
00256 
00257   // Device manager
00258   FX8Handle device_; 
00259   Scan scan_; 
00260   Config config_; 
00261   std::vector<ReceivedErrorCodePackets> error_code_; 
00262   std::vector<ErrorInfo> error_info_; 
00263 
00264   boost::thread driver_thread_; 
00265   bool device_running_; 
00266 
00267   // Publisher
00268   ros::Publisher range_publisher_; 
00269   ros::Publisher ir_publisher_; 
00270   ros::Publisher point_cloud_publisher_; 
00271   boost::mutex mutex_scan_; 
00272   ros::Time latest_update_time_; 
00273 
00274   // Diagnostic
00275   boost::shared_ptr<diagnostic_updater::Updater> diagnostic_updater_; 
00276   TopicDiagnosticPtr range_image_diagnostic_frequency_; 
00277   TopicDiagnosticPtr ir_image_diagnostic_frequency_; 
00278   TopicDiagnosticPtr point_cloud_diagnostic_frequency_; 
00279   boost::mutex mutex_diagnostics_; 
00280   bool diagnostics_enable_; 
00281   double target_frequency_; 
00282 
00283   // Reconfig
00284   boost::shared_ptr<ReconfigureServer> reconfigure_server_; 
00285 };
00286 } // namespace infinisoleil
00287 
00288 #endif // _FX8_DRIVER_H_


infinisoleil
Author(s): NCS 3D Sensing Team <3d-sensing@nippon-control-system.co.jp>
autogenerated on Thu Jun 6 2019 22:05:50