stcamera_interface.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (C) 2018, OMRON SENTECH. 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 are met:
8  * * Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * * Neither the names of OMRON SENTECH nor the names of its
14  * contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  *****************************************************************************/
29 
37 #ifndef STCAMERA_STCAMERA_INTERFACE_H
38 #define STCAMERA_STCAMERA_INTERFACE_H
39 
40 #include <mutex>
41 #include <ros/ros.h>
45 #include <sensor_msgs/CameraInfo.h>
46 
47 #include <omronsentech_camera/Event.h>
48 #include <omronsentech_camera/Chunk.h>
49 
50 #include <omronsentech_camera/ReadNode.h>
51 #include <omronsentech_camera/ReadNodeBool.h>
52 #include <omronsentech_camera/ReadNodeEnum.h>
53 #include <omronsentech_camera/ReadNodeInt.h>
54 #include <omronsentech_camera/ReadNodeFloat.h>
55 #include <omronsentech_camera/ReadNodeString.h>
56 
57 #include <omronsentech_camera/WriteNode.h>
58 #include <omronsentech_camera/WriteNodeBool.h>
59 #include <omronsentech_camera/WriteNodeEnumInt.h>
60 #include <omronsentech_camera/WriteNodeEnumStr.h>
61 #include <omronsentech_camera/WriteNodeInt.h>
62 #include <omronsentech_camera/WriteNodeFloat.h>
63 #include <omronsentech_camera/WriteNodeString.h>
64 #include <omronsentech_camera/ExecuteNode.h>
65 
66 #include <omronsentech_camera/EnableChunk.h>
67 #include <omronsentech_camera/EnableTrigger.h>
68 #include <omronsentech_camera/EnableEventNode.h>
69 #include <omronsentech_camera/EnableImageAcquisition.h>
70 #include <omronsentech_camera/EnableEventAcquisition.h>
71 
72 #include <omronsentech_camera/GetImageAcquisitionStatus.h>
73 #include <omronsentech_camera/GetEventAcquisitionStatusList.h>
74 #include <omronsentech_camera/GetEventNodeStatusList.h>
75 #include <omronsentech_camera/GetChunkList.h>
76 #include <omronsentech_camera/GetTriggerList.h>
77 #include <omronsentech_camera/GetEnumList.h>
78 #include <omronsentech_camera/GetGenICamNodeInfo.h>
79 #include <omronsentech_camera/SendSoftTrigger.h>
80 #include <omronsentech_camera/GetLastError.h>
81 
82 #include <StApi_TL.h>
84 
86 
87 namespace stcamera
88 {
89 
91 #define RETURN_ERR(X, MSG) \
92  ROS_ERROR("%s %s %d: \n\t%s error: %s", \
93  __FILE__,__func__,__LINE__,camera_namespace_.c_str(),MSG); \
94  last_error_ = X; return false;
95 
97 #define CHECK_NULLPTR(P, X, MSG) if (nullptr == P) \
98  { RETURN_ERR(X, MSG); }
99 
101 #define CATCH_COMMON_ERR() catch(const StApi::CStGenTLErrorException &x) \
102  {\
103  RETURN_ERR(x.GetError(), x.GetDescription());\
104  }\
105  catch(GenICam::GenericException &x)\
106  {\
107  RETURN_ERR(GENICAM_ERROR, x.GetDescription());\
108  }\
109  catch(...)\
110  {\
111  }\
112  RETURN_ERR(UNKNOWN_ERROR, UNKNOWN_ERROR_STR);
113 
116  struct StCallback
117  {
119  std::string topic_name_;
121  StApi::IStRegisteredCallbackReleasable *cb_;
122  };
123 
125 
128  typedef std::map<std::string, StCameraInterface*> MapCameraInterface;
129 
131  typedef std::map<std::string, struct StCallback> MapCallback;
132 
134  typedef std::map<std::string, GenApi::INode*> MapChunk;
135 
137  typedef std::map<std::string, ros::Publisher> MapPublisher;
138 
146  {
147  public:
148 
159  StCameraInterface(StApi::IStDeviceReleasable *dev,
160  ros::NodeHandle nh_parent,
161  const std::string &camera_namespace,
163  uint32_t queue_size = STCAMERA_QUEUE_SIZE);
164 
170  virtual ~StCameraInterface();
171 
175  bool deviceIsLost();
176 
177  protected:
178 
186  void eventSystemCB(StApi::IStCallbackParamBase *p, void *pvContext);
187 
195  void eventInterfaceCB(StApi::IStCallbackParamBase *p, void *pvContext);
196 
204  void eventDeviceCB(StApi::IStCallbackParamBase *p, void *pvContext);
205 
216  void eventGenApiNodeCB(GenApi::INode *p, void *pvContext);
217 
227  void eventDataStreamCB(StApi::IStCallbackParamBase *p, void *pvContext);
228 
236  bool readNodeCallback(omronsentech_camera::ReadNode::Request &req,
237  omronsentech_camera::ReadNode::Response &res);
238 
246  bool readNodeBoolCallback(omronsentech_camera::ReadNodeBool::Request &req,
247  omronsentech_camera::ReadNodeBool::Response &res);
248 
256  bool readNodeEnumCallback(omronsentech_camera::ReadNodeEnum::Request &req,
257  omronsentech_camera::ReadNodeEnum::Response &res);
258 
266  bool readNodeIntCallback(omronsentech_camera::ReadNodeInt::Request &req,
267  omronsentech_camera::ReadNodeInt::Response &res);
268 
276  bool readNodeFloatCallback(
277  omronsentech_camera::ReadNodeFloat::Request &req,
278  omronsentech_camera::ReadNodeFloat::Response &res);
279 
287  bool readNodeStringCallback(
288  omronsentech_camera::ReadNodeString::Request &req,
289  omronsentech_camera::ReadNodeString::Response &res);
290 
298  bool writeNodeCallback(
299  omronsentech_camera::WriteNode::Request &req,
300  omronsentech_camera::WriteNode::Response &res);
301 
309  bool writeNodeBoolCallback(
310  omronsentech_camera::WriteNodeBool::Request &req,
311  omronsentech_camera::WriteNodeBool::Response &res);
312 
321  bool writeNodeEnumIntCallback(
322  omronsentech_camera::WriteNodeEnumInt::Request &req,
323  omronsentech_camera::WriteNodeEnumInt::Response &res);
324 
333  bool writeNodeEnumStrCallback(
334  omronsentech_camera::WriteNodeEnumStr::Request &req,
335  omronsentech_camera::WriteNodeEnumStr::Response &res);
336 
344  bool writeNodeIntCallback(
345  omronsentech_camera::WriteNodeInt::Request &req,
346  omronsentech_camera::WriteNodeInt::Response &res);
347 
355  bool writeNodeFloatCallback(
356  omronsentech_camera::WriteNodeFloat::Request &req,
357  omronsentech_camera::WriteNodeFloat::Response &res);
358 
366  bool writeNodeStringCallback(
367  omronsentech_camera::WriteNodeString::Request &req,
368  omronsentech_camera::WriteNodeString::Response &res);
369 
377  bool executeNodeCallback(
378  omronsentech_camera::ExecuteNode::Request &req,
379  omronsentech_camera::ExecuteNode::Response &res);
380 
387  bool enableChunkCallback(
388  omronsentech_camera::EnableChunk::Request &req,
389  omronsentech_camera::EnableChunk::Response &res);
390 
397  bool enableTriggerCallback(
398  omronsentech_camera::EnableTrigger::Request &req,
399  omronsentech_camera::EnableTrigger::Response &res);
400 
407  bool enableEventNodeCallback(
408  omronsentech_camera::EnableEventNode::Request &req,
409  omronsentech_camera::EnableEventNode::Response &res);
410 
417  bool enableImageAcquisitionCallback(
418  omronsentech_camera::EnableImageAcquisition::Request &req,
419  omronsentech_camera::EnableImageAcquisition::Response &res);
420 
427  bool enableEventAcquisitionCallback(
428  omronsentech_camera::EnableEventAcquisition::Request &req,
429  omronsentech_camera::EnableEventAcquisition::Response &res);
430 
437  bool getImageAcquisitionStatusCallback(
438  omronsentech_camera::GetImageAcquisitionStatus::Request &req,
439  omronsentech_camera::GetImageAcquisitionStatus::Response &res);
440 
447  bool getEventAcquisitionStatusListCallback(
448  omronsentech_camera::GetEventAcquisitionStatusList::Request &req,
449  omronsentech_camera::GetEventAcquisitionStatusList::Response &res);
450 
457  bool getEventNodeStatusListCallback(
458  omronsentech_camera::GetEventNodeStatusList::Request &req,
459  omronsentech_camera::GetEventNodeStatusList::Response &res);
460 
467  bool getChunkListCallback(omronsentech_camera::GetChunkList::Request &req,
468  omronsentech_camera::GetChunkList::Response &res);
469 
476  bool getTriggerListCallback(
477  omronsentech_camera::GetTriggerList::Request &req,
478  omronsentech_camera::GetTriggerList::Response &res);
479 
487  bool getEnumListCallback(omronsentech_camera::GetEnumList::Request &req,
488  omronsentech_camera::GetEnumList::Response &res);
489 
497  bool getGenICamNodeInfoCallback(
498  omronsentech_camera::GetGenICamNodeInfo::Request &req,
499  omronsentech_camera::GetGenICamNodeInfo::Response &res);
500 
508  bool sendSoftTriggerCallback(
509  omronsentech_camera::SendSoftTrigger::Request &req,
510  omronsentech_camera::SendSoftTrigger::Response &res);
511 
517  bool getLastErrorCallback(
518  omronsentech_camera::GetLastError::Request &req,
519  omronsentech_camera::GetLastError::Response &res);
520 
524  void initializeCameraInfo();
525 
532  GenApi::INodeMap *getNodeMap(std::string &module_name);
533 
541  MapCallback *getCallbackMap(std::string &module_name);
542 
547  void publishEventDefault(omronsentech_camera::Event &msg);
548 
552  std::string camera_namespace_;
553 
555  StApi::CIStDevicePtr tl_dev_;
556 
558  StApi::CIStDataStreamPtr tl_ds_;
559 
562 
565 
568 
571 
574 
577 
579  MapPublisher map_msg_event_;
580 
584  uint32_t queue_size_;
585 
598 
615 
626 
641 
646 
648  std::mutex mtx_acquisition_;
651 
653  std::mutex mtx_event_;
654 
663 
668  MapCallback map_event_system_;
673  MapCallback map_event_interface_;
689 
691  std::mutex mtx_chunk_;
693  MapChunk map_chunk_;
694 
696  int32_t last_error_;
697 
700  };
701 }
702 #endif
ros::ServiceServer srv_write_node_int_
ros::ServiceServer srv_enable_image_acquisition_
StApi::IStRegisteredCallbackReleasable * cb_
ros::ServiceServer srv_read_node_string_
std::map< std::string, GenApi::INode * > MapChunk
ros::ServiceServer srv_write_node_
bool param(const std::string &param_name, T &param_val, const T &default_val)
ros::ServiceServer srv_get_genicam_node_info_
ros::ServiceServer srv_read_node_float_
ros::ServiceServer srv_write_node_bool_
ros::ServiceServer srv_get_last_error_
ros::ServiceServer srv_write_node_enum_int_
ros::ServiceServer srv_send_soft_trigger_
ros::ServiceServer srv_enable_chunk_
StApi::CIStDataStreamPtr tl_ds_
image_transport::CameraPublisher it_campub_
ros::ServiceServer srv_enable_trigger_
ros::ServiceServer srv_enable_event_node_
ros::ServiceServer srv_get_event_acquisition_status_list_
ros::ServiceServer srv_get_enum_list_
ros::ServiceServer srv_get_chunk_list_
ros::ServiceServer srv_write_node_string_
ros::ServiceServer srv_get_event_node_status_list_
ros::ServiceServer srv_read_node_bool_
ros::ServiceServer srv_write_node_float_
camera_info_manager::CameraInfoManager cinfo_
StApi::CIStDevicePtr tl_dev_
#define STCAMERA_QUEUE_SIZE
Definition: stheader.h:41
std::map< std::string, StCameraInterface * > MapCameraInterface
ros::ServiceServer srv_read_node_int_
ros::ServiceServer srv_read_node_
Contains definitions and macros.
ros::ServiceServer srv_enable_event_acquisition_
std::map< std::string, struct StCallback > MapCallback
ros::ServiceServer srv_read_node_enum_
Base class to control a connected camera.
ros::ServiceServer srv_get_trigger_list_
Class to handle ROS parameter.
Definition: stparameter.h:51
ros::ServiceServer srv_get_image_acquisition_status_
image_transport::ImageTransport it_
Class to handle ROS parameter.
ros::ServiceServer srv_execute_node_
std::map< std::string, ros::Publisher > MapPublisher
ros::ServiceServer srv_write_node_enum_str_


omronsentech_camera
Author(s): OSE ROS Support
autogenerated on Tue Jul 2 2019 19:44:14