-
Notifications
You must be signed in to change notification settings - Fork 28
Implement configurable frames for virtual objects #109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,7 +41,7 @@ struct VirtualObjectMarkerPublisher | |
| VirtualObjectMarkerPublisher(ensenso::ros::NodeHandle _nh, const std::string& topic, double publishRate, | ||
| const NxLibItem& objects, const std::string& frame, std::atomic_bool& stop_) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As mentioned below,
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Getting the following error when using the suggested
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, that must be
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Got the following runtime error now after using
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If it's okay for you, push your temporary changes and then I can have a look ;)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line 213
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Which version of Ensenso SDK do you use?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just tried it with both 3.3.1417 and 3.4.743, both with the same results. In line 168 you write the objects to the NxLib tree. From there on they are in the tree. Getting the target name in line 213 should work, unless you are modifying the tree from somewhere else? Are you perhaps adding or removing objects in the meantime? The error could e.g. occur if you added another object meanwhile, which has no target node. In case you want to be able to add and remove objects during operation, storing the object frames as you initially did would be required.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes I do add other objects in the meantime. I have two
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay I see. Then there is the problem. Since you guys are currently the only one developing (and maybe even using) this feature, it is quite hard for me - or us in general - to review the code. Do you think you could maybe write a test case that also acts as kind of a documentation? Then I can get an idea of how your code is supposed to work. |
||
| : nh(std::move(_nh)), rate(publishRate), stop(stop_) | ||
| { | ||
| { | ||
| // Create output topic | ||
| publisher = ensenso::ros::create_publisher<visualization_msgs::msg::MarkerArray>(nh, topic, 1); | ||
|
|
||
|
|
@@ -55,7 +55,7 @@ struct VirtualObjectMarkerPublisher | |
| marker.ns = ensenso::ros::get_node_name(nh); | ||
| marker.id = i; | ||
| marker.header.stamp = ensenso::ros::Time(0); | ||
| marker.header.frame_id = frame; | ||
| marker.header.frame_id = object[itmLink][itmTarget].asString(); | ||
| marker.action = visualization_msgs::msg::Marker::MODIFY; // Note: ADD = MODIFY | ||
|
|
||
| // Set color | ||
|
|
@@ -171,6 +171,7 @@ VirtualObjectHandler::VirtualObjectHandler(ensenso::ros::NodeHandle& nh, const s | |
| for (int i = 0; i < objects.count(); ++i) | ||
| { | ||
| originalTransforms.push_back(transformFromNxLib(objects[i][itmLink])); | ||
| objectFrames.push_back(objects[i][itmLink][itmTarget].asString()); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we do not need to store the objects frames, this line can be removed.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lines 166 and 167 could be changed to the following in order to make the interaction with the tree more clear: Since the objects are now written to the tree, we can simply read them from the tree whenever we need and do not have to pass the objects around. Both |
||
| } | ||
|
|
||
| // Create publisher thread | ||
|
|
@@ -201,24 +202,24 @@ void VirtualObjectHandler::updateObjectLinks() | |
| { | ||
| return; | ||
| } | ||
|
|
||
| // Find transform from the frame in which the objects were defined to the current optical frame | ||
| tf2::Transform cameraTransform; | ||
| try | ||
| { | ||
| cameraTransform = fromMsg(tfBuffer.lookupTransform(linkFrame, objectsFrame, ensenso::ros::Time(0)).transform); | ||
| } | ||
| catch (const tf2::TransformException& e) | ||
| { | ||
| ENSENSO_WARN("Could not look up the virtual object pose due to the TF error: %s", e.what()); | ||
| return; | ||
| } | ||
|
|
||
| auto objects = NxLibItem()[itmObjects]; | ||
| // Apply the transform to all of the original transforms | ||
| for (size_t i = 0; i < originalTransforms.size(); ++i) | ||
| for (int i = 0; i < objects.count(); ++i) | ||
| { | ||
| tf2::Transform objectTransform = cameraTransform * originalTransforms[i]; | ||
| NxLibItem objectLink = NxLibItem{ itmObjects }[static_cast<int>(i)][itmLink]; | ||
| writeTransformToNxLib(objectTransform.inverse(), objectLink); | ||
| auto objectLink = objects[i][itmLink]; | ||
| try | ||
| { | ||
| // Find the transformation from the object frame to the current optical frame | ||
| auto objectFrame = objectLink[itmTarget].asString(); | ||
| auto cameraTransform = fromMsg(tfBuffer.lookupTransform(linkFrame, objectFrame, ensenso::ros::Time(0)).transform); | ||
| // Transform object back to original frame | ||
| tf2::Transform objectTransform = cameraTransform * originalTransforms[i]; | ||
| writeTransformToNxLib(objectTransform.inverse(), objectLink); | ||
| } | ||
| catch (const tf2::TransformException& e) | ||
| { | ||
| ENSENSO_WARN("Could not look up the virtual object pose due to the TF error: %s", e.what()); | ||
| return; | ||
| } | ||
| } | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are the object frames going to change during operation? I guess not, and if so, I think we do not need to store them but can read them from the NxLib tree, see the comments in the .cpp file.