-
Notifications
You must be signed in to change notification settings - Fork 129
Add live ik solutions to cbirrt #5385
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
Open
dgottlieb
wants to merge
28
commits into
viamrobotics:main
Choose a base branch
from
dgottlieb:live-ik-solutions-to-cbirrt
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
8cf9c77
Feed live IK solutions to cbirrt. Add request file that does not prod…
dgottlieb 57f0a96
Clean up rudimentary working algorithm.
dgottlieb cfb4b52
revert noisy debugging
dgottlieb 073b392
fix log line
dgottlieb cfe0bd5
merge in main
dgottlieb 3197835
update scene with Inputs API change
dgottlieb 0ea3e16
Merge remote-tracking branch 'origin/main' into live-ik-solutions-to-…
dgottlieb 6f3579b
delete scene that is no longer relevant
dgottlieb 111bba2
remove node names
dgottlieb 48c50ef
lint
dgottlieb 4ff7b6f
Revert "remove node names"
dgottlieb dedf5c2
merge in main
dgottlieb b9c464c
to match default performance, change plan max IK solutions to 10
dgottlieb aa739b8
More efficient waiting
dgottlieb 80cd13f
further optimize IK cleanup waiting. batch at the end of plan manager…
dgottlieb 4b22174
lint
dgottlieb 49aa7f6
move debug output execution such that it waits for dependent input to…
dgottlieb 55074ae
lint
dgottlieb 1374f4b
lint
dgottlieb 2f1937c
check channel close
dgottlieb 1248e93
I was wrong, needed a copy
dgottlieb f48a693
move to safe spot
dgottlieb 5e3793c
actually have "not mine" be true
dgottlieb c05f441
lint
dgottlieb d218331
Test joint to joint code paths.
dgottlieb d7a8613
and...add the test file
dgottlieb c5d8f8d
feedback
dgottlieb 5c53c1c
remove max solutions
dgottlieb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -59,10 +59,11 @@ func newCBiRRTMotionPlanner(ctx context.Context, pc *planContext, psc *planSegme | |
|
|
||
| // only used for testin. | ||
| func (mp *cBiRRTMotionPlanner) planForTest(ctx context.Context) ([]referenceframe.FrameSystemInputs, error) { | ||
| initMaps, err := initRRTSolutions(ctx, mp.psc) | ||
| initMaps, bgGen, err := initRRTSolutions(ctx, mp.psc) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| bgGen.StopAndWait() // Assume initial solutions are good enough. | ||
|
|
||
| x := []referenceframe.FrameSystemInputs{mp.psc.start} | ||
|
|
||
|
|
@@ -71,7 +72,7 @@ func (mp *cBiRRTMotionPlanner) planForTest(ctx context.Context) ([]referencefram | |
| return x, nil | ||
| } | ||
|
|
||
| solution, err := mp.rrtRunner(ctx, initMaps.maps) | ||
| solution, err := mp.rrtRunner(ctx, initMaps.maps, bgGen) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
@@ -84,21 +85,19 @@ func (mp *cBiRRTMotionPlanner) planForTest(ctx context.Context) ([]referencefram | |
| func (mp *cBiRRTMotionPlanner) rrtRunner( | ||
| ctx context.Context, | ||
| rrtMaps *rrtMaps, | ||
| bgSolutionGenerator *backgroundGenerator, | ||
| ) (*rrtSolution, error) { | ||
| ctx, span := trace.StartSpan(ctx, "rrtRunner") | ||
| defer span.End() | ||
|
|
||
| mp.pc.logger.CDebugf(ctx, "starting cbirrt with start map len %d and goal map len %d\n", len(rrtMaps.startMap), len(rrtMaps.goalMap)) | ||
| mp.pc.logger.CDebugf(ctx, "starting cbirrt with start map len %d and goal map len %d", len(rrtMaps.startMap), len(rrtMaps.goalMap)) | ||
|
|
||
| // setup planner options | ||
| if mp.pc.planOpts == nil { | ||
| return nil, errNoPlannerOptions | ||
| } | ||
|
|
||
| _, cancel := context.WithCancel(ctx) | ||
| defer cancel() | ||
| startTime := time.Now() | ||
|
|
||
| var seed referenceframe.FrameSystemInputs | ||
|
|
||
| // initialize maps | ||
|
|
@@ -109,10 +108,9 @@ func (mp *cBiRRTMotionPlanner) rrtRunner( | |
| break | ||
| } | ||
| } | ||
| mp.pc.logger.CDebugf(ctx, "goal node: %v\n", rrtMaps.optNode.inputs) | ||
| mp.pc.logger.CDebugf(ctx, "start node: %v\n", seed) | ||
| mp.pc.logger.Debug("DOF", mp.pc.lfs.dof) | ||
|
|
||
| mp.pc.logger.CDebugf(ctx, "start node: %v goal node name: %v inputs: %v DOF: %v", | ||
| seed, rrtMaps.optNode.name, rrtMaps.optNode.inputs, mp.pc.lfs.dof) | ||
| interpConfig, err := referenceframe.InterpolateFS(mp.pc.fs, seed, rrtMaps.optNode.inputs, 0.5) | ||
| if err != nil { | ||
| return nil, err | ||
|
|
@@ -121,21 +119,35 @@ func (mp *cBiRRTMotionPlanner) rrtRunner( | |
| target := newConfigurationNode(interpConfig) | ||
|
|
||
| map1, map2 := rrtMaps.startMap, rrtMaps.goalMap | ||
| for i := 0; i < mp.pc.planOpts.PlanIter; i++ { | ||
| mp.pc.logger.CDebugf(ctx, "iteration: %d target: %v\n", i, target.inputs) | ||
| for iterNum := 0; iterNum < mp.pc.planOpts.PlanIter; iterNum++ { | ||
| if ctx.Err() != nil { | ||
| mp.pc.logger.CDebugf(ctx, "CBiRRT timed out after %d iterations", i) | ||
| mp.pc.logger.CDebugf(ctx, "CBiRRT timed out after %d iterations", iterNum) | ||
| return &rrtSolution{maps: rrtMaps}, fmt.Errorf("cbirrt timeout %w", ctx.Err()) | ||
| } | ||
| mp.pc.logger.CDebugf(ctx, "iteration: %d target: %v target name: %v", iterNum, target.inputs, target.name) | ||
|
|
||
| if iterNum%20 == 0 { | ||
| // We continue to generate IK solutions in the background. New candidates can only | ||
| // succeed if given some time. Hence we will pull on a reduced cadence. | ||
| select { | ||
| case newGoal := <-bgSolutionGenerator.newSolutionsCh: | ||
| mp.pc.logger.CDebugf(ctx, "Added new goal while birrting. Goal: %v GoalName: %v", newGoal.inputs, newGoal.name) | ||
| rrtMaps.goalMap[newGoal] = nil | ||
|
|
||
| // Readjust the target to give the new solution a chance to succeed. | ||
| target, err = mp.sample(newGoal, iterNum) | ||
| default: | ||
| } | ||
| } | ||
|
|
||
| tryExtend := func(target *node) (*node, *node) { | ||
| // attempt to extend maps 1 and 2 towards the target | ||
|
|
||
| nearest1 := nearestNeighbor(target, map1, nodeConfigurationDistanceFunc) | ||
| nearest2 := nearestNeighbor(target, map2, nodeConfigurationDistanceFunc) | ||
|
|
||
| map1reached := mp.constrainedExtend(ctx, i, map1, nearest1, target) | ||
| map2reached := mp.constrainedExtend(ctx, i, map2, nearest2, target) | ||
| map1reached := mp.constrainedExtend(ctx, iterNum, map1, nearest1, target) | ||
| map2reached := mp.constrainedExtend(ctx, iterNum, map2, nearest2, target) | ||
|
|
||
| map1reached.corner = true | ||
| map2reached.corner = true | ||
|
|
@@ -169,14 +181,13 @@ func (mp *cBiRRTMotionPlanner) rrtRunner( | |
|
|
||
| // Solved! | ||
| if reachedDelta <= mp.pc.planOpts.InputIdentDist { | ||
| mp.pc.logger.CDebugf(ctx, "CBiRRT found solution after %d iterations in %v", i, time.Since(startTime)) | ||
| cancel() | ||
| mp.pc.logger.CDebugf(ctx, "CBiRRT found solution after %d iterations in %v", iterNum, time.Since(startTime)) | ||
| path := extractPath(rrtMaps.startMap, rrtMaps.goalMap, &nodePair{map1reached, map2reached}, true) | ||
| return &rrtSolution{steps: path, maps: rrtMaps}, nil | ||
| } | ||
|
|
||
| // sample near map 1 and switch which map is which to keep adding to them even | ||
| target, err = mp.sample(map1reached, i) | ||
| target, err = mp.sample(map1reached, iterNum) | ||
| if err != nil { | ||
| return &rrtSolution{maps: rrtMaps}, err | ||
| } | ||
|
|
@@ -254,7 +265,7 @@ func (mp *cBiRRTMotionPlanner) constrainedExtend( | |
| doubled = false | ||
| } | ||
| // constrainNear will ensure path between oldNear and newNear satisfies constraints along the way | ||
| near = &node{inputs: newNear} | ||
| near = &node{name: int(nodeNameCounter.Add(1)), inputs: newNear} | ||
|
||
| rrtMap[near] = oldNear | ||
| } | ||
| return oldNear | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was the "unexpected" part of adding live IK solutions to cbirrt. Without this step of re-assigning the
target, I was never able to see a new solution succeed at getting picked.But if we do this too often, we waste time not advancing existing solutions. Some of which are probably perfectly fine. Hence the
iterNum%20at the top of the conditional.Mostly just need feedback on whether this general idea is acceptable (for now) @erh or if I should be doing something substantially different here.