Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove GetLatestMapInfo from SLAM #313

Merged
merged 13 commits into from
Feb 7, 2024
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -329,3 +329,5 @@ require (
periph.io/x/conn/v3 v3.7.0 // indirect
periph.io/x/host/v3 v3.8.2 // indirect
)

replace go.viam.com/rdk => /Users/jeremyhyde/Development/rdk
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this

Copy link
Contributor Author

@jeremyrhyde jeremyrhyde Jan 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will remove after RDK release and before merge

2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1392,8 +1392,6 @@ go.uber.org/zap v1.26.0 h1:sI7k6L95XOKS281NhVKOFCUNIvv9e0w4BF8N3u+tCRo=
go.uber.org/zap v1.26.0/go.mod h1:dtElttAiwGvoJ/vj4IwHBS/gXsEu/pZ50mUIRWuG0so=
go.viam.com/api v0.1.245 h1:DL5x1fxg0VUwPJRI1KaSwXeCZR/PnknTpw7AU0Mmu18=
go.viam.com/api v0.1.245/go.mod h1:msa4TPrMVeRDcG4YzKA/S6wLEUC7GyHQE973JklrQ10=
go.viam.com/rdk v0.18.0 h1:PiqAdBrE+4xr6X43AD5qbELQIJ0jMWgj49uY6x1aJXA=
go.viam.com/rdk v0.18.0/go.mod h1:zOfpk0LP2QKkdWmNwvSUTZldZ2KjrXCIo8KzF+eDfnk=
go.viam.com/test v1.1.1-0.20220913152726-5da9916c08a2 h1:oBiK580EnEIzgFLU4lHOXmGAE3MxnVbeR7s1wp/F3Ps=
go.viam.com/test v1.1.1-0.20220913152726-5da9916c08a2/go.mod h1:XM0tej6riszsiNLT16uoyq1YjuYPWlRBweTPRDanIts=
go.viam.com/utils v0.1.54 h1:1ENNj0atwDngCVKAOr4gXSJnoQdVd88qm38tEnqghaE=
Expand Down
13 changes: 4 additions & 9 deletions testhelper/integrationtesthelper.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,19 +116,14 @@ func testCartographerPosition(t *testing.T, svc slam.Service, useIMU bool, expec

// Checks the cartographer map and confirms there at least 100 map points.
func testCartographerMap(t *testing.T, svc slam.Service, localizationMode bool) {
timestamp1, err := svc.LatestMapInfo(context.Background())
prop, err := svc.Properties(context.Background())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] Clearer to read

Suggested change
prop, err := svc.Properties(context.Background())
props, err := svc.Properties(context.Background())

test.That(t, err, test.ShouldBeNil)
test.That(t, prop.cloud_slam, test.ShouldBeFalse)
test.That(t, prop.mapping_mode, test.ShouldEqual)

pcd, err := slam.PointCloudMapFull(context.Background(), svc)
test.That(t, err, test.ShouldBeNil)
test.That(t, pcd, test.ShouldNotBeNil)
timestamp2, err := svc.LatestMapInfo(context.Background())
test.That(t, err, test.ShouldBeNil)

if localizationMode {
test.That(t, timestamp1, test.ShouldResemble, timestamp2)
} else {
test.That(t, timestamp2.After(timestamp1), test.ShouldBeTrue)
}

pointcloud, err := pointcloud.ReadPCD(bytes.NewReader(pcd))
test.That(t, err, test.ShouldBeNil)
Expand Down
21 changes: 1 addition & 20 deletions viam_cartographer.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,6 @@ func New(
logger: logger,
cartoFacadeTimeout: cartoFacadeTimeout,
cartoFacadeInternalTimeout: cartoFacadeInternalTimeout,
mapTimestamp: time.Now().UTC(),
enableMapping: optionalConfigParams.EnableMapping,
existingMap: optionalConfigParams.ExistingMap,
}
Expand Down Expand Up @@ -501,8 +500,7 @@ type CartographerService struct {
sensorProcessWorkers sync.WaitGroup
cartoFacadeWorkers sync.WaitGroup

mapTimestamp time.Time
jobDone atomic.Bool
jobDone atomic.Bool

postprocessed atomic.Bool
postprocessingTasks []postprocess.Task
Expand Down Expand Up @@ -637,23 +635,6 @@ func (cartoSvc *CartographerService) Properties(ctx context.Context) (slam.Prope
return props, nil
}

// LatestMapInfo returns a new timestamp every time it is called when in mapping mode, to signal
// that the map should be updated. In localizing, the timestamp returned is the timestamp of the session.
func (cartoSvc *CartographerService) LatestMapInfo(ctx context.Context) (time.Time, error) {
_, span := trace.StartSpan(ctx, "viamcartographer::CartographerService::LatestMapInfo")
defer span.End()

if err := cartoSvc.isOpenAndRunningLocally("LatestMapInfo"); err != nil {
return time.Time{}, err
}

if cartoSvc.SlamMode != cartofacade.LocalizingMode {
cartoSvc.mapTimestamp = time.Now().UTC()
}

return cartoSvc.mapTimestamp, nil
}

// DoCommand receives arbitrary commands.
func (cartoSvc *CartographerService) DoCommand(ctx context.Context, req map[string]interface{}) (map[string]interface{}, error) {
_, span := trace.StartSpan(ctx, "viamcartographer::CartographerService::DoCommand")
Expand Down
25 changes: 0 additions & 25 deletions viam_cartographer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,6 @@ func TestNew(t *testing.T) {
test.That(t, gisF, test.ShouldBeNil)
test.That(t, err, test.ShouldBeError, viamcartographer.ErrUseCloudSlamEnabled)

mapTime, err := svc.LatestMapInfo(ctx)
test.That(t, err, test.ShouldBeError, viamcartographer.ErrUseCloudSlamEnabled)
test.That(t, mapTime, test.ShouldResemble, time.Time{})

prop, err := svc.Properties(ctx)
test.That(t, err, test.ShouldBeError, viamcartographer.ErrUseCloudSlamEnabled)
test.That(t, prop, test.ShouldResemble, slam.Properties{})
Expand Down Expand Up @@ -162,9 +158,6 @@ func TestNew(t *testing.T) {
test.That(t, ok, test.ShouldBeTrue)
test.That(t, cs.SlamMode, test.ShouldEqual, cartofacade.LocalizingMode)

timestamp1, err := svc.LatestMapInfo(context.Background())
test.That(t, err, test.ShouldBeNil)

// Test position
pose, componentReference, err := svc.Position(context.Background())
test.That(t, pose, test.ShouldBeNil)
Expand All @@ -188,11 +181,6 @@ func TestNew(t *testing.T) {
test.That(t, err, test.ShouldBeNil)
test.That(t, is, test.ShouldNotBeNil)

timestamp2, err := svc.LatestMapInfo(context.Background())
test.That(t, err, test.ShouldBeNil)
test.That(t, timestamp1.After(_zeroTime), test.ShouldBeTrue)
test.That(t, timestamp1, test.ShouldResemble, timestamp2)

// Test properties
prop, err := svc.Properties(context.Background())
test.That(t, err, test.ShouldBeNil)
Expand Down Expand Up @@ -230,9 +218,6 @@ func TestNew(t *testing.T) {
test.That(t, err, test.ShouldNotBeNil)
test.That(t, err.Error(), test.ShouldContainSubstring, "VIAM_CARTO_GET_POSITION_NOT_INITIALIZED")

timestamp1, err := svc.LatestMapInfo(context.Background())
test.That(t, err, test.ShouldBeNil)

// Test pointcloud map
pcmFunc, err := svc.PointCloudMap(context.Background())
test.That(t, err, test.ShouldBeNil)
Expand All @@ -249,12 +234,6 @@ func TestNew(t *testing.T) {
test.That(t, err, test.ShouldBeNil)
test.That(t, is, test.ShouldNotBeNil)

timestamp2, err := svc.LatestMapInfo(context.Background())
test.That(t, err, test.ShouldBeNil)

test.That(t, timestamp1.After(_zeroTime), test.ShouldBeTrue)
test.That(t, timestamp2.After(timestamp1), test.ShouldBeTrue)

// Test properties
prop, err := svc.Properties(context.Background())
test.That(t, err, test.ShouldBeNil)
Expand Down Expand Up @@ -341,10 +320,6 @@ func TestClose(t *testing.T) {
test.That(t, gisF, test.ShouldBeNil)
test.That(t, err, test.ShouldBeError, viamcartographer.ErrClosed)

mapTime, err := svc.LatestMapInfo(ctx)
test.That(t, err, test.ShouldBeError, viamcartographer.ErrClosed)
test.That(t, mapTime, test.ShouldResemble, time.Time{})

prop, err := svc.Properties(ctx)
test.That(t, err, test.ShouldBeError, viamcartographer.ErrClosed)
test.That(t, prop, test.ShouldResemble, slam.Properties{})
Expand Down
Loading