-
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
Conversation
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.
LGTM, just a few typos and more of a question.
Also, just remove the extra tutorial code instead of commenting out
|
||
// 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);*/ |
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
to A_bar
which enables rotating the reference frame, and we may need to achieve this.
Trying it out will tell.
|
||
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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
src/ktopt_planning_context.cpp
Outdated
// of the tolerances as the theta bound | ||
const double theta_bound = orientation_constraint.absolute_x_axis_tolerance; | ||
|
||
// Add position constraint to each knot point of the trajectory |
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.
I was wondering in the last PR whether we should have used the same number of knot points for all position/orientation constraints. What do you think?
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.
It is a parameter, so the user has the option of adding more/less constraints along the path.
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.
Yes, I meant should there be 2 separate parameters for position/orientation constraints, or just use the same parameter for all constraints?
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.
Ah I meant, right now even though im reading theta bound as the tolerance, I am using the one @sea-bass added as a parameter.
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.
Test it and it works for me, we can merge it once the comments are addressed
|
||
// 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);*/ |
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
|
||
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
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 a few remarks
src/ktopt_planning_context.cpp
Outdated
// Frame A: The frame in which the orientation constraint is defined | ||
// Frame B: The frame to which the orientation constraint is enforced |
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.
In the code below, the roles of A and B are exactly swapped: orientation_constraint.link_name
defines the frame which is enforced and orientation_constraint.header.frame_id
is the defining frame.
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.
Oooh nice catch. Thanks for that! However, I was adding it correctly into the constraints. I'll update the comments
src/ktopt_planning_context.cpp
Outdated
// Add position constraint to each knot point of the trajectory | ||
for (int i = 0; i < params_.num_orientation_constraint_points; ++i) | ||
{ | ||
trajopt.AddPathPositionConstraint( |
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.
PositionConstraint?
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.
Strangely enough, this is correct...
https://stackoverflow.com/q/79041210
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.
I believe the terminology reflects that it is indeed still a constraint on the generalized positions, which happens to be a vector in the configuration space. Therefore, you are adding a constraint on one coordinate (link end-effector) out of all the available coordinates. At least this is my understanding
src/ktopt_planning_context.cpp
Outdated
// NOTE: There are 3 tolerances given for the orientation constraint in moveit | ||
// message, rake only takes in a single theta bound. For now, we take any | ||
// of the tolerances as the theta bound | ||
const double theta_bound = orientation_constraint.absolute_x_axis_tolerance; |
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.
theta_bound
is not used!?
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.
Yeah, I think theta_bound
and padding
need to be combined in some way in the constructor of OrientationConstraint
below, whereas only padding
is currently used at the moment. That seems incorrect.
Probably just theta_bound - padding
, or theta_bound - 2.0 * padding
depending on how we want to enforce it? (plus some max
to make sure the bound does not go below zero)
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.
Also, since theta_bound
uses the whole angle (per the documentation), does it make sense to do something like take the norm of the X/Y/Z angle tolerances?
This is still not a proper calculation, so I think we anyhow have to be "creative" in how we interpret the tolerances in the MoveIt message vs. what translates to here.
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.
It is but only via the orientation padding parameter in the yaml file.
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.
no, the variable theta_bound
needs to be used in the actual OrientationConstraint
creation.
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.
I agree with #55 (comment) to use the norm or sum of all angle tolerances. MoveIt's orientation constraint is much more flexible than Drake's one, allowing deviations to be specified for all rotation axes separately. It will only translate in a meaningful way if the MoveIt tolerances are all identical.
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.
So for this, a better approach would be to add an additional rotational transformation to R_BbarB
, computing R_BbarBx
, R_BbarBy
and R_BbarBz
- add 3 different orientation constraints for each axis with the theta_bounds being the individual tolerances.
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.
This will not work. Drake's orientation constraint already fully constrains all three axes. Adding more orientation constraints doesn't make sense.
src/ktopt_planning_context.cpp
Outdated
trajopt.AddPathPositionConstraint(std::make_shared<drake::multibody::OrientationConstraint>( | ||
&plant, base_frame, drake::math::RotationMatrixd::Identity(), link_ee_frame, | ||
R_BbarB, padding, &plant_context), |
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.
Having read the documentation, I think link_ee_frame and base_frame need to be exchanged:
trajopt.AddPathPositionConstraint(std::make_shared<drake::multibody::OrientationConstraint>( | |
&plant, base_frame, drake::math::RotationMatrixd::Identity(), link_ee_frame, | |
R_BbarB, padding, &plant_context), | |
trajopt.AddPathPositionConstraint(std::make_shared<drake::multibody::OrientationConstraint>( | |
&plant, link_ee_frame, drake::math::RotationMatrixd::Identity(), base_frame, | |
R_BbarB, theta_bound, &plant_context), |
In MoveIt, the constraint's orientation is an offset given w.r.t. frame_id / base_frame, not w.r.t. link_ee_frame.
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.
Thanks for this @rhaschke. You are absolutely right, I assumed it would be the same as PositionConstraint
. Thanks for pointing this out.
src/ktopt_planning_context.cpp
Outdated
// NOTE: There are 3 tolerances given for the orientation constraint in moveit | ||
// message, rake only takes in a single theta bound. For now, we take any | ||
// of the tolerances as the theta bound | ||
const double theta_bound = orientation_constraint.absolute_x_axis_tolerance; |
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.
I agree with #55 (comment) to use the norm or sum of all angle tolerances. MoveIt's orientation constraint is much more flexible than Drake's one, allowing deviations to be specified for all rotation axes separately. It will only translate in a meaningful way if the MoveIt tolerances are all identical.
Allright, we have the constrained demo working for the box constraint, orientation and the mixed-constraint example. For the equality constraints, either you have to increase the number of points of constraint application - making it difficult for the optimization to succeed, or have only 10 points and the validator fails the motion plan. I have played around with the ideal number, it returns a plan if number of points are 25 60% of the time. I wouldn't know how to make this more deterministic right now. Do test and let me know. |
LGTM, go for it! |
The orientation constraints are working. The padding was a really good catch @sea-bass. Also, for some reason I don't understand completely, not including orientation constraints also passes MoveIt's constraint validation process. It looks like the B-spline representation handles orientation error pretty well, thought that was interesting.
I have tested this on the constrained demo. Can you test it and we can collect some trajectories and visualise them.
Addresses #44