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 hybrid planning #813

Merged
merged 12 commits into from
Dec 8, 2021
Merged

Add hybrid planning #813

merged 12 commits into from
Dec 8, 2021

Conversation

AndyZe
Copy link
Member

@AndyZe AndyZe commented Nov 18, 2021

This continues from #488. It addresses most of the comments there.

The big comment that's not addressed yet relates to the timer that is used in launching hybrid_planning_manager/hybrid_planning_manager.cpp. I made an issue for that. #811 and #763 tried to tackle that issue but they both crash. So I think it's something we can work on improving later.

I'll work on cleaning up the corresponding tutorial PR and adding some tests for this.

Suggestions on how to clean up the commit history are welcome. I'd be fine with squashing into five commits or so.

This work is sponsored by RE2 Robotics.

@AndyZe AndyZe changed the title Feature/hybrid planning Address hybrid planning reviews Nov 18, 2021
@codecov
Copy link

codecov bot commented Nov 18, 2021

Codecov Report

Merging #813 (5cd1a5f) into main (482950a) will decrease coverage by 3.07%.
The diff coverage is 27.86%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #813      +/-   ##
==========================================
- Coverage   60.86%   57.79%   -3.06%     
==========================================
  Files         273      305      +32     
  Lines       23880    26060    +2180     
==========================================
+ Hits        14533    15060     +527     
- Misses       9347    11000    +1653     
Impacted Files Coverage Δ
...rid_planning_manager/moveit_error_code_interface.h 0.00% <0.00%> (ø)
...ogic_plugins/src/replan_invalidated_trajectory.cpp 0.00% <0.00%> (ø)
.../hybrid_planning_manager/planner_logic_interface.h 3.85% <3.85%> (ø)
...lanner_logic_plugins/src/single_plan_execution.cpp 9.38% <9.38%> (ø)
...nstraint_solver_plugins/src/forward_trajectory.cpp 14.04% <14.04%> (ø)
..._manager_component/src/hybrid_planning_manager.cpp 20.84% <20.84%> (ø)
...trajectory_operator_plugins/src/simple_sampler.cpp 23.34% <23.34%> (ø)
..._planner_component/src/local_planner_component.cpp 33.11% <33.11%> (ø)
...l_planner_plugins/src/moveit_planning_pipeline.cpp 35.56% <35.56%> (ø)
...planner_component/src/global_planner_component.cpp 38.64% <38.64%> (ø)
... and 36 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 482950a...5cd1a5f. Read the comment docs.

@AndyZe AndyZe changed the title Address hybrid planning reviews Add hybrid planning Nov 19, 2021
@AndyZe AndyZe force-pushed the feature/hybrid_planning branch 4 times, most recently from 3454e6a to b753cf8 Compare November 19, 2021 19:48
@AndyZe AndyZe force-pushed the feature/hybrid_planning branch 5 times, most recently from 920b953 to 3e7ba55 Compare November 22, 2021 15:56
@AndyZe
Copy link
Member Author

AndyZe commented Nov 23, 2021

@sjahr I would appreciate it if you take a look at c9e1691. The logic for the action result isn't working here because reaction_result always reflects a SUCCESS.

I'm not really sure what it's intended to do. These are the lines:

  // Add result callback to print the result
  local_goal_options.result_callback =
      [this](const rclcpp_action::ClientGoalHandle<moveit_msgs::action::LocalPlanner>::WrappedResult& action_result) {
        RCLCPP_ERROR(LOGGER, "local action callback");
        RCLCPP_ERROR_STREAM(LOGGER, (bool)(action_result.code == rclcpp_action::ResultCode::SUCCEEDED));

        // Note: action_result is not used beyond this point

        // Reaction result from the latest event
        ReactionResult reaction_result =
            planner_logic_instance_->react(HybridPlanningEvent::LOCAL_PLANNING_ACTION_FINISHED);
        // TODO: This always thinks the action was successful!
        if (reaction_result.error_code.val != moveit_msgs::msg::MoveItErrorCodes::SUCCESS)
        {
          auto result = std::make_shared<moveit_msgs::action::HybridPlanner::Result>();
          result->error_code.val = reaction_result.error_code.val;
          result->error_message = reaction_result.error_message;
          hybrid_planning_goal_handle_->abort(result);
          RCLCPP_ERROR(LOGGER, "Hybrid Planning Manager failed to react to  '%s'", reaction_result.event.c_str());
        }
      };

