Skip to content

Update links in union constraint sampler and fix unit test. - #186

Merged
v4hn merged 4 commits into
moveit:kinetic-develfrom
scottpaulin:fix_robot_state_assertion
Sep 13, 2016
Merged

v4hn merged 4 commits into
moveit:kinetic-develfrom
scottpaulin:fix_robot_state_assertion

Conversation

@scottpaulin

Copy link
Copy Markdown
Contributor

This fixes the failing assertion in the unit tests. It fixes a bug where constrained samplers were being passed robot states with dirty link transforms. This is an issue when IKConstraintSamplers are used because they read the frame transforms to get the pose of the end-effector.


for (std::size_t i = 1 ; i < samplers_.size() ; ++i)
{
//ConstraintSampler::sample returns states with dirty link transforms (because it only writes values)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

should be indent of 2, not 4

@davetcoleman

Copy link
Copy Markdown
Member

This makes sense to me at a high level, but i do not have time to look into the surrounding code

@v4hn

v4hn commented Aug 28, 2016 •

Copy link
Copy Markdown
Contributor

Hey @scottpaulin,

that sounds like a pain to debug. Thanks for doing that! :)

+1 after cleaning up the tabs.
Should be cherry-picked to indigo/jade

{
EXPECT_TRUE(ucs.sample(ks, ks_const, 100));
ks.update();
ks.updateLinkTransforms(); //Returned samples have dirty link transforms.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

There's still a tab here :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Just fixed :)

@scottpaulin

Copy link
Copy Markdown
Contributor Author

Fixed the indenting, no idea how I missed that prior to PR.

On reflection it seems like a waste to call updateLinkTransforms for every type of sampler when only some types of samplers require it. It also looks like a lot of effort has gone into writing RobotState and the surrounding code in a way that minimizes the number of link updates that are performed, suggesting it can be a pretty expensive method.

The link transforms cannot be updated in IKConstraintSampler::sample since the RobotState argument is const. Instead of updating the link transforms before calling every type of sampler, could we add a flag to the samplers that shows whether or not the input robot state needs to have updated link transforms?

e.g. instead of:

for (std::size_t i = 1 ; i < samplers_.size() ; ++i)
 {
     // ConstraintSampler::sample returns states with dirty link transforms (because it only writes values)
     // but requires a state with clean link transforms as input. This means that we need to clean the link 
     // transforms between calls to ConstraintSampler::sample.
     state.updateLinkTransforms();
     if (!samplers_[i]->sample(state, state, max_attempts))
        return false;
 }

Could we do something like this?

for (std::size_t i = 1 ; i < samplers_.size() ; ++i)
 {
     // ConstraintSampler::sample returns states with dirty link transforms (because it only writes values)
     // but some types of samplers require a state with clean link transforms as input. This means that we may need to clean the link 
     // transforms between calls to sample.
     if (samplers[i]->needsUpdatedLinkTransformsToSample())
       state.updateLinkTransforms();
     if (!samplers_[i]->sample(state, state, max_attempts))
       return false;
 }

@v4hn

v4hn commented Aug 30, 2016

Copy link
Copy Markdown
Contributor

Could we do something like this?

-1 This would not be portable to indigo without breakage. Your current patch works fine.
Did you do experiments to compare the run-time in a setup? I assume the time saving is marginal.

@v4hn

v4hn commented Aug 31, 2016

Copy link
Copy Markdown
Contributor

Oh, as my previous message starts with "-1", I want to stress, that I +1 this patch as is.
Everyone, feel free to review.

@davetcoleman

Copy link
Copy Markdown
Member

I'm very curious to see benchmark results, as suggested, for this added update call.

@v4hn

v4hn commented Sep 8, 2016

Copy link
Copy Markdown
Contributor

On Wed, Sep 07, 2016 at 04:26:55PM -0700, Dave Coleman wrote:

I'm very curious to see benchmark results, as suggested, for this added update call.

At the moment this is broken, so I would propose to fix the bug first of all.
Imo, if we want to improve runtime again, anyone can propose changes for that afterward.

@scottpaulin

Copy link
Copy Markdown
Contributor Author

I wrapped some timing around calls to sample in TEST_F(LoadPlanningModelsPr2, UnionConstraintSampler) inside test_constraint_samplers.cpp:

From line 581:

boost::timer t;
for (int t = 0 ; t < 10000; ++t)
{
    ks.setToRandomPositions();
    ks.update();
    EXPECT_TRUE(ucs.sample(ks, ks_const, 100));
}
std::cout << "Time for constrained sampling: " << t.elapsed() << std::endl;

Times:
With extra call to updateLinkTransforms (i.e. this patch): 1.15s
Without extra call to updateLinkTransforms: 2.01s

Tested a few times and these numbers are relatively stable. I don't know enough about the sampling code to know whether the tests are valid (e.g. are not just using some cached values or something). If they are valid this patch somehow speeds up the constrained sampling. I am a bit skeptical about these results since I am not sure how updating link transforms could speed up sampling.

@v4hn

v4hn commented Sep 8, 2016

Copy link
Copy Markdown
Contributor

On Thu, Sep 08, 2016 at 03:14:19AM -0700, Scott Paulin wrote:

Times:
With extra call to updateLinkTransforms (i.e. this patch): 1.15s
Without extra call to updateLinkTransforms: 2.01s

If they are valid this patch somehow speeds up the constrained sampling.

LOL. If anything, that supports my point. ;)

