56   , system_(Spinnaker::System::GetInstance())
    57   , camList_(system_->GetCameras())
    58   , pCam_(static_cast<int>(NULL))  
    60   , camera_(static_cast<int>(NULL))
    61   , captureRunning_(false)
    63   unsigned int num_cameras = 
camList_.GetSize();
    81   std::lock_guard<std::mutex> scopedLock(
mutex_);
    85     ROS_DEBUG(
"SpinnakerCamera::setNewConfiguration: Reconfigure Stop.");
    89     camera_->setNewConfiguration(config, level);
    90     if (capture_was_running)
    95     camera_->setNewConfiguration(config, level);
   108     return camera_->getHeightMax();
   125     return camera_->readProperty(property_name);
   140       const auto serial_string = std::to_string(
serial_);
   146       catch (
const Spinnaker::Exception& e)
   148         throw std::runtime_error(
"[SpinnakerCamera::connect] Could not find camera with serial number " +
   149                                  serial_string + 
". Is that camera plugged in? Error: " + std::string(e.what()));
   159       catch (
const Spinnaker::Exception& e)
   161         throw std::runtime_error(
"[SpinnakerCamera::connect] Failed to get first connected camera. Error: " +
   162                                  std::string(e.what()));
   167       throw std::runtime_error(
"[SpinnakerCamera::connect] Failed to obtain camera reference.");
   173       Spinnaker::GenApi::INodeMap& genTLNodeMap = 
pCam_->GetTLDeviceNodeMap();
   177         Spinnaker::GenApi::CStringPtr serial_ptr =
   178             static_cast<Spinnaker::GenApi::CStringPtr
>(genTLNodeMap.GetNode(
"DeviceID"));
   179         if (IsAvailable(serial_ptr) && IsReadable(serial_ptr))
   181           serial_ = atoi(serial_ptr->GetValue().c_str());
   186           throw std::runtime_error(
"[SpinnakerCamera::connect]: Unable to determine serial number.");
   190       Spinnaker::GenApi::CEnumerationPtr device_type_ptr =
   191           static_cast<Spinnaker::GenApi::CEnumerationPtr
>(genTLNodeMap.GetNode(
"DeviceType"));
   193       if (IsAvailable(device_type_ptr) && IsReadable(device_type_ptr))
   195         ROS_INFO_STREAM(
"[SpinnakerCamera::connect]: Detected device type: " << device_type_ptr->ToString());
   197         if (device_type_ptr->GetCurrentEntry() == device_type_ptr->GetEntryByName(
"U3V"))
   199           Spinnaker::GenApi::CEnumerationPtr device_speed_ptr =
   200               static_cast<Spinnaker::GenApi::CEnumerationPtr
>(genTLNodeMap.GetNode(
"DeviceCurrentSpeed"));
   201           if (IsAvailable(device_speed_ptr) && IsReadable(device_speed_ptr))
   203             if (device_speed_ptr->GetCurrentEntry() != device_speed_ptr->GetEntryByName(
"SuperSpeed"))
   204               ROS_ERROR_STREAM(
"[SpinnakerCamera::connect]: U3V Device not running at Super-Speed. Check Cables! ");
   210     catch (
const Spinnaker::Exception& e)
   212       throw std::runtime_error(
"[SpinnakerCamera::connect] Failed to determine device info with error: " +
   213                                std::string(e.what()));
   225       Spinnaker::GenApi::CStringPtr model_name = 
node_map_->GetNode(
"DeviceModelName");
   226       std::string model_name_str(model_name->ToString());
   228       ROS_INFO(
"[SpinnakerCamera::connect]: Camera model name: %s", model_name_str.c_str());
   229       if (model_name_str.find(
"Blackfly S") != std::string::npos)
   231       else if (model_name_str.find(
"Chameleon3") != std::string::npos)
   233       else if (model_name_str.find(
"Grasshopper3") != std::string::npos)
   238         ROS_WARN(
"SpinnakerCamera::connect: Could not detect camera model name.");
   244     catch (
const Spinnaker::Exception& e)
   246       throw std::runtime_error(
"[SpinnakerCamera::connect] Failed to connect to camera. Error: " +
   247                                std::string(e.what()));
   249     catch (
const std::runtime_error& e)
   251       throw std::runtime_error(
"[SpinnakerCamera::connect] Failed to configure chunk data. Error: " +
   252                                std::string(e.what()));
   267   std::lock_guard<std::mutex> scopedLock(
mutex_);
   275       pCam_ = 
