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

Kinematic Trajectory Optimization Skeleton PR #8

Merged
merged 21 commits into from
Jul 10, 2024
Merged

Conversation

kamiradi
Copy link
Member

@kamiradi kamiradi commented Jun 20, 2024

This PR aims to transcribe a basic Kinematic Trajectory Optimization problem from Moveit to Drake

  • Overload the PlannerManager class
  • Overload the PlanningContext class
  • Implement a ktopt_interface class

Implement an example demo to test and integrate the above classes
PS: this is a draft, and the work may be split over a sequence of PRs

kamiradi added 6 commits June 20, 2024 16:56
This commit
* solves the vcs import todo on dockerfile, Dockerfile is self-contained
* compilation of motion plan request to trajectory optimization in
  progress
@sea-bass sea-bass requested review from sea-bass and sjahr June 25, 2024 12:27
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.

Looks good! I made some of the nitpicky comments.

As far as when I think we're at a mergeable state here: Ensure we can not only set up the KinematicTrajectoryOptimization program, but that we can actually solve it. Doesn't need to have any constraints. And then return the outcome as a planning response.

While I waited an eternity for the Docker container to keep building without OOMing my machine, I filled in some more placeholder code. Hope that's okay.

.docker/docker-compose.yaml Outdated Show resolved Hide resolved
include/ktopt_interface/ktopt_planning_context.h Outdated Show resolved Hide resolved
Comment on lines 65 to 66
// compile into a Kinematic Trajectory Optimization problem
auto trajopt = KinematicTrajectoryOptimization(plant_->num_positions(), 10);
Copy link
Contributor

Choose a reason for hiding this comment

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

TODO: Rather than the hard-coded 10, the number of control points should be one of the generate_parameter_library params defined in the YAML... or otherwise in the planner options.

Comment on lines 68 to 70
// bare minimum specification
// get the frame that needs constraints
//
Copy link
Contributor

Choose a reason for hiding this comment

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

Yep, so I think what we'll need is:

Must have:

  1. Constraints on initial and final joint configuration
  2. Joint position/velocity/acceleration limits from the joint limits params
  3. Collision avoidance (minimum distance constraint)

Nice to have:

  1. Getting position and orientation constraints from the MotionPlanningRequest

For both the collision and the position/orientation constraints, we'll also need a hyperparameter for how many samples from s=0 to s=1 we want to use. I would roughly recommend 2-3x the number of control points.

This can all be done in follow-on PRs, BTW

&builder, 0.0);

auto robot_instance = Parser(plant_, scene_graph_).AddModels(robot_description_);
plant_->WeldFrames(plant_->world_frame(), plant_->GetFrameByName("panda_link0"));
Copy link
Contributor

Choose a reason for hiding this comment

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

we'll need to figure out what exactly to weld here, since "panda_link0" is, of course, hard-coded. I'm sure there's a way to just weld the base-most link name of the robot description. That, or we can make it a parameter if needed, but hopefully isn't necessary.

Copy link
Member Author

Choose a reason for hiding this comment

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

creating issue.

@sea-bass
Copy link
Contributor

Made more updates to the Dockerfile. Now I can do:

  • docker compose build
  • docker compose run moveit
  • $ colcon build --packages-select moveit_drake
  • Run the demo

And there are still no moveit apt packages installed. Ever! No need to remove any extra ones either :)

Copy link
Member Author

@kamiradi kamiradi left a comment

Choose a reason for hiding this comment

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

@sea-bass, I see that you have added the relevant bits to report the motion plan response. Were you able to test this on the demo?

@sea-bass
Copy link
Contributor

sea-bass commented Jul 3, 2024

@sea-bass, I see that you have added the relevant bits to report the motion plan response. Were you able to test this on the demo?

I was, but it's far from complete. There are no actual costs/constraints added, and the Drake trajectory needs to be converted to a MoveIt RobotTrajectory ans packed up into the result.

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.

Lots of small comments but in general this looks good! Once they are either addressed in the code or by converting the bigger ones into issues, we should merge this

@@ -0,0 +1 @@
#pragma once
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove until we need it?

using drake::planning::trajectory_optimization::KinematicTrajectoryOptimization;
using drake::solvers::Solve;

class KTOptPlanningContext : public planning_interface::PlanningContext
Copy link
Contributor

Choose a reason for hiding this comment

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

TODO Add documentation

Copy link
Member Author

Choose a reason for hiding this comment

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

You mean add comments around the functions and includes?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes

Copy link
Member Author

Choose a reason for hiding this comment

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

creating issue.

ktopt_interface_plugin_description.xml Outdated Show resolved Hide resolved
package.xml Show resolved Hide resolved
// retrieve goal state
moveit::core::RobotState goal_state(start_state);
constraint_samplers::ConstraintSamplerManager sampler_manager;
auto goal_sampler = sampler_manager.selectSampler(getPlanningScene(), getGroupName(), req.goal_constraints[0]);
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess this will work for now, but maybe this step needs to be dropped and we let ktopt handle the goal constraints directly


