Skip to content

Commit

Permalink
replace geoObstacle with geoGeometry
Browse files Browse the repository at this point in the history
  • Loading branch information
nfranczak committed May 13, 2024
1 parent e2e3ea4 commit 5df698f
Show file tree
Hide file tree
Showing 13 changed files with 90 additions and 90 deletions.
4 changes: 2 additions & 2 deletions examples/customresources/models/mynavigation/mynavigation.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ func (svc *navSvc) RemoveWaypoint(ctx context.Context, id primitive.ObjectID, ex
return nil
}

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

func (svc *navSvc) Paths(ctx context.Context, extra map[string]interface{}) ([]*navigation.Path, error) {
Expand Down
10 changes: 5 additions & 5 deletions services/motion/builtin/move_on_globe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func TestMoveOnGlobe(t *testing.T) {
ComponentName: fakeBase.Name(),
Destination: dst,
MovementSensorName: injectedMovementSensor.Name(),
Obstacles: []*spatialmath.GeoObstacle{},
Obstacles: []*spatialmath.GeoGeometry{},
MotionCfg: motionCfg,
Extra: extra,
}
Expand Down Expand Up @@ -211,15 +211,15 @@ func TestMoveOnGlobe(t *testing.T) {
boxDims := r3.Vector{X: 5, Y: 50, Z: 10}
geometries, err := spatialmath.NewBox(boxPose, boxDims, "wall")
test.That(t, err, test.ShouldBeNil)
geoObstacle := spatialmath.NewGeoObstacle(gpsPoint, []spatialmath.Geometry{geometries})
geoGeometry := spatialmath.NewGeoGeometry(gpsPoint, []spatialmath.Geometry{geometries})
startPose, err := fakeBase.CurrentPosition(ctx)
test.That(t, err, test.ShouldBeNil)

req := motion.MoveOnGlobeReq{
ComponentName: fakeBase.Name(),
Destination: dst,
MovementSensorName: injectedMovementSensor.Name(),
Obstacles: []*spatialmath.GeoObstacle{geoObstacle},
Obstacles: []*spatialmath.GeoGeometry{geoGeometry},
MotionCfg: motionCfg,
Extra: extra,
}
Expand Down Expand Up @@ -270,13 +270,13 @@ func TestMoveOnGlobe(t *testing.T) {
boxDims = r3.Vector{X: 6660, Y: 20, Z: 10}
geometry4, err := spatialmath.NewBox(boxPose, boxDims, "wall4")
test.That(t, err, test.ShouldBeNil)
geoObstacle := spatialmath.NewGeoObstacle(gpsPoint, []spatialmath.Geometry{geometry1, geometry2, geometry3, geometry4})
geoGeometry := spatialmath.NewGeoGeometry(gpsPoint, []spatialmath.Geometry{geometry1, geometry2, geometry3, geometry4})

req := motion.MoveOnGlobeReq{
ComponentName: fakeBase.Name(),
Destination: dst,
MovementSensorName: injectedMovementSensor.Name(),
Obstacles: []*spatialmath.GeoObstacle{geoObstacle},
Obstacles: []*spatialmath.GeoGeometry{geoGeometry},
MotionCfg: &motion.MotionConfiguration{},
Extra: extra,
}
Expand Down
2 changes: 1 addition & 1 deletion services/motion/motion.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ type MoveOnGlobeReq struct {
// Name of the momement sensor which can be used to derive Position & Heading
MovementSensorName resource.Name
// Static obstacles that should be navigated around
Obstacles []*spatialmath.GeoObstacle
Obstacles []*spatialmath.GeoGeometry
// Optional motion configuration
MotionCfg *MotionConfiguration
Extra map[string]interface{}
Expand Down
6 changes: 3 additions & 3 deletions services/motion/motion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -980,7 +980,7 @@ func TestMoveOnGlobeReq(t *testing.T) {
Destination: geo.NewPoint(1, 2),
ComponentName: mybase,
MovementSensorName: movementsensor.Named("my-movementsensor"),
Obstacles: []*spatialmath.GeoObstacle{},
Obstacles: []*spatialmath.GeoGeometry{},
MotionCfg: &defaultMotionCfg,
Extra: map[string]interface{}{},
},
Expand All @@ -992,7 +992,7 @@ func TestMoveOnGlobeReq(t *testing.T) {
Destination: &commonpb.GeoPoint{Latitude: 1, Longitude: 2},
ComponentName: rprotoutils.ResourceNameToProto(mybase),
MovementSensorName: rprotoutils.ResourceNameToProto(movementsensor.Named("my-movementsensor")),
Obstacles: []*commonpb.GeoObstacle{},
Obstacles: []*commonpb.GeoGeometry{},
MotionConfiguration: &pb.MotionConfiguration{
ObstacleDetectors: obstacleDetectorsPB,
LinearMPerSec: &linearMPerSec,
Expand All @@ -1007,7 +1007,7 @@ func TestMoveOnGlobeReq(t *testing.T) {
Destination: dst,
ComponentName: mybase,
MovementSensorName: movementsensor.Named("my-movementsensor"),
Obstacles: []*spatialmath.GeoObstacle{},
Obstacles: []*spatialmath.GeoGeometry{},
MotionCfg: &MotionConfiguration{
ObstacleDetectors: obstacleDetectors,
LinearMPerSec: linearMPerSec,
Expand Down
8 changes: 4 additions & 4 deletions services/motion/pbhelpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,9 @@ func (r MoveOnGlobeReq) toProto(name string) (*pb.MoveOnGlobeRequest, error) {
}

if len(r.Obstacles) > 0 {
obstaclesProto := make([]*commonpb.GeoObstacle, 0, len(r.Obstacles))
obstaclesProto := make([]*commonpb.GeoGeometry, 0, len(r.Obstacles))
for _, obstacle := range r.Obstacles {
obstaclesProto = append(obstaclesProto, spatialmath.GeoObstacleToProtobuf(obstacle))
obstaclesProto = append(obstaclesProto, spatialmath.GeoGeometryToProtobuf(obstacle))
}
req.Obstacles = obstaclesProto
}
Expand All @@ -204,9 +204,9 @@ func moveOnGlobeRequestFromProto(req *pb.MoveOnGlobeRequest) (MoveOnGlobeReq, er
heading = req.GetHeading()
}
obstaclesProto := req.GetObstacles()
obstacles := make([]*spatialmath.GeoObstacle, 0, len(obstaclesProto))
obstacles := make([]*spatialmath.GeoGeometry, 0, len(obstaclesProto))
for _, eachProtoObst := range obstaclesProto {
convObst, err := spatialmath.GeoObstacleFromProtobuf(eachProtoObst)
convObst, err := spatialmath.GeoGeometryFromProtobuf(eachProtoObst)
if err != nil {
return MoveOnGlobeReq{}, err
}
Expand Down
14 changes: 7 additions & 7 deletions services/motion/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,11 +215,11 @@ func TestServerMoveOnGlobe(t *testing.T) {
"other wall")
test.That(t, err, test.ShouldBeNil)

geoObstacle1 := spatialmath.NewGeoObstacle(geo.NewPoint(70, 40), []spatialmath.Geometry{geometries1})
geoObstacle2 := spatialmath.NewGeoObstacle(geo.NewPoint(-70, 40), []spatialmath.Geometry{geometries2})
obs := []*commonpb.GeoObstacle{
spatialmath.GeoObstacleToProtobuf(geoObstacle1),
spatialmath.GeoObstacleToProtobuf(geoObstacle2),
geoGeometry1 := spatialmath.NewGeoGeometry(geo.NewPoint(70, 40), []spatialmath.Geometry{geometries1})
geoGeometry2 := spatialmath.NewGeoGeometry(geo.NewPoint(-70, 40), []spatialmath.Geometry{geometries2})
obs := []*commonpb.GeoGeometry{
spatialmath.GeoGeometryToProtobuf(geoGeometry1),
spatialmath.GeoGeometryToProtobuf(geoGeometry2),
}
angularDegsPerSec := 1.
linearMPerSec := 2.
Expand Down Expand Up @@ -262,8 +262,8 @@ func TestServerMoveOnGlobe(t *testing.T) {
test.That(t, req.Heading, test.ShouldResemble, reqHeading)
test.That(t, req.MovementSensorName, test.ShouldResemble, expectedMovSensorName)
test.That(t, len(req.Obstacles), test.ShouldEqual, 2)
test.That(t, req.Obstacles[0], test.ShouldResemble, geoObstacle1)
test.That(t, req.Obstacles[1], test.ShouldResemble, geoObstacle2)
test.That(t, req.Obstacles[0], test.ShouldResemble, geoGeometry1)
test.That(t, req.Obstacles[1], test.ShouldResemble, geoGeometry2)
test.That(t, req.MotionCfg.AngularDegsPerSec, test.ShouldAlmostEqual, angularDegsPerSec)
test.That(t, req.MotionCfg.LinearMPerSec, test.ShouldAlmostEqual, linearMPerSec)
test.That(t, req.MotionCfg.PlanDeviationMM, test.ShouldAlmostEqual, planDeviationM*1000)
Expand Down
22 changes: 11 additions & 11 deletions services/navigation/builtin/builtin.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ type Config struct {
DegPerSec float64 `json:"degs_per_sec,omitempty"`
MetersPerSec float64 `json:"meters_per_sec,omitempty"`

Obstacles []*spatialmath.GeoObstacleConfig `json:"obstacles,omitempty"`
Obstacles []*spatialmath.GeoGeometryConfig `json:"obstacles,omitempty"`
PositionPollingFrequencyHz float64 `json:"position_polling_frequency_hz,omitempty"`
ObstaclePollingFrequencyHz float64 `json:"obstacle_polling_frequency_hz,omitempty"`
PlanDeviationM float64 `json:"plan_deviation_m,omitempty"`
Expand Down Expand Up @@ -224,7 +224,7 @@ type builtIn struct {
motionService motion.Service
// exploreMotionService will be removed once the motion explore model is integrated into motion builtin
exploreMotionService motion.Service
obstacles []*spatialmath.GeoObstacle
obstacles []*spatialmath.GeoGeometry

motionCfg *motion.MotionConfiguration
replanCostFactor float64
Expand Down Expand Up @@ -363,7 +363,7 @@ func (svc *builtIn) Reconfigure(ctx context.Context, deps resource.Dependencies,
}

// Parse obstacles from the configuration
newObstacles, err := spatialmath.GeoObstaclesFromConfigs(svcConfig.Obstacles)
newObstacles, err := spatialmath.GeoGeometriesFromConfigs(svcConfig.Obstacles)
if err != nil {
return err
}
Expand Down Expand Up @@ -626,12 +626,12 @@ func (svc *builtIn) waypointIsDeleted() bool {
return svc.waypointInProgress == nil
}

func (svc *builtIn) Obstacles(ctx context.Context, extra map[string]interface{}) ([]*spatialmath.GeoObstacle, error) {
func (svc *builtIn) Obstacles(ctx context.Context, extra map[string]interface{}) ([]*spatialmath.GeoGeometry, error) {
svc.mu.RLock()
defer svc.mu.RUnlock()

// get static geoObstacles
geoObstacles := svc.obstacles
// get static GeoGeometriess
geoGeometries := svc.obstacles

for _, detector := range svc.motionCfg.ObstacleDetectors {
// get the vision service
Expand Down Expand Up @@ -719,7 +719,7 @@ func (svc *builtIn) Obstacles(ctx context.Context, extra map[string]interface{})
robotGeoPose := spatialmath.NewGeoPose(gp, baseHeading)
svc.logger.CDebugf(ctx, "robotGeoPose Location: %v, Heading: %v", *robotGeoPose.Location(), robotGeoPose.Heading())

// iterate through all detections and construct a geoObstacle to append
// iterate through all detections and construct a geoGeometry to append
for i, detection := range detections {
svc.logger.CInfof(
ctx,
Expand Down Expand Up @@ -777,14 +777,14 @@ func (svc *builtIn) Obstacles(ctx context.Context, extra map[string]interface{})
manipulatedGeom = detection.Geometry.Transform(transformBy)

// create the geo obstacle
obstacle := spatialmath.NewGeoObstacle(obstacleGeoPose.Location(), []spatialmath.Geometry{manipulatedGeom})
obstacle := spatialmath.NewGeoGeometry(obstacleGeoPose.Location(), []spatialmath.Geometry{manipulatedGeom})

// add manipulatedGeom to list of geoObstacles we return
geoObstacles = append(geoObstacles, obstacle)
// add manipulatedGeom to list of geoGeometries we return
geoGeometries = append(geoGeometries, obstacle)
}
}

return geoObstacles, nil
return geoGeometries, nil
}

func (svc *builtIn) Paths(ctx context.Context, extra map[string]interface{}) ([]*navigation.Path, error) {
Expand Down
12 changes: 6 additions & 6 deletions services/navigation/builtin/builtin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1685,11 +1685,11 @@ func TestValidateGeometry(t *testing.T) {
geometries, err := spatialmath.NewBox(boxPose, r3.Vector{X: 10, Y: 10, Z: 10}, "")
test.That(t, err, test.ShouldBeNil)

geoObstacle := spatialmath.NewGeoObstacle(geo.NewPoint(0, 0), []spatialmath.Geometry{geometries})
geoObstacleCfg, err := spatialmath.NewGeoObstacleConfig(geoObstacle)
geoGeometry := spatialmath.NewGeoGeometry(geo.NewPoint(0, 0), []spatialmath.Geometry{geometries})
geoGeometryCfg, err := spatialmath.NewGeoGeometryConfig(geoGeometry)
test.That(t, err, test.ShouldBeNil)

cfg.Obstacles = []*spatialmath.GeoObstacleConfig{geoObstacleCfg}
cfg.Obstacles = []*spatialmath.GeoGeometryConfig{geoGeometryCfg}

return cfg
}
Expand Down Expand Up @@ -1741,8 +1741,8 @@ func TestGetObstacles(t *testing.T) {
// create static geo obstacle
sphereGeom, err := spatialmath.NewSphere(spatialmath.NewZeroPose(), 1.0, "test-sphere")
test.That(t, err, test.ShouldBeNil)
sphereGob := spatialmath.NewGeoObstacle(geo.NewPoint(1, 1), []spatialmath.Geometry{sphereGeom})
gobCfg, err := spatialmath.NewGeoObstacleConfig(sphereGob)
sphereGob := spatialmath.NewGeoGeometry(geo.NewPoint(1, 1), []spatialmath.Geometry{sphereGeom})
gobCfg, err := spatialmath.NewGeoGeometryConfig(sphereGob)
test.That(t, err, test.ShouldBeNil)

// construct the navigation service
Expand All @@ -1766,7 +1766,7 @@ func TestGetObstacles(t *testing.T) {
DegPerSec: 1,
MetersPerSec: 1,
MapType: "",
Obstacles: []*spatialmath.GeoObstacleConfig{gobCfg},
Obstacles: []*spatialmath.GeoGeometryConfig{gobCfg},
ObstacleDetectors: []*ObstacleDetectorNameConfig{
{VisionServiceName: injectedVis.Name().Name, CameraName: injectedCam.Name().Name},
},
Expand Down
6 changes: 3 additions & 3 deletions services/navigation/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func (c *client) RemoveWaypoint(ctx context.Context, id primitive.ObjectID, extr
return nil
}

func (c *client) Obstacles(ctx context.Context, extra map[string]interface{}) ([]*spatialmath.GeoObstacle, error) {
func (c *client) Obstacles(ctx context.Context, extra map[string]interface{}) ([]*spatialmath.GeoGeometry, error) {
ext, err := protoutils.StructToStructPb(extra)
if err != nil {
return nil, err
Expand All @@ -179,9 +179,9 @@ func (c *client) Obstacles(ctx context.Context, extra map[string]interface{}) ([
return nil, err
}
protoObs := resp.GetObstacles()
geos := []*spatialmath.GeoObstacle{}
geos := []*spatialmath.GeoGeometry{}
for _, o := range protoObs {
obstacle, err := spatialmath.GeoObstacleFromProtobuf(o)
obstacle, err := spatialmath.GeoGeometryFromProtobuf(o)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions services/navigation/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,9 @@ func (server *serviceServer) GetObstacles(ctx context.Context, req *pb.GetObstac
if err != nil {
return nil, err
}
protoObs := []*commonpb.GeoObstacle{}
protoObs := []*commonpb.GeoGeometry{}
for _, obstacle := range obstacles {
protoObs = append(protoObs, spatialmath.GeoObstacleToProtobuf(obstacle))
protoObs = append(protoObs, spatialmath.GeoGeometryToProtobuf(obstacle))
}
return &pb.GetObstaclesResponse{Obstacles: protoObs}, nil
}
Expand Down
Loading

0 comments on commit 5df698f

Please sign in to comment.