static_cast<int>(NULL);
   278     Spinnaker::CameraList temp_list = 
system_->GetCameras();
   281   catch (
const Spinnaker::Exception& e)
   283     throw std::runtime_error(
"[SpinnakerCamera::disconnect] Failed to disconnect camera with error: " +
   284                              std::string(e.what()));
   296       pCam_->BeginAcquisition();
   300   catch (
const Spinnaker::Exception& e)
   302     throw std::runtime_error(
"[SpinnakerCamera::start] Failed to start capture with error: " + std::string(e.what()));
   314       pCam_->EndAcquisition();
   316     catch (
const Spinnaker::Exception& e)
   318       throw std::runtime_error(
"[SpinnakerCamera::stop] Failed to stop capture with error: " + std::string(e.what()));
   325   std::lock_guard<std::mutex> scopedLock(
mutex_);
   333       Spinnaker::ImagePtr image_ptr = 
pCam_->GetNextImage(
timeout_);
   337       if (image_ptr->IsIncomplete())
   339         throw std::runtime_error(
"[SpinnakerCamera::grabImage] Image received from camera " + std::to_string(
serial_) +
   345         image->header.stamp.sec = image_ptr->GetTimeStamp() * 1e-9;
   346         image->header.stamp.nsec = image_ptr->GetTimeStamp();
   349         size_t bitsPerPixel = image_ptr->GetBitsPerPixel();
   355         Spinnaker::GenApi::CEnumerationPtr color_filter_ptr =
   356             static_cast<Spinnaker::GenApi::CEnumerationPtr
>(
node_map_->GetNode(
"PixelColorFilter"));
   358         Spinnaker::GenICam::gcstring color_filter_str = color_filter_ptr->ToString();
   359         Spinnaker::GenICam::gcstring bayer_rg_str = 
"BayerRG";
   360         Spinnaker::GenICam::gcstring bayer_gr_str = 
"BayerGR";
   361         Spinnaker::GenICam::gcstring bayer_gb_str = 
"BayerGB";
   362         Spinnaker::GenICam::gcstring bayer_bg_str = 
"BayerBG";
   365         if (color_filter_ptr->GetCurrentEntry() != color_filter_ptr->GetEntryByName(
"None"))
   367           if (bitsPerPixel == 16)
   370             if (color_filter_str.compare(bayer_rg_str) == 0)
   374             else if (color_filter_str.compare(bayer_gr_str) == 0)
   378             else if (color_filter_str.compare(bayer_gb_str) == 0)
   382             else if (color_filter_str.compare(bayer_bg_str) == 0)
   388               throw std::runtime_error(
"[SpinnakerCamera::grabImage] Bayer format not recognized for 16-bit format.");
   394             if (color_filter_str.compare(bayer_rg_str) == 0)
   398             else if (color_filter_str.compare(bayer_gr_str) == 0)
   402             else if (color_filter_str.compare(bayer_gb_str) == 0)
   406             else if (color_filter_str.compare(bayer_bg_str) == 0)
   412               throw std::runtime_error(
"[SpinnakerCamera::grabImage] Bayer format not recognized for 8-bit format.");
   418           if (bitsPerPixel == 16)
   422           else if (bitsPerPixel == 24)
   432         int width = image_ptr->GetWidth();
   433         int height = image_ptr->GetHeight();
   434         int stride = image_ptr->GetStride();
   437         fillImage(*image, imageEncoding, height, width, stride, image_ptr->GetData());
   438         image->header.frame_id = frame_id;
   441     catch (
const Spinnaker::Exception& e)
   443       throw std::runtime_error(
"[SpinnakerCamera::grabImage] Failed to retrieve buffer with error: " +
   444                                std::string(e.what()));
   450                                     "capturing frames first.");
   454     throw std::runtime_error(
"[SpinnakerCamera::grabImage] Not connected to the camera.");
   460   timeout_ = 
