diff --git a/doc/chomp_interface/chomp_interface_tutorial.rst b/doc/chomp_interface/chomp_interface_tutorial.rst deleted file mode 100644 index e0efbd17a..000000000 --- a/doc/chomp_interface/chomp_interface_tutorial.rst +++ /dev/null @@ -1,58 +0,0 @@ -CHOMP Interface -=============== - -.. image:: chomp.png - :width: 700px - -Covariant Hamiltonian optimization for motion planning (CHOMP) is a novel gradient-based trajectory optimization procedure that makes many everyday motion planning problems both simple and trainable (Ratliff et al., 2009c). While most high-dimensional motion planners separate trajectory generation into distinct planning and optimization stages, this algorithm capitalizes on covariant gradient and functional gradient approaches to the optimization stage to design a motion planning algorithm based entirely on trajectory optimization. Given an infeasible naive trajectory, CHOMP reacts to the surrounding environment to quickly pull the trajectory out of collision while simultaneously optimizing dynamical quantities such as joint velocities and accelerations. It rapidly converges to a smooth collision-free trajectory that can be executed efficiently on the robot. Integration into latest version of MoveIt! is work in progress. `More info `_ - -Getting Started ---------------- -If you haven't already done so, make sure you've completed the steps in `Getting Started <../getting_started/getting_started.html>`_. - -You should also have gone through the steps in `Visualization with MoveIt! RViz Plugin <../quickstart_in_rviz/quickstart_in_rviz_tutorial.html>`_ - -Prerequisites --------------- - 1. You must have the latest version of MoveIt! installed. On ROS Kinetic you will need to build MoveIt! from source. We will go through the steps for doing this below. - 2. To use CHOMP with your robot you must already have a MoveIt! configuration package for your robot already. For example, if you have a Panda robot, it's probably called ``panda_moveit_config``. This is typically built using the `MoveIt! Setup Assistant <../setup_assistant/setup_assistant_tutorial.html>`_. - -Installing MoveIt! from Source ------------------------------- -As you add and remove packages from your workspace you will need to clean your workspace and re-run the command to install new missing dependencies. Clean your workspace to remove references to the system wide installation of MoveIt!: :: - - cd ~/ws_moveit/src - catkin clean - -Now follow the instructions on the MoveIt! homepage for `installing MoveIt! Kinetic from source `_. Note that you can skip the **Prerequisites** section since you should already have a Catkin workspace. - -Re-source the setup files: :: - - source ~/ws_moveit/devel/setup.bash - -Using CHOMP with Your Robot ---------------------------- -**Note:** if you are following this demo using the ``panda_moveit_config`` from the `ros-planning/panda_moveit_config `_ repository, these steps are already done for you and you can skip this section. - -#. Simply download `chomp_planning_pipeline.launch.xml `_ file into the launch directory of your MoveIt! config package. In our case, we will save this file in the ``panda_moveit_config/launch`` directory. -#. Adjust the line ```` to ```` replacing ```` with the name of your MoveIt! configuration package. -#. Download `chomp_planning.yaml `_ file into the config directory of your MoveIt! config package. In our case, we will save this file in the ``panda_moveit_config/config`` directory. -#. Open ``chomp_planning.yaml`` in your favorite editor and change ``animate_endeffector_segment: "panda_rightfinger"`` to the appropriate link for your robot. -#. Copy the ``demo.launch`` file to ``demo_chomp.launch``. Note that this file is also in the launch directory of your MoveIt! config package. In our case, the ``panda_moveit_config/launch`` directory. -#. Find the lines where ``move_group.launch`` is included and change it to: :: - - - - - - - - - -#. Open the ``move_group.launch`` file in your ``/launch/`` folder and make two changes. First, add ```` just under the ```` tag and second, within the ```` tag replace ```` with ````. - -Running the Demo ----------------- -If you have the ``panda_moveit_config`` from the `ros-planning/panda_moveit_config `_ repository you should be able to simply run the demo: :: - - roslaunch panda_moveit_config demo_chomp.launch \ No newline at end of file diff --git a/doc/chomp_interface/chomp.png b/doc/chomp_planner/chomp.png similarity index 100% rename from doc/chomp_interface/chomp.png rename to doc/chomp_planner/chomp.png diff --git a/doc/chomp_planner/chomp_planner_tutorial.rst b/doc/chomp_planner/chomp_planner_tutorial.rst new file mode 100644 index 000000000..ddedb7da3 --- /dev/null +++ b/doc/chomp_planner/chomp_planner_tutorial.rst @@ -0,0 +1,130 @@ +CHOMP Planner +=============== + +.. image:: chomp.png + :width: 700px + +Covariant Hamiltonian optimization for motion planning (CHOMP) is a novel gradient-based trajectory optimization procedure that makes many everyday motion planning problems both simple and trainable (Ratliff et al., 2009c). While most high-dimensional motion planners separate trajectory generation into distinct planning and optimization stages, this algorithm capitalizes on covariant gradient and functional gradient approaches to the optimization stage to design a motion planning algorithm based entirely on trajectory optimization. Given an infeasible naive trajectory, CHOMP reacts to the surrounding environment to quickly pull the trajectory out of collision while simultaneously optimizing dynamical quantities such as joint velocities and accelerations. It rapidly converges to a smooth collision-free trajectory that can be executed efficiently on the robot. Integration into latest version of MoveIt! is `work in progress `_. `More info `_ + +Getting Started +--------------- +If you haven't already done so, make sure you've completed the steps in `Getting Started <../getting_started/getting_started.html>`_. + +You should also have gone through the steps in `Visualization with MoveIt! RViz Plugin <../quickstart_in_rviz/quickstart_in_rviz_tutorial.html>`_ + +Prerequisites +-------------- + 1. You must have the latest version of MoveIt! installed. On ROS Kinetic you will need to build MoveIt! from source. A build from source is required as CHOMP is not part of the official release yet. It is therefore not included in the binary packages. We will go through the steps for doing this below. + 2. To use CHOMP with your robot you must already have a MoveIt! configuration package for your robot already. For example, if you have a Panda robot, it's probably called ``panda_moveit_config``. This is typically built using the `MoveIt! Setup Assistant <../setup_assistant/setup_assistant_tutorial.html>`_. + +Installing MoveIt! from Source +------------------------------ +As you add and remove packages from your workspace you will need to clean your workspace and re-run the command to install new missing dependencies. Clean your workspace to remove references to the system wide installation of MoveIt!: :: + + cd ~/ws_moveit/src + catkin clean + +Now follow the instructions on the MoveIt! homepage for `installing MoveIt! Kinetic from source `_. Note that you can skip the **Prerequisites** section since you should already have a Catkin workspace. + +Re-source the setup files: :: + + source ~/ws_moveit/devel/setup.bash + +Using CHOMP with Your Robot +--------------------------- +**Note:** if you are following this demo using the ``panda_moveit_config`` from the `ros-planning/panda_moveit_config `_ repository, these steps are already done for you and you can skip this section. + +#. Simply download `chomp_planning_pipeline.launch.xml `_ file into the launch directory of your MoveIt! config package. In our case, we will save this file in the ``panda_moveit_config/launch`` directory. +#. Adjust the line ```` to ```` replacing ```` with the name of your MoveIt! configuration package. +#. Download `chomp_planning.yaml `_ file into the config directory of your MoveIt! config package. In our case, we will save this file in the ``panda_moveit_config/config`` directory. +#. Open ``chomp_planning.yaml`` in your favorite editor and change ``animate_endeffector_segment: "panda_rightfinger"`` to the appropriate link for your robot. +#. Copy the ``demo.launch`` file to ``demo_chomp.launch``. Note that this file is also in the launch directory of your MoveIt! config package. In our case, the ``panda_moveit_config/launch`` directory. +#. Find the lines where ``move_group.launch`` is included and change it to: :: + + + + + + + + + +#. Open the ``move_group.launch`` file in your ``/launch/`` folder and make two changes. + + * First, add ```` just under the ```` tag, and, + + * Second, within the ```` tag replace ```` with ````. + +Running the Demo +---------------- +If you have the ``panda_moveit_config`` from the `ros-planning/panda_moveit_config `_ repository you should be able to simply run the demo: :: + + roslaunch panda_moveit_config demo_chomp.launch + +Running CHOMP with Obstacles in the Scene ++++++++++++++++++++++++++++++++++++++++++ +To run CHOMP in an evironment with obstacles, you can run the sample python script: + + :codedir:`collision_scene_example.py`. + +This scripts creates a cluttered scene with four ostacles or a simple scene with one obstacle depending on the argument given to the script. One can also change the position/size of the obstacles to change the scene. + +To run the CHOMP planner with obstacles, open two shells. In the first shell start RViz and wait for everything to finish loading: :: + + roslaunch panda_moveit_config demo_chomp.launch + +In the second shell, run either of the two commands: :: + + rosrun moveit_tutorials collision_scene_example.py cluttered + +or: :: + + rosrun moveit_tutorials collision_scene_example.py sparse + +Next, in RViz, select CHOMP in the MotionPlanning pannel under the Context tab. Set the desired start and goal states by moving the end-effector around with the imarker and then click on the Plan button under the Planning tab in the MotionPlanning pannel to start planning. The planner will now attempt to find a feasible solution between the given start and end position. + +Tweaking some of the parameters for CHOMP +----------------------------------------- +CHOMP has some optimization parameters associated with it. These can be modified for the given environment/robot you are working with and is normally present in the `chomp_planning.yaml `_ file in config folder of the robot you are working with. If this file does not exist for your robot, you can create it and set the parameter values as you want. The following are some of the insights to set up these parameter values for some of them: + +- *planning_time_limit*: the maximum time the optimizer can take to find a solution before terminating + +- *max_iterations*: this is the maximum number of iterations that the planner can take to find a good solution while optimization + +- *max_iterations_after_collision_free*: maximum iterations to be performed after a collision free path is found. + +- *smoothness_cost_weight*: the smoothness_cost_weight parameters controls its weight in the final cost that CHOMP is actually optimizing over + +- *obstacle_cost_weight*: this controls the weight to be given to obstacles towards the final cost CHOMP optimizes over. e.g., 0.0 would have obstacles to be ignored, 1.0 would be a hard constraint + +- *learning_rate*: this is the learning rate used by the optimizer to find the local / global minima while reducing the total cost. + +- *smoothness_cost_velocity, smoothness_cost_acceleration, smoothness_cost_jerk*: variables associated with the cost in velocity, acceleration and jerk. + +- *ridge_factor*: the noise added to the diagnal of the total `quadratic cost matrix `_ in the objective function. Addition of small noise (e.g., 0.001) allows CHOMP to avoid obstacles at the cost of smoothness in trajectory. + +- *use_pseudo_inverse*: enable pseudo inverse calculations or not. + +- *pseudo_inverse_ridge_factor*: set the ridge factor if pseudo inverse is enabled. + +- *joint_update_limit*: set the update limit for the robot joints + +- *collision_clearance*: the minimum distance that needs to be maintained to avoid obstacles. + +- *collision_threshold*: the collision threshold cost that needs to be mainted to avoid collisions + +- *use_stochastic_descent*: set this to true/false if you want to use stochastic descent while optimizing the cost. In stochastic descent, a random point from the trajectory is used, rather than all the trajectory points. This is faster and guaranteed to converge, but it may take more iterations in the worst case. + +Choosing parameters for CHOMP requires some sort of intuition based on the environment we are working in. One can have the default parameters for CHOMP and this works well in environments without obstacles. However in cases where the scene is populated with obstacles, we need to vary some parameters to ensure that CHOMP is not stuck in local minima, or quickly finds optimal solutions, prefering trajectories which ovoids obstacles. Some parameters like increasing the *ridge_factor* to say 0.001 makes CHOMP avoids obstacles by not prefering smooth trajectories, so there is a trade-off between smoothness and CHOMP's ability to avoid obstacles. Choosing the correct number of *max_iterations*, *learning_rate* is important based on the environment we are working in. Not choosing the appropriate CHOMP parameters might lead to CHOMP reporting not finding a collision free path. *collision_clearance*, *collision_threshold* parameters are useful in specifying the minimum distance to be kept from obstacles to avoid collisions. + +Some of the unused/commented parameters are *hmc_stochasticity*, *hmc_annealing_factor*, *hmc_discretization*, *use_hamiltonian_montecarlo*, *animate_endeffector*, *animate_endeffector_segment*, *animate_path*, *random_jump_amount*, *add_randomness*. + +Difference between plans obtained by CHOMP and OMPL +--------------------------------------------------- +Optimizing planners optimize a cost function that may sometimes lead to surprising results: moving through a thin obstacle might be lower cost than a long, winding trajectory that avoids all collisions. In this section we make a distinction between paths obtained from CHOMP and contrast it to those obtained from OMPL. + +OMPL is a open source library for sampling based / randomized motion planning algorithms. Sampling based algorithms are probabilistically complete: a solution would be eventually found if one exists, however non-existence of a solution cannot be reported. These algorithms are efficient and usually find a solution quickly. OMPL does not contain any code related to collision checking or visualization as the designers of OMPL did not want to tie it to a any particular colision checker or visualization front end. The library is designed so it can be easily integrated into systems that provide the additional components. MoveIt integrates directly with OMPL and uses the motion planners from OMP as its default set of planners. The planners in OMPL are abstract; i.e. OMPL has no concept of a robot. Instead, MoveIt! configures OMPL and provides the back-end for OMPL to work with problems in Robotics. + +CHOMP: While most high-dimensional motion planners separate trajectory generation into distinct planning and optimization stages, CHOMP capitalizes on covariant gradient and functional gradient approaches to the optimization stage to design a motion planning algorithm based entirely on trajectory optimization. Given an infeasible naive trajectory, CHOMP reacts to the surrounding environment to quickly pull the trajectory out of collision while simultaneously optimizing dynamical quantities such as joint velocities and accelerations. It rapidly converges to a smooth collision-free trajectory that can be executed efficiently on the robot. A covaraint update rule ensures that CHOMP quickly converges to a locally optimal trajectory. + +For scenes containing obstacles, CHOMP often generates paths which do not prefer smooth trajectories by addition of some noise (*ridge_factor*) in the cost function for the dynamical quantities of the robot (like acceleration, velocity). CHOMP is able to avoid obstacle in most cases but also fails in some if it gets stuck in the local minima and might report a solution not found due to a naive initial guess for the trajectory. OMPL on the other hand generates collision free smooth paths in the presence of obstacles too. \ No newline at end of file diff --git a/doc/chomp_planner/scripts/collision_scene_example.py b/doc/chomp_planner/scripts/collision_scene_example.py new file mode 100755 index 000000000..8edffb4ce --- /dev/null +++ b/doc/chomp_planner/scripts/collision_scene_example.py @@ -0,0 +1,81 @@ +#!/usr/bin/env python +import rospy +from moveit_commander import RobotCommander, PlanningSceneInterface +import geometry_msgs.msg +import time +import sys + +class CollisionSceneExample(object): + + def __init__(self): + self._scene = PlanningSceneInterface() + + # clear the scene + self._scene.remove_world_object() + + self.robot = RobotCommander() + + # pause to wait for rviz to load + print "============ Waiting while RVIZ displays the scene with obstacles..." + + # TODO: need to replace this sleep by explicitly waiting for the scene to be updated. + rospy.sleep(2) + + def add_one_box(self): + box1_pose = [0.25, 0.25, 0.0, 0, 0, 0, 1] + box1_dimensions = [0.25, 0.25, 0.75] + + self.add_box_object("box1", box1_dimensions, box1_pose) + + print "============ Added one obstacle to RViz!!" + + def add_four_boxes(self): + box1_pose = [0.20, 0.50, 0.25, 0, 0, 0, 1] + box1_dimensions = [0.2, 0.2, 0.5] + + box2_pose = [-0.55, -0.55, 0, 0, 0, 0, 1] + box2_dimensions = [0.25, 0.25, 1.75] + + box3_pose = [0.5, -0.55, 0.14, 0, 0, 0, 1] + box3_dimensions = [0.28, 0.28, 0.22] + + box4_pose = [-0.4, 0.4, 0.5, 0, 0, 0, 1] + box4_dimensions = [0.25, 0.25, 1.1] + + self.add_box_object("box1", box1_dimensions, box1_pose) + self.add_box_object("box2", box2_dimensions, box2_pose) + self.add_box_object("box3", box3_dimensions, box3_pose) + self.add_box_object("box4", box4_dimensions, box4_pose) + + print "========== Added 4 obstacles to the scene!!" + + def add_box_object(self, name, dimensions, pose): + p = geometry_msgs.msg.PoseStamped() + p.header.frame_id = self.robot.get_planning_frame() + p.header.stamp = rospy.Time.now() + p.pose.position.x = pose[0] + p.pose.position.y = pose[1] + p.pose.position.z = pose[2] + p.pose.orientation.x = pose[3] + p.pose.orientation.y = pose[4] + p.pose.orientation.z = pose[5] + p.pose.orientation.w = pose[6] + + self._scene.add_box(name, p, (dimensions[0], dimensions[1], dimensions[2])) + +if __name__ == "__main__": + rospy.init_node("collision_scene_example_cluttered") + while not rospy.search_param('robot_description_semantic') and not rospy.is_shutdown(): + time.sleep(0.5) + load_scene = CollisionSceneExample() + + if (len(sys.argv) != 2): + print "Correct usage:: \n\"rosrun moveit_tutorials collision_scene_example.py cluttered\" OR \n\"rosrun moveit_tutorials collision_scene_example.py sparse\"" + sys.exit() + if sys.argv[1] == "cluttered": + load_scene.add_four_boxes(); + elif sys.argv[1] == "sparse": + load_scene.add_one_box(); + else: + print "Please specify correct type of scene as cluttered or sparse" + sys.exit() diff --git a/index.rst b/index.rst index 929c8e198..c6749f4de 100644 --- a/index.rst +++ b/index.rst @@ -66,7 +66,7 @@ Configuration doc/kinematics_configuration/kinematics_configuration_tutorial doc/custom_constraint_samplers/custom_constraint_samplers_tutorial doc/ompl_interface/ompl_interface_tutorial - doc/chomp_interface/chomp_interface_tutorial + doc/chomp_planner/chomp_planner_tutorial Miscellaneous ----------------------------