21 nxLibInitialize(
true);
23 catch (NxLibException& e)
25 NODELET_ERROR(
"Error while initializing the NxLib. Shutting down.");
30 if (nhLocal.
getParam(
"threads", threads))
32 NxLibItem()[itmParameters][itmThreads] = threads;
35 std::string serial, fileCameraPath, cameraFrame, targetFrame, linkFrame, robotFrame, wristFrame;
38 if (!nhLocal.
getParam(
"serial", serial))
43 if (nhLocal.
getParam(
"serial", intSerial))
45 serial = std::to_string(intSerial);
51 NxLibItem cameras = NxLibItem()[itmCameras][itmBySerialNo];
53 bool foundAppropriateCamera =
false;
54 for (
int i = 0; i < cameras.count(); i++)
56 if (cameras[i][itmType].
exists() && cameras[i][itmType].asString() == valStereo)
58 foundAppropriateCamera =
true;
59 serial = cameras[i].name();
63 if (!foundAppropriateCamera)
71 nhLocal.
param<std::string>(
"file_camera_path", fileCameraPath,
"");
75 if (fileCameraPath.empty())
77 std::string type = NxLibItem()[itmCameras][itmBySerialNo][serial][itmType].asString();
78 std::string
const neededType = valStereo;
79 if (type != neededType)
81 NODELET_ERROR(
"The camera to be opened is of the wrong type %s. It should be %s.", type.c_str(),
88 nhLocal.
param(
"fixed", cameraIsFixed,
false);
90 if (!nhLocal.
getParam(
"camera_frame", cameraFrame))
92 cameraFrame = serial +
"_optical_frame";
95 nhLocal.
param<std::string>(
"robot_frame", robotFrame,
"");
96 nhLocal.
param<std::string>(
"wrist_frame", wristFrame,
"");
98 if (cameraIsFixed && robotFrame.empty())
100 robotFrame = cameraFrame;
102 if (!cameraIsFixed && wristFrame.empty())
104 wristFrame = cameraFrame;
107 nhLocal.
getParam(
"target_frame", targetFrame);
108 nhLocal.
getParam(
"link_frame", linkFrame);
110 if (!targetFrame.empty() && linkFrame.empty())
112 linkFrame = targetFrame;
114 else if (targetFrame.empty() && linkFrame.empty())
116 targetFrame = cameraFrame;
117 linkFrame = cameraFrame;
121 nhLocal.
param(
"capture_timeout", captureTimeout, 0);
124 std::unique_ptr<VirtualObjectHandler> virtualObjectHandler;
125 std::string objectsFile;
126 if (nhLocal.
getParam(
"objects_file", objectsFile) && !objectsFile.empty())
129 std::string objectsFrame = targetFrame;
130 nhLocal.
getParam(
"objects_frame", objectsFrame);
135 virtualObjectHandler = ::make_unique<VirtualObjectHandler>(objectsFile, objectsFrame, cameraFrame);
137 catch (
const std::exception &e)
139 NODELET_WARN(
"Unable to load virtual objects file '%s'. Error: %s", objectsFile.c_str(), e.what());
143 camera = ::make_unique<StereoCamera>(nh, serial, fileCameraPath, cameraIsFixed, cameraFrame, targetFrame, robotFrame,
144 wristFrame, linkFrame, captureTimeout, std::move(virtualObjectHandler));
152 std::string settingsFile;
153 if (nhLocal.
getParam(
"settings", settingsFile))
156 if (!camera->loadSettings(settingsFile,
true))
158 NODELET_ERROR(
"Failed to load the camera settings. Shutting down.");
164 camera->startServers();
165 camera->initTfPublishTimer();
166 camera->initStatusTimer();
#define NODELET_ERROR(...)
#define NODELET_WARN(...)
PLUGINLIB_EXPORT_CLASS(BAGReader, nodelet::Nodelet)
std::unique_ptr< StereoCamera > camera
ros::NodeHandle & getPrivateNodeHandle() const
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
ros::NodeHandle & getNodeHandle() const
bool getParam(const std::string &key, std::string &s) const
ROSCPP_DECL bool exists(const std::string &service_name, bool print_failure_reason)
#define NODELET_DEBUG(...)