If you run it a few times, I think you'll easily be able to see the issue. ros2 launch moveit_hybrid_planning hybrid_planning_demo.launch.py

@AndyZe AndyZe force-pushed the feature/hybrid_planning branch 3 times, most recently from e2a7315 to f8b0cbd Compare November 23, 2021 22:09
@sjahr
Copy link
Contributor

sjahr commented Nov 24, 2021

@sjahr I believe that f8b0cbd fixed my comment above about reaction_result always reflecting SUCCESS. Take a look if you have time.
@AndyZe I think this is not the correct way to fix it, sorry. I've answered in your review comment above.

@AndyZe AndyZe force-pushed the feature/hybrid_planning branch 2 times, most recently from e426ec2 to a4d3b5d Compare November 24, 2021 23:00
@AndyZe AndyZe force-pushed the feature/hybrid_planning branch 2 times, most recently from 7292535 to edb2bae Compare November 29, 2021 14:36
Copy link
Member

@tylerjw tylerjw left a comment

Choose a reason for hiding this comment

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

I left some comments. I'll create a PR to try to fix those things.

@sjahr
Copy link
Contributor

sjahr commented Nov 30, 2021

I left some comments. I'll create a PR to try to fix those things.

@tylerjw Thanks for reviewing this again! I am aware of this issue but I was not able to fix it yet. I've opened a WIP PR with my progress so far but I encountered an issue I have not fixed yet. If you have the time to take a look at this you can use my PR as a start and I'd be happy to hear your feedback on this approach or to review your own solution.

@tylerjw
Copy link
Member

tylerjw commented Nov 30, 2021

I tried fixing this in a PR to andy's branch and failed to fix it easily. I think it is important to acknowledge that one of the wonderful parts about software is that we can change it in the future and that nice software often takes many iterations to be really nice. In this case, I don't have the time to try to fix the issues I raised so I think we should just merge this as it is for now. Eventually, when one of us has time to work on this we should rewrite how the initialization of plugins work and accept that the plugin interface will probably have to change as a result.

@sjahr
Copy link
Contributor

sjahr commented Dec 3, 2021

There are still some build warnings (check CI). They are not enforced yet, but it would be nice if they were fixed. Also, I noticed that the include folders are not installed locally. This is only apparent when depending on hybrid planning from another package. Here is an error log when compiling the hybrid_planning_demo from the UR10e welding repo. Since this worked with an older version of hybrid planning, there must be some newer changes that broke this.

I had the same issue and I've fixed it with this PR

@sjahr
Copy link
Contributor

sjahr commented Dec 3, 2021

I re-read through all of this again. I think I'm ok with it for now. Eventually I want to figure out the initialization and lifetime of these plugins so there isn't a circular relationship.

Thanks! I think the key to solving this is to have a better solution for how hybrid_planning_manager and its logic plugin can share the same ros2 communication interfaces. When you have the time to work on it, I'd be happy to discuss the issue with you as I am struggling to find a good solution too

@AndyZe
Copy link
Member Author

AndyZe commented Dec 3, 2021

I am now getting a parameter loading error. This started to happen after I rebased. I think it is related to the loading of global_planner.yaml by moveit_planning_pipeline.cpp:

[component_container_mt-1] [FATAL] [1638568924.298387221] [moveit_ros.trajectory_execution_manager]: Exception while loading controller manager '<undefined>': According to the loaded plugin descriptions the class <undefined> with base class type moveit_controller_manager::MoveItControllerManager does not exist. Declared types are  moveit_ros_control_interface/MoveItControllerManager moveit_ros_control_interface/MoveItMultiControllerManager moveit_simple_controller_manager/MoveItSimpleControllerManager
[component_container_mt-1] [ERROR] [1638568924.298412408] [moveit_ros.trajectory_execution_manager]: Failed to reload controllers: `controller_manager_` does not exist.

