Skip to content

Commit b9d6d76

Browse files
authored
cache frame system kinematics and use for seeding ik
1 parent 81635b1 commit b9d6d76

38 files changed

+1067
-61
lines changed

etc/test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ if test -n "$GITHUB_RUN_ID"; then
2525
fi
2626

2727
# We run analyzetests on every run, pass or fail. We only run analyzecoverage when all tests passed.
28-
PION_LOG_WARN=webrtc,datachannel,sctp gotestsum --format $FORMAT $LOGFILE -- -tags=no_skip $RACE $COVER $TEST_TARGET
28+
PION_LOG_WARN=webrtc,datachannel,sctp gotestsum --format $FORMAT $LOGFILE -- -tags=no_skip -timeout 30m $RACE $COVER $TEST_TARGET
2929
SUCCESS=$?
3030

3131
if [[ $RACE != "" ]]; then

motionplan/armplanning/cBiRRT.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ func (mp *cBiRRTMotionPlanner) constrainNear(
293293
return nil
294294
}
295295

296-
solutions, err := ik.DoSolve(ctx, mp.fastGradDescent, mp.pc.linearizeFSmetric(mp.psc.checker.PathMetric()), linearSeed, .25)
296+
solutions, err := ik.DoSolve(ctx, mp.fastGradDescent, mp.pc.linearizeFSmetric(mp.psc.checker.PathMetric()), [][]float64{linearSeed}, .25)
297297
if err != nil {
298298
mp.pc.logger.Debugf("constrainNear fail (DoSolve): %v", err)
299299
return nil

motionplan/armplanning/node.go

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,9 @@ type solutionSolvingState struct {
107107
psc *planSegmentContext
108108
maxSolutions int
109109

110-
seed referenceframe.FrameSystemInputs
111-
linearSeed []float64
110+
seeds []referenceframe.FrameSystemInputs
111+
linearSeeds [][]float64
112+
112113
moving, nonmoving []string
113114

114115
ratios []float64
@@ -130,7 +131,7 @@ func newSolutionSolvingState(psc *planSegmentContext) (*solutionSolvingState, er
130131

131132
sss := &solutionSolvingState{
132133
psc: psc,
133-
seed: psc.start,
134+
seeds: []referenceframe.FrameSystemInputs{psc.start},
134135
solutions: []*node{},
135136
failures: newIkConstraintError(psc.pc.fs, psc.checker),
136137
startTime: time.Now(),
@@ -144,11 +145,32 @@ func newSolutionSolvingState(psc *planSegmentContext) (*solutionSolvingState, er
144145
sss.maxSolutions = defaultSolutionsToSeed
145146
}
146147

147-
psc.pc.logger.Debugf("psc.start -> seed: \n%v\n%v", psc.start, sss.seed)
148-
sss.linearSeed, err = psc.pc.lfs.mapToSlice(sss.seed)
148+
ls, err := psc.pc.lfs.mapToSlice(psc.start)
149149
if err != nil {
150150
return nil, err
151151
}
152+
sss.linearSeeds = [][]float64{ls}
153+
154+
if len(psc.pc.lfs.dof) <= 6 { // TODO - remove the limit
155+
ssc, err := smartSeed(psc.pc.fs, psc.pc.logger)
156+
if err != nil {
157+
return nil, fmt.Errorf("cannot create smartSeeder: %w", err)
158+
}
159+
160+
altSeeds, err := ssc.findSeeds(psc.goal, psc.start, psc.pc.logger)
161+
if err != nil {
162+
psc.pc.logger.Warnf("findSeeds failed, ignoring: %v", err)
163+
}
164+
for _, s := range altSeeds {
165+
ls, err := psc.pc.lfs.mapToSlice(s)
166+
if err != nil {
167+
psc.pc.logger.Warnf("mapToSlice failed? %v", err)
168+
continue
169+
}
170+
sss.seeds = append(sss.seeds, s)
171+
sss.linearSeeds = append(sss.linearSeeds, ls)
172+
}
173+
}
152174

153175
sss.moving, sss.nonmoving = sss.psc.motionChains.framesFilteredByMovingAndNonmoving()
154176

@@ -161,12 +183,12 @@ func newSolutionSolvingState(psc *planSegmentContext) (*solutionSolvingState, er
161183
}
162184

163185
func (sss *solutionSolvingState) computeGoodCost(goal referenceframe.FrameSystemPoses) error {
164-
sss.ratios = sss.psc.pc.lfs.inputChangeRatio(sss.psc.motionChains, sss.seed,
186+
sss.ratios = sss.psc.pc.lfs.inputChangeRatio(sss.psc.motionChains, sss.seeds[0], /* maybe use the best one? */
165187
sss.psc.pc.planOpts.getGoalMetric(goal), sss.psc.pc.logger)
166188

167189
adjusted := []float64{}
168190
for idx, r := range sss.ratios {
169-
adjusted = append(adjusted, sss.psc.pc.lfs.jog(idx, sss.linearSeed[idx], r))
191+
adjusted = append(adjusted, sss.psc.pc.lfs.jog(idx, sss.linearSeeds[0][idx] /* match above when we change */, r))
170192
}
171193
step, err := sss.psc.pc.lfs.sliceToMap(adjusted)
172194
if err != nil {
@@ -314,6 +336,9 @@ func (sss *solutionSolvingState) shouldStopEarly() bool {
314336
if sss.bestScoreNoProblem < sss.goodCost/20 {
315337
multiple = 0
316338
minMillis = 10
339+
} else if sss.bestScoreNoProblem < sss.goodCost/15 {
340+
multiple = 1
341+
minMillis = 15
317342
} else if sss.bestScoreNoProblem < sss.goodCost/10 {
318343
multiple = 0
319344
minMillis = 20
@@ -384,7 +409,7 @@ func getSolutions(ctx context.Context, psc *planSegmentContext) ([]*node, error)
384409
utils.PanicCapturingGo(func() {
385410
// This channel close doubles as signaling that the goroutine has exited.
386411
defer close(solutionGen)
387-
_, err := solver.Solve(ctxWithCancel, solutionGen, solvingState.linearSeed, solvingState.ratios, minFunc, psc.pc.randseed.Int())
412+
_, err := solver.Solve(ctxWithCancel, solutionGen, solvingState.linearSeeds, solvingState.ratios, minFunc, psc.pc.randseed.Int())
388413
if err != nil {
389414
solveErrorLock.Lock()
390415
solveError = err

motionplan/armplanning/real_test.go

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -153,22 +153,8 @@ func TestPirouette(t *testing.T) {
153153
armKinematics, err := referenceframe.ParseModelJSONFile(utils.ResolveFile("components/arm/fake/kinematics/ur5e.json"), armName)
154154
test.That(t, err, test.ShouldBeNil)
155155

156-
idealJointValues := [][]referenceframe.Input{
157-
{0 * 3.1415 / 180.0, 0, -90 * 3.1415 / 180.0, 0, 0, 0},
158-
{30 * 3.1415 / 180.0, 0, -90 * 3.1415 / 180.0, 0, 0, 0},
159-
{60 * 3.1415 / 180.0, 0, -90 * 3.1415 / 180.0, 0, 0, 0},
160-
{90 * 3.1415 / 180.0, 0, -90 * 3.1415 / 180.0, 0, 0, 0},
161-
{120 * 3.1415 / 180.0, 0, -90 * 3.1415 / 180.0, 0, 0, 0},
162-
{150 * 3.1415 / 180.0, 0, -90 * 3.1415 / 180.0, 0, 0, 0},
163-
{180 * 3.1415 / 180.0, 0, -90 * 3.1415 / 180.0, 0, 0, 0},
164-
{180 * 3.1415 / 180.0, 0, -90 * 3.1415 / 180.0, 0, 0, 0},
165-
{150 * 3.1415 / 180.0, 0, -90 * 3.1415 / 180.0, 0, 0, 0},
166-
{120 * 3.1415 / 180.0, 0, -90 * 3.1415 / 180.0, 0, 0, 0},
167-
{90 * 3.1415 / 180.0, 0, -90 * 3.1415 / 180.0, 0, 0, 0},
168-
{60 * 3.1415 / 180.0, 0, -90 * 3.1415 / 180.0, 0, 0, 0},
169-
{30 * 3.1415 / 180.0, 0, -90 * 3.1415 / 180.0, 0, 0, 0},
170-
{0 * 3.1415 / 180.0, 0, -90 * 3.1415 / 180.0, 0, 0, 0},
171-
}
156+
idealJointValues := pirIdealJointValues
157+
172158
// the only change here is in joint 0 in increments of 30, while all the other joints are kept at a constant value
173159
// below is change in joint 0 in degrees:
174160
// 0 -> 30 -> 60 -> 90 -> 120 -> 150 -> 180 -> 180 -> 150 -> 120 -> 90 -> 60 -> 30 -> 0

0 commit comments

Comments
 (0)