Skip to content

Commit b277de3

Browse files
authored
add dynamic parameters (#141)
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.
1 parent fb11843 commit b277de3

File tree

1 file changed

+50
-16
lines changed

1 file changed

+50
-16
lines changed

openni2_camera/src/openni2_driver.cpp

Lines changed: 50 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,52 @@ rcl_interfaces::msg::SetParametersResult OpenNI2Driver::paramCb(
234234
{
235235
auto result = rcl_interfaces::msg::SetParametersResult();
236236

237-
RCLCPP_WARN(this->get_logger(), "parameter change callback");
237+
// Assume success until we fail
238+
result.successful = true;
239+
240+
// Apply parameters
241+
for (const auto & param : parameters)
242+
{
243+
if (param.get_name() == "z_offset_mm")
244+
{
245+
z_offset_mm_ = param.as_int();
246+
}
247+
else if (param.get_name() == "z_scaling")
248+
{
249+
z_scaling_ = param.as_double();
250+
}
251+
else if (param.get_name() == "ir_time_offset")
252+
{
253+
ir_time_offset_ = param.as_double();
254+
}
255+
else if (param.get_name() == "color_time_offset")
256+
{
257+
color_time_offset_ = param.as_double();
258+
}
259+
else if (param.get_name() == "depth_time_offset")
260+
{
261+
depth_time_offset_ = param.as_double();
262+
}
263+
else if (param.get_name() == "auto_exposure")
264+
{
265+
auto_exposure_ = param.as_bool();
266+
}
267+
else if (param.get_name() == "auto_white_balance")
268+
{
269+
auto_white_balance_ = param.as_bool();
270+
}
271+
else if (param.get_name() == "exposure")
272+
{
273+
exposure_ = param.as_int();
274+
}
275+
else
276+
{
277+
RCLCPP_WARN(this->get_logger(), "Parameter %s is not settable", param.get_name().c_str());
278+
result.successful = false;
279+
}
280+
}
281+
282+
applyConfigToOpenNIDevice();
238283
return result;
239284
}
240285

@@ -295,11 +340,7 @@ void OpenNI2Driver::applyConfigToOpenNIDevice()
295340
{
296341
try
297342
{
298-
//if (!config_init_ || (old_config_.depth_registration != depth_registration_))
299-
if (depth_registration_)
300-
{
301-
device_->setImageRegistrationMode(depth_registration_);
302-
}
343+
device_->setImageRegistrationMode(depth_registration_);
303344
}
304345
catch (const OpenNI2Exception& exception)
305346
{
@@ -309,9 +350,7 @@ void OpenNI2Driver::applyConfigToOpenNIDevice()
309350

310351
try
311352
{
312-
//if (!config_init_ || (old_config_.color_depth_synchronization != color_depth_synchronization_))
313-
if (color_depth_synchronization_)
314-
device_->setDepthColorSync(color_depth_synchronization_);
353+
device_->setDepthColorSync(color_depth_synchronization_);
315354
}
316355
catch (const OpenNI2Exception& exception)
317356
{
@@ -320,9 +359,7 @@ void OpenNI2Driver::applyConfigToOpenNIDevice()
320359

321360
try
322361
{
323-
//if (!config_init_ || (old_config_.auto_exposure != auto_exposure_))
324-
if (auto_exposure_)
325-
device_->setAutoExposure(auto_exposure_);
362+
device_->setAutoExposure(auto_exposure_);
326363
}
327364
catch (const OpenNI2Exception& exception)
328365
{
@@ -331,9 +368,7 @@ void OpenNI2Driver::applyConfigToOpenNIDevice()
331368

332369
try
333370
{
334-
//if (!config_init_ || (old_config_.auto_white_balance != auto_white_balance_))
335-
if (auto_white_balance_)
336-
device_->setAutoWhiteBalance(auto_white_balance_);
371+
device_->setAutoWhiteBalance(auto_white_balance_);
337372
}
338373
catch (const OpenNI2Exception& exception)
339374
{
@@ -353,7 +388,6 @@ void OpenNI2Driver::applyConfigToOpenNIDevice()
353388
// Setting the exposure the old way, although this should not have an effect
354389
try
355390
{
356-
//if (!config_init_ || (old_config_.exposure != exposure_))
357391
device_->setExposure(exposure_);
358392
}
359393
catch (const OpenNI2Exception& exception)

0 commit comments

Comments
 (0)