A parameter dump for the global planner shows this:

/global_planner:
  ros__parameters:
    global_planner_name: moveit_hybrid_planning/MoveItPlanningPipeline
    hand:
      kinematics_solver: null
    moveit_controller_manager: <undefined>
    ...

@AndyZe AndyZe force-pushed the feature/hybrid_planning branch 2 times, most recently from 9227f93 to 418fe87 Compare December 5, 2021 05:39
@AndyZe
Copy link
Member Author

AndyZe commented Dec 5, 2021

Re. parameter loading:

moveit_controller_manager wasn't loaded because of a typo.

More importantly, all of these ompl parameters aren't declared or retrieved at all. No idea how this ever worked. I found this by comparing against the moveit_cpp demo. Maybe we can re-use the parameter loading code from moveit_cpp.

    ompl:
      panda_arm:
        planner_configs:
        - SBLkConfigDefault
        - ESTkConfigDefault
        - ...

@sjahr
Copy link
Contributor

sjahr commented Dec 6, 2021

Re. parameter loading:

moveit_controller_manager wasn't loaded because of a typo.

More importantly, all of these ompl parameters aren't declared or retrieved at all. No idea how this ever worked. I found this by comparing against the moveit_cpp demo. Maybe we can re-use the parameter loading code from moveit_cpp.

    ompl:
      panda_arm:
        planner_configs:
        - SBLkConfigDefault
        - ESTkConfigDefault
        - ...

There is a default_planner_config within the ompl interface class which is used if nothing else is declared. For the simple demos, this was sufficient but you are right, that we need to add the option to pass ompl parameters. The MoveIt cpp demo just uses node_options.automatically_declare_parameters_from_overrides(true); which simply declares every parameter given to the node by yaml file but this is considered bad practice (although it could be an interim solution as the parameter handling best practice pattern is a MoveIt2 "global" issue). I think a good place to declare the ompl parameters would be in the ompl interface class because the MoveItPlanningPipeline global planner plugin should be agnostic to the MoveIt planner plugin used (i.e. the Fraunhofer demo uses the PILZ planner I think). @JafarAbdi and @tylerjw put some work into parameter handling, what do you think?

@AndyZe
Copy link
Member Author

AndyZe commented Dec 6, 2021

@sjahr I found the magic line that makes it all work again 👍

node->declare_parameter<std::string>("ompl.planning_plugin", "ompl_interface/OMPLPlanner");

I don't know why it was working previously without this.

Will make an issue about parameter loading. I think your idea to load the parameters from ompl is a good one. It's not just hybrid planning but many components of MoveIt that are having this issue. (#892)

@tylerjw
Copy link
Member

tylerjw commented Dec 6, 2021

I fixed the merge conflict but it might be better to rebase this commit on main so my merge commit goes away (as we are going to merge this and not squash it).

