Skip to content

Commit bebbb3e

Browse files
authored
RSDK-6036 Remove GetLatestMapInfo from SLAM (viamrobotics#3388)
1 parent d96b797 commit bebbb3e

13 files changed

+8
-136
lines changed

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ require (
8383
go.uber.org/atomic v1.10.0
8484
go.uber.org/multierr v1.11.0
8585
go.uber.org/zap v1.24.0
86-
go.viam.com/api v0.1.248
86+
go.viam.com/api v0.1.253
8787
go.viam.com/test v1.1.1-0.20220913152726-5da9916c08a2
8888
go.viam.com/utils v0.1.54
8989
goji.io v2.0.2+incompatible

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -1492,8 +1492,8 @@ go.uber.org/zap v1.18.1/go.mod h1:xg/QME4nWcxGxrpdeYfq7UvYrLh66cuVKdrbD1XF/NI=
14921492
go.uber.org/zap v1.23.0/go.mod h1:D+nX8jyLsMHMYrln8A0rJjFt/T/9/bGgIhAqxv5URuY=
14931493
go.uber.org/zap v1.24.0 h1:FiJd5l1UOLj0wCgbSE0rwwXHzEdAZS6hiiSnxJN/D60=
14941494
go.uber.org/zap v1.24.0/go.mod h1:2kMP+WWQ8aoFoedH3T2sq6iJ2yDWpHbP0f6MQbS9Gkg=
1495-
go.viam.com/api v0.1.248 h1:RVLCLBbBIIZ0HWiq40UYXfx4JyVw5UQROJfpU+Fxopc=
1496-
go.viam.com/api v0.1.248/go.mod h1:msa4TPrMVeRDcG4YzKA/S6wLEUC7GyHQE973JklrQ10=
1495+
go.viam.com/api v0.1.253 h1:lqTtDtwpBy2r2Z4TPaT2rb6msK6IAU/E2MTRdprjQno=
1496+
go.viam.com/api v0.1.253/go.mod h1:msa4TPrMVeRDcG4YzKA/S6wLEUC7GyHQE973JklrQ10=
14971497
go.viam.com/test v1.1.1-0.20220913152726-5da9916c08a2 h1:oBiK580EnEIzgFLU4lHOXmGAE3MxnVbeR7s1wp/F3Ps=
14981498
go.viam.com/test v1.1.1-0.20220913152726-5da9916c08a2/go.mod h1:XM0tej6riszsiNLT16uoyq1YjuYPWlRBweTPRDanIts=
14991499
go.viam.com/utils v0.1.54 h1:1ENNj0atwDngCVKAOr4gXSJnoQdVd88qm38tEnqghaE=

services/sensors/client.go

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
// Package sensors contains a gRPC based sensors service client
2+
//
3+
//nolint:staticcheck
24
package sensors
35

46
import (

services/sensors/server.go

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
// Package sensors contains a gRPC based sensors service server
2+
//
3+
//nolint:staticcheck
24
package sensors
35

46
import (

services/sensors/server_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//nolint:staticcheck
12
package sensors_test
23

34
import (

services/slam/client.go

-19
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package slam
22

33
import (
44
"context"
5-
"time"
65

76
"github.com/pkg/errors"
87
"go.opencensus.io/trace"
@@ -82,24 +81,6 @@ func (c *client) InternalState(ctx context.Context) (func() ([]byte, error), err
8281
return grpchelper.InternalStateCallback(ctx, c.name, c.client)
8382
}
8483

85-
// LatestMapInfo creates a request, calls the slam service LatestMapInfo, and
86-
// returns the timestamp of the last update to the map.
87-
func (c *client) LatestMapInfo(ctx context.Context) (time.Time, error) {
88-
ctx, span := trace.StartSpan(ctx, "slam::client::LatestMapInfo")
89-
defer span.End()
90-
91-
req := &pb.GetLatestMapInfoRequest{
92-
Name: c.name,
93-
}
94-
95-
resp, err := c.client.GetLatestMapInfo(ctx, req)
96-
if err != nil {
97-
return time.Time{}, errors.New("failure to get latest map info")
98-
}
99-
lastMapUpdate := resp.LastMapUpdate.AsTime()
100-
return lastMapUpdate, err
101-
}
102-
10384
// Properties returns information regarding the current SLAM session, including
10485
// if the session is running in the cloud and what mapping mode it is in.
10586
func (c *client) Properties(ctx context.Context) (Properties, error) {

services/slam/client_test.go

-31
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"net"
99
"os"
1010
"testing"
11-
"time"
1211

1312
"github.com/golang/geo/r3"
1413
"github.com/pkg/errors"
@@ -49,7 +48,6 @@ func TestClientWorkingService(t *testing.T) {
4948
pcd, err := os.ReadFile(pcdPath)
5049
test.That(t, err, test.ShouldBeNil)
5150

52-
timestampSucc := time.Now().UTC()
5351
propSucc := slam.Properties{
5452
CloudSlam: false,
5553
MappingMode: slam.MappingModeNewMap,
@@ -92,10 +90,6 @@ func TestClientWorkingService(t *testing.T) {
9290
return f, nil
9391
}
9492

95-
workingSLAMService.LatestMapInfoFunc = func(ctx context.Context) (time.Time, error) {
96-
return timestampSucc, nil
97-
}
98-
9993
workingSLAMService.PropertiesFunc = func(ctx context.Context) (slam.Properties, error) {
10094
return propSucc, nil
10195
}
@@ -145,11 +139,6 @@ func TestClientWorkingService(t *testing.T) {
145139
test.That(t, err, test.ShouldBeNil)
146140
test.That(t, fullBytesInternalState, test.ShouldResemble, internalStateSucc)
147141

148-
// test latest map info
149-
timestamp, err := workingSLAMClient.LatestMapInfo(context.Background())
150-
test.That(t, err, test.ShouldBeNil)
151-
test.That(t, timestamp, test.ShouldResemble, timestampSucc)
152-
153142
// test properties
154143
prop, err := workingSLAMClient.Properties(context.Background())
155144
test.That(t, err, test.ShouldBeNil)
@@ -185,11 +174,6 @@ func TestClientWorkingService(t *testing.T) {
185174
test.That(t, err, test.ShouldBeNil)
186175
test.That(t, fullBytesInternalState, test.ShouldResemble, internalStateSucc)
187176

188-
// test latest map info
189-
timestamp, err := workingDialedClient.LatestMapInfo(context.Background())
190-
test.That(t, err, test.ShouldBeNil)
191-
test.That(t, timestamp, test.ShouldResemble, timestampSucc)
192-
193177
// test properties
194178
prop, err := workingDialedClient.Properties(context.Background())
195179
test.That(t, err, test.ShouldBeNil)
@@ -233,11 +217,6 @@ func TestClientWorkingService(t *testing.T) {
233217
test.That(t, err, test.ShouldBeNil)
234218
test.That(t, fullBytesInternalState, test.ShouldResemble, internalStateSucc)
235219

236-
// test latest map info
237-
timestamp, err := dialedClient.LatestMapInfo(context.Background())
238-
test.That(t, err, test.ShouldBeNil)
239-
test.That(t, timestamp, test.ShouldResemble, timestampSucc)
240-
241220
// test properties
242221
prop, err := dialedClient.Properties(context.Background())
243222
test.That(t, err, test.ShouldBeNil)
@@ -276,10 +255,6 @@ func TestFailingClient(t *testing.T) {
276255
return nil, errors.New("failure during get internal state")
277256
}
278257

279-
failingSLAMService.LatestMapInfoFunc = func(ctx context.Context) (time.Time, error) {
280-
return time.Time{}, errors.New("failure to get latest map info")
281-
}
282-
283258
failingSLAMService.PropertiesFunc = func(ctx context.Context) (slam.Properties, error) {
284259
return slam.Properties{}, errors.New("failure to get properties")
285260
}
@@ -333,12 +308,6 @@ func TestFailingClient(t *testing.T) {
333308
test.That(t, err.Error(), test.ShouldContainSubstring, "failure during get internal state")
334309
test.That(t, fullBytesInternalState, test.ShouldBeNil)
335310

336-
// test latest map info
337-
timestamp, err := failingSLAMClient.LatestMapInfo(context.Background())
338-
test.That(t, err, test.ShouldNotBeNil)
339-
test.That(t, err.Error(), test.ShouldContainSubstring, "failure to get latest map info")
340-
test.That(t, timestamp, test.ShouldResemble, time.Time{})
341-
342311
// test properties
343312
prop, err := failingSLAMClient.Properties(context.Background())
344313
test.That(t, err, test.ShouldNotBeNil)

services/slam/fake/slam.go

-9
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,6 @@ func (slamSvc *SLAM) InternalState(ctx context.Context) (func() ([]byte, error),
8888
return fakeInternalState(ctx, datasetDirectory, slamSvc)
8989
}
9090

91-
// LatestMapInfo returns information used to determine whether the slam mode is localizing.
92-
// Fake Slam is always in mapping mode, so it always returns a new timestamp.
93-
func (slamSvc *SLAM) LatestMapInfo(ctx context.Context) (time.Time, error) {
94-
_, span := trace.StartSpan(ctx, "slam::fake::LatestMapInfo")
95-
defer span.End()
96-
slamSvc.mapTimestamp = time.Now().UTC()
97-
return slamSvc.mapTimestamp, nil
98-
}
99-
10091
// Properties returns the mapping mode of the slam service as well as a boolean indicating if it is running
10192
// in the cloud or locally. In the case of fake slam, it will return that the service is being run locally
10293
// and is creating a new map.

services/slam/fake/slam_test.go

-11
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,6 @@ func TestFakeSLAMPosition(t *testing.T) {
4242
test.That(t, p, test.ShouldResemble, p2)
4343
}
4444

45-
func TestFakeSLAMLatestMapInfo(t *testing.T) {
46-
slamSvc := NewSLAM(slam.Named("test"), logging.NewTestLogger(t))
47-
48-
timestamp1, err := slamSvc.LatestMapInfo(context.Background())
49-
test.That(t, err, test.ShouldBeNil)
50-
51-
timestamp2, err := slamSvc.LatestMapInfo(context.Background())
52-
test.That(t, err, test.ShouldBeNil)
53-
test.That(t, timestamp2.After(timestamp1), test.ShouldBeTrue)
54-
}
55-
5645
func TestFakeProperties(t *testing.T) {
5746
slamSvc := NewSLAM(slam.Named("test"), logging.NewTestLogger(t))
5847

services/slam/server.go

-24
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"go.opencensus.io/trace"
99
commonpb "go.viam.com/api/common/v1"
1010
pb "go.viam.com/api/service/slam/v1"
11-
"google.golang.org/protobuf/types/known/timestamppb"
1211

1312
"go.viam.com/rdk/protoutils"
1413
"go.viam.com/rdk/resource"
@@ -127,29 +126,6 @@ func (server *serviceServer) GetInternalState(req *pb.GetInternalStateRequest,
127126
}
128127
}
129128

130-
// GetLatestMapInfo returns the timestamp of when the map was last updated.
131-
func (server *serviceServer) GetLatestMapInfo(ctx context.Context, req *pb.GetLatestMapInfoRequest) (
132-
*pb.GetLatestMapInfoResponse, error,
133-
) {
134-
ctx, span := trace.StartSpan(ctx, "slam::server::GetLatestMapInfo")
135-
defer span.End()
136-
137-
svc, err := server.coll.Resource(req.Name)
138-
if err != nil {
139-
return nil, err
140-
}
141-
142-
mapTimestamp, err := svc.LatestMapInfo(ctx)
143-
if err != nil {
144-
return nil, err
145-
}
146-
protoTimestamp := timestamppb.New(mapTimestamp)
147-
148-
return &pb.GetLatestMapInfoResponse{
149-
LastMapUpdate: protoTimestamp,
150-
}, nil
151-
}
152-
153129
// GetProperties returns the mapping mode and of the slam process and whether it is being done locally
154130
// or in the cloud.
155131
func (server *serviceServer) GetProperties(ctx context.Context, req *pb.GetPropertiesRequest) (

services/slam/server_test.go

-27
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"math"
99
"os"
1010
"testing"
11-
"time"
1211

1312
"github.com/golang/geo/r3"
1413
commonpb "go.viam.com/api/common/v1"
@@ -144,21 +143,6 @@ func TestWorkingServer(t *testing.T) {
144143
test.That(t, mockServer.rawBytes, test.ShouldResemble, internalStateSucc)
145144
})
146145

147-
t.Run("working GetLatestMapInfo", func(t *testing.T) {
148-
timestamp := time.Now().UTC()
149-
injectSvc.LatestMapInfoFunc = func(ctx context.Context) (time.Time, error) {
150-
return timestamp, nil
151-
}
152-
153-
reqInfo := &pb.GetLatestMapInfoRequest{
154-
Name: testSlamServiceName,
155-
}
156-
157-
respInfo, err := slamServer.GetLatestMapInfo(context.Background(), reqInfo)
158-
test.That(t, err, test.ShouldBeNil)
159-
test.That(t, respInfo.LastMapUpdate.AsTime(), test.ShouldResemble, timestamp)
160-
})
161-
162146
t.Run("working GetProperties", func(t *testing.T) {
163147
prop := slam.Properties{
164148
CloudSlam: false,
@@ -310,17 +294,6 @@ func TestFailingServer(t *testing.T) {
310294
test.That(t, err.Error(), test.ShouldContainSubstring, "callback error")
311295
})
312296

313-
t.Run("failing GetLatestMapInfo", func(t *testing.T) {
314-
injectSvc.LatestMapInfoFunc = func(ctx context.Context) (time.Time, error) {
315-
return time.Time{}, errors.New("failure to get latest map info")
316-
}
317-
reqInfo := &pb.GetLatestMapInfoRequest{Name: testSlamServiceName}
318-
319-
respInfo, err := slamServer.GetLatestMapInfo(context.Background(), reqInfo)
320-
test.That(t, err.Error(), test.ShouldContainSubstring, "failure to get latest map info")
321-
test.That(t, respInfo, test.ShouldBeNil)
322-
})
323-
324297
t.Run("failing GetProperties", func(t *testing.T) {
325298
injectSvc.PropertiesFunc = func(ctx context.Context) (slam.Properties, error) {
326299
return slam.Properties{}, errors.New("failure to get properties")

services/slam/slam.go

-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"bytes"
77
"context"
88
"io"
9-
"time"
109

1110
"github.com/pkg/errors"
1211
"go.opencensus.io/trace"
@@ -82,7 +81,6 @@ type Service interface {
8281
Position(ctx context.Context) (spatialmath.Pose, string, error)
8382
PointCloudMap(ctx context.Context) (func() ([]byte, error), error)
8483
InternalState(ctx context.Context) (func() ([]byte, error), error)
85-
LatestMapInfo(ctx context.Context) (time.Time, error)
8684
Properties(ctx context.Context) (Properties, error)
8785
}
8886

testutils/inject/slam_service.go

-10
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package inject
22

33
import (
44
"context"
5-
"time"
65

76
"go.viam.com/rdk/resource"
87
"go.viam.com/rdk/services/slam"
@@ -16,7 +15,6 @@ type SLAMService struct {
1615
PositionFunc func(ctx context.Context) (spatialmath.Pose, string, error)
1716
PointCloudMapFunc func(ctx context.Context) (func() ([]byte, error), error)
1817
InternalStateFunc func(ctx context.Context) (func() ([]byte, error), error)
19-
LatestMapInfoFunc func(ctx context.Context) (time.Time, error)
2018
PropertiesFunc func(ctx context.Context) (slam.Properties, error)
2119
DoCommandFunc func(ctx context.Context, cmd map[string]interface{}) (map[string]interface{}, error)
2220
CloseFunc func(ctx context.Context) error
@@ -56,14 +54,6 @@ func (slamSvc *SLAMService) InternalState(ctx context.Context) (func() ([]byte,
5654
return slamSvc.InternalStateFunc(ctx)
5755
}
5856

59-
// LatestMapInfo calls the injected LatestMapInfoFunc or the real version.
60-
func (slamSvc *SLAMService) LatestMapInfo(ctx context.Context) (time.Time, error) {
61-
if slamSvc.LatestMapInfoFunc == nil {
62-
return slamSvc.Service.LatestMapInfo(ctx)
63-
}
64-
return slamSvc.LatestMapInfoFunc(ctx)
65-
}
66-
6757
// Properties calls the injected PropertiesFunc or the real version.
6858
func (slamSvc *SLAMService) Properties(ctx context.Context) (slam.Properties, error) {
6959
if slamSvc.PropertiesFunc == nil {

0 commit comments

Comments
 (0)