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

Constraint functions should be std::function instead of function pointers #27

Closed
schulz0r opened this issue Sep 9, 2020 · 6 comments
Closed

Comments

@schulz0r
Copy link
Collaborator

schulz0r commented Sep 9, 2020

Every example in this project has predefined constraint functions (e.g. events) where values do not change during runtime. Since I have a lot of trajectories to plan which can have arbitrary start and endpoints, I need to reset the functions every time I want to plan a new trajectory. Sadly, the problem definition struct uses C-style function pointers, which do not allow for that.

I would like to see std::function to replace the C-style pointers, so it is possible to use lambdas which capture variables (e.g. the start and stop state) from outside the function. I think this change would not even require any changes to the examples because std::functions are pretty backward compatible.
To illustrate what I want to do, see following code. The first block depicts what is possible right now:

Eigen::Matrix<adouble, 6, 1> myFinalState; // fill this vector appropriately
Prob problem;
// you can assign lambdas to function pointers btw
problem.events = [](adouble* some_args) {
    // cannot see myFinalState
    // thus cannot set it
}

With std::function, following will be possible:

Eigen::Matrix<adouble, 6, 1> myFinalState; // fill this vector appropriately
Prob problem;
// std::function allows to capture myFinalState
problem.events = [&myFinalState](adouble* some_args) {
    Eigen::Map<Eigen::Matrix<adouble, 6, 1>> eventVector(e, 6);    // wrap pointer into eigen vector
    eventVector << myFinalState;    // set final state values here
}
@vmbecerra
Copy link
Contributor

vmbecerra commented Sep 9, 2020 via email

@schulz0r
Copy link
Collaborator Author

I received your advise to simply set the event constraint bounds:

problem.phases(1).bounds.lower.events << x0, xf;
problem.phases(1).bounds.upper.events << x0, xf;

The event function looks like the one from the Alpine Rider example.

@schulz0r
Copy link
Collaborator Author

schulz0r commented Sep 21, 2020 via email

@vmbecerra
Copy link
Contributor

vmbecerra commented Sep 21, 2020 via email

@schulz0r
Copy link
Collaborator Author

schulz0r commented Sep 21, 2020 via email

@vmbecerra
Copy link
Contributor

vmbecerra commented Sep 22, 2020 via email

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

No branches or pull requests

2 participants