49 #include <rc_genicam_api/config.h> 59 #include <rc_common_msgs/ReturnCodeConstants.h> 60 #include <rc_common_msgs/CameraParam.h> 101 if (ns.size() > 0 && ns[0] ==
'/')
120 std::string
id =
"*";
121 std::string access =
"control";
123 pnh.
param(
"device",
id,
id);
124 pnh.
param(
"gev_access", access, access);
127 if (access ==
"exclusive")
131 else if (access ==
"control")
160 rc_common_msgs::Trigger::Response& res)
162 std::lock_guard<std::recursive_mutex> lock(
device_mtx);
166 if (
config.depth_acquisition_mode !=
"Continuous")
174 res.return_code.value = rc_common_msgs::ReturnCodeConstants::SUCCESS;
175 res.return_code.message =
"Stereo matching was triggered.";
177 catch (
const std::exception& ex)
179 res.return_code.value = rc_common_msgs::ReturnCodeConstants::INTERNAL_ERROR;
180 res.return_code.message = ex.what();
186 res.return_code.value = rc_common_msgs::ReturnCodeConstants::NOT_APPLICABLE;
187 res.return_code.message =
"Triggering stereo matching is only possible if acquisition_mode is set to SingleFrame " 188 "or SingleFrameOut1!";
194 res.return_code.value = rc_common_msgs::ReturnCodeConstants::NOT_APPLICABLE;
195 res.return_code.message =
"Not connected";
203 std::lock_guard<std::recursive_mutex> lock(
device_mtx);
212 config.camera_exp_auto = (v !=
"Off");
214 if (
config.camera_exp_auto)
216 if (v ==
"Continuous")
218 config.camera_exp_auto_mode =
"Normal";
222 config.camera_exp_auto_mode = v;
233 catch (
const std::exception&)
235 config.camera_exp_auto_average_max = 0.75f;
236 config.camera_exp_auto_average_min = 0.25f;
252 config.camera_wb_auto = (v !=
"Off");
258 catch (
const std::exception&)
260 config.camera_wb_auto =
true;
261 config.camera_wb_ratio_red = 1.2;
262 config.camera_wb_ratio_blue = 2.4;
292 pnh.
param(
"camera_exp_auto_mode",
config.camera_exp_auto_mode,
config.camera_exp_auto_mode);
294 pnh.
param(
"camera_exp_auto_average_max",
config.camera_exp_auto_average_max,
config.camera_exp_auto_average_max);
295 pnh.
param(
"camera_exp_auto_average_min",
config.camera_exp_auto_average_min,
config.camera_exp_auto_average_min);
297 pnh.
param(
"camera_gain_value",
config.camera_gain_value,
config.camera_gain_value);
298 pnh.
param(
"camera_exp_offset_x",
config.camera_exp_offset_x,
config.camera_exp_offset_x);
299 pnh.
param(
"camera_exp_offset_y",
config.camera_exp_offset_y,
config.camera_exp_offset_y);
301 pnh.
param(
"camera_exp_height",
config.camera_exp_height,
config.camera_exp_height);
303 pnh.
param(
"camera_wb_ratio_red",
config.camera_wb_ratio_red,
config.camera_wb_ratio_red);
304 pnh.
param(
"camera_wb_ratio_blue",
config.camera_wb_ratio_blue,
config.camera_wb_ratio_blue);
305 pnh.
param(
"depth_acquisition_mode",
config.depth_acquisition_mode,
config.depth_acquisition_mode);
307 pnh.
param(
"depth_static_scene",
config.depth_static_scene,
config.depth_static_scene);
308 pnh.
param(
"depth_double_shot",
config.depth_double_shot,
config.depth_double_shot);
315 pnh.
param(
"depth_maxdeptherr",
config.depth_maxdeptherr,
config.depth_maxdeptherr);
324 pnh.
setParam(
"camera_exp_auto_mode",
config.camera_exp_auto_mode);
326 pnh.
setParam(
"camera_exp_auto_average_max",
config.camera_exp_auto_average_max);
327 pnh.
setParam(
"camera_exp_auto_average_min",
config.camera_exp_auto_average_min);
336 pnh.
setParam(
"camera_wb_ratio_blue",
config.camera_wb_ratio_blue);
337 pnh.
setParam(
"depth_acquisition_mode",
config.depth_acquisition_mode);
355 std::lock_guard<std::recursive_mutex> lock(
device_mtx);
368 if (c.camera_exp_auto)
372 if (c.camera_exp_auto_mode ==
"Off" || c.camera_exp_auto_mode ==
"Normal")
374 c.camera_exp_auto_mode =
"Continuous";
379 std::vector<std::string> list;
382 std::string mode =
"Continuous";
383 for (
size_t i = 0; i < list.size(); i++)
385 if (c.camera_exp_auto_mode == list[i])
397 if (mode ==
"Continuous")
402 c.camera_exp_auto_mode = mode;
424 NODELET_WARN(
"rc_visard does not support parameter 'exp_auto_average_max'");
425 c.camera_exp_auto_average_max = 0.75f;
433 NODELET_WARN(
"rc_visard does not support parameter 'exp_auto_average_min'");
434 c.camera_exp_auto_average_min = 0.25f;
443 c.camera_gain_value =
round(c.camera_gain_value / 6) * 6;
470 bool color_ok =
true;
474 if (c.camera_wb_auto)
506 c.camera_wb_auto =
true;
507 c.camera_wb_ratio_red = 1.2;
508 c.camera_wb_ratio_blue = 2.4;
515 if (c.depth_acquisition_mode ==
"S" || c.depth_acquisition_mode ==
"SingleFrame")
517 c.depth_acquisition_mode =
"SingleFrame";
519 else if (c.depth_acquisition_mode ==
"O" || c.depth_acquisition_mode ==
"SingleFrameOut1")
521 c.depth_acquisition_mode =
"SingleFrameOut1";
523 else if (c.depth_acquisition_mode ==
"C" || c.depth_acquisition_mode ==
"Continuous")
525 c.depth_acquisition_mode =
"Continuous";
529 c.depth_acquisition_mode =
"Continuous";
537 if (c.depth_quality ==
"Full" || c.depth_quality ==
"F")
539 c.depth_quality =
"Full";
541 else if (c.depth_quality ==
"High" || c.depth_quality ==
"H")
543 c.depth_quality =
"High";
545 else if (c.depth_quality ==
"Medium" || c.depth_quality ==
"M")
547 c.depth_quality =
"Medium";
549 else if (c.depth_quality ==
"Low" || c.depth_quality ==
"L")
551 c.depth_quality =
"Low";
555 c.depth_quality =
"High";
562 catch (
const std::exception&)
564 c.depth_quality =
"High";
567 NODELET_ERROR(
"Cannot set full quality. Sensor may have no 'stereo_plus' license!");
582 catch (
const std::exception&)
584 c.depth_double_shot =
false;
585 NODELET_ERROR(
"Cannot set double shot mode. Please update the sensor to version >= 20.11.0!");
594 if (level & 524288 && c.depth_smooth !=
config.depth_smooth)
600 catch (
const std::exception&)
602 c.depth_smooth =
false;
605 NODELET_ERROR(
"Cannot switch on smoothing. Sensor may have no 'stereo_plus' license!");
629 if (level & 16777216)
634 if ((level & 33554432) && c.ptp_enabled !=
config.ptp_enabled)
639 c.ptp_enabled =
false;
643 if ((level & 67108864) && c.out1_mode !=
config.out1_mode)
645 if (c.out1_mode !=
"Low" && c.out1_mode !=
"High" && c.out1_mode !=
"ExposureActive" &&
646 c.out1_mode !=
"ExposureAlternateActive")
656 NODELET_ERROR(
"Cannot change out1 mode. Sensor may have no 'iocontrol' license!");
660 if (level & 134217728 && c.out2_mode !=
config.out2_mode)
662 if (c.out2_mode !=
"Low" && c.out2_mode !=
"High" && c.out2_mode !=
"ExposureActive" &&
663 c.out2_mode !=
"ExposureAlternateActive")
673 NODELET_ERROR(
"Cannot change out2 mode. Sensor may have no 'iocontrol' license!");
678 catch (
const std::exception& ex)
688 std::lock_guard<std::recursive_mutex> lock(
device_mtx);
697 p->requiresComponents(rcomponents, rcolor);
714 {
"IntensityCombined", GenICam2RosPublisher::ComponentIntensityCombined },
720 for (
size_t i = 0; comp[i].name != 0; i++)
722 if (((rcomponents ^
scomponents) & comp[i].flag) || force)
727 const char* status =
"disabled";
728 if (rcomponents & comp[i].flag)
740 if (rcolor !=
scolor || force)
742 const char* format =
"Mono8";
745 format =
"YCbCr411_8";
777 stat.
summary(diagnostic_msgs::DiagnosticStatus::ERROR,
"Disconnected");
792 stat.
summary(diagnostic_msgs::DiagnosticStatus::OK,
"Streaming");
797 stat.
summary(diagnostic_msgs::DiagnosticStatus::WARN,
"No data");
803 stat.
summary(diagnostic_msgs::DiagnosticStatus::OK,
"Idle");
811 stat.
summary(diagnostic_msgs::DiagnosticStatus::ERROR,
"Unknown");
815 stat.
summary(diagnostic_msgs::DiagnosticStatus::OK,
"Info");
826 std::vector<std::shared_ptr<rcg::Device> > getSupportedDevices(
const std::string& devid,
827 const std::vector<std::string>& iname)
830 std::vector<std::shared_ptr<rcg::Device> > ret;
832 for (
size_t i = 0; i < system.size(); i++)
836 std::vector<std::shared_ptr<rcg::Interface> > interf = system[i]->getInterfaces();
838 for (
size_t k = 0; k < interf.size(); k++)
840 if (interf[k]->getTLType() ==
"GEV" &&
841 (iname.size() == 0 || std::find(iname.begin(), iname.end(), interf[k]->getID()) != iname.end()))
845 std::vector<std::shared_ptr<rcg::Device> > device = interf[k]->getDevices();
847 for (
size_t j = 0; j < device.size(); j++)
849 if ((device[j]->getVendor() ==
"Roboception GmbH" ||
850 device[j]->getModel().substr(0, 9) ==
"rc_visard" || device[j]->getModel().substr(0, 7) ==
"rc_cube") &&
851 (devid ==
"*" || device[j]->getID() == devid || device[j]->getSerialNumber() == devid ||
852 device[j]->getDisplayName() == devid))
854 ret.push_back(device[j]);
868 class NoDeviceException :
public std::invalid_argument
871 NoDeviceException(
const char*
msg) : std::invalid_argument(msg)
876 void split(std::vector<std::string>& list,
const std::string&
s,
char delim,
bool skip_empty =
true)
878 std::stringstream in(s);
881 while (
getline(in, elem, delim))
883 if (!skip_empty || elem.size() > 0)
885 list.push_back(elem);
918 std::shared_ptr<GenApi::CChunkAdapter> chunkadapter;
921 std::lock_guard<std::recursive_mutex> lock(
device_mtx);
925 std::vector<std::string> iname;
926 std::string dname = id;
929 size_t i = dname.find(
':');
930 if (i != std::string::npos)
934 iname.push_back(
id.substr(0, i));
937 dname = dname.substr(i + 1);
941 std::vector<std::shared_ptr<rcg::Device> > devices = getSupportedDevices(dname, iname);
943 if (devices.size() == 0)
945 throw NoDeviceException((
"Cannot find device '" +
id +
"'").c_str());
948 if (devices.size() > 1)
950 throw std::invalid_argument(
"Too many devices, please specify unique ID");
961 throw std::invalid_argument(
"Device is not yet ready");
974 <<
dev->getDisplayName());
982 std::vector<std::string> list;
985 if (list.size() < 3 || std::stoi(list[0]) < 20 || (std::stoi(list[0]) == 20 && std::stoi(list[1]) < 4))
988 throw std::invalid_argument(
"Device version must be 20.04 or higher: " +
device_version);
1000 reconfig =
new dynamic_reconfigure::Server<rc_genicam_driver::rc_genicam_driverConfig>(
1018 dynamic_reconfigure::Server<rc_genicam_driver::rc_genicam_driverConfig>::CallbackType cb;
1038 std::vector<std::string> formats;
1041 for (
auto&& format : formats)
1043 if (format ==
"YCbCr411_8")
1051 bool iocontrol_avail =
nodemap->_GetNode(
"LineSource")->GetAccessMode() ==
GenApi::RW;
1055 NODELET_INFO(
"Not a color camera. wb_auto, wb_ratio_red and wb_ratio_blue are without " 1061 NODELET_WARN(
"No stereo_plus license on device. quality=full and smoothing is not available.");
1064 if (!iocontrol_avail)
1066 NODELET_WARN(
"No iocontrol license on device. out1_mode and out2_mode are without function.");
1079 pub.push_back(std::make_shared<CameraInfoPublisher>(nh,
frame_id,
true, callback));
1080 pub.push_back(std::make_shared<CameraInfoPublisher>(nh,
frame_id,
false, callback));
1081 pub.push_back(std::make_shared<CameraParamPublisher>(nh,
frame_id,
true, callback));
1082 pub.push_back(std::make_shared<CameraParamPublisher>(nh,
frame_id,
false, callback));
1084 pub.push_back(std::make_shared<ImagePublisher>(it,
frame_id,
true,
false, iocontrol_avail, callback));
1085 pub.push_back(std::make_shared<ImagePublisher>(it,
frame_id,
false,
false, iocontrol_avail, callback));
1089 pub.push_back(std::make_shared<ImagePublisher>(it,
frame_id,
true,
true, iocontrol_avail, callback));
1090 pub.push_back(std::make_shared<ImagePublisher>(it,
frame_id,
false,
true, iocontrol_avail, callback));
1093 pub.push_back(std::make_shared<DisparityPublisher>(nh,
frame_id, callback));
1094 pub.push_back(std::make_shared<DisparityColorPublisher>(it,
frame_id, callback));
1095 pub.push_back(std::make_shared<DepthPublisher>(nh,
frame_id, callback));
1097 pub.push_back(std::make_shared<ConfidencePublisher>(nh,
frame_id, callback));
1098 pub.push_back(std::make_shared<ErrorDisparityPublisher>(nh,
frame_id, callback));
1099 pub.push_back(std::make_shared<ErrorDepthPublisher>(nh,
frame_id, callback));
1101 pub.push_back(std::make_shared<Points2Publisher>(nh,
frame_id, callback));
1105 for (
auto&& p :
pub)
1116 std::vector<std::shared_ptr<rcg::Stream> > stream =
dev->getStreams();
1118 if (stream.size() == 0)
1120 throw std::invalid_argument(
"Device does not offer streams");
1124 stream[0]->startStreaming();
1139 std::string out1_mode_on_sensor;
1150 out1_mode_on_sensor =
"";
1156 std::lock_guard<std::recursive_mutex> lock(
device_mtx);
1165 chunkadapter->AttachBuffer(reinterpret_cast<std::uint8_t*>(buffer->
getGlobalBase()),
1176 for (uint32_t part = 0; part < npart; part++)
1181 for (
auto&& p : pub)
1183 p->publish(buffer, part, pixelformat);
1190 chunkadapter->DetachBuffer();
1201 std::lock_guard<std::recursive_mutex> lock(
device_mtx);
1207 std::lock_guard<std::recursive_mutex> lock(
device_mtx);
1213 if (out1_mode_on_sensor.size() == 0)
1216 out1_mode_on_sensor =
config.out1_mode;
1219 if (out1_mode_on_sensor !=
config.out1_mode)
1221 config.out1_mode = out1_mode_on_sensor;
1233 stream[0]->stopStreaming();
1250 catch (
const NoDeviceException& ex)
1264 catch (
const std::exception& ex)
1296 std::lock_guard<std::recursive_mutex> lock(
device_mtx);
1306 catch (
const std::exception& ex)
Interface for all publishers relating to images, point clouds or other stereo-camera data...
std::shared_ptr< rcg::Device > dev
bool getBoolean(const std::shared_ptr< GenApi::CNodeMapRef > &nodemap, const char *name, bool exception=false, bool igncache=false)
#define NODELET_INFO_STREAM(...)
#define NODELET_ERROR(...)
bool depthAcquisitionTrigger(rc_common_msgs::Trigger::Request &req, rc_common_msgs::Trigger::Response &resp)
#define NODELET_WARN(...)
diagnostic_updater::Updater updater
size_t getSizeFilled() const
void summary(unsigned char lvl, const std::string s)
std::istream & getline(std::istream &is, GENICAM_NAMESPACE::gcstring &str)
std::shared_ptr< GenApi::CChunkAdapter > getChunkAdapter(const std::shared_ptr< GenApi::CNodeMapRef > &nodemap, const std::string &tltype)
static const int ComponentDisparity
virtual ~GenICamDeviceNodelet()
void setHardwareID(const std::string &hwid)
static std::vector< std::shared_ptr< System > > getSystems()
rc_genicam_driver::rc_genicam_driverConfig config
void add(const std::string &name, TaskFunction f)
int64_t getInteger(const std::shared_ptr< GenApi::CNodeMapRef > &nodemap, const char *name, int64_t *vmin=0, int64_t *vmax=0, bool exception=false, bool igncache=false)
ServiceServer advertiseService(const std::string &service, bool(T::*srv_func)(MReq &, MRes &), T *obj)
boost::recursive_mutex reconfig_mtx
bool setFloat(const std::shared_ptr< GenApi::CNodeMapRef > &nodemap, const char *name, double value, bool exception=false)
static const int ComponentError
int connection_loss_total
bool setEnum(const std::shared_ptr< GenApi::CNodeMapRef > &nodemap, const char *name, const char *value, bool exception=false)
ros::NodeHandle & getPrivateNodeHandle() const
static const int ComponentConfidence
static void clearSystems()
static const int ComponentIntensity
std::string device_interface
void * getGlobalBase() const
void publishConnectionDiagnostics(diagnostic_updater::DiagnosticStatusWrapper &stat)
ROSCPP_DECL const std::string & getNamespace()
void updateSubscriptions(bool force=false)
std::string getEnum(const std::shared_ptr< GenApi::CNodeMapRef > &nodemap, const char *name, bool exception=false)
uint64_t getPixelFormat(std::uint32_t part) const
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
int image_receive_timeouts_total
std::string device_serial
ros::NodeHandle & getNodeHandle() const
ros::ServiceServer trigger_service
#define NODELET_DEBUG_STREAM(...)
bool setBoolean(const std::shared_ptr< GenApi::CNodeMapRef > &nodemap, const char *name, bool value, bool exception=false)
std::shared_ptr< GenApi::CNodeMapRef > nodemap
#define NODELET_INFO(...)
double getFloat(const std::shared_ptr< GenApi::CNodeMapRef > &nodemap, const char *name, double *vmin=0, double *vmax=0, bool exception=false, bool igncache=false)
int current_reconnect_trial
dynamic_reconfigure::Server< rc_genicam_driver::rc_genicam_driverConfig > * reconfig
std::string device_version
void publishDeviceDiagnostics(diagnostic_updater::DiagnosticStatusWrapper &stat)
void grab(std::string id, rcg::Device::ACCESS access)
bool callCommand(const std::shared_ptr< GenApi::CNodeMapRef > &nodemap, const char *name, bool exception=false)
int complete_buffers_total
#define NODELET_FATAL_STREAM(...)
int incomplete_buffers_total
bool getImagePresent(std::uint32_t part) const
bool getIsIncomplete() const
bool setInteger(const std::shared_ptr< GenApi::CNodeMapRef > &nodemap, const char *name, int64_t value, bool exception=false)
void add(const std::string &key, const T &val)
std::vector< std::shared_ptr< GenICam2RosPublisher > > pub
#define NODELET_FATAL(...)
void reconfigure(rc_genicam_driver::rc_genicam_driverConfig &c, uint32_t level)
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)
void setParam(const std::string &key, const XmlRpc::XmlRpcValue &v) const
#define NODELET_DEBUG(...)
std::string getString(const std::shared_ptr< GenApi::CNodeMapRef > &nodemap, const char *name, bool exception=false, bool igncache=false)
static const int ComponentIntensityCombined
std::recursive_mutex device_mtx
std::uint32_t getNumberOfParts() const