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 test for PlanningContextManager in ompl interface #2248

Merged
merged 11 commits into from
Oct 18, 2020

Conversation

JeroenDM
Copy link
Contributor

Description

(This pull request could use some extra work, but early feedback would be really valuable.)

This test goes through the main steps in solving a planning problem with the interface;

  1. Create a PlanningContextManager.
  2. Call it's getPlanningContext with a specific request to get a ModelBasedPlanningContext.
  3. Call the solve method on the planning context.

The main intent is to check if the ModelBasedPlanningContext has the correct type of ModelBasedStateSpace assigned for planning. (For a detailed explanation of this process, see here.)
Calling the solve method is just the cherry on top of the cake.

The load_test_robot_class.h is exactly the same as in #2247, so I assume that change will not be part of this pull request once rebased.

TODO / issues

Loading a (dummy) IK solver for a planning group
The selection of the state space depends on the availability of an IK solver. I found an example of how to load a solver in a test class in test_constrained_sampler.cpp, which basically adds a complete implementation of an IK solver (KinematicsBase class) to the test directory.

rostest dependency
Ideally, this test could be completely ROS independent if I had a way to create a "dummy" ros::NodeHandle without actually starting a roscore. The only method that needs this ROS handle is loadConstraintApproximations, which I'm not testing here.

Why are these useful?

I'm currently using this test in the context of #2092, where they are extremely helpful.

Checklist

  • Required by CI: Code is auto formatted using clang-format
  • Extend the tutorials / documentation reference
  • Document API changes relevant to the user in the MIGRATION.md notes
  • Create tests, which fail without this PR reference
  • Include a screenshot if changing a GUI
  • While waiting for someone to review your request, please help review another open pull request to support the maintainers

@JeroenDM JeroenDM requested a review from mamoll as a code owner August 11, 2020 14:15
@JeroenDM
Copy link
Contributor Author

@felixvd @ommmid @mamoll Maybe something to discuss in the meeting?

@JeroenDM
Copy link
Contributor Author

Travis fails because I did not add rostest and eigen_conversions to the test dependencies in the package.xml yet.

Copy link
Contributor

@mamoll mamoll left a comment

Choose a reason for hiding this comment

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

Looks good to me. Just make sure copyright is assigned to KU Leuven, not Willow Garage.

moveit_planners/ompl/ompl_interface/test/load_test_robot.h Outdated Show resolved Hide resolved
@JeroenDM
Copy link
Contributor Author

JeroenDM commented Sep 8, 2020

I will fix the package.xml file tomorrow and remove the WIP tag.

@codecov
Copy link

codecov bot commented Sep 10, 2020

Codecov Report

Merging #2248 into master will decrease coverage by 1.52%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2248      +/-   ##
==========================================
- Coverage   57.94%   56.42%   -1.51%     
==========================================
  Files         327      287      -40     
  Lines       25645    24451    -1194     
==========================================
- Hits        14858    13795    -1063     
+ Misses      10787    10656     -131     
Impacted Files Coverage Δ
...include/moveit/robot_model/prismatic_joint_model.h 0.00% <0.00%> (-50.00%) ⬇️
...sh_filter/include/moveit/mesh_filter/mesh_filter.h 66.67% <0.00%> (-33.33%) ⬇️
...clude/moveit/occupancy_map_monitor/occupancy_map.h 16.67% <0.00%> (-20.83%) ⬇️
..._capabilities/clear_octomap_service_capability.cpp 30.00% <0.00%> (-20.00%) ⬇️
...de/moveit/constraint_samplers/constraint_sampler.h 20.00% <0.00%> (-17.50%) ⬇️
..._core/collision_detection/src/collision_common.cpp 33.34% <0.00%> (-16.66%) ⬇️
...e_controller_manager/src/moveit_fake_controllers.h 33.34% <0.00%> (-16.66%) ⬇️
moveit_core/exceptions/src/exceptions.cpp 0.00% <0.00%> (-16.66%) ⬇️
...ccupancy_map_monitor/src/occupancy_map_updater.cpp 58.83% <0.00%> (-13.90%) ⬇️
...tection/include/moveit/collision_detection/world.h 75.00% <0.00%> (-13.88%) ⬇️
... and 289 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8771af6...da55c87. Read the comment docs.

@JeroenDM
Copy link
Contributor Author

Woohoo, 0.06% coverage increase!

I don't think moveit_planners_ompl is low hanging fruit in terms of increasing code coverage. Most of it is tested by moveit_ros_planning_interface tests. But the tests added here are still really useful when working on improving the ompl interface and as documentation on how the internals work.

@JeroenDM JeroenDM changed the title WIP: add test for PlanningContextManager in ompl interface Add test for PlanningContextManager in ompl interface Sep 10, 2020
Copy link
Contributor

