Skip to content
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

[WIP] Refactor Bullet plugin implementation #286

Closed
wants to merge 1 commit into from

Conversation

joxoby
Copy link

@joxoby joxoby commented Aug 23, 2021

Refactor

Summary

Refactors Bullet plugin implementation to use a hierarchical memory ownership model. See Base.hh for detailed explanation. This representation greatly simplifies the entity management implementation.

EDIT: I'm currently looking into switching to btMultiBody so that Bullet uses reduced coordinates instead.

CC: @Blast545 @Lobotuerk

@joxoby joxoby requested a review from mxgrey as a code owner August 23, 2021 23:52
@github-actions github-actions bot added the 🏢 edifice Ignition Edifice label Aug 23, 2021
@joxoby joxoby force-pushed the bullet-refactor branch 3 times, most recently from 9766391 to 9f182cf Compare August 24, 2021 00:02
public: inline Identity AddWorld(std::unique_ptr<World> &&_world) {
auto id = this->GetNextEntity();
this->world = std::move(_world);
auto identity = this->GenerateIdentity(id, nullptr);
Copy link
Author

@joxoby joxoby Aug 24, 2021

Choose a reason for hiding this comment

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

Note how I'm using nullptr for the generated Identity. The function GenerateIdentity only takes a shared_ptr which means that it will also manage the lifetime of the related object. Since we don't want this, we could potentially add a version of GenerateIdentity that takes a raw pointer instead?

@chapulina chapulina added the Bullet Bullet engine label Aug 26, 2021
@joxoby joxoby force-pushed the bullet-refactor branch 5 times, most recently from eb8f64c to b57b5dd Compare August 26, 2021 18:48
@joxoby joxoby changed the title Refactor Bullet plugin implementation [WIP] Refactor Bullet plugin implementation Aug 27, 2021
const std::size_t child = this->FindOrConstructLink(
modelIdentity, _sdfModel, sdfJoint->ChildLinkName());
// Construct all the model's links
for (std::size_t i = 0; i < _sdfModel.LinkCount(); ++i) {
Copy link
Author

@joxoby joxoby Aug 27, 2021

Choose a reason for hiding this comment

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

For some reason, this loop never happens since _sdfModel.LinkCount() always gives 0. All the links seem to be constructed after all the models. ConstructSdfLink seems to be called through another path. This seems to be a problem: since I can't know a priori the number of links that a model has, I can't create an instance of btMultiBody...

Copy link

@Lobotuerk Lobotuerk Aug 27, 2021

Choose a reason for hiding this comment

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

That's one of the reasons we did not use btMultiBody. One solution we thought about at some point when trying to use it, was create some sort of nullptr, and "recreate" the multibody once you have enough information. Also, that would make you "recreate" the multibody any time something changes

Copy link
Author

Choose a reason for hiding this comment

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

That could work. The problem is programmatically defining the "enough information" trigger.

Copy link

@Lobotuerk Lobotuerk Aug 27, 2021

Choose a reason for hiding this comment

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

AFAIK, once you reach joint creation, you have already received all links (That only applies if you are not going to have detachable joints at some point). Edit* Even though is true, I meant on Collision creation, that's the direct next step after link creation.
Also

ConstructSdfLink seems to be called through another path.

Ign seems to consume the different Construct functions you make available. Probably @azeey can correct me if I'm wrong.

Copy link
Author

Choose a reason for hiding this comment

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

Ign seems to consume the different Construct functions you make available. Probably @azeey can correct me if I'm wrong.

Yes, it looks that it's called here: https://github.com/ignitionrobotics/ign-gazebo/blob/26832764749291b6ea22b525262136ecbb63fbb9/src/systems/physics/Physics.cc#L821-L820

AFAIK, once you reach joint creation, you have already received all links

We would basically create the btMultiBody instance inside ConstructSdfJoint. But, what if there are no joints?

(That only applies if you are not going to have detachable joints at some point).

Detachable Joints could be implemented separately using btFixedconstraints or something, WDYT?

Copy link
Author

Choose a reason for hiding this comment

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

I'm not sure if detached joints are considered part of the same model in IGN.

You would normally use detached joints to connect links across different models.

Choose a reason for hiding this comment

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

I mean, if you have a model, and you detach a link, is that detached joint still considered part of that model in the IGN's structure, or is a new model created with that link inside? I'm just thinking about the btMultibody structure, and if the latter one is correct, you would need to create 2 new ones on detaching.

Copy link
Author

Choose a reason for hiding this comment

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

In the IGN structure, I don't think that detachable joints are part of any model. They just connect two different models together. When you detach a joint, you're detaching different models, not a link from a model.

Choose a reason for hiding this comment

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

Then btFixedconstraints should make the trick

Copy link
Author

@joxoby joxoby Aug 27, 2021

Choose a reason for hiding this comment

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

Sorry, I missed one step. Don't create it on joint creation, create it on Collision creation.

The problem here is that we probably want to create btRigidBody for models without joints and btMultiBody for models with joints. This information is not yet available during Collision creation.

@traversaro
Copy link
Contributor

EDIT: I'm currently looking into switching to btMultiBody so that Bullet uses reduced coordinates instead.

Just FYI, a related comment on this: #44 (comment) .

@joxoby joxoby closed this Oct 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bullet Bullet engine 🏢 edifice Ignition Edifice
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants