Skip to content

Commit

Permalink
add BoudingRegions to arguments of MoveOnGlobe + update server test
Browse files Browse the repository at this point in the history
  • Loading branch information
nfranczak committed May 13, 2024
1 parent 5df698f commit 3656937
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 4 deletions.
4 changes: 2 additions & 2 deletions services/motion/builtin/move_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ func (ms *builtIn) newMoveOnGlobeRequest(
// ensure arguments are well behaved
obstacles := req.Obstacles
if obstacles == nil {
obstacles = []*spatialmath.GeoObstacle{}
obstacles = []*spatialmath.GeoGeometry{}
}
if req.Destination == nil {
return nil, errors.New("destination cannot be nil")
Expand Down Expand Up @@ -518,7 +518,7 @@ func (ms *builtIn) newMoveOnGlobeRequest(
return nil, err
}

geomsRaw := spatialmath.GeoObstaclesToGeometries(obstacles, origin)
geomsRaw := spatialmath.GeoGeometriesToGeometries(obstacles, origin)

mr, err := ms.createBaseMoveRequest(
ctx,
Expand Down
4 changes: 3 additions & 1 deletion services/motion/motion.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ type MoveOnGlobeReq struct {
Obstacles []*spatialmath.GeoGeometry
// Optional motion configuration
MotionCfg *MotionConfiguration
Extra map[string]interface{}
//Set of obstacles which the robot must remain within while navigating
BoundingRegions []*spatialmath.GeoGeometry
Extra map[string]interface{}
}

func (r MoveOnGlobeReq) String() string {
Expand Down
19 changes: 19 additions & 0 deletions services/motion/pbhelpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,13 @@ func (r MoveOnGlobeReq) toProto(name string) (*pb.MoveOnGlobeRequest, error) {
}
req.Obstacles = obstaclesProto
}
if len(r.BoundingRegions) > 0 {
obstaclesProto := make([]*commonpb.GeoGeometry, 0, len(r.Obstacles))
for _, obstacle := range r.BoundingRegions {
obstaclesProto = append(obstaclesProto, spatialmath.GeoGeometryToProtobuf(obstacle))
}
req.BoundingRegions = obstaclesProto
}
return req, nil
}

Expand All @@ -212,6 +219,17 @@ func moveOnGlobeRequestFromProto(req *pb.MoveOnGlobeRequest) (MoveOnGlobeReq, er
}
obstacles = append(obstacles, convObst)
}

boundingRegionGeometriesProto := req.GetBoundingRegions()
boundingRegionGeometries := make([]*spatialmath.GeoGeometry, 0, len(boundingRegionGeometriesProto))
for _, eachProtoObst := range boundingRegionGeometriesProto {
convObst, err := spatialmath.GeoGeometryFromProtobuf(eachProtoObst)
if err != nil {
return MoveOnGlobeReq{}, err
}
boundingRegionGeometries = append(boundingRegionGeometries, convObst)
}

protoComponentName := req.GetComponentName()
if protoComponentName == nil {
return MoveOnGlobeReq{}, errors.New("received nil *commonpb.ResourceName")
Expand All @@ -232,6 +250,7 @@ func moveOnGlobeRequestFromProto(req *pb.MoveOnGlobeRequest) (MoveOnGlobeReq, er
MovementSensorName: movementSensorName,
Obstacles: obstacles,
MotionCfg: motionCfg,
BoundingRegions: boundingRegionGeometries,
Extra: req.Extra.AsMap(),
}, nil
}
Expand Down
8 changes: 8 additions & 0 deletions services/motion/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,10 @@ func TestServerMoveOnGlobe(t *testing.T) {
spatialmath.GeoGeometryToProtobuf(geoGeometry1),
spatialmath.GeoGeometryToProtobuf(geoGeometry2),
}
boundingRegionGeoms := []*commonpb.GeoGeometry{
spatialmath.GeoGeometryToProtobuf(geoGeometry1),
spatialmath.GeoGeometryToProtobuf(geoGeometry2),
}
angularDegsPerSec := 1.
linearMPerSec := 2.
planDeviationM := 3.
Expand Down Expand Up @@ -252,6 +256,7 @@ func TestServerMoveOnGlobe(t *testing.T) {
PositionPollingFrequencyHz: &positionPollingFrequencyHz,
ObstacleDetectors: obstacleDetectorsPB,
},
BoundingRegions: boundingRegionGeoms,
}

firstExecutionID := uuid.New()
Expand All @@ -274,6 +279,9 @@ func TestServerMoveOnGlobe(t *testing.T) {
test.That(t, req.MotionCfg.ObstacleDetectors[0].CameraName, test.ShouldResemble, camera.Named("camera 1"))
test.That(t, req.MotionCfg.ObstacleDetectors[1].VisionServiceName, test.ShouldResemble, vision.Named("vision service 2"))
test.That(t, req.MotionCfg.ObstacleDetectors[1].CameraName, test.ShouldResemble, camera.Named("camera 2"))
test.That(t, len(req.BoundingRegions), test.ShouldEqual, 2)
test.That(t, req.BoundingRegions[0], test.ShouldResemble, geoGeometry1)
test.That(t, req.BoundingRegions[1], test.ShouldResemble, geoGeometry2)
return firstExecutionID, nil
}
moveOnGlobeResponse, err := server.MoveOnGlobe(context.Background(), moveOnGlobeRequest)
Expand Down
2 changes: 1 addition & 1 deletion services/navigation/navigation.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ type Service interface {
AddWaypoint(ctx context.Context, point *geo.Point, extra map[string]interface{}) error
RemoveWaypoint(ctx context.Context, id primitive.ObjectID, extra map[string]interface{}) error

Obstacles(ctx context.Context, extra map[string]interface{}) ([]*spatialmath.GeoObstacle, error)
Obstacles(ctx context.Context, extra map[string]interface{}) ([]*spatialmath.GeoGeometry, error)

Paths(ctx context.Context, extra map[string]interface{}) ([]*Path, error)

Expand Down

0 comments on commit 3656937

Please sign in to comment.