Skip to content

[RSDK-13561] - Dedup device property setting#70

Merged
seanavery merged 5 commits intoviam-modules:mainfrom
seanavery:RSDK-13561
Apr 20, 2026
Merged

[RSDK-13561] - Dedup device property setting#70
seanavery merged 5 commits intoviam-modules:mainfrom
seanavery:RSDK-13561

Conversation

@seanavery
Copy link
Copy Markdown
Contributor

@seanavery seanavery commented Apr 14, 2026

Description

Simple PR to clean up device property setting

Testing

  • Manually tested call_get_properties on amd64
{"set_device_properties": 
{"OB_PROP_COLOR_AUTO_EXPOSURE_BOOL": {"current": false},
"OB_PROP_COLOR_EXPOSURE_INT": {"current": 33000}}}     
Screen.Recording.2026-04-15.at.3.00.11.PM.mov

Review

1 approval

} else if (property_item.type == OB_BOOL_PROPERTY) {
if (!property_map.begin()->second.is_a<bool>()) {
return {{"error", "Invalid type for bool property"}};
if (property_item.permission == OB_PERMISSION_DENY || property_item.permission == OB_PERMISSION_READ) {
Copy link
Copy Markdown
Contributor Author

@seanavery seanavery Apr 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added check here to make sure we have write permissions
(Moved away from setDeviceProperties)

device->setBoolProperty(property_item.id, bool_value);
} else {
return {{"error", "Unsupported property type"}};
} catch (ob::Error& e) {
Copy link
Copy Markdown
Contributor Author

@seanavery seanavery Apr 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added try/catch to cleanly return errors instead of unhandled exceptions.

return {{"error", "properties must be a struct"}};
}
std::unordered_set<std::string> writable_properties;
std::unordered_set<std::string> seen_properties;
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed seen_properties, setDeviceProperty handles unsupported prop names

Comment thread src/module/device_control.hpp Outdated
return {{"error", "Invalid type for float property"}};
}
float float_value = property_map.begin()->second.get_unchecked<double>();
device->setFloatProperty(property_item.id, float_value);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[opt] I wonder if we could make a templated helper function to reduce the duplicate code between the different types

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good idea, it would declutter this code a lot.
Sean, do you think you could do this as a follow up?, or in this PR?

Copy link
Copy Markdown
Contributor Author

@seanavery seanavery Apr 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be better as a follow-up or maybe punt on this all together. Looks like the realsense SDK uses different setters per type (setFloatProperty, setIntProperty, setBoolProperty), so, it would NOT be a clean templated:

  device->setProperty<int>(id, value);                                                      
  device->setProperty<float>(id, value);                                                    
  device->setProperty<bool>(id, value); 

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, added templated helper validateAndSetProperty that checks types and fans out to the corresponding realsense method.

Copy link
Copy Markdown
Collaborator

@oliviamiller oliviamiller left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice lgtm!

Copy link
Copy Markdown
Contributor

@SebastianMunozP SebastianMunozP left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@seanavery
Copy link
Copy Markdown
Contributor Author

Manually tested DoCommand with template header -- merging

@seanavery seanavery merged commit 87c23a0 into viam-modules:main Apr 20, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants