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

Set position constraints via Moveit's PositionConstraint message #51

Merged
merged 7 commits into from
Oct 8, 2024

Conversation

kamiradi
Copy link
Member

@kamiradi kamiradi commented Oct 5, 2024

This PR setsup a MoveIt PositionConstraint transcription. It achieves the following

  • Reads Constraints in the MotionPlanningRequest
  • retrieves PostionConstraint based box constraint
  • Transcribes a drake Bounding Box constraint based on dimensions and pose of the box constraint.

@kamiradi kamiradi marked this pull request as ready for review October 7, 2024 10:50
@kamiradi kamiradi requested review from sea-bass and sjahr and removed request for sea-bass October 7, 2024 10:50
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.

Awesome to see! Few things I think should change in this one before we merge it.

As another optional recommendation, especially as we also seek to add orientation constraints, it might be helpful to factor out the addition of constraints to a separate function within this file.

@@ -23,6 +23,7 @@ find_package(pluginlib REQUIRED)
find_package(rclcpp REQUIRED)
find_package(rviz_visual_tools REQUIRED)
find_package(warehouse_ros REQUIRED)
find_package(shape_msgs REQUIRED)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: in this whole file, can you add shape_msgs in alphabetical order?

@@ -4,6 +4,11 @@ ktopt_interface:
description: "Robot description to be loaded by the internal Drake MultibodyPlant",
default_value: "package://drake_models/franka_description/urdf/panda_arm_hand.urdf",
}
link_ee: {
type: string,
description: "Name of the end-effector frame as per urdf/sdf",
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
description: "Name of the end-effector frame as per urdf/sdf",
description: "Name of the end-effector frame as per urdf/srdf",

@@ -4,6 +4,11 @@ ktopt_interface:
description: "Robot description to be loaded by the internal Drake MultibodyPlant",
default_value: "package://drake_models/franka_description/urdf/panda_arm_hand.urdf",
}
link_ee: {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need this parameter? The constraint message itself contains a link name field and we should likely use that:

https://github.com/moveit/moveit_msgs/blob/ros2/msg/PositionConstraint.msg#L5-L6

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 put this because I did not see a panda_EE frame on the visualised robot_description on RViz. Whereas the Drake urdf has it, and the PositionConstraint requires this. I'll debug this further.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmmm, weird. Can you use another frame that does exist in both URDFs?

Or maybe this is sufficient to have us make a local version of the Drake URDF? Worth discussing in 30 min.

Copy link
Contributor

Choose a reason for hiding this comment

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

Per discussion, let's just use the link_name field in the constraint message and "trust" that the planner has a URDF that knows about this frame (or errors if one is not found).

Copy link
Member Author

Choose a reason for hiding this comment

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

Latest commit reflects this.

// constraint_region.primitives Assuming it is a box
// (shape_msgs::SolidPrimitive::BOX) and has dimensions in [x, y, z]
const auto& primitive = position_constraint.constraint_region.primitives[0];
if (primitive.type == shape_msgs::msg::SolidPrimitive::BOX)
Copy link
Contributor

Choose a reason for hiding this comment

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

Would prefer the reverse: If the primitive is not a box, raise a warning and continue the loop; else, carry on.

This, in addition to being more readable, will save you an indent level.

Comment on lines 208 to 213
for (int i = 0; i < 10; ++i)
{
trajopt.AddPathPositionConstraint(
std::make_shared<PositionConstraint>(&plant, plant.world_frame(), lower_bound, upper_bound, link_ee_frame,
Eigen::Vector3d(0.0, 0.1, 0.0), &plant_context),
static_cast<double>(i) / 10.0);
Copy link
Contributor

Choose a reason for hiding this comment

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

The 10 here should not be hard-coded; it should be a parameter. See e.g. how the collision constraints are setup with num_collision_check_points:

https://github.com/moveit/moveit_drake/blob/main/res/ktopt_moveit_parameters.yaml#L31

{
trajopt.AddPathPositionConstraint(
std::make_shared<PositionConstraint>(&plant, plant.world_frame(), lower_bound, upper_bound, link_ee_frame,
Eigen::Vector3d(0.0, 0.1, 0.0), &plant_context),
Copy link
Contributor

Choose a reason for hiding this comment

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

Where does this Eigen::Vector(0.0, 0.1, 0.0) come from for the p_BQ argument?

Based on this description:

"Constrains the position of a point Q, rigidly attached to a frame B, to be within a bounding box measured and expressed in frame A."

It then seems like we should probably use all zeros for the translation if the point we're constraining is exactly the target 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.

Oops, good catch, I copied the argument list from one of my personal examples. You are right, i'll change this.

@kamiradi kamiradi requested a review from sea-bass October 8, 2024 11:28
moveit_core
moveit_msgs
EIGEN3
shape_msgs)
Copy link
Contributor

Choose a reason for hiding this comment

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

Here too re: alphabetical order

@@ -4,6 +4,11 @@ ktopt_interface:
description: "Robot description to be loaded by the internal Drake MultibodyPlant",
default_value: "package://drake_models/franka_description/urdf/panda_arm_hand.urdf",
}
link_ee: {
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmmm, weird. Can you use another frame that does exist in both URDFs?

Or maybe this is sufficient to have us make a local version of the Drake URDF? Worth discussing in 30 min.

const auto& primitive = position_constraint.constraint_region.primitives[0];
if (primitive.type != shape_msgs::msg::SolidPrimitive::BOX)
{
continue;
Copy link
Contributor

Choose a reason for hiding this comment

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

Worth a warning here? E.g.

"Geometric primitive must be a box. Cannot add position constraint."

Eigen::Vector3d upper_bound = box_center + Eigen::Vector3d(x_dim, y_dim, z_dim);

// Add position constraint to each knot point of the trajectory
for (int i = 0; i < 10; ++i)
Copy link
Contributor

Choose a reason for hiding this comment

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

Use the parameter here as well

Comment on lines +306 to +307
// auto robot_instance = Parser(plant_,
// scene_graph_).AddModelsFromString(robot_description_, ".urdf");
Copy link
Contributor

Choose a reason for hiding this comment

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

weird line break, is this from an autoformatter?

Copy link
Member Author

Choose a reason for hiding this comment

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

yup. Ill change it

@kamiradi kamiradi requested a review from sea-bass October 8, 2024 13:58
@kamiradi kamiradi merged commit 11e3e4e into moveit:main Oct 8, 2024
2 checks passed
@kamiradi kamiradi deleted the pr-position_constraint branch October 8, 2024 17:01
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.

2 participants