Pass RobotModel to kinematics plugins#150
Pass RobotModel to kinematics plugins#150jonbinney wants to merge 16 commits intomoveit:kinetic-develfrom
Conversation
…t-model-to-kinematics-plugins
|
Dave's PRs didn't touch it either (because I don't think it existed at the time), but I think the ('recently' added) LMA based plugin would also need to be updated? |
|
This is great! @jrgnicho can hopefully expand upon moveit_kinematic_tests |
| * @param search_discretization The discretization of the search when the solver steps through the redundancy | ||
| * @return True if initialization was successful, false otherwise | ||
| * | ||
| * Note: this is intended to be removed in future ROS versions in favor of robot_model being passed in |
There was a problem hiding this comment.
lets add MOVEIT_DEPRECATED then
There was a problem hiding this comment.
I tried adding MOVEIT_DEPRECATED to both this function and the other version of initialize() that uses the string urdf below. gcc spits out tons of warnings though, complaining about the below deprecated initialize() calling this deprecated initialize. This is on ubuntu 16.04 with gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.2).
There was a problem hiding this comment.
It seems like that shouldn't be the case though - if a deprecated function calls another deprecated function, shouldn't that be OK? Any C++ gurus that know a workaround?
There was a problem hiding this comment.
@baalexander suggested marking the below one as deprecated now, and then later removing it and marking this one as deprecated. That would take longer, but would have the advantage of not spewing warnings.
|
The kinematics_base_test repo was created to ensure that changes to the |
|
@gavanderhoorn I'll take a look at updating the LMA based plugin. That should definitely be included in this PR. |
…t-model-to-kinematics-plugins
…t-model-to-kinematics-plugins
Only works for the KDL kinematics plugin so far.
|
I've made some progress on this PR but still have some more work to do before it is ready to be reviewed again. The biggest problem remaining is that there is definitely a loop of shared pointers that keeps the RobotModel from ever being destroyed. The problem is:
So the loop is Any suggestions on how to fix this? It seems like one of these shared pointers needs to change to a weak pointer, but I'm not sure which. |
With the current design, I suppose |
|
The reason @v4hn gives to motivate the @jonbinney, there are many other cycles, e.g. I think, the best way to break the loop in the above case, is to pass a new |
ok, I didn't read through the dependencies in the recent past, so feel free to ignore my statement. 👶 |
|
ping @jonbinney any chance we could finish up this PR? |
|
Ah yes, sorry! This fell off my radar. I'll start working on it again. |
|
Having fun merging these changes with all the clang-format changes.... |
|
I haven't had any time to work on this for a while, and unfortunately I'm going to be very busy for the next few months as well. I'm going to close this for now. When/if I have time in the future I'll re-open it (or if anyone else has some time they're welcome to take it over). The changes in this PR are good, but time will need to be put in to make sure that they don't break existing behavior, since it affects a lot of code. Things that need to be resolved:
|
|
I'd suggest to keep this open -- closed issue & PRs are harder to be found. |
|
I agree with @130s, there's no need to close the request. I'll reopen this request. @jonbinney if you don't want to have the open request on your name around or don't want to keep the branch on your repository I can transition the commits to my fork. But I don't have the time to work on this either. |
|
Makes sense - I'm fine with keeping it open. |
|
@v4hn you mentioned on Sunday that this PR has been discussed at ROScon, could you summarize the results? I'll try to look into this soonish and would like to be up to date beforehand I might just take the changes here as an inspiration and do a new PR without any rebasing etc. My git skills are weak. Would that offend anyone? |
|
@simonschmeisser thanks for taking this on! Yes, feel free to start fresh - no need to preserve the history here. One thought - it would be good to have a shim set of functions that keep the current interface, construct the robot model from the URDF, and then call the new functions. We can mark them as deprecated so people have some warning and their custom IK plugins don't just stop working. |
|
@v4hn [...], could you summarize the results?
There were no results, everyone agreed that this needs to be tackled.
It would be wonderful if you could look into this!
I fully agree with @jonbinney.
|
|
Just had a discussion with @v4hn about this at IPA at WorldMoveItDay: It seems the best way to cut the shared_ptr dependency loop is to change the I have a slight fear that I will not finish that within World MoveIt! Day (any time zone) but I will start a PR testing that implementation. |
Can you please elaborate on this conclusion? I tend to agree, but it would be nice to understand (and document) your motivation as well ;-) |
|
Please also get rid of |
|
Sure, sorry for not giving more details. Your ( @rhaschke ) suggestion was to create a special std::shared_ptr<RobotModel, doNotDeleteMe>(robotModel.get()) and pass that to RobotState instances in the IK plugins. While this (probably) works, there would no direct way to stop people from using the "normal" RobotModel shared ptr and create that loop. We had some ideas for hacks/factory patterns etc but ... On the other hand all kinematic plugin instances are stored in KinematicsPluginLoader/RobotModelLoader as shared_ptr already. So we can use weak_ptrs elsewhere, especially in JointModelGroup Making the RobotModel pointer of RobotState weak would also have been possible but too invasive re const, yes, thought that as well |
I don't understand what you mean by "normal" here. I looked into this issue again for last hour and found the following: The RobotModelLoader (RML) owns its RobotModel (RM) as well as its KinematicsPluginLoader (KPL). Usually those caches are the proper choice for weak ptrs: As long as the pointer is still actively in use (outside the cache), the cached pointer can be reused. If all active instances are gone, the cache instance should be freed as well. However, in the present case, the cache only maintains unique instances - they are not shared. The only purpose of this logic is to not allocate KS twice in a row - once for validating that it is suitable for JMG here and once for actual use here. The important fact is, that not the KPL owns those instances, but the JMGs! Hence, the JMGs should store the shared_ptr. By clearing KPL's cache (and only the cache!) before RM in RML's destructor this can be handled. A better solution is to std::move the cached shared_ptr for return, but keeping the cache entry (which then has Regardless of this, the loop isn't broken, because the RM and thus JMG is not destroyed in first place, when the RML is unloaded. Thus, we need to ensure that the RML, in its destructor, actually triggers the destructor pipeline RM => JMG => KS. Hence, the only chance to break the loop is from KS back to RM. As far as I see, the old code doesn't provide an interface to directly pass a RobotModelPtr to KS. @simonschmeisser Sorry for the late reply. But it took me a while to understand all this. I suggest, I propose a solution along this line? (I still have all files open...) |
|
I committed a solution to a similar issue in |
|
Please see my comments on #1153 and consider reopening it |
Instead of just passing in the URDF as a string. This is based on the discussion in moveit/moveit_ros#731 and is just a rebasing of @davetcoleman's PRs moveit/moveit_core#216 and moveit/moveit_ros#541
There are two main motivations for this:
This doesn't actually fix (2) yet. This PR is the first step - it modifies the KinematicsBase API to pass the RobotModel to the kinematics plugins. A future PR will need to then use the values from the RobotModel instead of the URDF in each separate kinematics plugin.
I've rebased the original PRs and fixed the compile problems, but now I'm not sure how to test this. Ideally, there would be unit/integration tests that would load various plugins (in this case the KDL and SRV kinematics plugins) and make sure that they return valid answers for various kinematic and inverse kinematic queries for various robot arms. I was hoping that moveit/moveit_kinematics_tests#4 contained such tests, but it looks like it isn't (yet?) used for that purpose.
So my question is - how do people test things like this to make sure it works for various robots?