Skip to content

Commit

Permalink
Merge pull request #25 from bgromov/camera_poll
Browse files Browse the repository at this point in the history
Poll camera whenever external trigger is ON (fix #22)
  • Loading branch information
jack-oquin committed Sep 29, 2013
2 parents 3ba625e + d279c2d commit c307a9a
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 11 deletions.
24 changes: 18 additions & 6 deletions src/nodes/dev_camera1394.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -449,17 +449,27 @@ std::string bayer_string(dc1394color_filter_t pattern, unsigned int bits)
}

/** Return an image frame */
void Camera1394::readData(sensor_msgs::Image& image)
bool Camera1394::readData(sensor_msgs::Image& image)
{
ROS_ASSERT_MSG(camera_, "Attempt to read from camera that is not open.");

dc1394video_frame_t * frame = NULL;
dc1394_capture_dequeue (camera_, DC1394_CAPTURE_POLICY_WAIT, &frame);
if (!frame)
if (features_->isTriggerPowered())
{
ROS_DEBUG("[%016lx] polling camera", camera_->guid);
dc1394_capture_dequeue (camera_, DC1394_CAPTURE_POLICY_POLL, &frame);
if (!frame) return false;
}
else
{
ROS_DEBUG("[%016lx] waiting camera", camera_->guid);
dc1394_capture_dequeue (camera_, DC1394_CAPTURE_POLICY_WAIT, &frame);
if (!frame)
{
CAM_EXCEPT(camera1394::Exception, "Unable to capture frame");
return;
return false;
}
}

uint8_t* capture_buffer;

Expand All @@ -486,7 +496,7 @@ void Camera1394::readData(sensor_msgs::Image& image)
free(frame2.image);
dc1394_capture_enqueue(camera_, frame);
CAM_EXCEPT(camera1394::Exception, "Could not convert/debayer frames");
return;
return false;
}

capture_buffer = reinterpret_cast<uint8_t *>(frame2.image);
Expand Down Expand Up @@ -604,11 +614,13 @@ void Camera1394::readData(sensor_msgs::Image& image)
else
{
CAM_EXCEPT(camera1394::Exception, "Unknown image mode");
return;
return false;
}
}
dc1394_capture_enqueue(camera_, frame);

if (DoBayerConversion_)
free(capture_buffer);

return true;
}
2 changes: 1 addition & 1 deletion src/nodes/dev_camera1394.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ namespace camera1394

int open(camera1394::Camera1394Config &newconfig);
int close();
void readData (sensor_msgs::Image &image);
bool readData (sensor_msgs::Image &image);

/** check whether CameraInfo matches current video mode
*
Expand Down
2 changes: 1 addition & 1 deletion src/nodes/driver1394.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ namespace camera1394_driver
{
// Read data from the Camera
ROS_DEBUG_STREAM("[" << camera_name_ << "] reading data");
dev_->readData(*image);
success = dev_->readData(*image);
ROS_DEBUG_STREAM("[" << camera_name_ << "] read returned");
}
catch (camera1394::Exception& e)
Expand Down
8 changes: 6 additions & 2 deletions src/nodes/features.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,9 @@
#include <dc1394/dc1394.h>

#include "camera1394/Camera1394Config.h"
#include "trigger.h"
typedef camera1394::Camera1394Config Config;

class Trigger; // actually defined in trigger.h

/** @file
@brief Camera1394 features interface
Expand All @@ -68,6 +67,11 @@ class Features
bool initialize(Config *newconfig);
void reconfigure(Config *newconfig);

inline bool isTriggerPowered()
{
return trigger_->isPowered();
}

private:
typedef int state_t; ///< camera1394::Camera1394_* state values

Expand Down
5 changes: 5 additions & 0 deletions src/nodes/trigger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ dc1394switch_t Trigger::getExternalTriggerPowerState(dc1394camera_t *camera)
ROS_FATAL("getExternalTriggerPowerState() failed: %d", err);
return (dc1394switch_t)-1; // failure
}
externalTriggerPowerState_ = state;
return state;
}

Expand All @@ -267,6 +268,7 @@ bool Trigger::setExternalTriggerPowerState(dc1394camera_t *camera, dc1394switch_
ROS_FATAL("setExternalTriggerPowerState() failed: %d", err);
return false; // failure
}
externalTriggerPowerState_ = state;
ROS_DEBUG("setExternalTriggerPowerState(): %s", (state == DC1394_ON ? "ON" : "OFF"));
return true; // success
}
Expand Down Expand Up @@ -514,6 +516,9 @@ bool Trigger::initialize(Config *newconfig)
return false;
}

// Update externalTriggerPowerState_ variable with current value
Trigger::getExternalTriggerPowerState(camera_);

// configure trigger features
return reconfigure(newconfig);
}
15 changes: 14 additions & 1 deletion src/nodes/trigger.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ class Trigger
dc1394trigger_sources_t triggerSources_;
dc1394trigger_polarity_t triggerPolarity_;

dc1394switch_t externalTriggerPowerState_;

bool findTriggerMode(std::string str);
bool findTriggerSource(std::string str);
bool findTriggerPolarity(std::string str);
Expand All @@ -80,7 +82,7 @@ class Trigger
* @param camera address of DC1394 camera structure.
*/
Trigger(dc1394camera_t *camera):
camera_(camera), triggerSources_((dc1394trigger_sources_t){0})
camera_(camera), triggerSources_((dc1394trigger_sources_t){0}), externalTriggerPowerState_(DC1394_OFF)
{};

/** Return driver parameter name of DC1394 trigger_mode.
Expand Down Expand Up @@ -122,6 +124,17 @@ class Trigger
return "";
}

/** Checks whether external trigger power is ON or OFF.
* This method uses cached value, which is updated every
* time the settings are changed by user
*
* @return true if external trigger power is ON; false if not
*/
inline bool isPowered()
{
return (externalTriggerPowerState_ == DC1394_ON ? true : false);
}

bool enumSources(dc1394camera_t *camera, dc1394trigger_sources_t &sources);
dc1394trigger_polarity_t getPolarity(dc1394camera_t *camera);
bool setPolarity(dc1394camera_t *camera, dc1394trigger_polarity_t &polarity);
Expand Down

0 comments on commit c307a9a

Please sign in to comment.