-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
98 additions
and
62 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package builtin | ||
|
||
import ( | ||
"context" | ||
"math" | ||
"math/rand" | ||
|
||
"github.com/golang/geo/r3" | ||
"go.viam.com/utils" | ||
|
||
"go.viam.com/rdk/referenceframe" | ||
"go.viam.com/rdk/spatialmath" | ||
) | ||
|
||
const defaultDistanceMM = 50 * 1000 | ||
|
||
func (svc *builtIn) startExploreMode(ctx context.Context) { | ||
svc.logger.CDebug(ctx, "startExploreMode called") | ||
|
||
svc.activeBackgroundWorkers.Add(1) | ||
|
||
utils.ManagedGo(func() { | ||
// Send motionCfg parameters through extra until motionCfg can be added to Move() | ||
extra := map[string]interface{}{"motionCfg": *svc.motionCfg} | ||
|
||
for { | ||
if ctx.Err() != nil { | ||
return | ||
} | ||
|
||
// Choose a new random point using a normal distribution centered on the position directly the robot | ||
randAngle := rand.NormFloat64() + math.Pi | ||
destination := referenceframe.NewPoseInFrame(svc.base.Name().Name, spatialmath.NewPose( | ||
r3.Vector{ | ||
X: math.Sin(randAngle), | ||
Y: math.Cos(randAngle), | ||
Z: 0., | ||
}.Normalize().Mul(defaultDistanceMM), spatialmath.NewOrientationVector())) | ||
|
||
_, err := svc.exploreMotionService.Move(ctx, svc.base.Name(), destination, nil, nil, extra) | ||
if err != nil { | ||
svc.logger.CDebugf(ctx, "error occurred when moving to point %v: %v", destination, err) | ||
} | ||
} | ||
}, svc.activeBackgroundWorkers.Done) | ||
} |
This file contains 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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package builtin | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
"time" | ||
|
||
"github.com/golang/geo/r3" | ||
"github.com/pkg/errors" | ||
"go.viam.com/test" | ||
|
||
"go.viam.com/rdk/motionplan" | ||
frame "go.viam.com/rdk/referenceframe" | ||
"go.viam.com/rdk/resource" | ||
"go.viam.com/rdk/testutils/inject" | ||
) | ||
|
||
func TestExploreMode(t *testing.T) { | ||
cancelCtx, cancel := context.WithCancel(context.Background()) | ||
defer cancel() | ||
ns, teardown := setupNavigationServiceFromConfig(t, "../data/nav_no_map_cfg.json") | ||
|
||
var points []r3.Vector | ||
mockExploreMotionService := &inject.MotionService{} | ||
mockExploreMotionService.MoveFunc = func(ctx context.Context, componentName resource.Name, | ||
destination *frame.PoseInFrame, worldState *frame.WorldState, constraints *motionplan.Constraints, | ||
extra map[string]interface{}, | ||
) (bool, error) { | ||
points = append(points, destination.Pose().Point()) | ||
return false, errors.New("expected error") | ||
} | ||
|
||
nsStruct := ns.(*builtIn) | ||
nsStruct.exploreMotionService = mockExploreMotionService | ||
|
||
ctxTimeout, cancelFunc := context.WithTimeout(cancelCtx, 50*time.Millisecond) | ||
defer cancelFunc() | ||
nsStruct.startExploreMode(ctxTimeout) | ||
<-ctxTimeout.Done() | ||
teardown() | ||
test.That(t, len(points), test.ShouldBeGreaterThan, 2) | ||
} |