Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
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
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
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
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
00284 boost::shared_ptr<ReconfigureServer> reconfigure_server_;
00285 };
00286 }
00287
00288 #endif // _FX8_DRIVER_H_