-
Notifications
You must be signed in to change notification settings - Fork 8
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
Adds orientation constraints #55
Merged
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
6fad1fd
tweaks constrained planning tut to have only box and orientation cons…
kamiradi 5d894c8
[FT] adds orientation constraints
kamiradi ca77262
Merge branch 'main' into pr-orientation
sea-bass 7164d03
Merge remote-tracking branch 'origin/main' into pr-orientation
sea-bass 66f6797
Add docstring based on latest code cleanup
sea-bass b4b99a0
Fix build errors
sea-bass f04c8db
Working inequality and equality constraints position and orientation
kamiradi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -101,16 +101,16 @@ int main(int argc, char** argv) | |
|
||
// Now wait for the user to press Next before trying the planar constraints. | ||
moveit_visual_tools.prompt( | ||
"Press 'Next' in the RvizVisualToolsGui window to continue to the planar constraint example"); | ||
"Press 'Next' in the RvizVisualToolsGui window to continue to the orientation constraint example"); | ||
|
||
// Clear the path constraints and markers for the next example | ||
reset_demo(); | ||
/*reset_demo();*/ | ||
|
||
// In the second problem we plan with the end-effector constrained to a plane. | ||
// We need to create a pose goal that lies in this plane. | ||
// The plane is tilted by 45 degrees, so moving an equal amount in the y and z direction should be ok. | ||
// Any goal or start state should also satisfy the path constraints. | ||
target_pose = get_relative_pose(0.0, 0.3, -0.3); | ||
/*target_pose = get_relative_pose(0.0, 0.3, -0.3);*/ | ||
|
||
// We create a plane perpendicular to the y-axis and tilt it by 45 degrees | ||
|
||
|
@@ -122,88 +122,88 @@ int main(int argc, char** argv) | |
// (:code:`1e-4` by default). MoveIt will use the stricter tolerance (the box width) to check the constraints, and | ||
// many states will appear invalid. That's where the magic number :code:`0.0005` comes from, it is between | ||
// :code:`0.00001` and :code:`0.001`. | ||
moveit_msgs::msg::PositionConstraint plane_constraint; | ||
plane_constraint.header.frame_id = move_group_interface.getPoseReferenceFrame(); | ||
plane_constraint.link_name = move_group_interface.getEndEffectorLink(); | ||
shape_msgs::msg::SolidPrimitive plane; | ||
plane.type = shape_msgs::msg::SolidPrimitive::BOX; | ||
plane.dimensions = { 1.0, 0.0005, 1.0 }; | ||
plane_constraint.constraint_region.primitives.emplace_back(plane); | ||
|
||
geometry_msgs::msg::Pose plane_pose; | ||
plane_pose.position.x = current_pose.pose.position.x; | ||
plane_pose.position.y = current_pose.pose.position.y; | ||
plane_pose.position.z = current_pose.pose.position.z; | ||
plane_pose.orientation.x = sin(M_PI_4 / 2); | ||
plane_pose.orientation.y = 0.0; | ||
plane_pose.orientation.z = 0.0; | ||
plane_pose.orientation.w = cos(M_PI_4 / 2); | ||
plane_constraint.constraint_region.primitive_poses.emplace_back(plane_pose); | ||
plane_constraint.weight = 1.0; | ||
|
||
// Visualize the constraint | ||
auto d = sqrt(pow(target_pose.pose.position.y, 2) + pow(target_pose.pose.position.z, 2)); | ||
|
||
Eigen::Vector3d normal(0, 1, 1); | ||
moveit_visual_tools.publishNormalAndDistancePlane(normal, d, rviz_visual_tools::TRANSLUCENT_DARK); | ||
moveit_visual_tools.trigger(); | ||
|
||
moveit_msgs::msg::Constraints plane_constraints; | ||
plane_constraints.position_constraints.emplace_back(plane_constraint); | ||
plane_constraints.name = "use_equality_constraints"; | ||
move_group_interface.setPathConstraints(plane_constraints); | ||
|
||
// And again, configure and solve the planning problem | ||
move_group_interface.setPoseTarget(target_pose); | ||
move_group_interface.setPlanningTime(10.0); | ||
|
||
success = (move_group_interface.plan(plan) == moveit::core::MoveItErrorCode::SUCCESS); | ||
RCLCPP_INFO(LOGGER, "Plan with plane constraint %s", success ? "" : "FAILED"); | ||
|
||
moveit_visual_tools.prompt( | ||
"Press 'next' in the RvizVisualToolsGui window to continue to the linear constraint example"); | ||
|
||
reset_demo(); | ||
|
||
// We can also plan along a line. We can use the same pose as last time. | ||
target_pose = get_relative_pose(0.0, 0.3, -0.3); | ||
|
||
// Building on the previous constraint, we can make it a line, by also reducing the dimension of the box in the x-direction. | ||
moveit_msgs::msg::PositionConstraint line_constraint; | ||
line_constraint.header.frame_id = move_group_interface.getPoseReferenceFrame(); | ||
line_constraint.link_name = move_group_interface.getEndEffectorLink(); | ||
shape_msgs::msg::SolidPrimitive line; | ||
line.type = shape_msgs::msg::SolidPrimitive::BOX; | ||
line.dimensions = { 0.0005, 0.0005, 1.0 }; | ||
line_constraint.constraint_region.primitives.emplace_back(line); | ||
|
||
geometry_msgs::msg::Pose line_pose; | ||
line_pose.position.x = current_pose.pose.position.x; | ||
line_pose.position.y = current_pose.pose.position.y; | ||
line_pose.position.z = current_pose.pose.position.z; | ||
line_pose.orientation.x = sin(M_PI_4 / 2); | ||
line_pose.orientation.y = 0.0; | ||
line_pose.orientation.z = 0.0; | ||
line_pose.orientation.w = cos(M_PI_4 / 2); | ||
line_constraint.constraint_region.primitive_poses.emplace_back(line_pose); | ||
line_constraint.weight = 1.0; | ||
|
||
// Visualize the constraint | ||
moveit_visual_tools.publishLine(current_pose.pose.position, target_pose.pose.position, | ||
rviz_visual_tools::TRANSLUCENT_DARK); | ||
moveit_visual_tools.trigger(); | ||
|
||
moveit_msgs::msg::Constraints line_constraints; | ||
line_constraints.position_constraints.emplace_back(line_constraint); | ||
line_constraints.name = "use_equality_constraints"; | ||
move_group_interface.setPathConstraints(line_constraints); | ||
move_group_interface.setPoseTarget(target_pose); | ||
|
||
success = (move_group_interface.plan(plan) == moveit::core::MoveItErrorCode::SUCCESS); | ||
RCLCPP_INFO(LOGGER, "Plan with line constraint %s", success ? "" : "FAILED"); | ||
|
||
moveit_visual_tools.prompt( | ||
"Press 'Next' in the RvizVisualToolsGui window to continue to the orientation constraint example"); | ||
/*moveit_msgs::msg::PositionConstraint plane_constraint;*/ | ||
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. Remove whatever is commented out 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. Same here |
||
/*plane_constraint.header.frame_id = move_group_interface.getPoseReferenceFrame();*/ | ||
/*plane_constraint.link_name = move_group_interface.getEndEffectorLink();*/ | ||
/*shape_msgs::msg::SolidPrimitive plane;*/ | ||
/*plane.type = shape_msgs::msg::SolidPrimitive::BOX;*/ | ||
/*plane.dimensions = { 1.0, 0.0005, 1.0 };*/ | ||
/*plane_constraint.constraint_region.primitives.emplace_back(plane);*/ | ||
/**/ | ||
/*geometry_msgs::msg::Pose plane_pose;*/ | ||
/*plane_pose.position.x = current_pose.pose.position.x;*/ | ||
/*plane_pose.position.y = current_pose.pose.position.y;*/ | ||
/*plane_pose.position.z = current_pose.pose.position.z;*/ | ||
/*plane_pose.orientation.x = sin(M_PI_4 / 2);*/ | ||
/*plane_pose.orientation.y = 0.0;*/ | ||
/*plane_pose.orientation.z = 0.0;*/ | ||
/*plane_pose.orientation.w = cos(M_PI_4 / 2);*/ | ||
/*plane_constraint.constraint_region.primitive_poses.emplace_back(plane_pose);*/ | ||
/*plane_constraint.weight = 1.0;*/ | ||
/**/ | ||
/*// Visualize the constraint*/ | ||
/*auto d = sqrt(pow(target_pose.pose.position.y, 2) + pow(target_pose.pose.position.z, 2));*/ | ||
/**/ | ||
/*Eigen::Vector3d normal(0, 1, 1);*/ | ||
/*moveit_visual_tools.publishNormalAndDistancePlane(normal, d, rviz_visual_tools::TRANSLUCENT_DARK);*/ | ||
/*moveit_visual_tools.trigger();*/ | ||
/**/ | ||
/*moveit_msgs::msg::Constraints plane_constraints;*/ | ||
/*plane_constraints.position_constraints.emplace_back(plane_constraint);*/ | ||
/*plane_constraints.name = "use_equality_constraints";*/ | ||
/*move_group_interface.setPathConstraints(plane_constraints);*/ | ||
/**/ | ||
/*// And again, configure and solve the planning problem*/ | ||
/*move_group_interface.setPoseTarget(target_pose);*/ | ||
/*move_group_interface.setPlanningTime(10.0);*/ | ||
/**/ | ||
/*success = (move_group_interface.plan(plan) == moveit::core::MoveItErrorCode::SUCCESS);*/ | ||
/*RCLCPP_INFO(LOGGER, "Plan with plane constraint %s", success ? "" : "FAILED");*/ | ||
/**/ | ||
/*moveit_visual_tools.prompt(*/ | ||
/* "Press 'next' in the RvizVisualToolsGui window to continue to the linear constraint example");*/ | ||
/**/ | ||
/*reset_demo();*/ | ||
/**/ | ||
/*// We can also plan along a line. We can use the same pose as last time.*/ | ||
/*target_pose = get_relative_pose(0.0, 0.3, -0.3);*/ | ||
/**/ | ||
/*// Building on the previous constraint, we can make it a line, by also reducing the dimension of the box in the x-direction.*/ | ||
/*moveit_msgs::msg::PositionConstraint line_constraint;*/ | ||
/*line_constraint.header.frame_id = move_group_interface.getPoseReferenceFrame();*/ | ||
/*line_constraint.link_name = move_group_interface.getEndEffectorLink();*/ | ||
/*shape_msgs::msg::SolidPrimitive line;*/ | ||
/*line.type = shape_msgs::msg::SolidPrimitive::BOX;*/ | ||
/*line.dimensions = { 0.0005, 0.0005, 1.0 };*/ | ||
/*line_constraint.constraint_region.primitives.emplace_back(line);*/ | ||
/**/ | ||
/*geometry_msgs::msg::Pose line_pose;*/ | ||
/*line_pose.position.x = current_pose.pose.position.x;*/ | ||
/*line_pose.position.y = current_pose.pose.position.y;*/ | ||
/*line_pose.position.z = current_pose.pose.position.z;*/ | ||
/*line_pose.orientation.x = sin(M_PI_4 / 2);*/ | ||
/*line_pose.orientation.y = 0.0;*/ | ||
/*line_pose.orientation.z = 0.0;*/ | ||
/*line_pose.orientation.w = cos(M_PI_4 / 2);*/ | ||
/*line_constraint.constraint_region.primitive_poses.emplace_back(line_pose);*/ | ||
/*line_constraint.weight = 1.0;*/ | ||
/**/ | ||
/*// Visualize the constraint*/ | ||
/*moveit_visual_tools.publishLine(current_pose.pose.position, target_pose.pose.position,*/ | ||
/* rviz_visual_tools::TRANSLUCENT_DARK);*/ | ||
/*moveit_visual_tools.trigger();*/ | ||
/**/ | ||
/*moveit_msgs::msg::Constraints line_constraints;*/ | ||
/*line_constraints.position_constraints.emplace_back(line_constraint);*/ | ||
/*line_constraints.name = "use_equality_constraints";*/ | ||
/*move_group_interface.setPathConstraints(line_constraints);*/ | ||
/*move_group_interface.setPoseTarget(target_pose);*/ | ||
/**/ | ||
/*success = (move_group_interface.plan(plan) == moveit::core::MoveItErrorCode::SUCCESS);*/ | ||
/*RCLCPP_INFO(LOGGER, "Plan with line constraint %s", success ? "" : "FAILED");*/ | ||
/**/ | ||
/*moveit_visual_tools.prompt(*/ | ||
/* "Press 'Next' in the RvizVisualToolsGui window to continue to the orientation constraint example");*/ | ||
reset_demo(); | ||
|
||
// Finally, we can place constraints on orientation. | ||
|
@@ -229,42 +229,42 @@ int main(int argc, char** argv) | |
success = (move_group_interface.plan(plan) == moveit::core::MoveItErrorCode::SUCCESS); | ||
RCLCPP_INFO(LOGGER, "Plan with orientation constraint %s", success ? "" : "FAILED"); | ||
|
||
moveit_visual_tools.prompt("Press 'Next' in the RvizVisualToolsGui window to try mixed_constraints"); | ||
/*moveit_visual_tools.prompt("Press 'Next' in the RvizVisualToolsGui window to try mixed_constraints");*/ | ||
reset_demo(); | ||
|
||
// Finally, we can place constraints on orientation. | ||
// Use the target pose from the previous example | ||
target_pose = get_relative_pose(-0.6, 0.1, 0); | ||
|
||
// Reuse the orientation constraint, and make a new box constraint | ||
box.dimensions = { 1.0, 0.6, 1.0 }; | ||
box_constraint.constraint_region.primitives[0] = box; | ||
|
||
box_pose.position.x = 0; | ||
box_pose.position.y = -0.1; | ||
box_pose.position.z = current_pose.pose.position.z; | ||
box_constraint.constraint_region.primitive_poses[0] = box_pose; | ||
box_constraint.weight = 1.0; | ||
|
||
// Visualize the box constraint | ||
Eigen::Vector3d new_box_point_1(box_pose.position.x - box.dimensions[0] / 2, | ||
box_pose.position.y - box.dimensions[1] / 2, | ||
box_pose.position.z - box.dimensions[2] / 2); | ||
Eigen::Vector3d new_box_point_2(box_pose.position.x + box.dimensions[0] / 2, | ||
box_pose.position.y + box.dimensions[1] / 2, | ||
box_pose.position.z + box.dimensions[2] / 2); | ||
moveit_msgs::msg::Constraints mixed_constraints; | ||
mixed_constraints.position_constraints.emplace_back(box_constraint); | ||
mixed_constraints.orientation_constraints.emplace_back(orientation_constraint); | ||
moveit_visual_tools.publishCuboid(new_box_point_1, new_box_point_2, rviz_visual_tools::TRANSLUCENT_DARK); | ||
moveit_visual_tools.trigger(); | ||
|
||
move_group_interface.setPathConstraints(mixed_constraints); | ||
move_group_interface.setPoseTarget(target_pose); | ||
move_group_interface.setPlanningTime(20.0); | ||
|
||
success = (move_group_interface.plan(plan) == moveit::core::MoveItErrorCode::SUCCESS); | ||
RCLCPP_INFO(LOGGER, "Plan with mixed constraint %s", success ? "" : "FAILED"); | ||
/*target_pose = get_relative_pose(-0.6, 0.1, 0);*/ | ||
/**/ | ||
/*// Reuse the orientation constraint, and make a new box constraint*/ | ||
/*box.dimensions = { 1.0, 0.6, 1.0 };*/ | ||
/*box_constraint.constraint_region.primitives[0] = box;*/ | ||
/**/ | ||
/*box_pose.position.x = 0;*/ | ||
/*box_pose.position.y = -0.1;*/ | ||
/*box_pose.position.z = current_pose.pose.position.z;*/ | ||
/*box_constraint.constraint_region.primitive_poses[0] = box_pose;*/ | ||
/*box_constraint.weight = 1.0;*/ | ||
/**/ | ||
/*// Visualize the box constraint*/ | ||
/*Eigen::Vector3d new_box_point_1(box_pose.position.x - box.dimensions[0] / 2,*/ | ||
/* box_pose.position.y - box.dimensions[1] / 2,*/ | ||
/* box_pose.position.z - box.dimensions[2] / 2);*/ | ||
/*Eigen::Vector3d new_box_point_2(box_pose.position.x + box.dimensions[0] / 2,*/ | ||
/* box_pose.position.y + box.dimensions[1] / 2,*/ | ||
/* box_pose.position.z + box.dimensions[2] / 2);*/ | ||
/*moveit_msgs::msg::Constraints mixed_constraints;*/ | ||
/*mixed_constraints.position_constraints.emplace_back(box_constraint);*/ | ||
/*mixed_constraints.orientation_constraints.emplace_back(orientation_constraint);*/ | ||
/*moveit_visual_tools.publishCuboid(new_box_point_1, new_box_point_2, rviz_visual_tools::TRANSLUCENT_DARK);*/ | ||
/*moveit_visual_tools.trigger();*/ | ||
/**/ | ||
/*move_group_interface.setPathConstraints(mixed_constraints);*/ | ||
/*move_group_interface.setPoseTarget(target_pose);*/ | ||
/*move_group_interface.setPlanningTime(20.0);*/ | ||
/**/ | ||
/*success = (move_group_interface.plan(plan) == moveit::core::MoveItErrorCode::SUCCESS);*/ | ||
/*RCLCPP_INFO(LOGGER, "Plan with mixed constraint %s", success ? "" : "FAILED");*/ | ||
|
||
// Done! | ||
moveit_visual_tools.prompt("Press 'Next' in the RvizVisualToolsGui window to clear the markers"); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Remove?
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.
Just talked to Aditya and I think we should keep and uncomment as these are the move-on-line and move-within-plane demos
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.
Sounds good. I do suspect that the rotated bounding box constraints may not work with the current implementation of position constraints -- there is another overload that accepts a rigid transform from a coordinate frame
A
toA_bar
which enables rotating the reference frame, and we may need to achieve this.Trying it out will tell.