-
Notifications
You must be signed in to change notification settings - Fork 6
Add discrete interpollator and fix tests #58
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| definitions: [./CMakeLists.txt, ./benchmark, ./bindings, ./cmake, ./tests] | ||
| definitions: [./CMakeLists.txt, ./cmake, ./benchmark, ./bindings, ./tests] | ||
| line_length: 80 | ||
| indent: 2 | ||
| warn_about_unknown_commands: false |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,3 +30,4 @@ repos: | |
| rev: 0.19.3 | ||
| hooks: | ||
| - id: gersemi | ||
| args: ["--print-config=verbose"] | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -20,117 +20,166 @@ BOOST_AUTO_TEST_CASE(interpolate) | |||||
| Interpolator interpolator = Interpolator(model); | ||||||
|
|
||||||
| // Test configuration interpolation method | ||||||
| std::vector<Eigen::VectorXd> qs; | ||||||
| for (std::size_t i = 0; i < 4; i++) | ||||||
| { | ||||||
| Eigen::VectorXd q0(model.nq); | ||||||
| Eigen::VectorXd q1(model.nq); | ||||||
| q0 = pinocchio::neutral(model); | ||||||
| std::vector<Eigen::VectorXd> qs; | ||||||
| for (std::size_t i = 0; i < 4; i++) | ||||||
| { | ||||||
| Eigen::VectorXd q0(model.nq); | ||||||
| Eigen::VectorXd q1(model.nq); | ||||||
| q0 = pinocchio::neutral(model); | ||||||
| Eigen::VectorXd dq(model.nv); | ||||||
| dq.setRandom(); | ||||||
| pinocchio::integrate(model, q0, dq, q1); | ||||||
| qs.push_back(q1); | ||||||
| } | ||||||
| Eigen::VectorXd q_interp(model.nq); | ||||||
|
|
||||||
| double delay = 0.02; | ||||||
| interpolator.interpolateConfiguration(delay, timestep, qs, q_interp); | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
|
||||||
| BOOST_CHECK(qs[2].isApprox(q_interp)); | ||||||
|
|
||||||
| delay = 0.5; | ||||||
| interpolator.interpolateConfiguration(delay, timestep, qs, q_interp); | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| BOOST_CHECK(qs.back().isApprox(q_interp)); | ||||||
|
|
||||||
| delay = 0.005; | ||||||
| interpolator.interpolateConfiguration(delay, timestep, qs, q_interp); | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| Eigen::VectorXd q_interp2(model.nq); | ||||||
| Eigen::VectorXd dq(model.nv); | ||||||
| dq.setRandom(); | ||||||
| pinocchio::integrate(model, q0, dq, q1); | ||||||
|
|
||||||
| qs.push_back(q1); | ||||||
| } | ||||||
| double delay = 0.02; | ||||||
|
|
||||||
| Eigen::VectorXd q_interp(model.nq); | ||||||
| interpolator.interpolateConfiguration(delay, timestep, qs, q_interp); | ||||||
|
|
||||||
| BOOST_CHECK(qs[2].isApprox(q_interp)); | ||||||
|
|
||||||
| delay = 0.5; | ||||||
| interpolator.interpolateConfiguration(delay, timestep, qs, q_interp); | ||||||
| BOOST_CHECK(qs.back().isApprox(q_interp)); | ||||||
|
|
||||||
| delay = 0.005; | ||||||
| interpolator.interpolateConfiguration(delay, timestep, qs, q_interp); | ||||||
| Eigen::VectorXd q_interp2(model.nq); | ||||||
| Eigen::VectorXd dq(model.nv); | ||||||
| pinocchio::difference(model, qs[0], qs[1], dq); | ||||||
| pinocchio::integrate(model, qs[0], dq * 0.5, q_interp2); | ||||||
|
|
||||||
| BOOST_CHECK(q_interp2.isApprox(q_interp)); | ||||||
|
|
||||||
| std::vector<Eigen::VectorXd> qs2; | ||||||
| for (std::size_t i = 0; i < 2; i++) | ||||||
| { | ||||||
| qs2.push_back(qs[0]); | ||||||
| pinocchio::difference(model, qs[0], qs[1], dq); | ||||||
| pinocchio::integrate(model, qs[0], dq * 0.5, q_interp2); | ||||||
|
|
||||||
| BOOST_CHECK(q_interp2.isApprox(q_interp)); | ||||||
|
|
||||||
| std::vector<Eigen::VectorXd> qs2; | ||||||
| for (std::size_t i = 0; i < 2; i++) | ||||||
| { | ||||||
| qs2.push_back(qs[0]); | ||||||
| } | ||||||
| interpolator.interpolateConfiguration(delay, timestep, qs2, q_interp); | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| BOOST_CHECK(qs2[0].isApprox(q_interp)); | ||||||
| } | ||||||
| interpolator.interpolateConfiguration(delay, timestep, qs2, q_interp); | ||||||
| BOOST_CHECK(qs2[0].isApprox(q_interp)); | ||||||
|
|
||||||
| // Test state interpolation method | ||||||
| std::vector<Eigen::VectorXd> xs; | ||||||
| for (std::size_t i = 0; i < 4; i++) | ||||||
| { | ||||||
| Eigen::VectorXd x0(model.nq + model.nv); | ||||||
| x0.head(model.nq) = pinocchio::neutral(model); | ||||||
| std::vector<Eigen::VectorXd> xs; | ||||||
| for (std::size_t i = 0; i < 4; i++) | ||||||
| { | ||||||
| Eigen::VectorXd x0(model.nq + model.nv); | ||||||
| x0.head(model.nq) = pinocchio::neutral(model); | ||||||
| Eigen::VectorXd dq(model.nv); | ||||||
| dq.setRandom(); | ||||||
| pinocchio::integrate(model, x0.head(model.nq), dq, x0.head(model.nq)); | ||||||
| x0.tail(model.nv).setRandom(); | ||||||
| xs.push_back(x0); | ||||||
| } | ||||||
| Eigen::VectorXd x_interp(model.nq + model.nv); | ||||||
| Eigen::VectorXd dq(model.nv); | ||||||
| dq.setRandom(); | ||||||
| pinocchio::integrate(model, x0.head(model.nq), dq, x0.head(model.nq)); | ||||||
| x0.tail(model.nv).setRandom(); | ||||||
|
|
||||||
| xs.push_back(x0); | ||||||
| double delay = 0.02; | ||||||
| interpolator.interpolateState(delay, timestep, xs, x_interp); | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| BOOST_CHECK(xs[2].isApprox(x_interp)); | ||||||
|
|
||||||
| delay = 0.5; | ||||||
| interpolator.interpolateState(delay, timestep, xs, x_interp); | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| BOOST_CHECK(xs.back().isApprox(x_interp)); | ||||||
|
|
||||||
| delay = 0.005; | ||||||
| interpolator.interpolateState(delay, timestep, xs, x_interp); | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| Eigen::VectorXd x_interp2(model.nq + model.nv); | ||||||
| pinocchio::difference(model, xs[0].head(model.nq), xs[1].head(model.nq), dq); | ||||||
| pinocchio::integrate(model, xs[0].head(model.nq), dq * 0.5, x_interp2.head(model.nq)); | ||||||
| x_interp2.tail(model.nv) = (xs[0].tail(model.nv) + xs[1].tail(model.nv)) * 0.5; | ||||||
| BOOST_CHECK(x_interp2.isApprox(x_interp)); | ||||||
|
|
||||||
| std::vector<Eigen::VectorXd> xs2; | ||||||
| for (std::size_t i = 0; i < 2; i++) | ||||||
| { | ||||||
| xs2.push_back(xs[0]); | ||||||
| } | ||||||
| interpolator.interpolateState(delay, timestep, xs2, x_interp); | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| BOOST_CHECK(xs2[0].isApprox(x_interp)); | ||||||
| } | ||||||
| delay = 0.02; | ||||||
|
|
||||||
| Eigen::VectorXd x_interp(model.nq + model.nv); | ||||||
| interpolator.interpolateState(delay, timestep, xs, x_interp); | ||||||
| BOOST_CHECK(xs[2].isApprox(x_interp)); | ||||||
|
|
||||||
| delay = 0.5; | ||||||
| interpolator.interpolateState(delay, timestep, xs, x_interp); | ||||||
| BOOST_CHECK(xs.back().isApprox(x_interp)); | ||||||
|
|
||||||
| delay = 0.005; | ||||||
| interpolator.interpolateState(delay, timestep, xs, x_interp); | ||||||
| Eigen::VectorXd x_interp2(model.nq + model.nv); | ||||||
| pinocchio::difference(model, xs[0].head(model.nq), xs[1].head(model.nq), dq); | ||||||
| pinocchio::integrate(model, xs[0].head(model.nq), dq * 0.5, x_interp2.head(model.nq)); | ||||||
| x_interp2.tail(model.nv) = (xs[0].tail(model.nv) + xs[1].tail(model.nv)) * 0.5; | ||||||
| BOOST_CHECK(x_interp2.isApprox(x_interp)); | ||||||
|
|
||||||
| std::vector<Eigen::VectorXd> xs2; | ||||||
| for (std::size_t i = 0; i < 2; i++) | ||||||
|
|
||||||
| // Test linear interpolation method | ||||||
| { | ||||||
| xs2.push_back(xs[0]); | ||||||
| std::vector<Eigen::VectorXd> vs; | ||||||
| for (std::size_t i = 0; i < 4; i++) | ||||||
| { | ||||||
| Eigen::VectorXd v0(model.nv); | ||||||
| v0.setRandom(); | ||||||
| vs.push_back(v0); | ||||||
| } | ||||||
| Eigen::VectorXd v_interp(model.nv); | ||||||
|
|
||||||
| double delay = 0.02; | ||||||
| interpolator.interpolateLinear(delay, timestep, vs, v_interp); | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| BOOST_CHECK(vs[2].isApprox(v_interp)); | ||||||
|
|
||||||
| delay = 0.5; | ||||||
| interpolator.interpolateLinear(delay, timestep, vs, v_interp); | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| BOOST_CHECK(vs.back().isApprox(v_interp)); | ||||||
|
|
||||||
| delay = 0.005; | ||||||
| interpolator.interpolateLinear(delay, timestep, vs, v_interp); | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| Eigen::VectorXd v_interp2(model.nv); | ||||||
| v_interp2 = (vs[0] + vs[1]) * 0.5; | ||||||
|
|
||||||
| BOOST_CHECK(v_interp2.isApprox(v_interp)); | ||||||
|
|
||||||
| std::vector<Eigen::VectorXd> vs2; | ||||||
| for (std::size_t i = 0; i < 2; i++) | ||||||
| { | ||||||
| vs2.push_back(vs[0]); | ||||||
| } | ||||||
| interpolator.interpolateLinear(delay, timestep, vs2, v_interp); | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| BOOST_CHECK(vs2[0].isApprox(v_interp)); | ||||||
| } | ||||||
| interpolator.interpolateState(delay, timestep, xs2, x_interp); | ||||||
| BOOST_CHECK(xs2[0].isApprox(x_interp)); | ||||||
|
|
||||||
| // Test linear interpolation method | ||||||
| std::vector<Eigen::VectorXd> vs; | ||||||
| for (std::size_t i = 0; i < 4; i++) | ||||||
| // Test contacts interpolation method | ||||||
| { | ||||||
| Eigen::VectorXd v0(model.nv); | ||||||
| v0.setRandom(); | ||||||
| const size_t n_contacts = 4; | ||||||
|
|
||||||
| vs.push_back(v0); | ||||||
| } | ||||||
| delay = 0.02; | ||||||
| Eigen::VectorXd v_interp(model.nv); | ||||||
| interpolator.interpolateLinear(delay, timestep, vs, v_interp); | ||||||
| BOOST_CHECK(vs[2].isApprox(v_interp)); | ||||||
| std::vector<std::vector<bool>> cs; | ||||||
| for (std::size_t i = 0; i < n_contacts; i++) | ||||||
| { | ||||||
| std::vector<bool> c(n_contacts, false); | ||||||
| c[i] = true; | ||||||
| cs.push_back(c); | ||||||
| } | ||||||
| std::vector<bool> c_interp(n_contacts); | ||||||
|
|
||||||
| delay = 0.5; | ||||||
| interpolator.interpolateLinear(delay, timestep, vs, v_interp); | ||||||
| BOOST_CHECK(vs.back().isApprox(v_interp)); | ||||||
| // First element | ||||||
| interpolator.interpolateContacts(-0.001, 0.1, cs, c_interp); | ||||||
| BOOST_CHECK(std::equal(c_interp.begin(), c_interp.end(), cs[0].begin())); | ||||||
|
|
||||||
| delay = 0.005; | ||||||
| interpolator.interpolateLinear(delay, timestep, vs, v_interp); | ||||||
| Eigen::VectorXd v_interp2(model.nv); | ||||||
| v_interp2 = (vs[0] + vs[1]) * 0.5; | ||||||
| interpolator.interpolateContacts(0, 0.1, cs, c_interp); | ||||||
| BOOST_CHECK(std::equal(c_interp.begin(), c_interp.end(), cs[0].begin())); | ||||||
|
|
||||||
| BOOST_CHECK(v_interp2.isApprox(v_interp)); | ||||||
| interpolator.interpolateContacts(0.001, 0.1, cs, c_interp); | ||||||
| BOOST_CHECK(std::equal(c_interp.begin(), c_interp.end(), cs[0].begin())); | ||||||
|
|
||||||
| std::vector<Eigen::VectorXd> vs2; | ||||||
| for (std::size_t i = 0; i < 2; i++) | ||||||
| { | ||||||
| vs2.push_back(vs[0]); | ||||||
| // Middle element | ||||||
| interpolator.interpolateContacts(0.1, 0.1, cs, c_interp); | ||||||
| BOOST_CHECK(std::equal(c_interp.begin(), c_interp.end(), cs[1].begin())); | ||||||
|
|
||||||
| interpolator.interpolateContacts(0.15, 0.1, cs, c_interp); | ||||||
| BOOST_CHECK(std::equal(c_interp.begin(), c_interp.end(), cs[1].begin())); | ||||||
|
|
||||||
| interpolator.interpolateContacts(0.2, 0.1, cs, c_interp); | ||||||
| BOOST_CHECK(std::equal(c_interp.begin(), c_interp.end(), cs[2].begin())); | ||||||
|
|
||||||
| // Last element | ||||||
| interpolator.interpolateContacts(0.39, 0.1, cs, c_interp); | ||||||
| BOOST_CHECK(std::equal(c_interp.begin(), c_interp.end(), cs[3].begin())); | ||||||
|
|
||||||
| interpolator.interpolateContacts(0.4, 0.1, cs, c_interp); | ||||||
| BOOST_CHECK(std::equal(c_interp.begin(), c_interp.end(), cs[3].begin())); | ||||||
|
|
||||||
| interpolator.interpolateContacts(0.5, 0.1, cs, c_interp); | ||||||
| BOOST_CHECK(std::equal(c_interp.begin(), c_interp.end(), cs[3].begin())); | ||||||
| } | ||||||
| interpolator.interpolateLinear(delay, timestep, vs2, v_interp); | ||||||
| BOOST_CHECK(vs2[0].isApprox(v_interp)); | ||||||
| } | ||||||
|
|
||||||
| BOOST_AUTO_TEST_SUITE_END() | ||||||
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 would suggest something like this if you want this templated:
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.
So apparently the problems remains
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.
Can you show the calling code and the current implementation?
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.
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.
What about the
interpolateConfigurationfunction itself?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 tried with and without the type template
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.
Strange. You could remove
MatTypeas an argument and writeEigen::Matrix<...>everywhere in its place. Perhaps this messed up the function template parameter deduction...