Go to the documentation of this file.
40 #include <rc_genicam_api/config.h>
56 #define ROS_HAS_STEADYTIME (ROS_VERSION_MINIMUM(1, 13, 1) || ((ROS_VERSION_MINOR == 12) && ROS_VERSION_PATCH >= 8))
68 ROS_INFO(
"rc_genicam_camera: Shutting down");
83 ROS_INFO(
"rc_genicam_camera: Initialization");
90 std::string device =
"";
91 std::string access =
"control";
92 std::string config =
"";
93 std::string calib =
"";
102 if (ns.size() > 0 && ns[0] ==
'/')
117 pnh.
param(
"calib_id", cid, cid);
125 pnh.
param(
"device", device, device);
126 pnh.
param(
"gev_access", access, access);
127 pnh.
param(
"config_file", config, config);
128 pnh.
param(
"calib_file", calib, calib);
129 pnh.
param(
"calib_id", calib_id, calib_id);
131 if (device.size() == 0)
133 ROS_FATAL(
"The GenICam device ID must be given in the private parameter 'device'!");
138 if (access ==
"exclusive")
142 else if (access ==
"control")
148 ROS_FATAL_STREAM(
"rc_visard_driver: Access must be 'control' or 'exclusive': " << access);
154 bool host_timestamp =
false;
155 pnh.
param(
"host_timestamp", host_timestamp, host_timestamp);
165 std::string sync_info;
166 pnh.
param(
"sync_info", sync_info, sync_info);
169 if (sync_info.size() > 0)
215 std::string loadConfig(
const std::string& filename)
217 if (filename.size() > 0)
219 std::ifstream in(filename);
220 std::stringstream buffer;
224 buffer << in.rdbuf();
233 return std::string();
243 void applyParameters(
const std::shared_ptr<GenApi::CNodeMapRef>& nodemap,
const std::string& parameters)
247 while (i < parameters.size())
251 while (i < parameters.size() && std::isspace(parameters[i]))
256 if (i < parameters.size() && parameters[i] ==
'#')
258 while (i < parameters.size() && parameters[i] !=
'\n')
264 while (k < parameters.size() && !std::isspace(parameters[k]))
267 size_t j = parameters.find(
'=', i);
271 std::string name = parameters.substr(i, j - i);
272 std::string value = parameters.substr(j + 1, k - j - 1);
278 std::string name = parameters.substr(i, k - i);
291 rc_genicam_camera::GetGenICamParameter::Response& resp)
300 resp.return_code.value = resp.return_code.SUCCESS;
301 resp.return_code.message =
"ok";
303 catch (
const std::exception& ex)
307 resp.return_code.value = resp.return_code.INVALID_ARGUMENT;
308 resp.return_code.message = ex.what();
316 rc_genicam_camera::SetGenICamParameter::Response& resp)
326 resp.return_code.value = resp.return_code.SUCCESS;
327 resp.return_code.message =
"ok";
329 catch (
const std::exception& ex)
331 ROS_ERROR_STREAM(
"rc_genicam_camera: Cannot set parameters: " << ex.what());
333 resp.return_code.value = resp.return_code.INVALID_ARGUMENT;
334 resp.return_code.message = ex.what();
344 void storeImage(
const std::string &prefix,
const sensor_msgs::ImagePtr &image)
350 uint64_t t_sec = image->header.stamp.sec;
351 uint64_t t_nsec = image->header.stamp.nsec;
353 name << prefix <<
"_" << t_sec <<
"." << std::setfill(
'0') << std::setw(9) << t_nsec <<
".pgm";
364 size_t height = image->height;
365 uint8_t* p =
reinterpret_cast<uint8_t*
>(&image->data[0]);
367 FILE *out = fopen(name.
str().c_str(),
"w");
371 fprintf(out,
"P5\n%lu %lu\n255\n",
width, height);
372 size_t n = fwrite(p, 1,
width*height, out);
374 if (n <
width*height)
377 " (" << n <<
" < " <<
width*height <<
")");
393 sensor_msgs::ImagePtr image;
396 std::lock_guard<std::mutex> lock(
sync_mtx_);
416 image->header.stamp = info->header.stamp;
446 ROS_INFO(
"rc_genicam_camera: Grabbing thread started");
450 std::string init_params = loadConfig(config);
475 throw std::invalid_argument(
"Cannot find device");
487 catch (
const std::exception& ex)
489 ROS_ERROR_STREAM(
"rc_genicam_camera: Error during initial camera configuration: " << ex.what());
498 "rc_genicam_camera: Cannot determine offset between host and camera clock with maximum tolerance of "
504 std::vector<std::shared_ptr<rcg::Stream> > stream =
rcgdev_->getStreams();
506 if (stream.size() == 0)
508 throw std::invalid_argument(
"Device does not offer streams");
512 stream[0]->startStreaming();
527 for (uint32_t part = 0; part < npart; part++)
539 ts_host.
correct(image->header.stamp);
546 std::lock_guard<std::mutex> lock(
sync_mtx_);
550 sensor_msgs::CameraInfoPtr info =
info_list_.
find(image->header.stamp);
566 image->header.stamp = info->header.stamp;
610 ROS_ERROR_STREAM(
"rc_genicam_camera: Cannot determine offset between host and camera clock with "
611 "maximum tolerance of "
624 stream[0]->stopStreaming();
627 catch (
const std::exception& ex)
646 catch (
const std::exception& ex)
656 ROS_INFO(
"rc_genicam_camera: Grabbing thread stopped");
const std::string BAYER_RGGB8
const ROSCPP_DECL std::string & getNamespace()
ros::NodeHandle & getNodeHandle() const
#define ROS_ERROR_STREAM(args)
int removeOld(const ros::Time ×tamp)
Remove all images that have a timestamp that is older or equal than the given timestamp.
std::atomic_bool running_
sensor_msgs::ImagePtr rosImageFromBuffer(const std::string &frame_id, const rcg::Buffer *buffer, uint32_t part, bool rotate)
Converts a (supported) image in a GenICam buffer into a ROS image.
#define ROS_FATAL_STREAM(args)
#define ROS_WARN_THROTTLE(period,...)
sensor_msgs::ImagePtr find(const ros::Time ×tamp) const
Returns the oldest image that has a timestamp within the tolerance of the given timestamp.
void grab(std::string device, rcg::Device::ACCESS access, std::string config)
double timestamp_tolerance_
void publish(const sensor_msgs::ImagePtr &image)
sensor_msgs::ImagePtr add(const sensor_msgs::ImagePtr &image)
Adds the given image to the internal list.
const std::string BAYER_GBRG8
ros::ServiceServer get_param_service_
ServiceServer advertiseService(AdvertiseServiceOptions &ops)
std::uint32_t getNumberOfParts() const
CameraInfoList info_list_
CameraInfoPublisher caminfo_pub_
bool getIsIncomplete() const
void setSize(size_t maxsize)
Set maximum size of the list.
bool getGenICamParameter(rc_genicam_camera::GetGenICamParameter::Request &req, rc_genicam_camera::GetGenICamParameter::Response &resp)
ros::NodeHandle & getPrivateNodeHandle() const
std::string storeImage(const std::string &name, ImgFmt fmt, const Image &image, size_t yoffset=0, size_t height=0)
int removeOld(const ros::Time ×tamp)
Remove all camera infos that have a timestamp that is older or equal than the given timestamp.
bool callCommand(const std::shared_ptr< GenApi::CNodeMapRef > &nodemap, const char *name, bool exception=false)
void init(image_transport::ImageTransport &id)
Initialization of publisher.
void publish(const sensor_msgs::ImagePtr &image)
bool determineOffset(const std::shared_ptr< GenApi::CNodeMapRef > &nodemap)
Determine the offset between the system and camera clock.
#define ROS_WARN_STREAM(args)
void setTolerance(uint64_t tolerance)
Set tolerance for finding corresponding timestamps.
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)
std::shared_ptr< Device > getDevice(const char *devid)
static void clearSystems()
const std::string BAYER_BGGR8
int64_t correct(ros::Time &time)
Correct the given camera timestamp to system time.
std::string image_prefix_
void setMaximumTolerance(int64_t tol_ns)
Set the maximum tolerance for the offset between system and camera clock.
virtual ~GenICamCameraNodelet()
Subscriber subscribe(const std::string &topic, uint32_t queue_size, const boost::function< void(C)> &callback, const VoidConstPtr &tracked_object=VoidConstPtr(), const TransportHints &transport_hints=TransportHints())
#define ROS_INFO_STREAM(args)
sensor_msgs::CameraInfoPtr find(const ros::Time ×tamp) const
Returns the oldest camera info that has a timestamp within the tolerance of the given timestamp.
bool setGenICamParameter(rc_genicam_camera::SetGenICamParameter::Request &req, rc_genicam_camera::SetGenICamParameter::Response &resp)
ros::ServiceServer set_param_service_
bool setString(const std::shared_ptr< GenApi::CNodeMapRef > &nodemap, const char *name, const char *value, bool exception=false)
sensor_msgs::CameraInfoPtr add(const sensor_msgs::CameraInfoPtr &info)
Adds the given camera info to the internal list.
void init(ros::NodeHandle &nh, const char *calib_file, int id)
Initialization of publisher.
This class uses the GenICam command "TimestampLatch" and the parameter "TimestampLatchValue" to deter...
void setSize(size_t maxsize)
Set maximum size of the list.
bool getImagePresent(std::uint32_t part) const
void setTolerance(uint64_t tolerance)
Set tolerance for finding corresponding timestamps.
void setInterval(int64_t interval_ns)
Set minimum time between determination of offset.
std::shared_ptr< GenApi::CNodeMapRef > rcgnodemap_
T param(const std::string ¶m_name, const T &default_val) const
void syncInfo(sensor_msgs::CameraInfoPtr info)
const std::string BAYER_GRBG8
std::string getString(const std::shared_ptr< GenApi::CNodeMapRef > &nodemap, const char *name, bool exception=false, bool igncache=false)
ros::Subscriber sub_sync_info_
ImagePublisher image_pub_
std::shared_ptr< rcg::Device > rcgdev_
rc_genicam_camera
Author(s): Heiko Hirschmueller
autogenerated on Wed Mar 2 2022 00:49:18