-
Notifications
You must be signed in to change notification settings - Fork 276
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
Add support for cloning entities #959
Conversation
Signed-off-by: Ashton Larkin <[email protected]>
Currently, I am having an issue where the cloned entity cannot be moved. Here's what I am seeing when I run through the steps in the Does anyone know what might be causing this? |
I looked a bit into it and I'm not sure. I verified that:
I did notice that the code never reaches this point when moving the copied model, but it does when moving other models: My suggestion would be to trace back what's missing for the code to get there. I hope that helps |
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.
looks like the box
and box_copy
have the same canonical link in the physics system. Maybe when cloning the entity, you'll need to update the cloned entity's canonical link to the cloned child link?
Signed-off-by: Ashton Larkin <[email protected]>
Yeah, that was the issue! I addressed this in 8b0e17c, and things seem to be working now. So, this PR should be ready for review 🤞 One other thing to note is a TODO note that I left in the code: https://github.com/ignitionrobotics/ign-gazebo/blob/8b0e17c2887028a8662aea087d2905a31679ecae/src/systems/user_commands/UserCommands.cc#L744 This is referring to the following field in the We have a method for getting the pose of an entity in the world: https://github.com/ignitionrobotics/ign-gazebo/blob/09e2ea78bf10d0bf84871e4ad3d0e120b85100eb/include/ignition/gazebo/Util.hh#L38-L43 Do we have any other similar methods for getting the pose of an entity in a particular frame? |
Signed-off-by: Ashton Larkin <[email protected]>
There is this RelativePose function in the physics system that may be useful here? |
copying simple shapes and meshes work well. I then tried to copy lights and sensors and ran into issues:
I'm testing with
|
actually I think this may be ok. It's the same behavior when user tries to insert the same sensor model twice into the scene. If a user wants different camera topics, they will need to leave out the |
Signed-off-by: Ashton Larkin <[email protected]>
Signed-off-by: Ashton Larkin <[email protected]>
Okay, so looking into this has been quite the debugging journey! There appeared to be a few issues:
I've noticed some other strange behavior when testing cloning lights. I made the following change to --- a/src/rendering/SceneManager.cc
+++ b/src/rendering/SceneManager.cc
@@ -1108,7 +1108,13 @@ rendering::LightPtr SceneManager::CreateLight(Entity _id,
break;
case sdf::LightType::SPOT:
{
+ ignerr << "about to create spotlight in scene..." << std::endl;
light = this->dataPtr->scene->CreateSpotLight(name);
+ if (nullptr == light)
+ ignerr << "light is null!" << std::endl;
+ else
+ ignerr << "light is not null" << std::endl;
+ ignerr << std::endl;
rendering::SpotLightPtr spotLight =
std::dynamic_pointer_cast<rendering::SpotLight>(light);
spotLight->SetInnerAngle(_light.SpotInnerAngle()); Then, I run
At this point, I see the following output in the console (the last two sets of output are from the clone calls, and the first two sets of output are from when simulation was started):
Now, press play to start simulation. I see the following output (followed by a crash):
So, it looks like the the server tries to create the light twice, but the second try fails since it's a duplicate (it fails due to the reasoning I explained earlier for having to change the cloned |
Codecov Report
@@ Coverage Diff @@
## main #959 +/- ##
==========================================
- Coverage 63.47% 63.44% -0.03%
==========================================
Files 241 241
Lines 19577 19656 +79
==========================================
+ Hits 12426 12471 +45
- Misses 7151 7185 +34
Continue to review full report at Codecov.
|
This reverts commit fe95598. Signed-off-by: Ashton Larkin <[email protected]>
07feabb
to
d9de439
Compare
I've opened a better fix in #1001 which seems to resolve the race condition issue, so I have reverted the temporary fix in d9de439. |
#1001 has been merged, and this PR has been updated to include these changes in 876724b. So, now, I believe that the only other issue (for lights, at least) is what I described in the second half of #959 (comment) (cloning -> deleting -> re-cloning while simulation is paused), which seems to be a bug that already existed before this PR. |
Signed-off-by: Ashton Larkin <[email protected]>
I found that when cloning actors, the same fix with the light sdf (#959 (comment)) had to be applied. Cloning actors should work now with 2fbb384. I believe that cloning support now exists for simple shapes, meshes, sensors, lights, and actors. This should be ready for another round of review. |
I think the problem is the order in which the rendering thread processes requests from the ECM. This may be what's happening: When the user Clones -> Deletes -> Clones a
At minimum, I think we should catch duplicate lights in SceneManager e.g. using |
I went ahead and made the following changes to catch duplicate lights: diff --git a/src/rendering/SceneManager.cc b/src/rendering/SceneManager.cc
index 283c12f1..b8f891ac 100644
--- a/src/rendering/SceneManager.cc
+++ b/src/rendering/SceneManager.cc
@@ -1101,6 +1101,12 @@ rendering::LightPtr SceneManager::CreateLight(Entity _id,
name = parent->Name() + "::" + name;
rendering::LightPtr light;
+ if (this->dataPtr->scene->HasLightName(name))
+ {
+ ignerr << "A light named [" << name << "] already exists in the scene.\n";
+ return light;
+ }
+ However, I must say that I am still a little confused by the behavior. If I follow the same pattern of creating -> deleting -> creating the light copy while simulation is paused, and then press play, no crash occurs and I see this error message, as expected:
But, after doing this, if I press play and then delete -> create the light copy again, I see the same error message when re-creating the light, which doesn't make sense to me since the light has been deleted and re-created successfully in the GUI. So, my concern is that while things may appear to be okay on the GUI, something still isn't right on the server side. |
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.
I did a first pass. There are some things that concern me about the changes to the ECM as I wrote below. But I think that the addition of Component::Clone
is good, and that's the actual ABI breaking change. So if we can't sort out the ECM until code freeze, I think we can at least get the Component::Clone
function into Fortress and add the ECM stuff later.
Signed-off-by: Ashton Larkin <[email protected]>
Signed-off-by: Ashton Larkin <[email protected]>
Signed-off-by: Louise Poubel <[email protected]>
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.
Great work! The usefulness of the new API and transport service goes beyond the copy/paste GUI functionality.
Signed-off-by: Louise Poubel <[email protected]>
The Windows build failed with an infra issue. I'm going to merge this, hopefully it compiles on Windows 🤞 Otherwise we fix it tomorrow |
Signed-off-by: Ashton Larkin [email protected]
🎉 New feature
Part of #102
Summary
This PR completes "The Great Way", part 1 of #102 (comment). I had to make an ABI-breaking change in
Component.hh
by adding a new virtualClone
method for components, so this is targeting main. If there's a way to achieve component cloning functionality without breaking ABI, let me know!Test it
New tests have been written in this PR (see
src/Component_TEST.cc
, src/EntityComponentManager_TEST.cc
).To test this manually, you can do the following:
position.z
is set to 3 in the service call, the cloned box should appear above the original box:Checklist
codecheck
passed (See contributing)Note to maintainers: Remember to use Squash-Merge