Skip to content

Commit 75a7dad

Browse files
erhdanielbotros
authored andcommitted
remove rrtstar (viamrobotics#5242)
1 parent 63c6e0f commit 75a7dad

File tree

8 files changed

+2
-435
lines changed

8 files changed

+2
-435
lines changed

motionplan/armplanning/motion_planner.go

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -214,56 +214,6 @@ func (mp *planner) getScoringFunction() motionplan.SegmentFSMetric {
214214
return mp.scoringFunction
215215
}
216216

217-
// smoothPath will try to naively smooth the path by picking points partway between waypoints and seeing if it can interpolate
218-
// directly between them. This will significantly improve paths from RRT*, as it will shortcut the randomly-selected configurations.
219-
// This will only ever improve paths (or leave them untouched), and runs very quickly.
220-
func (mp *planner) smoothPath(ctx context.Context, path []node) []node {
221-
mp.logger.CDebugf(ctx, "running simple smoother on path of len %d", len(path))
222-
if mp.planOpts == nil {
223-
mp.logger.CDebug(ctx, "nil opts, cannot shortcut")
224-
return path
225-
}
226-
if len(path) <= 2 {
227-
mp.logger.CDebug(ctx, "path too short, cannot shortcut")
228-
return path
229-
}
230-
231-
// Randomly pick which quarter of motion to check from; this increases flexibility of smoothing.
232-
waypoints := []float64{0.25, 0.5, 0.75}
233-
234-
for i := 0; i < mp.planOpts.SmoothIter; i++ {
235-
select {
236-
case <-ctx.Done():
237-
return path
238-
default:
239-
}
240-
// get start node of first edge. Cannot be either the last or second-to-last node.
241-
// Intn will return an int in the half-open interval half-open interval [0,n)
242-
firstEdge := mp.randseed.Intn(len(path) - 2)
243-
secondEdge := firstEdge + 1 + mp.randseed.Intn((len(path)-2)-firstEdge)
244-
245-
// Use the frame system to interpolate between configurations
246-
wayPoint1, err := referenceframe.InterpolateFS(mp.fs, path[firstEdge].Q(), path[firstEdge+1].Q(), waypoints[mp.randseed.Intn(3)])
247-
if err != nil {
248-
return path
249-
}
250-
wayPoint2, err := referenceframe.InterpolateFS(mp.fs, path[secondEdge].Q(), path[secondEdge+1].Q(), waypoints[mp.randseed.Intn(3)])
251-
if err != nil {
252-
return path
253-
}
254-
255-
if mp.checkPath(wayPoint1, wayPoint2) {
256-
newpath := []node{}
257-
newpath = append(newpath, path[:firstEdge+1]...)
258-
newpath = append(newpath, newConfigurationNode(wayPoint1), newConfigurationNode(wayPoint2))
259-
// have to split this up due to go compiler quirk where elipses operator can't be mixed with other vars in append
260-
newpath = append(newpath, path[secondEdge+1:]...)
261-
path = newpath
262-
}
263-
}
264-
return path
265-
}
266-
267217
type solutionSolvingState struct {
268218
solutions map[float64]referenceframe.FrameSystemInputs
269219
failures map[string]int // A map keeping track of which constraints fail

motionplan/armplanning/motion_planner_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ type planConfigConstructor func(logger logging.Logger) (*planConfig, error)
4848
func TestUnconstrainedMotion(t *testing.T) {
4949
t.Parallel()
5050
planners := []plannerConstructor{
51-
newRRTStarConnectMotionPlanner,
5251
newCBiRRTMotionPlanner,
5352
}
5453
testCases := []struct {

motionplan/armplanning/nearest_neighbor.go

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ package armplanning
55
import (
66
"context"
77
"math"
8-
"sort"
98

109
"go.viam.com/utils"
1110
)
@@ -25,40 +24,6 @@ type neighbor struct {
2524
node node
2625
}
2726

28-
func kNearestNeighbors(tree rrtMap, target node, neighborhoodSize int, nodeDistanceFunc NodeDistanceMetric) []*neighbor {
29-
kNeighbors := neighborhoodSize
30-
if neighborhoodSize > len(tree) {
31-
kNeighbors = len(tree)
32-
}
33-
34-
allCosts := make([]*neighbor, 0)
35-
for rrtnode := range tree {
36-
dist := nodeDistanceFunc(target, rrtnode)
37-
allCosts = append(allCosts, &neighbor{dist: dist, node: rrtnode})
38-
}
39-
// sort neighbors by their distance to target first so that first nearest neighbor isn't always the start node of tree
40-
sort.Slice(allCosts, func(i, j int) bool {
41-
if !math.IsNaN(allCosts[i].node.Cost()) {
42-
if !math.IsNaN(allCosts[j].node.Cost()) {
43-
return allCosts[i].dist < allCosts[j].dist
44-
}
45-
}
46-
return allCosts[i].dist < allCosts[j].dist
47-
})
48-
allCosts = allCosts[:kNeighbors]
49-
// sort k nearest distance neighbors by "total cost to target" metric so that target's nearest neighbor
50-
// provides the smallest cost path from start node to target
51-
sort.Slice(allCosts, func(i, j int) bool {
52-
if !math.IsNaN(allCosts[i].node.Cost()) {
53-
if !math.IsNaN(allCosts[j].node.Cost()) {
54-
return (allCosts[i].dist + allCosts[i].node.Cost()) < (allCosts[j].dist + allCosts[j].node.Cost())
55-
}
56-
}
57-
return allCosts[i].dist < allCosts[j].dist
58-
})
59-
return allCosts
60-
}
61-
6227
// Can return `nil` when the context is canceled during processing.
6328
func (nm *neighborManager) nearestNeighbor(
6429
ctx context.Context,

motionplan/armplanning/node.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -91,18 +91,6 @@ func (n *basicNode) SetCorner(corner bool) {
9191
// TODO(rb): in the future we might think about making this into a list of nodes.
9292
type nodePair struct{ a, b node }
9393

94-
func (np *nodePair) sumCosts() float64 {
95-
aCost := np.a.Cost()
96-
if math.IsNaN(aCost) {
97-
return 0
98-
}
99-
bCost := np.b.Cost()
100-
if math.IsNaN(bCost) {
101-
return 0
102-
}
103-
return aCost + bCost
104-
}
105-
10694
func extractPath(startMap, goalMap map[node]node, pair *nodePair, matched bool) []node {
10795
// need to figure out which of the two nodes is in the start map
10896
var startReached, goalReached node

motionplan/armplanning/planning_algorithms.go

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ const (
1616
// CBiRRT indicates that a CBiRRTMotionPlanner should be used. This is currently the
1717
// default motion planner.
1818
CBiRRT PlanningAlgorithm = "cbirrt"
19-
// RRTStar indicates that an RRTStarConnectMotionPlanner should be used.
20-
RRTStar PlanningAlgorithm = "rrtstar"
2119
// TPSpace indicates that TPSpaceMotionPlanner should be used.
2220
TPSpace PlanningAlgorithm = "tpspace"
2321
// UnspecifiedAlgorithm indicates that the use of our motion planning will accept whatever defaults the package
@@ -28,9 +26,8 @@ const (
2826
// AlgorithmSettings is a polymorphic representation of motion planning algorithms and their parameters. The `Algorithm`
2927
// should correlate with the available options (e.g. if `Algorithm` us CBiRRT, RRTStarOpts should be nil and CBirrtOpts should not).
3028
type AlgorithmSettings struct {
31-
Algorithm PlanningAlgorithm `json:"algorithm"`
32-
CBirrtOpts *cbirrtOptions `json:"cbirrt_settings"`
33-
RRTStarOpts *rrtStarConnectOptions `json:"rrtstar_settings"`
29+
Algorithm PlanningAlgorithm `json:"algorithm"`
30+
CBirrtOpts *cbirrtOptions `json:"cbirrt_settings"`
3431
}
3532

3633
// move back to cBiRRT.go when motionplan is taken out of RDK.
@@ -42,15 +39,6 @@ type cbirrtOptions struct {
4239
qstep map[string][]float64
4340
}
4441

45-
// move back to rrtStarConnect.go when motionplan is taken out of RDK.
46-
type rrtStarConnectOptions struct {
47-
// The number of nearest neighbors to consider when adding a new sample to the tree
48-
NeighborhoodSize int `json:"neighborhood_size"`
49-
50-
// This is how far rrtStarConnect will try to extend the map towards a goal per-step
51-
qstep map[string][]float64
52-
}
53-
5442
type plannerConstructor func(
5543
*referenceframe.FrameSystem,
5644
*rand.Rand,
@@ -71,8 +59,6 @@ func newMotionPlanner(
7159
switch opt.PlanningAlgorithm() {
7260
case CBiRRT:
7361
return newCBiRRTMotionPlanner(fs, seed, logger, opt, constraintHandler, chains)
74-
case RRTStar:
75-
return newRRTStarConnectMotionPlanner(fs, seed, logger, opt, constraintHandler, chains)
7662
case TPSpace:
7763
return newTPSpaceMotionPlanner(fs, seed, logger, opt, constraintHandler, chains)
7864
case UnspecifiedAlgorithm:

motionplan/armplanning/rrt.go

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -105,21 +105,6 @@ func initRRTSolutions(ctx context.Context, wp atomicWaypoint) *rrtSolution {
105105
return rrt
106106
}
107107

108-
func shortestPath(maps *rrtMaps, nodePairs []*nodePair) *rrtSolution {
109-
if len(nodePairs) == 0 {
110-
return &rrtSolution{err: errPlannerFailed, maps: maps}
111-
}
112-
minIdx := 0
113-
minDist := nodePairs[0].sumCosts()
114-
for i := 1; i < len(nodePairs); i++ {
115-
if dist := nodePairs[i].sumCosts(); dist < minDist {
116-
minDist = dist
117-
minIdx = i
118-
}
119-
}
120-
return &rrtSolution{steps: extractPath(maps.startMap, maps.goalMap, nodePairs[minIdx], true), maps: maps}
121-
}
122-
123108
type rrtPlan struct {
124109
motionplan.SimplePlan
125110

0 commit comments

Comments
 (0)