Skip to content

[WIP] Pass RobotModel to ik plugins#1153

Closed
simonschmeisser wants to merge 3 commits intomoveit:kinetic-develfrom
isys-vision:pass_robot_model_to_ik
Closed

[WIP] Pass RobotModel to ik plugins#1153
simonschmeisser wants to merge 3 commits intomoveit:kinetic-develfrom
isys-vision:pass_robot_model_to_ik

Conversation

@simonschmeisser
Copy link
Copy Markdown
Contributor

This is a proof of concept for further discussion of a way to pass RobotModel(Ptr) to kinematics plugins. It is inspired by #150 and the recent and not so recent discussion therein

The main objective of this (and previous PRs (and previous 4y old PRs)) is to

  1. save some parsing and loading time by reusing the RobotModel
  2. use consistent joint limits in all parts of the code

Passing in std::shared_ptr<RobotModel> (aka RobotModelPtr) to kinematics::KinematicsBase derived plugins and storing it there or in a member variable RobotState will however create a cyclic shared pointer loop as
RobotModel -> JointModelGroup -> KinematicsSolver/KinematicsBase (plugin) -> RobotModel

This was discussed at length yesterday at #150 (comment) and following

The solution sketched here is to turn the shared pointer from JointModelGroup -> KinematicsSolver into a weak pointer and have them owned by RobotModelLoader in its KinematicPluginLoader. KinematicPluginLoader already has the KinematicSolvers in a cache so changes there would only be needed for clarity. We could also move/copy the KinematicSolvers to a more explicit "storage" directly in RobotModelLoader (or elsewhere outside of RobotModel)

Further points open for discussion:
This PR adds a member variable of type RobotModelPtr to kinematics::KinematicsBase for simple access. This breaks ABI. (but not API!) Still it means that e.g. ikFast plugins from ros-I packages need to be recompiled to be able to be loaded. This could be avoided by having a virtual setRobotModel(RobotModelPtr) be called right after the constructor and not storing the pointer in KinematicsBase. Plugins could then override this function to store the pointer themselves, thus preserving ABI as well.

This PR is made against kinetic-devel, mostly for convenience. Since it can change behavior it should probably only (eventually) be applied against melodic. I'm sure this can be handled by git ninjas

If during the discussion slight hints of approval emerge, I would port further plugins as well during this slightly extended World MoveIt! Week. They will continue working as is however for the time being.

@rhaschke
Copy link
Copy Markdown
Contributor

The solution sketched here is to turn the shared pointer from JointModelGroup -> KinematicsSolver into a weak pointer and have them owned by RobotModelLoader in its KinematicPluginLoader. KinematicPluginLoader already has the KinematicSolvers in a cache so changes there would only be needed for clarity.

Did you read #150 (comment)?
There, I stated that using a weak_ptr in JMG will not solve the issue. The JMG is not destructed in first place, because there is a circular shared_ptr on RM. Hence the RM is not destructed and for this reason neither the JMG.

This PR adds a member variable of type RobotModelPtr to kinematics::KinematicsBase for simple access. This breaks ABI. This could be avoided by having a virtual setRobotModel(RobotModelPtr).

Adding a virtual method breaks ABI as well.

This PR is made against kinetic-devel, mostly for convenience.
I will prepare an alternative approach targeted on Melodic

@rhaschke rhaschke closed this Oct 27, 2018
@simonschmeisser
Copy link
Copy Markdown
Contributor Author

@rhaschke Could we go back to closing PRs once discussion is finished?

@simonschmeisser
Copy link
Copy Markdown
Contributor Author

With this PR ownership of KinematicSolvers (ik plugins) is transfered to RobotModelLoader. So once RobotModelLoader gets released it will release the KinematicsSolvers as well as their use count is now 0. RobotModel only has a weak pointer on the KinematicSolvers which does not increase the use counter. So step 1 is done, ik plugin unloaded/released.

Now during the release of the IK plugin it releases all it's shared pointers to RobotModel (as well as all RobotStates that have shared pointers to RobotModel). If nobody else (outside the kinematics code) owns further shared_pointers of RobotModel it's use count now reaches zero as well and it gets released.

This PR demonstrates a way to achieve the goal of having a shared RobotModel available in plugins and does not add new shared pointer loops. That those exist elsewhere is an unrelated problem.

@rhaschke
Copy link
Copy Markdown
Contributor

Could we go back to closing PRs once discussion is finished?

Sorry, I didn't want to offend you. For me it was so obvious that this approach is wrong.

With this PR ownership of KinematicSolvers is transfered to RobotModelLoader. So once RobotModelLoader gets released it will release the KinematicsSolvers [and their RobotModels].

Thanks for clarifying your approach. I agree that this will work. However, I disagree to transferring ownership of KinematicSolvers from JMG to RobotModelLoader.
Theoretically, JMGs can exist without a RobotModelLoader at all. While JMGs are part of moveit_core, RobotModelLoader is only introduced in moveit_ros as a convenience function. For this reason I didn't consider your approach as an option (and still do not).

@rhaschke rhaschke reopened this Oct 27, 2018
Copy link
Copy Markdown
Contributor

@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.

IMHO this is a HACK, misusing RobotModelLoader as the storage place for IK solver instances, while they are actually owned by the RobotModel / JMG.

@rhaschke
Copy link
Copy Markdown
Contributor

@simonschmeisser I filed #1166 as an alternative approach. Please have a look.

@rhaschke
Copy link
Copy Markdown
Contributor

Closing in favour of merged #1166.

@rhaschke rhaschke closed this Nov 22, 2018
@simonschmeisser simonschmeisser deleted the pass_robot_model_to_ik branch November 22, 2018 09:41
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