@mamoll mamoll left a comment

Choose a reason for hiding this comment

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

Looks good to me!

@mamoll mamoll requested a review from rhaschke October 14, 2020 15:30
Copy link
Contributor

@rhaschke rhaschke left a comment

Choose a reason for hiding this comment

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

I'm not sure the tests are very specific. Other than some nitpicks, I'm fine with it.

moveit_planners/ompl/ompl_interface/test/load_test_robot.h Outdated Show resolved Hide resolved
Comment on lines 145 to 148
// TODO(jeroendm) As the joint_model_group_ has not IK solver initialized, we still get a joint model state space
// here, it would be nice if we could load an IK solver for the robot to test the PoseModelStateSpace.
auto ss = dynamic_cast<ompl_interface::JointModelStateSpace*>(pc->getOMPLStateSpace().get());
EXPECT_NE(ss, nullptr);
Copy link
Contributor

Choose a reason for hiding this comment

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

If I'm not mistaken, you validate that you don't get a JointModelStateSpace here. This contradicts the comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I updated the comment to:

// As the joint_model_group_ has no IK solver initialized, we expect a joint model state space

I tried this summer, but I did not manage to figure out how to manually load an IK solver for the joint model group.

EXPECT_TRUE(success);
}

void testPathConstraints(const std::vector<double>& start, const std::vector<double>& goal)
Copy link
Contributor

Choose a reason for hiding this comment

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

The test here doesn't differ from testSimpleRequest() except that path constraints are created. Particularly, the test doesn't verify that the constraints are correctly created and used.

Copy link
Contributor Author

@JeroenDM JeroenDM Oct 18, 2020

Choose a reason for hiding this comment

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

I added tests to see if the path constraints are added to the planning context and properly used by the planner. (The specific start and goal state used maybe a bit too trivial, but I'll leave this as future work if that's ok. Otherwise, I fear I might never finish this PR and continue working on the constrained planning PR.)

    // Are the path constraints created in the planning context?
    auto path_constraints = pc->getPathConstraints();
    EXPECT_FALSE(path_constraints->empty());
    EXPECT_EQ(path_constraints->getOrientationConstraints().size(), 1);
    EXPECT_TRUE(path_constraints->getPositionConstraints().empty());
    EXPECT_TRUE(path_constraints->getJointConstraints().empty());
    EXPECT_TRUE(path_constraints->getVisibilityConstraints().empty());

    // Check if all the states in the solution satisfy the path constraints.
    // A detailed response returns 3 solutions: the ompl solution, the simplified solution and the interpolated
    // solution. We test all of them here.
    for (const robot_trajectory::RobotTrajectoryPtr& trajectory : res.trajectory_)
    {
      for (std::size_t pt_index = { 0 }; pt_index < trajectory->getWayPointCount(); ++pt_index)
      {
        EXPECT_TRUE(path_constraints->decide(trajectory->getWayPoint(pt_index)).satisfied);
      }
    }

Comment on lines +2 to +4
<launch>
<test pkg="moveit_planners_ompl" type="test_planning_context_manager" test-name="test_planning_context_manager" />
</launch>
Copy link
Contributor

Choose a reason for hiding this comment

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

There is no ROS environment loaded here. Do you need a rostest with a launch file after all?
Can the test run as a plain gtest as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I need a node handle to call getPlanningRequest, but the node handle is never used. As mentioned in the pr description:

Ideally, this test could be completely ROS independent if I had a way to create a "dummy" ros::NodeHandle without actually starting a roscore. The only method that needs this ROS handle is loadConstraintApproximations, which I'm not testing here.

I wish I could come up with a better solution. It is unfortunate that a ROS dependency got introduced in a non-ROS specific part of MoveIt. Technically, the code for the constraint approximations could be refactored to avoid this ros node handle dependency, but that would introduce breaking API changes for users, I think.

@JeroenDM
Copy link
Contributor Author

@rhaschke thank you for the feedback!

I'm not sure the tests are very specific.

I think they become really useful if the new constrained-state-space gets merged, where an extra test is added to test the configurations options that the user can specify.
I wrote these tests originally more as documentation for future me when working on the new state space.

@JeroenDM
Copy link
Contributor Author

Note that I'll have to rebase this if #2247 gets merged first, because of the load_robot_model.h that is used by both tests.

@rhaschke rhaschke merged commit 144adb7 into moveit:master Oct 18, 2020
@tylerjw tylerjw mentioned this pull request Oct 23, 2020
57 tasks
@JeroenDM JeroenDM deleted the add-planning-context-test branch January 9, 2021 09:07
@tylerjw tylerjw mentioned this pull request Apr 9, 2021
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.

None yet

3 participants