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

Adds orientation constraints #55

Merged
merged 7 commits into from
Oct 15, 2024
Merged

Conversation

kamiradi
Copy link
Member

@kamiradi kamiradi commented Oct 14, 2024

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

@kamiradi kamiradi requested review from sjahr and sea-bass and removed request for sjahr October 14, 2024 10:59
@kamiradi kamiradi marked this pull request as ready for review October 14, 2024 11:07
Copy link
Contributor

@sea-bass sea-bass left a 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);*/
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove?

Copy link
Contributor

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

Copy link
Contributor

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;*/
Copy link
Contributor

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

Copy link
Contributor

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 Show resolved Hide resolved
src/ktopt_planning_context.cpp Outdated Show resolved Hide resolved
src/ktopt_planning_context.cpp Outdated Show resolved Hide resolved
// 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
Copy link
Contributor

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?

Copy link
Member Author

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.

Copy link
Contributor

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?

Copy link
Member Author

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.

Copy link
Contributor

@sjahr sjahr left a 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);*/
Copy link
Contributor

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;*/
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here

Copy link

@rhaschke rhaschke left a 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

Comment on lines 270 to 271
// Frame A: The frame in which the orientation constraint is defined
// Frame B: The frame to which the orientation constraint is enforced

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.

Copy link
Member Author

@kamiradi kamiradi Oct 15, 2024

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

// Add position constraint to each knot point of the trajectory
for (int i = 0; i < params_.num_orientation_constraint_points; ++i)
{
trajopt.AddPathPositionConstraint(

Choose a reason for hiding this comment

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

PositionConstraint?

Copy link
Contributor

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

Copy link
Member Author

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

// 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;

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!?

Copy link
Contributor

@sea-bass sea-bass Oct 15, 2024

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)

Copy link
Contributor

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.

Copy link
Member Author

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.

Copy link
Contributor

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.

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.

Copy link
Member Author

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.

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.

@sea-bass
Copy link
Contributor

@kamiradi I resolved the conflicts with #57 -- all yours again!

Comment on lines 324 to 326
trajopt.AddPathPositionConstraint(std::make_shared<drake::multibody::OrientationConstraint>(
&plant, base_frame, drake::math::RotationMatrixd::Identity(), link_ee_frame,
R_BbarB, padding, &plant_context),

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:

Suggested change
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.

Copy link
Member Author

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.

// 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;

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.

@kamiradi
Copy link
Member Author

kamiradi commented Oct 15, 2024

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.

@sea-bass
Copy link
Contributor

LGTM, go for it!

@kamiradi kamiradi merged commit 154e32b into moveit:main Oct 15, 2024
2 checks passed
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.

4 participants