nodelet.cpp
Go to the documentation of this file.
2 
4 #include <string>
5 
6 #include "nxLib.h"
7 
9 
10 namespace ensenso_camera
11 {
13 {
16 
17  NODELET_DEBUG("Initializing the NxLib...");
18  try
19  {
20  nxLibInitialize(true);
21  }
22  catch (NxLibException& e)
23  {
24  NODELET_ERROR("Error while initializing the NxLib. Shutting down.");
25  exit(EXIT_FAILURE);
26  }
27 
28  int threads;
29  if (nhLocal.getParam("threads", threads))
30  {
31  NxLibItem()[itmParameters][itmThreads] = threads;
32  }
33 
34  std::string serial, fileCameraPath, cameraFrame, targetFrame, robotFrame, wristFrame;
35  bool cameraIsFixed;
36 
37  if (!nhLocal.getParam("serial", serial))
38  {
39  // Try to get the serial as an integer, because rosparam sometimes
40  // automatically converts the serials to numbers.
41  int intSerial;
42  if (nhLocal.getParam("serial", intSerial))
43  {
44  serial = std::to_string(intSerial);
45  }
46  }
47  if (serial.empty())
48  {
49  // No serial specified. Try to use the first camera in the tree.
50  NxLibItem cameras = NxLibItem()[itmCameras][itmBySerialNo];
51  if (cameras.count() > 0)
52  {
53  serial = cameras[0].name();
54  }
55  else
56  {
57  NODELET_ERROR("Could not find any camera. Shutting down.");
58  nxLibFinalize();
59  exit(EXIT_FAILURE);
60  }
61  }
62 
63  nhLocal.param<std::string>("file_camera_path", fileCameraPath, "");
64  nhLocal.param("fixed", cameraIsFixed, false);
65 
66  if (!nhLocal.getParam("camera_frame", cameraFrame))
67  {
68  cameraFrame = "ensenso_optical_frame";
69  }
70  if (!nhLocal.getParam("target_frame", targetFrame))
71  {
72  targetFrame = cameraFrame;
73  }
74 
75  nhLocal.param<std::string>("robot_frame", robotFrame, "");
76  nhLocal.param<std::string>("wrist_frame", wristFrame, "");
77  if (cameraIsFixed && robotFrame.empty())
78  {
79  robotFrame = cameraFrame;
80  }
81  if (!cameraIsFixed && wristFrame.empty())
82  {
83  wristFrame = cameraFrame;
84  }
85 
86  NODELET_DEBUG("Opening the camera '%s'...", serial.c_str());
87  camera = make_unique<Camera>(nh, serial, fileCameraPath, cameraIsFixed, cameraFrame, targetFrame, robotFrame,
88  wristFrame);
89  if (!camera->open())
90  {
91  NODELET_ERROR("Failed to open the camera. Shutting down.");
92  nxLibFinalize();
93  exit(EXIT_FAILURE);
94  }
95 
96  std::string settingsFile;
97  if (nhLocal.getParam("settings", settingsFile))
98  {
99  NODELET_DEBUG("Loading camera settings...");
100  if (!camera->loadSettings(settingsFile, true))
101  {
102  NODELET_ERROR("Failed to load the camera settings. Shutting down.");
103  nxLibFinalize();
104  exit(EXIT_FAILURE);
105  }
106  }
107 
108  camera->startServers();
109 }
110 
112 {
113  camera->close();
114  nxLibFinalize();
115 }
116 
117 } // namespace ensenso_camera
118 
#define NODELET_ERROR(...)
PLUGINLIB_EXPORT_CLASS(BAGReader, nodelet::Nodelet)
void onInit() override
Definition: nodelet.cpp:12
ros::NodeHandle & getPrivateNodeHandle() const
bool param(const std::string &param_name, T &param_val, const T &default_val) const
ros::NodeHandle & getNodeHandle() const
std::unique_ptr< Camera > camera
Definition: nodelet.h:14
bool getParam(const std::string &key, std::string &s) const
#define NODELET_DEBUG(...)


ensenso_camera
Author(s): Ensenso
autogenerated on Thu May 16 2019 02:44:23