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

Planning scene transcription #23

Merged
merged 30 commits into from
Aug 4, 2024
Merged

Planning scene transcription #23

merged 30 commits into from
Aug 4, 2024

Conversation

kamiradi
Copy link
Member

@kamiradi kamiradi commented Jul 23, 2024

This PR works on transcribing a Moveit planning scene to Drake's scene graph.

Edit: @sea-bass @sjahr This PR is out of the draft stage. It accomplishes the following

  • Set's up a dummy box in the planning scene. This is reflected in the motion planning request.
  • Transcribes a list of collision objects inside the Planning Scene into the drake Scene Graph. For now, I manually insert the box. I plan to exhaustively setup an object transcription in upcoming PR.
  • Adds a MinimumDistanceLowerBoundConstraint to the optimization problem. This does the necessary collision checking.
  • Solves for a collision free trajectory, uses that to warm-start a collision-checked trajectory in the optimization.
  • Visualizes everything on RVIZ.

Open for reviews

kamiradi and others added 22 commits July 11, 2024 10:03
demo file had to be changed to utilise the loaded drake pipeline and the
KTOpt plugin
For some reaosn demo cmake is not being configured.
Adds an error message if the robot description in the planner manager
has not yet been set. Will not proceed to service any motion planning
request until robot description has been set.
This commit wants tests if the initialized subscriber's callback is
executed to set the robot description.
For now, loading urdf from drake models rather than ros subcription
This remains untested, build complete
This commit tested a complete motion plan request from the planning
pipeline benchmark. It visualises resulting plan on RViZ
This commit made a few changes based on the comments fomr reviews.
Additionally joint velocties are also set in the robot state.
@kamiradi
Copy link
Member Author

kamiradi commented Jul 29, 2024

Hi @sea-bass @sjahr, following is an update

I have transcribed a basic planning scene with a box somewhere within the vicinity of the robot, big enough that it matters, small enough that it can find a solution. I have a basic transcription (PlanningScene to SceneGraph) up on the latest commit. sanity check: KTOPT plans and cube is visualised in meshcat.

However, I am unable to test it as it keeps running into a segmentation fault. The current hypothesis is that the planning scene doesn't yet have all the information to iterate through at the time the MutlibodyPlant and SceneGraph are created (setRobotDescription). This is happening when the planner manager is asked for a planning context.

Any suggestions on debugging?

On a broader note, I know @sea-bass is in favor of writing tests for each part of the code. I have postponed this up until I have a basic (box-test) planning scene transcription. If I had to start setting these up, could you also point me towards resources.

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.

See my comment about trying to not rely on raw pointers to see about the segfault.

As for testing references, you could maybe borrow from here?
https://github.com/moveit/moveit2/blob/main/moveit_core/planning_scene/test/test_planning_scene.cpp

Comment on lines 85 to 90
SceneGraph<double>* scene_graph_{};
MultibodyPlant<double>* plant_{};
std::unique_ptr<Diagram<double>> diagram_;
std::unique_ptr<Context<double>> diagram_context_;
Context<double>* plant_context_{};
Context<double>* visualizer_context_{};
Copy link
Contributor

@sea-bass sea-bass Jul 29, 2024

Choose a reason for hiding this comment

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

my first suspicion as to why you're getting segfaults is that storing these raw pointers as member variables is actually very memory unsafe and likely something went out of scope.

I think you should actually try removing scene_graph_, plant_, plant_context_, and visualizer_context_ from the member variables -- we recently ran into this at work.

The correct usage is to leverage the diagram_ smart pointer you have to do extractions like these in the function scopes that require them:

  const auto& plant =
      dynamic_cast<const drake::multibody::MultibodyPlant<double>&>(diagram_->GetSubsystemByName("plant"));
  auto& plant_context = diagram_->GetMutableSubsystemContext(plant, diagram_context_.get());