// package up the resulting trajectory
auto traj = trajopt.ReconstructTrajectory(result);
const size_t num_pts = 101; // TODO: should be sample time based instead
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess this could be exposed as a ROS parameter to let the use define the trajectory density

Copy link
Member Author

Choose a reason for hiding this comment

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

Completely agreed! That was going to be the next step.


bool KTOptPlanningContext::terminate()
{
return true;
Copy link
Contributor

Choose a reason for hiding this comment

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

Print a warning here that termination is not implemented by this planner

Comment on lines +94 to +105
robot_description_ = robot_description;

// also perform some drake related initialisations here
DiagramBuilder<double> builder;

std::tie(plant_, scene_graph_) = AddMultibodyPlantSceneGraph(&builder, 0.0);

auto robot_instance = Parser(plant_, scene_graph_).AddModels(robot_description_);
plant_->WeldFrames(plant_->world_frame(), plant_->GetFrameByName("panda_link0"));

// for now finalize plant here
plant_->Finalize();
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if this (in a follow-up PR) should be moved into the constructor or even the planner manager

Copy link
Member Author

Choose a reason for hiding this comment

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

Again, I declared this as a function because , there could be use in resetting the robot_description once a planning_context has been set. The alternative is to expose a ros_handler and pass it to the planner_manager. I'll experiment with that in a future pass.


void KTOptPlanningContext::clear()
{
// do something
Copy link
Contributor

Choose a reason for hiding this comment

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

Just print warning that is it not implemented for now 😉

README.md Outdated
### Some helper commands
To just build `moveit_drake`
```
colcon build --packages-select mvoeit_drake
Copy link
Contributor

Choose a reason for hiding this comment

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

Typo: moveit_drake

Copy link
Member Author

@kamiradi kamiradi left a comment

Choose a reason for hiding this comment

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

So I have made a few changes to the repository based on your comments and create a few follow on issues to be tracked with later commits.

CMakeLists.txt Outdated Show resolved Hide resolved
@sjahr
Copy link
Contributor

sjahr commented Jul 3, 2024

@kamiradi Can you ping when you addressed all comments for another review round? You can resolve the conversation you addressed and comment on the ones where you might be unsure/ have questions or commetns

@kamiradi
Copy link
Member Author

kamiradi commented Jul 4, 2024

@sjahr, I remember you pointing me towards a specific yaml file that needs to have a _planning suffix to be loaded by the class loader. Could you point me towards an example? I believe this is needed for the drake planning plugin to be loaded during runtime.

@sjahr
Copy link
Contributor

sjahr commented Jul 4, 2024

@sjahr, I remember you pointing me towards a specific yaml file that needs to have a _planning suffix to be loaded by the class loader. Could you point me towards an example? I believe this is needed for the drake planning plugin to be loaded during runtime.

@kamiradi The file is specified per moveit config, for example in panda_moveit_config for stomp:
https://github.com/moveit/moveit_resources/blob/ros2/panda_moveit_config/config/stomp_planning.yaml

The content is equivalent with the section you've added to the launch file and either the yaml file or the launch file section can be used (although the .yaml file is best practices for fleshed out plugins).

@kamiradi
Copy link
Member Author

kamiradi commented Jul 4, 2024

Ah I see, so this is an alternative to the launch file config mentioned in the launch file. Is there a runtime requirement for the yaml file also to be present? Can I defer this to the next PR?

So the requirement now is to:

  1. Declare a similar ktopt_planning.yaml file (where should I be doing this? should I create a new config folder within the repository?)
  2. And the class loader automagically loads this at runtime.

Copy link
Member Author

@kamiradi kamiradi Jul 4, 2024

Choose a reason for hiding this comment

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

@sea-bass @sjahr help needed with the drake moveit pipeline demo test. Creating a separate issue to track this

Copy link
Contributor

@sea-bass sea-bass Jul 5, 2024

Choose a reason for hiding this comment

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

I found a typo in the XML, that "planning_interface:PlannerManager" needs to have :: instead of a single :. There was also a missing space, though unclear if that does anything.

Fixed in 2ff0c3b -- try with that?

@kamiradi kamiradi mentioned this pull request Jul 4, 2024
@sjahr sjahr marked this pull request as ready for review July 9, 2024 12:35
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.

Approving pending @sjahr's final review.

My only suggestion: Rename the PR title to something like "Kinematic Trajectory Optimization skeleton"

ktopt_moveit_parameters)

# Ensure that the plugin finds libdrake.so at runtime
set_target_properties(
Copy link
Contributor

Choose a reason for hiding this comment

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

@kamiradi @sea-bass I needed to set these properties to avoid a segfault when the plugin was loaded because it couldn't find libdrake at runtime. Let me know what you think

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.

Works for me now 🎉

@sjahr sjahr merged commit 345e52c into moveit:main Jul 10, 2024
1 check passed
@kamiradi kamiradi changed the title Kinematic Trajectory Optimization draft PR Kinematic Trajectory Optimization Skeleton PR Jul 10, 2024
@kamiradi kamiradi deleted the ktopt_new branch July 11, 2024 08:40
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.

3 participants