Skip to content

Commit bcf9fa8

Browse files
Add multiple constraint example to OMPL Constraints guide (#421)
1 parent c7a0cb3 commit bcf9fa8

File tree

3 files changed

+83
-2
lines changed

3 files changed

+83
-2
lines changed
770 KB
Binary file not shown.

doc/how_to_guides/using_ompl_constrained_planning/ompl_constrained_planning.rst

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,16 @@ You can see the trajectory animated if planning succeeds. Finally, press Next to
9191
OMPL constrained planning orientation constraint example
9292
</video>
9393

94-
This example may take longer to plan. Press Next to remove all markers and end the example. If planning fails, you can start at the beginning of the section to try again.
94+
This example may take longer to plan. If planning fails, you can start at the beginning of the section to try again. Press Next to try mixed constraints,
9595

96+
.. raw:: html
97+
98+
<video width="300px" controls="true" autoplay="true" loop="true">
99+
<source src="../../../_static/videos/ompl_mixed_constraints.webm" type="video/webm">
100+
OMPL constrained planning orientation constraint example
101+
</video>
102+
103+
Press Next to remove all markers and end the example.
96104

97105
How to Set Constraints
98106
^^^^^^^^^^^^^^^^^^^^^^
@@ -250,7 +258,7 @@ Building on the previous constraint, we can make it a line by also reducing the
250258
Orientation Constraints
251259
-----------------------
252260

253-
Finally, we can place constraints on orientation. We set the target pose to be the other side of the robot for a more drastic move as we are no longer constrained by position.
261+
We can place constraints on orientation. We set the target pose to be the other side of the robot for a more drastic move as we are no longer constrained by position.
254262

255263
.. code-block:: c++
256264

@@ -289,3 +297,39 @@ Set up the planning problem as before and plan.
289297
move_group_interface.setPoseTarget(target_pose);
290298
move_group_interface.setPlanningTime(10.0);
291299
move_group_interface.plan(plan);
300+
301+
302+
Mixed Constraints
303+
-----------------
304+
305+
Finally, we can set both a position and an orientation constraint. We will use the same target pose that we used for the orientation constraint.
306+
307+
.. code-block:: c++
308+
309+
target_pose = get_relative_pose(-0.6, 0.1, 0);
310+
311+
We will also reuse our orientation constraint - but this time, the original box constraint won't work as the target pose is outside of our original box. Let's modify the box pose and dimensions such that the goal pose is reachable. Be aware that having a both a position and orientation constraint can drastically shrink the reachable area - the target pose not only needs to be within the box constraint as mentioned, but needs to be reachable while satisfying the orientation constriant, which is more difficult to visualize.
312+
313+
.. code-block:: c++
314+
315+
box.dimensions = { 1.0, 0.6, 1.0 };
316+
box_constraint.constraint_region.primitives[0] = box;
317+
318+
box_pose.position.x = 0;
319+
box_pose.position.y = -0.1;
320+
box_pose.position.z = current_pose.pose.position.z;
321+
box_constraint.constraint_region.primitive_poses[0] = box_pose;
322+
box_constraint.weight = 1.0;
323+
324+
As before, we create a generalized constraint message, this time adding both our position and orientation constrint.
325+
326+
.. code-block:: c++
327+
328+
moveit_msgs::msg::Constraints mixed_constraints;
329+
mixed_constraints.position_constraints.emplace_back(box_constraint);
330+
mixed_constraints.orientation_constraints.emplace_back(orientation_constraint);
331+
332+
move_group_interface.setPathConstraints(mixed_constraints);
333+
move_group_interface.setPoseTarget(target_pose);
334+
move_group_interface.setPlanningTime(10.0);
335+
move_group_interface.plan(plan);

doc/how_to_guides/using_ompl_constrained_planning/src/ompl_constrained_planning_tutorial.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,43 @@ int main(int argc, char** argv)
226226
success = (move_group_interface.plan(plan) == moveit::core::MoveItErrorCode::SUCCESS);
227227
RCLCPP_INFO(LOGGER, "Plan with orientation constraint %s", success ? "" : "FAILED");
228228

229+
moveit_visual_tools.prompt("Press 'Next' in the RvizVisualToolsGui window to try mixed_constraints");
230+
reset_demo();
231+
232+
// Finally, we can place constraints on orientation.
233+
// Use the target pose from the previous example
234+
target_pose = get_relative_pose(-0.6, 0.1, 0);
235+
236+
// Reuse the orientation constraint, and make a new box constraint
237+
box.dimensions = { 1.0, 0.6, 1.0 };
238+
box_constraint.constraint_region.primitives[0] = box;
239+
240+
box_pose.position.x = 0;
241+
box_pose.position.y = -0.1;
242+
box_pose.position.z = current_pose.pose.position.z;
243+
box_constraint.constraint_region.primitive_poses[0] = box_pose;
244+
box_constraint.weight = 1.0;
245+
246+
// Visualize the box constraint
247+
Eigen::Vector3d new_box_point_1(box_pose.position.x - box.dimensions[0] / 2,
248+
box_pose.position.y - box.dimensions[1] / 2,
249+
box_pose.position.z - box.dimensions[2] / 2);
250+
Eigen::Vector3d new_box_point_2(box_pose.position.x + box.dimensions[0] / 2,
251+
box_pose.position.y + box.dimensions[1] / 2,
252+
box_pose.position.z + box.dimensions[2] / 2);
253+
moveit_msgs::msg::Constraints mixed_constraints;
254+
mixed_constraints.position_constraints.emplace_back(box_constraint);
255+
mixed_constraints.orientation_constraints.emplace_back(orientation_constraint);
256+
moveit_visual_tools.publishCuboid(new_box_point_1, new_box_point_2, rviz_visual_tools::TRANSLUCENT_DARK);
257+
moveit_visual_tools.trigger();
258+
259+
move_group_interface.setPathConstraints(mixed_constraints);
260+
move_group_interface.setPoseTarget(target_pose);
261+
move_group_interface.setPlanningTime(20.0);
262+
263+
success = (move_group_interface.plan(plan) == moveit::core::MoveItErrorCode::SUCCESS);
264+
RCLCPP_INFO(LOGGER, "Plan with mixed constraint %s", success ? "" : "FAILED");
265+
229266
// Done!
230267
moveit_visual_tools.prompt("Press 'Next' in the RvizVisualToolsGui window to clear the markers");
231268
moveit_visual_tools.deleteAllMarkers();

0 commit comments

Comments
 (0)