fx8_driver_nodelet.h
Go to the documentation of this file.
1 /*****************************************************************************
2  *
3  * Copyright (C) 2013, NIPPON CONTROL SYSTEM Corporation
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  * * Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  *
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  *
18  * * Neither the name of the NIPPON CONTROL SYSTEM Corporation nor
19  * the names of its contributors may be used to endorse or promote
20  * products derived from this software without specific prior
21  * written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34  * POSSIBILITY OF SUCH DAMAGE.
35  *
36  *****************************************************************************/
37 
38 #ifndef _FX8_DRIVER_H_
39 #define _FX8_DRIVER_H_
40 
41 #include <ros/ros.h>
42 #include <nodelet/nodelet.h>
43 #include <dynamic_reconfigure/server.h>
46 
47 #include <boost/thread.hpp>
48 
49 #include <fx8.h>
50 #include <infinisoleil/FX8Config.h>
51 
53 namespace infinisoleil
54 {
60 {
61  typedef fx8_handle FX8Handle;
62  typedef fx8_measure_mode FX8MeasureMode;
63  typedef fx8_bool FX8Bool;
64  typedef fx8_sensor_info FX8SensorInfo;
65  typedef fx8_xy_data_element FX8XyDataElement;
66  typedef fx8_xy_data_surface FX8XyDataSurface;
67  typedef fx8_xy_data FX8XyData;
68  typedef dynamic_reconfigure::Server<infinisoleil::FX8Config> ReconfigureServer;
69  typedef std::vector<unsigned char> ScanDataPackets;
70  typedef std::pair<ros::Time, std::vector<unsigned char> > ReceivedErrorCodePackets;
71  typedef std::pair<ros::Time, std::string> ErrorInfo;
74 
79  struct FX8Scan
80  {
81  FX8XyData xy_data;
82  ScanDataPackets scan_data;
83  std::string range_frame_id;
84  std::string ir_frame_id;
85  std::string point_cloud_frame_id;
86  };
87 
92  struct FX8Info
93  {
94  FX8SensorInfo sensor_info;
98  };
99 
100  typedef FX8Info Config;
101  typedef FX8Scan Scan;
102 
103 public:
106 
108  virtual ~FX8DriverNodelet();
109 
110 private:
112  virtual void onInit();
113 
115  void initializeNodelet();
116 
118  void shutdownNodelet();
119 
125 
128 
130  void setupDiagnostics();
131 
133  void driverThreadFunc();
134 
139  bool initializeDevice();
140 
142  void shutdownDevice();
143 
151  bool setDeviceMeasureMode(const FX8Handle device, const FX8MeasureMode measure_mode,
152  FX8SensorInfo* sensor_info, FX8XyData* xy_data);
153 
161  bool getDeviceSensorInfo(const FX8Handle device, FX8SensorInfo* sensor_info, FX8XyData* xy_data);
162 
164  void outputDeviceParameters();
165 
170  bool startScan();
171 
173  void spin();
174 
180  void publishScanData(const unsigned char* scan_data, size_t size);
181 
183  sensor_msgs::ImagePtr createRangeImageMessage();
184 
186  sensor_msgs::ImagePtr createIRImageMessage();
187 
189  sensor_msgs::PointCloud2Ptr createPointCloudMessage();
190 
198  void setMessageData(
199  sensor_msgs::ImagePtr range_msg, sensor_msgs::ImagePtr ir_msg, sensor_msgs::PointCloud2Ptr point_cloud_msg,
200  unsigned char surface_number);
201 
209  inline void extractRangeAndIntensityFromScanData(int index, const unsigned char* scan_data,
210  unsigned short* range, unsigned short* intensity);
211 
217 
223 
229  void addDiagnostics(const unsigned char* error_data, size_t size);
230 
236  void reconfigureFX8Callback(FX8Config config, uint32_t level);
237 
239  inline void updateTime();
240 
247  static void receiveScanDataCallback(const unsigned char* scan_data, size_t size, void* user_data);
248 
255  static void receiveErrorCodeCallback(const unsigned char* error_data, size_t size, void* user_data);
256 
257  // Device manager
258  FX8Handle device_;
259  Scan scan_;
260  Config config_;
261  std::vector<ReceivedErrorCodePackets> error_code_;
262  std::vector<ErrorInfo> error_info_;
263 
264  boost::thread driver_thread_;
266 
267  // Publisher
271  boost::mutex mutex_scan_;
273 
274  // Diagnostic
277  TopicDiagnosticPtr ir_image_diagnostic_frequency_;
279  boost::mutex mutex_diagnostics_;
282 
283  // Reconfig
285 };
286 } // namespace infinisoleil
287 
288 #endif // _FX8_DRIVER_H_
boost::mutex mutex_scan_
Mutex for scan data.
fx8_xy_data_surface FX8XyDataSurface
Surface of device xy data.
fx8_sensor_info FX8SensorInfo
Sensor information.
FX8Scan Scan
Scan data of FX8.
std::vector< ErrorInfo > error_info_
Error information of FX8.
sensor_msgs::ImagePtr createRangeImageMessage()
Create message for range_image topic.
dynamic_reconfigure::Server< infinisoleil::FX8Config > ReconfigureServer
Dynamic reconfigure server.
fx8_handle FX8Handle
Device handle.
void shutdownDevice()
Shut down device.
virtual ~FX8DriverNodelet()
Destructor.
void extractRangeAndIntensityFromScanData(int index, const unsigned char *scan_data, unsigned short *range, unsigned short *intensity)
Extract range and intensity data from scan data packets.
std::vector< unsigned char > ScanDataPackets
Received FX8 scan data packets.
sensor_msgs::ImagePtr createIRImageMessage()
Create message for ir_image topic.
boost::shared_ptr< TopicDiagnostic > TopicDiagnosticPtr
Shared pointer of topic diagnostic.
FX8Info Config
Configurations of FX8.
void shutdownReconfigureServer()
Shut down reconfigure server.
std::vector< ReceivedErrorCodePackets > error_code_
Received error code from FX8.
void addDiagnostics(const unsigned char *error_data, size_t size)
Add obtained error data.
TopicDiagnosticPtr point_cloud_diagnostic_frequency_
Topic diagnostic for point cloud.
static void receiveScanDataCallback(const unsigned char *scan_data, size_t size, void *user_data)
Receive FX8 scan data.
fx8_xy_data_element FX8XyDataElement
Element of device xy data.
ros::Publisher ir_publisher_
Publisher of IR image.
std::string range_frame_id
Range frame id.
Config config_
Configurations of FX8.
boost::shared_ptr< diagnostic_updater::Updater > diagnostic_updater_
Diagnostic updater.
diagnostic_updater::HeaderlessTopicDiagnostic TopicDiagnostic
Topic diagnostic.
ros::Publisher point_cloud_publisher_
Publisher of point cloud.
FX8Handle device_
Handle of FX8.
void reconfigureFX8Callback(FX8Config config, uint32_t level)
Reconfigure FX8.
std::pair< ros::Time, std::vector< unsigned char > > ReceivedErrorCodePackets
Received FX8 error code.
bool setDeviceMeasureMode(const FX8Handle device, const FX8MeasureMode measure_mode, FX8SensorInfo *sensor_info, FX8XyData *xy_data)
Set measure mode of FX8.
void spin()
Spin driver thread.
void fillDiagnosticStatusByErrorInfo(diagnostic_updater::DiagnosticStatusWrapper &status)
Fill diagnostic status by error information of FX8.
std::string point_cloud_frame_id
Point cloud frame id.
boost::mutex mutex_diagnostics_
Mutex for diagnostics.
FX8SensorInfo sensor_info
Sensor information.
ros::Time latest_update_time_
Timestamp for topics.
static void receiveErrorCodeCallback(const unsigned char *error_data, size_t size, void *user_data)
Receive FX8 Error code.
virtual void onInit()
Initialize FX8 driver.
sensor_msgs::PointCloud2Ptr createPointCloudMessage()
Create message for point_cloud topic.
fx8_measure_mode FX8MeasureMode
Device measure mode.
Scan scan_
Scan data from FX8.
fx8_bool FX8Bool
Boolean of libfx8.
void driverThreadFunc()
FX8 driver thread.
boost::thread driver_thread_
FX8 driver thread.
bool device_running_
Flag of running device.
bool initializeDevice()
Initialize and connect to FX8.
void publishScanData(const unsigned char *scan_data, size_t size)
Publish scan data.
void fillDiagnosticStatusByReceivedErrorCode(diagnostic_updater::DiagnosticStatusWrapper &status)
Fill diagnostic status by received error code of FX8.
TopicDiagnosticPtr ir_image_diagnostic_frequency_
Topic diagnostic for IR image.
void setMessageData(sensor_msgs::ImagePtr range_msg, sensor_msgs::ImagePtr ir_msg, sensor_msgs::PointCloud2Ptr point_cloud_msg, unsigned char surface_number)
Set data of range image, IR image and point cloud.
Namespace containing driver.
void initializeReconfigureServer(ros::NodeHandle param_nh)
Initialize reconfigure server.
void updateTime()
Update timestamp.
std::pair< ros::Time, std::string > ErrorInfo
Error information.
void initializeNodelet()
Initialize nodelet.
boost::shared_ptr< ReconfigureServer > reconfigure_server_
Server for reconfiguration.
void outputDeviceParameters()
Output FX8 parameters to parameter server.
double target_frequency_
Target frame rate of topics.
void setupDiagnostics()
Setup diagnostics.
TopicDiagnosticPtr range_image_diagnostic_frequency_
Topic diagnostic for range image.
void shutdownNodelet()
Shut down nodelet.
bool diagnostics_enable_
Flag to enable diagnostics.
ros::Publisher range_publisher_
Publisher of range image.
fx8_xy_data FX8XyData
Device xy data.
FX8 driver nodelet class.
bool getDeviceSensorInfo(const FX8Handle device, FX8SensorInfo *sensor_info, FX8XyData *xy_data)
Get FX8SensorInfo and set these.


infinisoleil
Author(s): NCS 3D Sensing Team <3d-sensing@nippon-control-system.co.jp>
autogenerated on Mon Jun 10 2019 13:34:27