36 #include <boost/format.hpp> 42 srv_(priv_nh), it_(node)
54 int major, minor, build;
56 ROS_INFO(
"Loaded uEye SDK %s.", version);
58 ROS_WARN(
"Loaded uEye SDK %d.%d.%d. Expecting %s.", major, minor, build, version);
63 if (num_cameras > 0) {
64 if (num_cameras == 1) {
68 ROS_INFO(
"Found %d uEye cameras.", num_cameras);
86 if (priv_nh.
getParam(
"lSerialNo",
id)) {
88 ROS_ERROR(
"Failed to open uEye camera with serialNo: %u.",
id);
92 }
else if (priv_nh.
getParam(
"lDeviceId",
id)) {
94 ROS_ERROR(
"Failed to open uEye camera with deviceId: %u.",
id);
101 ROS_ERROR(
"Failed to open uEye camera with cameraId: %u.",
id);
108 if (priv_nh.
getParam(
"rSerialNo",
id)) {
110 ROS_ERROR(
"Failed to open uEye camera with serialNo: %u.",
id);
114 }
else if (priv_nh.
getParam(
"rDeviceId",
id)) {
116 ROS_ERROR(
"Failed to open uEye camera with deviceId: %u.",
id);
123 ROS_ERROR(
"Failed to open uEye camera with cameraId: %u.",
id);
138 dynamic_reconfigure::Server<stereoConfig>::CallbackType
f = boost::bind(&
StereoNode::reconfig,
this, _1, _2);
153 if (path.length() == 0) {
158 unsigned int length = path.length();
160 if (path.c_str()[length - 1] ==
'/') {
161 path = path.substr(0, length - 1);
170 switch (config.color) {
172 case mono_COLOR_MONO8:
175 case mono_COLOR_MONO16:
181 case mono_COLOR_YCbCr:
184 case mono_COLOR_BGR5:
187 case mono_COLOR_BGR565:
190 case mono_COLOR_BGR8:
193 case mono_COLOR_BGRA8:
196 case mono_COLOR_BGRY8:
199 case mono_COLOR_RGB8:
202 case mono_COLOR_RGBA8:
205 case mono_COLOR_RGBY8:
227 if (!config.auto_gain) {
232 if (cam.
getZoom() != config.zoom) {
237 if (config.trigger == stereo_TGR_SOFTWARE) {
243 ROS_INFO(
"config.trigger %d", config.trigger);
250 if (!config.auto_exposure) {
266 switch (config.trigger) {
267 case stereo_TGR_SOFTWARE:
268 case stereo_TGR_HARDWARE_RISING:
271 case stereo_TGR_HARDWARE_FALLING:
274 case stereo_TGR_L_MASTER_R_RISING:
277 l_flash = flash_active_mode;
279 case stereo_TGR_L_MASTER_R_FALLING:
282 l_flash = flash_active_mode;
284 case stereo_TGR_R_MASTER_L_RISING:
287 r_flash = flash_active_mode;
289 case stereo_TGR_R_MASTER_L_FALLING:
292 r_flash = flash_active_mode;
294 case stereo_TGR_AUTO:
296 config.trigger = stereo_TGR_AUTO;
301 ROS_ERROR(
"Failed to configure triggers");
304 config.trigger = stereo_TGR_AUTO;
308 l_cam_.
setFlash(l_flash, config.flash_delay, config.flash_duration);
309 r_cam_.
setFlash(r_flash, config.flash_delay, config.flash_duration);
339 if (
zoom_ != config.zoom) {
365 ROS_WARN(
"Failed to force trigger");
373 Camera& cam, sensor_msgs::CameraInfo &msg_info)
375 ROS_INFO(
"New camera info received");
376 sensor_msgs::CameraInfo &info = req.camera_info;
377 info.header.frame_id = msg_info.header.frame_id;
381 unsigned int width = cam.
getWidth();
383 if (info.width != width || info.height != height) {
385 rsp.status_message = (boost::format(
"Camera_info resolution %ix%i does not match current video " 386 "setting, camera running at resolution %ix%i.") % info.width % info.height
387 % width % height).str();
388 ROS_ERROR(
"%s", rsp.status_message.c_str());
393 std::stringstream ini_stream;
395 rsp.status_message =
"Error formatting camera_info for storage.";
398 std::string ini = ini_stream.str();
399 std::fstream param_file;
401 param_file.open(filename.c_str(), std::ios::in | std::ios::out | std::ios::trunc);
403 if (param_file.is_open()) {
404 param_file << ini.c_str();
411 rsp.status_message =
"file write failed";
415 ROS_ERROR(
"%s", rsp.status_message.c_str());
434 std::fstream param_file;
435 param_file.open(MyPath.c_str(), std::ios::in);
437 if (param_file.is_open()) {
438 param_file.read(buffer, 12800);
443 std::string camera_name;
447 ROS_WARN(
"Failed to load intrinsics for camera from file");
453 sensor_msgs::CameraInfoPtr &info, sensor_msgs::CameraInfo &msg_info)
455 msg_info.roi.x_offset = 0;
456 msg_info.roi.y_offset = 0;
459 msg_info.roi.width = 0;
460 msg_info.roi.height = 0;
461 sensor_msgs::CameraInfoPtr msg(
new sensor_msgs::CameraInfo(msg_info));
464 sensor_msgs::ImagePtr msg_image(
new sensor_msgs::Image());
465 msg_image->header = msg_info.header;
466 msg_image->height = msg_info.height;
467 msg_image->width = msg_info.width;
469 msg_image->is_bigendian =
false;
470 msg_image->step = size / msg_image->height;
471 msg_image->data.resize(size);
472 memcpy(msg_image->data.data(), frame, size);
480 boost::lock_guard<boost::mutex> lock(
mutex_);
483 if ((diff >= 0) && (diff < 0.02)) {
488 sensor_msgs::CameraInfoPtr info;
495 boost::lock_guard<boost::mutex> lock(
mutex_);
498 if ((diff >= 0) && (diff < 0.02)) {
503 sensor_msgs::CameraInfoPtr info;
unsigned int getHardwareGain()
void handlePath(std::string &path)
dynamic_reconfigure::Server< stereoConfig > srv_
void publish(const sensor_msgs::Image &image, const sensor_msgs::CameraInfo &info) const
void setFlash(FlashMode mode, int delay_usec, unsigned int duration_usec)
void setHardwareGain(int *gain)
void loadIntrinsics(Camera &cam, sensor_msgs::CameraInfo &msg_info)
ros::ServiceServer r_srv_cam_info_
static const char * colorModeToString(uEyeColor mode)
unsigned int getCameraSerialNo() const
uint32_t getNumSubscribers() const
void setAutoGain(bool *enable)
void setPeriod(const Duration &period, bool reset=true)
const char * getCameraName() const
bool setTriggerMode(TriggerMode mode)
sensor_msgs::CameraInfo r_msg_camera_info_
image_transport::CameraPublisher l_pub_stream_
bool setCameraInfo(sensor_msgs::SetCameraInfo::Request &req, sensor_msgs::SetCameraInfo::Response &rsp, Camera &cam, sensor_msgs::CameraInfo &msg_info)
image_transport::CameraPublisher r_pub_stream_
ServiceServer advertiseService(const std::string &service, bool(T::*srv_func)(MReq &, MRes &), T *obj)
ros::ServiceServer l_srv_cam_info_
void setTriggerDelay(int delay_usec)
ros::Timer timer_force_trigger_
bool getGainBoost() const
void setHardwareGamma(bool *enable)
void timerCallback(const ros::TimerEvent &event)
CameraPublisher advertiseCamera(const std::string &base_topic, uint32_t queue_size, bool latch=false)
bool getAutoExposure() const
void reconfig(stereoConfig &config, uint32_t level)
void setAutoExposure(bool *enable)
bool openCameraDevId(unsigned int id)
Timer createTimer(Rate r, Handler h, Obj o, bool oneshot=false, bool autostart=true) const
sensor_msgs::ImagePtr processFrame(const char *frame, size_t size, const Camera &cam, sensor_msgs::CameraInfoPtr &info, sensor_msgs::CameraInfo &msg_info)
void setGainBoost(bool *enable)
bool writeCalibrationIni(std::ostream &out, const std::string &camera_name, const sensor_msgs::CameraInfo &cam_info)
int getNumberOfCameras() const
void startVideoCapture(CamCaptureCB)
int getPixelClock() const
void setPixelClock(int *MHz)
ROSLIB_DECL std::string getPath(const std::string &package_name)
void publishImageR(const char *frame, size_t size)
void setColorMode(uEyeColor mode)
StereoNode(ros::NodeHandle node, ros::NodeHandle private_nh)
sensor_msgs::CameraInfo l_msg_camera_info_
bool getParam(const std::string &key, std::string &s) const
void setFrameRate(double *rate)
void timerForceTrigger(const ros::TimerEvent &event)
bool openCameraSerNo(unsigned int serial_number)
static std::string configFileName(const Camera &cam)
ROSCPP_DECL void shutdown()
void setExposure(double *time_ms)
bool parseCalibrationIni(const std::string &buffer, std::string &camera_name, sensor_msgs::CameraInfo &cam_info)
void reconfigCam(stereoConfig &config, uint32_t level, Camera &cam)
uEyeColor getColorMode() const
image_transport::ImageTransport it_
bool setCameraInfoL(sensor_msgs::SetCameraInfo::Request &req, sensor_msgs::SetCameraInfo::Response &rsp)
static bool checkVersion(int &major, int &minor, int &build, const char *&expected)
void publishImageL(const char *frame, size_t size)
bool getHardwareGamma() const
bool openCameraCamId(unsigned int id)
bool setCameraInfoR(sensor_msgs::SetCameraInfo::Request &req, sensor_msgs::SetCameraInfo::Response &rsp)