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

Added get/setLCPSolver functions to ConstraintSolver #633

Merged
merged 2 commits into from
Mar 21, 2016

Conversation

mkoval
Copy link
Collaborator

@mkoval mkoval commented Mar 17, 2016

There is currently no way to use anything other than the default LCP solver in ConstraintSolver. This pull request adds functions that parallel the get/setCollisionDetector for the LCPSolver.


/// Get collision detector
collision::CollisionDetector* getCollisionDetector() const;

/// Set LCP solver
void setLCPSolver(std::unique_ptr<LCPSolver> _lcpSolver);
Copy link
Member

Choose a reason for hiding this comment

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

Passing const reference like std::shared_ptr<T> case?

Copy link
Member

Choose a reason for hiding this comment

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

That shouldn't be done for unique_ptr because we want the ownership of the solver to be passed into the ConstraintSolver. Passing by reference wouldn't allow that.

unique_ptr is really weird when it comes to function arguments.

Copy link
Member

Choose a reason for hiding this comment

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

I see, thanks for the clarification. Good to know!

Also, this pull request looks good to merge.

@mkoval
Copy link
Collaborator Author

mkoval commented Mar 17, 2016

I'm not really sure whether this should be managed by smart_ptr or unique_ptr. I changed CollisionDetector from a raw pointer to a unique_ptr in #616 to maintain backwards compatibility and used the same convention here for consistency.

There are no backwards compatibility concerns with LCPSolver, since this was never publicly accessible before this pull request, so I am open to either option. @mxgrey @jslee02 Which do you prefer?

@jslee02 jslee02 added this to the DART 6.0.0 milestone Mar 17, 2016
@mxgrey
Copy link
Member

mxgrey commented Mar 17, 2016

I think unique_ptr makes the most sense since sharing an LCPSolver could entail some serious multi-threading issues depending on the implementation of the LCPSolver.

Since unique_ptrs are kind of weird, I would suggest also having a function like

template <typename T, typename... Args>
void setLCPSolver(Args&&... args)
{
  setLCPSolver(std::unique_ptr<T>(new T(std::forward<Args>(args)...)));
}

For the user's convenience. This way an LCPSolver can be set like:

constraintSolver->setLCPSolver<DantzigLCPSolver>(timestep);

Instead of requiring the user to do confusing things with std::move().

@mkoval
Copy link
Collaborator Author

mkoval commented Mar 17, 2016

I am not a huge fan of that paradigm for two reasons. First, the function signature is inscrutable to people that are unfamiliar with template argument packs. Second, we have to define this type of overload for every function that accepts an std::unique_ptr.

I would prefer to provide a make_unique function in the common or utils namespace. This exists in C++14 and was omitted from C++11 as "partly an oversight".

@mxgrey
Copy link
Member

mxgrey commented Mar 17, 2016

That sounds like a good alternative to me.

@jslee02
Copy link
Member

jslee02 commented Mar 17, 2016

make_unique sounds good. I would prefer to have it in StlHelpers.h.

jslee02 added a commit that referenced this pull request Mar 21, 2016
Added get/setLCPSolver functions to ConstraintSolver
@jslee02 jslee02 merged commit beafa98 into dartsim:master Mar 21, 2016
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