(and there's probably a similar usage for retrieving the scene graph)

I know it seems like a lot, but I think this is how Drake is intended to be used based on our tireless comb through the source code in lieu of there being very little examples to borrow from.

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, I did see them use this in their examples initially, but I went for whatever was compiling. I'll refactor accordingly and test.

@sea-bass sea-bass marked this pull request as ready for review August 1, 2024 03:01
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.

I mostly just found cleanup stuff -- this is looking great!

Question: Why doesn't the gripper show up in Meshcat? Does that come from a separate URDF?

image

demo/src/pipeline_testbench_main.cpp Show resolved Hide resolved
include/ktopt_interface/ktopt_planning_context.hpp 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
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
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
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.

Still need to test it but here are some small clean-up comments you should address before we merge it 😃

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

sjahr commented Aug 1, 2024

Oh an it looks like you need to rebase on main

@scastro-bdai
Copy link

scastro-bdai commented Aug 1, 2024

Oh an it looks like you need to rebase on main

Actually, I meant to bring this up.

@kamiradi I think you might be making things difficult for yourself by continuing to use the same dev branch to put up all your PRs. If you simply make feature branches off the moveit_drake main repo each time, I think you won't need to do this on every PR unless someone else is introducing conflicts.

EDIT: Another day, another using the wrong account 😅

@kamiradi
Copy link
Member Author

kamiradi commented Aug 2, 2024

Yeah, I was about to ask general best practices on git and open source, because I may not be using the tool like I am supposed to. I'll bring it up in our next meeting.

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.

Just run pre-commit and we can go ahead and merge this!

@kamiradi
Copy link
Member Author

kamiradi commented Aug 3, 2024

@sea-bass @sjahr. Any idea how I can run the pre-commit script inside the docker container. When I run it inside the container, since it is a submodule it raises a "not a git repository error". I tried running it locally on my machine, but that means I run it with clang-format-12 (I believe 14 is required), and does not autoformat the code. I don't have the option of upgrading it as it may lead to other dependencies being upgraded which may break other projects.

Any workarounds?

@sea-bass
Copy link
Contributor

sea-bass commented Aug 3, 2024

@sea-bass @sjahr. Any idea how I can run the pre-commit script inside the docker container. When I run it inside the container, since it is a submodule it raises a "not a git repository error". I tried running it locally on my machine, but that means I run it with clang-format-12 (I believe 14 is required), and does not autoformat the code. I don't have the option of upgrading it as it may lead to other dependencies being upgraded which may break other projects.

Any workarounds?

Is the .git folder, or the pre-commit-config.yaml file ignored in the dockerignore file and not mounted into the container? Or otherwise just not mounted as a volume? That would be a thing to check right away.

Else, I can look into this. In the meantime, just change the clang-format version in your precommit file!

@sea-bass
Copy link
Contributor

sea-bass commented Aug 3, 2024

Seems like it is... dumb question, are you running this from the workspace root, or from the src/moveit_drake folder? (Should be the latter)

@kamiradi
Copy link
Member Author

kamiradi commented Aug 3, 2024

I think I know what is happening, I am currently working with moveit_drake as a gitsubmodule as part of another moveit_drake_contrib package I created at the start of the project. Which is why it does not have a .git folder but a placeholder file within docker. I'll reclone the repository and it should work within docker.

@kamiradi
Copy link
Member Author

kamiradi commented Aug 3, 2024

Nope that wasnt the issue, I still get "not a git directory" from within docker

@sea-bass
Copy link
Contributor

sea-bass commented Aug 3, 2024

Nope that wasnt the issue, I still get "not a git directory" from within docker

I just tried it out by building the regular Docker container. I had to do the following:

docker compose run base moveit

Then, in the container:

# Can be added to the Dockerfile
pip3 install pre-commit
sudo apt install clang-format-14

# Can be added to the entrypoint
git config --global --add safe.directory src/moveit_drake/ 

cd src/moveit_drake
pre-commit run -a

@sea-bass sea-bass merged commit 204092d into moveit:main Aug 4, 2024
2 checks passed
@kamiradi kamiradi deleted the dev branch August 6, 2024 07:24
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