@AndyZe AndyZe force-pushed the feature/hybrid_planning branch 2 times, most recently from c7e0082 to bb46766 Compare December 7, 2021 16:31
@moveit moveit deleted a comment from mergify bot Dec 7, 2021
sjahr and others added 12 commits December 7, 2021 15:14
* Add hybrid_planning architecture skeleton code
* Add simple state machines to hybrid planning manager and local planner
* Initial global planner prototype implementation
* Forward joint_trajectory with local planner
* Forward hybrid planning motion request to global planner
* Abstract planner logic from hybrid planning manager by using a plugin
* Implement single plan execution logic
* Add test launch files, RViz and demo config
* Add test for motion_planning_request
* Make local planner component generic
* Add next_waypoint_sampler trajectory operator
* Update hybrid planning test to include collision object
* Clean up code and fix minor bugs.
* Update local planner component parameter
* Add local collision constraint solver
* Update planning scene topic name and test node
* Fix bugs and runtime errors in local planner component and it's plugins
* Add collision object that invalidates global trajectory
* Add simple "stop in front of collision object" demo
* Add hybrid planning manager reaction to local planner feedback
* Fix ament_lint_cmake
* Ensure that local planner start command and collision event are send once
* Add simple replanning logic plugin
* Use current state as start state for global planner
* Use RobotTrajectory instead of constraint vector describe local problem
* Add PlanningSceneMonitorPtr to local solver plugin
* Add local planner frequency parameter
* Use PID controller to create control outputs for robot controller
* Add hybrid_planning_manager config file
* Add more complex test node
* Update README
* Reset index in next_waypoint_sampler
* Use correct isPathValid() interface
* Rename path_invalidation flag
* Read planning scene instead of cloning it in local planner
* Add TODO creator
* Rename local constraint solver plugin
* Use read-locked access to the planning scene for collision checking
* Rename constraint_solver into local_constraint_solver
* Add missing pointer initialization
* Export missing plugins
* Use std::chrono_literals
* Construct smart pointers with std::make_* instead of 'new'
* Fixup const-ref in function signatures, reduce copies
* Improve planning scene locking, robot state processing, controller logic
* Add forward_trajectory local solver plugin (moveit#359)
* Use ros2_control based joint simulation and remove unnecessary comment
* Update copyrights
* Restructure hybrid planning package
* Fix formatting and add missing time stamp in local solver plugin
* Remove unnecessary logging and param loading
* Enable different interfaces between local planner and controller
* Use JointGroupPositionController as demo hardware controller
* Add reset method for trajectory operator and local constraint sampler
* Refactor next_waypoint_sampler into simple_sampler
* Include collision checking to forward_trajectory and remove unneeded plugin
* Fix formatting and plugin description
* Update README and add missing planner logic plugin description

Add TODO to use lifecycle components nodes to trigger initialization

Return a reaction result instead of bool on react()

Set invalidation flag to false on reset() in ForwardTrajectory local solver

Return local planner feedback from trajectory operator function calls

Fix segfault caused by passing through the global trajectory

Update comment, unify logging and add missing config parameters

Update to rolling
…eit#585)

Fix hybrid planning include folders (moveit#675)

Order stuff in the CMakeLists.txt and remove control_box package

Update README

Move member initialization to initializer lists

Remove control_box include dependency

Replace "loop-run" with "iteration"

Remove cpp interface class constructors and destructors

Use joint_state_broadcaster, clean up test node, add execution dependencies

Use only plugin interface header files and add missing dependencies

Clean up constructor and destructor definitions

Declare missing parameter in moveit_planning_pipeline_plugin

Move rclcpp::Loggers into anonymous namespaces

Switch CI branches to feature/hybrid_planning

Update message name

Remove moveit_msgs from .repos file

Update github workflows

Remove note from readme about building from source

Minor renamings, make reset() noexcept

Check for vector length of zero

Load moveit_cpp options with the Options helper. Reduces LOC.

Set the planning parameters within plan()

Function renaming

Authors and descriptions in header files only. New header file for error code interface.

Update namespacing

Use default QoS for subscribers

Better progress comparison

Add publish_joint_positions and publish_joint_velocities param

Grammar and other minor nitpicks

Restore moveit_msgs to .repos, for now
Refactor Global and Local Planner Components into NodeClasses

Add a simple launch test (#1)

Try to fix plugin export; add helpful debug when stuck

Error if global planning fails

READY and AWAIT_TRAJ states are redundant

Lock the planning scene as briefly as possible

Specify joint group when checking waypoint distance

Implement a reset() function in the local planner

Detect when the local planner gets stuck
Update robot state properly; remove debug prints; clang format

Check if the local planner is stuck within the forward_traj plugin, not local_planner_component
* Add unsuccessful action Hybrid Planning events and handle them in logic

* Replace std::once with simple bool variable

* Remove unneeded variable and update comments

Don't const& for built-in types

Co-authored-by: Tyler Weaver <tylerjw@gmail.com>
* Install hybrid_planning_demo_node separately to avoid exporting it

* Fix exported include directory

* Remove getTargetWayPointIndex() from abstract trajectory operator class

* Delete unused getTargetWayPointIndex()
@sjahr sjahr mentioned this pull request Dec 8, 2021
7 tasks
@AndyZe AndyZe merged commit 595813c into moveit:main Dec 8, 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

5 participants