static_cast<uint64_t
>(std::round(timeout * 1000));
   479     Spinnaker::GenApi::CBooleanPtr ptrChunkModeActive = nodeMap.GetNode(
"ChunkModeActive");
   480     if (!Spinnaker::GenApi::IsAvailable(ptrChunkModeActive) || !Spinnaker::GenApi::IsWritable(ptrChunkModeActive))
   482       throw std::runtime_error(
"Unable to activate chunk mode. Aborting...");
   484     ptrChunkModeActive->SetValue(
true);
   500     Spinnaker::GenApi::NodeList_t entries;
   502     Spinnaker::GenApi::CEnumerationPtr ptrChunkSelector = nodeMap.GetNode(
"ChunkSelector");
   503     if (!Spinnaker::GenApi::IsAvailable(ptrChunkSelector) || !Spinnaker::GenApi::IsReadable(ptrChunkSelector))
   505       throw std::runtime_error(
"Unable to retrieve chunk selector. Aborting...");
   508     ptrChunkSelector->GetEntries(entries);
   512     for (
unsigned int i = 0; i < entries.size(); i++)
   515       Spinnaker::GenApi::CEnumEntryPtr ptrChunkSelectorEntry = entries.at(i);
   517       if (!Spinnaker::GenApi::IsAvailable(ptrChunkSelectorEntry) ||
   518           !Spinnaker::GenApi::IsReadable(ptrChunkSelectorEntry))
   522       ptrChunkSelector->SetIntValue(ptrChunkSelectorEntry->GetValue());
   526       Spinnaker::GenApi::CBooleanPtr ptrChunkEnable = nodeMap.GetNode(
"ChunkEnable");
   528       if (!Spinnaker::GenApi::IsAvailable(ptrChunkEnable))
   532       else if (ptrChunkEnable->GetValue())
   536       else if (Spinnaker::GenApi::IsWritable(ptrChunkEnable))
   538         ptrChunkEnable->SetValue(
true);
   547   catch (
const Spinnaker::Exception& e)
   549     throw std::runtime_error(e.what());
 
const std::string BAYER_GRBG8
void setGain(const float &gain)
void grabImage(sensor_msgs::Image *image, const std::string &frame_id)
Loads the raw data from the cameras buffer. 
std::mutex mutex_
A mutex to make sure that we don't try to grabImages while reconfiguring or vice versa. 
void disconnect()
Disconnects from the camera. 
const std::string BAYER_GRBG16
void connect()
Function that connects to a specified camera. 
const std::string BAYER_RGGB16
void ConfigureChunkData(const Spinnaker::GenApi::INodeMap &nodeMap)
static const uint8_t LEVEL_RECONFIGURE_STOP
Spinnaker::CameraList camList_
const std::string BAYER_GBRG8
Spinnaker::CameraPtr pCam_
const std::string BAYER_GBRG16
const std::string BAYER_BGGR16
void start()
Starts the camera loading data into its buffer. 
volatile bool captureRunning_
void setTimeout(const double &timeout)
Will set grabImage timeout for the camera. 
Spinnaker::GenApi::CNodePtr readProperty(const Spinnaker::GenICam::gcstring property_name)
void setDesiredCamera(const uint32_t &id)
Used to set the serial number for the camera you wish to connect to. 
#define ROS_INFO_STREAM_ONCE(args)
const std::string BAYER_BGGR8
#define ROS_INFO_STREAM(args)
Spinnaker::GenApi::INodeMap * node_map_
Interface to Point Grey cameras. 
const std::string BAYER_RGGB8
uint32_t serial_
A variable to hold the serial number of the desired camera. 
#define ROS_ERROR_STREAM(args)
void stop()
Stops the camera loading data into its buffer. 
Spinnaker::SystemPtr system_
std::shared_ptr< Camera > camera_
void setNewConfiguration(const spinnaker_camera_driver::SpinnakerConfig &config, const uint32_t &level)
Function that allows reconfiguration of the camera.