Skip to content

Commit

Permalink
add dynamic parameters (#141)
Browse files Browse the repository at this point in the history
In ROS 1, a number of things were dynamic - this PR re-adds them using
the new ROS 2 paradigm for parameter updating. I've tested this with a
Primesense device and am able to disable auto_exposure and
auto_white_balance.
  • Loading branch information
mikeferguson committed Nov 3, 2024
1 parent 774bf64 commit 5463573
Showing 1 changed file with 50 additions and 16 deletions.
66 changes: 50 additions & 16 deletions openni2_camera/src/openni2_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,52 @@ rcl_interfaces::msg::SetParametersResult OpenNI2Driver::paramCb(
{
auto result = rcl_interfaces::msg::SetParametersResult();

RCLCPP_WARN(this->get_logger(), "parameter change callback");
// Assume success until we fail
result.successful = true;

// Apply parameters
for (const auto & param : parameters)
{
if (param.get_name() == "z_offset_mm")
{
z_offset_mm_ = param.as_int();
}
else if (param.get_name() == "z_scaling")
{
z_scaling_ = param.as_double();
}
else if (param.get_name() == "ir_time_offset")
{
ir_time_offset_ = param.as_double();
}
else if (param.get_name() == "color_time_offset")
{
color_time_offset_ = param.as_double();
}
else if (param.get_name() == "depth_time_offset")
{
depth_time_offset_ = param.as_double();
}
else if (param.get_name() == "auto_exposure")
{
auto_exposure_ = param.as_bool();
}
else if (param.get_name() == "auto_white_balance")
{
auto_white_balance_ = param.as_bool();
}
else if (param.get_name() == "exposure")
{
exposure_ = param.as_int();
}
else
{
RCLCPP_WARN(this->get_logger(), "Parameter %s is not settable", param.get_name().c_str());
result.successful = false;
}
}

applyConfigToOpenNIDevice();
return result;
}

Expand Down Expand Up @@ -273,11 +318,7 @@ void OpenNI2Driver::applyConfigToOpenNIDevice()
{
try
{
//if (!config_init_ || (old_config_.depth_registration != depth_registration_))
if (depth_registration_)
{
device_->setImageRegistrationMode(depth_registration_);
}
device_->setImageRegistrationMode(depth_registration_);
}
catch (const OpenNI2Exception& exception)
{
Expand All @@ -287,9 +328,7 @@ void OpenNI2Driver::applyConfigToOpenNIDevice()

try
{
//if (!config_init_ || (old_config_.color_depth_synchronization != color_depth_synchronization_))
if (color_depth_synchronization_)
device_->setDepthColorSync(color_depth_synchronization_);
device_->setDepthColorSync(color_depth_synchronization_);
}
catch (const OpenNI2Exception& exception)
{
Expand All @@ -298,9 +337,7 @@ void OpenNI2Driver::applyConfigToOpenNIDevice()

try
{
//if (!config_init_ || (old_config_.auto_exposure != auto_exposure_))
if (auto_exposure_)
device_->setAutoExposure(auto_exposure_);
device_->setAutoExposure(auto_exposure_);
}
catch (const OpenNI2Exception& exception)
{
Expand All @@ -309,9 +346,7 @@ void OpenNI2Driver::applyConfigToOpenNIDevice()

try
{
//if (!config_init_ || (old_config_.auto_white_balance != auto_white_balance_))
if (auto_white_balance_)
device_->setAutoWhiteBalance(auto_white_balance_);
device_->setAutoWhiteBalance(auto_white_balance_);
}
catch (const OpenNI2Exception& exception)
{
Expand All @@ -331,7 +366,6 @@ void OpenNI2Driver::applyConfigToOpenNIDevice()
// Setting the exposure the old way, although this should not have an effect
try
{
//if (!config_init_ || (old_config_.exposure != exposure_))
device_->setExposure(exposure_);
}
catch (const OpenNI2Exception& exception)
Expand Down

0 comments on commit 5463573

Please sign in to comment.