Skip to content

Commit

Permalink
Make sure power is on before setting a feature to any other mode (#15).
Browse files Browse the repository at this point in the history
  • Loading branch information
jack-oquin committed Aug 18, 2013
1 parent 7481d14 commit 491e0e1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.rst
Expand Up @@ -5,6 +5,8 @@ Change history
-------------------

* Add external triggering support (`#9`_), thanks to Boris Gromov.
* Turn power on for a feature before setting its operating mode
(`#15`_).

1.9.4 (2013-08-03)
------------------
Expand Down Expand Up @@ -126,6 +128,7 @@ Change history
.. _`#9`: https://github.com/ros-drivers/camera1394/pull/9
.. _`#10`: https://github.com/ros-drivers/camera1394/issues/10
.. _`#11`: https://github.com/ros-drivers/camera1394/pull/11
.. _`#15`: https://github.com/ros-drivers/camera1394/issues/15
.. _`#4222`: https://code.ros.org/trac/ros-pkg/ticket/4222
.. _`#4251`: https://code.ros.org/trac/ros-pkg/ticket/4251
.. _`#4261`: https://code.ros.org/trac/ros-pkg/ticket/4261
Expand Down
29 changes: 17 additions & 12 deletions src/nodes/features.cpp
Expand Up @@ -293,7 +293,7 @@ void Features::configure(dc1394feature_t feature, int *control,
switch (*control)
{
case camera1394::Camera1394_Off:
setOff(finfo);
setPower(finfo, DC1394_OFF);
break;

case camera1394::Camera1394_Query:
Expand All @@ -303,14 +303,14 @@ void Features::configure(dc1394feature_t feature, int *control,
case camera1394::Camera1394_Auto:
if (!setMode(finfo, DC1394_FEATURE_MODE_AUTO))
{
setOff(finfo);
setPower(finfo, DC1394_OFF);
}
break;

case camera1394::Camera1394_Manual:
if (!setMode(finfo, DC1394_FEATURE_MODE_MANUAL))
{
setOff(finfo);
setPower(finfo, DC1394_OFF);
break;
}

Expand Down Expand Up @@ -390,7 +390,7 @@ void Features::configure(dc1394feature_t feature, int *control,
setMode(finfo, DC1394_FEATURE_MODE_ONE_PUSH_AUTO);

// Now turn the control off, so camera does not continue adjusting
setOff(finfo);
setPower(finfo, DC1394_OFF);
break;

case camera1394::Camera1394_None:
Expand Down Expand Up @@ -573,6 +573,9 @@ bool Features::setMode(dc1394feature_info_t *finfo, dc1394feature_mode_t mode)
dc1394feature_t feature = finfo->id;
if (hasMode(finfo, mode))
{
// first, make sure the feature is powered on
setPower(finfo, DC1394_ON);

ROS_DEBUG_STREAM("setting feature " << featureName(feature)
<< " mode to " << modeName(mode));
if (DC1394_SUCCESS !=
Expand All @@ -593,30 +596,32 @@ bool Features::setMode(dc1394feature_info_t *finfo, dc1394feature_mode_t mode)
return true;
}

/** Set a feature Off.
/** Set power for a feature On or Off.
*
* @pre feature_set_ initialized for this camera
*
* @param finfo pointer to information for this feature
* @param on_off either DC1394_ON or DC1394_OFF
*/
void Features::setOff(dc1394feature_info_t *finfo)
void Features::setPower(dc1394feature_info_t *finfo, dc1394switch_t on_off)
{
dc1394feature_t feature = finfo->id;
if (finfo->on_off_capable)
{
ROS_DEBUG_STREAM("setting feature " << featureName(feature) << " Off");
ROS_DEBUG_STREAM("Setting power for feature " << featureName(feature)
<< " to " << on_off);
if (DC1394_SUCCESS !=
dc1394_feature_set_power(camera_, feature, DC1394_OFF))
dc1394_feature_set_power(camera_, feature, on_off))
{
ROS_WARN_STREAM("failed to set feature " << featureName(feature)
<< " Off ");
<< " power to " << on_off);
}
}
else
{
// This device does not support turning this feature off.
// Inform the user, but pretend it worked.
ROS_DEBUG_STREAM("no Off mode for feature " << featureName(feature));
// This device does not support turning this feature on or off.
// That's OK.
ROS_DEBUG_STREAM("no power control for feature " << featureName(feature));
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/nodes/features.h
Expand Up @@ -110,7 +110,7 @@ class Features
boost::shared_ptr<Trigger> trigger_;

bool setMode(dc1394feature_info_t *finfo, dc1394feature_mode_t mode);
void setOff(dc1394feature_info_t *finfo);
void setPower(dc1394feature_info_t *finfo, dc1394switch_t on_off);
void updateIfChanged(dc1394feature_t feature,
int old_control, int *control,
double old_value, double *value);
Expand Down

0 comments on commit 491e0e1

Please sign in to comment.