Did you run separate trials with and without the patch?

@scottpaulin

Copy link
Copy Markdown
Contributor Author

Yip! They were separate trials, 1.15 seconds was with the patch and 2.01 was without.

LOL. If anything, that supports my point. ;)

Haha yip! Lucky you suggested the test. Is there anything blocking this from being merged now?

@davetcoleman

Copy link
Copy Markdown
Member

+1

@v4hn
v4hn merged commit 0119d58 into moveit:kinetic-devel Sep 13, 2016
v4hn pushed a commit that referenced this pull request Sep 13, 2016
Update links in union constraint sampler and fix unit test.
v4hn pushed a commit that referenced this pull request Sep 13, 2016
Update links in union constraint sampler and fix unit test.
@v4hn

v4hn commented Sep 13, 2016

Copy link
Copy Markdown
Contributor

merged and cherry-picked to indigo/jade.

Thanks again @scottpaulin !

@scottpaulin
scottpaulin deleted the fix_robot_state_assertion branch September 15, 2016 06:23
v4hn added a commit to v4hn/moveit that referenced this pull request Dec 20, 2016
This extends moveit#186 (0119d58).

Scott Paulin found that the UnionConstraintSampler should explicitly
update the LinkTransforms of the returned samples, because one of the
other samplers could require them to be valid.

Back then, we missed that the sampler also provides a `project` method
that has the same limitation. So I update the transforms there too.
davetcoleman pushed a commit that referenced this pull request Dec 24, 2016
This extends #186 (0119d58).

Scott Paulin found that the UnionConstraintSampler should explicitly
update the LinkTransforms of the returned samples, because one of the
other samplers could require them to be valid.

Back then, we missed that the sampler also provides a `project` method
that has the same limitation. So I update the transforms there too.
davetcoleman pushed a commit that referenced this pull request Dec 24, 2016
This extends #186 (0119d58).

Scott Paulin found that the UnionConstraintSampler should explicitly
update the LinkTransforms of the returned samples, because one of the
other samplers could require them to be valid.

Back then, we missed that the sampler also provides a `project` method
that has the same limitation. So I update the transforms there too.
davetcoleman pushed a commit that referenced this pull request Dec 24, 2016
This extends #186 (0119d58).

Scott Paulin found that the UnionConstraintSampler should explicitly
update the LinkTransforms of the returned samples, because one of the
other samplers could require them to be valid.

Back then, we missed that the sampler also provides a `project` method
that has the same limitation. So I update the transforms there too.
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