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

Add Costs Analogous to, e.g., MinimumDistanceLowerBoundConstraint #21989

Open
cohnt opened this issue Oct 3, 2024 · 6 comments
Open

Add Costs Analogous to, e.g., MinimumDistanceLowerBoundConstraint #21989

cohnt opened this issue Oct 3, 2024 · 6 comments
Assignees
Labels
component: planning and control Optimization-based planning and control, and search- and sampling-based planning type: feature request

Comments

@cohnt
Copy link
Contributor

cohnt commented Oct 3, 2024

MinimumDistanceLowerBoundConstraint adds a constraint that requires the distance between pairs of geometries be at least a certain quantity, but it also adds an objective cost that penalizes being close to that quantity. It would be useful to me if I could just add the associated cost, but not the constraint. That way, I can bias trajectories or IK problems to avoid obstacles, without adding nonconvex constraints.

cc @shrutigarg914

@jwnimmer-tri
Copy link
Collaborator

... adds an objective cost that penalizes ...

Does it? As far as I can tell, it is only a constraint MinimumDistanceUpperBoundConstraint final : public solvers::Constraint.

@cohnt
Copy link
Contributor Author

cohnt commented Oct 3, 2024

I may be misunderstanding the documentation of what the penalty function is doing -- I assumed that this described how the cost is affected when the constraint is almost active.

But whether or not this constraint also adds a cost, I would like to be able to add a cost based on the minimum distance to an obstacle.

@jwnimmer-tri
Copy link
Collaborator

Sounds good.

I should also broadcast the current work-around suggestion from slack: use the EvaluatorCost wrapper to convert the constraint into a cost.

@xuchenhan-tri xuchenhan-tri added component: mathematical program Formulating and solving mathematical programs; our autodiff and symbolic libraries component: planning and control Optimization-based planning and control, and search- and sampling-based planning and removed component: mathematical program Formulating and solving mathematical programs; our autodiff and symbolic libraries labels Oct 3, 2024
@xuchenhan-tri
Copy link
Contributor

Assigning @hongkai-dai per platform reviewer checklist.

@hongkai-dai
Copy link
Contributor

But whether or not this constraint also adds a cost, I would like to be able to add a cost based on the minimum distance to an obstacle.

@cohnt What is the mathematical formulation of your cost? Let's say it is a function of the minimal distance d. Could you write down explicit form of the cost as a function of d? Is it just cost=-d?

@hongkai-dai
Copy link
Contributor

@cohnt could you try this code snippet?

min_distance_constraint = multibody.MinimumDistanceLowerBoundConstraint(plant, plant_context, bound=0)
# min_distance_constraint.Eval() computes ϕ(d/d_influence − 1)/ϕ(−1), where d is the minimal distance, and ϕ() is the penalty function.
# To maximize the distance, we want to minimize ϕ(d/d_influence − 1)/ϕ(−1), because ϕ() is monotonically decreasing.
prog.AddCost(lambda q: min_distance_constraint.Eval(q), q)

You might need to play with the influence_distance_offset in the constructor of MinimumDistanceLowerBoundConstraint to achieve good performance in the nonlinear solver, at TRI we use a very small value (1E-6) instead of the default 0.01.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: planning and control Optimization-based planning and control, and search- and sampling-based planning type: feature request
Projects
None yet
Development

No branches or pull requests

4 participants